sncosmo / sncosmo

Python library for supernova cosmology

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Interpolating built-in source snf-2011fe results in partially negative spectrum

JTerwel opened this issue · comments

I stumbled upon this while playing around with the built-in TimeSeriesSource for SN2011fe.
Interpolating the spectrum to around 40 days after peak seems to cause the blue part of the spectrum to go negative. As a result of this, when requesting an interpolated light curve in e.g. ztfg there is a region where light curve disappears.

For instance, by running the following code:

import sncosmo
import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(-15, 95, 111)
test = sncosmo.get_source('snf-2011fe')
plt.plot(test._phase, test.bandmag('ztfg', 'ab', test._phase), label='built-in')
plt.plot(x, test.bandmag('ztfg', 'ab', x), label='built-in interpolated')
plt.xlim(-20, 110)
plt.ylim(16, 9.5)
plt.legend(loc='upper right')
plt.show()

plt.plot(test._wave, test.flux(40, test._wave))
plt.show()

I plot the light curve, while only using the phases of the spectra in the TimeSeriesSource (No interpolation, blue curve).
I also plot the light curve by interpolating to get the magnitude each day (orange curve).

The second plot shows the interpolated spectrum at phase=40. The blue part of the spectrum, up to 5500 Angstrom is too low.

This is the result from the code above:
Screenshot 2021-10-14 at 15 39 40

The issue seems to come from the spline interpolation combined with the large gap between spectra in the TimeSeriesSource (last one is at phase=23.7 & next one is at phase=74.1) allowing inaccuracies in the interpolation to grow.
It might be possible to remedy this by changing the order of the spline, but I have yet to find a way to change it. kx & ky are currently both fixed at 3 inside the TimeSeriesSource.

So in short, I found an interpolation problem within the built-in SN2011fe source. The problem itself might however be more general if it is rooted in the spline interpolation in a TimeSeriesSource.

Yes, this is a problem that shows up for several of the sparsely sampled TimeSeriesSources. There was discussion about this in #203 from a few years ago.

We should probably be using linear interpolation for time series like this one with large gaps instead of spline interpolation.

I put together a quick PR (#329) that changes SNCosmo to use linear interpolation instead of a cubic spline for this source.

Note that this does linear interpolation in flux rather than in magnitude, so the results are a bit different from the linear interpolation that you showed:

linear_interp

By the way, if your goal is just to get a model of a normal Type Ia supernova, I'd recommend either using the Hsiao template ('hsiao' in SNCosmo) or the SALT2 mean model ('salt2' in SNCosmo). The SN2011fe "model" is really just a bunch of spectra and will never be a very accurate model at times where there are no nearby spectra.

I was building my own SN2011fe model using different spectra, and wanted to compare it to the built-in one. My model has the same issue, but at different phases. Changing the spline order seems to work quite well.

Fixed with #329