In [1]:
from __future__ import print_function
import numpy as np
from matplotlib import pyplot as plt
import sncosmo
%matplotlib inline
In [2]:
model = sncosmo.Model(source='salt2')
In [3]:
# a model is initialized with some set of parameters
model.param_names
Out[3]:
In [4]:
model.parameters
Out[4]:
In [5]:
# printing a model will display some information and the current parameters
print(model)
In [6]:
# setting and getting parameters by name
model.set(x1=1.0)
In [7]:
# set multiple parameters at once
model.set(z=0.5, x0=1.e-6, x1=0.5, c=0.2)
In [8]:
# this is equivalent:
params = {'z': 0.5, 'x0': 1.e-6, 'x1': 0.5, 'c': 0.2}
model.set(**params)
In [9]:
# get parameters by name
model.get('x1')
Out[9]:
In [10]:
# get individual times and wavelengths
model.flux(0., 4000.)
Out[10]:
In [11]:
# arrays or lists work as you'd expect:
model.flux(0., [3000., 4000.])
Out[11]:
In [12]:
# time introduces a second dimension
model.flux(time=[0., 1.], wave=[3000., 4000.])
Out[12]:
In [13]:
# plot the spectrum
wave = np.linspace(3000., 9200., 1000)
flux = model.flux(0., wave)
plt.plot(wave, flux)
plt.ylim(ymin=0.)
plt.xlim(2000, 9200);
In [14]:
# light curve at wavelength = 4000 angstroms
time = np.linspace(-20., 50., 71)
flux = model.flux(time, 8000.)
flux.shape
Out[14]:
In [15]:
plt.plot(time, flux[:,0]);
In [16]:
# there are a lot of built-in bandpasses
band = sncosmo.get_bandpass('sdssg')
In [17]:
wave = np.linspace(3000., 6000., 1000)
plt.plot(wave, band(wave));
In [18]:
# create a bandpass
band = sncosmo.Bandpass([4000., 5000.], [1., 1.], name='tophatg')
In [19]:
wave = np.linspace(3000., 6000., 1000)
plt.plot(wave, band(wave));
In [20]:
model.bandmag('sdssr', 'ab', [0., 10., 20.])
Out[20]:
In [21]:
# equivalent to:
band = sncosmo.get_bandpass('sdssr')
magsys = sncosmo.get_magsystem('ab')
model.bandmag(band, magsys, [0., 10., 20.])
Out[21]:
In [22]:
# in flux units rather than magnitudes
model.bandflux('sdssr', [0., 10., 20.]) # physical flux in photons/s/cm^2
Out[22]:
In [23]:
# more useful scaling:
model.bandflux('sdssr', [0., 10., 20.], zp=20., zpsys='ab') # flux scaled to desired zp
Out[23]:
In [24]:
!more $HOME/.astropy/config/sncosmo.cfg
In [ ]: