warpTemplate is a Python package designed to provide warped supernova (SN) time series templates and correction models using the sncosmo package. It includes tools for loading existing templates, warping time series data, and calculating correction coefficients to match observed SN data. The package uses advanced techniques such as spline-based warping and template fitting to generate accurate, customized models for SN research.
- Warped SN Time Series: Load existing SN templates and apply warping based on user-supplied data (phase, wavelength, flux).
- Template Correction: Correct templates to match observed SN data by calculating correction coefficients and interpolation.
- Easy-to-use Models: Create
sncosmo.Modelobjects with the corrected templates. - Data Handling: The package works directly with SN data tables (e.g., from ZTF, DES, or other surveys).
- Reproducible Results: Optional reproducibility with random seed for template selection.
The repository separates two working layers:
notebooks/template_creation/: historical notebooks and helper files for creating, validating, and colour-calibrating warp coefficient libraries.notebooks/template_usage/: current notebooks for loading existing coefficients, visualising templates, and creating light-curve tables.
The importable package code remains at the top level of warpTemplate/:
loaders.py: load and sample stored coefficient files.models.py: wrap warped sources assncosmo.Modelobjects.sources.py: implement the warped time-series source.lightcurves.py: convenience helpers for checking and plotting generated light curves.corrections.py: construction-side correction algorithm used by the historical template-building workflow.
For practical use, start with notebooks/template_usage/create_usable_template_lightcurves.ipynb.
pip install warp_templatesgit clone https://github.com/your-username/warp_templates.git
cd warp_templates
pip install .- Python >= 3.10
numpyscipyastropysncosmomatplotlib
from warp_templates import get_warpedTimeSeriesModel
warpdata = {
'corrmodel': {
'phase': [...],
'wave': [...],
'flux': [...],
}
}
# Example of generating a warped time series model
model = get_warpedTimeSeriesModel(
name="warped_Ia",
original_template_name="template_name",
warpdata=warpdata,
z=0.05,
hostr_v=3.1
)
# Use the model for further analysis or plottingfrom warp_templates import WarpfitTemplateLoader, get_template_correction
# Load templates
loader = WarpfitTemplateLoader("warpcoeffs/")
templates = loader.get_templates("Ia")
# Compute correction for a template based on data (astropy Table)
tab = ... # Your SN data table
correction = get_template_correction(tab, "Ia_template", z=0.05)
# Use the correction model for further work# The correction model is a 2D spline object that you can apply to your data
corrmodel = correction['corrmodel']
flux_corrected = corrmodel(some_phase_values, some_wave_values)get_warpedTimeSeriesModel(name: str, original_template_name: str, warpdata: dict, ...): Creates ansncosmo.Modelusing the warped template data.WarpfitTemplateLoader: A class for loading and filtering warp coefficients for different supernova templates.get_template_correction(tab: Table, templatename: str, z: float, ...): Computes the correction coefficients to match a template to observed SN data, including outlier rejection and interpolation.
- Load warp coefficients using
WarpfitTemplateLoader. - Select a SN template and compute the correction to match observed SN data using
get_template_correction. - Generate the warped model using
get_warpedTimeSeriesModel. - Apply the correction model to the observed SN data for analysis or fitting.
The package supports plotting of both the model and the corrected data. For example, you can save correction plots to disk:
import matplotlib.pyplot as plt
# Plot model data
fig = sncosmo.plot_lc(tab, model=model, errors=result.errors)
fig.savefig("model_plot.png")This package includes a set of tests to ensure correct functionality. To run the tests:
pytestMIT License. See LICENSE for more details.
This package leverages the sncosmo library for SN model fitting and flux computation.