template#
This module provides core template tools, and defines the Template, GridTemplate, and TemplateCollection classes, which wrap sncosmo.Model objects to generate and fit lightcurves and spectra.
- skysurvey.template.get_sncosmo_model(source='salt2', zero_before=True, **params)[source]#
Get the template (sncosmo.Model).
- Parameters:
source (sncosmo.Source or str) – The model for the spectral evolution of the source. If a string is given, it is used to retrieve a sncosmo.Source from the registry.
model (**kwargs goes to model.set() to change the parameter's)
- Returns:
the sncosmo.Model template
- Return type:
sncosmo.Model
- skysurvey.template.sncosmoresult_to_pandas(result)[source]#
Takes a sncosmo.Results (lc fit output) and converts it in pandas’s objects.
- Parameters:
result (sncosmo.Result) – output of sncosmo’s lightcurve fit function.
- Returns:
results (value, errors, covariances) and metadata (chi2, etc.)
- Return type:
pandas.DataFrame, pandas.Series
- skysurvey.template.parse_template(template)[source]#
Parse a template or source into a
skysurvey.Templateinstance.- Parameters:
template (str, sncosmo.Source, sncosmo.Model, or
skysurvey.Template) – The template to parse. If a string is given, it is assumed to be a sncosmo model name.- Returns:
The parsed template(s).
- Return type:
skysurvey.Templateor list ofskysurvey.Template
- class skysurvey.template.Template(sncosmo_model)[source]#
Bases:
objectA class to model templates.
- Parameters:
sncosmo_model (sncosmo.Model) – The sncosmo model.
- classmethod from_sncosmo(source, **kwargs)[source]#
Loads the instance given the source name.
- Parameters:
source (sncosmo.Source or str) – The model for the spectral evolution of the source. If a string is given, it is used to retrieve a sncosmo.Source from the registry.
**kwargs – goes to
get_sncosmo_model(source, **kwargs)
- Return type:
instance
- add_effect(effects)[source]#
Add effects to the sncosmo model.
- Parameters:
effects (
skysurvey.effect, list) – effect to be applied to the sncosmo model It could be a list of effects. (seeskysurvey.effect.from_sncosmo, if you have a sncosmo.PropagationEffect, name and frame)- Return type:
None
- get(**kwargs)[source]#
Return a copy of the model. You can set new parameter to this copy using kwargs.
- Return type:
sncosmo.Model
- get_lightcurve(band, times, sncosmo_model=None, in_mag=False, zp=25, zpsys='ab', **kwargs)[source]#
Get the lightcurves (flux or mag).
- Parameters:
times (array) – Array of times.
sncosmo_model (sncosmo.Model, optional) – The sncosmo model to use. If None, the instance’s model is used.
in_mag (bool, optional) – If True, return the lightcurve in magnitude.
zp (float, optional) – Zero point for the flux.
zpsys (str, optional) – Zero point system.
**kwargs – Goes to
self.get()to set the model parameters.
- Returns:
The lightcurve values.
- Return type:
array
- get_spectrum(time, lbdas, sncosmo_model=None, as_phase=True, **kwargs)[source]#
Get the spectrum at phase (time) for the given wavelength.
(based in sncosmo_model.flux(time, lbda)
- Parameters:
time (float or list_like) – Time(s) in days. If None (default), the times corresponding to the native phases of the model are used.
lbdas (float or list_like) – Wavelength(s) in Angstroms. If None (default), the native wavelengths of the model are used.
as_phase (bool) – Is the given time a phase ? (as_phase=True) or a actual time (False) If phase, it is multiplied by (1+z) to be in restframe
- Returns:
flux – Spectral flux density values in ergs / s / cm^2 / Angstrom.
- Return type:
float or numpy.ndarray
See also
get_lightcurve()get the transient lightcurve
- show_spectrum(time, lbdas, params={}, ax=None, fig=None, **kwargs)[source]#
Show the spectrum at a given time.
- show_lightcurve(band, params=None, ax=None, fig=None, colors=None, phase_range=None, npoints=500, zp=25, zpsys='ab', format_time=True, t0_format='mjd', in_mag=False, invert_mag=True, **kwargs)[source]#
Show the lightcurve.
- Parameters:
params (dict, optional) – Parameters for the model.
ax (matplotlib.axes, optional) – The axes to plot on.
fig (matplotlib.figure, optional) – The figure to plot on.
colors (list, optional) – List of colors for the bands.
phase_range (list, optional) – Phase range to plot.
npoints (int, optional) – Number of points to plot.
zp (float, optional) – Zero point for the flux.
zpsys (str, optional) – Zero point system.
format_time (bool, optional) – If True, format the time axis.
t0_format (str, optional) – Format of the t0.
in_mag (bool, optional) – If True, plot in magnitude.
invert_mag (bool, optional) – If True, invert the magnitude axis.
**kwargs – Goes to ax.plot().
- Return type:
matplotlib.figure
- fit_data(data, guessparams=None, fixedparams=None, vparam_names=None, bounds=None, **kwargs)[source]#
Fit the data with the template.
- Parameters:
data (pandas.DataFrame) – The data to fit.
guessparams (dict, optional) – Guess parameters for the fit.
fixedparams (dict, optional) – Fixed parameters for the fit.
vparam_names (list, optional) – List of parameters to vary.
bounds (dict, optional) – Bounds for the parameters.
**kwargs – Goes to sncosmo.fit_lc().
- Returns:
The results of the fit.
- Return type:
pandas.DataFrame, pandas.Series
- property source#
The sncosmo source.
- property sncosmo_model#
Hiden sncosmo_model model to check what’s inside.
- property parameters#
The model parameters.
- property effect_parameters#
The model effect parameters.
- property core_parameters#
The model core parameters.
- class skysurvey.template.GridTemplate(sncosmo_model)[source]#
Bases:
TemplateA class to model Gridtemplates.
- Parameters:
sncosmo_model (sncosmo.Model) – The sncosmo model.
_GRID_OF (str) – The class type that populates this grid (e.g., a specific Source or Target class). Defaults to None.
- classmethod from_filenames(filenames, refindex=0, grid_of=None)[source]#
Load the instance from a list of filenames.
- set_grid_datafile(datafile)[source]#
Set the grid datafile.
- Parameters:
datafile (pandas.DataFrame) – The grid datafile.
- set_grid_data(data)[source]#
Set the grid data.
- Parameters:
data (pandas.DataFrame) – The grid data.
- get(grid_element, **kwargs)[source]#
Return a sncosmo model for the template’s source name (
self.source).- Parameters:
grid_element (tuple) – The grid element to get.
**kwargs – Goes to
Template.get().
- Return type:
sncosmo.Model
- get_lightcurve(grid_element, band, times, sncosmo_model=None, params=None, in_mag=False, zp=25, zpsys='ab')[source]#
Get the lightcurve for a given grid element.
- Parameters:
grid_element (tuple) – The grid element to get.
times (array) – Array of times.
sncosmo_model (sncosmo.Model, optional) – The sncosmo model to use. If None, the instance’s model is used.
params (dict, optional) – Parameters for the model.
in_mag (bool, optional) – If True, return the lightcurve in magnitude.
zp (float, optional) – Zero point for the flux.
zpsys (str, optional) – Zero point system.
- Returns:
The lightcurve values.
- Return type:
array
- fit_data(data, grid_element, guessparams=None, fixedparams=None, vparam_names=None, bounds=None, **kwargs)[source]#
Fit the data with the template for a given grid element.
- Parameters:
data (pandas.DataFrame) – The data to fit.
grid_element (tuple) – The grid element to use.
guessparams (dict, optional) – Guess parameters for the fit.
fixedparams (dict, optional) – Fixed parameters for the fit.
vparam_names (list, optional) – List of parameters to vary.
bounds (dict, optional) – Bounds for the parameters.
**kwargs – Goes to sncosmo.fit_lc().
- Returns:
The results of the fit.
- Return type:
pandas.DataFrame, pandas.Series
- show_lightcurve(band, grid_element, params=None, ax=None, fig=None, colors=None, phase_range=None, npoints=500, zp=25, zpsys='ab', format_time=True, t0_format='mjd', in_mag=False, invert_mag=True, **kwargs)[source]#
Show the lightcurve for a given grid element.
- Parameters:
grid_element (tuple) – The grid element to use.
params (dict, optional) – Parameters for the model.
ax (matplotlib.axes, optional) – The axes to plot on.
fig (matplotlib.figure, optional) – The figure to plot on.
colors (list, optional) – List of colors for the bands.
phase_range (list, optional) – Phase range to plot.
npoints (int, optional) – Number of points to plot.
zp (float, optional) – Zero point for the flux.
zpsys (str, optional) – Zero point system.
format_time (bool, optional) – If True, format the time axis.
t0_format (str, optional) – Format of the t0.
in_mag (bool, optional) – If True, plot in magnitude.
invert_mag (bool, optional) – If True, invert the magnitude axis.
**kwargs – Goes to ax.plot().
- Return type:
matplotlib.figure
- property grid#
The grid of templates.
- property grid_datafile#
The grid datafile.
- property grid_data#
The grid data.
- property grid_parameters#
The grid parameters.
- property full_parameters#
Template parameters plus grid parameters.
- grid_of = None#
- class skysurvey.template.TemplateCollection(templates)[source]#
Bases:
objectA class to model collections of templates.
- Parameters:
templates (list) – List of templates.
- classmethod from_sncosmo(templates)[source]#
Load the instance from a list of sncosmo sources.
- Parameters:
templates (list) – List of sncosmo sources.
- Return type:
TemplateCollection
- classmethod from_list(templates)[source]#
Load the instance from a list of templates.
- Parameters:
templates (list) – List of templates.
- Return type:
TemplateCollection
- call_down_source(which, margs=None, allow_call=True, **kwargs)[source]#
Call a method on all templates sources.
- add_effect(effects)[source]#
Add an effect to all templates.
- Parameters:
effects (list) – List of effects.
- get_lightcurve(band, times, index=None, sncosmo_model=None, in_mag=False, zp=25, zpsys='ab', **kwargs)[source]#
Get the lightcurve for a given template.
- Parameters:
times (array) – Array of times.
index (int, optional) – The index of the template to use.
sncosmo_model (sncosmo.Model, optional) – The sncosmo model to use. If None, the instance’s model is used.
in_mag (bool, optional) – If True, return the lightcurve in magnitude.
zp (float, optional) – Zero point for the flux.
zpsys (str, optional) – Zero point system.
**kwargs – Goes to the template’s
get_lightcurvemethod.
- Returns:
The lightcurve values.
- Return type:
array
- property templates#
The list of templates.
- property ntemplates#
The number of templates.
- property names#
The names of the templates.
- property is_uniquetype#
Whether the templates are of a unique type.
- property effect_parameters#
The effect parameters of all templates in the collection.
- property template_parameters#
The template parameters of the templates.
- property parameters#
The parameters of the templates.