Skip to content

Commit 9e550d2

Browse files
daniloeflDanilo Ferreira de Lima
andauthored
Fixed behaviour of TOF response reading due to change in API in PR483. (#506)
* Fixed behaviour of TOF response reading due to change in API in PR483. * Change order of data reading and selection when estimating response to optimize for speed. --------- Co-authored-by: Danilo Ferreira de Lima <danilo.enoque.ferreira.de.lima@xfel.de>
1 parent 3c5857a commit 9e550d2

4 files changed

Lines changed: 20 additions & 9 deletions

File tree

docs/changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ Fixed:
8585
- Fixed support for plotting images with zeros/negative numbers with
8686
[imshow2()][extra.utils.imshow2] and `lognorm=True` (!491).
8787
- Fixed counting threshold for `CookieboxCalibration` (!498).
88+
- [CookieboxCalibration][extra.applications.CookieboxCalibration] bug fix for
89+
new `extra.applications.base.SerializableMixin` interface (!506).
8890

8991
Changed:
9092

src/extra/applications/cookiebox.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,8 +453,7 @@ def _fromdict(cls, all_data):
453453
if "_tof_response" in all_data.keys():
454454
self._tof_response = dict()
455455
for tof_id in sorted(all_data["_tof_response"].keys()):
456-
self._tof_response[tof_id] = TOFAnalogResponse()
457-
self._tof_response[tof_id]._fromdict(all_data["_tof_response"][tof_id])
456+
self._tof_response[tof_id] = TOFAnalogResponse._fromdict(all_data["_tof_response"][tof_id])
458457
return self
459458

460459
def setup(self,

src/extra/applications/cookiebox_deconvolve.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -457,13 +457,16 @@ def setup(self,
457457
data = list()
458458
h = list()
459459
bins = np.arange(0, self.n_samples+1)
460-
if scan is not None:
461-
for k, e in enumerate(scan.positions):
462-
tof_data = tof.select_trains(by_id[scan.positions_train_ids[k]])
463-
if self.count_threshold is None or self.count_threshold >= 0:
464-
this_tof_data = -tof_data.pulse_data(pulse_dim="pulseIndex").mean('pulse')
465-
else:
466-
tof_data = tof_data.pulse_edges(pulse_dim='pulseIndex', threshold=self.count_threshold).reset_index()
460+
if scan is not None: # use the scan
461+
# if not counting photo-electrons -- ie: analog mode
462+
if self.count_threshold is None or self.count_threshold >= 0:
463+
this_tof_data = -tof.pulse_data(pulse_dim="pulseIndex").unstack("pulse")
464+
for k, e in enumerate(scan.positions):
465+
data += [this_tof_data.sel(trainId=scan.positions_train_ids[k]).mean("trainId").mean("pulseIndex").to_numpy()]
466+
else:
467+
# count photo-electrons by histogramming peak positions
468+
for k, e in enumerate(scan.positions):
469+
tof_data = tof.pulse_edges(pulse_dim='pulseIndex', threshold=self.count_threshold).reset_index()
467470
this_tof_data, _ = np.histogram(tof_data.edge, bins=bins, weights=-tof_data.amplitude)
468471
this_tof_data = xr.DataArray(this_tof_data, dims=('sample'), coords={'sample': bins[:-1]})
469472
if self.roi is not None:

tests/test_applications_cookiebox.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,13 @@ def test_deconvolve(mock_sqs_etof_calibration_run, tmp_path):
432432
tof_response.to_file(fpath)
433433
tof_response_read = TOFAnalogResponse.from_file(fpath)
434434

435+
# setup TOFAnalogResponse using counting of photo-electrons
436+
tof_response_count = TOFAnalogResponse(roi=slice(75, None), n_samples=150, count_threshold=-20)
437+
tof_response_count.setup(tof_channel[0], scan)
438+
439+
# setup TOFAnalogResponse without Scan
440+
tof_response_noscan = TOFAnalogResponse(roi=slice(75, None), n_samples=150)
441+
tof_response_noscan.setup(tof_channel[0])
435442

436443
# create calibration object to read data in the appropriate format
437444
energy_axis = np.linspace(965, 1070, 160)

0 commit comments

Comments
 (0)