Compare commits
80 Commits
Author | SHA1 | Date | |
---|---|---|---|
5c4362d984 | |||
8d065b85a4 | |||
c86466b470 | |||
b8968192ca | |||
4745f0f401 | |||
9f6e7230fa | |||
089a0cf5ac | |||
639dc070c3 | |||
fec463398d | |||
b6d7a52b06 | |||
d6e599d4f9 | |||
d6b27fb33a | |||
bae15ee2ef | |||
c2bd6c25f5 | |||
cf6527af13 | |||
57e503fc3d | |||
c10efeb9cc | |||
137f20cc20 | |||
531463a637 | |||
e3368c1817 | |||
313bd8bc62 | |||
fe61d3c4cb | |||
f6d9f63863 | |||
620f32446a | |||
4b4d5c16ce | |||
91b9e01441 | |||
18ea894f35 | |||
9141ac49c7 | |||
2adbcc6bcd | |||
b39d970960 | |||
b11004bf0f | |||
6c2e221595 | |||
502a4b8096 | |||
3fe4fca96a | |||
a3e3e6768f | |||
0b6a58e160 | |||
09d22e7674 | |||
90387174e5 | |||
e99edbaf72 | |||
a2fceffc1b | |||
415d68b4dc | |||
00ff4117ea | |||
67853b8db4 | |||
60787bccb7 | |||
880d86d750 | |||
7a88e5e254 | |||
20f2a8ada4 | |||
42c092fc14 | |||
8153db9f67 | |||
62c969d6ad | |||
085620abae | |||
9ebe290966 | |||
c9cd96c521 | |||
d745cda4a5 | |||
1b5f70afa0 | |||
a034065a09 | |||
2a60c86b48 | |||
ccc075975f | |||
4982b05de0 | |||
2b0c392a3e | |||
099842b2bd | |||
bd3efd698a | |||
24f083e585 | |||
f43488af34 | |||
1b90d53466 | |||
c1b3a28351 | |||
5b45685257 | |||
e7b28a4e75 | |||
83a7d607a5 | |||
5eedd14b3f | |||
3db7dca7ba | |||
b2d1a0be02 | |||
69d22dd067 | |||
242da76c59 | |||
0c812a5dd5 | |||
4cfcb3d396 | |||
8018783eb5 | |||
fdb1609a41 | |||
e7dda3cda8 | |||
f788d74f15 |
1
.github/workflows/deployment.yaml
vendored
1
.github/workflows/deployment.yaml
vendored
@ -16,6 +16,7 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
$CONDA/bin/conda install --quiet --yes conda-build anaconda-client
|
$CONDA/bin/conda install --quiet --yes conda-build anaconda-client
|
||||||
$CONDA/bin/conda config --append channels conda-forge
|
$CONDA/bin/conda config --append channels conda-forge
|
||||||
|
$CONDA/bin/conda config --set channel_priority strict
|
||||||
$CONDA/bin/conda config --set anaconda_upload yes
|
$CONDA/bin/conda config --set anaconda_upload yes
|
||||||
|
|
||||||
- name: Build and upload
|
- name: Build and upload
|
||||||
|
@ -23,10 +23,8 @@ requirements:
|
|||||||
- scipy
|
- scipy
|
||||||
- h5py
|
- h5py
|
||||||
- bokeh =2.3
|
- bokeh =2.3
|
||||||
- matplotlib
|
|
||||||
- numba
|
- numba
|
||||||
- lmfit
|
- lmfit
|
||||||
- uncertainties
|
|
||||||
|
|
||||||
|
|
||||||
about:
|
about:
|
||||||
|
@ -4,4 +4,8 @@ from pyzebra.h5 import *
|
|||||||
from pyzebra.xtal import *
|
from pyzebra.xtal import *
|
||||||
from pyzebra.ccl_process import *
|
from pyzebra.ccl_process import *
|
||||||
|
|
||||||
__version__ = "0.3.0"
|
ZEBRA_PROPOSALS_PATHS = [
|
||||||
|
f"/afs/psi.ch/project/sinqdata/{year}/zebra/" for year in (2016, 2017, 2018, 2020, 2021)
|
||||||
|
]
|
||||||
|
|
||||||
|
__version__ = "0.5.0"
|
||||||
|
@ -7,6 +7,7 @@ DATA_FACTORY_IMPLEMENTATION = [
|
|||||||
"morph",
|
"morph",
|
||||||
"d10",
|
"d10",
|
||||||
]
|
]
|
||||||
|
|
||||||
REFLECTION_PRINTER_FORMATS = [
|
REFLECTION_PRINTER_FORMATS = [
|
||||||
"rafin",
|
"rafin",
|
||||||
"rafinf",
|
"rafinf",
|
||||||
@ -20,11 +21,21 @@ REFLECTION_PRINTER_FORMATS = [
|
|||||||
"oksana",
|
"oksana",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
ANATRIC_PATH = "/afs/psi.ch/project/sinq/rhel7/bin/anatric"
|
||||||
ALGORITHMS = ["adaptivemaxcog", "adaptivedynamic"]
|
ALGORITHMS = ["adaptivemaxcog", "adaptivedynamic"]
|
||||||
|
|
||||||
|
|
||||||
def anatric(config_file, anatric_path="/afs/psi.ch/project/sinq/rhel7/bin/anatric"):
|
def anatric(config_file, anatric_path=ANATRIC_PATH, cwd=None):
|
||||||
subprocess.run([anatric_path, config_file], check=True)
|
comp_proc = subprocess.run(
|
||||||
|
[anatric_path, config_file],
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.STDOUT,
|
||||||
|
cwd=cwd,
|
||||||
|
check=True,
|
||||||
|
text=True,
|
||||||
|
)
|
||||||
|
print(" ".join(comp_proc.args))
|
||||||
|
print(comp_proc.stdout)
|
||||||
|
|
||||||
|
|
||||||
class AnatricConfig:
|
class AnatricConfig:
|
||||||
@ -51,10 +62,13 @@ class AnatricConfig:
|
|||||||
def save_as(self, filename):
|
def save_as(self, filename):
|
||||||
self._tree.write(filename)
|
self._tree.write(filename)
|
||||||
|
|
||||||
|
def tostring(self):
|
||||||
|
return ET.tostring(self._tree.getroot(), encoding="unicode")
|
||||||
|
|
||||||
def _get_attr(self, name, tag, attr):
|
def _get_attr(self, name, tag, attr):
|
||||||
elem = self._tree.find(name).find(tag)
|
elem = self._tree.find(name).find(tag)
|
||||||
if elem is None:
|
if elem is None:
|
||||||
return None
|
return ""
|
||||||
return elem.attrib[attr]
|
return elem.attrib[attr]
|
||||||
|
|
||||||
def _set_attr(self, name, tag, attr, value):
|
def _set_attr(self, name, tag, attr, value):
|
||||||
@ -217,7 +231,7 @@ class AnatricConfig:
|
|||||||
elem = self._tree.find("crystal").find("UB")
|
elem = self._tree.find("crystal").find("UB")
|
||||||
if elem is not None:
|
if elem is not None:
|
||||||
return elem.text
|
return elem.text
|
||||||
return None
|
return ""
|
||||||
|
|
||||||
@crystal_UB.setter
|
@crystal_UB.setter
|
||||||
def crystal_UB(self, value):
|
def crystal_UB(self, value):
|
||||||
@ -236,12 +250,37 @@ class AnatricConfig:
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def dataFactory_dist1(self):
|
def dataFactory_dist1(self):
|
||||||
return self._tree.find("DataFactory").find("dist1").attrib["value"]
|
elem = self._tree.find("DataFactory").find("dist1")
|
||||||
|
if elem is not None:
|
||||||
|
return elem.attrib["value"]
|
||||||
|
return ""
|
||||||
|
|
||||||
@dataFactory_dist1.setter
|
@dataFactory_dist1.setter
|
||||||
def dataFactory_dist1(self, value):
|
def dataFactory_dist1(self, value):
|
||||||
self._tree.find("DataFactory").find("dist1").attrib["value"] = value
|
self._tree.find("DataFactory").find("dist1").attrib["value"] = value
|
||||||
|
|
||||||
|
@property
|
||||||
|
def dataFactory_dist2(self):
|
||||||
|
elem = self._tree.find("DataFactory").find("dist2")
|
||||||
|
if elem is not None:
|
||||||
|
return elem.attrib["value"]
|
||||||
|
return ""
|
||||||
|
|
||||||
|
@dataFactory_dist2.setter
|
||||||
|
def dataFactory_dist2(self, value):
|
||||||
|
self._tree.find("DataFactory").find("dist2").attrib["value"] = value
|
||||||
|
|
||||||
|
@property
|
||||||
|
def dataFactory_dist3(self):
|
||||||
|
elem = self._tree.find("DataFactory").find("dist3")
|
||||||
|
if elem is not None:
|
||||||
|
return elem.attrib["value"]
|
||||||
|
return ""
|
||||||
|
|
||||||
|
@dataFactory_dist3.setter
|
||||||
|
def dataFactory_dist3(self, value):
|
||||||
|
self._tree.find("DataFactory").find("dist3").attrib["value"] = value
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def reflectionPrinter_format(self):
|
def reflectionPrinter_format(self):
|
||||||
return self._tree.find("ReflectionPrinter").attrib["format"]
|
return self._tree.find("ReflectionPrinter").attrib["format"]
|
||||||
@ -253,6 +292,14 @@ class AnatricConfig:
|
|||||||
|
|
||||||
self._tree.find("ReflectionPrinter").attrib["format"] = value
|
self._tree.find("ReflectionPrinter").attrib["format"] = value
|
||||||
|
|
||||||
|
@property
|
||||||
|
def reflectionPrinter_file(self):
|
||||||
|
return self._tree.find("ReflectionPrinter").attrib["file"]
|
||||||
|
|
||||||
|
@reflectionPrinter_file.setter
|
||||||
|
def reflectionPrinter_file(self, value):
|
||||||
|
self._tree.find("ReflectionPrinter").attrib["file"] = value
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def algorithm(self):
|
def algorithm(self):
|
||||||
return self._tree.find("Algorithm").attrib["implementation"]
|
return self._tree.find("Algorithm").attrib["implementation"]
|
||||||
@ -269,7 +316,7 @@ class AnatricConfig:
|
|||||||
def _get_alg_attr(self, alg, tag, attr):
|
def _get_alg_attr(self, alg, tag, attr):
|
||||||
param_elem = self._alg_elems[alg].find(tag)
|
param_elem = self._alg_elems[alg].find(tag)
|
||||||
if param_elem is None:
|
if param_elem is None:
|
||||||
return None
|
return ""
|
||||||
return param_elem.attrib[attr]
|
return param_elem.attrib[attr]
|
||||||
|
|
||||||
def _set_alg_attr(self, alg, tag, attr, value):
|
def _set_alg_attr(self, alg, tag, attr, value):
|
||||||
|
@ -8,6 +8,7 @@ from bokeh.models import Tabs, TextAreaInput
|
|||||||
|
|
||||||
import panel_ccl_integrate
|
import panel_ccl_integrate
|
||||||
import panel_hdf_anatric
|
import panel_hdf_anatric
|
||||||
|
import panel_hdf_param_study
|
||||||
import panel_hdf_viewer
|
import panel_hdf_viewer
|
||||||
import panel_param_study
|
import panel_param_study
|
||||||
import panel_spind
|
import panel_spind
|
||||||
@ -26,15 +27,18 @@ bokeh_logger.addHandler(bokeh_handler)
|
|||||||
bokeh_log_textareainput = TextAreaInput(title="server output:", height=150)
|
bokeh_log_textareainput = TextAreaInput(title="server output:", height=150)
|
||||||
|
|
||||||
# Final layout
|
# Final layout
|
||||||
tab_hdf_viewer = panel_hdf_viewer.create()
|
|
||||||
tab_hdf_anatric = panel_hdf_anatric.create()
|
|
||||||
tab_ccl_integrate = panel_ccl_integrate.create()
|
|
||||||
tab_param_study = panel_param_study.create()
|
|
||||||
tab_spind = panel_spind.create()
|
|
||||||
|
|
||||||
doc.add_root(
|
doc.add_root(
|
||||||
column(
|
column(
|
||||||
Tabs(tabs=[tab_hdf_viewer, tab_hdf_anatric, tab_ccl_integrate, tab_param_study, tab_spind]),
|
Tabs(
|
||||||
|
tabs=[
|
||||||
|
panel_hdf_viewer.create(),
|
||||||
|
panel_hdf_anatric.create(),
|
||||||
|
panel_ccl_integrate.create(),
|
||||||
|
panel_param_study.create(),
|
||||||
|
panel_hdf_param_study.create(),
|
||||||
|
panel_spind.create(),
|
||||||
|
]
|
||||||
|
),
|
||||||
row(stdout_textareainput, bokeh_log_textareainput, sizing_mode="scale_both"),
|
row(stdout_textareainput, bokeh_log_textareainput, sizing_mode="scale_both"),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -6,6 +6,7 @@ from bokeh.application.application import Application
|
|||||||
from bokeh.application.handlers import ScriptHandler
|
from bokeh.application.handlers import ScriptHandler
|
||||||
from bokeh.server.server import Server
|
from bokeh.server.server import Server
|
||||||
|
|
||||||
|
from pyzebra.anatric import ANATRIC_PATH
|
||||||
from pyzebra.app.handler import PyzebraHandler
|
from pyzebra.app.handler import PyzebraHandler
|
||||||
|
|
||||||
logging.basicConfig(format="%(asctime)s %(message)s", level=logging.INFO)
|
logging.basicConfig(format="%(asctime)s %(message)s", level=logging.INFO)
|
||||||
@ -38,10 +39,11 @@ def main():
|
|||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--anatric-path",
|
"--anatric-path", type=str, default=ANATRIC_PATH, help="path to anatric executable",
|
||||||
type=str,
|
)
|
||||||
default=None,
|
|
||||||
help="path to anatric executable",
|
parser.add_argument(
|
||||||
|
"--spind-path", type=str, default=None, help="path to spind scripts folder",
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
@ -55,7 +57,7 @@ def main():
|
|||||||
|
|
||||||
logger.info(app_path)
|
logger.info(app_path)
|
||||||
|
|
||||||
pyzebra_handler = PyzebraHandler(args.anatric_path)
|
pyzebra_handler = PyzebraHandler(args.anatric_path, args.spind_path)
|
||||||
handler = ScriptHandler(filename=app_path, argv=args.args)
|
handler = ScriptHandler(filename=app_path, argv=args.args)
|
||||||
server = Server(
|
server = Server(
|
||||||
{"/": Application(pyzebra_handler, handler)},
|
{"/": Application(pyzebra_handler, handler)},
|
||||||
|
@ -5,7 +5,7 @@ class PyzebraHandler(Handler):
|
|||||||
"""Provides a mechanism for generic bokeh applications to build up new streamvis documents.
|
"""Provides a mechanism for generic bokeh applications to build up new streamvis documents.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, anatric_path):
|
def __init__(self, anatric_path, spind_path):
|
||||||
"""Initialize a pyzebra handler for bokeh applications.
|
"""Initialize a pyzebra handler for bokeh applications.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -14,6 +14,7 @@ class PyzebraHandler(Handler):
|
|||||||
super().__init__() # no-op
|
super().__init__() # no-op
|
||||||
|
|
||||||
self.anatric_path = anatric_path
|
self.anatric_path = anatric_path
|
||||||
|
self.spind_path = spind_path
|
||||||
|
|
||||||
def modify_document(self, doc):
|
def modify_document(self, doc):
|
||||||
"""Modify an application document with pyzebra specific features.
|
"""Modify an application document with pyzebra specific features.
|
||||||
@ -26,5 +27,6 @@ class PyzebraHandler(Handler):
|
|||||||
"""
|
"""
|
||||||
doc.title = "pyzebra"
|
doc.title = "pyzebra"
|
||||||
doc.anatric_path = self.anatric_path
|
doc.anatric_path = self.anatric_path
|
||||||
|
doc.spind_path = self.spind_path
|
||||||
|
|
||||||
return doc
|
return doc
|
||||||
|
@ -5,11 +5,13 @@ import tempfile
|
|||||||
import types
|
import types
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
from bokeh.io import curdoc
|
||||||
from bokeh.layouts import column, row
|
from bokeh.layouts import column, row
|
||||||
from bokeh.models import (
|
from bokeh.models import (
|
||||||
BasicTicker,
|
BasicTicker,
|
||||||
Button,
|
Button,
|
||||||
CheckboxEditor,
|
CheckboxEditor,
|
||||||
|
CheckboxGroup,
|
||||||
ColumnDataSource,
|
ColumnDataSource,
|
||||||
CustomJS,
|
CustomJS,
|
||||||
DataRange1d,
|
DataRange1d,
|
||||||
@ -27,7 +29,7 @@ from bokeh.models import (
|
|||||||
Panel,
|
Panel,
|
||||||
PanTool,
|
PanTool,
|
||||||
Plot,
|
Plot,
|
||||||
RadioButtonGroup,
|
RadioGroup,
|
||||||
ResetTool,
|
ResetTool,
|
||||||
Scatter,
|
Scatter,
|
||||||
Select,
|
Select,
|
||||||
@ -37,48 +39,73 @@ from bokeh.models import (
|
|||||||
TableColumn,
|
TableColumn,
|
||||||
TextAreaInput,
|
TextAreaInput,
|
||||||
TextInput,
|
TextInput,
|
||||||
Toggle,
|
|
||||||
WheelZoomTool,
|
WheelZoomTool,
|
||||||
Whisker,
|
Whisker,
|
||||||
)
|
)
|
||||||
|
|
||||||
import pyzebra
|
import pyzebra
|
||||||
from pyzebra.ccl_io import AREA_METHODS
|
from pyzebra.ccl_io import EXPORT_TARGETS
|
||||||
|
from pyzebra.ccl_process import AREA_METHODS
|
||||||
|
|
||||||
|
|
||||||
javaScript = """
|
javaScript = """
|
||||||
|
let j = 0;
|
||||||
for (let i = 0; i < js_data.data['fname'].length; i++) {
|
for (let i = 0; i < js_data.data['fname'].length; i++) {
|
||||||
if (js_data.data['content'][i] === "") continue;
|
if (js_data.data['content'][i] === "") continue;
|
||||||
|
|
||||||
const blob = new Blob([js_data.data['content'][i]], {type: 'text/plain'})
|
setTimeout(function() {
|
||||||
const link = document.createElement('a');
|
const blob = new Blob([js_data.data['content'][i]], {type: 'text/plain'})
|
||||||
document.body.appendChild(link);
|
const link = document.createElement('a');
|
||||||
const url = window.URL.createObjectURL(blob);
|
document.body.appendChild(link);
|
||||||
link.href = url;
|
const url = window.URL.createObjectURL(blob);
|
||||||
link.download = js_data.data['fname'][i];
|
link.href = url;
|
||||||
link.click();
|
link.download = js_data.data['fname'][i] + js_data.data['ext'][i];
|
||||||
window.URL.revokeObjectURL(url);
|
link.click();
|
||||||
document.body.removeChild(link);
|
window.URL.revokeObjectURL(url);
|
||||||
|
document.body.removeChild(link);
|
||||||
|
}, 100 * j)
|
||||||
|
|
||||||
|
j++;
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
PROPOSAL_PATH = "/afs/psi.ch/project/sinqdata/2020/zebra/"
|
|
||||||
|
|
||||||
|
|
||||||
def create():
|
def create():
|
||||||
|
doc = curdoc()
|
||||||
det_data = {}
|
det_data = {}
|
||||||
fit_params = {}
|
fit_params = {}
|
||||||
js_data = ColumnDataSource(data=dict(content=["", ""], fname=["", ""]))
|
js_data = ColumnDataSource(data=dict(content=["", ""], fname=["", ""], ext=["", ""]))
|
||||||
|
|
||||||
def proposal_textinput_callback(_attr, _old, new):
|
def file_select_update_for_proposal():
|
||||||
ccl_path = os.path.join(PROPOSAL_PATH, new.strip())
|
proposal = proposal_textinput.value.strip()
|
||||||
ccl_file_list = []
|
if not proposal:
|
||||||
for file in os.listdir(ccl_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 = []
|
||||||
|
for file in os.listdir(proposal_path):
|
||||||
if file.endswith((".ccl", ".dat")):
|
if file.endswith((".ccl", ".dat")):
|
||||||
ccl_file_list.append((os.path.join(ccl_path, file), file))
|
file_list.append((os.path.join(proposal_path, file), file))
|
||||||
file_select.options = ccl_file_list
|
file_select.options = file_list
|
||||||
|
file_open_button.disabled = False
|
||||||
|
file_append_button.disabled = False
|
||||||
|
|
||||||
proposal_textinput = TextInput(title="Proposal number:", default_size=145)
|
doc.add_periodic_callback(file_select_update_for_proposal, 5000)
|
||||||
|
|
||||||
|
def proposal_textinput_callback(_attr, _old, _new):
|
||||||
|
file_select_update_for_proposal()
|
||||||
|
|
||||||
|
proposal_textinput = TextInput(title="Proposal number:", width=210)
|
||||||
proposal_textinput.on_change("value", proposal_textinput_callback)
|
proposal_textinput.on_change("value", proposal_textinput_callback)
|
||||||
|
|
||||||
def _init_datatable():
|
def _init_datatable():
|
||||||
@ -92,23 +119,17 @@ def create():
|
|||||||
scan_table_source.selected.indices = [0]
|
scan_table_source.selected.indices = [0]
|
||||||
|
|
||||||
merge_options = [(str(i), f"{i} ({idx})") for i, idx in enumerate(scan_list)]
|
merge_options = [(str(i), f"{i} ({idx})") for i, idx in enumerate(scan_list)]
|
||||||
merge_source_select.options = merge_options
|
merge_from_select.options = merge_options
|
||||||
merge_source_select.value = merge_options[0][0]
|
merge_from_select.value = merge_options[0][0]
|
||||||
merge_dest_select.options = merge_options
|
|
||||||
merge_dest_select.value = merge_options[0][0]
|
|
||||||
|
|
||||||
def ccl_file_select_callback(_attr, _old, _new):
|
file_select = MultiSelect(title="Available .ccl/.dat files:", width=210, height=250)
|
||||||
pass
|
|
||||||
|
|
||||||
file_select = MultiSelect(title="Available .ccl/.dat files:", default_size=200, height=250)
|
|
||||||
file_select.on_change("value", ccl_file_select_callback)
|
|
||||||
|
|
||||||
def file_open_button_callback():
|
def file_open_button_callback():
|
||||||
nonlocal det_data
|
nonlocal det_data
|
||||||
det_data = []
|
det_data = []
|
||||||
for f_name in file_select.value:
|
for f_path in file_select.value:
|
||||||
with open(f_name) as file:
|
with open(f_path) as file:
|
||||||
base, ext = os.path.splitext(f_name)
|
base, ext = os.path.splitext(os.path.basename(f_path))
|
||||||
if det_data:
|
if det_data:
|
||||||
append_data = pyzebra.parse_1D(file, ext)
|
append_data = pyzebra.parse_1D(file, ext)
|
||||||
pyzebra.normalize_dataset(append_data, monitor_spinner.value)
|
pyzebra.normalize_dataset(append_data, monitor_spinner.value)
|
||||||
@ -117,17 +138,18 @@ def create():
|
|||||||
det_data = pyzebra.parse_1D(file, ext)
|
det_data = pyzebra.parse_1D(file, ext)
|
||||||
pyzebra.normalize_dataset(det_data, monitor_spinner.value)
|
pyzebra.normalize_dataset(det_data, monitor_spinner.value)
|
||||||
pyzebra.merge_duplicates(det_data)
|
pyzebra.merge_duplicates(det_data)
|
||||||
js_data.data.update(fname=[base + ".comm", base + ".incomm"])
|
js_data.data.update(fname=[base, base])
|
||||||
|
|
||||||
_init_datatable()
|
_init_datatable()
|
||||||
|
append_upload_button.disabled = False
|
||||||
|
|
||||||
file_open_button = Button(label="Open New", default_size=100)
|
file_open_button = Button(label="Open New", width=100, disabled=True)
|
||||||
file_open_button.on_click(file_open_button_callback)
|
file_open_button.on_click(file_open_button_callback)
|
||||||
|
|
||||||
def file_append_button_callback():
|
def file_append_button_callback():
|
||||||
for f_name in file_select.value:
|
for f_path in file_select.value:
|
||||||
with open(f_name) as file:
|
with open(f_path) as file:
|
||||||
_, ext = os.path.splitext(f_name)
|
_, ext = os.path.splitext(f_path)
|
||||||
append_data = pyzebra.parse_1D(file, ext)
|
append_data = pyzebra.parse_1D(file, ext)
|
||||||
|
|
||||||
pyzebra.normalize_dataset(append_data, monitor_spinner.value)
|
pyzebra.normalize_dataset(append_data, monitor_spinner.value)
|
||||||
@ -135,12 +157,13 @@ def create():
|
|||||||
|
|
||||||
_init_datatable()
|
_init_datatable()
|
||||||
|
|
||||||
file_append_button = Button(label="Append", default_size=100)
|
file_append_button = Button(label="Append", width=100, disabled=True)
|
||||||
file_append_button.on_click(file_append_button_callback)
|
file_append_button.on_click(file_append_button_callback)
|
||||||
|
|
||||||
def upload_button_callback(_attr, _old, new):
|
def upload_button_callback(_attr, _old, new):
|
||||||
nonlocal det_data
|
nonlocal det_data
|
||||||
det_data = []
|
det_data = []
|
||||||
|
proposal_textinput.value = ""
|
||||||
for f_str, f_name in zip(new, upload_button.filename):
|
for f_str, f_name in zip(new, upload_button.filename):
|
||||||
with io.StringIO(base64.b64decode(f_str).decode()) as file:
|
with io.StringIO(base64.b64decode(f_str).decode()) as file:
|
||||||
base, ext = os.path.splitext(f_name)
|
base, ext = os.path.splitext(f_name)
|
||||||
@ -152,12 +175,13 @@ def create():
|
|||||||
det_data = pyzebra.parse_1D(file, ext)
|
det_data = pyzebra.parse_1D(file, ext)
|
||||||
pyzebra.normalize_dataset(det_data, monitor_spinner.value)
|
pyzebra.normalize_dataset(det_data, monitor_spinner.value)
|
||||||
pyzebra.merge_duplicates(det_data)
|
pyzebra.merge_duplicates(det_data)
|
||||||
js_data.data.update(fname=[base + ".comm", base + ".incomm"])
|
js_data.data.update(fname=[base, base])
|
||||||
|
|
||||||
_init_datatable()
|
_init_datatable()
|
||||||
|
append_upload_button.disabled = False
|
||||||
|
|
||||||
upload_div = Div(text="or upload new .ccl/.dat files:", margin=(5, 5, 0, 5))
|
upload_div = Div(text="or upload new .ccl/.dat files:", margin=(5, 5, 0, 5))
|
||||||
upload_button = FileInput(accept=".ccl,.dat", multiple=True, default_size=200)
|
upload_button = FileInput(accept=".ccl,.dat", multiple=True, width=200)
|
||||||
upload_button.on_change("value", upload_button_callback)
|
upload_button.on_change("value", upload_button_callback)
|
||||||
|
|
||||||
def append_upload_button_callback(_attr, _old, new):
|
def append_upload_button_callback(_attr, _old, new):
|
||||||
@ -172,7 +196,7 @@ def create():
|
|||||||
_init_datatable()
|
_init_datatable()
|
||||||
|
|
||||||
append_upload_div = Div(text="append extra files:", margin=(5, 5, 0, 5))
|
append_upload_div = Div(text="append extra files:", margin=(5, 5, 0, 5))
|
||||||
append_upload_button = FileInput(accept=".ccl,.dat", multiple=True, default_size=200)
|
append_upload_button = FileInput(accept=".ccl,.dat", multiple=True, width=200, disabled=True)
|
||||||
append_upload_button.on_change("value", append_upload_button_callback)
|
append_upload_button.on_change("value", append_upload_button_callback)
|
||||||
|
|
||||||
def monitor_spinner_callback(_attr, old, new):
|
def monitor_spinner_callback(_attr, old, new):
|
||||||
@ -190,7 +214,7 @@ def create():
|
|||||||
def _update_plot(scan):
|
def _update_plot(scan):
|
||||||
scan_motor = scan["scan_motor"]
|
scan_motor = scan["scan_motor"]
|
||||||
|
|
||||||
y = scan["Counts"]
|
y = scan["counts"]
|
||||||
x = scan[scan_motor]
|
x = scan[scan_motor]
|
||||||
|
|
||||||
plot.axis[0].axis_label = scan_motor
|
plot.axis[0].axis_label = scan_motor
|
||||||
@ -254,7 +278,7 @@ def create():
|
|||||||
plot_bkg_source, Line(x="x", y="y", line_color="green", line_dash="dashed")
|
plot_bkg_source, Line(x="x", y="y", line_color="green", line_dash="dashed")
|
||||||
)
|
)
|
||||||
|
|
||||||
plot_peak_source = ColumnDataSource(dict(xs=[0], ys=[0]))
|
plot_peak_source = ColumnDataSource(dict(xs=[[0]], ys=[[0]]))
|
||||||
plot_peak = plot.add_glyph(
|
plot_peak = plot.add_glyph(
|
||||||
plot_peak_source, MultiLine(xs="xs", ys="ys", line_color="red", line_dash="dashed")
|
plot_peak_source, MultiLine(xs="xs", ys="ys", line_color="red", line_dash="dashed")
|
||||||
)
|
)
|
||||||
@ -299,7 +323,12 @@ def create():
|
|||||||
|
|
||||||
_update_plot(det_data[new[0]])
|
_update_plot(det_data[new[0]])
|
||||||
|
|
||||||
|
def scan_table_source_callback(_attr, _old, _new):
|
||||||
|
_update_preview()
|
||||||
|
|
||||||
scan_table_source = ColumnDataSource(dict(scan=[], hkl=[], fit=[], export=[]))
|
scan_table_source = ColumnDataSource(dict(scan=[], hkl=[], fit=[], export=[]))
|
||||||
|
scan_table_source.on_change("data", scan_table_source_callback)
|
||||||
|
|
||||||
scan_table = DataTable(
|
scan_table = DataTable(
|
||||||
source=scan_table_source,
|
source=scan_table_source,
|
||||||
columns=[
|
columns=[
|
||||||
@ -319,33 +348,39 @@ def create():
|
|||||||
def _get_selected_scan():
|
def _get_selected_scan():
|
||||||
return det_data[scan_table_source.selected.indices[0]]
|
return det_data[scan_table_source.selected.indices[0]]
|
||||||
|
|
||||||
merge_dest_select = Select(title="destination:", width=100)
|
merge_from_select = Select(title="scan:", width=145)
|
||||||
merge_source_select = Select(title="source:", width=100)
|
|
||||||
|
|
||||||
def merge_button_callback():
|
def merge_button_callback():
|
||||||
scan_dest_ind = int(merge_dest_select.value)
|
scan_into = _get_selected_scan()
|
||||||
scan_source_ind = int(merge_source_select.value)
|
scan_from = det_data[int(merge_from_select.value)]
|
||||||
|
|
||||||
if scan_dest_ind == scan_source_ind:
|
if scan_into is scan_from:
|
||||||
print("WARNING: Selected scans for merging are identical")
|
print("WARNING: Selected scans for merging are identical")
|
||||||
return
|
return
|
||||||
|
|
||||||
pyzebra.merge_scans(det_data[scan_dest_ind], det_data[scan_source_ind])
|
pyzebra.merge_scans(scan_into, scan_from)
|
||||||
_update_plot(_get_selected_scan())
|
_update_plot(_get_selected_scan())
|
||||||
|
|
||||||
merge_button = Button(label="Merge scans", width=145)
|
merge_button = Button(label="Merge into current", width=145)
|
||||||
merge_button.on_click(merge_button_callback)
|
merge_button.on_click(merge_button_callback)
|
||||||
|
|
||||||
|
def restore_button_callback():
|
||||||
|
pyzebra.restore_scan(_get_selected_scan())
|
||||||
|
_update_plot(_get_selected_scan())
|
||||||
|
|
||||||
|
restore_button = Button(label="Restore scan", width=145)
|
||||||
|
restore_button.on_click(restore_button_callback)
|
||||||
|
|
||||||
def fit_from_spinner_callback(_attr, _old, new):
|
def fit_from_spinner_callback(_attr, _old, new):
|
||||||
fit_from_span.location = new
|
fit_from_span.location = new
|
||||||
|
|
||||||
fit_from_spinner = Spinner(title="Fit from:", default_size=145)
|
fit_from_spinner = Spinner(title="Fit from:", width=145)
|
||||||
fit_from_spinner.on_change("value", fit_from_spinner_callback)
|
fit_from_spinner.on_change("value", fit_from_spinner_callback)
|
||||||
|
|
||||||
def fit_to_spinner_callback(_attr, _old, new):
|
def fit_to_spinner_callback(_attr, _old, new):
|
||||||
fit_to_span.location = new
|
fit_to_span.location = new
|
||||||
|
|
||||||
fit_to_spinner = Spinner(title="to:", default_size=145)
|
fit_to_spinner = Spinner(title="to:", width=145)
|
||||||
fit_to_spinner.on_change("value", fit_to_spinner_callback)
|
fit_to_spinner.on_change("value", fit_to_spinner_callback)
|
||||||
|
|
||||||
def fitparams_add_dropdown_callback(click):
|
def fitparams_add_dropdown_callback(click):
|
||||||
@ -364,8 +399,7 @@ def create():
|
|||||||
("Pseudo Voigt", "pvoigt"),
|
("Pseudo Voigt", "pvoigt"),
|
||||||
# ("Pseudo Voigt1", "pseudovoigt1"),
|
# ("Pseudo Voigt1", "pseudovoigt1"),
|
||||||
],
|
],
|
||||||
default_size=145,
|
width=145,
|
||||||
disabled=True,
|
|
||||||
)
|
)
|
||||||
fitparams_add_dropdown.on_click(fitparams_add_dropdown_callback)
|
fitparams_add_dropdown.on_click(fitparams_add_dropdown_callback)
|
||||||
|
|
||||||
@ -385,7 +419,7 @@ def create():
|
|||||||
else:
|
else:
|
||||||
fitparams_table_source.data.update(dict(param=[], value=[], vary=[], min=[], max=[]))
|
fitparams_table_source.data.update(dict(param=[], value=[], vary=[], min=[], max=[]))
|
||||||
|
|
||||||
fitparams_select = MultiSelect(options=[], height=120, default_size=145)
|
fitparams_select = MultiSelect(options=[], height=120, width=145)
|
||||||
fitparams_select.tags = [0]
|
fitparams_select.tags = [0]
|
||||||
fitparams_select.on_change("value", fitparams_select_callback)
|
fitparams_select.on_change("value", fitparams_select_callback)
|
||||||
|
|
||||||
@ -400,7 +434,7 @@ def create():
|
|||||||
|
|
||||||
fitparams_select.value = []
|
fitparams_select.value = []
|
||||||
|
|
||||||
fitparams_remove_button = Button(label="Remove fit function", default_size=145, disabled=True)
|
fitparams_remove_button = Button(label="Remove fit function", width=145)
|
||||||
fitparams_remove_button.on_click(fitparams_remove_button_callback)
|
fitparams_remove_button.on_click(fitparams_remove_button_callback)
|
||||||
|
|
||||||
def fitparams_factory(function):
|
def fitparams_factory(function):
|
||||||
@ -422,6 +456,14 @@ def create():
|
|||||||
param=params, value=[None] * n, vary=[True] * n, min=[None] * n, max=[None] * n,
|
param=params, value=[None] * n, vary=[True] * n, min=[None] * n, max=[None] * n,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if function == "linear":
|
||||||
|
fitparams["value"] = [0, 1]
|
||||||
|
fitparams["vary"] = [False, True]
|
||||||
|
fitparams["min"] = [None, 0]
|
||||||
|
|
||||||
|
elif function == "gaussian":
|
||||||
|
fitparams["min"] = [0, None, None]
|
||||||
|
|
||||||
return fitparams
|
return fitparams
|
||||||
|
|
||||||
fitparams_table_source = ColumnDataSource(dict(param=[], value=[], vary=[], min=[], max=[]))
|
fitparams_table_source = ColumnDataSource(dict(param=[], value=[], vary=[], min=[], max=[]))
|
||||||
@ -448,44 +490,49 @@ def create():
|
|||||||
|
|
||||||
fit_output_textinput = TextAreaInput(title="Fit results:", width=750, height=200)
|
fit_output_textinput = TextAreaInput(title="Fit results:", width=750, height=200)
|
||||||
|
|
||||||
def fit_all_button_callback():
|
def proc_all_button_callback():
|
||||||
for scan, export in zip(det_data, scan_table_source.data["export"]):
|
for scan, export in zip(det_data, scan_table_source.data["export"]):
|
||||||
if export:
|
if export:
|
||||||
pyzebra.fit_scan(
|
pyzebra.fit_scan(
|
||||||
scan, fit_params, fit_from=fit_from_spinner.value, fit_to=fit_to_spinner.value
|
scan, fit_params, fit_from=fit_from_spinner.value, fit_to=fit_to_spinner.value
|
||||||
)
|
)
|
||||||
|
pyzebra.get_area(
|
||||||
|
scan,
|
||||||
|
area_method=AREA_METHODS[area_method_radiobutton.active],
|
||||||
|
lorentz=lorentz_checkbox.active,
|
||||||
|
)
|
||||||
|
|
||||||
_update_plot(_get_selected_scan())
|
_update_plot(_get_selected_scan())
|
||||||
_update_table()
|
_update_table()
|
||||||
|
|
||||||
fit_all_button = Button(label="Fit All", button_type="primary", default_size=145)
|
proc_all_button = Button(label="Process All", button_type="primary", width=145)
|
||||||
fit_all_button.on_click(fit_all_button_callback)
|
proc_all_button.on_click(proc_all_button_callback)
|
||||||
|
|
||||||
def fit_button_callback():
|
def proc_button_callback():
|
||||||
scan = _get_selected_scan()
|
scan = _get_selected_scan()
|
||||||
pyzebra.fit_scan(
|
pyzebra.fit_scan(
|
||||||
scan, fit_params, fit_from=fit_from_spinner.value, fit_to=fit_to_spinner.value
|
scan, fit_params, fit_from=fit_from_spinner.value, fit_to=fit_to_spinner.value
|
||||||
)
|
)
|
||||||
|
pyzebra.get_area(
|
||||||
|
scan,
|
||||||
|
area_method=AREA_METHODS[area_method_radiobutton.active],
|
||||||
|
lorentz=lorentz_checkbox.active,
|
||||||
|
)
|
||||||
|
|
||||||
_update_plot(scan)
|
_update_plot(scan)
|
||||||
_update_table()
|
_update_table()
|
||||||
|
|
||||||
fit_button = Button(label="Fit Current", default_size=145)
|
proc_button = Button(label="Process Current", width=145)
|
||||||
fit_button.on_click(fit_button_callback)
|
proc_button.on_click(proc_button_callback)
|
||||||
|
|
||||||
area_method_radiobutton = RadioButtonGroup(
|
area_method_div = Div(text="Intensity:", margin=(5, 5, 0, 5))
|
||||||
labels=["Fit area", "Int area"], active=0, default_size=145, disabled=True
|
area_method_radiobutton = RadioGroup(labels=["Function", "Area"], active=0, width=145)
|
||||||
)
|
|
||||||
|
|
||||||
bin_size_spinner = Spinner(
|
lorentz_checkbox = CheckboxGroup(labels=["Lorentz Correction"], width=145, margin=(13, 5, 5, 5))
|
||||||
title="Bin size:", value=1, low=1, step=1, default_size=145, disabled=True
|
|
||||||
)
|
|
||||||
|
|
||||||
lorentz_toggle = Toggle(label="Lorentz Correction", default_size=145)
|
export_preview_textinput = TextAreaInput(title="Export file(s) preview:", width=500, height=400)
|
||||||
|
|
||||||
export_preview_textinput = TextAreaInput(title="Export preview:", width=500, height=400)
|
def _update_preview():
|
||||||
|
|
||||||
def preview_button_callback():
|
|
||||||
with tempfile.TemporaryDirectory() as temp_dir:
|
with tempfile.TemporaryDirectory() as temp_dir:
|
||||||
temp_file = temp_dir + "/temp"
|
temp_file = temp_dir + "/temp"
|
||||||
export_data = []
|
export_data = []
|
||||||
@ -496,14 +543,13 @@ def create():
|
|||||||
pyzebra.export_1D(
|
pyzebra.export_1D(
|
||||||
export_data,
|
export_data,
|
||||||
temp_file,
|
temp_file,
|
||||||
area_method=AREA_METHODS[int(area_method_radiobutton.active)],
|
export_target_select.value,
|
||||||
lorentz=lorentz_toggle.active,
|
|
||||||
hkl_precision=int(hkl_precision_select.value),
|
hkl_precision=int(hkl_precision_select.value),
|
||||||
)
|
)
|
||||||
|
|
||||||
exported_content = ""
|
exported_content = ""
|
||||||
file_content = []
|
file_content = []
|
||||||
for ext in (".comm", ".incomm"):
|
for ext in EXPORT_TARGETS[export_target_select.value]:
|
||||||
fname = temp_file + ext
|
fname = temp_file + ext
|
||||||
if os.path.isfile(fname):
|
if os.path.isfile(fname):
|
||||||
with open(fname) as f:
|
with open(fname) as f:
|
||||||
@ -516,32 +562,39 @@ def create():
|
|||||||
js_data.data.update(content=file_content)
|
js_data.data.update(content=file_content)
|
||||||
export_preview_textinput.value = exported_content
|
export_preview_textinput.value = exported_content
|
||||||
|
|
||||||
preview_button = Button(label="Preview", default_size=200)
|
def export_target_select_callback(_attr, _old, new):
|
||||||
preview_button.on_click(preview_button_callback)
|
js_data.data.update(ext=EXPORT_TARGETS[new])
|
||||||
|
_update_preview()
|
||||||
|
|
||||||
|
export_target_select = Select(
|
||||||
|
title="Export target:", options=list(EXPORT_TARGETS.keys()), value="fullprof", width=80
|
||||||
|
)
|
||||||
|
export_target_select.on_change("value", export_target_select_callback)
|
||||||
|
js_data.data.update(ext=EXPORT_TARGETS[export_target_select.value])
|
||||||
|
|
||||||
|
def hkl_precision_select_callback(_attr, _old, _new):
|
||||||
|
_update_preview()
|
||||||
|
|
||||||
hkl_precision_select = Select(
|
hkl_precision_select = Select(
|
||||||
title="hkl precision:", options=["2", "3", "4"], value="2", default_size=80
|
title="hkl precision:", options=["2", "3", "4"], value="2", width=80
|
||||||
)
|
)
|
||||||
|
hkl_precision_select.on_change("value", hkl_precision_select_callback)
|
||||||
|
|
||||||
save_button = Button(label="Download preview", button_type="success", default_size=200)
|
save_button = Button(label="Download File(s)", button_type="success", width=200)
|
||||||
save_button.js_on_click(CustomJS(args={"js_data": js_data}, code=javaScript))
|
save_button.js_on_click(CustomJS(args={"js_data": js_data}, code=javaScript))
|
||||||
|
|
||||||
fitpeak_controls = row(
|
fitpeak_controls = row(
|
||||||
column(fitparams_add_dropdown, fitparams_select, fitparams_remove_button),
|
column(fitparams_add_dropdown, fitparams_select, fitparams_remove_button),
|
||||||
fitparams_table,
|
fitparams_table,
|
||||||
Spacer(width=20),
|
Spacer(width=20),
|
||||||
column(
|
column(fit_from_spinner, lorentz_checkbox, area_method_div, area_method_radiobutton),
|
||||||
row(fit_from_spinner, fit_to_spinner),
|
column(fit_to_spinner, proc_button, proc_all_button),
|
||||||
row(bin_size_spinner, column(Spacer(height=19), lorentz_toggle)),
|
|
||||||
row(area_method_radiobutton),
|
|
||||||
row(fit_button, fit_all_button),
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
scan_layout = column(
|
scan_layout = column(
|
||||||
scan_table,
|
scan_table,
|
||||||
monitor_spinner,
|
row(monitor_spinner, column(Spacer(height=19), restore_button)),
|
||||||
row(column(Spacer(height=19), merge_button), merge_dest_select, merge_source_select),
|
row(column(Spacer(height=19), merge_button), merge_from_select),
|
||||||
)
|
)
|
||||||
|
|
||||||
import_layout = column(
|
import_layout = column(
|
||||||
@ -556,7 +609,9 @@ def create():
|
|||||||
|
|
||||||
export_layout = column(
|
export_layout = column(
|
||||||
export_preview_textinput,
|
export_preview_textinput,
|
||||||
row(hkl_precision_select, column(Spacer(height=19), row(preview_button, save_button))),
|
row(
|
||||||
|
export_target_select, hkl_precision_select, column(Spacer(height=19), row(save_button))
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
tab_layout = column(
|
tab_layout = column(
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import base64
|
import base64
|
||||||
import io
|
import io
|
||||||
|
import os
|
||||||
import re
|
import re
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
@ -10,9 +11,9 @@ from bokeh.models import (
|
|||||||
Div,
|
Div,
|
||||||
FileInput,
|
FileInput,
|
||||||
Panel,
|
Panel,
|
||||||
RadioButtonGroup,
|
|
||||||
Select,
|
Select,
|
||||||
Spacer,
|
Spacer,
|
||||||
|
Tabs,
|
||||||
TextAreaInput,
|
TextAreaInput,
|
||||||
TextInput,
|
TextInput,
|
||||||
)
|
)
|
||||||
@ -29,7 +30,7 @@ def create():
|
|||||||
config.load_from_file(file)
|
config.load_from_file(file)
|
||||||
|
|
||||||
logfile_textinput.value = config.logfile
|
logfile_textinput.value = config.logfile
|
||||||
logfile_verbosity_select.value = config.logfile_verbosity
|
logfile_verbosity.value = config.logfile_verbosity
|
||||||
|
|
||||||
filelist_type.value = config.filelist_type
|
filelist_type.value = config.filelist_type
|
||||||
filelist_format_textinput.value = config.filelist_format
|
filelist_format_textinput.value = config.filelist_format
|
||||||
@ -44,11 +45,16 @@ def create():
|
|||||||
ub_textareainput.value = config.crystal_UB
|
ub_textareainput.value = config.crystal_UB
|
||||||
|
|
||||||
dataFactory_implementation_select.value = config.dataFactory_implementation
|
dataFactory_implementation_select.value = config.dataFactory_implementation
|
||||||
dataFactory_dist1_textinput.value = config.dataFactory_dist1
|
if config.dataFactory_dist1 is not None:
|
||||||
|
dataFactory_dist1_textinput.value = config.dataFactory_dist1
|
||||||
|
if config.dataFactory_dist2 is not None:
|
||||||
|
dataFactory_dist2_textinput.value = config.dataFactory_dist2
|
||||||
|
if config.dataFactory_dist3 is not None:
|
||||||
|
dataFactory_dist3_textinput.value = config.dataFactory_dist3
|
||||||
reflectionPrinter_format_select.value = config.reflectionPrinter_format
|
reflectionPrinter_format_select.value = config.reflectionPrinter_format
|
||||||
|
|
||||||
set_active_widgets(config.algorithm)
|
|
||||||
if config.algorithm == "adaptivemaxcog":
|
if config.algorithm == "adaptivemaxcog":
|
||||||
|
algorithm_params.active = 0
|
||||||
threshold_textinput.value = config.threshold
|
threshold_textinput.value = config.threshold
|
||||||
shell_textinput.value = config.shell
|
shell_textinput.value = config.shell
|
||||||
steepness_textinput.value = config.steepness
|
steepness_textinput.value = config.steepness
|
||||||
@ -57,6 +63,7 @@ def create():
|
|||||||
aps_window_textinput.value = str(tuple(map(int, config.aps_window.values())))
|
aps_window_textinput.value = str(tuple(map(int, config.aps_window.values())))
|
||||||
|
|
||||||
elif config.algorithm == "adaptivedynamic":
|
elif config.algorithm == "adaptivedynamic":
|
||||||
|
algorithm_params.active = 1
|
||||||
adm_window_textinput.value = str(tuple(map(int, config.adm_window.values())))
|
adm_window_textinput.value = str(tuple(map(int, config.adm_window.values())))
|
||||||
border_textinput.value = str(tuple(map(int, config.border.values())))
|
border_textinput.value = str(tuple(map(int, config.border.values())))
|
||||||
minWindow_textinput.value = str(tuple(map(int, config.minWindow.values())))
|
minWindow_textinput.value = str(tuple(map(int, config.minWindow.values())))
|
||||||
@ -66,45 +73,16 @@ def create():
|
|||||||
loop_textinput.value = config.loop
|
loop_textinput.value = config.loop
|
||||||
minPeakCount_textinput.value = config.minPeakCount
|
minPeakCount_textinput.value = config.minPeakCount
|
||||||
displacementCurve_textinput.value = "\n".join(map(str, config.displacementCurve))
|
displacementCurve_textinput.value = "\n".join(map(str, config.displacementCurve))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise ValueError("Unknown processing mode.")
|
raise ValueError("Unknown processing mode.")
|
||||||
|
|
||||||
def set_active_widgets(implementation):
|
|
||||||
if implementation == "adaptivemaxcog":
|
|
||||||
mode_radio_button_group.active = 0
|
|
||||||
disable_adaptivemaxcog = False
|
|
||||||
disable_adaptivedynamic = True
|
|
||||||
|
|
||||||
elif implementation == "adaptivedynamic":
|
|
||||||
mode_radio_button_group.active = 1
|
|
||||||
disable_adaptivemaxcog = True
|
|
||||||
disable_adaptivedynamic = False
|
|
||||||
else:
|
|
||||||
raise ValueError("Implementation can be either 'adaptivemaxcog' or 'adaptivedynamic'")
|
|
||||||
|
|
||||||
threshold_textinput.disabled = disable_adaptivemaxcog
|
|
||||||
shell_textinput.disabled = disable_adaptivemaxcog
|
|
||||||
steepness_textinput.disabled = disable_adaptivemaxcog
|
|
||||||
duplicateDistance_textinput.disabled = disable_adaptivemaxcog
|
|
||||||
maxequal_textinput.disabled = disable_adaptivemaxcog
|
|
||||||
aps_window_textinput.disabled = disable_adaptivemaxcog
|
|
||||||
|
|
||||||
adm_window_textinput.disabled = disable_adaptivedynamic
|
|
||||||
border_textinput.disabled = disable_adaptivedynamic
|
|
||||||
minWindow_textinput.disabled = disable_adaptivedynamic
|
|
||||||
reflectionFile_textinput.disabled = disable_adaptivedynamic
|
|
||||||
targetMonitor_textinput.disabled = disable_adaptivedynamic
|
|
||||||
smoothSize_textinput.disabled = disable_adaptivedynamic
|
|
||||||
loop_textinput.disabled = disable_adaptivedynamic
|
|
||||||
minPeakCount_textinput.disabled = disable_adaptivedynamic
|
|
||||||
displacementCurve_textinput.disabled = disable_adaptivedynamic
|
|
||||||
|
|
||||||
def upload_button_callback(_attr, _old, new):
|
def upload_button_callback(_attr, _old, new):
|
||||||
with io.BytesIO(base64.b64decode(new)) as file:
|
with io.BytesIO(base64.b64decode(new)) as file:
|
||||||
_load_config_file(file)
|
_load_config_file(file)
|
||||||
|
|
||||||
upload_div = Div(text="Open XML configuration file:")
|
upload_div = Div(text="Open .xml config:")
|
||||||
upload_button = FileInput(accept=".xml")
|
upload_button = FileInput(accept=".xml", width=200)
|
||||||
upload_button.on_change("value", upload_button_callback)
|
upload_button.on_change("value", upload_button_callback)
|
||||||
|
|
||||||
# General parameters
|
# General parameters
|
||||||
@ -112,16 +90,14 @@ def create():
|
|||||||
def logfile_textinput_callback(_attr, _old, new):
|
def logfile_textinput_callback(_attr, _old, new):
|
||||||
config.logfile = new
|
config.logfile = new
|
||||||
|
|
||||||
logfile_textinput = TextInput(title="Logfile:", value="logfile.log", width=320)
|
logfile_textinput = TextInput(title="Logfile:", value="logfile.log")
|
||||||
logfile_textinput.on_change("value", logfile_textinput_callback)
|
logfile_textinput.on_change("value", logfile_textinput_callback)
|
||||||
|
|
||||||
def logfile_verbosity_select_callback(_attr, _old, new):
|
def logfile_verbosity_callback(_attr, _old, new):
|
||||||
config.logfile_verbosity = new
|
config.logfile_verbosity = new
|
||||||
|
|
||||||
logfile_verbosity_select = Select(
|
logfile_verbosity = TextInput(title="verbosity:", width=70)
|
||||||
title="verbosity:", options=["0", "5", "10", "15", "30"], width=70
|
logfile_verbosity.on_change("value", logfile_verbosity_callback)
|
||||||
)
|
|
||||||
logfile_verbosity_select.on_change("value", logfile_verbosity_select_callback)
|
|
||||||
|
|
||||||
# ---- FileList
|
# ---- FileList
|
||||||
def filelist_type_callback(_attr, _old, new):
|
def filelist_type_callback(_attr, _old, new):
|
||||||
@ -148,20 +124,20 @@ def create():
|
|||||||
ranges.append(re.findall(r"\b\d+\b", line))
|
ranges.append(re.findall(r"\b\d+\b", line))
|
||||||
config.filelist_ranges = ranges
|
config.filelist_ranges = ranges
|
||||||
|
|
||||||
filelist_ranges_textareainput = TextAreaInput(title="ranges:", height=100)
|
filelist_ranges_textareainput = TextAreaInput(title="ranges:", rows=1)
|
||||||
filelist_ranges_textareainput.on_change("value", filelist_ranges_textareainput_callback)
|
filelist_ranges_textareainput.on_change("value", filelist_ranges_textareainput_callback)
|
||||||
|
|
||||||
# ---- crystal
|
# ---- crystal
|
||||||
def crystal_sample_textinput_callback(_attr, _old, new):
|
def crystal_sample_textinput_callback(_attr, _old, new):
|
||||||
config.crystal_sample = new
|
config.crystal_sample = new
|
||||||
|
|
||||||
crystal_sample_textinput = TextInput(title="Sample Name:")
|
crystal_sample_textinput = TextInput(title="Sample Name:", width=290)
|
||||||
crystal_sample_textinput.on_change("value", crystal_sample_textinput_callback)
|
crystal_sample_textinput.on_change("value", crystal_sample_textinput_callback)
|
||||||
|
|
||||||
def lambda_textinput_callback(_attr, _old, new):
|
def lambda_textinput_callback(_attr, _old, new):
|
||||||
config.crystal_lambda = new
|
config.crystal_lambda = new
|
||||||
|
|
||||||
lambda_textinput = TextInput(title="lambda:", width=145)
|
lambda_textinput = TextInput(title="lambda:", width=100)
|
||||||
lambda_textinput.on_change("value", lambda_textinput_callback)
|
lambda_textinput.on_change("value", lambda_textinput_callback)
|
||||||
|
|
||||||
def ub_textareainput_callback(_attr, _old, new):
|
def ub_textareainput_callback(_attr, _old, new):
|
||||||
@ -173,19 +149,19 @@ def create():
|
|||||||
def zeroOM_textinput_callback(_attr, _old, new):
|
def zeroOM_textinput_callback(_attr, _old, new):
|
||||||
config.crystal_zeroOM = new
|
config.crystal_zeroOM = new
|
||||||
|
|
||||||
zeroOM_textinput = TextInput(title="zeroOM:", width=145)
|
zeroOM_textinput = TextInput(title="zeroOM:", width=100)
|
||||||
zeroOM_textinput.on_change("value", zeroOM_textinput_callback)
|
zeroOM_textinput.on_change("value", zeroOM_textinput_callback)
|
||||||
|
|
||||||
def zeroSTT_textinput_callback(_attr, _old, new):
|
def zeroSTT_textinput_callback(_attr, _old, new):
|
||||||
config.crystal_zeroSTT = new
|
config.crystal_zeroSTT = new
|
||||||
|
|
||||||
zeroSTT_textinput = TextInput(title="zeroSTT:", width=145)
|
zeroSTT_textinput = TextInput(title="zeroSTT:", width=100)
|
||||||
zeroSTT_textinput.on_change("value", zeroSTT_textinput_callback)
|
zeroSTT_textinput.on_change("value", zeroSTT_textinput_callback)
|
||||||
|
|
||||||
def zeroCHI_textinput_callback(_attr, _old, new):
|
def zeroCHI_textinput_callback(_attr, _old, new):
|
||||||
config.crystal_zeroCHI = new
|
config.crystal_zeroCHI = new
|
||||||
|
|
||||||
zeroCHI_textinput = TextInput(title="zeroCHI:", width=145)
|
zeroCHI_textinput = TextInput(title="zeroCHI:", width=100)
|
||||||
zeroCHI_textinput.on_change("value", zeroCHI_textinput_callback)
|
zeroCHI_textinput.on_change("value", zeroCHI_textinput_callback)
|
||||||
|
|
||||||
# ---- DataFactory
|
# ---- DataFactory
|
||||||
@ -200,9 +176,21 @@ def create():
|
|||||||
def dataFactory_dist1_textinput_callback(_attr, _old, new):
|
def dataFactory_dist1_textinput_callback(_attr, _old, new):
|
||||||
config.dataFactory_dist1 = new
|
config.dataFactory_dist1 = new
|
||||||
|
|
||||||
dataFactory_dist1_textinput = TextInput(title="dist1:", width=145)
|
dataFactory_dist1_textinput = TextInput(title="dist1:", width=75)
|
||||||
dataFactory_dist1_textinput.on_change("value", dataFactory_dist1_textinput_callback)
|
dataFactory_dist1_textinput.on_change("value", dataFactory_dist1_textinput_callback)
|
||||||
|
|
||||||
|
def dataFactory_dist2_textinput_callback(_attr, _old, new):
|
||||||
|
config.dataFactory_dist2 = new
|
||||||
|
|
||||||
|
dataFactory_dist2_textinput = TextInput(title="dist2:", width=75)
|
||||||
|
dataFactory_dist2_textinput.on_change("value", dataFactory_dist2_textinput_callback)
|
||||||
|
|
||||||
|
def dataFactory_dist3_textinput_callback(_attr, _old, new):
|
||||||
|
config.dataFactory_dist3 = new
|
||||||
|
|
||||||
|
dataFactory_dist3_textinput = TextInput(title="dist3:", width=75)
|
||||||
|
dataFactory_dist3_textinput.on_change("value", dataFactory_dist3_textinput_callback)
|
||||||
|
|
||||||
# ---- BackgroundProcessor
|
# ---- BackgroundProcessor
|
||||||
|
|
||||||
# ---- DetectorEfficency
|
# ---- DetectorEfficency
|
||||||
@ -221,42 +209,42 @@ def create():
|
|||||||
def threshold_textinput_callback(_attr, _old, new):
|
def threshold_textinput_callback(_attr, _old, new):
|
||||||
config.threshold = new
|
config.threshold = new
|
||||||
|
|
||||||
threshold_textinput = TextInput(title="Threshold:")
|
threshold_textinput = TextInput(title="Threshold:", width=145)
|
||||||
threshold_textinput.on_change("value", threshold_textinput_callback)
|
threshold_textinput.on_change("value", threshold_textinput_callback)
|
||||||
|
|
||||||
# ---- shell
|
# ---- shell
|
||||||
def shell_textinput_callback(_attr, _old, new):
|
def shell_textinput_callback(_attr, _old, new):
|
||||||
config.shell = new
|
config.shell = new
|
||||||
|
|
||||||
shell_textinput = TextInput(title="Shell:")
|
shell_textinput = TextInput(title="Shell:", width=145)
|
||||||
shell_textinput.on_change("value", shell_textinput_callback)
|
shell_textinput.on_change("value", shell_textinput_callback)
|
||||||
|
|
||||||
# ---- steepness
|
# ---- steepness
|
||||||
def steepness_textinput_callback(_attr, _old, new):
|
def steepness_textinput_callback(_attr, _old, new):
|
||||||
config.steepness = new
|
config.steepness = new
|
||||||
|
|
||||||
steepness_textinput = TextInput(title="Steepness:")
|
steepness_textinput = TextInput(title="Steepness:", width=145)
|
||||||
steepness_textinput.on_change("value", steepness_textinput_callback)
|
steepness_textinput.on_change("value", steepness_textinput_callback)
|
||||||
|
|
||||||
# ---- duplicateDistance
|
# ---- duplicateDistance
|
||||||
def duplicateDistance_textinput_callback(_attr, _old, new):
|
def duplicateDistance_textinput_callback(_attr, _old, new):
|
||||||
config.duplicateDistance = new
|
config.duplicateDistance = new
|
||||||
|
|
||||||
duplicateDistance_textinput = TextInput(title="Duplicate Distance:")
|
duplicateDistance_textinput = TextInput(title="Duplicate Distance:", width=145)
|
||||||
duplicateDistance_textinput.on_change("value", duplicateDistance_textinput_callback)
|
duplicateDistance_textinput.on_change("value", duplicateDistance_textinput_callback)
|
||||||
|
|
||||||
# ---- maxequal
|
# ---- maxequal
|
||||||
def maxequal_textinput_callback(_attr, _old, new):
|
def maxequal_textinput_callback(_attr, _old, new):
|
||||||
config.maxequal = new
|
config.maxequal = new
|
||||||
|
|
||||||
maxequal_textinput = TextInput(title="Max Equal:")
|
maxequal_textinput = TextInput(title="Max Equal:", width=145)
|
||||||
maxequal_textinput.on_change("value", maxequal_textinput_callback)
|
maxequal_textinput.on_change("value", maxequal_textinput_callback)
|
||||||
|
|
||||||
# ---- window
|
# ---- window
|
||||||
def aps_window_textinput_callback(_attr, _old, new):
|
def aps_window_textinput_callback(_attr, _old, new):
|
||||||
config.aps_window = dict(zip(("x", "y", "z"), re.findall(r"\b\d+\b", new)))
|
config.aps_window = dict(zip(("x", "y", "z"), re.findall(r"\b\d+\b", new)))
|
||||||
|
|
||||||
aps_window_textinput = TextInput(title="Window (x, y, z):")
|
aps_window_textinput = TextInput(title="Window (x, y, z):", width=145)
|
||||||
aps_window_textinput.on_change("value", aps_window_textinput_callback)
|
aps_window_textinput.on_change("value", aps_window_textinput_callback)
|
||||||
|
|
||||||
# Adaptive Dynamic Mask Integration (adaptivedynamic)
|
# Adaptive Dynamic Mask Integration (adaptivedynamic)
|
||||||
@ -264,56 +252,56 @@ def create():
|
|||||||
def adm_window_textinput_callback(_attr, _old, new):
|
def adm_window_textinput_callback(_attr, _old, new):
|
||||||
config.adm_window = dict(zip(("x", "y", "z"), re.findall(r"\b\d+\b", new)))
|
config.adm_window = dict(zip(("x", "y", "z"), re.findall(r"\b\d+\b", new)))
|
||||||
|
|
||||||
adm_window_textinput = TextInput(title="Window (x, y, z):")
|
adm_window_textinput = TextInput(title="Window (x, y, z):", width=145)
|
||||||
adm_window_textinput.on_change("value", adm_window_textinput_callback)
|
adm_window_textinput.on_change("value", adm_window_textinput_callback)
|
||||||
|
|
||||||
# ---- border
|
# ---- border
|
||||||
def border_textinput_callback(_attr, _old, new):
|
def border_textinput_callback(_attr, _old, new):
|
||||||
config.border = dict(zip(("x", "y", "z"), re.findall(r"\b\d+\b", new)))
|
config.border = dict(zip(("x", "y", "z"), re.findall(r"\b\d+\b", new)))
|
||||||
|
|
||||||
border_textinput = TextInput(title="Border (x, y, z):")
|
border_textinput = TextInput(title="Border (x, y, z):", width=145)
|
||||||
border_textinput.on_change("value", border_textinput_callback)
|
border_textinput.on_change("value", border_textinput_callback)
|
||||||
|
|
||||||
# ---- minWindow
|
# ---- minWindow
|
||||||
def minWindow_textinput_callback(_attr, _old, new):
|
def minWindow_textinput_callback(_attr, _old, new):
|
||||||
config.minWindow = dict(zip(("x", "y", "z"), re.findall(r"\b\d+\b", new)))
|
config.minWindow = dict(zip(("x", "y", "z"), re.findall(r"\b\d+\b", new)))
|
||||||
|
|
||||||
minWindow_textinput = TextInput(title="Min Window (x, y, z):")
|
minWindow_textinput = TextInput(title="Min Window (x, y, z):", width=145)
|
||||||
minWindow_textinput.on_change("value", minWindow_textinput_callback)
|
minWindow_textinput.on_change("value", minWindow_textinput_callback)
|
||||||
|
|
||||||
# ---- reflectionFile
|
# ---- reflectionFile
|
||||||
def reflectionFile_textinput_callback(_attr, _old, new):
|
def reflectionFile_textinput_callback(_attr, _old, new):
|
||||||
config.reflectionFile = new
|
config.reflectionFile = new
|
||||||
|
|
||||||
reflectionFile_textinput = TextInput(title="Reflection File:")
|
reflectionFile_textinput = TextInput(title="Reflection File:", width=145)
|
||||||
reflectionFile_textinput.on_change("value", reflectionFile_textinput_callback)
|
reflectionFile_textinput.on_change("value", reflectionFile_textinput_callback)
|
||||||
|
|
||||||
# ---- targetMonitor
|
# ---- targetMonitor
|
||||||
def targetMonitor_textinput_callback(_attr, _old, new):
|
def targetMonitor_textinput_callback(_attr, _old, new):
|
||||||
config.targetMonitor = new
|
config.targetMonitor = new
|
||||||
|
|
||||||
targetMonitor_textinput = TextInput(title="Target Monitor:")
|
targetMonitor_textinput = TextInput(title="Target Monitor:", width=145)
|
||||||
targetMonitor_textinput.on_change("value", targetMonitor_textinput_callback)
|
targetMonitor_textinput.on_change("value", targetMonitor_textinput_callback)
|
||||||
|
|
||||||
# ---- smoothSize
|
# ---- smoothSize
|
||||||
def smoothSize_textinput_callback(_attr, _old, new):
|
def smoothSize_textinput_callback(_attr, _old, new):
|
||||||
config.smoothSize = new
|
config.smoothSize = new
|
||||||
|
|
||||||
smoothSize_textinput = TextInput(title="Smooth Size:")
|
smoothSize_textinput = TextInput(title="Smooth Size:", width=145)
|
||||||
smoothSize_textinput.on_change("value", smoothSize_textinput_callback)
|
smoothSize_textinput.on_change("value", smoothSize_textinput_callback)
|
||||||
|
|
||||||
# ---- loop
|
# ---- loop
|
||||||
def loop_textinput_callback(_attr, _old, new):
|
def loop_textinput_callback(_attr, _old, new):
|
||||||
config.loop = new
|
config.loop = new
|
||||||
|
|
||||||
loop_textinput = TextInput(title="Loop:")
|
loop_textinput = TextInput(title="Loop:", width=145)
|
||||||
loop_textinput.on_change("value", loop_textinput_callback)
|
loop_textinput.on_change("value", loop_textinput_callback)
|
||||||
|
|
||||||
# ---- minPeakCount
|
# ---- minPeakCount
|
||||||
def minPeakCount_textinput_callback(_attr, _old, new):
|
def minPeakCount_textinput_callback(_attr, _old, new):
|
||||||
config.minPeakCount = new
|
config.minPeakCount = new
|
||||||
|
|
||||||
minPeakCount_textinput = TextInput(title="Min Peak Count:")
|
minPeakCount_textinput = TextInput(title="Min Peak Count:", width=145)
|
||||||
minPeakCount_textinput.on_change("value", minPeakCount_textinput_callback)
|
minPeakCount_textinput.on_change("value", minPeakCount_textinput_callback)
|
||||||
|
|
||||||
# ---- displacementCurve
|
# ---- displacementCurve
|
||||||
@ -324,95 +312,82 @@ def create():
|
|||||||
config.displacementCurve = maps
|
config.displacementCurve = maps
|
||||||
|
|
||||||
displacementCurve_textinput = TextAreaInput(
|
displacementCurve_textinput = TextAreaInput(
|
||||||
title="Displacement Curve (twotheta, x, y):", height=100
|
title="Displ. Curve (2θ, x, y):", width=145, height=100
|
||||||
)
|
)
|
||||||
displacementCurve_textinput.on_change("value", displacementCurve_textinput_callback)
|
displacementCurve_textinput.on_change("value", displacementCurve_textinput_callback)
|
||||||
|
|
||||||
def mode_radio_button_group_callback(active):
|
def algorithm_tabs_callback(_attr, _old, new):
|
||||||
if active == 0:
|
if new == 0:
|
||||||
config.algorithm = "adaptivemaxcog"
|
config.algorithm = "adaptivemaxcog"
|
||||||
set_active_widgets("adaptivemaxcog")
|
|
||||||
else:
|
else:
|
||||||
config.algorithm = "adaptivedynamic"
|
config.algorithm = "adaptivedynamic"
|
||||||
set_active_widgets("adaptivedynamic")
|
|
||||||
|
|
||||||
mode_radio_button_group = RadioButtonGroup(
|
algorithm_params = Tabs(
|
||||||
labels=["Adaptive Peak Detection", "Adaptive Dynamic Integration"], active=0
|
tabs=[
|
||||||
|
Panel(
|
||||||
|
child=column(
|
||||||
|
row(threshold_textinput, shell_textinput, steepness_textinput),
|
||||||
|
row(duplicateDistance_textinput, maxequal_textinput, aps_window_textinput),
|
||||||
|
),
|
||||||
|
title="Peak Search",
|
||||||
|
),
|
||||||
|
Panel(
|
||||||
|
child=column(
|
||||||
|
row(adm_window_textinput, border_textinput, minWindow_textinput),
|
||||||
|
row(reflectionFile_textinput, targetMonitor_textinput, smoothSize_textinput),
|
||||||
|
row(loop_textinput, minPeakCount_textinput, displacementCurve_textinput),
|
||||||
|
),
|
||||||
|
title="Dynamic Integration",
|
||||||
|
),
|
||||||
|
]
|
||||||
)
|
)
|
||||||
mode_radio_button_group.on_click(mode_radio_button_group_callback)
|
algorithm_params.on_change("active", algorithm_tabs_callback)
|
||||||
set_active_widgets("adaptivemaxcog")
|
|
||||||
|
|
||||||
def process_button_callback():
|
def process_button_callback():
|
||||||
with tempfile.TemporaryDirectory() as temp_dir:
|
with tempfile.TemporaryDirectory() as temp_dir:
|
||||||
temp_file = temp_dir + "/temp.xml"
|
temp_file = temp_dir + "/config.xml"
|
||||||
config.save_as(temp_file)
|
config.save_as(temp_file)
|
||||||
if doc.anatric_path:
|
pyzebra.anatric(temp_file, anatric_path=doc.anatric_path, cwd=temp_dir)
|
||||||
pyzebra.anatric(temp_file, anatric_path=doc.anatric_path)
|
|
||||||
else:
|
|
||||||
pyzebra.anatric(temp_file)
|
|
||||||
|
|
||||||
with open(config.logfile) as f_log:
|
with open(os.path.join(temp_dir, config.logfile)) as f_log:
|
||||||
output_log.value = f_log.read()
|
output_log.value = f_log.read()
|
||||||
|
|
||||||
|
with open(os.path.join(temp_dir, config.reflectionPrinter_file)) as f_res:
|
||||||
|
output_res.value = f_res.read()
|
||||||
|
|
||||||
process_button = Button(label="Process", button_type="primary")
|
process_button = Button(label="Process", button_type="primary")
|
||||||
process_button.on_click(process_button_callback)
|
process_button.on_click(process_button_callback)
|
||||||
|
|
||||||
output_log = TextAreaInput(title="Logfile output:", height=600, disabled=True)
|
output_log = TextAreaInput(title="Logfile output:", height=320, width=465, disabled=True)
|
||||||
output_config = TextAreaInput(title="Current config:", height=600, width=400, disabled=True)
|
output_res = TextAreaInput(title="Result output:", height=320, width=465, disabled=True)
|
||||||
|
output_config = TextAreaInput(title="Current config:", height=320, width=465, disabled=True)
|
||||||
|
|
||||||
general_params_layout = column(
|
general_params_layout = column(
|
||||||
row(logfile_textinput, logfile_verbosity_select),
|
row(column(Spacer(height=2), upload_div), upload_button),
|
||||||
|
row(logfile_textinput, logfile_verbosity),
|
||||||
row(filelist_type, filelist_format_textinput),
|
row(filelist_type, filelist_format_textinput),
|
||||||
filelist_datapath_textinput,
|
filelist_datapath_textinput,
|
||||||
filelist_ranges_textareainput,
|
filelist_ranges_textareainput,
|
||||||
crystal_sample_textinput,
|
row(crystal_sample_textinput, lambda_textinput),
|
||||||
row(lambda_textinput, zeroOM_textinput),
|
|
||||||
row(zeroSTT_textinput, zeroCHI_textinput),
|
|
||||||
ub_textareainput,
|
ub_textareainput,
|
||||||
row(dataFactory_implementation_select, dataFactory_dist1_textinput),
|
row(zeroOM_textinput, zeroSTT_textinput, zeroCHI_textinput),
|
||||||
reflectionPrinter_format_select,
|
row(
|
||||||
|
dataFactory_implementation_select,
|
||||||
|
dataFactory_dist1_textinput,
|
||||||
|
dataFactory_dist2_textinput,
|
||||||
|
dataFactory_dist3_textinput,
|
||||||
|
),
|
||||||
|
row(reflectionPrinter_format_select),
|
||||||
)
|
)
|
||||||
|
|
||||||
algorithm_params_layout = column(
|
tab_layout = row(
|
||||||
mode_radio_button_group,
|
general_params_layout,
|
||||||
row(
|
column(output_config, algorithm_params, row(process_button)),
|
||||||
column(
|
column(output_log, output_res),
|
||||||
threshold_textinput,
|
|
||||||
shell_textinput,
|
|
||||||
steepness_textinput,
|
|
||||||
duplicateDistance_textinput,
|
|
||||||
maxequal_textinput,
|
|
||||||
aps_window_textinput,
|
|
||||||
),
|
|
||||||
column(
|
|
||||||
adm_window_textinput,
|
|
||||||
border_textinput,
|
|
||||||
minWindow_textinput,
|
|
||||||
reflectionFile_textinput,
|
|
||||||
targetMonitor_textinput,
|
|
||||||
smoothSize_textinput,
|
|
||||||
loop_textinput,
|
|
||||||
minPeakCount_textinput,
|
|
||||||
displacementCurve_textinput,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
tab_layout = column(
|
|
||||||
row(column(Spacer(height=2), upload_div), upload_button),
|
|
||||||
row(
|
|
||||||
general_params_layout,
|
|
||||||
algorithm_params_layout,
|
|
||||||
column(row(output_config, output_log), row(process_button)),
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
async def update_config():
|
async def update_config():
|
||||||
with tempfile.TemporaryDirectory() as temp_dir:
|
output_config.value = config.tostring()
|
||||||
temp_file = temp_dir + "/debug.xml"
|
|
||||||
config.save_as(temp_file)
|
|
||||||
with open(temp_file) as f_config:
|
|
||||||
output_config.value = f_config.read()
|
|
||||||
|
|
||||||
doc.add_periodic_callback(update_config, 1000)
|
doc.add_periodic_callback(update_config, 1000)
|
||||||
|
|
||||||
|
623
pyzebra/app/panel_hdf_param_study.py
Normal file
623
pyzebra/app/panel_hdf_param_study.py
Normal file
@ -0,0 +1,623 @@
|
|||||||
|
import base64
|
||||||
|
import io
|
||||||
|
import math
|
||||||
|
import os
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
from bokeh.io import curdoc
|
||||||
|
from bokeh.layouts import column, gridplot, row
|
||||||
|
from bokeh.models import (
|
||||||
|
BasicTicker,
|
||||||
|
BoxZoomTool,
|
||||||
|
Button,
|
||||||
|
CheckboxGroup,
|
||||||
|
ColumnDataSource,
|
||||||
|
DataRange1d,
|
||||||
|
DataTable,
|
||||||
|
Div,
|
||||||
|
FileInput,
|
||||||
|
Grid,
|
||||||
|
MultiSelect,
|
||||||
|
NumberEditor,
|
||||||
|
NumberFormatter,
|
||||||
|
Image,
|
||||||
|
LinearAxis,
|
||||||
|
LinearColorMapper,
|
||||||
|
Panel,
|
||||||
|
PanTool,
|
||||||
|
Plot,
|
||||||
|
Range1d,
|
||||||
|
ResetTool,
|
||||||
|
Scatter,
|
||||||
|
Select,
|
||||||
|
Spinner,
|
||||||
|
TableColumn,
|
||||||
|
Tabs,
|
||||||
|
TextInput,
|
||||||
|
Title,
|
||||||
|
WheelZoomTool,
|
||||||
|
)
|
||||||
|
from bokeh.palettes import Cividis256, Greys256, Plasma256 # pylint: disable=E0611
|
||||||
|
from scipy.optimize import curve_fit
|
||||||
|
|
||||||
|
import pyzebra
|
||||||
|
|
||||||
|
IMAGE_W = 256
|
||||||
|
IMAGE_H = 128
|
||||||
|
IMAGE_PLOT_W = int(IMAGE_W * 2) + 52
|
||||||
|
IMAGE_PLOT_H = int(IMAGE_H * 2) + 27
|
||||||
|
|
||||||
|
|
||||||
|
def create():
|
||||||
|
doc = curdoc()
|
||||||
|
zebra_data = []
|
||||||
|
det_data = {}
|
||||||
|
cami_meta = {}
|
||||||
|
|
||||||
|
num_formatter = NumberFormatter(format="0.00", nan_format="")
|
||||||
|
|
||||||
|
def file_select_update_for_proposal():
|
||||||
|
proposal = proposal_textinput.value.strip()
|
||||||
|
if not proposal:
|
||||||
|
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 = []
|
||||||
|
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
|
||||||
|
|
||||||
|
doc.add_periodic_callback(file_select_update_for_proposal, 5000)
|
||||||
|
|
||||||
|
def proposal_textinput_callback(_attr, _old, _new):
|
||||||
|
nonlocal cami_meta
|
||||||
|
cami_meta = {}
|
||||||
|
file_select_update_for_proposal()
|
||||||
|
|
||||||
|
proposal_textinput = TextInput(title="Proposal number:", width=210)
|
||||||
|
proposal_textinput.on_change("value", proposal_textinput_callback)
|
||||||
|
|
||||||
|
def upload_button_callback(_attr, _old, new):
|
||||||
|
nonlocal cami_meta
|
||||||
|
proposal_textinput.value = ""
|
||||||
|
with io.StringIO(base64.b64decode(new).decode()) as file:
|
||||||
|
cami_meta = pyzebra.parse_h5meta(file)
|
||||||
|
file_list = cami_meta["filelist"]
|
||||||
|
file_select.options = [(entry, os.path.basename(entry)) for entry in file_list]
|
||||||
|
|
||||||
|
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():
|
||||||
|
file_list = []
|
||||||
|
for scan in zebra_data:
|
||||||
|
file_list.append(os.path.basename(scan["original_filename"]))
|
||||||
|
|
||||||
|
scan_table_source.data.update(
|
||||||
|
file=file_list,
|
||||||
|
param=[None] * len(zebra_data),
|
||||||
|
frame=[None] * len(zebra_data),
|
||||||
|
x_pos=[None] * len(zebra_data),
|
||||||
|
y_pos=[None] * len(zebra_data),
|
||||||
|
)
|
||||||
|
scan_table_source.selected.indices = []
|
||||||
|
scan_table_source.selected.indices = [0]
|
||||||
|
|
||||||
|
param_select.value = "user defined"
|
||||||
|
|
||||||
|
def _update_table():
|
||||||
|
frame = []
|
||||||
|
x_pos = []
|
||||||
|
y_pos = []
|
||||||
|
for scan in zebra_data:
|
||||||
|
if "fit" in scan:
|
||||||
|
framei = scan["fit"]["frame"]
|
||||||
|
x_posi = scan["fit"]["x_pos"]
|
||||||
|
y_posi = scan["fit"]["y_pos"]
|
||||||
|
else:
|
||||||
|
framei = x_posi = y_posi = None
|
||||||
|
|
||||||
|
frame.append(framei)
|
||||||
|
x_pos.append(x_posi)
|
||||||
|
y_pos.append(y_posi)
|
||||||
|
|
||||||
|
scan_table_source.data.update(frame=frame, x_pos=x_pos, y_pos=y_pos)
|
||||||
|
|
||||||
|
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_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_append_button = Button(label="Append", width=100)
|
||||||
|
file_append_button.on_click(file_append_button_callback)
|
||||||
|
|
||||||
|
# Scan select
|
||||||
|
def scan_table_select_callback(_attr, old, new):
|
||||||
|
nonlocal det_data
|
||||||
|
|
||||||
|
if not new:
|
||||||
|
# skip empty selections
|
||||||
|
return
|
||||||
|
|
||||||
|
# Avoid selection of multiple indicies (via Shift+Click or Ctrl+Click)
|
||||||
|
if len(new) > 1:
|
||||||
|
# drop selection to the previous one
|
||||||
|
scan_table_source.selected.indices = old
|
||||||
|
return
|
||||||
|
|
||||||
|
if len(old) > 1:
|
||||||
|
# skip unnecessary update caused by selection drop
|
||||||
|
return
|
||||||
|
|
||||||
|
det_data = zebra_data[new[0]]
|
||||||
|
|
||||||
|
zebra_mode = det_data["zebra_mode"]
|
||||||
|
if zebra_mode == "nb":
|
||||||
|
metadata_table_source.data.update(geom=["normal beam"])
|
||||||
|
else: # zebra_mode == "bi"
|
||||||
|
metadata_table_source.data.update(geom=["bisecting"])
|
||||||
|
|
||||||
|
update_image(0)
|
||||||
|
update_overview_plot()
|
||||||
|
|
||||||
|
def scan_table_source_callback(_attr, _old, _new):
|
||||||
|
pass
|
||||||
|
|
||||||
|
scan_table_source = ColumnDataSource(dict(file=[], param=[], frame=[], x_pos=[], y_pos=[]))
|
||||||
|
scan_table_source.selected.on_change("indices", scan_table_select_callback)
|
||||||
|
scan_table_source.on_change("data", scan_table_source_callback)
|
||||||
|
|
||||||
|
scan_table = DataTable(
|
||||||
|
source=scan_table_source,
|
||||||
|
columns=[
|
||||||
|
TableColumn(field="file", title="file", width=150),
|
||||||
|
TableColumn(
|
||||||
|
field="param",
|
||||||
|
title="param",
|
||||||
|
formatter=num_formatter,
|
||||||
|
editor=NumberEditor(),
|
||||||
|
width=50,
|
||||||
|
),
|
||||||
|
TableColumn(field="frame", title="Frame", formatter=num_formatter, width=70),
|
||||||
|
TableColumn(field="x_pos", title="X", formatter=num_formatter, width=70),
|
||||||
|
TableColumn(field="y_pos", title="Y", formatter=num_formatter, width=70),
|
||||||
|
],
|
||||||
|
width=470, # +60 because of the index column
|
||||||
|
height=420,
|
||||||
|
editable=True,
|
||||||
|
autosize_mode="none",
|
||||||
|
)
|
||||||
|
|
||||||
|
def param_select_callback(_attr, _old, new):
|
||||||
|
if new == "user defined":
|
||||||
|
param = [None] * len(zebra_data)
|
||||||
|
else:
|
||||||
|
# TODO: which value to take?
|
||||||
|
param = [scan[new][0] for scan in zebra_data]
|
||||||
|
|
||||||
|
scan_table_source.data["param"] = param
|
||||||
|
_update_param_plot()
|
||||||
|
|
||||||
|
param_select = Select(
|
||||||
|
title="Parameter:",
|
||||||
|
options=["user defined", "temp", "mf", "h", "k", "l"],
|
||||||
|
value="user defined",
|
||||||
|
width=145,
|
||||||
|
)
|
||||||
|
param_select.on_change("value", param_select_callback)
|
||||||
|
|
||||||
|
def update_image(index=None):
|
||||||
|
if "mf" in det_data:
|
||||||
|
metadata_table_source.data.update(mf=[det_data["mf"][index]])
|
||||||
|
else:
|
||||||
|
metadata_table_source.data.update(mf=[None])
|
||||||
|
|
||||||
|
if "temp" in det_data:
|
||||||
|
metadata_table_source.data.update(temp=[det_data["temp"][index]])
|
||||||
|
else:
|
||||||
|
metadata_table_source.data.update(temp=[None])
|
||||||
|
|
||||||
|
def update_overview_plot():
|
||||||
|
h5_data = det_data["data"]
|
||||||
|
n_im, n_y, n_x = h5_data.shape
|
||||||
|
overview_x = np.mean(h5_data, axis=1)
|
||||||
|
overview_y = np.mean(h5_data, axis=2)
|
||||||
|
|
||||||
|
overview_plot_x_image_source.data.update(image=[overview_x], dw=[n_x], dh=[n_im])
|
||||||
|
overview_plot_y_image_source.data.update(image=[overview_y], dw=[n_y], dh=[n_im])
|
||||||
|
|
||||||
|
if proj_auto_checkbox.active:
|
||||||
|
im_min = min(np.min(overview_x), np.min(overview_y))
|
||||||
|
im_max = max(np.max(overview_x), np.max(overview_y))
|
||||||
|
|
||||||
|
proj_display_min_spinner.value = im_min
|
||||||
|
proj_display_max_spinner.value = im_max
|
||||||
|
|
||||||
|
overview_plot_x_image_glyph.color_mapper.low = im_min
|
||||||
|
overview_plot_y_image_glyph.color_mapper.low = im_min
|
||||||
|
overview_plot_x_image_glyph.color_mapper.high = im_max
|
||||||
|
overview_plot_y_image_glyph.color_mapper.high = im_max
|
||||||
|
|
||||||
|
frame_range.start = 0
|
||||||
|
frame_range.end = n_im
|
||||||
|
frame_range.reset_start = 0
|
||||||
|
frame_range.reset_end = n_im
|
||||||
|
frame_range.bounds = (0, n_im)
|
||||||
|
|
||||||
|
scan_motor = det_data["scan_motor"]
|
||||||
|
overview_plot_y.axis[1].axis_label = f"Scanning motor, {scan_motor}"
|
||||||
|
|
||||||
|
var = det_data[scan_motor]
|
||||||
|
var_start = var[0]
|
||||||
|
var_end = var[-1] + (var[-1] - var[0]) / (n_im - 1)
|
||||||
|
|
||||||
|
scanning_motor_range.start = var_start
|
||||||
|
scanning_motor_range.end = var_end
|
||||||
|
scanning_motor_range.reset_start = var_start
|
||||||
|
scanning_motor_range.reset_end = var_end
|
||||||
|
# handle both, ascending and descending sequences
|
||||||
|
scanning_motor_range.bounds = (min(var_start, var_end), max(var_start, var_end))
|
||||||
|
|
||||||
|
# shared frame ranges
|
||||||
|
frame_range = Range1d(0, 1, bounds=(0, 1))
|
||||||
|
scanning_motor_range = Range1d(0, 1, bounds=(0, 1))
|
||||||
|
|
||||||
|
det_x_range = Range1d(0, IMAGE_W, bounds=(0, IMAGE_W))
|
||||||
|
overview_plot_x = Plot(
|
||||||
|
title=Title(text="Projections on X-axis"),
|
||||||
|
x_range=det_x_range,
|
||||||
|
y_range=frame_range,
|
||||||
|
extra_y_ranges={"scanning_motor": scanning_motor_range},
|
||||||
|
plot_height=400,
|
||||||
|
plot_width=IMAGE_PLOT_W - 3,
|
||||||
|
)
|
||||||
|
|
||||||
|
# ---- tools
|
||||||
|
wheelzoomtool = WheelZoomTool(maintain_focus=False)
|
||||||
|
overview_plot_x.toolbar.logo = None
|
||||||
|
overview_plot_x.add_tools(
|
||||||
|
PanTool(), BoxZoomTool(), wheelzoomtool, ResetTool(),
|
||||||
|
)
|
||||||
|
overview_plot_x.toolbar.active_scroll = wheelzoomtool
|
||||||
|
|
||||||
|
# ---- axes
|
||||||
|
overview_plot_x.add_layout(LinearAxis(axis_label="Coordinate X, pix"), place="below")
|
||||||
|
overview_plot_x.add_layout(
|
||||||
|
LinearAxis(axis_label="Frame", major_label_orientation="vertical"), place="left"
|
||||||
|
)
|
||||||
|
|
||||||
|
# ---- grid lines
|
||||||
|
overview_plot_x.add_layout(Grid(dimension=0, ticker=BasicTicker()))
|
||||||
|
overview_plot_x.add_layout(Grid(dimension=1, ticker=BasicTicker()))
|
||||||
|
|
||||||
|
# ---- rgba image glyph
|
||||||
|
overview_plot_x_image_source = ColumnDataSource(
|
||||||
|
dict(image=[np.zeros((1, 1), dtype="float32")], x=[0], y=[0], dw=[IMAGE_W], dh=[1])
|
||||||
|
)
|
||||||
|
|
||||||
|
overview_plot_x_image_glyph = Image(image="image", x="x", y="y", dw="dw", dh="dh")
|
||||||
|
overview_plot_x.add_glyph(
|
||||||
|
overview_plot_x_image_source, overview_plot_x_image_glyph, name="image_glyph"
|
||||||
|
)
|
||||||
|
|
||||||
|
det_y_range = Range1d(0, IMAGE_H, bounds=(0, IMAGE_H))
|
||||||
|
overview_plot_y = Plot(
|
||||||
|
title=Title(text="Projections on Y-axis"),
|
||||||
|
x_range=det_y_range,
|
||||||
|
y_range=frame_range,
|
||||||
|
extra_y_ranges={"scanning_motor": scanning_motor_range},
|
||||||
|
plot_height=400,
|
||||||
|
plot_width=IMAGE_PLOT_H + 22,
|
||||||
|
)
|
||||||
|
|
||||||
|
# ---- tools
|
||||||
|
wheelzoomtool = WheelZoomTool(maintain_focus=False)
|
||||||
|
overview_plot_y.toolbar.logo = None
|
||||||
|
overview_plot_y.add_tools(
|
||||||
|
PanTool(), BoxZoomTool(), wheelzoomtool, ResetTool(),
|
||||||
|
)
|
||||||
|
overview_plot_y.toolbar.active_scroll = wheelzoomtool
|
||||||
|
|
||||||
|
# ---- axes
|
||||||
|
overview_plot_y.add_layout(LinearAxis(axis_label="Coordinate Y, pix"), place="below")
|
||||||
|
overview_plot_y.add_layout(
|
||||||
|
LinearAxis(
|
||||||
|
y_range_name="scanning_motor",
|
||||||
|
axis_label="Scanning motor",
|
||||||
|
major_label_orientation="vertical",
|
||||||
|
),
|
||||||
|
place="right",
|
||||||
|
)
|
||||||
|
|
||||||
|
# ---- grid lines
|
||||||
|
overview_plot_y.add_layout(Grid(dimension=0, ticker=BasicTicker()))
|
||||||
|
overview_plot_y.add_layout(Grid(dimension=1, ticker=BasicTicker()))
|
||||||
|
|
||||||
|
# ---- rgba image glyph
|
||||||
|
overview_plot_y_image_source = ColumnDataSource(
|
||||||
|
dict(image=[np.zeros((1, 1), dtype="float32")], x=[0], y=[0], dw=[IMAGE_H], dh=[1])
|
||||||
|
)
|
||||||
|
|
||||||
|
overview_plot_y_image_glyph = Image(image="image", x="x", y="y", dw="dw", dh="dh")
|
||||||
|
overview_plot_y.add_glyph(
|
||||||
|
overview_plot_y_image_source, overview_plot_y_image_glyph, name="image_glyph"
|
||||||
|
)
|
||||||
|
|
||||||
|
cmap_dict = {
|
||||||
|
"gray": Greys256,
|
||||||
|
"gray_reversed": Greys256[::-1],
|
||||||
|
"plasma": Plasma256,
|
||||||
|
"cividis": Cividis256,
|
||||||
|
}
|
||||||
|
|
||||||
|
def colormap_callback(_attr, _old, new):
|
||||||
|
overview_plot_x_image_glyph.color_mapper = LinearColorMapper(palette=cmap_dict[new])
|
||||||
|
overview_plot_y_image_glyph.color_mapper = LinearColorMapper(palette=cmap_dict[new])
|
||||||
|
|
||||||
|
colormap = Select(title="Colormap:", options=list(cmap_dict.keys()), width=210)
|
||||||
|
colormap.on_change("value", colormap_callback)
|
||||||
|
colormap.value = "plasma"
|
||||||
|
|
||||||
|
PROJ_STEP = 0.1
|
||||||
|
|
||||||
|
def proj_auto_checkbox_callback(state):
|
||||||
|
if state:
|
||||||
|
proj_display_min_spinner.disabled = True
|
||||||
|
proj_display_max_spinner.disabled = True
|
||||||
|
else:
|
||||||
|
proj_display_min_spinner.disabled = False
|
||||||
|
proj_display_max_spinner.disabled = False
|
||||||
|
|
||||||
|
update_overview_plot()
|
||||||
|
|
||||||
|
proj_auto_checkbox = CheckboxGroup(
|
||||||
|
labels=["Projections Intensity Range"], active=[0], width=145, margin=[10, 5, 0, 5]
|
||||||
|
)
|
||||||
|
proj_auto_checkbox.on_click(proj_auto_checkbox_callback)
|
||||||
|
|
||||||
|
def proj_display_max_spinner_callback(_attr, _old_value, new_value):
|
||||||
|
proj_display_min_spinner.high = new_value - PROJ_STEP
|
||||||
|
overview_plot_x_image_glyph.color_mapper.high = new_value
|
||||||
|
overview_plot_y_image_glyph.color_mapper.high = new_value
|
||||||
|
|
||||||
|
proj_display_max_spinner = Spinner(
|
||||||
|
low=0 + PROJ_STEP,
|
||||||
|
value=1,
|
||||||
|
step=PROJ_STEP,
|
||||||
|
disabled=bool(proj_auto_checkbox.active),
|
||||||
|
width=100,
|
||||||
|
height=31,
|
||||||
|
)
|
||||||
|
proj_display_max_spinner.on_change("value", proj_display_max_spinner_callback)
|
||||||
|
|
||||||
|
def proj_display_min_spinner_callback(_attr, _old_value, new_value):
|
||||||
|
proj_display_max_spinner.low = new_value + PROJ_STEP
|
||||||
|
overview_plot_x_image_glyph.color_mapper.low = new_value
|
||||||
|
overview_plot_y_image_glyph.color_mapper.low = new_value
|
||||||
|
|
||||||
|
proj_display_min_spinner = Spinner(
|
||||||
|
low=0,
|
||||||
|
high=1 - PROJ_STEP,
|
||||||
|
value=0,
|
||||||
|
step=PROJ_STEP,
|
||||||
|
disabled=bool(proj_auto_checkbox.active),
|
||||||
|
width=100,
|
||||||
|
height=31,
|
||||||
|
)
|
||||||
|
proj_display_min_spinner.on_change("value", proj_display_min_spinner_callback)
|
||||||
|
|
||||||
|
def fit_event(scan):
|
||||||
|
p0 = [1.0, 0.0, 1.0]
|
||||||
|
maxfev = 100000
|
||||||
|
|
||||||
|
# wave = scan["wave"]
|
||||||
|
# ddist = scan["ddist"]
|
||||||
|
# cell = scan["cell"]
|
||||||
|
|
||||||
|
# gamma = scan["gamma"][0]
|
||||||
|
# omega = scan["omega"][0]
|
||||||
|
# nu = scan["nu"][0]
|
||||||
|
# chi = scan["chi"][0]
|
||||||
|
# phi = scan["phi"][0]
|
||||||
|
|
||||||
|
scan_motor = scan["scan_motor"]
|
||||||
|
var_angle = scan[scan_motor]
|
||||||
|
|
||||||
|
x0 = int(np.floor(det_x_range.start))
|
||||||
|
xN = int(np.ceil(det_x_range.end))
|
||||||
|
y0 = int(np.floor(det_y_range.start))
|
||||||
|
yN = int(np.ceil(det_y_range.end))
|
||||||
|
fr0 = int(np.floor(frame_range.start))
|
||||||
|
frN = int(np.ceil(frame_range.end))
|
||||||
|
data_roi = scan["data"][fr0:frN, y0:yN, x0:xN]
|
||||||
|
|
||||||
|
cnts = np.sum(data_roi, axis=(1, 2))
|
||||||
|
coeff, _ = curve_fit(gauss, range(len(cnts)), cnts, p0=p0, maxfev=maxfev)
|
||||||
|
|
||||||
|
# m = cnts.mean()
|
||||||
|
# sd = cnts.std()
|
||||||
|
# snr_cnts = np.where(sd == 0, 0, m / sd)
|
||||||
|
|
||||||
|
frC = fr0 + coeff[1]
|
||||||
|
var_F = var_angle[math.floor(frC)]
|
||||||
|
var_C = var_angle[math.ceil(frC)]
|
||||||
|
# frStep = frC - math.floor(frC)
|
||||||
|
var_step = var_C - var_F
|
||||||
|
# var_p = var_F + var_step * frStep
|
||||||
|
|
||||||
|
# if scan_motor == "gamma":
|
||||||
|
# gamma = var_p
|
||||||
|
# elif scan_motor == "omega":
|
||||||
|
# omega = var_p
|
||||||
|
# elif scan_motor == "nu":
|
||||||
|
# nu = var_p
|
||||||
|
# elif scan_motor == "chi":
|
||||||
|
# chi = var_p
|
||||||
|
# elif scan_motor == "phi":
|
||||||
|
# phi = var_p
|
||||||
|
|
||||||
|
intensity = coeff[1] * abs(coeff[2] * var_step) * math.sqrt(2) * math.sqrt(np.pi)
|
||||||
|
|
||||||
|
projX = np.sum(data_roi, axis=(0, 1))
|
||||||
|
coeff, _ = curve_fit(gauss, range(len(projX)), projX, p0=p0, maxfev=maxfev)
|
||||||
|
x_pos = x0 + coeff[1]
|
||||||
|
|
||||||
|
projY = np.sum(data_roi, axis=(0, 2))
|
||||||
|
coeff, _ = curve_fit(gauss, range(len(projY)), projY, p0=p0, maxfev=maxfev)
|
||||||
|
y_pos = y0 + coeff[1]
|
||||||
|
|
||||||
|
scan["fit"] = {"frame": frC, "x_pos": x_pos, "y_pos": y_pos, "intensity": intensity}
|
||||||
|
|
||||||
|
metadata_table_source = ColumnDataSource(dict(geom=[""], temp=[None], mf=[None]))
|
||||||
|
metadata_table = DataTable(
|
||||||
|
source=metadata_table_source,
|
||||||
|
columns=[
|
||||||
|
TableColumn(field="geom", title="Geometry", width=100),
|
||||||
|
TableColumn(field="temp", title="Temperature", formatter=num_formatter, width=100),
|
||||||
|
TableColumn(field="mf", title="Magnetic Field", formatter=num_formatter, width=100),
|
||||||
|
],
|
||||||
|
width=300,
|
||||||
|
height=50,
|
||||||
|
autosize_mode="none",
|
||||||
|
index_position=None,
|
||||||
|
)
|
||||||
|
|
||||||
|
def _update_param_plot():
|
||||||
|
x = []
|
||||||
|
y = []
|
||||||
|
fit_param = fit_param_select.value
|
||||||
|
for s, p in zip(zebra_data, scan_table_source.data["param"]):
|
||||||
|
if "fit" in s and fit_param:
|
||||||
|
x.append(p)
|
||||||
|
y.append(s["fit"][fit_param])
|
||||||
|
param_plot_scatter_source.data.update(x=x, y=y)
|
||||||
|
|
||||||
|
# Parameter plot
|
||||||
|
param_plot = Plot(x_range=DataRange1d(), y_range=DataRange1d(), plot_height=400, plot_width=700)
|
||||||
|
|
||||||
|
param_plot.add_layout(LinearAxis(axis_label="Fit parameter"), place="left")
|
||||||
|
param_plot.add_layout(LinearAxis(axis_label="Parameter"), place="below")
|
||||||
|
|
||||||
|
param_plot.add_layout(Grid(dimension=0, ticker=BasicTicker()))
|
||||||
|
param_plot.add_layout(Grid(dimension=1, ticker=BasicTicker()))
|
||||||
|
|
||||||
|
param_plot_scatter_source = ColumnDataSource(dict(x=[], y=[]))
|
||||||
|
param_plot.add_glyph(param_plot_scatter_source, Scatter(x="x", y="y"))
|
||||||
|
|
||||||
|
param_plot.add_tools(PanTool(), WheelZoomTool(), ResetTool())
|
||||||
|
param_plot.toolbar.logo = None
|
||||||
|
|
||||||
|
def fit_param_select_callback(_attr, _old, _new):
|
||||||
|
_update_param_plot()
|
||||||
|
|
||||||
|
fit_param_select = Select(title="Fit parameter", options=[], width=145)
|
||||||
|
fit_param_select.on_change("value", fit_param_select_callback)
|
||||||
|
|
||||||
|
def proc_all_button_callback():
|
||||||
|
for scan in zebra_data:
|
||||||
|
fit_event(scan)
|
||||||
|
|
||||||
|
_update_table()
|
||||||
|
|
||||||
|
for scan in zebra_data:
|
||||||
|
if "fit" in scan:
|
||||||
|
options = list(scan["fit"].keys())
|
||||||
|
fit_param_select.options = options
|
||||||
|
fit_param_select.value = options[0]
|
||||||
|
break
|
||||||
|
|
||||||
|
_update_param_plot()
|
||||||
|
|
||||||
|
proc_all_button = Button(label="Process All", button_type="primary", width=145)
|
||||||
|
proc_all_button.on_click(proc_all_button_callback)
|
||||||
|
|
||||||
|
def proc_button_callback():
|
||||||
|
fit_event(det_data)
|
||||||
|
|
||||||
|
_update_table()
|
||||||
|
|
||||||
|
for scan in zebra_data:
|
||||||
|
if "fit" in scan:
|
||||||
|
options = list(scan["fit"].keys())
|
||||||
|
fit_param_select.options = options
|
||||||
|
fit_param_select.value = options[0]
|
||||||
|
break
|
||||||
|
|
||||||
|
_update_param_plot()
|
||||||
|
|
||||||
|
proc_button = Button(label="Process Current", width=145)
|
||||||
|
proc_button.on_click(proc_button_callback)
|
||||||
|
|
||||||
|
layout_controls = row(
|
||||||
|
colormap,
|
||||||
|
column(proj_auto_checkbox, row(proj_display_min_spinner, proj_display_max_spinner)),
|
||||||
|
proc_button,
|
||||||
|
proc_all_button,
|
||||||
|
)
|
||||||
|
|
||||||
|
layout_overview = column(
|
||||||
|
gridplot(
|
||||||
|
[[overview_plot_x, overview_plot_y]],
|
||||||
|
toolbar_options=dict(logo=None),
|
||||||
|
merge_tools=True,
|
||||||
|
toolbar_location="left",
|
||||||
|
),
|
||||||
|
layout_controls,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Plot tabs
|
||||||
|
plots = Tabs(
|
||||||
|
tabs=[
|
||||||
|
Panel(child=layout_overview, title="single scan"),
|
||||||
|
Panel(child=column(param_plot, row(fit_param_select)), title="parameter plot"),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
# Final layout
|
||||||
|
import_layout = column(
|
||||||
|
proposal_textinput,
|
||||||
|
upload_div,
|
||||||
|
upload_button,
|
||||||
|
file_select,
|
||||||
|
row(file_open_button, file_append_button),
|
||||||
|
)
|
||||||
|
|
||||||
|
scan_layout = column(scan_table, row(param_select, metadata_table))
|
||||||
|
|
||||||
|
tab_layout = column(row(import_layout, scan_layout, plots))
|
||||||
|
|
||||||
|
return Panel(child=tab_layout, title="hdf param study")
|
||||||
|
|
||||||
|
|
||||||
|
def gauss(x, *p):
|
||||||
|
"""Defines Gaussian function
|
||||||
|
Args:
|
||||||
|
A - amplitude, mu - position of the center, sigma - width
|
||||||
|
Returns:
|
||||||
|
Gaussian function
|
||||||
|
"""
|
||||||
|
A, mu, sigma = p
|
||||||
|
return A * np.exp(-((x - mu) ** 2) / (2.0 * sigma ** 2))
|
@ -1,19 +1,26 @@
|
|||||||
import base64
|
import base64
|
||||||
import io
|
import io
|
||||||
|
import math
|
||||||
import os
|
import os
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
from bokeh.events import MouseEnter
|
||||||
|
from bokeh.io import curdoc
|
||||||
from bokeh.layouts import column, gridplot, row
|
from bokeh.layouts import column, gridplot, row
|
||||||
from bokeh.models import (
|
from bokeh.models import (
|
||||||
BasicTicker,
|
BasicTicker,
|
||||||
BoxEditTool,
|
BoxEditTool,
|
||||||
BoxZoomTool,
|
BoxZoomTool,
|
||||||
Button,
|
Button,
|
||||||
|
CheckboxGroup,
|
||||||
ColumnDataSource,
|
ColumnDataSource,
|
||||||
DataRange1d,
|
DataRange1d,
|
||||||
|
DataTable,
|
||||||
Div,
|
Div,
|
||||||
FileInput,
|
FileInput,
|
||||||
Grid,
|
Grid,
|
||||||
|
MultiSelect,
|
||||||
|
NumberFormatter,
|
||||||
HoverTool,
|
HoverTool,
|
||||||
Image,
|
Image,
|
||||||
Line,
|
Line,
|
||||||
@ -22,56 +29,75 @@ from bokeh.models import (
|
|||||||
Panel,
|
Panel,
|
||||||
PanTool,
|
PanTool,
|
||||||
Plot,
|
Plot,
|
||||||
RadioButtonGroup,
|
|
||||||
Range1d,
|
Range1d,
|
||||||
Rect,
|
Rect,
|
||||||
ResetTool,
|
ResetTool,
|
||||||
Select,
|
Select,
|
||||||
|
Slider,
|
||||||
Spacer,
|
Spacer,
|
||||||
Spinner,
|
Spinner,
|
||||||
TextAreaInput,
|
TableColumn,
|
||||||
TextInput,
|
TextInput,
|
||||||
Title,
|
Title,
|
||||||
Toggle,
|
|
||||||
WheelZoomTool,
|
WheelZoomTool,
|
||||||
)
|
)
|
||||||
from bokeh.palettes import Cividis256, Greys256, Plasma256 # pylint: disable=E0611
|
from bokeh.palettes import Cividis256, Greys256, Plasma256 # pylint: disable=E0611
|
||||||
|
from scipy.optimize import curve_fit
|
||||||
|
|
||||||
import pyzebra
|
import pyzebra
|
||||||
|
|
||||||
IMAGE_W = 256
|
IMAGE_W = 256
|
||||||
IMAGE_H = 128
|
IMAGE_H = 128
|
||||||
IMAGE_PLOT_W = int(IMAGE_W * 2.5)
|
IMAGE_PLOT_W = int(IMAGE_W * 2) + 52
|
||||||
IMAGE_PLOT_H = int(IMAGE_H * 2.5)
|
IMAGE_PLOT_H = int(IMAGE_H * 2) + 27
|
||||||
|
|
||||||
PROPOSAL_PATH = "/afs/psi.ch/project/sinqdata/2020/zebra/"
|
|
||||||
|
|
||||||
|
|
||||||
def create():
|
def create():
|
||||||
|
doc = curdoc()
|
||||||
det_data = {}
|
det_data = {}
|
||||||
roi_selection = {}
|
cami_meta = {}
|
||||||
|
|
||||||
|
num_formatter = NumberFormatter(format="0.00", nan_format="")
|
||||||
|
|
||||||
|
def file_select_update_for_proposal():
|
||||||
|
proposal = proposal_textinput.value.strip()
|
||||||
|
if not proposal:
|
||||||
|
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}'.")
|
||||||
|
|
||||||
def proposal_textinput_callback(_attr, _old, new):
|
|
||||||
full_proposal_path = os.path.join(PROPOSAL_PATH, new.strip())
|
|
||||||
file_list = []
|
file_list = []
|
||||||
for file in os.listdir(full_proposal_path):
|
for file in os.listdir(proposal_path):
|
||||||
if file.endswith(".hdf"):
|
if file.endswith(".hdf"):
|
||||||
file_list.append((os.path.join(full_proposal_path, file), file))
|
file_list.append((os.path.join(proposal_path, file), file))
|
||||||
filelist.options = file_list
|
file_select.options = file_list
|
||||||
filelist.value = file_list[0][0]
|
|
||||||
|
|
||||||
proposal_textinput = TextInput(title="Enter proposal number:", default_size=145)
|
doc.add_periodic_callback(file_select_update_for_proposal, 5000)
|
||||||
|
|
||||||
|
def proposal_textinput_callback(_attr, _old, _new):
|
||||||
|
nonlocal cami_meta
|
||||||
|
cami_meta = {}
|
||||||
|
file_select_update_for_proposal()
|
||||||
|
|
||||||
|
proposal_textinput = TextInput(title="Proposal number:", width=210)
|
||||||
proposal_textinput.on_change("value", proposal_textinput_callback)
|
proposal_textinput.on_change("value", proposal_textinput_callback)
|
||||||
|
|
||||||
def upload_button_callback(_attr, _old, new):
|
def upload_button_callback(_attr, _old, new):
|
||||||
|
nonlocal cami_meta
|
||||||
|
proposal_textinput.value = ""
|
||||||
with io.StringIO(base64.b64decode(new).decode()) as file:
|
with io.StringIO(base64.b64decode(new).decode()) as file:
|
||||||
h5meta_list = pyzebra.parse_h5meta(file)
|
cami_meta = pyzebra.parse_h5meta(file)
|
||||||
file_list = h5meta_list["filelist"]
|
file_list = cami_meta["filelist"]
|
||||||
filelist.options = [(entry, os.path.basename(entry)) for entry in file_list]
|
file_select.options = [(entry, os.path.basename(entry)) for entry in file_list]
|
||||||
filelist.value = file_list[0]
|
|
||||||
|
|
||||||
upload_div = Div(text="or upload .cami file:", margin=(5, 5, 0, 5))
|
upload_div = Div(text="or upload .cami file:", margin=(5, 5, 0, 5))
|
||||||
upload_button = FileInput(accept=".cami")
|
upload_button = FileInput(accept=".cami", width=200)
|
||||||
upload_button.on_change("value", upload_button_callback)
|
upload_button.on_change("value", upload_button_callback)
|
||||||
|
|
||||||
def update_image(index=None):
|
def update_image(index=None):
|
||||||
@ -91,7 +117,7 @@ def create():
|
|||||||
)
|
)
|
||||||
image_source.data.update(image=[current_image])
|
image_source.data.update(image=[current_image])
|
||||||
|
|
||||||
if auto_toggle.active:
|
if main_auto_checkbox.active:
|
||||||
im_min = np.min(current_image)
|
im_min = np.min(current_image)
|
||||||
im_max = np.max(current_image)
|
im_max = np.max(current_image)
|
||||||
|
|
||||||
@ -102,14 +128,14 @@ def create():
|
|||||||
image_glyph.color_mapper.high = im_max
|
image_glyph.color_mapper.high = im_max
|
||||||
|
|
||||||
if "mf" in det_data:
|
if "mf" in det_data:
|
||||||
mf_spinner.value = det_data["mf"][index]
|
metadata_table_source.data.update(mf=[det_data["mf"][index]])
|
||||||
else:
|
else:
|
||||||
mf_spinner.value = None
|
metadata_table_source.data.update(mf=[None])
|
||||||
|
|
||||||
if "temp" in det_data:
|
if "temp" in det_data:
|
||||||
temp_spinner.value = det_data["temp"][index]
|
metadata_table_source.data.update(temp=[det_data["temp"][index]])
|
||||||
else:
|
else:
|
||||||
temp_spinner.value = None
|
metadata_table_source.data.update(temp=[None])
|
||||||
|
|
||||||
gamma, nu = calculate_pol(det_data, index)
|
gamma, nu = calculate_pol(det_data, index)
|
||||||
omega = np.ones((IMAGE_H, IMAGE_W)) * det_data["omega"][index]
|
omega = np.ones((IMAGE_H, IMAGE_W)) * det_data["omega"][index]
|
||||||
@ -121,10 +147,10 @@ def create():
|
|||||||
overview_x = np.mean(h5_data, axis=1)
|
overview_x = np.mean(h5_data, axis=1)
|
||||||
overview_y = np.mean(h5_data, axis=2)
|
overview_y = np.mean(h5_data, axis=2)
|
||||||
|
|
||||||
overview_plot_x_image_source.data.update(image=[overview_x], dw=[n_x])
|
overview_plot_x_image_source.data.update(image=[overview_x], dw=[n_x], dh=[n_im])
|
||||||
overview_plot_y_image_source.data.update(image=[overview_y], dw=[n_y])
|
overview_plot_y_image_source.data.update(image=[overview_y], dw=[n_y], dh=[n_im])
|
||||||
|
|
||||||
if proj_auto_toggle.active:
|
if proj_auto_checkbox.active:
|
||||||
im_min = min(np.min(overview_x), np.min(overview_y))
|
im_min = min(np.min(overview_x), np.min(overview_y))
|
||||||
im_max = max(np.max(overview_x), np.max(overview_y))
|
im_max = max(np.max(overview_x), np.max(overview_y))
|
||||||
|
|
||||||
@ -136,48 +162,70 @@ def create():
|
|||||||
overview_plot_x_image_glyph.color_mapper.high = im_max
|
overview_plot_x_image_glyph.color_mapper.high = im_max
|
||||||
overview_plot_y_image_glyph.color_mapper.high = im_max
|
overview_plot_y_image_glyph.color_mapper.high = im_max
|
||||||
|
|
||||||
if frame_button_group.active == 0: # Frame
|
frame_range.start = 0
|
||||||
overview_plot_x.axis[1].axis_label = "Frame"
|
frame_range.end = n_im
|
||||||
overview_plot_y.axis[1].axis_label = "Frame"
|
frame_range.reset_start = 0
|
||||||
|
frame_range.reset_end = n_im
|
||||||
|
frame_range.bounds = (0, n_im)
|
||||||
|
|
||||||
overview_plot_x_image_source.data.update(y=[0], dh=[n_im])
|
scan_motor = det_data["scan_motor"]
|
||||||
overview_plot_y_image_source.data.update(y=[0], dh=[n_im])
|
overview_plot_y.axis[1].axis_label = f"Scanning motor, {scan_motor}"
|
||||||
|
|
||||||
elif frame_button_group.active == 1: # Variable angle
|
var = det_data[scan_motor]
|
||||||
scan_motor = det_data["scan_motor"]
|
var_start = var[0]
|
||||||
overview_plot_x.axis[1].axis_label = scan_motor
|
var_end = var[-1] + (var[-1] - var[0]) / (n_im - 1)
|
||||||
overview_plot_y.axis[1].axis_label = scan_motor
|
|
||||||
|
|
||||||
var = det_data[scan_motor]
|
scanning_motor_range.start = var_start
|
||||||
var_start = var[0]
|
scanning_motor_range.end = var_end
|
||||||
var_end = (var[-1] - var[0]) * n_im / (n_im - 1)
|
scanning_motor_range.reset_start = var_start
|
||||||
overview_plot_x_image_source.data.update(y=[var_start], dh=[var_end])
|
scanning_motor_range.reset_end = var_end
|
||||||
overview_plot_y_image_source.data.update(y=[var_start], dh=[var_end])
|
# handle both, ascending and descending sequences
|
||||||
|
scanning_motor_range.bounds = (min(var_start, var_end), max(var_start, var_end))
|
||||||
|
|
||||||
def filelist_callback(_attr, _old, new):
|
def file_select_callback(_attr, old, new):
|
||||||
nonlocal det_data
|
nonlocal det_data
|
||||||
det_data = pyzebra.read_detector_data(new)
|
if not new:
|
||||||
|
# skip empty selections
|
||||||
|
return
|
||||||
|
|
||||||
|
# Avoid selection of multiple indicies (via Shift+Click or Ctrl+Click)
|
||||||
|
if len(new) > 1:
|
||||||
|
# drop selection to the previous one
|
||||||
|
file_select.value = old
|
||||||
|
return
|
||||||
|
|
||||||
|
if len(old) > 1:
|
||||||
|
# skip unnecessary update caused by selection drop
|
||||||
|
return
|
||||||
|
|
||||||
|
det_data = pyzebra.read_detector_data(new[0], cami_meta)
|
||||||
|
|
||||||
index_spinner.value = 0
|
index_spinner.value = 0
|
||||||
index_spinner.high = det_data["data"].shape[0] - 1
|
index_spinner.high = det_data["data"].shape[0] - 1
|
||||||
|
index_slider.end = det_data["data"].shape[0] - 1
|
||||||
|
|
||||||
zebra_mode = det_data["zebra_mode"]
|
zebra_mode = det_data["zebra_mode"]
|
||||||
if zebra_mode == "nb":
|
if zebra_mode == "nb":
|
||||||
geometry_textinput.value = "normal beam"
|
metadata_table_source.data.update(geom=["normal beam"])
|
||||||
else: # zebra_mode == "bi"
|
else: # zebra_mode == "bi"
|
||||||
geometry_textinput.value = "bisecting"
|
metadata_table_source.data.update(geom=["bisecting"])
|
||||||
|
|
||||||
update_image(0)
|
update_image(0)
|
||||||
update_overview_plot()
|
update_overview_plot()
|
||||||
|
|
||||||
filelist = Select(title="Available .hdf files:")
|
file_select = MultiSelect(title="Available .hdf files:", width=210, height=250)
|
||||||
filelist.on_change("value", filelist_callback)
|
file_select.on_change("value", file_select_callback)
|
||||||
|
|
||||||
def index_spinner_callback(_attr, _old, new):
|
def index_callback(_attr, _old, new):
|
||||||
update_image(new)
|
update_image(new)
|
||||||
|
|
||||||
index_spinner = Spinner(title="Image index:", value=0, low=0)
|
index_slider = Slider(value=0, start=0, end=1, show_value=False, width=400)
|
||||||
index_spinner.on_change("value", index_spinner_callback)
|
|
||||||
|
index_spinner = Spinner(title="Image index:", value=0, low=0, width=100)
|
||||||
|
index_spinner.on_change("value", index_callback)
|
||||||
|
|
||||||
|
index_slider.js_link("value_throttled", index_spinner, "value")
|
||||||
|
index_spinner.js_link("value", index_slider, "value")
|
||||||
|
|
||||||
plot = Plot(
|
plot = Plot(
|
||||||
x_range=Range1d(0, IMAGE_W, bounds=(0, IMAGE_W)),
|
x_range=Range1d(0, IMAGE_W, bounds=(0, IMAGE_W)),
|
||||||
@ -232,6 +280,15 @@ def create():
|
|||||||
image_glyph = Image(image="image", x="x", y="y", dw="dw", dh="dh")
|
image_glyph = Image(image="image", x="x", y="y", dw="dw", dh="dh")
|
||||||
plot.add_glyph(image_source, image_glyph, name="image_glyph")
|
plot.add_glyph(image_source, image_glyph, name="image_glyph")
|
||||||
|
|
||||||
|
# calculate hkl-indices of first mouse entry
|
||||||
|
def mouse_enter_callback(_event):
|
||||||
|
if det_data and np.array_equal(image_source.data["h"][0], np.zeros((1, 1))):
|
||||||
|
index = index_spinner.value
|
||||||
|
h, k, l = calculate_hkl(det_data, index)
|
||||||
|
image_source.data.update(h=[h], k=[k], l=[l])
|
||||||
|
|
||||||
|
plot.on_event(MouseEnter, mouse_enter_callback)
|
||||||
|
|
||||||
# ---- projections
|
# ---- projections
|
||||||
proj_v = Plot(
|
proj_v = Plot(
|
||||||
x_range=plot.x_range,
|
x_range=plot.x_range,
|
||||||
@ -310,15 +367,18 @@ def create():
|
|||||||
)
|
)
|
||||||
plot.toolbar.active_scroll = wheelzoomtool
|
plot.toolbar.active_scroll = wheelzoomtool
|
||||||
|
|
||||||
# shared frame range
|
# shared frame ranges
|
||||||
frame_range = DataRange1d()
|
frame_range = Range1d(0, 1, bounds=(0, 1))
|
||||||
|
scanning_motor_range = Range1d(0, 1, bounds=(0, 1))
|
||||||
|
|
||||||
det_x_range = Range1d(0, IMAGE_W, bounds=(0, IMAGE_W))
|
det_x_range = Range1d(0, IMAGE_W, bounds=(0, IMAGE_W))
|
||||||
overview_plot_x = Plot(
|
overview_plot_x = Plot(
|
||||||
title=Title(text="Projections on X-axis"),
|
title=Title(text="Projections on X-axis"),
|
||||||
x_range=det_x_range,
|
x_range=det_x_range,
|
||||||
y_range=frame_range,
|
y_range=frame_range,
|
||||||
|
extra_y_ranges={"scanning_motor": scanning_motor_range},
|
||||||
plot_height=400,
|
plot_height=400,
|
||||||
plot_width=IMAGE_PLOT_W,
|
plot_width=IMAGE_PLOT_W - 3,
|
||||||
)
|
)
|
||||||
|
|
||||||
# ---- tools
|
# ---- tools
|
||||||
@ -354,8 +414,9 @@ def create():
|
|||||||
title=Title(text="Projections on Y-axis"),
|
title=Title(text="Projections on Y-axis"),
|
||||||
x_range=det_y_range,
|
x_range=det_y_range,
|
||||||
y_range=frame_range,
|
y_range=frame_range,
|
||||||
|
extra_y_ranges={"scanning_motor": scanning_motor_range},
|
||||||
plot_height=400,
|
plot_height=400,
|
||||||
plot_width=IMAGE_PLOT_H,
|
plot_width=IMAGE_PLOT_H + 22,
|
||||||
)
|
)
|
||||||
|
|
||||||
# ---- tools
|
# ---- tools
|
||||||
@ -369,7 +430,12 @@ def create():
|
|||||||
# ---- axes
|
# ---- axes
|
||||||
overview_plot_y.add_layout(LinearAxis(axis_label="Coordinate Y, pix"), place="below")
|
overview_plot_y.add_layout(LinearAxis(axis_label="Coordinate Y, pix"), place="below")
|
||||||
overview_plot_y.add_layout(
|
overview_plot_y.add_layout(
|
||||||
LinearAxis(axis_label="Frame", major_label_orientation="vertical"), place="left"
|
LinearAxis(
|
||||||
|
y_range_name="scanning_motor",
|
||||||
|
axis_label="Scanning motor",
|
||||||
|
major_label_orientation="vertical",
|
||||||
|
),
|
||||||
|
place="right",
|
||||||
)
|
)
|
||||||
|
|
||||||
# ---- grid lines
|
# ---- grid lines
|
||||||
@ -386,16 +452,10 @@ def create():
|
|||||||
overview_plot_y_image_source, overview_plot_y_image_glyph, name="image_glyph"
|
overview_plot_y_image_source, overview_plot_y_image_glyph, name="image_glyph"
|
||||||
)
|
)
|
||||||
|
|
||||||
def frame_button_group_callback(_active):
|
|
||||||
update_overview_plot()
|
|
||||||
|
|
||||||
frame_button_group = RadioButtonGroup(labels=["Frames", "Variable Angle"], active=0)
|
|
||||||
frame_button_group.on_click(frame_button_group_callback)
|
|
||||||
|
|
||||||
roi_avg_plot = Plot(
|
roi_avg_plot = Plot(
|
||||||
x_range=DataRange1d(),
|
x_range=DataRange1d(),
|
||||||
y_range=DataRange1d(),
|
y_range=DataRange1d(),
|
||||||
plot_height=200,
|
plot_height=150,
|
||||||
plot_width=IMAGE_PLOT_W,
|
plot_width=IMAGE_PLOT_W,
|
||||||
toolbar_location="left",
|
toolbar_location="left",
|
||||||
)
|
)
|
||||||
@ -426,13 +486,13 @@ def create():
|
|||||||
overview_plot_x_image_glyph.color_mapper = LinearColorMapper(palette=cmap_dict[new])
|
overview_plot_x_image_glyph.color_mapper = LinearColorMapper(palette=cmap_dict[new])
|
||||||
overview_plot_y_image_glyph.color_mapper = LinearColorMapper(palette=cmap_dict[new])
|
overview_plot_y_image_glyph.color_mapper = LinearColorMapper(palette=cmap_dict[new])
|
||||||
|
|
||||||
colormap = Select(title="Colormap:", options=list(cmap_dict.keys()), default_size=145)
|
colormap = Select(title="Colormap:", options=list(cmap_dict.keys()), width=210)
|
||||||
colormap.on_change("value", colormap_callback)
|
colormap.on_change("value", colormap_callback)
|
||||||
colormap.value = "plasma"
|
colormap.value = "plasma"
|
||||||
|
|
||||||
STEP = 1
|
STEP = 1
|
||||||
# ---- colormap auto toggle button
|
|
||||||
def auto_toggle_callback(state):
|
def main_auto_checkbox_callback(state):
|
||||||
if state:
|
if state:
|
||||||
display_min_spinner.disabled = True
|
display_min_spinner.disabled = True
|
||||||
display_max_spinner.disabled = True
|
display_max_spinner.disabled = True
|
||||||
@ -442,45 +502,43 @@ def create():
|
|||||||
|
|
||||||
update_image()
|
update_image()
|
||||||
|
|
||||||
auto_toggle = Toggle(
|
main_auto_checkbox = CheckboxGroup(
|
||||||
label="Main Auto Range", active=True, button_type="default", default_size=125
|
labels=["Frame Intensity Range"], active=[0], width=145, margin=[10, 5, 0, 5]
|
||||||
)
|
)
|
||||||
auto_toggle.on_click(auto_toggle_callback)
|
main_auto_checkbox.on_click(main_auto_checkbox_callback)
|
||||||
|
|
||||||
# ---- colormap display max value
|
|
||||||
def display_max_spinner_callback(_attr, _old_value, new_value):
|
def display_max_spinner_callback(_attr, _old_value, new_value):
|
||||||
display_min_spinner.high = new_value - STEP
|
display_min_spinner.high = new_value - STEP
|
||||||
image_glyph.color_mapper.high = new_value
|
image_glyph.color_mapper.high = new_value
|
||||||
|
|
||||||
display_max_spinner = Spinner(
|
display_max_spinner = Spinner(
|
||||||
title="Max Value:",
|
|
||||||
low=0 + STEP,
|
low=0 + STEP,
|
||||||
value=1,
|
value=1,
|
||||||
step=STEP,
|
step=STEP,
|
||||||
disabled=auto_toggle.active,
|
disabled=bool(main_auto_checkbox.active),
|
||||||
default_size=80,
|
width=100,
|
||||||
|
height=31,
|
||||||
)
|
)
|
||||||
display_max_spinner.on_change("value", display_max_spinner_callback)
|
display_max_spinner.on_change("value", display_max_spinner_callback)
|
||||||
|
|
||||||
# ---- colormap display min value
|
|
||||||
def display_min_spinner_callback(_attr, _old_value, new_value):
|
def display_min_spinner_callback(_attr, _old_value, new_value):
|
||||||
display_max_spinner.low = new_value + STEP
|
display_max_spinner.low = new_value + STEP
|
||||||
image_glyph.color_mapper.low = new_value
|
image_glyph.color_mapper.low = new_value
|
||||||
|
|
||||||
display_min_spinner = Spinner(
|
display_min_spinner = Spinner(
|
||||||
title="Min Value:",
|
|
||||||
low=0,
|
low=0,
|
||||||
high=1 - STEP,
|
high=1 - STEP,
|
||||||
value=0,
|
value=0,
|
||||||
step=STEP,
|
step=STEP,
|
||||||
disabled=auto_toggle.active,
|
disabled=bool(main_auto_checkbox.active),
|
||||||
default_size=80,
|
width=100,
|
||||||
|
height=31,
|
||||||
)
|
)
|
||||||
display_min_spinner.on_change("value", display_min_spinner_callback)
|
display_min_spinner.on_change("value", display_min_spinner_callback)
|
||||||
|
|
||||||
PROJ_STEP = 0.1
|
PROJ_STEP = 0.1
|
||||||
# ---- proj colormap auto toggle button
|
|
||||||
def proj_auto_toggle_callback(state):
|
def proj_auto_checkbox_callback(state):
|
||||||
if state:
|
if state:
|
||||||
proj_display_min_spinner.disabled = True
|
proj_display_min_spinner.disabled = True
|
||||||
proj_display_max_spinner.disabled = True
|
proj_display_max_spinner.disabled = True
|
||||||
@ -490,102 +548,197 @@ def create():
|
|||||||
|
|
||||||
update_overview_plot()
|
update_overview_plot()
|
||||||
|
|
||||||
proj_auto_toggle = Toggle(
|
proj_auto_checkbox = CheckboxGroup(
|
||||||
label="Proj Auto Range", active=True, button_type="default", default_size=125
|
labels=["Projections Intensity Range"], active=[0], width=145, margin=[10, 5, 0, 5]
|
||||||
)
|
)
|
||||||
proj_auto_toggle.on_click(proj_auto_toggle_callback)
|
proj_auto_checkbox.on_click(proj_auto_checkbox_callback)
|
||||||
|
|
||||||
# ---- proj colormap display max value
|
|
||||||
def proj_display_max_spinner_callback(_attr, _old_value, new_value):
|
def proj_display_max_spinner_callback(_attr, _old_value, new_value):
|
||||||
proj_display_min_spinner.high = new_value - PROJ_STEP
|
proj_display_min_spinner.high = new_value - PROJ_STEP
|
||||||
overview_plot_x_image_glyph.color_mapper.high = new_value
|
overview_plot_x_image_glyph.color_mapper.high = new_value
|
||||||
overview_plot_y_image_glyph.color_mapper.high = new_value
|
overview_plot_y_image_glyph.color_mapper.high = new_value
|
||||||
|
|
||||||
proj_display_max_spinner = Spinner(
|
proj_display_max_spinner = Spinner(
|
||||||
title="Max Value:",
|
|
||||||
low=0 + PROJ_STEP,
|
low=0 + PROJ_STEP,
|
||||||
value=1,
|
value=1,
|
||||||
step=PROJ_STEP,
|
step=PROJ_STEP,
|
||||||
disabled=proj_auto_toggle.active,
|
disabled=bool(proj_auto_checkbox.active),
|
||||||
default_size=80,
|
width=100,
|
||||||
|
height=31,
|
||||||
)
|
)
|
||||||
proj_display_max_spinner.on_change("value", proj_display_max_spinner_callback)
|
proj_display_max_spinner.on_change("value", proj_display_max_spinner_callback)
|
||||||
|
|
||||||
# ---- proj colormap display min value
|
|
||||||
def proj_display_min_spinner_callback(_attr, _old_value, new_value):
|
def proj_display_min_spinner_callback(_attr, _old_value, new_value):
|
||||||
proj_display_max_spinner.low = new_value + PROJ_STEP
|
proj_display_max_spinner.low = new_value + PROJ_STEP
|
||||||
overview_plot_x_image_glyph.color_mapper.low = new_value
|
overview_plot_x_image_glyph.color_mapper.low = new_value
|
||||||
overview_plot_y_image_glyph.color_mapper.low = new_value
|
overview_plot_y_image_glyph.color_mapper.low = new_value
|
||||||
|
|
||||||
proj_display_min_spinner = Spinner(
|
proj_display_min_spinner = Spinner(
|
||||||
title="Min Value:",
|
|
||||||
low=0,
|
low=0,
|
||||||
high=1 - PROJ_STEP,
|
high=1 - PROJ_STEP,
|
||||||
value=0,
|
value=0,
|
||||||
step=PROJ_STEP,
|
step=PROJ_STEP,
|
||||||
disabled=proj_auto_toggle.active,
|
disabled=bool(proj_auto_checkbox.active),
|
||||||
default_size=80,
|
width=100,
|
||||||
|
height=31,
|
||||||
)
|
)
|
||||||
proj_display_min_spinner.on_change("value", proj_display_min_spinner_callback)
|
proj_display_min_spinner.on_change("value", proj_display_min_spinner_callback)
|
||||||
|
|
||||||
def hkl_button_callback():
|
events_data = dict(
|
||||||
index = index_spinner.value
|
wave=[],
|
||||||
h, k, l = calculate_hkl(det_data, index)
|
ddist=[],
|
||||||
image_source.data.update(h=[h], k=[k], l=[l])
|
cell=[],
|
||||||
|
frame=[],
|
||||||
hkl_button = Button(label="Calculate hkl (slow)")
|
x_pos=[],
|
||||||
hkl_button.on_click(hkl_button_callback)
|
y_pos=[],
|
||||||
|
intensity=[],
|
||||||
selection_list = TextAreaInput(rows=7)
|
snr_cnts=[],
|
||||||
|
gamma=[],
|
||||||
def selection_button_callback():
|
omega=[],
|
||||||
nonlocal roi_selection
|
chi=[],
|
||||||
selection = [
|
phi=[],
|
||||||
int(np.floor(det_x_range.start)),
|
nu=[],
|
||||||
int(np.ceil(det_x_range.end)),
|
)
|
||||||
int(np.floor(det_y_range.start)),
|
doc.events_data = events_data
|
||||||
int(np.ceil(det_y_range.end)),
|
|
||||||
int(np.floor(frame_range.start)),
|
events_table_source = ColumnDataSource(events_data)
|
||||||
int(np.ceil(frame_range.end)),
|
events_table = DataTable(
|
||||||
]
|
source=events_table_source,
|
||||||
|
columns=[
|
||||||
filename_id = filelist.value[-8:-4]
|
TableColumn(field="frame", title="Frame", formatter=num_formatter, width=70),
|
||||||
if filename_id in roi_selection:
|
TableColumn(field="x_pos", title="X", formatter=num_formatter, width=70),
|
||||||
roi_selection[f"{filename_id}"].append(selection)
|
TableColumn(field="y_pos", title="Y", formatter=num_formatter, width=70),
|
||||||
else:
|
TableColumn(field="intensity", title="Intensity", formatter=num_formatter, width=70),
|
||||||
roi_selection[f"{filename_id}"] = [selection]
|
TableColumn(field="gamma", title="Gamma", formatter=num_formatter, width=70),
|
||||||
|
TableColumn(field="omega", title="Omega", formatter=num_formatter, width=70),
|
||||||
selection_list.value = str(roi_selection)
|
TableColumn(field="chi", title="Chi", formatter=num_formatter, width=70),
|
||||||
|
TableColumn(field="phi", title="Phi", formatter=num_formatter, width=70),
|
||||||
selection_button = Button(label="Add selection")
|
TableColumn(field="nu", title="Nu", formatter=num_formatter, width=70),
|
||||||
selection_button.on_click(selection_button_callback)
|
],
|
||||||
|
height=150,
|
||||||
mf_spinner = Spinner(
|
width=630,
|
||||||
title="Magnetic field:", format="0.00", width=145, disabled=True
|
autosize_mode="none",
|
||||||
|
index_position=None,
|
||||||
|
)
|
||||||
|
|
||||||
|
def add_event_button_callback():
|
||||||
|
p0 = [1.0, 0.0, 1.0]
|
||||||
|
maxfev = 100000
|
||||||
|
|
||||||
|
wave = det_data["wave"]
|
||||||
|
ddist = det_data["ddist"]
|
||||||
|
cell = det_data["cell"]
|
||||||
|
|
||||||
|
gamma = det_data["gamma"][0]
|
||||||
|
omega = det_data["omega"][0]
|
||||||
|
nu = det_data["nu"][0]
|
||||||
|
chi = det_data["chi"][0]
|
||||||
|
phi = det_data["phi"][0]
|
||||||
|
|
||||||
|
scan_motor = det_data["scan_motor"]
|
||||||
|
var_angle = det_data[scan_motor]
|
||||||
|
|
||||||
|
x0 = int(np.floor(det_x_range.start))
|
||||||
|
xN = int(np.ceil(det_x_range.end))
|
||||||
|
y0 = int(np.floor(det_y_range.start))
|
||||||
|
yN = int(np.ceil(det_y_range.end))
|
||||||
|
fr0 = int(np.floor(frame_range.start))
|
||||||
|
frN = int(np.ceil(frame_range.end))
|
||||||
|
data_roi = det_data["data"][fr0:frN, y0:yN, x0:xN]
|
||||||
|
|
||||||
|
cnts = np.sum(data_roi, axis=(1, 2))
|
||||||
|
coeff, _ = curve_fit(gauss, range(len(cnts)), cnts, p0=p0, maxfev=maxfev)
|
||||||
|
|
||||||
|
m = cnts.mean()
|
||||||
|
sd = cnts.std()
|
||||||
|
snr_cnts = np.where(sd == 0, 0, m / sd)
|
||||||
|
|
||||||
|
frC = fr0 + coeff[1]
|
||||||
|
var_F = var_angle[math.floor(frC)]
|
||||||
|
var_C = var_angle[math.ceil(frC)]
|
||||||
|
frStep = frC - math.floor(frC)
|
||||||
|
var_step = var_C - var_F
|
||||||
|
var_p = var_F + var_step * frStep
|
||||||
|
|
||||||
|
if scan_motor == "gamma":
|
||||||
|
gamma = var_p
|
||||||
|
elif scan_motor == "omega":
|
||||||
|
omega = var_p
|
||||||
|
elif scan_motor == "nu":
|
||||||
|
nu = var_p
|
||||||
|
elif scan_motor == "chi":
|
||||||
|
chi = var_p
|
||||||
|
elif scan_motor == "phi":
|
||||||
|
phi = var_p
|
||||||
|
|
||||||
|
intensity = coeff[1] * abs(coeff[2] * var_step) * math.sqrt(2) * math.sqrt(np.pi)
|
||||||
|
|
||||||
|
projX = np.sum(data_roi, axis=(0, 1))
|
||||||
|
coeff, _ = curve_fit(gauss, range(len(projX)), projX, p0=p0, maxfev=maxfev)
|
||||||
|
x_pos = x0 + coeff[1]
|
||||||
|
|
||||||
|
projY = np.sum(data_roi, axis=(0, 2))
|
||||||
|
coeff, _ = curve_fit(gauss, range(len(projY)), projY, p0=p0, maxfev=maxfev)
|
||||||
|
y_pos = y0 + coeff[1]
|
||||||
|
|
||||||
|
events_data["wave"].append(wave)
|
||||||
|
events_data["ddist"].append(ddist)
|
||||||
|
events_data["cell"].append(cell)
|
||||||
|
events_data["frame"].append(frC)
|
||||||
|
events_data["x_pos"].append(x_pos)
|
||||||
|
events_data["y_pos"].append(y_pos)
|
||||||
|
events_data["intensity"].append(intensity)
|
||||||
|
events_data["snr_cnts"].append(snr_cnts)
|
||||||
|
events_data["gamma"].append(gamma)
|
||||||
|
events_data["omega"].append(omega)
|
||||||
|
events_data["chi"].append(chi)
|
||||||
|
events_data["phi"].append(phi)
|
||||||
|
events_data["nu"].append(nu)
|
||||||
|
|
||||||
|
events_table_source.data = events_data
|
||||||
|
|
||||||
|
add_event_button = Button(label="Add spind event", width=145)
|
||||||
|
add_event_button.on_click(add_event_button_callback)
|
||||||
|
|
||||||
|
def remove_event_button_callback():
|
||||||
|
ind2remove = events_table_source.selected.indices
|
||||||
|
for value in events_data.values():
|
||||||
|
for ind in reversed(ind2remove):
|
||||||
|
del value[ind]
|
||||||
|
|
||||||
|
events_table_source.data = events_data
|
||||||
|
|
||||||
|
remove_event_button = Button(label="Remove spind event", width=145)
|
||||||
|
remove_event_button.on_click(remove_event_button_callback)
|
||||||
|
|
||||||
|
metadata_table_source = ColumnDataSource(dict(geom=[""], temp=[None], mf=[None]))
|
||||||
|
metadata_table = DataTable(
|
||||||
|
source=metadata_table_source,
|
||||||
|
columns=[
|
||||||
|
TableColumn(field="geom", title="Geometry", width=100),
|
||||||
|
TableColumn(field="temp", title="Temperature", formatter=num_formatter, width=100),
|
||||||
|
TableColumn(field="mf", title="Magnetic Field", formatter=num_formatter, width=100),
|
||||||
|
],
|
||||||
|
width=300,
|
||||||
|
height=50,
|
||||||
|
autosize_mode="none",
|
||||||
|
index_position=None,
|
||||||
)
|
)
|
||||||
temp_spinner = Spinner(title="Temperature:", format="0.00", width=145, disabled=True)
|
|
||||||
geometry_textinput = TextInput(title="Geometry:", disabled=True)
|
|
||||||
|
|
||||||
# Final layout
|
# Final layout
|
||||||
|
import_layout = column(proposal_textinput, upload_div, upload_button, file_select)
|
||||||
layout_image = column(gridplot([[proj_v, None], [plot, proj_h]], merge_tools=False))
|
layout_image = column(gridplot([[proj_v, None], [plot, proj_h]], merge_tools=False))
|
||||||
colormap_layout = column(
|
colormap_layout = column(
|
||||||
row(colormap),
|
colormap,
|
||||||
row(column(Spacer(height=19), auto_toggle), display_max_spinner, display_min_spinner),
|
main_auto_checkbox,
|
||||||
row(
|
row(display_min_spinner, display_max_spinner),
|
||||||
column(Spacer(height=19), proj_auto_toggle),
|
proj_auto_checkbox,
|
||||||
proj_display_max_spinner,
|
row(proj_display_min_spinner, proj_display_max_spinner),
|
||||||
proj_display_min_spinner,
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
hkl_layout = column(geometry_textinput, hkl_button)
|
|
||||||
params_layout = row(mf_spinner, temp_spinner)
|
|
||||||
|
|
||||||
layout_controls = row(
|
layout_controls = column(
|
||||||
column(selection_button, selection_list),
|
row(metadata_table, index_spinner, column(Spacer(height=25), index_slider)),
|
||||||
Spacer(width=20),
|
row(column(add_event_button, remove_event_button), events_table),
|
||||||
column(frame_button_group, colormap_layout),
|
|
||||||
Spacer(width=20),
|
|
||||||
column(index_spinner, params_layout, hkl_layout),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
layout_overview = column(
|
layout_overview = column(
|
||||||
@ -598,19 +751,25 @@ def create():
|
|||||||
)
|
)
|
||||||
|
|
||||||
tab_layout = row(
|
tab_layout = row(
|
||||||
column(
|
column(import_layout, colormap_layout),
|
||||||
row(
|
column(layout_overview, layout_controls),
|
||||||
proposal_textinput, filelist, Spacer(width=100), column(upload_div, upload_button),
|
|
||||||
),
|
|
||||||
layout_overview,
|
|
||||||
layout_controls,
|
|
||||||
),
|
|
||||||
column(roi_avg_plot, layout_image),
|
column(roi_avg_plot, layout_image),
|
||||||
)
|
)
|
||||||
|
|
||||||
return Panel(child=tab_layout, title="hdf viewer")
|
return Panel(child=tab_layout, title="hdf viewer")
|
||||||
|
|
||||||
|
|
||||||
|
def gauss(x, *p):
|
||||||
|
"""Defines Gaussian function
|
||||||
|
Args:
|
||||||
|
A - amplitude, mu - position of the center, sigma - width
|
||||||
|
Returns:
|
||||||
|
Gaussian function
|
||||||
|
"""
|
||||||
|
A, mu, sigma = p
|
||||||
|
return A * np.exp(-((x - mu) ** 2) / (2.0 * sigma ** 2))
|
||||||
|
|
||||||
|
|
||||||
def calculate_hkl(det_data, index):
|
def calculate_hkl(det_data, index):
|
||||||
h = np.empty(shape=(IMAGE_H, IMAGE_W))
|
h = np.empty(shape=(IMAGE_H, IMAGE_W))
|
||||||
k = np.empty(shape=(IMAGE_H, IMAGE_W))
|
k = np.empty(shape=(IMAGE_H, IMAGE_W))
|
||||||
|
@ -6,11 +6,13 @@ import tempfile
|
|||||||
import types
|
import types
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
from bokeh.io import curdoc
|
||||||
from bokeh.layouts import column, row
|
from bokeh.layouts import column, row
|
||||||
from bokeh.models import (
|
from bokeh.models import (
|
||||||
BasicTicker,
|
BasicTicker,
|
||||||
Button,
|
Button,
|
||||||
CheckboxEditor,
|
CheckboxEditor,
|
||||||
|
CheckboxGroup,
|
||||||
ColumnDataSource,
|
ColumnDataSource,
|
||||||
CustomJS,
|
CustomJS,
|
||||||
DataRange1d,
|
DataRange1d,
|
||||||
@ -20,6 +22,7 @@ from bokeh.models import (
|
|||||||
FileInput,
|
FileInput,
|
||||||
Grid,
|
Grid,
|
||||||
HoverTool,
|
HoverTool,
|
||||||
|
Image,
|
||||||
Legend,
|
Legend,
|
||||||
Line,
|
Line,
|
||||||
LinearAxis,
|
LinearAxis,
|
||||||
@ -29,7 +32,7 @@ from bokeh.models import (
|
|||||||
Panel,
|
Panel,
|
||||||
PanTool,
|
PanTool,
|
||||||
Plot,
|
Plot,
|
||||||
RadioButtonGroup,
|
RadioGroup,
|
||||||
ResetTool,
|
ResetTool,
|
||||||
Scatter,
|
Scatter,
|
||||||
Select,
|
Select,
|
||||||
@ -40,34 +43,37 @@ from bokeh.models import (
|
|||||||
Tabs,
|
Tabs,
|
||||||
TextAreaInput,
|
TextAreaInput,
|
||||||
TextInput,
|
TextInput,
|
||||||
Toggle,
|
|
||||||
WheelZoomTool,
|
WheelZoomTool,
|
||||||
Whisker,
|
Whisker,
|
||||||
)
|
)
|
||||||
from bokeh.palettes import Category10, Turbo256
|
from bokeh.palettes import Category10, Turbo256
|
||||||
from bokeh.transform import linear_cmap
|
from bokeh.transform import linear_cmap
|
||||||
|
from scipy import interpolate
|
||||||
|
|
||||||
import pyzebra
|
import pyzebra
|
||||||
from pyzebra.ccl_io import AREA_METHODS
|
from pyzebra.ccl_process import AREA_METHODS
|
||||||
|
|
||||||
javaScript = """
|
javaScript = """
|
||||||
|
let j = 0;
|
||||||
for (let i = 0; i < js_data.data['fname'].length; i++) {
|
for (let i = 0; i < js_data.data['fname'].length; i++) {
|
||||||
if (js_data.data['content'][i] === "") continue;
|
if (js_data.data['content'][i] === "") continue;
|
||||||
|
|
||||||
const blob = new Blob([js_data.data['content'][i]], {type: 'text/plain'})
|
setTimeout(function() {
|
||||||
const link = document.createElement('a');
|
const blob = new Blob([js_data.data['content'][i]], {type: 'text/plain'})
|
||||||
document.body.appendChild(link);
|
const link = document.createElement('a');
|
||||||
const url = window.URL.createObjectURL(blob);
|
document.body.appendChild(link);
|
||||||
link.href = url;
|
const url = window.URL.createObjectURL(blob);
|
||||||
link.download = js_data.data['fname'][i];
|
link.href = url;
|
||||||
link.click();
|
link.download = js_data.data['fname'][i] + js_data.data['ext'][i];
|
||||||
window.URL.revokeObjectURL(url);
|
link.click();
|
||||||
document.body.removeChild(link);
|
window.URL.revokeObjectURL(url);
|
||||||
|
document.body.removeChild(link);
|
||||||
|
}, 100 * j)
|
||||||
|
|
||||||
|
j++;
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
PROPOSAL_PATH = "/afs/psi.ch/project/sinqdata/2020/zebra/"
|
|
||||||
|
|
||||||
|
|
||||||
def color_palette(n_colors):
|
def color_palette(n_colors):
|
||||||
palette = itertools.cycle(Category10[10])
|
palette = itertools.cycle(Category10[10])
|
||||||
@ -75,19 +81,41 @@ def color_palette(n_colors):
|
|||||||
|
|
||||||
|
|
||||||
def create():
|
def create():
|
||||||
|
doc = curdoc()
|
||||||
det_data = []
|
det_data = []
|
||||||
fit_params = {}
|
fit_params = {}
|
||||||
js_data = ColumnDataSource(data=dict(content=["", ""], fname=["", ""]))
|
js_data = ColumnDataSource(data=dict(content=[""], fname=[""], ext=[""]))
|
||||||
|
|
||||||
def proposal_textinput_callback(_attr, _old, new):
|
def file_select_update_for_proposal():
|
||||||
full_proposal_path = os.path.join(PROPOSAL_PATH, new.strip())
|
proposal = proposal_textinput.value.strip()
|
||||||
dat_file_list = []
|
if not proposal:
|
||||||
for file in os.listdir(full_proposal_path):
|
file_select.options = []
|
||||||
if file.endswith(".dat"):
|
file_open_button.disabled = True
|
||||||
dat_file_list.append((os.path.join(full_proposal_path, file), file))
|
file_append_button.disabled = True
|
||||||
file_select.options = dat_file_list
|
return
|
||||||
|
|
||||||
proposal_textinput = TextInput(title="Proposal number:", default_size=200)
|
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 = []
|
||||||
|
for file in os.listdir(proposal_path):
|
||||||
|
if file.endswith((".ccl", ".dat")):
|
||||||
|
file_list.append((os.path.join(proposal_path, file), file))
|
||||||
|
file_select.options = file_list
|
||||||
|
file_open_button.disabled = False
|
||||||
|
file_append_button.disabled = False
|
||||||
|
|
||||||
|
doc.add_periodic_callback(file_select_update_for_proposal, 5000)
|
||||||
|
|
||||||
|
def proposal_textinput_callback(_attr, _old, _new):
|
||||||
|
file_select_update_for_proposal()
|
||||||
|
|
||||||
|
proposal_textinput = TextInput(title="Proposal number:", width=210)
|
||||||
proposal_textinput.on_change("value", proposal_textinput_callback)
|
proposal_textinput.on_change("value", proposal_textinput_callback)
|
||||||
|
|
||||||
def _init_datatable():
|
def _init_datatable():
|
||||||
@ -106,20 +134,18 @@ def create():
|
|||||||
scan_table_source.selected.indices = []
|
scan_table_source.selected.indices = []
|
||||||
scan_table_source.selected.indices = [0]
|
scan_table_source.selected.indices = [0]
|
||||||
|
|
||||||
|
scan_motor_select.options = det_data[0]["scan_motors"]
|
||||||
|
scan_motor_select.value = det_data[0]["scan_motor"]
|
||||||
param_select.value = "user defined"
|
param_select.value = "user defined"
|
||||||
|
|
||||||
def file_select_callback(_attr, _old, _new):
|
file_select = MultiSelect(title="Available .ccl/.dat files:", width=210, height=250)
|
||||||
pass
|
|
||||||
|
|
||||||
file_select = MultiSelect(title="Available .dat files:", default_size=200, height=250)
|
|
||||||
file_select.on_change("value", file_select_callback)
|
|
||||||
|
|
||||||
def file_open_button_callback():
|
def file_open_button_callback():
|
||||||
nonlocal det_data
|
nonlocal det_data
|
||||||
det_data = []
|
det_data = []
|
||||||
for f_name in file_select.value:
|
for f_path in file_select.value:
|
||||||
with open(f_name) as file:
|
with open(f_path) as file:
|
||||||
base, ext = os.path.splitext(f_name)
|
base, ext = os.path.splitext(os.path.basename(f_path))
|
||||||
if det_data:
|
if det_data:
|
||||||
append_data = pyzebra.parse_1D(file, ext)
|
append_data = pyzebra.parse_1D(file, ext)
|
||||||
pyzebra.normalize_dataset(append_data, monitor_spinner.value)
|
pyzebra.normalize_dataset(append_data, monitor_spinner.value)
|
||||||
@ -127,17 +153,18 @@ def create():
|
|||||||
else:
|
else:
|
||||||
det_data = pyzebra.parse_1D(file, ext)
|
det_data = pyzebra.parse_1D(file, ext)
|
||||||
pyzebra.normalize_dataset(det_data, monitor_spinner.value)
|
pyzebra.normalize_dataset(det_data, monitor_spinner.value)
|
||||||
js_data.data.update(fname=[base + ".comm", base + ".incomm"])
|
js_data.data.update(fname=[base])
|
||||||
|
|
||||||
_init_datatable()
|
_init_datatable()
|
||||||
|
append_upload_button.disabled = False
|
||||||
|
|
||||||
file_open_button = Button(label="Open New", default_size=100)
|
file_open_button = Button(label="Open New", width=100, disabled=True)
|
||||||
file_open_button.on_click(file_open_button_callback)
|
file_open_button.on_click(file_open_button_callback)
|
||||||
|
|
||||||
def file_append_button_callback():
|
def file_append_button_callback():
|
||||||
for f_name in file_select.value:
|
for f_path in file_select.value:
|
||||||
with open(f_name) as file:
|
with open(f_path) as file:
|
||||||
_, ext = os.path.splitext(f_name)
|
_, ext = os.path.splitext(f_path)
|
||||||
append_data = pyzebra.parse_1D(file, ext)
|
append_data = pyzebra.parse_1D(file, ext)
|
||||||
|
|
||||||
pyzebra.normalize_dataset(append_data, monitor_spinner.value)
|
pyzebra.normalize_dataset(append_data, monitor_spinner.value)
|
||||||
@ -145,12 +172,13 @@ def create():
|
|||||||
|
|
||||||
_init_datatable()
|
_init_datatable()
|
||||||
|
|
||||||
file_append_button = Button(label="Append", default_size=100)
|
file_append_button = Button(label="Append", width=100, disabled=True)
|
||||||
file_append_button.on_click(file_append_button_callback)
|
file_append_button.on_click(file_append_button_callback)
|
||||||
|
|
||||||
def upload_button_callback(_attr, _old, new):
|
def upload_button_callback(_attr, _old, new):
|
||||||
nonlocal det_data
|
nonlocal det_data
|
||||||
det_data = []
|
det_data = []
|
||||||
|
proposal_textinput.value = ""
|
||||||
for f_str, f_name in zip(new, upload_button.filename):
|
for f_str, f_name in zip(new, upload_button.filename):
|
||||||
with io.StringIO(base64.b64decode(f_str).decode()) as file:
|
with io.StringIO(base64.b64decode(f_str).decode()) as file:
|
||||||
base, ext = os.path.splitext(f_name)
|
base, ext = os.path.splitext(f_name)
|
||||||
@ -161,12 +189,13 @@ def create():
|
|||||||
else:
|
else:
|
||||||
det_data = pyzebra.parse_1D(file, ext)
|
det_data = pyzebra.parse_1D(file, ext)
|
||||||
pyzebra.normalize_dataset(det_data, monitor_spinner.value)
|
pyzebra.normalize_dataset(det_data, monitor_spinner.value)
|
||||||
js_data.data.update(fname=[base + ".comm", base + ".incomm"])
|
js_data.data.update(fname=[base])
|
||||||
|
|
||||||
_init_datatable()
|
_init_datatable()
|
||||||
|
append_upload_button.disabled = False
|
||||||
|
|
||||||
upload_div = Div(text="or upload new .dat files:", margin=(5, 5, 0, 5))
|
upload_div = Div(text="or upload new .ccl/.dat files:", margin=(5, 5, 0, 5))
|
||||||
upload_button = FileInput(accept=".dat", multiple=True, default_size=200)
|
upload_button = FileInput(accept=".ccl,.dat", multiple=True, width=200)
|
||||||
upload_button.on_change("value", upload_button_callback)
|
upload_button.on_change("value", upload_button_callback)
|
||||||
|
|
||||||
def append_upload_button_callback(_attr, _old, new):
|
def append_upload_button_callback(_attr, _old, new):
|
||||||
@ -181,7 +210,7 @@ def create():
|
|||||||
_init_datatable()
|
_init_datatable()
|
||||||
|
|
||||||
append_upload_div = Div(text="append extra files:", margin=(5, 5, 0, 5))
|
append_upload_div = Div(text="append extra files:", margin=(5, 5, 0, 5))
|
||||||
append_upload_button = FileInput(accept=".dat", multiple=True, default_size=200)
|
append_upload_button = FileInput(accept=".ccl,.dat", multiple=True, width=200, disabled=True)
|
||||||
append_upload_button.on_change("value", append_upload_button_callback)
|
append_upload_button.on_change("value", append_upload_button_callback)
|
||||||
|
|
||||||
def monitor_spinner_callback(_attr, _old, new):
|
def monitor_spinner_callback(_attr, _old, new):
|
||||||
@ -192,6 +221,15 @@ def create():
|
|||||||
monitor_spinner = Spinner(title="Monitor:", mode="int", value=100_000, low=1, width=145)
|
monitor_spinner = Spinner(title="Monitor:", mode="int", value=100_000, low=1, width=145)
|
||||||
monitor_spinner.on_change("value", monitor_spinner_callback)
|
monitor_spinner.on_change("value", monitor_spinner_callback)
|
||||||
|
|
||||||
|
def scan_motor_select_callback(_attr, _old, new):
|
||||||
|
if det_data:
|
||||||
|
for scan in det_data:
|
||||||
|
scan["scan_motor"] = new
|
||||||
|
_update_plot()
|
||||||
|
|
||||||
|
scan_motor_select = Select(title="Scan motor:", options=[], width=145)
|
||||||
|
scan_motor_select.on_change("value", scan_motor_select_callback)
|
||||||
|
|
||||||
def _update_table():
|
def _update_table():
|
||||||
fit_ok = [(1 if "fit" in scan else 0) for scan in det_data]
|
fit_ok = [(1 if "fit" in scan else 0) for scan in det_data]
|
||||||
scan_table_source.data.update(fit=fit_ok)
|
scan_table_source.data.update(fit=fit_ok)
|
||||||
@ -203,7 +241,7 @@ def create():
|
|||||||
def _update_single_scan_plot(scan):
|
def _update_single_scan_plot(scan):
|
||||||
scan_motor = scan["scan_motor"]
|
scan_motor = scan["scan_motor"]
|
||||||
|
|
||||||
y = scan["Counts"]
|
y = scan["counts"]
|
||||||
x = scan[scan_motor]
|
x = scan[scan_motor]
|
||||||
|
|
||||||
plot.axis[0].axis_label = scan_motor
|
plot.axis[0].axis_label = scan_motor
|
||||||
@ -252,10 +290,10 @@ def create():
|
|||||||
scan_motor = scan["scan_motor"]
|
scan_motor = scan["scan_motor"]
|
||||||
xs.append(scan[scan_motor])
|
xs.append(scan[scan_motor])
|
||||||
x.extend(scan[scan_motor])
|
x.extend(scan[scan_motor])
|
||||||
ys.append(scan["Counts"])
|
ys.append(scan["counts"])
|
||||||
y.extend([float(p)] * len(scan[scan_motor]))
|
y.extend([float(p)] * len(scan[scan_motor]))
|
||||||
param.append(float(p))
|
param.append(float(p))
|
||||||
par.extend(scan["Counts"])
|
par.extend(scan["counts"])
|
||||||
|
|
||||||
if det_data:
|
if det_data:
|
||||||
scan_motor = det_data[0]["scan_motor"]
|
scan_motor = det_data[0]["scan_motor"]
|
||||||
@ -269,6 +307,32 @@ def create():
|
|||||||
mapper["transform"].high = np.max([np.max(y) for y in ys])
|
mapper["transform"].high = np.max([np.max(y) for y in ys])
|
||||||
ov_param_plot_scatter_source.data.update(x=x, y=y, param=par)
|
ov_param_plot_scatter_source.data.update(x=x, y=y, param=par)
|
||||||
|
|
||||||
|
if y:
|
||||||
|
interp_f = interpolate.interp2d(x, y, par)
|
||||||
|
x1, x2 = min(x), max(x)
|
||||||
|
y1, y2 = min(y), max(y)
|
||||||
|
image = interp_f(
|
||||||
|
np.linspace(x1, x2, ov_param_plot.inner_width // 10),
|
||||||
|
np.linspace(y1, y2, ov_param_plot.inner_height // 10),
|
||||||
|
assume_sorted=True,
|
||||||
|
)
|
||||||
|
ov_param_plot_image_source.data.update(
|
||||||
|
image=[image], x=[x1], y=[y1], dw=[x2 - x1], dh=[y2 - y1]
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
ov_param_plot_image_source.data.update(image=[], x=[], y=[], dw=[], dh=[])
|
||||||
|
|
||||||
|
def _update_param_plot():
|
||||||
|
x = []
|
||||||
|
y = []
|
||||||
|
fit_param = fit_param_select.value
|
||||||
|
for s, p in zip(det_data, scan_table_source.data["param"]):
|
||||||
|
if "fit" in s and fit_param:
|
||||||
|
x.append(p)
|
||||||
|
y.append(s["fit"].values[fit_param])
|
||||||
|
|
||||||
|
param_plot_scatter_source.data.update(x=x, y=y)
|
||||||
|
|
||||||
# Main plot
|
# Main plot
|
||||||
plot = Plot(
|
plot = Plot(
|
||||||
x_range=DataRange1d(),
|
x_range=DataRange1d(),
|
||||||
@ -297,7 +361,7 @@ def create():
|
|||||||
plot_bkg_source, Line(x="x", y="y", line_color="green", line_dash="dashed")
|
plot_bkg_source, Line(x="x", y="y", line_color="green", line_dash="dashed")
|
||||||
)
|
)
|
||||||
|
|
||||||
plot_peak_source = ColumnDataSource(dict(xs=[0], ys=[0]))
|
plot_peak_source = ColumnDataSource(dict(xs=[[0]], ys=[[0]]))
|
||||||
plot_peak = plot.add_glyph(
|
plot_peak = plot.add_glyph(
|
||||||
plot_peak_source, MultiLine(xs="xs", ys="ys", line_color="red", line_dash="dashed")
|
plot_peak_source, MultiLine(xs="xs", ys="ys", line_color="red", line_dash="dashed")
|
||||||
)
|
)
|
||||||
@ -325,7 +389,7 @@ def create():
|
|||||||
plot.toolbar.logo = None
|
plot.toolbar.logo = None
|
||||||
|
|
||||||
# Overview multilines plot
|
# Overview multilines plot
|
||||||
ov_plot = Plot(x_range=DataRange1d(), y_range=DataRange1d(), plot_height=400, plot_width=700)
|
ov_plot = Plot(x_range=DataRange1d(), y_range=DataRange1d(), plot_height=450, plot_width=700)
|
||||||
|
|
||||||
ov_plot.add_layout(LinearAxis(axis_label="Counts"), place="left")
|
ov_plot.add_layout(LinearAxis(axis_label="Counts"), place="left")
|
||||||
ov_plot.add_layout(LinearAxis(axis_label="Scan motor"), place="below")
|
ov_plot.add_layout(LinearAxis(axis_label="Scan motor"), place="below")
|
||||||
@ -344,7 +408,7 @@ def create():
|
|||||||
|
|
||||||
# Overview perams plot
|
# Overview perams plot
|
||||||
ov_param_plot = Plot(
|
ov_param_plot = Plot(
|
||||||
x_range=DataRange1d(), y_range=DataRange1d(), plot_height=400, plot_width=700
|
x_range=DataRange1d(), y_range=DataRange1d(), plot_height=450, plot_width=700
|
||||||
)
|
)
|
||||||
|
|
||||||
ov_param_plot.add_layout(LinearAxis(axis_label="Param"), place="left")
|
ov_param_plot.add_layout(LinearAxis(axis_label="Param"), place="left")
|
||||||
@ -353,6 +417,11 @@ def create():
|
|||||||
ov_param_plot.add_layout(Grid(dimension=0, ticker=BasicTicker()))
|
ov_param_plot.add_layout(Grid(dimension=0, ticker=BasicTicker()))
|
||||||
ov_param_plot.add_layout(Grid(dimension=1, ticker=BasicTicker()))
|
ov_param_plot.add_layout(Grid(dimension=1, ticker=BasicTicker()))
|
||||||
|
|
||||||
|
ov_param_plot_image_source = ColumnDataSource(dict(image=[], x=[], y=[], dw=[], dh=[]))
|
||||||
|
ov_param_plot.add_glyph(
|
||||||
|
ov_param_plot_image_source, Image(image="image", x="x", y="y", dw="dw", dh="dh")
|
||||||
|
)
|
||||||
|
|
||||||
ov_param_plot_scatter_source = ColumnDataSource(dict(x=[], y=[], param=[]))
|
ov_param_plot_scatter_source = ColumnDataSource(dict(x=[], y=[], param=[]))
|
||||||
mapper = linear_cmap(field_name="param", palette=Turbo256, low=0, high=50)
|
mapper = linear_cmap(field_name="param", palette=Turbo256, low=0, high=50)
|
||||||
ov_param_plot.add_glyph(
|
ov_param_plot.add_glyph(
|
||||||
@ -363,12 +432,34 @@ def create():
|
|||||||
ov_param_plot.add_tools(PanTool(), WheelZoomTool(), ResetTool())
|
ov_param_plot.add_tools(PanTool(), WheelZoomTool(), ResetTool())
|
||||||
ov_param_plot.toolbar.logo = None
|
ov_param_plot.toolbar.logo = None
|
||||||
|
|
||||||
|
# Parameter plot
|
||||||
|
param_plot = Plot(x_range=DataRange1d(), y_range=DataRange1d(), plot_height=400, plot_width=700)
|
||||||
|
|
||||||
|
param_plot.add_layout(LinearAxis(axis_label="Fit parameter"), place="left")
|
||||||
|
param_plot.add_layout(LinearAxis(axis_label="Parameter"), place="below")
|
||||||
|
|
||||||
|
param_plot.add_layout(Grid(dimension=0, ticker=BasicTicker()))
|
||||||
|
param_plot.add_layout(Grid(dimension=1, ticker=BasicTicker()))
|
||||||
|
|
||||||
|
param_plot_scatter_source = ColumnDataSource(dict(x=[], y=[]))
|
||||||
|
param_plot.add_glyph(param_plot_scatter_source, Scatter(x="x", y="y"))
|
||||||
|
|
||||||
|
param_plot.add_tools(PanTool(), WheelZoomTool(), ResetTool())
|
||||||
|
param_plot.toolbar.logo = None
|
||||||
|
|
||||||
|
def fit_param_select_callback(_attr, _old, _new):
|
||||||
|
_update_param_plot()
|
||||||
|
|
||||||
|
fit_param_select = Select(title="Fit parameter", options=[], width=145)
|
||||||
|
fit_param_select.on_change("value", fit_param_select_callback)
|
||||||
|
|
||||||
# Plot tabs
|
# Plot tabs
|
||||||
plots = Tabs(
|
plots = Tabs(
|
||||||
tabs=[
|
tabs=[
|
||||||
Panel(child=plot, title="single scan"),
|
Panel(child=plot, title="single scan"),
|
||||||
Panel(child=ov_plot, title="overview"),
|
Panel(child=ov_plot, title="overview"),
|
||||||
Panel(child=ov_param_plot, title="overview map"),
|
Panel(child=ov_param_plot, title="overview map"),
|
||||||
|
Panel(child=column(param_plot, row(fit_param_select)), title="parameter plot"),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -390,7 +481,12 @@ def create():
|
|||||||
|
|
||||||
_update_plot()
|
_update_plot()
|
||||||
|
|
||||||
|
def scan_table_source_callback(_attr, _old, _new):
|
||||||
|
_update_preview()
|
||||||
|
|
||||||
scan_table_source = ColumnDataSource(dict(file=[], scan=[], param=[], fit=[], export=[]))
|
scan_table_source = ColumnDataSource(dict(file=[], scan=[], param=[], fit=[], export=[]))
|
||||||
|
scan_table_source.on_change("data", scan_table_source_callback)
|
||||||
|
|
||||||
scan_table = DataTable(
|
scan_table = DataTable(
|
||||||
source=scan_table_source,
|
source=scan_table_source,
|
||||||
columns=[
|
columns=[
|
||||||
@ -422,25 +518,26 @@ def create():
|
|||||||
param = [scan[new] for scan in det_data]
|
param = [scan[new] for scan in det_data]
|
||||||
|
|
||||||
scan_table_source.data["param"] = param
|
scan_table_source.data["param"] = param
|
||||||
|
_update_param_plot()
|
||||||
|
|
||||||
param_select = Select(
|
param_select = Select(
|
||||||
title="Parameter:",
|
title="Parameter:",
|
||||||
options=["user defined", "temp", "mf", "h", "k", "l"],
|
options=["user defined", "temp", "mf", "h", "k", "l"],
|
||||||
value="user defined",
|
value="user defined",
|
||||||
default_size=145,
|
width=145,
|
||||||
)
|
)
|
||||||
param_select.on_change("value", param_select_callback)
|
param_select.on_change("value", param_select_callback)
|
||||||
|
|
||||||
def fit_from_spinner_callback(_attr, _old, new):
|
def fit_from_spinner_callback(_attr, _old, new):
|
||||||
fit_from_span.location = new
|
fit_from_span.location = new
|
||||||
|
|
||||||
fit_from_spinner = Spinner(title="Fit from:", default_size=145)
|
fit_from_spinner = Spinner(title="Fit from:", width=145)
|
||||||
fit_from_spinner.on_change("value", fit_from_spinner_callback)
|
fit_from_spinner.on_change("value", fit_from_spinner_callback)
|
||||||
|
|
||||||
def fit_to_spinner_callback(_attr, _old, new):
|
def fit_to_spinner_callback(_attr, _old, new):
|
||||||
fit_to_span.location = new
|
fit_to_span.location = new
|
||||||
|
|
||||||
fit_to_spinner = Spinner(title="to:", default_size=145)
|
fit_to_spinner = Spinner(title="to:", width=145)
|
||||||
fit_to_spinner.on_change("value", fit_to_spinner_callback)
|
fit_to_spinner.on_change("value", fit_to_spinner_callback)
|
||||||
|
|
||||||
def fitparams_add_dropdown_callback(click):
|
def fitparams_add_dropdown_callback(click):
|
||||||
@ -459,7 +556,7 @@ def create():
|
|||||||
("Pseudo Voigt", "pvoigt"),
|
("Pseudo Voigt", "pvoigt"),
|
||||||
# ("Pseudo Voigt1", "pseudovoigt1"),
|
# ("Pseudo Voigt1", "pseudovoigt1"),
|
||||||
],
|
],
|
||||||
default_size=145,
|
width=145,
|
||||||
)
|
)
|
||||||
fitparams_add_dropdown.on_click(fitparams_add_dropdown_callback)
|
fitparams_add_dropdown.on_click(fitparams_add_dropdown_callback)
|
||||||
|
|
||||||
@ -479,7 +576,7 @@ def create():
|
|||||||
else:
|
else:
|
||||||
fitparams_table_source.data.update(dict(param=[], value=[], vary=[], min=[], max=[]))
|
fitparams_table_source.data.update(dict(param=[], value=[], vary=[], min=[], max=[]))
|
||||||
|
|
||||||
fitparams_select = MultiSelect(options=[], height=120, default_size=145)
|
fitparams_select = MultiSelect(options=[], height=120, width=145)
|
||||||
fitparams_select.tags = [0]
|
fitparams_select.tags = [0]
|
||||||
fitparams_select.on_change("value", fitparams_select_callback)
|
fitparams_select.on_change("value", fitparams_select_callback)
|
||||||
|
|
||||||
@ -494,7 +591,7 @@ def create():
|
|||||||
|
|
||||||
fitparams_select.value = []
|
fitparams_select.value = []
|
||||||
|
|
||||||
fitparams_remove_button = Button(label="Remove fit function", default_size=145)
|
fitparams_remove_button = Button(label="Remove fit function", width=145)
|
||||||
fitparams_remove_button.on_click(fitparams_remove_button_callback)
|
fitparams_remove_button.on_click(fitparams_remove_button_callback)
|
||||||
|
|
||||||
def fitparams_factory(function):
|
def fitparams_factory(function):
|
||||||
@ -516,6 +613,14 @@ def create():
|
|||||||
param=params, value=[None] * n, vary=[True] * n, min=[None] * n, max=[None] * n,
|
param=params, value=[None] * n, vary=[True] * n, min=[None] * n, max=[None] * n,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if function == "linear":
|
||||||
|
fitparams["value"] = [0, 1]
|
||||||
|
fitparams["vary"] = [False, True]
|
||||||
|
fitparams["min"] = [None, 0]
|
||||||
|
|
||||||
|
elif function == "gaussian":
|
||||||
|
fitparams["min"] = [0, None, None]
|
||||||
|
|
||||||
return fitparams
|
return fitparams
|
||||||
|
|
||||||
fitparams_table_source = ColumnDataSource(dict(param=[], value=[], vary=[], min=[], max=[]))
|
fitparams_table_source = ColumnDataSource(dict(param=[], value=[], vary=[], min=[], max=[]))
|
||||||
@ -542,92 +647,105 @@ def create():
|
|||||||
|
|
||||||
fit_output_textinput = TextAreaInput(title="Fit results:", width=750, height=200)
|
fit_output_textinput = TextAreaInput(title="Fit results:", width=750, height=200)
|
||||||
|
|
||||||
def fit_all_button_callback():
|
def proc_all_button_callback():
|
||||||
for scan, export in zip(det_data, scan_table_source.data["export"]):
|
for scan, export in zip(det_data, scan_table_source.data["export"]):
|
||||||
if export:
|
if export:
|
||||||
pyzebra.fit_scan(
|
pyzebra.fit_scan(
|
||||||
scan, fit_params, fit_from=fit_from_spinner.value, fit_to=fit_to_spinner.value
|
scan, fit_params, fit_from=fit_from_spinner.value, fit_to=fit_to_spinner.value
|
||||||
)
|
)
|
||||||
|
pyzebra.get_area(
|
||||||
|
scan,
|
||||||
|
area_method=AREA_METHODS[area_method_radiobutton.active],
|
||||||
|
lorentz=lorentz_checkbox.active,
|
||||||
|
)
|
||||||
|
|
||||||
_update_plot()
|
_update_plot()
|
||||||
_update_table()
|
_update_table()
|
||||||
|
|
||||||
fit_all_button = Button(label="Fit All", button_type="primary", default_size=145)
|
for scan in det_data:
|
||||||
fit_all_button.on_click(fit_all_button_callback)
|
if "fit" in scan:
|
||||||
|
options = list(scan["fit"].params.keys())
|
||||||
|
fit_param_select.options = options
|
||||||
|
fit_param_select.value = options[0]
|
||||||
|
break
|
||||||
|
_update_param_plot()
|
||||||
|
|
||||||
def fit_button_callback():
|
proc_all_button = Button(label="Process All", button_type="primary", width=145)
|
||||||
|
proc_all_button.on_click(proc_all_button_callback)
|
||||||
|
|
||||||
|
def proc_button_callback():
|
||||||
scan = _get_selected_scan()
|
scan = _get_selected_scan()
|
||||||
pyzebra.fit_scan(
|
pyzebra.fit_scan(
|
||||||
scan, fit_params, fit_from=fit_from_spinner.value, fit_to=fit_to_spinner.value
|
scan, fit_params, fit_from=fit_from_spinner.value, fit_to=fit_to_spinner.value
|
||||||
)
|
)
|
||||||
|
pyzebra.get_area(
|
||||||
|
scan,
|
||||||
|
area_method=AREA_METHODS[area_method_radiobutton.active],
|
||||||
|
lorentz=lorentz_checkbox.active,
|
||||||
|
)
|
||||||
|
|
||||||
_update_plot()
|
_update_plot()
|
||||||
_update_table()
|
_update_table()
|
||||||
|
|
||||||
fit_button = Button(label="Fit Current", default_size=145)
|
for scan in det_data:
|
||||||
fit_button.on_click(fit_button_callback)
|
if "fit" in scan:
|
||||||
|
options = list(scan["fit"].params.keys())
|
||||||
|
fit_param_select.options = options
|
||||||
|
fit_param_select.value = options[0]
|
||||||
|
break
|
||||||
|
_update_param_plot()
|
||||||
|
|
||||||
area_method_radiobutton = RadioButtonGroup(
|
proc_button = Button(label="Process Current", width=145)
|
||||||
labels=["Fit area", "Int area"], active=0, default_size=145, disabled=True
|
proc_button.on_click(proc_button_callback)
|
||||||
)
|
|
||||||
|
|
||||||
bin_size_spinner = Spinner(
|
area_method_div = Div(text="Intensity:", margin=(5, 5, 0, 5))
|
||||||
title="Bin size:", value=1, low=1, step=1, default_size=145, disabled=True
|
area_method_radiobutton = RadioGroup(labels=["Function", "Area"], active=0, width=145)
|
||||||
)
|
|
||||||
|
|
||||||
lorentz_toggle = Toggle(label="Lorentz Correction", default_size=145)
|
lorentz_checkbox = CheckboxGroup(labels=["Lorentz Correction"], width=145, margin=(13, 5, 5, 5))
|
||||||
|
|
||||||
export_preview_textinput = TextAreaInput(title="Export preview:", width=450, height=400)
|
export_preview_textinput = TextAreaInput(title="Export file preview:", width=450, height=400)
|
||||||
|
|
||||||
def preview_button_callback():
|
def _update_preview():
|
||||||
with tempfile.TemporaryDirectory() as temp_dir:
|
with tempfile.TemporaryDirectory() as temp_dir:
|
||||||
temp_file = temp_dir + "/temp"
|
temp_file = temp_dir + "/temp"
|
||||||
export_data = []
|
export_data = []
|
||||||
for s, export in zip(det_data, scan_table_source.data["export"]):
|
param_data = []
|
||||||
|
for s, p, export in zip(
|
||||||
|
det_data, scan_table_source.data["param"], scan_table_source.data["export"]
|
||||||
|
):
|
||||||
if export:
|
if export:
|
||||||
export_data.append(s)
|
export_data.append(s)
|
||||||
|
param_data.append(p)
|
||||||
|
|
||||||
pyzebra.export_1D(
|
pyzebra.export_param_study(export_data, param_data, temp_file)
|
||||||
export_data,
|
|
||||||
temp_file,
|
|
||||||
area_method=AREA_METHODS[int(area_method_radiobutton.active)],
|
|
||||||
lorentz=lorentz_toggle.active,
|
|
||||||
)
|
|
||||||
|
|
||||||
exported_content = ""
|
exported_content = ""
|
||||||
file_content = []
|
file_content = []
|
||||||
for ext in (".comm", ".incomm"):
|
|
||||||
fname = temp_file + ext
|
fname = temp_file
|
||||||
if os.path.isfile(fname):
|
if os.path.isfile(fname):
|
||||||
with open(fname) as f:
|
with open(fname) as f:
|
||||||
content = f.read()
|
content = f.read()
|
||||||
exported_content += f"{ext} file:\n" + content
|
exported_content += content
|
||||||
else:
|
else:
|
||||||
content = ""
|
content = ""
|
||||||
file_content.append(content)
|
file_content.append(content)
|
||||||
|
|
||||||
js_data.data.update(content=file_content)
|
js_data.data.update(content=file_content)
|
||||||
export_preview_textinput.value = exported_content
|
export_preview_textinput.value = exported_content
|
||||||
|
|
||||||
preview_button = Button(label="Preview", default_size=220)
|
save_button = Button(label="Download File", button_type="success", width=220)
|
||||||
preview_button.on_click(preview_button_callback)
|
|
||||||
|
|
||||||
save_button = Button(label="Download preview", button_type="success", default_size=220)
|
|
||||||
save_button.js_on_click(CustomJS(args={"js_data": js_data}, code=javaScript))
|
save_button.js_on_click(CustomJS(args={"js_data": js_data}, code=javaScript))
|
||||||
|
|
||||||
fitpeak_controls = row(
|
fitpeak_controls = row(
|
||||||
column(fitparams_add_dropdown, fitparams_select, fitparams_remove_button),
|
column(fitparams_add_dropdown, fitparams_select, fitparams_remove_button),
|
||||||
fitparams_table,
|
fitparams_table,
|
||||||
Spacer(width=20),
|
Spacer(width=20),
|
||||||
column(
|
column(fit_from_spinner, lorentz_checkbox, area_method_div, area_method_radiobutton),
|
||||||
row(fit_from_spinner, fit_to_spinner),
|
column(fit_to_spinner, proc_button, proc_all_button),
|
||||||
row(bin_size_spinner, column(Spacer(height=19), lorentz_toggle)),
|
|
||||||
row(area_method_radiobutton),
|
|
||||||
row(fit_button, fit_all_button),
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
scan_layout = column(scan_table, row(monitor_spinner, param_select))
|
scan_layout = column(scan_table, row(monitor_spinner, scan_motor_select, param_select))
|
||||||
|
|
||||||
import_layout = column(
|
import_layout = column(
|
||||||
proposal_textinput,
|
proposal_textinput,
|
||||||
@ -639,7 +757,7 @@ def create():
|
|||||||
append_upload_button,
|
append_upload_button,
|
||||||
)
|
)
|
||||||
|
|
||||||
export_layout = column(export_preview_textinput, row(preview_button, save_button))
|
export_layout = column(export_preview_textinput, row(save_button))
|
||||||
|
|
||||||
tab_layout = column(
|
tab_layout = column(
|
||||||
row(import_layout, scan_layout, plots, Spacer(width=30), export_layout),
|
row(import_layout, scan_layout, plots, Spacer(width=30), export_layout),
|
||||||
|
@ -1,11 +1,9 @@
|
|||||||
import ast
|
|
||||||
import math
|
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import tempfile
|
import tempfile
|
||||||
from collections import defaultdict
|
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
from bokeh.io import curdoc
|
||||||
from bokeh.layouts import column, row
|
from bokeh.layouts import column, row
|
||||||
from bokeh.models import (
|
from bokeh.models import (
|
||||||
Button,
|
Button,
|
||||||
@ -17,33 +15,35 @@ from bokeh.models import (
|
|||||||
TextAreaInput,
|
TextAreaInput,
|
||||||
TextInput,
|
TextInput,
|
||||||
)
|
)
|
||||||
from scipy.optimize import curve_fit
|
|
||||||
|
|
||||||
import pyzebra
|
import pyzebra
|
||||||
|
|
||||||
|
|
||||||
def create():
|
def create():
|
||||||
path_prefix_textinput = TextInput(title="Path prefix:", value="")
|
doc = curdoc()
|
||||||
selection_list = TextAreaInput(title="ROIs:", rows=7)
|
events_data = doc.events_data
|
||||||
lattice_const_textinput = TextInput(
|
|
||||||
title="Lattice constants:", value="8.3211,8.3211,8.3211,90.00,90.00,90.00"
|
npeaks_spinner = Spinner(title="Number of peaks from hdf_view panel:", disabled=True)
|
||||||
)
|
lattice_const_textinput = TextInput(title="Lattice constants:")
|
||||||
max_res_spinner = Spinner(title="max-res", value=2, step=0.01)
|
max_res_spinner = Spinner(title="max-res:", value=2, step=0.01, width=145)
|
||||||
seed_pool_size_spinner = Spinner(title="seed-pool-size", value=5, step=0.01)
|
seed_pool_size_spinner = Spinner(title="seed-pool-size:", value=5, step=0.01, width=145)
|
||||||
seed_len_tol_spinner = Spinner(title="seed-len-tol", value=0.02, step=0.01)
|
seed_len_tol_spinner = Spinner(title="seed-len-tol:", value=0.02, step=0.01, width=145)
|
||||||
seed_angle_tol_spinner = Spinner(title="seed-angle-tol", value=1, step=0.01)
|
seed_angle_tol_spinner = Spinner(title="seed-angle-tol:", value=1, step=0.01, width=145)
|
||||||
eval_hkl_tol_spinner = Spinner(title="eval-hkl-tol", value=0.15, step=0.01)
|
eval_hkl_tol_spinner = Spinner(title="eval-hkl-tol:", value=0.15, step=0.01, width=145)
|
||||||
|
|
||||||
diff_vec = []
|
diff_vec = []
|
||||||
|
ub_matrices = []
|
||||||
|
|
||||||
def process_button_callback():
|
def process_button_callback():
|
||||||
|
# drop table selection to clear result fields
|
||||||
|
results_table_source.selected.indices = []
|
||||||
|
|
||||||
nonlocal diff_vec
|
nonlocal diff_vec
|
||||||
with tempfile.TemporaryDirectory() as temp_dir:
|
with tempfile.TemporaryDirectory() as temp_dir:
|
||||||
temp_peak_list_dir = os.path.join(temp_dir, "peak_list")
|
temp_peak_list_dir = os.path.join(temp_dir, "peak_list")
|
||||||
os.mkdir(temp_peak_list_dir)
|
os.mkdir(temp_peak_list_dir)
|
||||||
temp_event_file = os.path.join(temp_peak_list_dir, "event-0.txt")
|
temp_event_file = os.path.join(temp_peak_list_dir, "event-0.txt")
|
||||||
temp_hkl_file = os.path.join(temp_dir, "hkl.h5")
|
temp_hkl_file = os.path.join(temp_dir, "hkl.h5")
|
||||||
roi_dict = ast.literal_eval(selection_list.value)
|
|
||||||
|
|
||||||
comp_proc = subprocess.run(
|
comp_proc = subprocess.run(
|
||||||
[
|
[
|
||||||
@ -51,7 +51,7 @@ def create():
|
|||||||
"-n",
|
"-n",
|
||||||
"2",
|
"2",
|
||||||
"python",
|
"python",
|
||||||
"spind/gen_hkl_table.py",
|
os.path.join(doc.spind_path, "gen_hkl_table.py"),
|
||||||
lattice_const_textinput.value,
|
lattice_const_textinput.value,
|
||||||
"--max-res",
|
"--max-res",
|
||||||
str(max_res_spinner.value),
|
str(max_res_spinner.value),
|
||||||
@ -66,7 +66,37 @@ def create():
|
|||||||
print(" ".join(comp_proc.args))
|
print(" ".join(comp_proc.args))
|
||||||
print(comp_proc.stdout)
|
print(comp_proc.stdout)
|
||||||
|
|
||||||
diff_vec = prepare_event_file(temp_event_file, roi_dict, path_prefix_textinput.value)
|
# prepare an event file
|
||||||
|
diff_vec = []
|
||||||
|
with open(temp_event_file, "w") as f:
|
||||||
|
npeaks = len(next(iter(doc.events_data.values())))
|
||||||
|
for ind in range(npeaks):
|
||||||
|
wave = events_data["wave"][ind]
|
||||||
|
ddist = events_data["ddist"][ind]
|
||||||
|
x_pos = events_data["x_pos"][ind]
|
||||||
|
y_pos = events_data["y_pos"][ind]
|
||||||
|
intensity = events_data["intensity"][ind]
|
||||||
|
snr_cnts = events_data["snr_cnts"][ind]
|
||||||
|
gamma = events_data["gamma"][ind]
|
||||||
|
omega = events_data["omega"][ind]
|
||||||
|
chi = events_data["chi"][ind]
|
||||||
|
phi = events_data["phi"][ind]
|
||||||
|
nu = events_data["nu"][ind]
|
||||||
|
|
||||||
|
ga, nu = pyzebra.det2pol(ddist, gamma, nu, x_pos, y_pos)
|
||||||
|
diff_vector = pyzebra.z1frmd(wave, ga, omega, chi, phi, nu)
|
||||||
|
d_spacing = float(pyzebra.dandth(wave, diff_vector)[0])
|
||||||
|
diff_vector = diff_vector.flatten() * 1e10
|
||||||
|
dv1, dv2, dv3 = diff_vector
|
||||||
|
|
||||||
|
diff_vec.append(diff_vector)
|
||||||
|
f.write(
|
||||||
|
f"{x_pos} {y_pos} {intensity} {snr_cnts} {dv1} {dv2} {dv3} {d_spacing}\n"
|
||||||
|
)
|
||||||
|
|
||||||
|
print(f"Content of {temp_event_file}:")
|
||||||
|
with open(temp_event_file) as f:
|
||||||
|
print(f.read())
|
||||||
|
|
||||||
comp_proc = subprocess.run(
|
comp_proc = subprocess.run(
|
||||||
[
|
[
|
||||||
@ -74,7 +104,7 @@ def create():
|
|||||||
"-n",
|
"-n",
|
||||||
"2",
|
"2",
|
||||||
"python",
|
"python",
|
||||||
"spind/SPIND.py",
|
os.path.join(doc.spind_path, "SPIND.py"),
|
||||||
temp_peak_list_dir,
|
temp_peak_list_dir,
|
||||||
temp_hkl_file,
|
temp_hkl_file,
|
||||||
"-o",
|
"-o",
|
||||||
@ -96,9 +126,12 @@ def create():
|
|||||||
print(" ".join(comp_proc.args))
|
print(" ".join(comp_proc.args))
|
||||||
print(comp_proc.stdout)
|
print(comp_proc.stdout)
|
||||||
|
|
||||||
|
spind_out_file = os.path.join(temp_dir, "spind.txt")
|
||||||
|
spind_res = dict(
|
||||||
|
label=[], crystal_id=[], match_rate=[], matched_peaks=[], column_5=[], ub_matrix=[],
|
||||||
|
)
|
||||||
try:
|
try:
|
||||||
with open(os.path.join(temp_dir, "spind.txt")) as f_out:
|
with open(spind_out_file) as f_out:
|
||||||
spind_res = defaultdict(list)
|
|
||||||
for line in f_out:
|
for line in f_out:
|
||||||
c1, c2, c3, c4, c5, *c_rest = line.split()
|
c1, c2, c3, c4, c5, *c_rest = line.split()
|
||||||
spind_res["label"].append(c1)
|
spind_res["label"].append(c1)
|
||||||
@ -109,32 +142,45 @@ def create():
|
|||||||
|
|
||||||
# last digits are spind UB matrix
|
# last digits are spind UB matrix
|
||||||
vals = list(map(float, c_rest))
|
vals = list(map(float, c_rest))
|
||||||
ub_matrix_spind = np.array(vals).reshape(3, 3)
|
ub_matrix_spind = np.transpose(np.array(vals).reshape(3, 3))
|
||||||
ub_matrix = np.linalg.inv(np.transpose(ub_matrix_spind)) * 1e10
|
ub_matrix = np.linalg.inv(ub_matrix_spind)
|
||||||
spind_res["ub_matrix"].append(ub_matrix)
|
ub_matrices.append(ub_matrix)
|
||||||
|
spind_res["ub_matrix"].append(str(ub_matrix_spind * 1e-10))
|
||||||
|
|
||||||
results_table_source.data.update(spind_res)
|
print(f"Content of {spind_out_file}:")
|
||||||
|
with open(spind_out_file) as f:
|
||||||
|
print(f.read())
|
||||||
|
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
print("No results from spind")
|
print("No results from spind")
|
||||||
|
|
||||||
|
results_table_source.data.update(spind_res)
|
||||||
|
|
||||||
process_button = Button(label="Process", button_type="primary")
|
process_button = Button(label="Process", button_type="primary")
|
||||||
process_button.on_click(process_button_callback)
|
process_button.on_click(process_button_callback)
|
||||||
|
|
||||||
hkl_textareainput = TextAreaInput(title="hkl values:", rows=7)
|
if doc.spind_path is None:
|
||||||
|
process_button.disabled = True
|
||||||
|
|
||||||
|
ub_matrix_textareainput = TextAreaInput(title="UB matrix:", rows=7, width=400)
|
||||||
|
hkl_textareainput = TextAreaInput(title="hkl values:", rows=7, width=400)
|
||||||
|
|
||||||
def results_table_select_callback(_attr, old, new):
|
def results_table_select_callback(_attr, old, new):
|
||||||
if new:
|
if new:
|
||||||
ind = new[0]
|
ind = new[0]
|
||||||
ub_matrix = results_table_source.data["ub_matrix"][ind]
|
ub_matrix = ub_matrices[ind]
|
||||||
res = ""
|
res = ""
|
||||||
for vec in diff_vec:
|
for vec in diff_vec:
|
||||||
res += f"{vec @ ub_matrix}\n"
|
res += f"{ub_matrix @ vec}\n"
|
||||||
|
ub_matrix_textareainput.value = str(ub_matrix * 1e10)
|
||||||
hkl_textareainput.value = res
|
hkl_textareainput.value = res
|
||||||
else:
|
else:
|
||||||
hkl_textareainput.value = None
|
ub_matrix_textareainput.value = ""
|
||||||
|
hkl_textareainput.value = ""
|
||||||
|
|
||||||
results_table_source = ColumnDataSource(dict())
|
results_table_source = ColumnDataSource(
|
||||||
|
dict(label=[], crystal_id=[], match_rate=[], matched_peaks=[], column_5=[], ub_matrix=[])
|
||||||
|
)
|
||||||
results_table = DataTable(
|
results_table = DataTable(
|
||||||
source=results_table_source,
|
source=results_table_source,
|
||||||
columns=[
|
columns=[
|
||||||
@ -143,10 +189,10 @@ def create():
|
|||||||
TableColumn(field="match_rate", title="Match Rate", width=100),
|
TableColumn(field="match_rate", title="Match Rate", width=100),
|
||||||
TableColumn(field="matched_peaks", title="Matched Peaks", width=100),
|
TableColumn(field="matched_peaks", title="Matched Peaks", width=100),
|
||||||
TableColumn(field="column_5", title="", width=100),
|
TableColumn(field="column_5", title="", width=100),
|
||||||
TableColumn(field="ub_matrix", title="UB Matrix", width=250),
|
TableColumn(field="ub_matrix", title="UB Matrix", width=700),
|
||||||
],
|
],
|
||||||
height=300,
|
height=300,
|
||||||
width=700,
|
width=1200,
|
||||||
autosize_mode="none",
|
autosize_mode="none",
|
||||||
index_position=None,
|
index_position=None,
|
||||||
)
|
)
|
||||||
@ -155,99 +201,23 @@ def create():
|
|||||||
|
|
||||||
tab_layout = row(
|
tab_layout = row(
|
||||||
column(
|
column(
|
||||||
path_prefix_textinput,
|
npeaks_spinner,
|
||||||
selection_list,
|
|
||||||
lattice_const_textinput,
|
lattice_const_textinput,
|
||||||
max_res_spinner,
|
row(max_res_spinner, seed_pool_size_spinner),
|
||||||
seed_pool_size_spinner,
|
row(seed_len_tol_spinner, seed_angle_tol_spinner),
|
||||||
seed_len_tol_spinner,
|
row(eval_hkl_tol_spinner),
|
||||||
seed_angle_tol_spinner,
|
|
||||||
eval_hkl_tol_spinner,
|
|
||||||
process_button,
|
process_button,
|
||||||
),
|
),
|
||||||
column(results_table, row(hkl_textareainput)),
|
column(results_table, row(ub_matrix_textareainput, hkl_textareainput)),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
async def update_npeaks_spinner():
|
||||||
|
npeaks = len(next(iter(doc.events_data.values())))
|
||||||
|
npeaks_spinner.value = npeaks
|
||||||
|
# TODO: check cell parameter for consistency?
|
||||||
|
if npeaks:
|
||||||
|
lattice_const_textinput.value = ",".join(map(str, doc.events_data["cell"][0]))
|
||||||
|
|
||||||
|
doc.add_periodic_callback(update_npeaks_spinner, 1000)
|
||||||
|
|
||||||
return Panel(child=tab_layout, title="spind")
|
return Panel(child=tab_layout, title="spind")
|
||||||
|
|
||||||
|
|
||||||
def gauss(x, *p):
|
|
||||||
"""Defines Gaussian function
|
|
||||||
Args:
|
|
||||||
A - amplitude, mu - position of the center, sigma - width
|
|
||||||
Returns:
|
|
||||||
Gaussian function
|
|
||||||
"""
|
|
||||||
A, mu, sigma = p
|
|
||||||
return A * np.exp(-((x - mu) ** 2) / (2.0 * sigma ** 2))
|
|
||||||
|
|
||||||
|
|
||||||
def prepare_event_file(export_filename, roi_dict, path_prefix=""):
|
|
||||||
diff_vec = []
|
|
||||||
p0 = [1.0, 0.0, 1.0]
|
|
||||||
maxfev = 100000
|
|
||||||
with open(export_filename, "w") as f:
|
|
||||||
for file, rois in roi_dict.items():
|
|
||||||
dat = pyzebra.read_detector_data(path_prefix + file + ".hdf")
|
|
||||||
|
|
||||||
wave = dat["wave"]
|
|
||||||
ddist = dat["ddist"]
|
|
||||||
|
|
||||||
gamma = dat["gamma"][0]
|
|
||||||
omega = dat["omega"][0]
|
|
||||||
nu = dat["nu"][0]
|
|
||||||
chi = dat["chi"][0]
|
|
||||||
phi = dat["phi"][0]
|
|
||||||
|
|
||||||
scan_motor = dat["scan_motor"]
|
|
||||||
var_angle = dat[scan_motor]
|
|
||||||
|
|
||||||
for roi in rois:
|
|
||||||
x0, xN, y0, yN, fr0, frN = roi
|
|
||||||
data_roi = dat["data"][fr0:frN, y0:yN, x0:xN]
|
|
||||||
|
|
||||||
cnts = np.sum(data_roi, axis=(1, 2))
|
|
||||||
coeff, _ = curve_fit(gauss, range(len(cnts)), cnts, p0=p0, maxfev=maxfev)
|
|
||||||
|
|
||||||
m = cnts.mean()
|
|
||||||
sd = cnts.std()
|
|
||||||
snr_cnts = np.where(sd == 0, 0, m / sd)
|
|
||||||
|
|
||||||
frC = fr0 + coeff[1]
|
|
||||||
var_F = var_angle[math.floor(frC)]
|
|
||||||
var_C = var_angle[math.ceil(frC)]
|
|
||||||
frStep = frC - math.floor(frC)
|
|
||||||
var_step = var_C - var_F
|
|
||||||
var_p = var_F + var_step * frStep
|
|
||||||
|
|
||||||
if scan_motor == "gamma":
|
|
||||||
gamma = var_p
|
|
||||||
elif scan_motor == "omega":
|
|
||||||
omega = var_p
|
|
||||||
elif scan_motor == "nu":
|
|
||||||
nu = var_p
|
|
||||||
elif scan_motor == "chi":
|
|
||||||
chi = var_p
|
|
||||||
elif scan_motor == "phi":
|
|
||||||
phi = var_p
|
|
||||||
|
|
||||||
intensity = coeff[1] * abs(coeff[2] * var_step) * math.sqrt(2) * math.sqrt(np.pi)
|
|
||||||
|
|
||||||
projX = np.sum(data_roi, axis=(0, 1))
|
|
||||||
coeff, _ = curve_fit(gauss, range(len(projX)), projX, p0=p0, maxfev=maxfev)
|
|
||||||
x_pos = x0 + coeff[1]
|
|
||||||
|
|
||||||
projY = np.sum(data_roi, axis=(0, 2))
|
|
||||||
coeff, _ = curve_fit(gauss, range(len(projY)), projY, p0=p0, maxfev=maxfev)
|
|
||||||
y_pos = y0 + coeff[1]
|
|
||||||
|
|
||||||
ga, nu = pyzebra.det2pol(ddist, gamma, nu, x_pos, y_pos)
|
|
||||||
diff_vector = pyzebra.z1frmd(wave, ga, omega, chi, phi, nu)
|
|
||||||
d_spacing = float(pyzebra.dandth(wave, diff_vector)[0])
|
|
||||||
dv1, dv2, dv3 = diff_vector.flatten() * 1e10
|
|
||||||
|
|
||||||
diff_vec.append(diff_vector.flatten())
|
|
||||||
|
|
||||||
f.write(f"{x_pos} {y_pos} {intensity} {snr_cnts} {dv1} {dv2} {dv3} {d_spacing}\n")
|
|
||||||
|
|
||||||
return diff_vec
|
|
||||||
|
@ -76,7 +76,7 @@ CCL_SECOND_LINE = (
|
|||||||
("scan_motor", str),
|
("scan_motor", str),
|
||||||
)
|
)
|
||||||
|
|
||||||
AREA_METHODS = ("fit_area", "int_area")
|
EXPORT_TARGETS = {"fullprof": (".comm", ".incomm"), "jana": (".col", ".incol")}
|
||||||
|
|
||||||
|
|
||||||
def load_1D(filepath):
|
def load_1D(filepath):
|
||||||
@ -159,6 +159,7 @@ def parse_1D(fileobj, data_type):
|
|||||||
|
|
||||||
# "om" -> "omega"
|
# "om" -> "omega"
|
||||||
s["scan_motor"] = "omega"
|
s["scan_motor"] = "omega"
|
||||||
|
s["scan_motors"] = ["omega", ]
|
||||||
# overwrite metadata, because it only refers to the scan center
|
# overwrite metadata, because it only refers to the scan center
|
||||||
half_dist = (s["n_points"] - 1) / 2 * s["angle_step"]
|
half_dist = (s["n_points"] - 1) / 2 * s["angle_step"]
|
||||||
s["omega"] = np.linspace(s["omega"] - half_dist, s["omega"] + half_dist, s["n_points"])
|
s["omega"] = np.linspace(s["omega"] - half_dist, s["omega"] + half_dist, s["n_points"])
|
||||||
@ -167,7 +168,7 @@ def parse_1D(fileobj, data_type):
|
|||||||
counts = []
|
counts = []
|
||||||
while len(counts) < s["n_points"]:
|
while len(counts) < s["n_points"]:
|
||||||
counts.extend(map(float, next(fileobj).split()))
|
counts.extend(map(float, next(fileobj).split()))
|
||||||
s["Counts"] = np.array(counts)
|
s["counts"] = np.array(counts)
|
||||||
|
|
||||||
if s["h"].is_integer() and s["k"].is_integer() and s["l"].is_integer():
|
if s["h"].is_integer() and s["k"].is_integer() and s["l"].is_integer():
|
||||||
s["h"], s["k"], s["l"] = map(int, (s["h"], s["k"], s["l"]))
|
s["h"], s["k"], s["l"] = map(int, (s["h"], s["k"], s["l"]))
|
||||||
@ -182,23 +183,15 @@ def parse_1D(fileobj, data_type):
|
|||||||
s = defaultdict(list)
|
s = defaultdict(list)
|
||||||
|
|
||||||
match = re.search("Scanning Variables: (.*), Steps: (.*)", next(fileobj))
|
match = re.search("Scanning Variables: (.*), Steps: (.*)", next(fileobj))
|
||||||
if match.group(1) == "h, k, l":
|
motors = [motor.lower() for motor in match.group(1).split(", ")]
|
||||||
steps = match.group(2).split()
|
steps = [float(step) for step in match.group(2).split()]
|
||||||
for step, ind in zip(steps, "hkl"):
|
|
||||||
if float(step) != 0:
|
|
||||||
scan_motor = ind
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
scan_motor = match.group(1)
|
|
||||||
|
|
||||||
s["scan_motor"] = scan_motor
|
|
||||||
|
|
||||||
match = re.search("(.*) Points, Mode: (.*), Preset (.*)", next(fileobj))
|
match = re.search("(.*) Points, Mode: (.*), Preset (.*)", next(fileobj))
|
||||||
if match.group(2) != "Monitor":
|
if match.group(2) != "Monitor":
|
||||||
raise Exception("Unknown mode in dat file.")
|
raise Exception("Unknown mode in dat file.")
|
||||||
s["monitor"] = float(match.group(3))
|
s["monitor"] = float(match.group(3))
|
||||||
|
|
||||||
col_names = next(fileobj).split()
|
col_names = list(map(str.lower, next(fileobj).split()))
|
||||||
|
|
||||||
for line in fileobj:
|
for line in fileobj:
|
||||||
if "END-OF-DATA" in line:
|
if "END-OF-DATA" in line:
|
||||||
@ -211,15 +204,28 @@ def parse_1D(fileobj, data_type):
|
|||||||
for name in col_names:
|
for name in col_names:
|
||||||
s[name] = np.array(s[name])
|
s[name] = np.array(s[name])
|
||||||
|
|
||||||
|
s["scan_motors"] = []
|
||||||
|
for motor, step in zip(motors, steps):
|
||||||
|
if step == 0:
|
||||||
|
# it's not a scan motor, so keep only the median value
|
||||||
|
s[motor] = np.median(s[motor])
|
||||||
|
else:
|
||||||
|
s["scan_motors"].append(motor)
|
||||||
|
s["scan_motor"] = s["scan_motors"][0]
|
||||||
|
|
||||||
# "om" -> "omega"
|
# "om" -> "omega"
|
||||||
if s["scan_motor"] == "om":
|
if "om" in s["scan_motors"]:
|
||||||
s["scan_motor"] = "omega"
|
s["scan_motors"][s["scan_motors"].index("om")] = "omega"
|
||||||
|
if s["scan_motor"] == "om":
|
||||||
|
s["scan_motor"] = "omega"
|
||||||
s["omega"] = s["om"]
|
s["omega"] = s["om"]
|
||||||
del s["om"]
|
del s["om"]
|
||||||
|
|
||||||
# "tt" -> "temp"
|
# "tt" -> "temp"
|
||||||
elif s["scan_motor"] == "tt":
|
elif "tt" in s["scan_motors"]:
|
||||||
s["scan_motor"] = "temp"
|
s["scan_motors"][s["scan_motors"].index("tt")] = "temp"
|
||||||
|
if s["scan_motor"] == "tt":
|
||||||
|
s["scan_motor"] = "temp"
|
||||||
s["temp"] = s["tt"]
|
s["temp"] = s["tt"]
|
||||||
del s["tt"]
|
del s["tt"]
|
||||||
|
|
||||||
@ -243,14 +249,19 @@ def parse_1D(fileobj, data_type):
|
|||||||
return scan
|
return scan
|
||||||
|
|
||||||
|
|
||||||
def export_1D(data, path, area_method=AREA_METHODS[0], lorentz=False, hkl_precision=2):
|
def export_1D(data, path, export_target, hkl_precision=2):
|
||||||
"""Exports data in the .comm/.incomm format
|
"""Exports data in the .comm/.incomm format for fullprof or .col/.incol format for jana.
|
||||||
|
|
||||||
Scans with integer/real hkl values are saved in .comm/.incomm files correspondingly. If no scans
|
Scans with integer/real hkl values are saved in .comm/.incomm or .col/.incol files
|
||||||
are present for a particular output format, that file won't be created.
|
correspondingly. If no scans are present for a particular output format, that file won't be
|
||||||
|
created.
|
||||||
"""
|
"""
|
||||||
|
if export_target not in EXPORT_TARGETS:
|
||||||
|
raise ValueError(f"Unknown export target: {export_target}.")
|
||||||
|
|
||||||
zebra_mode = data[0]["zebra_mode"]
|
zebra_mode = data[0]["zebra_mode"]
|
||||||
file_content = {".comm": [], ".incomm": []}
|
exts = EXPORT_TARGETS[export_target]
|
||||||
|
file_content = {ext: [] for ext in exts}
|
||||||
|
|
||||||
for scan in data:
|
for scan in data:
|
||||||
if "fit" not in scan:
|
if "fit" not in scan:
|
||||||
@ -261,36 +272,11 @@ def export_1D(data, path, area_method=AREA_METHODS[0], lorentz=False, hkl_precis
|
|||||||
h, k, l = scan["h"], scan["k"], scan["l"]
|
h, k, l = scan["h"], scan["k"], scan["l"]
|
||||||
hkl_are_integers = isinstance(h, int) # if True, other indices are of type 'int' too
|
hkl_are_integers = isinstance(h, int) # if True, other indices are of type 'int' too
|
||||||
if hkl_are_integers:
|
if hkl_are_integers:
|
||||||
hkl_str = f"{h:6}{k:6}{l:6}"
|
hkl_str = f"{h:4}{k:4}{l:4}"
|
||||||
else:
|
else:
|
||||||
hkl_str = f"{h:8.{hkl_precision}f}{k:8.{hkl_precision}f}{l:8.{hkl_precision}f}"
|
hkl_str = f"{h:8.{hkl_precision}f}{k:8.{hkl_precision}f}{l:8.{hkl_precision}f}"
|
||||||
|
|
||||||
for name, param in scan["fit"].params.items():
|
area_n, area_s = scan["area"]
|
||||||
if "amplitude" in name:
|
|
||||||
area_n = param.value
|
|
||||||
area_s = param.stderr
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
area_n = 0
|
|
||||||
area_s = 0
|
|
||||||
|
|
||||||
if area_n is None or area_s is None:
|
|
||||||
print(f"Couldn't export scan: {scan['idx']}")
|
|
||||||
continue
|
|
||||||
|
|
||||||
# apply lorentz correction to area
|
|
||||||
if lorentz:
|
|
||||||
if zebra_mode == "bi":
|
|
||||||
twotheta = np.deg2rad(scan["twotheta"])
|
|
||||||
corr_factor = np.sin(twotheta)
|
|
||||||
else: # zebra_mode == "nb":
|
|
||||||
gamma = np.deg2rad(scan["gamma"])
|
|
||||||
nu = np.deg2rad(scan["nu"])
|
|
||||||
corr_factor = np.sin(gamma) * np.cos(nu)
|
|
||||||
|
|
||||||
area_n = np.abs(area_n * corr_factor)
|
|
||||||
area_s = np.abs(area_s * corr_factor)
|
|
||||||
|
|
||||||
area_str = f"{area_n:10.2f}{area_s:10.2f}"
|
area_str = f"{area_n:10.2f}{area_s:10.2f}"
|
||||||
|
|
||||||
ang_str = ""
|
ang_str = ""
|
||||||
@ -299,12 +285,47 @@ def export_1D(data, path, area_method=AREA_METHODS[0], lorentz=False, hkl_precis
|
|||||||
angle_center = (np.min(scan[angle]) + np.max(scan[angle])) / 2
|
angle_center = (np.min(scan[angle]) + np.max(scan[angle])) / 2
|
||||||
else:
|
else:
|
||||||
angle_center = scan[angle]
|
angle_center = scan[angle]
|
||||||
|
|
||||||
|
if angle == "twotheta" and export_target == "jana":
|
||||||
|
angle_center /= 2
|
||||||
|
|
||||||
ang_str = ang_str + f"{angle_center:8g}"
|
ang_str = ang_str + f"{angle_center:8g}"
|
||||||
|
|
||||||
ref = file_content[".comm"] if hkl_are_integers else file_content[".incomm"]
|
if export_target == "jana":
|
||||||
|
ang_str = ang_str + f"{scan['temp']:8}" + f"{scan['monitor']:8}"
|
||||||
|
|
||||||
|
ref = file_content[exts[0]] if hkl_are_integers else file_content[exts[1]]
|
||||||
ref.append(idx_str + hkl_str + area_str + ang_str + "\n")
|
ref.append(idx_str + hkl_str + area_str + ang_str + "\n")
|
||||||
|
|
||||||
for ext, content in file_content.items():
|
for ext, content in file_content.items():
|
||||||
if content:
|
if content:
|
||||||
with open(path + ext, "w") as out_file:
|
with open(path + ext, "w") as out_file:
|
||||||
out_file.writelines(content)
|
out_file.writelines(content)
|
||||||
|
|
||||||
|
|
||||||
|
def export_param_study(data, param_data, path):
|
||||||
|
file_content = []
|
||||||
|
for scan, param in zip(data, param_data):
|
||||||
|
if "fit" not in scan:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if not file_content:
|
||||||
|
title_str = f"{'param':12}"
|
||||||
|
for fit_param_name in scan["fit"].params:
|
||||||
|
title_str = title_str + f"{fit_param_name:20}" + f"{'std_' + fit_param_name:20}"
|
||||||
|
title_str = title_str + "file"
|
||||||
|
file_content.append(title_str + "\n")
|
||||||
|
|
||||||
|
param_str = f"{param:<12.2f}"
|
||||||
|
|
||||||
|
fit_str = ""
|
||||||
|
for fit_param in scan["fit"].params.values():
|
||||||
|
fit_str = fit_str + f"{fit_param.value:<20.2f}" + f"{fit_param.stderr:<20.2f}"
|
||||||
|
|
||||||
|
_, fname_str = os.path.split(scan["original_filename"])
|
||||||
|
|
||||||
|
file_content.append(param_str + fit_str + fname_str + "\n")
|
||||||
|
|
||||||
|
if file_content:
|
||||||
|
with open(path, "w") as out_file:
|
||||||
|
out_file.writelines(file_content)
|
||||||
|
@ -3,6 +3,7 @@ import os
|
|||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from lmfit.models import GaussianModel, LinearModel, PseudoVoigtModel, VoigtModel
|
from lmfit.models import GaussianModel, LinearModel, PseudoVoigtModel, VoigtModel
|
||||||
|
from scipy.integrate import simpson, trapezoid
|
||||||
|
|
||||||
from .ccl_io import CCL_ANGLES
|
from .ccl_io import CCL_ANGLES
|
||||||
|
|
||||||
@ -22,18 +23,23 @@ MAX_RANGE_GAP = {
|
|||||||
"omega": 0.5,
|
"omega": 0.5,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AREA_METHODS = ("fit_area", "int_area")
|
||||||
|
|
||||||
|
|
||||||
def normalize_dataset(dataset, monitor=100_000):
|
def normalize_dataset(dataset, monitor=100_000):
|
||||||
for scan in dataset:
|
for scan in dataset:
|
||||||
monitor_ratio = monitor / scan["monitor"]
|
monitor_ratio = monitor / scan["monitor"]
|
||||||
scan["Counts"] *= monitor_ratio
|
scan["counts"] *= monitor_ratio
|
||||||
scan["monitor"] = monitor
|
scan["monitor"] = monitor
|
||||||
|
|
||||||
|
|
||||||
def merge_duplicates(dataset):
|
def merge_duplicates(dataset):
|
||||||
for scan_i, scan_j in itertools.combinations(dataset, 2):
|
merged = np.zeros(len(dataset), dtype=np.bool)
|
||||||
if _parameters_match(scan_i, scan_j):
|
for ind_into, scan_into in enumerate(dataset):
|
||||||
merge_scans(scan_i, scan_j)
|
for ind_from, scan_from in enumerate(dataset[ind_into + 1 :], start=ind_into + 1):
|
||||||
|
if _parameters_match(scan_into, scan_from) and not merged[ind_from]:
|
||||||
|
merge_scans(scan_into, scan_from)
|
||||||
|
merged[ind_from] = True
|
||||||
|
|
||||||
|
|
||||||
def _parameters_match(scan1, scan2):
|
def _parameters_match(scan1, scan2):
|
||||||
@ -61,30 +67,45 @@ def _parameters_match(scan1, scan2):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def merge_datasets(dataset1, dataset2):
|
def merge_datasets(dataset_into, dataset_from):
|
||||||
for scan_j in dataset2:
|
merged = np.zeros(len(dataset_from), dtype=np.bool)
|
||||||
for scan_i in dataset1:
|
for scan_into in dataset_into:
|
||||||
if _parameters_match(scan_i, scan_j):
|
for ind, scan_from in enumerate(dataset_from):
|
||||||
merge_scans(scan_i, scan_j)
|
if _parameters_match(scan_into, scan_from) and not merged[ind]:
|
||||||
break
|
merge_scans(scan_into, scan_from)
|
||||||
|
merged[ind] = True
|
||||||
|
|
||||||
dataset1.append(scan_j)
|
for scan_from in dataset_from:
|
||||||
|
dataset_into.append(scan_from)
|
||||||
|
|
||||||
|
|
||||||
def merge_scans(scan1, scan2):
|
def merge_scans(scan_into, scan_from):
|
||||||
omega = np.concatenate((scan1["omega"], scan2["omega"]))
|
# TODO: does it need to be "scan_motor" instead of omega for a generalized solution?
|
||||||
counts = np.concatenate((scan1["Counts"], scan2["Counts"]))
|
if "init_omega" not in scan_into:
|
||||||
|
scan_into["init_omega"] = scan_into["omega"]
|
||||||
|
scan_into["init_counts"] = scan_into["counts"]
|
||||||
|
|
||||||
|
omega = np.concatenate((scan_into["omega"], scan_from["omega"]))
|
||||||
|
counts = np.concatenate((scan_into["counts"], scan_from["counts"]))
|
||||||
|
|
||||||
index = np.argsort(omega)
|
index = np.argsort(omega)
|
||||||
|
|
||||||
scan1["omega"] = omega[index]
|
scan_into["omega"] = omega[index]
|
||||||
scan1["Counts"] = counts[index]
|
scan_into["counts"] = counts[index]
|
||||||
|
|
||||||
scan2["active"] = False
|
scan_from["active"] = False
|
||||||
|
|
||||||
fname1 = os.path.basename(scan1["original_filename"])
|
fname1 = os.path.basename(scan_into["original_filename"])
|
||||||
fname2 = os.path.basename(scan2["original_filename"])
|
fname2 = os.path.basename(scan_from["original_filename"])
|
||||||
print(f'Merging scans: {scan1["idx"]} ({fname1}) <-- {scan2["idx"]} ({fname2})')
|
print(f'Merging scans: {scan_into["idx"]} ({fname1}) <-- {scan_from["idx"]} ({fname2})')
|
||||||
|
|
||||||
|
|
||||||
|
def restore_scan(scan):
|
||||||
|
if "init_omega" in scan:
|
||||||
|
scan["omega"] = scan["init_omega"]
|
||||||
|
scan["counts"] = scan["init_counts"]
|
||||||
|
del scan["init_omega"]
|
||||||
|
del scan["init_counts"]
|
||||||
|
|
||||||
|
|
||||||
def fit_scan(scan, model_dict, fit_from=None, fit_to=None):
|
def fit_scan(scan, model_dict, fit_from=None, fit_to=None):
|
||||||
@ -93,7 +114,7 @@ def fit_scan(scan, model_dict, fit_from=None, fit_to=None):
|
|||||||
if fit_to is None:
|
if fit_to is None:
|
||||||
fit_to = np.inf
|
fit_to = np.inf
|
||||||
|
|
||||||
y_fit = scan["Counts"]
|
y_fit = scan["counts"]
|
||||||
x_fit = scan[scan["scan_motor"]]
|
x_fit = scan[scan["scan_motor"]]
|
||||||
|
|
||||||
# apply fitting range
|
# apply fitting range
|
||||||
@ -128,6 +149,17 @@ def fit_scan(scan, model_dict, fit_from=None, fit_to=None):
|
|||||||
else:
|
else:
|
||||||
param_hints[hint_name] = tmp
|
param_hints[hint_name] = tmp
|
||||||
|
|
||||||
|
if "center" in param_name:
|
||||||
|
if np.isneginf(param_hints["min"]):
|
||||||
|
param_hints["min"] = np.min(x_fit)
|
||||||
|
|
||||||
|
if np.isposinf(param_hints["max"]):
|
||||||
|
param_hints["max"] = np.max(x_fit)
|
||||||
|
|
||||||
|
if "sigma" in param_name:
|
||||||
|
if np.isposinf(param_hints["max"]):
|
||||||
|
param_hints["max"] = np.max(x_fit) - np.min(x_fit)
|
||||||
|
|
||||||
_model.set_param_hint(param_name, **param_hints)
|
_model.set_param_hint(param_name, **param_hints)
|
||||||
|
|
||||||
if model is None:
|
if model is None:
|
||||||
@ -137,3 +169,42 @@ def fit_scan(scan, model_dict, fit_from=None, fit_to=None):
|
|||||||
|
|
||||||
weights = [1 / np.sqrt(val) if val != 0 else 1 for val in y_fit]
|
weights = [1 / np.sqrt(val) if val != 0 else 1 for val in y_fit]
|
||||||
scan["fit"] = model.fit(y_fit, x=x_fit, weights=weights)
|
scan["fit"] = model.fit(y_fit, x=x_fit, weights=weights)
|
||||||
|
|
||||||
|
|
||||||
|
def get_area(scan, area_method, lorentz):
|
||||||
|
if area_method not in AREA_METHODS:
|
||||||
|
raise ValueError(f"Unknown area method: {area_method}.")
|
||||||
|
|
||||||
|
if area_method == "fit_area":
|
||||||
|
area_v = 0
|
||||||
|
area_s = 0
|
||||||
|
for name, param in scan["fit"].params.items():
|
||||||
|
if "amplitude" in name:
|
||||||
|
if param.stderr is None:
|
||||||
|
area_v = np.nan
|
||||||
|
area_s = np.nan
|
||||||
|
else:
|
||||||
|
area_v += param.value
|
||||||
|
area_s += param.stderr
|
||||||
|
|
||||||
|
else: # area_method == "int_area"
|
||||||
|
y_val = scan["counts"]
|
||||||
|
x_val = scan[scan["scan_motor"]]
|
||||||
|
y_bkg = scan["fit"].eval_components(x=x_val)["f0_"]
|
||||||
|
area_v = simpson(y_val, x=x_val) - trapezoid(y_bkg, x=x_val)
|
||||||
|
area_s = np.sqrt(area_v)
|
||||||
|
|
||||||
|
if lorentz:
|
||||||
|
# lorentz correction to area
|
||||||
|
if scan["zebra_mode"] == "bi":
|
||||||
|
twotheta = np.deg2rad(scan["twotheta"])
|
||||||
|
corr_factor = np.sin(twotheta)
|
||||||
|
else: # zebra_mode == "nb":
|
||||||
|
gamma = np.deg2rad(scan["gamma"])
|
||||||
|
nu = np.deg2rad(scan["nu"])
|
||||||
|
corr_factor = np.sin(gamma) * np.cos(nu)
|
||||||
|
|
||||||
|
area_v = np.abs(area_v * corr_factor)
|
||||||
|
area_s = np.abs(area_s * corr_factor)
|
||||||
|
|
||||||
|
scan["area"] = (area_v, area_s)
|
||||||
|
@ -1,6 +1,11 @@
|
|||||||
import h5py
|
import h5py
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
|
||||||
|
META_MATRIX = ("UB")
|
||||||
|
META_CELL = ("cell")
|
||||||
|
META_STR = ("name")
|
||||||
|
|
||||||
def read_h5meta(filepath):
|
def read_h5meta(filepath):
|
||||||
"""Open and parse content of a h5meta file.
|
"""Open and parse content of a h5meta file.
|
||||||
|
|
||||||
@ -23,18 +28,37 @@ def parse_h5meta(file):
|
|||||||
line = line.strip()
|
line = line.strip()
|
||||||
if line.startswith("#begin "):
|
if line.startswith("#begin "):
|
||||||
section = line[len("#begin ") :]
|
section = line[len("#begin ") :]
|
||||||
content[section] = []
|
if section in ("detector parameters", "crystal"):
|
||||||
|
content[section] = {}
|
||||||
|
else:
|
||||||
|
content[section] = []
|
||||||
|
|
||||||
elif line.startswith("#end"):
|
elif line.startswith("#end"):
|
||||||
section = None
|
section = None
|
||||||
|
|
||||||
elif section:
|
elif section:
|
||||||
content[section].append(line)
|
if section in ("detector parameters", "crystal"):
|
||||||
|
if "=" in line:
|
||||||
|
variable, value = line.split("=", 1)
|
||||||
|
variable = variable.strip()
|
||||||
|
value = value.strip()
|
||||||
|
|
||||||
|
if variable in META_STR:
|
||||||
|
pass
|
||||||
|
elif variable in META_CELL:
|
||||||
|
value = np.array(value.split(",")[:6], dtype=np.float)
|
||||||
|
elif variable in META_MATRIX:
|
||||||
|
value = np.array(value.split(",")[:9], dtype=np.float).reshape(3, 3)
|
||||||
|
else: # default is a single float number
|
||||||
|
value = float(value)
|
||||||
|
content[section][variable] = value
|
||||||
|
else:
|
||||||
|
content[section].append(line)
|
||||||
|
|
||||||
return content
|
return content
|
||||||
|
|
||||||
|
|
||||||
def read_detector_data(filepath):
|
def read_detector_data(filepath, cami_meta=None):
|
||||||
"""Read detector data and angles from an h5 file.
|
"""Read detector data and angles from an h5 file.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -51,12 +75,18 @@ def read_detector_data(filepath):
|
|||||||
data = data.reshape(n, rows, cols)
|
data = data.reshape(n, rows, cols)
|
||||||
|
|
||||||
det_data = {"data": data}
|
det_data = {"data": data}
|
||||||
|
det_data["original_filename"] = filepath
|
||||||
|
|
||||||
if "/entry1/zebra_mode" in h5f:
|
if "/entry1/zebra_mode" in h5f:
|
||||||
det_data["zebra_mode"] = h5f["/entry1/zebra_mode"][0].decode()
|
det_data["zebra_mode"] = h5f["/entry1/zebra_mode"][0].decode()
|
||||||
else:
|
else:
|
||||||
det_data["zebra_mode"] = "nb"
|
det_data["zebra_mode"] = "nb"
|
||||||
|
|
||||||
|
# overwrite zebra_mode from cami
|
||||||
|
if cami_meta is not None:
|
||||||
|
if "zebra_mode" in cami_meta:
|
||||||
|
det_data["zebra_mode"] = cami_meta["zebra_mode"][0]
|
||||||
|
|
||||||
# om, sometimes ph
|
# om, sometimes ph
|
||||||
if det_data["zebra_mode"] == "nb":
|
if det_data["zebra_mode"] == "nb":
|
||||||
det_data["omega"] = h5f["/entry1/area_detector2/rotation_angle"][:]
|
det_data["omega"] = h5f["/entry1/area_detector2/rotation_angle"][:]
|
||||||
@ -70,6 +100,8 @@ def read_detector_data(filepath):
|
|||||||
det_data["chi"] = h5f["/entry1/sample/chi"][:] # ch
|
det_data["chi"] = h5f["/entry1/sample/chi"][:] # ch
|
||||||
det_data["phi"] = h5f["/entry1/sample/phi"][:] # ph
|
det_data["phi"] = h5f["/entry1/sample/phi"][:] # ph
|
||||||
det_data["ub"] = h5f["/entry1/sample/UB"][:].reshape(3, 3)
|
det_data["ub"] = h5f["/entry1/sample/UB"][:].reshape(3, 3)
|
||||||
|
det_data["name"] = h5f["/entry1/sample/name"][0].decode()
|
||||||
|
det_data["cell"] = h5f["/entry1/sample/cell"][:]
|
||||||
|
|
||||||
for var in ("omega", "gamma", "nu", "chi", "phi"):
|
for var in ("omega", "gamma", "nu", "chi", "phi"):
|
||||||
if abs(det_data[var][0] - det_data[var][-1]) > 0.1:
|
if abs(det_data[var][0] - det_data[var][-1]) > 0.1:
|
||||||
@ -85,4 +117,22 @@ def read_detector_data(filepath):
|
|||||||
if "/entry1/sample/temperature" in h5f:
|
if "/entry1/sample/temperature" in h5f:
|
||||||
det_data["temp"] = h5f["/entry1/sample/temperature"][:]
|
det_data["temp"] = h5f["/entry1/sample/temperature"][:]
|
||||||
|
|
||||||
|
# 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:
|
||||||
|
det_data["name"] = cami_meta_crystal["name"]
|
||||||
|
if "UB" in cami_meta_crystal:
|
||||||
|
det_data["ub"] = cami_meta_crystal["UB"]
|
||||||
|
if "cell" in cami_meta_crystal:
|
||||||
|
det_data["cell"] = cami_meta_crystal["cell"]
|
||||||
|
if "lambda" in cami_meta_crystal:
|
||||||
|
det_data["wave"] = cami_meta_crystal["lambda"]
|
||||||
|
|
||||||
|
if "detector parameters" in cami_meta:
|
||||||
|
cami_meta_detparam = cami_meta["detector parameters"]
|
||||||
|
if "dist1" in cami_meta_detparam:
|
||||||
|
det_data["ddist"] = cami_meta_detparam["dist1"]
|
||||||
|
|
||||||
return det_data
|
return det_data
|
||||||
|
@ -1,15 +1,5 @@
|
|||||||
import math
|
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from numba import njit
|
from numba import njit
|
||||||
from scipy.optimize import curve_fit
|
|
||||||
|
|
||||||
import pyzebra
|
|
||||||
|
|
||||||
try:
|
|
||||||
from matplotlib import pyplot as plt
|
|
||||||
except ImportError:
|
|
||||||
print("matplotlib is not available")
|
|
||||||
|
|
||||||
pi_r = 180 / np.pi
|
pi_r = 180 / np.pi
|
||||||
|
|
||||||
@ -393,84 +383,3 @@ def gauss(x, *p):
|
|||||||
"""
|
"""
|
||||||
A, mu, sigma = p
|
A, mu, sigma = p
|
||||||
return A * np.exp(-((x - mu) ** 2) / (2.0 * sigma ** 2))
|
return A * np.exp(-((x - mu) ** 2) / (2.0 * sigma ** 2))
|
||||||
|
|
||||||
|
|
||||||
def box_int(file, box):
|
|
||||||
"""Calculates center of the peak in the NB-geometry angles and Intensity of the peak
|
|
||||||
|
|
||||||
Args:
|
|
||||||
file name, box size [x0:xN, y0:yN, fr0:frN]
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
gamma, omPeak, nu polar angles, Int and data for 3 fit plots
|
|
||||||
"""
|
|
||||||
|
|
||||||
dat = pyzebra.read_detector_data(file)
|
|
||||||
|
|
||||||
sttC = dat["gamma"][0]
|
|
||||||
om = dat["omega"]
|
|
||||||
nuC = dat["nu"][0]
|
|
||||||
ddist = dat["ddist"]
|
|
||||||
|
|
||||||
# defining indices
|
|
||||||
x0, xN, y0, yN, fr0, frN = box
|
|
||||||
|
|
||||||
# omega fit
|
|
||||||
om = dat["omega"][fr0:frN]
|
|
||||||
cnts = np.sum(dat["data"][fr0:frN, y0:yN, x0:xN], axis=(1, 2))
|
|
||||||
|
|
||||||
p0 = [1.0, 0.0, 1.0]
|
|
||||||
coeff, var_matrix = curve_fit(gauss, range(len(cnts)), cnts, p0=p0)
|
|
||||||
|
|
||||||
frC = fr0 + coeff[1]
|
|
||||||
omF = dat["omega"][math.floor(frC)]
|
|
||||||
omC = dat["omega"][math.ceil(frC)]
|
|
||||||
frStep = frC - math.floor(frC)
|
|
||||||
omStep = omC - omF
|
|
||||||
omP = omF + omStep * frStep
|
|
||||||
Int = coeff[1] * abs(coeff[2] * omStep) * math.sqrt(2) * math.sqrt(np.pi)
|
|
||||||
# omega plot
|
|
||||||
x_fit = np.linspace(0, len(cnts), 100)
|
|
||||||
y_fit = gauss(x_fit, *coeff)
|
|
||||||
plt.figure()
|
|
||||||
plt.subplot(131)
|
|
||||||
plt.plot(range(len(cnts)), cnts)
|
|
||||||
plt.plot(x_fit, y_fit)
|
|
||||||
plt.ylabel("Intensity in the box")
|
|
||||||
plt.xlabel("Frame N of the box")
|
|
||||||
label = "om"
|
|
||||||
# gamma fit
|
|
||||||
sliceXY = dat["data"][fr0:frN, y0:yN, x0:xN]
|
|
||||||
sliceXZ = np.sum(sliceXY, axis=1)
|
|
||||||
sliceYZ = np.sum(sliceXY, axis=2)
|
|
||||||
|
|
||||||
projX = np.sum(sliceXZ, axis=0)
|
|
||||||
p0 = [1.0, 0.0, 1.0]
|
|
||||||
coeff, var_matrix = curve_fit(gauss, range(len(projX)), projX, p0=p0)
|
|
||||||
x = x0 + coeff[1]
|
|
||||||
# gamma plot
|
|
||||||
x_fit = np.linspace(0, len(projX), 100)
|
|
||||||
y_fit = gauss(x_fit, *coeff)
|
|
||||||
plt.subplot(132)
|
|
||||||
plt.plot(range(len(projX)), projX)
|
|
||||||
plt.plot(x_fit, y_fit)
|
|
||||||
plt.ylabel("Intensity in the box")
|
|
||||||
plt.xlabel("X-pixel of the box")
|
|
||||||
|
|
||||||
# nu fit
|
|
||||||
projY = np.sum(sliceYZ, axis=0)
|
|
||||||
p0 = [1.0, 0.0, 1.0]
|
|
||||||
coeff, var_matrix = curve_fit(gauss, range(len(projY)), projY, p0=p0)
|
|
||||||
y = y0 + coeff[1]
|
|
||||||
# nu plot
|
|
||||||
x_fit = np.linspace(0, len(projY), 100)
|
|
||||||
y_fit = gauss(x_fit, *coeff)
|
|
||||||
plt.subplot(133)
|
|
||||||
plt.plot(range(len(projY)), projY)
|
|
||||||
plt.plot(x_fit, y_fit)
|
|
||||||
plt.ylabel("Intensity in the box")
|
|
||||||
plt.xlabel("Y-pixel of the box")
|
|
||||||
|
|
||||||
ga, nu = pyzebra.det2pol(ddist, sttC, nuC, x, y)
|
|
||||||
|
|
||||||
return ga[0], omP, nu[0], Int
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
source /home/pyzebra/miniconda3/etc/profile.d/conda.sh
|
source /home/pyzebra/miniconda3/etc/profile.d/conda.sh
|
||||||
|
|
||||||
conda activate prod
|
conda activate prod
|
||||||
pyzebra --port=80 --allow-websocket-origin=pyzebra.psi.ch:80
|
pyzebra --port=80 --allow-websocket-origin=pyzebra.psi.ch:80 --spind-path=/home/pyzebra/spind
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
source /home/pyzebra/miniconda3/etc/profile.d/conda.sh
|
source /home/pyzebra/miniconda3/etc/profile.d/conda.sh
|
||||||
|
|
||||||
conda activate test
|
conda activate test
|
||||||
python ~/pyzebra/pyzebra/app/cli.py --allow-websocket-origin=pyzebra.psi.ch:5006
|
python ~/pyzebra/pyzebra/app/cli.py --allow-websocket-origin=pyzebra.psi.ch:5006 --spind-path=/home/pyzebra/spind
|
||||||
|
Reference in New Issue
Block a user