-
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
base: main
Are you sure you want to change the base?
Conversation
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 esspolarization to 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 esspolarization to do the correction.
|
Requires scipp/esspolarization#91 |
|
The notebook might need some clean up - I'll take a look at that later today. |
SimonHeybrock
left a comment
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.
Some comments below.
|
|
||
| if "Q" in ref.coords: | ||
| ref.coords.pop("Q") | ||
| if "theta" in ref.coords: | ||
| ref.coords.pop("theta") | ||
|
|
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.
Unclear why this was added or what it may break. Can you add a comment?
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.
It was added so that if the input already has a Q or theta coordinate those are still recomputed in the coordinate transformation further down in the function.
For Amor theta is typically a binnned coordinate, so it's not present in ReducedReference (because that is a histogram).
But I noticed that if theta is computed without gravity correction then it will not be a binned coordinate, and it might be preserved on ReducedReference and so it will not be replaced by the coordinate transformation below, and that leads to incorrect results.
Removing them here is just defensive - we always want them to be replaced.
Q is always a binned coordinate, so it should not be a coordinate on ReducedReference, unless explicitly added.
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.
I've changed it now to only remove theta.
src/ess/estia/calibration.py
Outdated
| spin anti-parallel to instrument polarization.''' | ||
|
|
||
| @classmethod | ||
| def from_reference_measurements(cls, Io, Is): |
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.
type hints
src/ess/estia/calibration.py
Outdated
| Rspp_plus_Rsaa = ( | ||
| 4 | ||
| * (rho * alp * Ipp + Iaa + rho * Ipa + alp * Iap) | ||
| / ((1 + rho) * (1 + alp) * I0) | ||
| ) | ||
| Pp = sc.sqrt( | ||
| (Ipp + Iaa - Ipa - Iap) | ||
| * (alp * (Ipp - Iap) - Iaa + Ipa) | ||
| / ( | ||
| (rho * alp * Ipp + Iaa + rho * Ipa + alp * Iap) | ||
| * (rho * (Ipp - Ipa) - Iaa + Iap) | ||
| ) | ||
| ) | ||
| Ap = sc.sqrt( | ||
| (Ipp + Iaa - Ipa - Iap) | ||
| * (rho * (Ipp - Ipa) - Iaa + Iap) | ||
| / ( | ||
| (rho * alp * Ipp + Iaa + rho * Ipa + alp * Iap) | ||
| * (alp * (Ipp - Iap) - Iaa + Ipa) | ||
| ) | ||
| ) | ||
| Rs = sc.sqrt( | ||
| (alp * (Ipp - Iap) - Iaa + Ipa) | ||
| * (rho * (Ipp - Ipa) - Iaa + Iap) | ||
| / ( | ||
| (rho * alp * Ipp + Iaa + rho * Ipa + alp * Iap) | ||
| * (Ipp + Iaa - Ipa - Iap) | ||
| ) |
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.
Write this in a less repetitive manner, this is hard to read/review
src/ess/estia/normalization.py
Outdated
| if "Q" in ref.coords: | ||
| ref.coords.pop("Q") |
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.
Explain please.
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.
Same as above. For Estia there is no gravity correction, so theta is a coordinate on ReducedReference, but that coordinate should be replaced here.
| ) | ||
|
|
||
|
|
||
| def reduce_to_q(da, qbins): |
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.
type hints
| Io = intensity_from_parameters( | ||
| I0, Pp, Pa, Ap, Aa, sc.scalar(1), sc.scalar(0), sc.scalar(0), sc.scalar(1) | ||
| ) | ||
| Is = intensity_from_parameters( | ||
| I0, Pp, Pa, Ap, Aa, Rspp, sc.scalar(0), sc.scalar(0), Rsaa | ||
| ) |
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.
Unclear why passing the same values to both is a reasonable test. Same for passing zeros? Does this mean the test has gaps?
Also, keyword args and type hints would help.
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.
The test verifies that PolarizationCalibrationParameters.from_reference_measurements is the inverse of intensity_from_parameters.
It does that for 10 different seeds. It's a hypothesis test.
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.
Unclear why passing the same values to both is a reasonable test.
Maybe it's better if we talk in person since there seems to be some misunderstanding here.
Polarization correction for ESTIA
Only important differences from #108 are in
src/ess/estia/calibration.py: https://github.com/scipp/essreflectometry/pull/122/files#diff-df676f2a67f8251976ea2fcc161ea759d49deef6ef66c5adbf01d10665230077