Skip to content

Commit

Permalink
Add include_spectra for creating JF16M NeXus master files
Browse files Browse the repository at this point in the history
Uses the convention of nexusformat/definitions#717 with the addition of a yet-unofficial field, incident_wavelength_calculated, to store the calculated wavelength SwissFEL provides. This wavelength comes from a smoothed, fitted processing of the spectra.  As it can be considered derived information, so is in a separate dataset.
  • Loading branch information
phyy-nx committed Apr 3, 2020
1 parent 22ff789 commit af61095
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions xfel/swissfel/jf16m_cxigeom2nexus.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
.type = path
.help = Overrides wavelength. Reads the pulse IDs in the provided file \
to get a list of wavelengths for the master.
include_spectra = False
.type = bool
.help = If true, 2D spectral data will be included in the master file, \
as read from the beam_file.
mask_file = None
.type = str
.help = Path to file with external bad pixel mask.
Expand Down Expand Up @@ -128,10 +132,27 @@ def create_nexus_master_file(self):
beam_pulse_ids = beam_h5['data/SARFE10-PSSS059:SPECTRUM_CENTER/pulse_id'][()]
beam_energies = beam_h5['data/SARFE10-PSSS059:SPECTRUM_CENTER/data'][()]
energies = np.ndarray((len(data_pulse_ids),), dtype='f8')
if self.params.include_spectra:
beam_spectra_x = beam_h5['data/SARFE10-PSSS059:SPECTRUM_X/data'][()]
beam_spectra_y = beam_h5['data/SARFE10-PSSS059:SPECTRUM_Y/data'][()]
spectra_x = np.ndarray((len(data_pulse_ids),beam_spectra_x.shape[1]), dtype='f8')
spectra_y = np.ndarray((len(data_pulse_ids),beam_spectra_y.shape[1]), dtype='f8')

for i, pulse_id in enumerate(data_pulse_ids):
energies[i] = beam_energies[np.where(beam_pulse_ids==pulse_id)[0][0]]
where = np.where(beam_pulse_ids==pulse_id)[0][0]
energies[i] = beam_energies[where]
if self.params.include_spectra:
spectra_x[i] = beam_spectra_x[where]
spectra_y[i] = beam_spectra_y[where]

wavelengths = 12398.4187/energies
beam.create_dataset('incident_wavelength', wavelengths.shape, data=wavelengths, dtype=wavelengths.dtype)
if self.params.include_spectra:
beam.create_dataset('incident_wavelength', spectra_x.shape, data=12398.4187/spectra_x, dtype=spectra_x.dtype)
beam.create_dataset('incident_wavelength_weight', spectra_y.shape, data=spectra_y, dtype=spectra_y.dtype)
beam.create_dataset('incident_wavelength_calculated', wavelengths.shape, data=wavelengths, dtype=wavelengths.dtype)
beam['incident_wavelength_calculated'].attrs['units'] = 'angstrom'
else:
beam.create_dataset('incident_wavelength', wavelengths.shape, data=wavelengths, dtype=wavelengths.dtype)
else:
assert self.params.wavelength is not None, "Provide a wavelength"
beam.create_dataset('incident_wavelength', (1,), data=self.params.wavelength, dtype='f8')
Expand Down

0 comments on commit af61095

Please sign in to comment.