Commit 1748c624 authored by JosefBrandt's avatar JosefBrandt

Added batching of spectra for TrueMatch when using AdvancedWITec

parent 79594c9c
......@@ -205,6 +205,7 @@ class WITecCOM(RamanBase):
self.advSpec = AdvancedWITecSpectra()
if 'Autofocus' not in [param.name for param in self.ramanParameters]:
self.ramanParameters.append(RamanSettingParam('Autofocus', 'checkBox', default=False))
self.ramanParameters.append(RamanSettingParam('Spectra Batch Size', 'int', default=1000, minVal=1, maxVal=1e6))
def getBrightness(self):
assert self.connected
......@@ -381,6 +382,7 @@ class WITecCOM(RamanBase):
def initateSilentSpectrumAcquisition(self, ramanSettings):
self.advSpec.setDatasetPath(ramanSettings['path'])
self.advSpec.setSpectraBatchSize(ramanSettings['Spectra Batch Size'])
self.doAutoFocus = ramanSettings['Autofocus']
......
......@@ -32,10 +32,14 @@ class AdvancedWITecSpectra(object):
self.tmpspecpath = None
self.curSpecIndex = None
self.excitWavel = None
self.spectraBatchSize = None
def setDatasetPath(self, path):
self.dsetpath = path
def setSpectraBatchSize(self, batchSize):
self.spectraBatchSize = batchSize
def createTmpSpecFolder(self):
assert self.dsetpath is not None
self.tmpspecpath = os.path.join(self.dsetpath, 'spectra')
......@@ -152,22 +156,16 @@ class AdvancedWITecSpectra(object):
return allSpectra
def createTrueMatchTxt(self, allSpectra, wavelength):
wavenumbers = allSpectra[:, 0]
spectra = allSpectra[:, 1:]
specSize = allSpectra.shape[0]
del allSpectra
outName = os.path.join(self.dsetpath, 'SpectraForTrueMatch.txt')
if os.path.exists(outName):
os.remove(outName)
with open(outName, 'w') as fp:
def writeHeader(fp):
fp.write('[WITEC_TRUEMATCH_ASCII_HEADER]\n\r')
fp.write('Version = 2.0\n\r\n\r')
def writeWavenumbers(fp, wavenumbers):
fp.write('[XData]\n\r')
for line in wavenumbers:
fp.write(str(line) + '\n\r')
for specIndex in range(spectra.shape[1]):
def writeSpectrum(fp, intensities):
fp.write('\n\r')
fp.write('[SpectrumHeader]\n\r')
fp.write(f'Title = Spectrum {specIndex} \n\r')
......@@ -175,16 +173,35 @@ class AdvancedWITecSpectra(object):
fp.write(f'SpectrumSize = {specSize}\n\r')
fp.write('XDataKind = 1/cm\n\r\n\r')
fp.write('[SampleMetaData]\n\r')
# fp.write(f'double Integration_Time = )
fp.write(f'int Spectrum_Number = {specIndex}\n\r\n\r')
fp.write('[SpectrumData]\n\r')
spec = spectra[:, specIndex]
for line in spec:
for line in intensities:
fp.write(str(line) + '\n\r')
wavenumbers = allSpectra[:, 0]
spectra = allSpectra[:, 1:]
specSize = allSpectra.shape[0]
del allSpectra
numSpectra = spectra.shape[1]
numBatches = np.ceil(numSpectra/self.spectraBatchSize)
for batchIndex in range(numBatches):
outName = os.path.join(self.dsetpath, f'SpectraForTrueMatch {batchIndex}.txt')
if os.path.exists(outName):
os.remove(outName)
if batchIndex < numBatches-1:
specIndicesInBatch = np.arange(batchIndex*self.spectraBatchSize, (batchIndex+1)*self.spectraBatchSize)
else:
specIndicesInBatch = np.arange(batchIndex*self.spectraBatchSize, numSpectra)
with open(outName, 'w') as fp:
writeHeader(fp)
writeWavenumbers(fp, wavenumbers)
for specIndex in specIndicesInBatch:
spec = spectra[:, specIndex]
writeSpectrum(fp, spec)
def isNumber(self, string):
isNumber = False
......
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