Add export to param_study
This commit is contained in:
parent
b8968192ca
commit
c86466b470
@ -54,18 +54,23 @@ import pyzebra
|
|||||||
from pyzebra.ccl_process 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++;
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@ -79,7 +84,7 @@ def create():
|
|||||||
doc = curdoc()
|
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 file_select_update_for_proposal():
|
def file_select_update_for_proposal():
|
||||||
proposal = proposal_textinput.value.strip()
|
proposal = proposal_textinput.value.strip()
|
||||||
@ -148,7 +153,7 @@ 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
|
append_upload_button.disabled = False
|
||||||
@ -184,7 +189,7 @@ 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
|
append_upload_button.disabled = False
|
||||||
@ -698,34 +703,38 @@ def create():
|
|||||||
|
|
||||||
lorentz_checkbox = CheckboxGroup(labels=["Lorentz Correction"], width=145, margin=(13, 5, 5, 5))
|
lorentz_checkbox = CheckboxGroup(labels=["Lorentz Correction"], width=145, margin=(13, 5, 5, 5))
|
||||||
|
|
||||||
export_preview_textinput = TextAreaInput(title="Export file(s) preview:", width=450, height=400)
|
export_preview_textinput = TextAreaInput(title="Export file preview:", width=450, height=400)
|
||||||
|
|
||||||
def _update_preview():
|
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(export_data, temp_file, "fullprof")
|
pyzebra.export_param_study(export_data, param_data, temp_file)
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
save_button = Button(label="Download File(s)", button_type="success", width=220)
|
save_button = Button(label="Download File", button_type="success", width=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(
|
||||||
|
@ -301,3 +301,31 @@ def export_1D(data, path, export_target, hkl_precision=2):
|
|||||||
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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user