-
Notifications
You must be signed in to change notification settings - Fork 3
Polarization correction #122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jokasimr
wants to merge
74
commits into
main
Choose a base branch
from
polcal
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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 f78be6c
docs: include figures
jokasimr 0c686af
docs: add header
jokasimr a25ef55
changes
jokasimr d22df0f
feat: implement calibration and reduction
jokasimr e3bb2c1
refactor: move test code to tests, add docstrings
jokasimr 2e50d3b
feat: draft sciline domain types
jokasimr 7b70b11
test: solve recovers expected parameters
jokasimr ab78efb
test: stacking logic in linsolve
jokasimr fc20fd0
fix: remove unused
jokasimr 893abdb
fix: add position already in reduction to lz
jokasimr 0fb609a
fix: calibration on lz grid, compute Q on lz grid for sample + add ma…
jokasimr 727bf44
docs: add esspolarization + tox -e deps
jokasimr ec48ec6
docs: add example reducing polarized mcstas data
jokasimr e9acb7c
fix: move factor from normalization to polarization matrix
jokasimr 6e11c7d
fix: use pandas to load csv
jokasimr 381227e
fix: tweak center of incident angle for mcstas data
jokasimr 0329a22
fix: old value was better
jokasimr 179aaef
fix: tests
jokasimr 261ac50
feat: make normalization able to handle different kinds of references
jokasimr cca0ce5
fix: no need to have two reduce to Q functions
jokasimr 4930b00
docs: stap template
jokasimr 725ee1d
fix: remove unnecessary
jokasimr 91fb8cd
deps: add ipympl to docs
jokasimr 8d9ba1d
Merge branch 'polcal' of github.com:scipp/essreflectometry into polcal
jokasimr 6089d41
docs: remove polarization notebook
jokasimr f8083b2
docs: remove polarization notebook from docs
jokasimr d7d31c0
docs: remove polarization correction experiment notebook
jokasimr b187fbd
Merge branch 'main' into polcal
jokasimr 6e1a83f
docs: remove figures
jokasimr 1c92913
Merge branch 'polcal' of github.com:scipp/essreflectometry into polcal
jokasimr c5610b7
fix: use np.kron to construct calibration matrix
jokasimr 0913455
deps: use latest sciline for new Scope
jokasimr 4099486
fix: use dims arg to do concatenation
jokasimr f6764bb
refactor: implement container for polarization calibration parameters
jokasimr be37702
fix: better doc comment + fix typo
jokasimr 76bcf3c
Merge remote-tracking branch 'origin/main' into polcal
jokasimr 7d1753c
Merge branch 'main' into polcal
jokasimr ca28f99
fix: reimplement kron, numpy and scipp doesn't play nicely in this case
jokasimr e0db8f0
fix: don't assume only dimension of 1d reference is Q
jokasimr e72eb85
docs: add notebook and data for test case with simulated spin flip sa…
jokasimr dc36161
Update src/ess/estia/calibration.py
jokasimr 3f7182b
Apply automatic formatting
pre-commit-ci-lite[bot] 9aaf79d
docs: add new example notebook to index
jokasimr e801737
Merge branch 'polcal' of github.com:scipp/essreflectometry into polcal
jokasimr 889ecc5
docs: fix hader
jokasimr 8d071c7
docs: fix sample names
jokasimr 8843f96
Merge remote-tracking branch 'origin/main' into polcal
jokasimr b6e0484
Merge remote-tracking branch 'origin/main' into polcal
jokasimr 8be1834
ci: update pooch data
jokasimr 9bafe51
fix: add Q approximation to reduced reference
jokasimr 89c3293
docs: update example notebook
jokasimr 280c6a9
refactor: remove old polarization implementation
jokasimr 7e18c82
refactor: remove unused
jokasimr 61cb147
deps
jokasimr 3abdc52
Merge remote-tracking branch 'origin/main' into polcal
jokasimr 940bdd2
deps: add esspolarization
jokasimr c82d472
fix
jokasimr db753ef
fix: remove old Q and theta coords before setting coords based on sam…
jokasimr 32d1845
Merge branch 'polcal' of github.com:scipp/essreflectometry into polcal
jokasimr 8e77dfd
Merge branch 'main' into polcal
jokasimr bad0209
Merge branch 'main' into polcal
jokasimr baf5b6e
Merge branch 'main' into polcal
jokasimr 395006b
Merge branch 'main' into polcal
jokasimr 3383824
Rewrite calibration expression in less repetetive way
jokasimr 8495b20
typing
jokasimr 8df14fc
typing
jokasimr ebb6f85
fix
jokasimr 65c4d91
fix: remove Q from ReducedReference
jokasimr efb020b
typing
jokasimr ff17f06
fix: use threadpool to minimize risk of race condition
jokasimr 0ad5433
fix
jokasimr 8222e92
fix
jokasimr 6e611cb
docs: rename domain types
jokasimr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,4 +41,5 @@ hidden: | |
|
|
||
| estia-mcstas-reduction | ||
| estia-advanced-mcstas-reduction | ||
| simulated-spin-flip-sample | ||
| ``` | ||
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,6 @@ | |
| -r test.in | ||
| -r wheels.in | ||
| copier | ||
| jupyterlab | ||
| jupyterlab>=4.4.3 | ||
| pip-compile-multi | ||
| pre-commit | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 = () |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use
esspolarizationto perform the correction?There was a problem hiding this comment.
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
esspolarizationto do the correction.