Skip to content

Commit ff368ed

Browse files
authored
Add EuXFEL attritutes to experiment and detector groups in the virtual CXI files. (#749)
* Write proposal and run numbers to virtual CXI files. * Check if proposal and run numbers are in run_metadata. * Store proposal and run numbers as attributes of the experiment entry. * Store detector name as an attribute. * Add experiment 'name' as an attribute of entry_1. * Change entry_1 attributes names to euxfelProposalNumber and euxfelRunNumber.
1 parent b4167ae commit ff368ed

1 file changed

Lines changed: 20 additions & 10 deletions

File tree

extra_data/write_cxi.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -240,20 +240,30 @@ def write(self, filename, fillvalues=None):
240240
# be read by HDF5 1.10.
241241
with h5py.File(filename, 'w', libver=('v110', 'v110')) as f:
242242
f.create_dataset('cxi_version', data=[150])
243-
d = f.create_dataset('entry_1/experiment_identifier',
244-
shape=experiment_ids.shape,
245-
dtype=h5py.special_dtype(vlen=str))
243+
expgrp = f.create_group('entry_1')
244+
d = expgrp.create_dataset(
245+
'experiment_identifier',
246+
shape=experiment_ids.shape,
247+
dtype=h5py.special_dtype(vlen=str)
248+
)
246249
d[:] = experiment_ids
247250

248-
# pulseId, trainId, cellId are not part of the CXI standard,
249-
# but it allows extra data.
250-
f.create_dataset(f'entry_1/{self.pulse_id_label}', data=pulse_ids)
251-
f.create_dataset('entry_1/trainId', data=self.train_ids_perframe)
252-
cellids = f.create_virtual_dataset('entry_1/cellId',
253-
layouts[self.cell_id_label])
251+
# proposal, run, pulseId, trainId, cellId are not part of
252+
# the CXI standard, but it allows extra data.
253+
run_metadata = self.detdata.data.run_metadata()
254+
if 'proposalNumber' in run_metadata and 'runNumber' in run_metadata:
255+
expgrp.attrs['name'] = f"EuXFEL proposal {run_metadata['proposalNumber']}" \
256+
f" run {run_metadata['runNumber']}"
257+
expgrp.attrs['euxfelProposalNumber'] = run_metadata['proposalNumber']
258+
expgrp.attrs['euxfelRunNumber'] = run_metadata['runNumber']
259+
expgrp.create_dataset(f'{self.pulse_id_label}', data=pulse_ids)
260+
expgrp.create_dataset('trainId', data=self.train_ids_perframe)
261+
cellids = expgrp.create_virtual_dataset('cellId', layouts[self.cell_id_label])
254262
cellids.attrs['axes'] = 'experiment_identifier:module_identifier'
255263

256-
dgrp = f.create_group('entry_1/instrument_1/detector_1')
264+
dgrp = expgrp.create_group('instrument_1/detector_1')
265+
# Store detector name as an attribute
266+
dgrp.attrs['name'] = self.detdata.detector_name
257267
if len(layouts[data_label].shape) == 4:
258268
axes_s = 'experiment_identifier:module_identifier:y:x'
259269
else:

0 commit comments

Comments
 (0)