Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
8768696
docs: polarization calibration prototype
jokasimr Feb 25, 2025
f78be6c
docs: include figures
jokasimr Feb 25, 2025
0c686af
docs: add header
jokasimr Feb 25, 2025
a25ef55
changes
jokasimr Feb 27, 2025
d22df0f
feat: implement calibration and reduction
jokasimr Feb 27, 2025
e3bb2c1
refactor: move test code to tests, add docstrings
jokasimr Mar 18, 2025
2e50d3b
feat: draft sciline domain types
jokasimr Mar 18, 2025
7b70b11
test: solve recovers expected parameters
jokasimr Mar 18, 2025
ab78efb
test: stacking logic in linsolve
jokasimr Mar 18, 2025
fc20fd0
fix: remove unused
jokasimr Mar 19, 2025
893abdb
fix: add position already in reduction to lz
jokasimr Mar 19, 2025
0fb609a
fix: calibration on lz grid, compute Q on lz grid for sample + add ma…
jokasimr Mar 19, 2025
727bf44
docs: add esspolarization + tox -e deps
jokasimr Mar 20, 2025
ec48ec6
docs: add example reducing polarized mcstas data
jokasimr Mar 31, 2025
e9acb7c
fix: move factor from normalization to polarization matrix
jokasimr Apr 1, 2025
6e11c7d
fix: use pandas to load csv
jokasimr Apr 1, 2025
381227e
fix: tweak center of incident angle for mcstas data
jokasimr Apr 1, 2025
0329a22
fix: old value was better
jokasimr Apr 2, 2025
179aaef
fix: tests
jokasimr Apr 2, 2025
261ac50
feat: make normalization able to handle different kinds of references
jokasimr Apr 2, 2025
cca0ce5
fix: no need to have two reduce to Q functions
jokasimr Apr 4, 2025
4930b00
docs: stap template
jokasimr Apr 4, 2025
725ee1d
fix: remove unnecessary
jokasimr Apr 7, 2025
91fb8cd
deps: add ipympl to docs
jokasimr Apr 9, 2025
8d9ba1d
Merge branch 'polcal' of github.com:scipp/essreflectometry into polcal
jokasimr Apr 9, 2025
6089d41
docs: remove polarization notebook
jokasimr Apr 9, 2025
f8083b2
docs: remove polarization notebook from docs
jokasimr Apr 9, 2025
d7d31c0
docs: remove polarization correction experiment notebook
jokasimr Apr 9, 2025
b187fbd
Merge branch 'main' into polcal
jokasimr Apr 9, 2025
6e1a83f
docs: remove figures
jokasimr Apr 9, 2025
1c92913
Merge branch 'polcal' of github.com:scipp/essreflectometry into polcal
jokasimr Apr 9, 2025
c5610b7
fix: use np.kron to construct calibration matrix
jokasimr Apr 25, 2025
0913455
deps: use latest sciline for new Scope
jokasimr Apr 25, 2025
4099486
fix: use dims arg to do concatenation
jokasimr Apr 28, 2025
f6764bb
refactor: implement container for polarization calibration parameters
jokasimr Apr 28, 2025
be37702
fix: better doc comment + fix typo
jokasimr Apr 28, 2025
76bcf3c
Merge remote-tracking branch 'origin/main' into polcal
jokasimr Apr 28, 2025
7d1753c
Merge branch 'main' into polcal
jokasimr Apr 28, 2025
ca28f99
fix: reimplement kron, numpy and scipp doesn't play nicely in this case
jokasimr Apr 29, 2025
e0db8f0
fix: don't assume only dimension of 1d reference is Q
jokasimr Apr 29, 2025
e72eb85
docs: add notebook and data for test case with simulated spin flip sa…
jokasimr Apr 29, 2025
dc36161
Update src/ess/estia/calibration.py
jokasimr Apr 30, 2025
3f7182b
Apply automatic formatting
pre-commit-ci-lite[bot] Apr 30, 2025
9aaf79d
docs: add new example notebook to index
jokasimr Apr 30, 2025
e801737
Merge branch 'polcal' of github.com:scipp/essreflectometry into polcal
jokasimr Apr 30, 2025
889ecc5
docs: fix hader
jokasimr Apr 30, 2025
8d071c7
docs: fix sample names
jokasimr Apr 30, 2025
8843f96
Merge remote-tracking branch 'origin/main' into polcal
jokasimr May 27, 2025
b6e0484
Merge remote-tracking branch 'origin/main' into polcal
jokasimr May 27, 2025
8be1834
ci: update pooch data
jokasimr May 27, 2025
9bafe51
fix: add Q approximation to reduced reference
jokasimr May 27, 2025
89c3293
docs: update example notebook
jokasimr Jun 2, 2025
280c6a9
refactor: remove old polarization implementation
jokasimr Jun 2, 2025
7e18c82
refactor: remove unused
jokasimr Jun 2, 2025
61cb147
deps
jokasimr Aug 25, 2025
3abdc52
Merge remote-tracking branch 'origin/main' into polcal
jokasimr Aug 25, 2025
940bdd2
deps: add esspolarization
jokasimr Aug 25, 2025
c82d472
fix
jokasimr Aug 25, 2025
db753ef
fix: remove old Q and theta coords before setting coords based on sam…
jokasimr Aug 26, 2025
32d1845
Merge branch 'polcal' of github.com:scipp/essreflectometry into polcal
jokasimr Aug 26, 2025
8e77dfd
Merge branch 'main' into polcal
jokasimr Aug 26, 2025
bad0209
Merge branch 'main' into polcal
jokasimr Aug 26, 2025
baf5b6e
Merge branch 'main' into polcal
jokasimr Aug 28, 2025
395006b
Merge branch 'main' into polcal
jokasimr Nov 12, 2025
3383824
Rewrite calibration expression in less repetetive way
jokasimr Nov 12, 2025
8495b20
typing
jokasimr Nov 12, 2025
8df14fc
typing
jokasimr Nov 12, 2025
ebb6f85
fix
jokasimr Nov 12, 2025
65c4d91
fix: remove Q from ReducedReference
jokasimr Nov 12, 2025
efb020b
typing
jokasimr Nov 12, 2025
ff17f06
fix: use threadpool to minimize risk of race condition
jokasimr Nov 12, 2025
0ad5433
fix
jokasimr Nov 12, 2025
8222e92
fix
jokasimr Nov 12, 2025
6e611cb
docs: rename domain types
jokasimr Nov 12, 2025
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
1 change: 1 addition & 0 deletions docs/user-guide/estia/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ hidden:

