Skip to content

Commit

Permalink
Merge pull request #28 from scipp/fix-wavelength-bounds
Browse files Browse the repository at this point in the history
fix: re-add the optional wavelength edges
  • Loading branch information
jokasimr authored Feb 7, 2024
2 parents 2bd788f + 748c314 commit b764f28
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
5 changes: 3 additions & 2 deletions docs/examples/amor.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
" Filename[Sample]: \"sample.nxs\",\n",
" SampleRotation[Reference]: sc.scalar(0.8389, unit='deg'),\n",
" Filename[Reference]: \"reference.nxs\",\n",
" WavelengthEdges: sc.array(dims=['wavelength'], values=[2.4, 16.0], unit='angstrom'),\n",
"}"
]
},
Expand Down Expand Up @@ -121,7 +122,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "essreflectometry",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -139,5 +140,5 @@
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
9 changes: 8 additions & 1 deletion src/essreflectometry/amor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@

from .. import providers as reflectometry_providers
from .. import supermirror
from ..types import BeamSize, DetectorSpatialResolution, Gravity, Run, SampleSize
from ..types import (
BeamSize,
DetectorSpatialResolution,
Gravity,
Run,
SampleSize,
WavelengthEdges,
)
from . import beamline, conversions, load, resolution
from .beamline import instrument_view_components
from .instrument_view import instrument_view
Expand Down
8 changes: 8 additions & 0 deletions src/essreflectometry/conversions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2023 Scipp contributors (https://github.com/scipp)
from typing import Optional

import scipp as sc
from scipp.constants import h, m_n, pi
from scippneutron._utils import elem_dtype, elem_unit
Expand All @@ -16,6 +18,7 @@
SpecularReflectionCoordTransformGraph,
ThetaData,
WavelengthData,
WavelengthEdges,
)


Expand Down Expand Up @@ -118,6 +121,7 @@ def specular_reflection() -> SpecularReflectionCoordTransformGraph:
def tof_to_wavelength(
data_array: RawData[Run],
graph: SpecularReflectionCoordTransformGraph,
wavelength_edges: Optional[WavelengthEdges],
) -> WavelengthData[Run]:
"""
Use :code:`transform_coords` to convert from ToF to wavelength, cutoff high and
Expand All @@ -129,13 +133,17 @@ def tof_to_wavelength(
Data array to convert.
graph:
Graph for :code:`transform_coords`.
wavelength_edges:
Bounds for wavelength values, exclude data outside of bounds.
Returns
-------
:
New data array with wavelength dimension.
"""
data_array_wav = data_array.transform_coords(["wavelength"], graph=graph)
if wavelength_edges is not None:
data_array_wav = data_array_wav.bin({wavelength_edges.dim: wavelength_edges})
# TODO
# try:
# from orsopy import fileio
Expand Down
3 changes: 3 additions & 0 deletions src/essreflectometry/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ class IofQ(sciline.Scope[Run, sc.DataArray], sc.DataArray):
QBins = NewType('QBins', sc.Variable)
'''Bins for the momentum transfer histogram.'''

WavelengthEdges = NewType('WavelengthEdges', sc.Variable)
'''Include only events within the specified edges.'''


class Filename(sciline.Scope[Run, str], str):
"""Filename of the event data nexus file."""
Expand Down

0 comments on commit b764f28

Please sign in to comment.