Skip to content

Commit 3671db7

Browse files
committed
Enhanced starting/stopping procedure.
1 parent 734b512 commit 3671db7

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

application.py

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ class Application(tk.Frame):
182182

183183
BACKUP_CONFIG_FILE_NAME = "temporary_cfg.ctcf"
184184

185+
WHITE = "WHITE"
186+
BLACK = "BLACK"
187+
185188
def __init__(self, master=None, P_bnc=None):
186189

187190
super().__init__(master)
@@ -324,7 +327,16 @@ def _rawLoadConfig(self, file):
324327
try:
325328
self._bnc.load_from_pick(tp_config_tup[0])
326329
for key in tp_config_tup[1].keys():
327-
self.config_dict[key].set(tp_config_tup[1][key])
330+
if isinstance(tp_config_tup[1][key], str):
331+
self.config_dict[key].set(tp_config_tup[1][key])
332+
elif isinstance(tp_config_tup[1][key], spectro.Spectrum):
333+
self.config_dict[key] = tp_config_tup[1][key]
334+
if key == self.WHITE:
335+
self.liveDisplay.putSpectrasAndUpdate(
336+
2, self.config_dict[key])
337+
elif key == self.BLACK:
338+
self.liveDisplay.putSpectrasAndUpdate(
339+
1, self.config_dict[key])
328340
except Exception as e:
329341
logger.critical("Error while loading file :", exc_info=e)
330342
finally:
@@ -334,7 +346,6 @@ def get_saving_dict(self):
334346
tp_config_dict = dict([])
335347
for key in self.config_dict.keys():
336348
tp_config_dict[key] = self.config_dict[key].get()
337-
338349
return self._bnc.save_to_pickle(), tp_config_dict
339350

340351
def _rawSaveConfig(self, file):
@@ -492,9 +503,9 @@ def set_black(self):
492503
p_N_c))
493504
self.avh.waitAll()
494505
self._bnc.stop()
495-
self.black_spectra = self.avh.getScopes()
506+
self.config_dict[self.BLACK] = self.avh.getScopes()
496507
experiment_logger.info("Black set.")
497-
self.liveDisplay.putSpectrasAndUpdate(1, self.black_spectra)
508+
self.liveDisplay.putSpectrasAndUpdate(1, self.config_dict[self.BLACK])
498509
self.avh.stopAll()
499510
self.avh.release()
500511
self.pause_live_display.clear()
@@ -531,9 +542,9 @@ def set_white(self):
531542
p_N_c))
532543
self.avh.waitAll()
533544
self._bnc.stop()
534-
self.white_spectra = self.avh.getScopes()
545+
self.config_dict[self.WHITE] = self.avh.getScopes()
535546
experiment_logger.info("White set.")
536-
self.liveDisplay.putSpectrasAndUpdate(2, self.white_spectra)
547+
self.liveDisplay.putSpectrasAndUpdate(2, self.config_dict[self.WHITE])
537548
self.avh.stopAll()
538549
self.avh.release()
539550
self.pause_live_display.clear()
@@ -573,20 +584,24 @@ def experiment(self):
573584
totalAbsorbanceSpectras = []
574585

575586
try:
576-
self.black_spectra
587+
self.config_dict[self.BLACK]
577588
except Exception:
578589
experiment_logger.warning("Black not set, aborting.")
579590
abort = True
580591
self.experiment_on = False
581592

582593
try:
583-
self.white_spectra
594+
self.config_dict[self.WHITE]
584595
except Exception:
585596
experiment_logger.warning("White not set, aborting.")
586597
self.experiment_on = False
587598
abort = True
588599

589-
correction_spectrum = self.get_selected_absorbance(self.white_spectra)
600+
if self.referenceChannel.get() != "":
601+
correction_spectrum = self.get_selected_absorbance(
602+
self.config_dict[self.WHITE])
603+
else:
604+
abort = True
590605

591606
experiment_logger.info("Starting observation.")
592607
if not abort and tMsg.\
@@ -656,8 +671,9 @@ def experiment(self):
656671
experiment_logger.warning("Experiment aborted.")
657672
abort = True
658673
self.experiment_on = False
659-
self.treatSpectras([self.black_spectra, self.white_spectra]
660-
+ totalSpectras)
674+
self.treatSpectras(
675+
[self.config_dict[self.BLACK], self.config_dict[self.WHITE]]
676+
+ totalSpectras)
661677
self.avh.release()
662678
self.pause_live_display.clear()
663679

0 commit comments

Comments
 (0)