示例#1
0
    def test_fit_lc_returns_correct_type(self) -> None:
        """Test the fit_lc function returns an ``SNModel`` instance for the fitted model"""

        data = sncosmo.load_example_data()
        model = SNModel('salt2')

        with warnings.catch_warnings():
            warnings.filterwarnings('ignore')
            _, fitted_model = sncosmo.fit_lc(data, model, ['x0'])

        self.assertIsInstance(fitted_model, SNModel)
示例#2
0
    def runTest() -> None:
        data = sncosmo.load_example_data()
        light_curve = LightCurve.from_sncosmo(data)

        np.testing.assert_array_equal(data['time'], light_curve.time)
        np.testing.assert_array_equal(data['band'], light_curve.band)
        np.testing.assert_array_equal(data['flux'], light_curve.flux)
        np.testing.assert_array_equal(data['fluxerr'], light_curve.fluxerr)
        np.testing.assert_array_equal(data['zp'], light_curve.zp)
        np.testing.assert_array_equal(data['zpsys'], light_curve.zpsys)
        np.testing.assert_array_equal(0, light_curve.phot_flag)
示例#3
0
    def test_mcmc_lc_returns_correct_type(self) -> None:
        """Test the fit_lc function returns an ``SNModel`` instance for the fitted model"""

        data = sncosmo.load_example_data()
        model = SNModel('salt2-extended')

        # Some sncosmo versions use deprecated emcee kwargs
        with warnings.catch_warnings():
            warnings.simplefilter('ignore')
            _, fitted_model = sncosmo.mcmc_lc(data, model, ['x0'])

        self.assertIsInstance(fitted_model, SNModel)
示例#4
0
    def test_to_pandas() -> None:
        """Test data returned by ``to_pandas`` matches data used to build the LightCurve"""

        data = sncosmo.load_example_data().to_pandas('time')
        data['phot_flag'] = 0.0

        light_curve = LightCurve(time=data.index,
                                 band=data['band'],
                                 flux=data['flux'],
                                 fluxerr=data['fluxerr'],
                                 zp=data['zp'],
                                 zpsys=data['zpsys'],
                                 phot_flag=data['phot_flag'])

        pd.testing.assert_frame_equal(data, light_curve.to_pandas())
示例#5
0
    def test_to_astropy() -> None:
        """Test data returned by ``to_astropy`` matches data used to build the LightCurve"""

        data = sncosmo.load_example_data()
        data['phot_flag'] = 0

        light_curve = LightCurve(time=data['time'],
                                 band=data['band'],
                                 flux=data['flux'],
                                 fluxerr=data['fluxerr'],
                                 zp=data['zp'],
                                 zpsys=data['zpsys'],
                                 phot_flag=data['phot_flag'])

        np.testing.assert_array_equal(data, light_curve.to_astropy())
示例#6
0
def create_mock_light_curve() -> LightCurve:
    """Create a mock light-curve

    Returns:
        A LightCurve instance filled with dummy data
    """

    data = sncosmo.load_example_data()
    data['band'] = [b.replace('sdss', 'lsst_hardware_') for b in data['band']]
    return LightCurve(time=data['time'],
                      band=data['band'],
                      flux=data['flux'],
                      fluxerr=data['fluxerr'],
                      zp=data['zp'],
                      zpsys=data['zpsys'])
示例#7
0
wave = np.linspace(2000.0, 10000.0, 500)
for w in (0.0, 0.2, 0.4, 0.6, 0.8, 1.0):
    source.set(w=w)
    plt.plot(wave, source.flux(10., wave), label='w={:3.1f}'.format(w))

plt.legend()
plt.show()

##########################################################################
# The w=0 spectrum is that of the Ia model, the w=1 spectrum is that of
# the IIp model, while intermediate spectra are weighted combinations.
#
# We can even fit the model to some data!

model = sncosmo.Model(source=source)
data = sncosmo.load_example_data()
result, fitted_model = sncosmo.fit_lc(data,
                                      model, ['z', 't0', 'amplitude', 'w'],
                                      bounds={
                                          'z': (0.2, 1.0),
                                          'w': (0.0, 1.0)
                                      })

sncosmo.plot_lc(data, model=fitted_model, errors=result.errors)

##########################################################################
# The fact that the fitted value of w is closer to 0 than 1 indicates that
# the light curve looks more like the Ia template than the IIp template.
# This is generally what we expected since the example data here was
# generated from a Ia template (although not the Nugent template!).
from matplotlib import pyplot as plt

wave = np.linspace(2000.0, 10000.0, 500)
for w in (0.0, 0.2, 0.4, 0.6, 0.8, 1.0):
    source.set(w=w)
    plt.plot(wave, source.flux(10., wave), label='w={:3.1f}'.format(w))

plt.legend()
plt.show()

##########################################################################
# The w=0 spectrum is that of the Ia model, the w=1 spectrum is that of
# the IIp model, while intermediate spectra are weighted combinations.
#
# We can even fit the model to some data!

model = sncosmo.Model(source=source)
data = sncosmo.load_example_data()
result, fitted_model = sncosmo.fit_lc(data, model,
                                      ['z', 't0', 'amplitude', 'w'],
                                      bounds={'z': (0.2, 1.0),
                                              'w': (0.0, 1.0)})

sncosmo.plot_lc(data, model=fitted_model, errors=result.errors)

##########################################################################
# The fact that the fitted value of w is closer to 0 than 1 indicates that
# the light curve looks more like the Ia template than the IIp template.
# This is generally what we expected since the example data here was
# generated from a Ia template (although not the Nugent template!).
示例#9
0
def test_load_example_data():
    data = sncosmo.load_example_data()
示例#10
0
def test_load_example_data():
    data = sncosmo.load_example_data()