diff --git a/pyzebra/app/panel_hdf_param_study.py b/pyzebra/app/panel_hdf_param_study.py index 502a680..960663a 100644 --- a/pyzebra/app/panel_hdf_param_study.py +++ b/pyzebra/app/panel_hdf_param_study.py @@ -141,22 +141,29 @@ def create(): scan_table_source.data.update(frame=frame, x_pos=x_pos, y_pos=y_pos) + def _file_open(): + new_data = [] + for f_name in file_select.value: + try: + new_data.append(pyzebra.read_detector_data(f_name)) + except KeyError: + print("Could not read data from the file.") + return + + zebra_data.extend(new_data) + + _init_datatable() + def file_open_button_callback(): nonlocal zebra_data zebra_data = [] - for f_name in file_select.value: - zebra_data.append(pyzebra.read_detector_data(f_name)) - - _init_datatable() + _file_open() file_open_button = Button(label="Open New", width=100) file_open_button.on_click(file_open_button_callback) def file_append_button_callback(): - for f_name in file_select.value: - zebra_data.append(pyzebra.read_detector_data(f_name)) - - _init_datatable() + _file_open() file_append_button = Button(label="Append", width=100) file_append_button.on_click(file_append_button_callback) diff --git a/pyzebra/app/panel_hdf_viewer.py b/pyzebra/app/panel_hdf_viewer.py index 6483a79..4aec069 100644 --- a/pyzebra/app/panel_hdf_viewer.py +++ b/pyzebra/app/panel_hdf_viewer.py @@ -107,9 +107,13 @@ def create(): upload_cami_button = FileInput(accept=".cami", width=200) upload_cami_button.on_change("value", upload_cami_button_callback) - def _open_file(file, cami_meta): + def _file_open(file, cami_meta): nonlocal det_data - det_data = pyzebra.read_detector_data(file, cami_meta) + try: + det_data = pyzebra.read_detector_data(file, cami_meta) + except KeyError: + print("Could not read data from the file.") + return index_spinner.value = 0 index_spinner.high = det_data["data"].shape[0] - 1 @@ -125,7 +129,7 @@ def create(): update_overview_plot() def upload_hdf_button_callback(_attr, _old, new): - _open_file(io.BytesIO(base64.b64decode(new)), None) + _file_open(io.BytesIO(base64.b64decode(new)), None) upload_hdf_div = Div(text="or upload .hdf file:", margin=(5, 5, 0, 5)) upload_hdf_button = FileInput(accept=".hdf", width=200) @@ -136,9 +140,9 @@ def create(): return if data_source.value == "proposal number": - _open_file(file_select.value[0], None) + _file_open(file_select.value[0], None) else: - _open_file(file_select.value[0], cami_meta) + _file_open(file_select.value[0], cami_meta) file_open_button = Button(label="Open New", width=100) file_open_button.on_click(file_open_button_callback)