Commit 8020cfd2 authored by Elisa Kanaki's avatar Elisa Kanaki

Update importSpectra, include version number from branch Development

parent b5b8af90
......@@ -18,63 +18,36 @@ You should have received a copy of the GNU General Public License
along with this program, see COPYING.
If not, see <>.
import logging
import logging.handlers
import traceback
import os
from io import StringIO
from typing import List
from PyQt5 import QtCore, QtWidgets, QtGui
from .sampleview import SampleView
from .gui.scalebar import ScaleBar
from .instrumentcom.instrumentConfig import defaultPath
from .instrumentcom.lightModeSwitch import LightModeSwitch
from .gui.colorlegend import ColorLegend
from .gepardlogging import setDefaultLoggingConfig
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
tbinfofile = StringIO()
traceback.print_tb(tracebackobj, None, tbinfofile)
tbinfo =
logging.critical("Fatal error in program excecution!")
from .errors import showErrorMessageAsWidget
from .scalebar import ScaleBar
from .ramancom.ramancontrol import defaultPath
from .ramancom.ramanSwitch import RamanSwitch
from .analysis.colorlegend import ColorLegend
from gepard import __version__
class GEPARDMainWindow(QtWidgets.QMainWindow):
def __init__(self, logger):
def __init__(self, logpath):
super(GEPARDMainWindow, self).__init__()
self.fname: str = ''
self.setWindowTitle("GEPARD " + __version__)
self.resize(900, 700)
self.view = SampleView(logpath)
self.view.imparent = self
self.scalebar = ScaleBar(self)
self.legend = ColorLegend(self)
self.lightModeSwitch = LightModeSwitch(self)
self.view = SampleView(self, logger)
self.ramanSwitch = RamanSwitch(self)
mdiarea = QtWidgets.QMdiArea(self)
subview = mdiarea.addSubWindow(self.view)
......@@ -3,7 +3,7 @@
Created on Tue May 28 20:33:14 2019
@author: brandt
@author: brandt, kanaki
import numpy as np
......@@ -11,7 +11,21 @@ import numpy as np
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 firstColumnOnlyHasUniqueNumbers(data):
......@@ -28,7 +42,8 @@ def importWITecSpectra(fname):
return data, names
raise ImportError
def importRenishawSpectra(fname):
data = np.loadtxt(fname)
rawSpectra = data[:, 2:4]
......@@ -54,16 +69,32 @@ def importRenishawSpectra(fname):
return spectra, names
# return np.transpose(np.hstack((wavenumbers, spectra))), names
def importPerkinElmerSpectra(fname):
"""Import Spotlight spectra from csv-file created with the PerkingElmer convert-tool."""
names = []
spectra = []
rawSpectra = []
spectraIndices = []
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()):
if index == 0:
for name in line.split(';'):
specIndex = int(name.split('.sp')[0].split('_')[1])
except IndexError:
specIndex = int(0)
names.append(name.split('.sp')[0] + ' (' + str(specIndex)+ ')')
elif index > 1:
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:]
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment