scippneutron.io.cif.Block#
- class scippneutron.io.cif.Block(name, content=None, *, comment='', schema=None)#
A CIF data block.
A block contains an ordered sequence of loops and chunks (groups of key-value-pairs). The contents are written to file in the order specified in the block.
- __init__(name, content=None, *, comment='', schema=None)#
Create a new CIF data block.
- Parameters:
name (
str
) – Name of the block. Can contain any non-whitespace characters. Can be at most 75 characters long.content (
Optional
[Iterable
[Union
[Mapping
[str
,Any
],Loop
,Chunk
]]], default:None
) – Initial loops and chunks.dicts
are converted toscippneutron.io.cif.Chunk
.comment (
str
, default:''
) – Optional comment that can be written above the block in the file.schema (
Union
[CIFSchema
,Iterable
[CIFSchema
],None
], default:None
) – CIF Schema used for the block. Content is not checked against the schema, but the schema is written to the file.
Methods
__init__
(name[, content, comment, schema])Create a new CIF data block.
add
(content, /[, comment])Add a chunk or loop to the end of the block.
add_powder_calibration
(cal, *[, comment])Add a powder calibration table.
add_reduced_powder_data
(data, *[, comment])Add a loop with reduced powder data.
write
(f)Write this block to a file.
Attributes
Optional comment that can be written above the block in the file.
Name of the block.
CIF Schema used for the block.
- add(content, /, comment='')#
Add a chunk or loop to the end of the block.
- add_powder_calibration(cal, *, comment='')#
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:
- Return type:
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])}, ... ) >>> block = cif.Block('powder-calibration') >>> block.add_powder_calibration(cal)
- add_reduced_powder_data(data, *, comment='')#
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_net'
.The 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:
- Return type:
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 block:
>>> from scippneutron.io import cif >>> block = cif.Block('reduced-data') >>> da = sc.DataArray(intensity, coords={'tof': tof}) >>> block.add_reduced_powder_data(da)
- write(f)#
Write this block to a file.
Used mainly internally, use
scippneutron.io.cif.save_cif()
instead.- Parameters:
f (
TextIOBase
) – File handle.- Return type: