scippneutron.io.cif.CIF#
- class scippneutron.io.cif.CIF(name='', *, comment='')[source]#
A builder for CIF files.
This class implements a builder pattern for defining the contents of a CIF file. See the module documentation of
cif
for examples.Methods
__init__
([name, comment])copy
()Return a copy of this builder.
save
(fname)with_authors
(*authors)Add one or more authors.
with_beamline
(*, beamline[, facility, ...])Add beamline information.
with_powder_calibration
(cal, *[, comment])Add a powder calibration table.
with_reduced_powder_data
(data, *[, comment])Add a loop with reduced powder data.
with_reducers
(*reducers)Add one or more programs that were used to reduce the software.
Attributes
Optional comment that can be written at the top of the file.
name
CIF schemas used for the file.
- with_beamline(*, beamline, facility=None, device=None, comment='')[source]#
Add beamline information.
- Return type:
- with_powder_calibration(cal, *, comment='')[source]#
Add a powder calibration table.
The calibration data encode the following transformation from d-spacing to time-of-flight:
\[t = \sum_{i=0}^N\, c_i d^{p_i}\]where \(c_i\) is the i-th element of
cal
and \(p^{p_i}\) is the i-th element ofcal.coords['power']
.- Parameters:
- Returns:
CIF
– A builder with added calibration data.
Examples
Add a mockup calibration table:
>>> import scipp as sc >>> from scippneutron.io import cif >>> cal = sc.DataArray( ... sc.array(dims=['cal'], values=[3.4, 0.2]), ... coords={'power': sc.array(dims=['cal'], values=[0, 1])}, ... ) >>> cif_ = cif.CIF('powder-calibration') >>> cif_ = cif_.with_powder_calibration(cal)
- with_reduced_powder_data(data, *, comment='')[source]#
Add a loop with reduced powder data.
The input must be 1-dimensional with a dimension name in
('tof', 'dspacing')
. The data array may also have a name in('intensity_net', 'intensity_norm', 'intensity_total')
. If the name is not set, it defaults to'intensity_norm'
, which is appropriate for typical outputs from data reduction. See COMCIFS/Powder_DictionaryThe data gets written as intensity along a single coord whose name matches the dimension name. Standard uncertainties are also written if present.
The unit of the coordinate must match the requirement of pdCIF.
- Parameters:
- Returns:
CIF
– A builder with added reduced data.
Examples
Make mockup powder diffraction data:
>>> import scipp as sc >>> tof = sc.array(dims=['tof'], values=[1.2, 1.4, 2.3], unit='us') >>> intensity = sc.array( ... dims=['tof'], ... values=[13.6, 26.0, 9.7], ... variances=[0.7, 1.1, 0.5], ... )
Add to a CIF builder:
>>> from scippneutron.io import cif >>> cif_ = cif.CIF('reduced-data') >>> da = sc.DataArray(intensity, coords={'tof': tof}) >>> cif_ = cif_.with_reduced_powder_data(da)