diff --git a/mtor/gui.py b/mtor/gui.py index 5ee0901..d1784f0 100644 --- a/mtor/gui.py +++ b/mtor/gui.py @@ -217,30 +217,37 @@ class MtorImageAnalysis(QWidget): def run_gui(): - app = QApplication(sys.argv) - mia = MtorImageAnalysis() - app.exec_() - - if mia.analysis_parameters is not None: - pw = prescan_workflow(**mia.analysis_parameters) - iw = image_workflow(pw.parameters) - dw = data_workflow(iw.data, iw.parameters) - fw = postprocessing_workflow(dw.data, dw.parameters) - pdf_path = fw.parameters.data_dir / "report.pdf" - if sys.platform.startswith("win"): - os.startfile(str(pdf_path)) - else: - if sys.platform.startswith("darwin"): - cmd = ["open", str(pdf_path)] + import traceback + + try: + + app = QApplication(sys.argv) + mia = MtorImageAnalysis() + app.exec_() + + if mia.analysis_parameters is not None: + pw = prescan_workflow(**mia.analysis_parameters) + iw = image_workflow(pw.parameters) + dw = data_workflow(iw.data, iw.parameters) + fw = postprocessing_workflow(dw.data, dw.parameters) + pdf_path = fw.parameters.data_dir / "report.pdf" + if sys.platform.startswith("win"): + os.startfile(str(pdf_path)) else: - cmd = ["xdg-open", str(pdf_path)] - Popen( - cmd, - shell=False, - stdin=None, - stdout=None, - stderr=None, - close_fds=True, - ) - - sys.exit() + if sys.platform.startswith("darwin"): + cmd = ["open", str(pdf_path)] + else: + cmd = ["xdg-open", str(pdf_path)] + Popen( + cmd, + shell=False, + stdin=None, + stdout=None, + stderr=None, + close_fds=True, + ) + except Exception as err: + traceback.print_exc() + input("Press enter to close this window") + finally: + sys.exit() diff --git a/mtor/imageproc.py b/mtor/imageproc.py index 511c05f..869f70e 100644 --- a/mtor/imageproc.py +++ b/mtor/imageproc.py @@ -12,7 +12,7 @@ from .commons import ( def open_as_array(tif_image): with tif_image.path.open("rb") as filehandle: - image = Image.open(filehandle) + image = Image.open(filehandle).convert(mode="I") image_array = numpy.array(image, dtype=numpy.int32) return TifArray( path=tif_image.path, frame=tif_image.frame, data=image_array diff --git a/mtor/prescan.py b/mtor/prescan.py index 149b27a..6a9d7d9 100644 --- a/mtor/prescan.py +++ b/mtor/prescan.py @@ -11,7 +11,7 @@ def scan_tifs(parameters): for tif in tqdm(parameters.tif_list): with tif.path.open("rb") as filehandle: - image = Image.open(filehandle) + image = Image.open(filehandle).convert(mode="I") mi, ma = image.getextrema() lowest = min(lowest, mi) highest = max(highest, ma)