estia-mcstas-reduction
estia-advanced-mcstas-reduction
simulated-spin-flip-sample
```
419 changes: 419 additions & 0 deletions docs/user-guide/estia/simulated-spin-flip-sample.ipynb

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ dependencies = [
"scippneutron>=24.10.0",
"scippnexus>=24.9.1",
"essreduce>=25.11.0",
"esspolarization>=25.7.0",
"essreduce>=25.4.0",
"pandas>=2.1.2",
]

Expand Down
2 changes: 2 additions & 0 deletions requirements/base.in
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ scipp>=24.09.1
scippneutron>=24.10.0
scippnexus>=24.9.1
essreduce>=25.11.0
esspolarization>=25.7.0
essreduce>=25.4.0
pandas>=2.1.2
30 changes: 20 additions & 10 deletions requirements/base.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SHA1:ac5d5ed5d7ed7425eb3b92f0cfa128fe6db146b4
# SHA1:7d24e61b002964358637133b46eac8bab3600eae
#
# This file was generated by pip-compile-multi.
# To update, run:
Expand All @@ -17,20 +17,28 @@ cyclebane==24.10.0
# via sciline
cycler==0.12.1
# via matplotlib
dask==2025.10.0
# via -r base.in
dask==2025.11.0
# via
# -r base.in
# esspolarization
dnspython==2.8.0
# via email-validator
email-validator==2.3.0
# via scippneutron
essreduce==25.11.0
esspolarization==25.10.0
# via -r base.in
essreduce==25.11.1
# via
# -r base.in
# esspolarization
fonttools==4.60.1
# via matplotlib
fsspec==2025.10.0
# via dask
graphviz==0.21
# via -r base.in
# via
# -r base.in
# esspolarization
h5py==3.15.1
# via
# scippneutron
Expand Down Expand Up @@ -81,9 +89,9 @@ plopp==25.10.0
# via
# -r base.in
# scippneutron
pydantic==2.12.3
pydantic==2.12.4
# via scippneutron
pydantic-core==2.41.4
pydantic-core==2.41.5
# via pydantic
pyparsing==3.2.5
# via matplotlib
Expand All @@ -93,7 +101,6 @@ python-dateutil==2.9.0.post0
# matplotlib
# pandas
# scippneutron
# scippnexus
pytz==2025.2
# via pandas
pyyaml==6.0.3
Expand All @@ -103,24 +110,27 @@ pyyaml==6.0.3
sciline==25.11.1
# via
# -r base.in
# esspolarization
# essreduce
scipp==25.8.0
scipp==25.11.0
# via
# -r base.in
# esspolarization
# essreduce
# scippneutron
# scippnexus
scippneutron==25.7.0
# via
# -r base.in
# essreduce
scippnexus==25.6.0
scippnexus==25.11.0
# via
# -r base.in
# essreduce
# scippneutron
scipy==1.16.3
# via
# esspolarization
# scippneutron
# scippnexus
six==1.17.0
Expand Down
4 changes: 2 additions & 2 deletions requirements/basetest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#
# requirements upgrade
#
certifi==2025.10.5
certifi==2025.11.12
# via requests
charset-normalizer==3.4.4
# via requests
Expand All @@ -25,7 +25,7 @@ pooch==1.8.2
# via -r basetest.in
pygments==2.19.2
# via pytest
pytest==8.4.2
pytest==9.0.0
# via -r basetest.in
requests==2.32.5
# via pooch
Expand Down
2 changes: 1 addition & 1 deletion requirements/ci.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#
cachetools==6.2.1
# via tox
certifi==2025.10.5
certifi==2025.11.12
# via requests
chardet==5.2.0
# via tox
Expand Down
2 changes: 1 addition & 1 deletion requirements/dev.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
-r test.in
-r wheels.in
copier
jupyterlab
jupyterlab>=4.4.3
pip-compile-multi
pre-commit
2 changes: 1 addition & 1 deletion requirements/dev.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SHA1:efd19a3a98c69fc3d6d6233ed855de7e4a208f74
# SHA1:d4ffe53db30990b73c1af821d46399aafea47d77
#
# This file was generated by pip-compile-multi.
# To update, run:
Expand Down
6 changes: 3 additions & 3 deletions requirements/docs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ bleach[css]==6.3.0
# via nbconvert
bqplot==0.12.45
# via ipydatagrid
certifi==2025.10.5
certifi==2025.11.12
# via requests
charset-normalizer==3.4.4
# via requests
Expand Down Expand Up @@ -66,7 +66,7 @@ ipykernel==7.1.0
# via -r docs.in
ipympl==0.9.8
# via -r docs.in
ipython==9.6.0
ipython==9.7.0
# via
# -r docs.in
# ipykernel
Expand Down Expand Up @@ -173,7 +173,7 @@ pybtex==0.25.1
# sphinxcontrib-bibtex
pybtex-docutils==1.0.3
# via sphinxcontrib-bibtex
pydantic-settings==2.11.0
pydantic-settings==2.12.0
# via autodoc-pydantic
pydata-sphinx-theme==0.16.1
# via -r docs.in
Expand Down
2 changes: 2 additions & 0 deletions requirements/nightly.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ python-dateutil
graphviz
orsopy>=1.2
essreduce>=25.11.0
esspolarization>=25.7.0
essreduce>=25.4.0
pandas>=2.1.2
pytest>=7.0
pooch>=1.5
Expand Down
31 changes: 21 additions & 10 deletions requirements/nightly.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SHA1:1e183c3e9d303722f2579385b8d7861f9200b810
# SHA1:ccf027ae6c53853baac5291a4a5faf53045d0292
#
# This file was generated by pip-compile-multi.
# To update, run:
Expand All @@ -10,7 +10,7 @@

annotated-types==0.7.0
# via pydantic
certifi==2025.10.5
certifi==2025.11.12
# via requests
charset-normalizer==3.4.4
# via requests
Expand All @@ -24,20 +24,28 @@ cyclebane==24.10.0
# via sciline
cycler==0.12.1
# via matplotlib
dask==2025.10.0
# via -r nightly.in
dask==2025.11.0
# via
# -r nightly.in
# esspolarization
dnspython==2.8.0
# via email-validator
email-validator==2.3.0
# via scippneutron
essreduce==25.11.0
esspolarization==25.10.0
# via -r nightly.in
essreduce==25.11.1
# via
# -r nightly.in
# esspolarization
fonttools==4.60.1
# via matplotlib
fsspec==2025.10.0
# via dask
graphviz==0.21
# via -r nightly.in
# via
# -r nightly.in
# esspolarization
h5py==3.15.1
# via
# scippneutron
Expand All @@ -64,7 +72,7 @@ matplotlib==3.10.7
# plopp
mpltoolbox==25.10.0
# via scippneutron
networkx==3.5
networkx==3.6rc0
# via cyclebane
numpy==2.3.4
# via
Expand Down Expand Up @@ -100,15 +108,15 @@ pluggy==1.6.0
# via pytest
pooch==1.8.2
# via -r nightly.in
pydantic==2.12.3
pydantic==2.12.4
# via scippneutron
pydantic-core==2.41.4
pydantic-core==2.41.5
# via pydantic
pygments==2.19.2
# via pytest
pyparsing==3.3.0a1
# via matplotlib
pytest==8.4.2
pytest==9.0.0
# via -r nightly.in
python-dateutil==2.9.0.post0
# via
Expand All @@ -127,10 +135,12 @@ requests==2.32.5
sciline @ git+https://github.com/scipp/sciline@main
# via
# -r nightly.in
# esspolarization
# essreduce
scipp==100.0.0.dev0
# via
# -r nightly.in
# esspolarization
# essreduce
# scippneutron
# scippnexus
Expand All @@ -145,6 +155,7 @@ scippnexus @ git+https://github.com/scipp/scippnexus@main
# scippneutron
scipy==1.16.3
# via
# esspolarization
# scippneutron
# scippnexus
six==1.17.0
Expand Down
2 changes: 1 addition & 1 deletion requirements/static.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ nodeenv==1.9.1
# via pre-commit
platformdirs==4.5.0
# via virtualenv
pre-commit==4.3.0
pre-commit==4.4.0
# via -r static.in
pyyaml==6.0.3
# via pre-commit
Expand Down
4 changes: 4 additions & 0 deletions src/ess/amor/normalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ def evaluate_reference_at_sample_coords(
ref.coords["sample_size"] = sample.coords["sample_size"]
ref.coords["detector_spatial_resolution"] = detector_spatial_resolution
ref.coords["wavelength"] = sc.midpoints(ref.coords["wavelength"])

if "theta" in ref.coords:
ref.coords.pop("theta")

ref = ref.transform_coords(
(
"Q",
Expand Down
80 changes: 80 additions & 0 deletions src/ess/estia/calibration.py
Copy link
Member

Choose a reason for hiding this comment

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

Can we use esspolarization to perform the correction?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right now we can't because of scipp/esspolarization#84

When that is fixed we should be able to use esspolarization to do the correction.

Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
from dataclasses import dataclass
from typing import Self

import scipp as sc


@dataclass
class PolarizationCalibrationParameters:
I0: sc.DataArray
'''Reference intensity.'''
Pp: sc.DataArray
'''Effective polarization of polarizer when polarizer flipper is off.'''
Pa: sc.DataArray
'''Effective polarization of polarizer when polarizer flipper is on.'''
Ap: sc.DataArray
'''Effective polarization of analyzer when analyzer flipper if on.'''
Aa: sc.DataArray
'''Effective polarization of analyzer when analyzer flipper is off.'''
Rspp: sc.DataArray
'''Magnetic supermirror reflectivity for neutrons with
spin parallel to instrument polarization.'''
Rsaa: sc.DataArray
'''Magnetic supermirror reflectivity for neutrons with
spin anti-parallel to instrument polarization.'''

@classmethod
def from_reference_measurements(
cls: type[Self],
Io: tuple[sc.DataArray, sc.DataArray, sc.DataArray, sc.DataArray],
Is: tuple[sc.DataArray, sc.DataArray, sc.DataArray, sc.DataArray],
) -> Self:
"""
Solves for the calibration parameters given the reference
measurements.

See https://doi.org/10.1016/S0921-4526(00)00823-1.

Parameters
------------
Io:
Intensity from measurements with perfect
non-magnetic supermirror.
Is:
Intensity from measurements with
magnetic supermirror.

Returns
----------
:
Polarization calibration parameters
"""
Iopp, Iopa, Ioap, Ioaa = Io
Ipp, Ipa, Iap, Iaa = Is

I0 = 2 * (Iopp * Ioaa - Iopa * Ioap) / (Iopp + Ioaa - Iopa - Ioap)
rho = (Ioaa - Ioap) / (Iopp - Iopa)
alp = (Ioaa - Iopa) / (Iopp - Ioap)

num_base = rho * alp * Ipp + Iaa + rho * Ipa + alp * Iap
den_base = Ipp + Iaa - Ipa - Iap
term_rho = rho * (Ipp - Ipa) - Iaa + Iap
term_alp = alp * (Ipp - Iap) - Iaa + Ipa

Rspp_plus_Rsaa = 4 * num_base / ((1 + rho) * (1 + alp) * I0)

Pp = sc.sqrt(den_base * term_alp / (num_base * term_rho))
Ap = sc.sqrt(den_base * term_rho / (num_base * term_alp))
Rs = sc.sqrt(term_alp * term_rho / (num_base * den_base))

Pa = -rho * Pp
Aa = -alp * Ap

Rspp_minus_Rsaa = Rs * Rspp_plus_Rsaa
Rspp = (Rspp_plus_Rsaa + Rspp_minus_Rsaa) / 2
Rsaa = Rspp_plus_Rsaa - Rspp

return cls(I0, Pp, Pa, Ap, Aa, Rspp, Rsaa)


providers = ()
Loading
Loading