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
TabulatedPhase
: better eval method
#226
Conversation
I found no need to update the regression tests with these changes ; they still pass. |
# compute the smallest regular grid that does not loose information | ||
# in the sense of Shannon theorem | ||
dmu = np.abs(self.data.mu.diff(dim="mu")).values.min() | ||
nmu = 2 * int(np.ceil(2.0 / dmu)) |
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.
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.
Any thoughts about that? @leroyvn
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'm not a signal processing expert so I don't have strong arguments to oppose: if you guys have proper arguments in favour of tuning down the number of grid points, go for it. Just keep that in mind when analysing results ;)
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.
Well Lucio made the point that the data is already sampled at a maximum frequency of dmu, so we don't really gain anything from resampling it at 2*dmu.
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.
For the record, my reasoning is that the smallest mu step is likely to be found at the extreme right of the [-1, 1] mu
interval since this is where the forward scattering peak is located. Therefore, if we buid the regular mu
grid using:
dmu_min = np.abs(self.data.mu.diff(dim="mu")).values.min()
nmu = int(np.ceil(2.0 / dmu_min)) + 1
mu = np.linspace(-1, 1, nmu)
the two far-right mu points in [-1, 1] will exactly match the mu
points in the input data. From these points on, the data to the left will be interpolated, therefore we incur a loss accuracy. Arguably, the loss of accuracy is minimised where it is important to be accuracy, namely close to mu=1.0
.
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.
@schunkes I am not convinced that:
dmu is the minimal mu step
implies that:
1 / dmu is the maximal frequency in the phase function signal
If you take the Fourrier transform of a realistic particle phase function in the mu-space, you will find an infinite number of harmonics in my opinion
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.
After more discussion with the whiteboard, we found that assuming the following:
- the input data is propertly discretised, namely the smallest mu-step is found where the phase function has the sharpest variations
- the sharpest feature occurs either at
mu=-1
or atmu=1.0
, or if it is located somewhere in the middle of the interval, the input data is well enough sampled in themu
space
the smallest delta mu regularisation method is the best.
As illustrated by the figure below, in the presumably most common case where the phase function has sharpest variations around mu=1.0, interpolating on the regular grid prescribed by the Shannon's theorem or on the regular grid using the smallest mu-step lead to the same result:
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.
As a rule of thumb, the smallest the mu step in the input data, the lowest the interpolation errors.
We note that this regular grid tabulated phase function approach is not best suited for phase function with very sharp features, generally speaking, because of the overhead in memory and in interpolation time.
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.
However, this approach is the only available to us at the moment...
I'll add a couple of tests |
5b3d62f
to
4264958
Compare
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.
Hi @nollety, this is a nice PR. I made a couple of comments which I'd like to see addressed.
Thanks for the feedback! @leroyvn |
Alright, we are ready for another review round I think :) |
Thanks @nollety, we're good to go: I'll merge this. |
Description
Resolves eradiate/eradiate-issues#165
I improved how
TabulatedPhase.eval
maps the input phase function data to a regular grid of scattering angle cosine (mu
) when the input data does not already map to a regularmu
grid.Changes
I removed the hidden
_n_mu
class attribute and updatedeval_mono
in the following way:data
maps to amu
regular grid, interpolate in wavelength and return the valuesmu
grid based on the smallestmu
step found in the input phase function data, and interpolate in wavelength (usingxarray.DataArray.interp
) and on that regularmu
grid (usingnumpy.interp
for performance) and return the values. For further details, refer to a discussion about the choice of this regularmu
grid in the comments down below.I added 2 unit tests for this new implementation (hence the data submodule update).
If the user wants to control the number of points used along the
mu
axis to discretize a tabulated phase function, they would simply have to provide phase function data mapping directly to a regularmu
grid, since in that case the inputDataArray
is left unchanged.I added a converter for the
data
attribute, that ensures themu
coordinate is monotonically increasing.I added a validator for the
data
attribute to check that themu
coordinate in the input data set goes from-1.0
to1.0
.I added
TabulatedPhaseFunction
to the API Reference.Checklist
main
branch