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.
The goal of this PR is to test the SALT2 model against the implementation in snfit and to make modifications to the sncosmo implementation where necessary.
Interpolation
Although the snfit codebase has some code for basis splines, it doesn't appear to actually be used in the SALT2 model. The components of the model are actually backed by
Grid2DFunction
objects. This class performs bicubic convolution, except when the input value is within one knot of any boundary, in which case it performs bilinear interpolation.Although this is generally a worse interpolator than scipy's RectBivariateSpline, I've implemented an equivalent in cython (the
BicubicInterpolator
class, which can be found insncosmo/salt2utils.pyx
in this PR), and intend to use it in sncosmo's SALT2 model (not yet done). Here's why I say it is a worse interpolator:I do wish the snfit implementation had just used splines, but for now we're valuing consistency.
As an aside, the implementation of the interpolator here is likely to be faster than the C++ implementation in snfit because this version operates on arrays of points whereas the C++ version operates one point at a time. Because we're often evaluating the interpolator on a grid of points (in wavelength and time), there are savings to be had in lookups and reusing coefficients between points on the grid.
SALT2 color law
This PR also implements the SALT2 color law in cython (SALT2ColorLaw in
sncosmo/salt2utils.pyx
). Formerly we had an exact Python implementation and then used a spline approximation to it for speed. The cython implementation allows us to skip the approximation. Additionally, it actually turns out to be faster than the spline evaluation.Testing
This PR adds a small C++ program (
misc/test_salt2model.cc
) that links to a built snfit to output some results from the salt2 model that we can test against in sncosmo.(Testing not yet done.)The C++ program is there for provenance, but won't actually be used in running sncosmo tests. Rather, the output from the C++ program is included in the repo under test data (sncosmo/tests/data
).