Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Open sidebar
GEPARD
GEPARD
Commits
8020cfd2
Commit
8020cfd2
authored
Oct 14, 2020
by
Elisa Kanaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update importSpectra, include version number from branch Development
parent
b5b8af90
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
51 deletions
+56
-51
__init__.py
__init__.py
+1
-0
__main__.py
__main__.py
+15
-42
analysis/importSpectra.py
analysis/importSpectra.py
+40
-9
No files found.
__init__.py
View file @
8020cfd2
__version__
=
"1.0.0"
__main__.py
View file @
8020cfd2
...
@@ -18,63 +18,36 @@ You should have received a copy of the GNU General Public License
...
@@ -18,63 +18,36 @@ You should have received a copy of the GNU General Public License
along with this program, see COPYING.
along with this program, see COPYING.
If not, see <https://www.gnu.org/licenses/>.
If not, see <https://www.gnu.org/licenses/>.
"""
"""
import
logging
import
logging.handlers
import
traceback
import
os
import
os
from
io
import
StringIO
from
typing
import
List
from
PyQt5
import
QtCore
,
QtWidgets
,
QtGui
from
PyQt5
import
QtCore
,
QtWidgets
,
QtGui
from
.sampleview
import
SampleView
from
.sampleview
import
SampleView
from
.gui.scalebar
import
ScaleBar
from
.scalebar
import
ScaleBar
from
.instrumentcom.instrumentConfig
import
defaultPath
from
.ramancom.ramancontrol
import
defaultPath
from
.instrumentcom.lightModeSwitch
import
LightModeSwitch
from
.ramancom.ramanSwitch
import
RamanSwitch
from
.gui.colorlegend
import
ColorLegend
from
.analysis.colorlegend
import
ColorLegend
from
.gepardlogging
import
setDefaultLoggingConfig
from
gepard
import
__version__
from
.workmodes
import
ModeHandler
from
.unittests.test_gepard
import
testGepard
from
.helperfunctions
import
getAppFolder
def
excepthook
(
excType
,
excValue
,
tracebackobj
):
"""
Global function to catch unhandled exceptions.
@param excType exception type
@param excValue exception value
@param tracebackobj traceback object
:return:
"""
tbinfofile
=
StringIO
()
traceback
.
print_tb
(
tracebackobj
,
None
,
tbinfofile
)
tbinfofile
.
seek
(
0
)
tbinfo
=
tbinfofile
.
read
()
logging
.
critical
(
"Fatal error in program excecution!"
)
logging
.
critical
(
tbinfo
)
from
.errors
import
showErrorMessageAsWidget
showErrorMessageAsWidget
(
tbinfo
)
class
GEPARDMainWindow
(
QtWidgets
.
QMainWindow
):
class
GEPARDMainWindow
(
QtWidgets
.
QMainWindow
):
def
__init__
(
self
,
log
ger
):
def
__init__
(
self
,
log
path
):
super
(
GEPARDMainWindow
,
self
).
__init__
()
super
(
GEPARDMainWindow
,
self
).
__init__
()
self
.
setWindowTitle
(
"GEPARD"
)
self
.
setWindowTitle
(
"GEPARD "
+
__version__
)
self
.
fname
:
str
=
''
self
.
resize
(
900
,
700
)
self
.
resize
(
900
,
700
)
self
.
view
=
SampleView
(
logpath
)
self
.
view
.
imparent
=
self
self
.
view
.
ScalingChanged
.
connect
(
self
.
scalingChanged
)
self
.
scalebar
=
ScaleBar
(
self
)
self
.
scalebar
=
ScaleBar
(
self
)
self
.
legend
=
ColorLegend
(
self
)
self
.
legend
=
ColorLegend
(
self
)
self
.
lightModeSwitch
=
LightModeSwitch
(
self
)
self
.
ramanSwitch
=
RamanSwitch
(
self
)
self
.
view
=
SampleView
(
self
,
logger
)
self
.
view
.
ScalingChanged
.
connect
(
self
.
scalingChanged
)
self
.
view
.
ScalingChanged
.
connect
(
self
.
scalebar
.
updateScale
)
self
.
view
.
ScalingChanged
.
connect
(
self
.
scalebar
.
updateScale
)
mdiarea
=
QtWidgets
.
QMdiArea
(
self
)
mdiarea
=
QtWidgets
.
QMdiArea
(
self
)
mdiarea
.
addSubWindow
(
self
.
scalebar
)
mdiarea
.
addSubWindow
(
self
.
scalebar
)
mdiarea
.
addSubWindow
(
self
.
legend
)
mdiarea
.
addSubWindow
(
self
.
legend
)
mdiarea
.
addSubWindow
(
self
.
lightMode
Switch
)
mdiarea
.
addSubWindow
(
self
.
raman
Switch
)
self
.
legend
.
hide
()
self
.
legend
.
hide
()
self
.
lightMode
Switch
.
hide
()
self
.
raman
Switch
.
hide
()
subview
=
mdiarea
.
addSubWindow
(
self
.
view
)
subview
=
mdiarea
.
addSubWindow
(
self
.
view
)
subview
.
showMaximized
()
subview
.
showMaximized
()
...
...
analysis/importSpectra.py
View file @
8020cfd2
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
"""
"""
Created on Tue May 28 20:33:14 2019
Created on Tue May 28 20:33:14 2019
@author: brandt
@author: brandt
, kanaki
"""
"""
import
numpy
as
np
import
numpy
as
np
...
@@ -11,7 +11,21 @@ import numpy as np
...
@@ -11,7 +11,21 @@ import numpy as np
and names for all in file contained spectra'''
and names for all in file contained spectra'''
#TODO: Include sanity checks for correct file format?
def
listInstruments
():
instruments
=
[
"WiTec"
,
"PerkinElmer"
,
"Renishaw"
]
return
instruments
def
chooseInstrument
(
instrument
,
fname
):
if
instrument
==
"WiTec"
:
spectra
,
names
=
importWITecSpectra
(
fname
)
elif
instrument
==
"PerkinElmer"
:
spectra
,
names
=
importPerkinElmerSpectra
(
fname
)
elif
instrument
==
"Renishaw"
:
spectra
,
names
=
importRenishawSpectra
(
fname
)
return
spectra
,
names
def
importWITecSpectra
(
fname
):
def
importWITecSpectra
(
fname
):
def
firstColumnOnlyHasUniqueNumbers
(
data
):
def
firstColumnOnlyHasUniqueNumbers
(
data
):
...
@@ -28,7 +42,8 @@ def importWITecSpectra(fname):
...
@@ -28,7 +42,8 @@ def importWITecSpectra(fname):
return
data
,
names
return
data
,
names
else
:
else
:
raise
ImportError
raise
ImportError
def
importRenishawSpectra
(
fname
):
def
importRenishawSpectra
(
fname
):
data
=
np
.
loadtxt
(
fname
)
data
=
np
.
loadtxt
(
fname
)
rawSpectra
=
data
[:,
2
:
4
]
rawSpectra
=
data
[:,
2
:
4
]
...
@@ -54,16 +69,32 @@ def importRenishawSpectra(fname):
...
@@ -54,16 +69,32 @@ def importRenishawSpectra(fname):
return
spectra
,
names
return
spectra
,
names
# return np.transpose(np.hstack((wavenumbers, spectra))), names
# return np.transpose(np.hstack((wavenumbers, spectra))), names
def
importPerkinElmerSpectra
(
fname
):
def
importPerkinElmerSpectra
(
fname
):
"""Import Spotlight spectra from csv-file created with the PerkingElmer convert-tool."""
names
=
[]
names
=
[]
spectra
=
[]
rawSpectra
=
[]
spectraIndices
=
[]
with
open
(
fname
)
as
fp
:
with
open
(
fname
)
as
fp
:
# First line contains spectra file names. The first name is Marker.sp, the rest Marker_xxx.sp, starting with
# 001. Spectra start in third line
for
index
,
line
in
enumerate
(
fp
.
readlines
()):
for
index
,
line
in
enumerate
(
fp
.
readlines
()):
if
index
==
0
:
if
index
==
0
:
for
name
in
line
.
split
(
';'
):
for
name
in
line
.
split
(
';'
):
names
.
append
(
name
.
split
(
'.sp'
)[
0
])
try
:
specIndex
=
int
(
name
.
split
(
'.sp'
)[
0
].
split
(
'_'
)[
1
])
except
IndexError
:
specIndex
=
int
(
0
)
names
.
append
(
name
.
split
(
'.sp'
)[
0
]
+
' ('
+
str
(
specIndex
)
+
')'
)
spectraIndices
.
append
(
specIndex
)
elif
index
>
1
:
elif
index
>
1
:
spectra
.
append
(
line
.
split
(
';'
))
rawSpectra
.
append
(
line
.
split
(
';'
))
return
np
.
array
(
spectra
,
dtype
=
np
.
float
),
names
[
1
:]
# Spectra in csv are sorted alphabetically by filename, causing incorrect order when 1000 spectra are
# exceeded. Sort numerically by spectrum index:
sortingIndex
=
np
.
argsort
(
spectraIndices
)
namesSorted
=
[
names
[
ii
]
for
ii
in
sortingIndex
]
spectra
=
np
.
array
(
rawSpectra
,
dtype
=
np
.
float
)[:,
sortingIndex
]
return
spectra
,
namesSorted
[
1
:]
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment