Add Apply button to proposal selection
This commit is contained in:
parent
a73c34b06f
commit
a77a40618d
@ -1,11 +1,8 @@
|
|||||||
from pyzebra.anatric import *
|
from pyzebra.anatric import *
|
||||||
from pyzebra.ccl_io import *
|
from pyzebra.ccl_io import *
|
||||||
from pyzebra.h5 import *
|
|
||||||
from pyzebra.xtal import *
|
|
||||||
from pyzebra.ccl_process import *
|
from pyzebra.ccl_process import *
|
||||||
|
from pyzebra.h5 import *
|
||||||
ZEBRA_PROPOSALS_PATHS = [
|
from pyzebra.utils import *
|
||||||
f"/afs/psi.ch/project/sinqdata/{year}/zebra/" for year in (2016, 2017, 2018, 2020, 2021)
|
from pyzebra.xtal import *
|
||||||
]
|
|
||||||
|
|
||||||
__version__ = "0.5.0"
|
__version__ = "0.5.0"
|
||||||
|
@ -2,9 +2,10 @@ import logging
|
|||||||
import sys
|
import sys
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
|
|
||||||
|
import pyzebra
|
||||||
from bokeh.io import curdoc
|
from bokeh.io import curdoc
|
||||||
from bokeh.layouts import column, row
|
from bokeh.layouts import column, row
|
||||||
from bokeh.models import Panel, Tabs, TextAreaInput, TextInput
|
from bokeh.models import Button, Panel, Tabs, TextAreaInput, TextInput
|
||||||
|
|
||||||
import panel_ccl_integrate
|
import panel_ccl_integrate
|
||||||
import panel_hdf_anatric
|
import panel_hdf_anatric
|
||||||
@ -25,15 +26,32 @@ bokeh_logger = logging.getLogger("bokeh")
|
|||||||
bokeh_logger.addHandler(bokeh_handler)
|
bokeh_logger.addHandler(bokeh_handler)
|
||||||
bokeh_log_textareainput = TextAreaInput(title="server output:", height=150)
|
bokeh_log_textareainput = TextAreaInput(title="server output:", height=150)
|
||||||
|
|
||||||
proposal_textinput = TextInput(title="Proposal number:", width=210)
|
def proposal_textinput_callback(_attr, _old, _new):
|
||||||
|
apply_button.disabled = False
|
||||||
|
|
||||||
|
proposal_textinput = TextInput(title="Proposal number:", name="")
|
||||||
|
proposal_textinput.on_change("value_input", proposal_textinput_callback)
|
||||||
doc.proposal_textinput = proposal_textinput
|
doc.proposal_textinput = proposal_textinput
|
||||||
|
|
||||||
|
def apply_button_callback():
|
||||||
|
try:
|
||||||
|
proposal_path = pyzebra.find_proposal_path(proposal_textinput.value)
|
||||||
|
except ValueError as e:
|
||||||
|
print(e)
|
||||||
|
return
|
||||||
|
|
||||||
|
proposal_textinput.name = proposal_path
|
||||||
|
apply_button.disabled = True
|
||||||
|
|
||||||
|
apply_button = Button(label="Apply", button_type="primary")
|
||||||
|
apply_button.on_click(apply_button_callback)
|
||||||
|
|
||||||
# Final layout
|
# Final layout
|
||||||
doc.add_root(
|
doc.add_root(
|
||||||
column(
|
column(
|
||||||
Tabs(
|
Tabs(
|
||||||
tabs=[
|
tabs=[
|
||||||
Panel(child=proposal_textinput, title="user config"),
|
Panel(child=column(proposal_textinput, apply_button), title="user config"),
|
||||||
panel_hdf_viewer.create(),
|
panel_hdf_viewer.create(),
|
||||||
panel_hdf_anatric.create(),
|
panel_hdf_anatric.create(),
|
||||||
panel_ccl_integrate.create(),
|
panel_ccl_integrate.create(),
|
||||||
|
@ -76,21 +76,8 @@ def create():
|
|||||||
js_data = ColumnDataSource(data=dict(content=["", ""], fname=["", ""], ext=["", ""]))
|
js_data = ColumnDataSource(data=dict(content=["", ""], fname=["", ""], ext=["", ""]))
|
||||||
|
|
||||||
def file_select_update_for_proposal():
|
def file_select_update_for_proposal():
|
||||||
proposal = proposal_textinput.value.strip()
|
proposal_path = proposal_textinput.name
|
||||||
if not proposal:
|
if proposal_path:
|
||||||
file_select.options = []
|
|
||||||
file_open_button.disabled = True
|
|
||||||
file_append_button.disabled = True
|
|
||||||
return
|
|
||||||
|
|
||||||
for zebra_proposals_path in pyzebra.ZEBRA_PROPOSALS_PATHS:
|
|
||||||
proposal_path = os.path.join(zebra_proposals_path, proposal)
|
|
||||||
if os.path.isdir(proposal_path):
|
|
||||||
# found it
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
raise ValueError(f"Can not find data for proposal '{proposal}'.")
|
|
||||||
|
|
||||||
file_list = []
|
file_list = []
|
||||||
for file in os.listdir(proposal_path):
|
for file in os.listdir(proposal_path):
|
||||||
if file.endswith((".ccl", ".dat")):
|
if file.endswith((".ccl", ".dat")):
|
||||||
@ -98,6 +85,10 @@ def create():
|
|||||||
file_select.options = file_list
|
file_select.options = file_list
|
||||||
file_open_button.disabled = False
|
file_open_button.disabled = False
|
||||||
file_append_button.disabled = False
|
file_append_button.disabled = False
|
||||||
|
else:
|
||||||
|
file_select.options = []
|
||||||
|
file_open_button.disabled = True
|
||||||
|
file_append_button.disabled = True
|
||||||
|
|
||||||
doc.add_periodic_callback(file_select_update_for_proposal, 5000)
|
doc.add_periodic_callback(file_select_update_for_proposal, 5000)
|
||||||
|
|
||||||
@ -105,7 +96,7 @@ def create():
|
|||||||
file_select_update_for_proposal()
|
file_select_update_for_proposal()
|
||||||
|
|
||||||
proposal_textinput = doc.proposal_textinput
|
proposal_textinput = doc.proposal_textinput
|
||||||
proposal_textinput.on_change("value", proposal_textinput_callback)
|
proposal_textinput.on_change("name", proposal_textinput_callback)
|
||||||
|
|
||||||
def _init_datatable():
|
def _init_datatable():
|
||||||
scan_list = [s["idx"] for s in det_data]
|
scan_list = [s["idx"] for s in det_data]
|
||||||
|
@ -57,24 +57,15 @@ def create():
|
|||||||
|
|
||||||
def file_select_update():
|
def file_select_update():
|
||||||
if data_source.value == "proposal number":
|
if data_source.value == "proposal number":
|
||||||
proposal = proposal_textinput.value.strip()
|
proposal_path = proposal_textinput.name
|
||||||
if not proposal:
|
if proposal_path:
|
||||||
file_select.options = []
|
|
||||||
return
|
|
||||||
|
|
||||||
for zebra_proposals_path in pyzebra.ZEBRA_PROPOSALS_PATHS:
|
|
||||||
proposal_path = os.path.join(zebra_proposals_path, proposal)
|
|
||||||
if os.path.isdir(proposal_path):
|
|
||||||
# found it
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
raise ValueError(f"Can not find data for proposal '{proposal}'.")
|
|
||||||
|
|
||||||
file_list = []
|
file_list = []
|
||||||
for file in os.listdir(proposal_path):
|
for file in os.listdir(proposal_path):
|
||||||
if file.endswith(".hdf"):
|
if file.endswith(".hdf"):
|
||||||
file_list.append((os.path.join(proposal_path, file), file))
|
file_list.append((os.path.join(proposal_path, file), file))
|
||||||
file_select.options = file_list
|
file_select.options = file_list
|
||||||
|
else:
|
||||||
|
file_select.options = []
|
||||||
|
|
||||||
else: # "cami file"
|
else: # "cami file"
|
||||||
if not cami_meta:
|
if not cami_meta:
|
||||||
@ -101,7 +92,7 @@ def create():
|
|||||||
file_select_update()
|
file_select_update()
|
||||||
|
|
||||||
proposal_textinput = doc.proposal_textinput
|
proposal_textinput = doc.proposal_textinput
|
||||||
proposal_textinput.on_change("value", proposal_textinput_callback)
|
proposal_textinput.on_change("name", proposal_textinput_callback)
|
||||||
|
|
||||||
def upload_button_callback(_attr, _old, new):
|
def upload_button_callback(_attr, _old, new):
|
||||||
nonlocal cami_meta
|
nonlocal cami_meta
|
||||||
|
@ -60,24 +60,15 @@ def create():
|
|||||||
|
|
||||||
def file_select_update():
|
def file_select_update():
|
||||||
if data_source.value == "proposal number":
|
if data_source.value == "proposal number":
|
||||||
proposal = proposal_textinput.value.strip()
|
proposal_path = proposal_textinput.name
|
||||||
if not proposal:
|
if proposal_path:
|
||||||
file_select.options = []
|
|
||||||
return
|
|
||||||
|
|
||||||
for zebra_proposals_path in pyzebra.ZEBRA_PROPOSALS_PATHS:
|
|
||||||
proposal_path = os.path.join(zebra_proposals_path, proposal)
|
|
||||||
if os.path.isdir(proposal_path):
|
|
||||||
# found it
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
raise ValueError(f"Can not find data for proposal '{proposal}'.")
|
|
||||||
|
|
||||||
file_list = []
|
file_list = []
|
||||||
for file in os.listdir(proposal_path):
|
for file in os.listdir(proposal_path):
|
||||||
if file.endswith(".hdf"):
|
if file.endswith(".hdf"):
|
||||||
file_list.append((os.path.join(proposal_path, file), file))
|
file_list.append((os.path.join(proposal_path, file), file))
|
||||||
file_select.options = file_list
|
file_select.options = file_list
|
||||||
|
else:
|
||||||
|
file_select.options = []
|
||||||
|
|
||||||
else: # "cami file"
|
else: # "cami file"
|
||||||
if not cami_meta:
|
if not cami_meta:
|
||||||
@ -104,7 +95,7 @@ def create():
|
|||||||
file_select_update()
|
file_select_update()
|
||||||
|
|
||||||
proposal_textinput = doc.proposal_textinput
|
proposal_textinput = doc.proposal_textinput
|
||||||
proposal_textinput.on_change("value", proposal_textinput_callback)
|
proposal_textinput.on_change("name", proposal_textinput_callback)
|
||||||
|
|
||||||
def upload_button_callback(_attr, _old, new):
|
def upload_button_callback(_attr, _old, new):
|
||||||
nonlocal cami_meta
|
nonlocal cami_meta
|
||||||
|
@ -86,21 +86,8 @@ def create():
|
|||||||
js_data = ColumnDataSource(data=dict(content=[""], fname=[""], ext=[""]))
|
js_data = ColumnDataSource(data=dict(content=[""], fname=[""], ext=[""]))
|
||||||
|
|
||||||
def file_select_update_for_proposal():
|
def file_select_update_for_proposal():
|
||||||
proposal = proposal_textinput.value.strip()
|
proposal_path = proposal_textinput.name
|
||||||
if not proposal:
|
if proposal_path:
|
||||||
file_select.options = []
|
|
||||||
file_open_button.disabled = True
|
|
||||||
file_append_button.disabled = True
|
|
||||||
return
|
|
||||||
|
|
||||||
for zebra_proposals_path in pyzebra.ZEBRA_PROPOSALS_PATHS:
|
|
||||||
proposal_path = os.path.join(zebra_proposals_path, proposal)
|
|
||||||
if os.path.isdir(proposal_path):
|
|
||||||
# found it
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
raise ValueError(f"Can not find data for proposal '{proposal}'.")
|
|
||||||
|
|
||||||
file_list = []
|
file_list = []
|
||||||
for file in os.listdir(proposal_path):
|
for file in os.listdir(proposal_path):
|
||||||
if file.endswith((".ccl", ".dat")):
|
if file.endswith((".ccl", ".dat")):
|
||||||
@ -108,6 +95,10 @@ def create():
|
|||||||
file_select.options = file_list
|
file_select.options = file_list
|
||||||
file_open_button.disabled = False
|
file_open_button.disabled = False
|
||||||
file_append_button.disabled = False
|
file_append_button.disabled = False
|
||||||
|
else:
|
||||||
|
file_select.options = []
|
||||||
|
file_open_button.disabled = True
|
||||||
|
file_append_button.disabled = True
|
||||||
|
|
||||||
doc.add_periodic_callback(file_select_update_for_proposal, 5000)
|
doc.add_periodic_callback(file_select_update_for_proposal, 5000)
|
||||||
|
|
||||||
@ -115,7 +106,7 @@ def create():
|
|||||||
file_select_update_for_proposal()
|
file_select_update_for_proposal()
|
||||||
|
|
||||||
proposal_textinput = doc.proposal_textinput
|
proposal_textinput = doc.proposal_textinput
|
||||||
proposal_textinput.on_change("value", proposal_textinput_callback)
|
proposal_textinput.on_change("name", proposal_textinput_callback)
|
||||||
|
|
||||||
def _init_datatable():
|
def _init_datatable():
|
||||||
scan_list = [s["idx"] for s in det_data]
|
scan_list = [s["idx"] for s in det_data]
|
||||||
|
20
pyzebra/utils.py
Normal file
20
pyzebra/utils.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
ZEBRA_PROPOSALS_PATHS = [
|
||||||
|
f"/afs/psi.ch/project/sinqdata/{year}/zebra/" for year in (2016, 2017, 2018, 2020, 2021)
|
||||||
|
]
|
||||||
|
|
||||||
|
def find_proposal_path(proposal):
|
||||||
|
proposal = proposal.strip()
|
||||||
|
if proposal:
|
||||||
|
for zebra_proposals_path in ZEBRA_PROPOSALS_PATHS:
|
||||||
|
proposal_path = os.path.join(zebra_proposals_path, proposal)
|
||||||
|
if os.path.isdir(proposal_path):
|
||||||
|
# found it
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
raise ValueError(f"Can not find data for proposal '{proposal}'.")
|
||||||
|
else:
|
||||||
|
proposal_path = ""
|
||||||
|
|
||||||
|
return proposal_path
|
Loading…
x
Reference in New Issue
Block a user