Skip to content

Commit

Permalink
Make supermirror parameter of the pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
jokasimr committed Oct 24, 2023
1 parent 4f485b7 commit 50deaae
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 29 deletions.
3 changes: 2 additions & 1 deletion docs/examples/amor.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"source": [
"import scipp as sc\n",
"import sciline\n",
"from essreflectometry.amor import providers as amor\n",
"from essreflectometry.amor import providers as amor, default_parameters\n",
"from essreflectometry.reflectometry import providers as reflectometry\n",
"from essreflectometry.reflectometry.types import (\n",
" Sample, Reference, Sample, SampleRotation, Filename,\n",
Expand All @@ -18,6 +18,7 @@
"pipeline = sciline.Pipeline(\n",
" amor + reflectometry,\n",
" params={\n",
" **default_parameters,\n",
" QBins: sc.geomspace(dim='Q', start=0.008, stop=0.075, num=200, unit='1/angstrom'),\n",
" SampleRotation[Sample]: sc.scalar(0.7989, unit='deg'),\n",
" Filename[Sample]: \"sample.nxs\",\n",
Expand Down
14 changes: 12 additions & 2 deletions src/essreflectometry/amor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
# flake8: noqa: F401
from itertools import chain

from . import calibrations, conversions, load, normalize, resolution, tools
from .beamline import instrument_view_components
import scipp as sc

from . import beamline, calibrations, conversions, load, normalize, resolution, tools

# from .beamline import instrument_view_components
from .instrument_view import instrument_view
from .types import *

providers = list(
chain(
Expand All @@ -17,3 +21,9 @@
beamline.providers,
)
)

default_parameters = {
Supermirror[MValue]: sc.scalar(5, unit=sc.units.dimensionless),
Supermirror[CriticalEdge]: 0.022 * sc.Unit('1/angstrom'),
Supermirror[Alpha]: sc.scalar(0.25 / 0.088, unit=sc.units.angstrom),
}
39 changes: 13 additions & 26 deletions src/essreflectometry/amor/calibrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

# from ..reflectometry import orso
from ..reflectometry.types import CalibratedReference, Histogrammed, Reference
from .types import Alpha, CriticalEdge, MValue, Supermirror


def supermirror_calibration(
data_array: Histogrammed[Reference],
m_value: Supermirror[MValue],
critical_edge: Supermirror[CriticalEdge],
alpha: Supermirror[Alpha],
) -> Histogrammed[CalibratedReference]:
# TODO
m_value: sc.Variable = None
critical_edge: sc.Variable = None
alpha: sc.Variable = None
"""
Calibrate supermirror measurements
Expand All @@ -21,23 +21,16 @@ def supermirror_calibration(
data_array:
Data array to get q-bins/values from.
m_value:
m-value for the supermirror. Defaults to 5.
m-value for the supermirror.
critical_edge:
Supermirror critical edge. Defaults to 0.022 1/angstrom.
Supermirror critical edge.
alpha:
Supermirror alpha value. Defaults to 0.25 / 0.088 angstrom.
Supermirror alpha value.
Returns
-------
:
Calibrated supermirror measurement.
"""
if m_value is None:
m_value = sc.scalar(5, unit=sc.units.dimensionless)
if critical_edge is None:
critical_edge = 0.022 * sc.Unit('1/angstrom')
if alpha is None:
alpha = sc.scalar(0.25 / 0.088, unit=sc.units.angstrom)
calibration = calibration_factor(data_array, m_value, critical_edge, alpha)
data_array_cal = data_array * calibration
# TODO
Expand All @@ -52,9 +45,9 @@ def supermirror_calibration(

def calibration_factor(
data_array: sc.DataArray,
m_value: sc.Variable = None,
critical_edge: sc.Variable = None,
alpha: sc.Variable = None,
m_value: sc.Variable,
critical_edge: sc.Variable,
alpha: sc.Variable,
) -> sc.Variable:
"""
Return the calibration factor for the supermirror.
Expand All @@ -64,23 +57,17 @@ def calibration_factor(
data_array:
Data array to get q-bins/values from.
m_value:
m-value for the supermirror. Defaults to 5.
m-value for the supermirror.
critical_edge:
Supermirror critical edge. Defaults to 0.022 1/angstrom.
Supermirror critical edge.
alpha:
Supermirror alpha value. Defaults to 0.25 / 0.088 angstrom.
Supermirror alpha value.
Returns
-------
:
Calibration factor at the midpoint of each Q-bin.
"""
if m_value is None:
m_value = sc.scalar(5, unit=sc.units.dimensionless)
if critical_edge is None:
critical_edge = 0.022 * sc.Unit('1/angstrom')
if alpha is None:
alpha = sc.scalar(0.25 / 0.088, unit=sc.units.angstrom)
q = data_array.coords['Q']
if data_array.coords.is_edges('Q'):
q = sc.midpoints(q)
Expand Down
13 changes: 13 additions & 0 deletions src/essreflectometry/amor/types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from typing import NewType, TypeVar

import sciline
import scipp as sc

MValue = NewType('MValue', str)
CriticalEdge = NewType('CriticalEdge', str)
Alpha = NewType('Alpha', str)
SupermirrorParameter = TypeVar('SupermirrorParameter', MValue, CriticalEdge, Alpha)


class Supermirror(sciline.Scope[SupermirrorParameter, sc.Variable], sc.Variable):
"""Supermirror parameter scope"""

0 comments on commit 50deaae

Please sign in to comment.