diff --git a/__init__.py b/__init__.py index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..5becc17c04a9e3ad1c2a15f53252b7bb5a7517e7 100644 --- a/__init__.py +++ b/__init__.py @@ -0,0 +1 @@ +__version__ = "1.0.0" diff --git a/__main__.py b/__main__.py index 5a10300cc95eb63488189359941018bd07a627b4..3969552835c1253b392f72b22fdf8e8a4679c605 100644 --- a/__main__.py +++ b/__main__.py @@ -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 - :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) - - +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.setWindowTitle("GEPARD") - self.fname: str = '' + self.setWindowTitle("GEPARD " + __version__) self.resize(900, 700) + + self.view = SampleView(logpath) + self.view.imparent = self + self.view.ScalingChanged.connect(self.scalingChanged) self.scalebar = ScaleBar(self) self.legend = ColorLegend(self) - self.lightModeSwitch = LightModeSwitch(self) - self.view = SampleView(self, logger) - self.view.ScalingChanged.connect(self.scalingChanged) + self.ramanSwitch = RamanSwitch(self) self.view.ScalingChanged.connect(self.scalebar.updateScale) mdiarea = QtWidgets.QMdiArea(self) mdiarea.addSubWindow(self.scalebar) mdiarea.addSubWindow(self.legend) - mdiarea.addSubWindow(self.lightModeSwitch) + mdiarea.addSubWindow(self.ramanSwitch) self.legend.hide() - self.lightModeSwitch.hide() + self.ramanSwitch.hide() subview = mdiarea.addSubWindow(self.view) subview.showMaximized() diff --git a/analysis/importSpectra.py b/analysis/importSpectra.py index 06ea9dd38bd28255d4cf527653da44114203b195..c0c66a54408e21724fea3bdbcccc04600aabbe93 100644 --- a/analysis/importSpectra.py +++ b/analysis/importSpectra.py @@ -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 else: 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(';'): - 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: - spectra.append(line.split(';')) - - return np.array(spectra, dtype=np.float), names[1:] + rawSpectra.append(line.split(';')) + + # 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:]