-
Notifications
You must be signed in to change notification settings - Fork 1
Add 2nd order polynomial supermirror efficiency function #67
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
Conversation
src/ess/polarization/supermirror.py
Outdated
@dataclass | ||
class SecondOrderPolynomialEfficiency(SupermirrorEfficiencyFunction[PolarizingElement]): | ||
""" | ||
Efficiency of a supermirror as a second-order polynomial |
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.
(minor) second degree polynomial?
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.
Thanks, fixed!
src/ess/polarization/supermirror.py
Outdated
c: sc.Variable | ||
|
||
def __post_init__(self): | ||
if self.a.unit != sc.Unit('1/angstrom**2'): |
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.
Maybe it's better like this, not sure. But alternatively we could keep the parameters dimensionless and deal with the units in the __call__
method. The advantage is that we / the users don't have to care about the parameter units.
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.
Maybe it's better like this, not sure.
The core philosophy of Scipp is to avoid values without units wherever possible. It avoids really bad and hard to track-down bugs, as well as being self-documenting. Fewer bugs + documentation is what we chose over minor inconvenience.
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.
Oh but I didn't suggest not having units. I suggested to define the parameters as dimensionless. We would still do unit checks in the __call__
function.
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.
But sure, it's probably better like this.
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.
Oh but I didn't suggest not having units. I suggested to define the parameters as dimensionless.
Don't the values of the parameters depend on their units? That is, if the user has in mind "b is 123/nm" and sets b=123
we get nonsense?
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.
But you are also testing wrong powers, e.g. a, b, c all in 1/angstrom (first part of the test) - and that does not give an error?
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.
You mean code like this?
with pytest.raises(sc.UnitError, match=" to `dimensionless` is not valid"):
eff = pol.SecondDegreePolynomialEfficiency(
a=sc.scalar(1.0, unit='1/angstrom'),
b=sc.scalar(1.0, unit='1/angstrom'),
c=sc.scalar(1.0),
)
eff(wavelength=wav)
Note the with pytest.raises(sc.UnitError, match=" to
dimensionless is not valid"):
--- this checks that the code raises the expected exception.
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.
Ah ok, and the following code which in principle is correct from dimensions of a,b,c checks that it does not comply with some wavelength/time , i.e., for comparing a,b,c in their respective angstrom units with a "wavelength" in angstrom/s ?
with pytest.raises(sc.UnitError, match=" to `dimensionless` is not valid"):
eff = pol.SecondDegreePolynomialEfficiency(
a=sc.scalar(1.0, unit='1/angstrom**2'),
b=sc.scalar(1.0, unit='1/angstrom'),
c=sc.scalar(1.0),
)
eff(wavelength=wav / sc.scalar(1.0, unit='s'))
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.
Correct!
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.
Ah, perfect, understood! Will be tested on the zoom data this week :)
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.
Looks good to me. Left some minor comments.
Fixes #65
I slightly extended the Zoom notebook with a usage example.