22import scipp as sc
33
44
5- def dspacing_peak_positions_from_cif (cif , intensity_threshold = None ) -> sc .Variable :
5+ def dspacing_peaks_from_cif (cif , intensity_threshold = None , ** kwargs ) -> sc .DataArray :
66 """
7- Retrieves a list of the peak positions for the given material.
7+ Retrieves a data array representing the bragg peaks of the given material.
88
99 The material is represented by a cif file or a codid or similar.
1010 The number of peaks retrieved can be controlled by setting the intensity
@@ -27,20 +27,58 @@ def dspacing_peak_positions_from_cif(cif, intensity_threshold=None) -> sc.Variab
2727 times the multiplicity of the peak.
2828 The ``intensity_threshold`` must be convertible to unit ``barn``.
2929
30+ kwargs:
31+ Can be anything that :py:`NCrystal.NCMATComposer.from_cif` supports.
32+ For example: ``uiso_temperature`` or ``override_spacegroup``.
33+
3034 Returns
3135 ------------
32- Array containing the peak positions in `dspacing`, with unit ``angstrom``.
33- """
34- info = NC .NCMATComposer .from_cif (cif ).load ('comp=bragg' ).info
36+ Data array representing peak amplitudes and peak positions in ``dspacing``.
37+ The full NCrystal information object is added as a coordinate with the name ``info``.
38+ The input arguments are added as scalar coordinates.
39+
40+ Examples
41+ --------
42+ >>> from ess.diffraction.peaks import dspacing_peaks_from_cif
43+ >>> dspacing_peaks_from_cif(
44+ ... 'codid::9008460',
45+ ... uiso_temperature=400,
46+ ... override_spacegroup='F d -3 m:1',
47+ ... )
48+ <scipp.DataArray>
49+ Dimensions: Sizes[peaks:162, ]
50+ Coordinates:
51+ * cif string <no unit> () "codid::9008460"
52+ * dspacing float64 [Å] (peaks) [2.33803, 2.02479, ..., 0.243756, 0.243756]
53+ * info PyObject <no unit> () <NCrystal.core.Info object at ...>
54+ * override_spacegroup string <no unit> () "F d -3 m:1"
55+ * uiso_temperature int64 [dimensionless] () 400
56+ Data:
57+ float64 [barn] (peaks) [13.3631, 9.59562, ..., 0.000556426, 0.000556426]
58+
59+ """ # noqa: E501
60+ info = NC .NCMATComposer .from_cif (cif , ** kwargs ).load ('comp=bragg' ).info
3561 min_intensity = (
3662 intensity_threshold .to (unit = 'barn' ).value
3763 if intensity_threshold is not None
3864 else 0
3965 )
40- return sc . array (
41- dims = [ 'peaks' ],
42- values = [
43- hkl . d for hkl in info . hklObjects () if ( hkl . f2 * hkl . mult ) >= min_intensity
44- ],
66+ dims = [ 'peaks' ]
67+ peaks = [ hkl for hkl in info . hklObjects () if ( hkl . f2 * hkl . mult ) >= min_intensity ]
68+ dspacing = sc . array (
69+ dims = dims ,
70+ values = [ hkl . d for hkl in peaks ],
4571 unit = 'angstrom' ,
4672 )
73+ out = sc .DataArray (
74+ sc .array (dims = dims , values = [hkl .f2 * hkl .mult for hkl in peaks ], unit = 'barn' ),
75+ coords = {
76+ 'dspacing' : dspacing ,
77+ 'cif' : sc .scalar (cif ),
78+ 'info' : sc .scalar (info ),
79+ ** {name : sc .scalar (value ) for name , value in kwargs .items ()},
80+ },
81+ )
82+ if intensity_threshold is not None :
83+ out .coords ['intensity_threshold' ] = intensity_threshold
84+ return out
0 commit comments