-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add energy (FEE/Ebeam) calibration to the XFEL UI
- EnergyTab is a new tab in the GUI where the user can use the FEE calibration tools, generate and view associated plots, and export a phil file with the results. The phil can be imported into rungroups directly, avoiding manual transcription errors. This includes the FEE spectrometer calibration from the notch scan as well as visualizing and calculating the Ebeam offset -- that is, spectrum_eV_offset, spectrum_eV_per_pixel, and wavelength_offset. (Note, we really should consider renaming these and doing all adjustments in eV.) - CalibWorker is a new thread running in the background, executing any requested calibration tasks (so far just for EnergyTab). - ebeam_plotter.py is the plotting tool to replace the command line script thing.py for use in the GUI. - Small necessary changes were made to existing calibration and visualization scripts to make them able to accept an existing matplotlib figure and add plots to it, and to write out results. - Note of caution, window resizing seems to be crash-prone. Not entirely sure why, but given this fact, I haven't put work into making things resize nicely for different screen sizes. This is all optimized for the control room at MFX.
- Loading branch information
1 parent
7c1c51f
commit 75ead7a
Showing
4 changed files
with
631 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
from __future__ import division | ||
|
||
import dxtbx | ||
from xfel.cxi.cspad_ana import cspad_tbx | ||
from matplotlib import pyplot as plt | ||
import numpy as np | ||
from simtbx.nanoBragg.utils import ENERGY_CONV | ||
|
||
def compare_ebeams_with_fees(locfiles, runs=None, plot=True, use_figure=None): | ||
if plot: | ||
fig = use_figure or plt.figure() | ||
ax = fig.subplots() | ||
|
||
ebeam_eV_offsets = [] | ||
ebeam_wav_offsets = [] | ||
|
||
for i in range(len(locfiles)): | ||
if locfiles[i] is None: | ||
if plot: | ||
ax.plot([],[], label='No data for run {runs[i]}') | ||
continue | ||
|
||
img = dxtbx.load(locfiles[i]) | ||
n_img = img.get_num_images() | ||
|
||
ebeams_eV = [] | ||
ebeams_wav = [] | ||
fee_coms_eV = [] | ||
fee_coms_wav = [] | ||
|
||
for j in range(n_img): | ||
if not img.get_spectrum(j): | ||
continue # no FEE | ||
ewav = cspad_tbx.evt_wavelength(img._get_event(j)) | ||
if not ewav: | ||
continue # no ebeam | ||
fee_coms_wav.append(fwav:=img.get_beam(j).get_wavelength()) | ||
fee_coms_eV.append(feV:=ENERGY_CONV/fwav) | ||
ebeams_wav.append(ewav) | ||
ebeams_eV.append(eeV:=ENERGY_CONV/ewav) | ||
print(f'{i}: {int(feV)} eV FEE / {int(eeV)} eV Ebeam') | ||
|
||
if plot: | ||
ax.hist(ebeams_eV, alpha=0.5, bins=40, label=f'run {runs[i]} ebeams ({int(eeV)} eV)') | ||
ax.hist(fee_coms_eV, alpha=0.5, bins=40, label=f'run {runs[i]} FEE COMs ({int(feV)} eV)') | ||
|
||
diffs_eV = np.array(fee_coms_eV) - np.array(ebeams_eV) | ||
ebeam_eV_offsets.append(sum(diffs_eV)/len(diffs_eV)) | ||
diffs_wav = np.array(fee_coms_wav) - np.array(ebeams_wav) | ||
ebeam_wav_offsets.append(sum(diffs_wav)/len(diffs_wav)) | ||
|
||
if plot: | ||
ax.legend() | ||
ax.set_xlabel('Energy (eV)') | ||
ax.set_ylabel('Counts') | ||
ax.set_title('Ebeam vs Calibrated FEE') | ||
if not use_figure: | ||
plt.show() | ||
|
||
return (sum(ebeam_eV_offsets)/len(ebeam_eV_offsets), | ||
sum(ebeam_wav_offsets)/len(ebeam_wav_offsets)) | ||
|
Oops, something went wrong.
75ead7a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I notice I'm failing syntax tests on python ≤ 3.7. Someone remind me how to override this?
75ead7a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For syntax incompatible with python2, add file path to
.azure-pipelines/py2_syntax_exceptions.txt
75ead7a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know a way to ignore python 3.7 syntax, though I do not immediately see anything incompatible with it.
EDIT: Ah walrus operator. I think we got rid of those the last time :)
75ead7a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, walrus operator. I thought purging walrus operators was a stopgap for a dependency snafu with psana though -- are we still avoiding them? They're compatible with our current builds at LCLS.
75ead7a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated the pipeline to also ignore the files in
.azure-pipelines/py2_syntax_exceptions.txt
for Python 3.7. We'll be stopping Python 2.7 and 3.7 checks by the end of this year.