Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/ess/beer/peakfinding.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from ..diffraction.peaks import dspacing_peak_positions_from_cif
from ..diffraction.peaks import dspacing_peaks_from_cif
from .types import CIFIdentifierForPeakPositions, CIFPeaksMinIntensity, DHKLList


def dhkl_peaks_from_cif(
cif: CIFIdentifierForPeakPositions, intensity_threshold: CIFPeaksMinIntensity
) -> DHKLList:
'''Gets the list of expected peak positions from a CIF file/identifier.'''
return dspacing_peak_positions_from_cif(cif, intensity_threshold)
return dspacing_peaks_from_cif(cif, intensity_threshold).coords['dspacing']
58 changes: 48 additions & 10 deletions src/ess/diffraction/peaks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import scipp as sc


def dspacing_peak_positions_from_cif(cif, intensity_threshold=None) -> sc.Variable:
def dspacing_peaks_from_cif(cif, intensity_threshold=None, **kwargs) -> sc.DataArray:
"""
Retrieves a list of the peak positions for the given material.
Retrieves a data array representing the bragg peaks of the given material.

The material is represented by a cif file or a codid or similar.
The number of peaks retrieved can be controlled by setting the intensity
Expand All @@ -27,20 +27,58 @@ def dspacing_peak_positions_from_cif(cif, intensity_threshold=None) -> sc.Variab
times the multiplicity of the peak.
The ``intensity_threshold`` must be convertible to unit ``barn``.

kwargs:
Can be anything that :py:`NCrystal.NCMATComposer.from_cif` supports.
For example: ``uiso_temperature`` or ``override_spacegroup``.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the return description to explain what the values and coords are.

Returns
------------
Array containing the peak positions in `dspacing`, with unit ``angstrom``.
"""
info = NC.NCMATComposer.from_cif(cif).load('comp=bragg').info
Data array representing peak amplitudes and peak positions in ``dspacing``.
The full NCrystal information object is added as a coordinate with the name ``info``.
The input arguments are added as scalar coordinates.

Examples
--------
>>> from ess.diffraction.peaks import dspacing_peaks_from_cif
>>> dspacing_peaks_from_cif(
... 'codid::9008460',
... uiso_temperature=400,
... override_spacegroup='F d -3 m:1',
... )
<scipp.DataArray>
Dimensions: Sizes[peaks:162, ]
Coordinates:
* cif string <no unit> () "codid::9008460"
* dspacing float64 [Å] (peaks) [2.33803, 2.02479, ..., 0.243756, 0.243756]
* info PyObject <no unit> () <NCrystal.core.Info object at ...>
* override_spacegroup string <no unit> () "F d -3 m:1"
* uiso_temperature int64 [dimensionless] () 400
Data:
float64 [barn] (peaks) [13.3631, 9.59562, ..., 0.000556426, 0.000556426]

""" # noqa: E501
info = NC.NCMATComposer.from_cif(cif, **kwargs).load('comp=bragg').info
min_intensity = (
intensity_threshold.to(unit='barn').value
if intensity_threshold is not None
else 0
)
return sc.array(
dims=['peaks'],
values=[
hkl.d for hkl in info.hklObjects() if (hkl.f2 * hkl.mult) >= min_intensity
],
dims = ['peaks']
peaks = [hkl for hkl in info.hklObjects() if (hkl.f2 * hkl.mult) >= min_intensity]
dspacing = sc.array(
dims=dims,
values=[hkl.d for hkl in peaks],
unit='angstrom',
)
out = sc.DataArray(
sc.array(dims=dims, values=[hkl.f2 * hkl.mult for hkl in peaks], unit='barn'),
coords={
'dspacing': dspacing,
'cif': sc.scalar(cif),
'info': sc.scalar(info),
**{name: sc.scalar(value) for name, value in kwargs.items()},
},
)
if intensity_threshold is not None:
out.coords['intensity_threshold'] = intensity_threshold
return out
18 changes: 13 additions & 5 deletions tests/diffraction/test_peaks.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
import scipp as sc

from ess.diffraction.peaks import dspacing_peak_positions_from_cif
from ess.diffraction.peaks import dspacing_peaks_from_cif


def test_retreived_peak_list_has_expected_units():
d = dspacing_peak_positions_from_cif(
d = dspacing_peaks_from_cif(
'codid::9011998',
sc.scalar(50, unit='barn'),
)
assert d.unit == 'angstrom'
assert d.coords['dspacing'].unit == 'angstrom'
assert d.unit == 'barn'


def test_intensity_threshold_is_taken_into_account():
d = dspacing_peak_positions_from_cif(
d = dspacing_peaks_from_cif(
'codid::9011998',
sc.scalar(50, unit='barn'),
)
assert len(d) > 0

d = dspacing_peak_positions_from_cif(
d = dspacing_peaks_from_cif(
'codid::9011998',
sc.scalar(50, unit='Mbarn'),
)
assert len(d) == 0


def test_retreived_peak_list_with_temperature_kwarg():
d = dspacing_peaks_from_cif(
'codid::9011998', sc.scalar(50, unit='barn'), uiso_temperature=300
)
assert d.coords['uiso_temperature'] == 300
Loading