diff --git a/pyzebra/app/panel_hdf_param_study.py b/pyzebra/app/panel_hdf_param_study.py index d9aedf5..3286381 100644 --- a/pyzebra/app/panel_hdf_param_study.py +++ b/pyzebra/app/panel_hdf_param_study.py @@ -1,5 +1,3 @@ -import base64 -import io import os import numpy as np @@ -12,8 +10,6 @@ from bokeh.models import ( CheckboxGroup, ColumnDataSource, DataTable, - Div, - FileInput, LinearColorMapper, MultiSelect, NumberEditor, @@ -42,40 +38,19 @@ def create(): doc = curdoc() log = doc.logger dataset = [] - cami_meta = {} num_formatter = NumberFormatter(format="0.00", nan_format="") def file_select_update(): - if data_source.value == "proposal number": - proposal_path = proposal_textinput.name - if proposal_path: - file_list = [] - for file in os.listdir(proposal_path): - if file.endswith(".hdf"): - file_list.append((os.path.join(proposal_path, file), file)) - file_select.options = file_list - else: - file_select.options = [] - - else: # "cami file" - if not cami_meta: - file_select.options = [] - return - - file_list = cami_meta["filelist"] - file_select.options = [(entry, os.path.basename(entry)) for entry in file_list] - - def data_source_callback(_attr, _old, _new): - file_select_update() - - data_source = Select( - title="Data Source:", - value="proposal number", - options=["proposal number", "cami file"], - width=210, - ) - data_source.on_change("value", data_source_callback) + proposal_path = proposal_textinput.name + if proposal_path: + file_list = [] + for file in os.listdir(proposal_path): + if file.endswith(".hdf"): + file_list.append((os.path.join(proposal_path, file), file)) + file_select.options = file_list + else: + file_select.options = [] doc.add_periodic_callback(file_select_update, 5000) @@ -85,17 +60,6 @@ def create(): proposal_textinput = doc.proposal_textinput proposal_textinput.on_change("name", proposal_textinput_callback) - def upload_button_callback(_attr, _old, new): - nonlocal cami_meta - with io.StringIO(base64.b64decode(new).decode()) as file: - cami_meta = pyzebra.parse_h5meta(file) - data_source.value = "cami file" - file_select_update() - - upload_div = Div(text="or upload .cami file:", margin=(5, 5, 0, 5)) - upload_button = FileInput(accept=".cami", width=200) - upload_button.on_change("value", upload_button_callback) - file_select = MultiSelect(title="Available .hdf files:", width=210, height=320) def _init_datatable(): @@ -502,13 +466,7 @@ def create(): ) # Final layout - import_layout = column( - data_source, - upload_div, - upload_button, - file_select, - row(file_open_button, file_append_button), - ) + import_layout = column(file_select, row(file_open_button, file_append_button)) scan_layout = column(scan_table, row(param_select, metadata_table)) diff --git a/pyzebra/app/panel_hdf_viewer.py b/pyzebra/app/panel_hdf_viewer.py index 0eb41b0..cc49b36 100644 --- a/pyzebra/app/panel_hdf_viewer.py +++ b/pyzebra/app/panel_hdf_viewer.py @@ -49,40 +49,19 @@ def create(): doc = curdoc() log = doc.logger dataset = [] - cami_meta = {} num_formatter = NumberFormatter(format="0.00", nan_format="") def file_select_update(): - if data_source.value == "proposal number": - proposal_path = proposal_textinput.name - if proposal_path: - file_list = [] - for file in os.listdir(proposal_path): - if file.endswith(".hdf"): - file_list.append((os.path.join(proposal_path, file), file)) - file_select.options = file_list - else: - file_select.options = [] - - else: # "cami file" - if not cami_meta: - file_select.options = [] - return - - file_list = cami_meta["filelist"] - file_select.options = [(entry, os.path.basename(entry)) for entry in file_list] - - def data_source_callback(_attr, _old, _new): - file_select_update() - - data_source = Select( - title="Data Source:", - value="proposal number", - options=["proposal number", "cami file"], - width=210, - ) - data_source.on_change("value", data_source_callback) + proposal_path = proposal_textinput.name + if proposal_path: + file_list = [] + for file in os.listdir(proposal_path): + if file.endswith(".hdf"): + file_list.append((os.path.join(proposal_path, file), file)) + file_select.options = file_list + else: + file_select.options = [] doc.add_periodic_callback(file_select_update, 5000) @@ -92,21 +71,10 @@ def create(): proposal_textinput = doc.proposal_textinput proposal_textinput.on_change("name", proposal_textinput_callback) - def upload_cami_button_callback(_attr, _old, new): - nonlocal cami_meta - with io.StringIO(base64.b64decode(new).decode()) as file: - cami_meta = pyzebra.parse_h5meta(file) - data_source.value = "cami file" - file_select_update() - - upload_cami_div = Div(text="or upload .cami file:", margin=(5, 5, 0, 5)) - upload_cami_button = FileInput(accept=".cami", width=200) - upload_cami_button.on_change("value", upload_cami_button_callback) - def upload_hdf_button_callback(_attr, _old, new): nonlocal dataset try: - scan = pyzebra.read_detector_data(io.BytesIO(base64.b64decode(new)), None) + scan = pyzebra.read_detector_data(io.BytesIO(base64.b64decode(new))) except Exception as e: log.exception(e) return @@ -130,18 +98,17 @@ def create(): _init_datatable() - upload_hdf_div = Div(text="or upload .hdf file:", margin=(5, 5, 0, 5)) + upload_hdf_div = Div(text="Upload .hdf file:", margin=(5, 5, 0, 5)) upload_hdf_button = FileInput(accept=".hdf", width=200) upload_hdf_button.on_change("value", upload_hdf_button_callback) def file_open_button_callback(): nonlocal dataset new_data = [] - cm = cami_meta if data_source.value == "cami file" else None for f_path in file_select.value: f_name = os.path.basename(f_path) try: - file_data = [pyzebra.read_detector_data(f_path, cm)] + file_data = [pyzebra.read_detector_data(f_path)] except Exception as e: log.exception(e) continue @@ -165,7 +132,7 @@ def create(): for f_path in file_select.value: f_name = os.path.basename(f_path) try: - file_data = [pyzebra.read_detector_data(f_path, None)] + file_data = [pyzebra.read_detector_data(f_path)] except Exception as e: log.exception(e) continue @@ -900,13 +867,7 @@ def create(): ) import_layout = column( - data_source, - upload_cami_div, - upload_cami_button, - upload_hdf_div, - upload_hdf_button, - file_select, - row(file_open_button, file_append_button), + upload_hdf_div, upload_hdf_button, file_select, row(file_open_button, file_append_button) ) layout_image = column(grid([[proj_v, None], [plot, proj_h]])) diff --git a/pyzebra/h5.py b/pyzebra/h5.py index a8f0748..19c20a0 100644 --- a/pyzebra/h5.py +++ b/pyzebra/h5.py @@ -59,7 +59,7 @@ def parse_h5meta(file): return content -def read_detector_data(filepath, cami_meta=None): +def read_detector_data(filepath): """Read detector data and angles from an h5 file. Args: @@ -87,11 +87,6 @@ def read_detector_data(filepath, cami_meta=None): else: scan["zebra_mode"] = "nb" - # overwrite zebra_mode from cami - if cami_meta is not None: - if "zebra_mode" in cami_meta: - scan["zebra_mode"] = cami_meta["zebra_mode"][0] - if "/entry1/control/Monitor" in h5f: scan["monitor"] = h5f["/entry1/control/Monitor"][0] else: # old path @@ -163,24 +158,6 @@ def read_detector_data(filepath, cami_meta=None): # this is not a great solution, but makes it safe to use the array in bokeh scan["temp"] = np.where(np.isnan(scan["temp"]), None, scan["temp"]) - # overwrite metadata from .cami - if cami_meta is not None: - if "crystal" in cami_meta: - cami_meta_crystal = cami_meta["crystal"] - if "name" in cami_meta_crystal: - scan["name"] = cami_meta_crystal["name"] - if "UB" in cami_meta_crystal: - scan["ub"] = cami_meta_crystal["UB"] - if "cell" in cami_meta_crystal: - scan["cell"] = cami_meta_crystal["cell"] - if "lambda" in cami_meta_crystal: - scan["wave"] = cami_meta_crystal["lambda"] - - if "detector parameters" in cami_meta: - cami_meta_detparam = cami_meta["detector parameters"] - if "dist2" in cami_meta_detparam: - scan["ddist"] = cami_meta_detparam["dist2"] - return scan