API Documentation¶
Fitting¶
-
sntd.fitting.
fit_data
(curves=None, snType='Ia', bands=None, models=None, params=None, bounds={}, ignore=None, constants={}, method='parallel', t0_guess=None, effect_names=[], effect_frames=[], batch_init=None, cut_time=None, dust=None, microlensing=None, fitOrder=None, color_bands=None, min_points_per_band=3, identify_micro=False, fit_prior=None, par_or_batch='parallel', batch_partition=None, nbatch_jobs=None, batch_python_path=None, n_per_node=1, wait_for_batch=False, band_order=None, set_from_simMeta=None, guess_amplitude=True, trial_fit=True, clip_data=False, kernel='RBF', refImage='image_1', nMicroSamples=100, color_curve=None, warning_supress=True, verbose=True, **kwargs)[source]¶ The main high-level fitting function.
Parameters: - curves (
curveDict
) – The curveDict object containing the multiple images to fit. - snType (str) – The supernova classification
- bands (
list
ofBandpass
orstr
, orBandpass
orstr
) – The band(s) to be fit - models (
list
ofModel
or str, orModel
orstr
) – The model(s) to be used for fitting to the data - params (
list
ofstr
) – The parameters to be fit for the models inside of the parameter models - bounds (
dict
) – A dictionary with parameters in params as keys and a tuple of bounds as values - ignore (
list
ofstr
) – List of parameters to ignore - constants (
dict
) – Dictionary with parameters as keys and the constant value you want to set them to as values - method (
str
orlist
) – Needs to be ‘parallel’, ‘series’, or ‘color’, or a list containting one or more of these - t0_guess (
dict
) – Dictionary with image names (i.e. ‘image_1’,’image_2’) as keys and a guess for time of peak as values - effect_names (
list
ofstr
) – List of effect names if model contains aPropagationEffect
. - effect_frames (
list
ofstr
) – List of the frames (e.g. obs or rest) that correspond to the effects in effect_names - batch_init (
str
) – A string to be pasted into the batch python file (e.g. extra imports or filters added to sncosmo.) - cut_time (
list
) – The start and end (rest frame) phase that you want to fit in, default accept all phases. - dust (
sncosmo.PropagationEffect
) – An sncosmo dust propagation effect to include in the model - microlensing (str) – If None microlensing is ignored, otherwise should be str (e.g. achromatic, chromatic)
- fitOrder (
list
) – The order you want to fit the images if using parallel method (default chooses by npoints/SNR) - color_bands (
list
) – If using multiple methods (in batch mode), the subset of bands to use for color fitting. - min_points_per_band (int) – Only accept bands to fit with this number of points fitting other criterion (e.g. minsnr)
- identify_micro (bool) – If True, function is run to attempt to identify bands where microlensing is least problematic.
- fit_prior (
curveDict
or bool) – if implementing parallel method alongside others and fit_prior is True, will use output of parallel as prior for series/color. If SNTD curveDict object, used as prior for series or color. - par_or_batch (str) – if providing a list of SNe, par means multiprocessing and batch means sbatch. Must supply other batch parameters if batch is chosen, so parallel is default.
- batch_partition (str) – The name of the partition for sbatch command
- nbatch_jobs (int) – number of jobs (10 jobs for 100 light curves is 10 light curves per job)
- batch_python_path (str) – path to python you want to use for batch mode (if different from current)
- n_per_node (int) – Number of SNe to fit per node (in series) in batch mode.
- wait_for_batch (bool) – if false, submits job in the background. If true, waits for job to finish (shows progress bar) and returns output.
- band_order (
list
) – If you want colors to be fit in a specific order (e.g. B-V instead of V-B depending on band order) - set_from_simMeta (
dict
) – Dictionary where keys are model parameters and values are the corresponding key in thecurveDict
.images.simMeta dictionary (e.g. {‘z’:’sim_redshift’} if you want to set the model redshift based on a simulated redshift in simMeta called ‘sim_redshfit’) - guess_amplitude (bool) – If True, the amplitude parameter for the model is estimated, as well as its bounds
- trial_fit (bool) – If true, a simple minuit fit is performed to locate the parameter space for nestle fits, otherwise the full parameter range in bounds is used.
- clip_data (bool) – If true, criterion like minsnr and cut_time actually will remove data from the light curve, as opposed to simply not fitting those data points.
- kernel (str) – The kernel to use for microlensing GPR
- refImage (str) – The name of the image you want to be the reference image (i.e. image_1,image_2, etc.)
- nMicroSamples (int) – The number of pulls from the GPR posterior you want to use for microlensing uncertainty estimation
- color_curve (
astropy.Table
) – A color curve to define the relationship between bands for parameterized light curve model. - warning_supress (bool) – Turns on or off warnings
- verbose (bool) – Turns on/off the verbosity flag
Returns: fitted_curveDict – The same curveDict that was passed to fit_data, but with new fits and time delay measurements included. List if list was provided.
Return type: Examples
>>> fitCurves=sntd.fit_data(myMISN,snType='Ia', models='salt2-extended',bands=['F110W','F125W'], params=['x0','x1','t0','c'],constants={'z':1.33},bounds={'t0':(-15,15),'x1':(-2,2),'c':(0,1)}, method='parallel',microlensing=None)
- curves (
Simulation¶
-
sntd.simulation.
createMultiplyImagedSN
(sourcename, snType, redshift, z_lens=None, telescopename='telescope', objectName='object', time_delays=[10.0, 50.0], magnifications=[2.0, 1.0], numImages=2, cadence=5, epochs=30, clip_time=[-30, 150], bands=['F105W', 'F160W'], start_time=None, gain=200.0, skynoiseRange=(1, 1.1), timeArr=None, zpsys='ab', zp=None, microlensing_type=None, microlensing_params=[], ml_loc=[None, None], dust_model='CCM89Dust', av_host=0.3, av_lens=None, fix_luminosity=False, minsnr=0.0, scatter=True, snrFunc=None)[source]¶ Generate a multiply-imaged SN light curve set, with user-specified time delays and magnifications.
Parameters: - sourcename (
Source
or str) – The model for the spectral evolution of the source. If a string is given, it is used to retrieve aSource
from the registry. - snType (str) – The classification of the supernova
- redshift (float) – Redshift of the source
- z_lens (float) – Redshift of the lens
- telescopename (str) – The name of the telescope used for observations
- objectName (str) – The name of the simulated supernova
- time_delays (
list
offloat
) – The relative time delays for the multiple images of the supernova. Must be same length as numImages - magnifications (
list
offloat
) – The relative magnifications for the multiple images of hte supernova. Must be same length as numImages - numImages (int) – The number of images to simulate
- cadence (float) – The cadence of the simulated observations (if timeArr is not defined)
- epochs (int) – The number of simulated observations (if timeArr is not defined)
- clip_time (
list
) – Rest frame phase start and end time, will clip output table to these values. - bands (
list
ofBandpass
orstr
) – The bandpass(es) used for simulated observations - start_time (float) – Start time for the leading image. If None, start will be the first value in the time array, and the peak will be this ± the relative time delay for the leading image.
- gain (float) – Gain of the telescope “obtaining” the simulated observations (if snrFunc not defined)
- skynoiseRange (
list
offloat
) – The left and right bounds of sky noise used to define observational noise (if snrFunc not defined) - timeArr (
list
offloat
) – A list of times that define the simulated observation epochs - zpsys (str or
MagSystem
) – The zero-point system used to define the photometry - zp (float or
list
offloat
) – The zero-point used to define the photometry, list if simulating multiple bandpasses. Then this list must be the same length as bands - microlensing_type (str) – If microlensing is to be included, defines whether it is “AchromaticSplineMicrolensing” or “AchromaticMicrolensing”
- microlensing_params (
array
orlist
ofint
) – If using AchromaticSplineMicrolensing, then this params list must give three values for [nanchor, sigmadm, nspl]. If using AchromaticMicrolensing, then this must be a microcaustic defined by a 2D numpy array - ml_loc (
list
) – List containing tuple locations of SN on microlensing map (random if Nones) - dust_model (str) – The dust model to be used for simulations, see sncosmo documentation for options
- av_host (float) – The A<sub>V</sub> parameter for the simulated dust effect in the source plane
- av_lens (float) – The A<sub>V</sub> parameter for the simulated dust effect in the lens plane
- fix_luminosity (bool) – Set the luminosity of every SN to be the peak of the distribution
- minsnr (float) – A minimum SNR threshold for observations when defining uncertainty
- scatter (bool) – Boolean that decides whether Gaussian scatter is applied to simulated observations
- snrFunc (
interp1d
ordict
) – An interpolation function that defines the signal to noise ratio (SNR) as a function of magnitude in the AB system. Used to define the observations instead of telescope parameters like gain and skynoise. This can be a dictionary, so that it’s different for each filter with filters as keys and interpolation functions as values.
Returns: MISN – A curveDict object containing each of the multiply-imaged SN light curves and the simulation parameters.
Return type: curveDict
Examples
>>> myMISN = sntd.createMultiplyImagedSN('salt2', 'Ia', 1.33,z_lens=.53, bands=['F110W'], zp=[26.8], cadence=5., epochs=35.,skynoiseRange=(.001,.005),gain=70. , time_delays=[10., 78.], magnifications=[7,3.5], objectName='My Type Ia SN', telescopename='HST',minsnr=5.0)
- sourcename (
I/O¶
-
class
sntd.curve_io.
curve
(zpsys='AB')[source]¶ SNTD class that describes each image of a MISN
-
bands
= None¶ str band names used
Type: @type
-
fits
= None¶ newDict
Contains fit information from fit_dataType: @type
-
meta
= None¶ dict
The metadata for the curveDict object, intialized with an empty “info” key value pair. It’s populated by added _metachar__ characters into the header of your data file.Type: @type
-
simMeta
= None¶ dict
A dictionary containing simulation metadata if this is a simulated curve objectType: @type
-
table
= None¶ astropy.table.Table
A table containing the data, used for SNCosmo functions, etc.Type: @type
-
zpsys
= None¶ str The zero-point system for this curve object
Type: @type
-
-
class
sntd.curve_io.
curveDict
(telescopename='Unknown', object='Unknown')[source]¶ The main object for SNTD. This organizes a MISN, containing the multiple light curves in self.images, all the fits, etc.
-
add_curve
(myCurve, key=None)[source]¶ Adds a curve object to the existing curveDict (i.e. adds an image to a MISN)
Parameters: - myCurve (
sntd.curve
) – The curve to add to self. - key (str) – The key you want to save this as, default is ‘image_1,image_2,etc.’
Returns: self
Return type: - myCurve (
-
color_table
(band1, band2, time_delays=None, referenceImage='image_1', ignore_images=[], static=False, model=None, minsnr=0.0)[source]¶ Takes the multiple images in self.images and combines the data into a single color curve using defined time delays and magnifications or best (quick) guesses.
Parameters: - band1 (str) – The first band for color curve
- band2 (str) – The second band for color curve
- time_delays (
dict
) – Dictionary with image names as keys and relative time delays as values (e.g. {‘image_1’:0,’image_2’:20}). Guessed if None. - referenceImage (str) – The image you want to be the reference (e.g. image_1, image_2, etc.)
- ignore_images (
list
) – List of images you do not want to include in the color curve. - static (bool) – Make the color curve, don’t shift the data
- model (
Model
) – If you want to use an sncosmo Model (and the guess_t0_amplitude method) to guess time delays - minsnr (float) – Cut data that don’t meet this threshold before making the color curve.
Returns: self
Return type:
-
combine_curves
(time_delays=None, magnifications=None, referenceImage='image_1', static=False, model=None, minsnr=0)[source]¶ Takes the multiple images in self.images and combines the data into a single light curve using defined time delays and magnifications or best (quick) guesses.
Parameters: - time_delays (
dict
) – Dictionary with image names as keys and relative time delays as values (e.g. {‘image_1’:0,’image_2’:20}). Guessed if None. - magnifications (
dict
) – Dictionary with image names as keys and relative magnifications as values (e.g. {‘image_1’:0,’image_2’:20}). Guessed if None. - referenceImage (str) – The image you want to be the reference (e.g. image_1, image_2, etc.)
- ignore_images (
list
) – List of images you do not want to include in the color curve. - static (bool) – Make the color curve, don’t shift the data
- model (
Model
) – If you want to use an sncosmo Model (and the guess_t0_amplitude method) to guess time delays - minsnr (float) – Cut data that don’t meet this threshold before making the color curve.
Returns: self
Return type: - time_delays (
-
meta
= None¶ dict
The metadata for the curveDict object, intialized with an empty “info” key value pair. It’s populated by added _metachar__ characters into the header of your data file.Type: @type
-
object
= None¶ str Object of interest
Type: @type
-
plot_fit
(method='parallel', par_image=None)[source]¶ Makes a corner plot based on one of the fitting methods
Parameters: method (str) – parallel, series, or color Returns: figure object Return type: figure
-
plot_object
(bands='all', savefig=False, plot3D=False, filename='mySN', orientation='horizontal', method='separate', showModel=False, showFit=False, showMicro=False, **kwargs)[source]¶ - Plot the multiply-imaged SN light curves and show/save to a file.
- Each subplot shows a single-band light curve, for all images of the SN.
Parameters: - bands (str or
list
ofstr
) – ‘all’ = plot all bands; or provide a list of bands to plot - savefig (bool) – boolean to save or not save plot
- plot3D (bool) – boolean to plot in 3D with plotly
- filename (str) – if savefig is True, this is the output filename
- orientation (str) – ‘horizontal’ = all subplots are in a single row ‘vertical’ = all subplots are in a single column
- method (str) – Plots the result of separate, series, or color curve method
- showModel (bool) – If true, the underlying model before microlensing is plotted as well
- showFit (bool) – If true and it exists, the best fit model from self.images[‘image’].fits.model is plotted
- showMicro (bool) – If true and it exists, the simulated microlensing is plotted as well
Returns: figure
Return type: ~matplotlib.pyplot.figure
-
table
= None¶ Table
The astropy table containing all of the data in your data fileType: @type
-
telescopename
= None¶ str Name of the telescope that the data were gathered from
Type: @type
-
-
sntd.curve_io.
read_data
(filename, **kwargs)[source]¶ - Used to read a light curve or curve object in pickle format.
- Either way, it’ll come out as a curve object.
Parameters: filename (str) – Name of the file to be read (ascii or pickle) Returns: curve Return type: curve
orcurveDict
-
sntd.curve_io.
write_data
(curves, filename=None, protocol=-1)[source]¶ - Used to write a curveDict object to a pickle
- to be read later
Parameters: Returns: Return type:
-
sntd.curve_io.
table_factory
(tables, telescopename='Unknown', object_name=None)[source]¶ This function will create a new curve object using an astropy table or tables.
Parameters: - tables (~astropy.table.Table or
list
) – Astropy table with all of your data from your data file, or a list of such tables. - telescopename (str) – Name of telescope for labeling purposes inside curve object
- object_name (str) – Name of object for labeling purposes inside curve object (e.g. SN2006jf, etc.)
Returns: curve
Return type: curve
- tables (~astropy.table.Table or
Microlensing¶
-
sntd.ml.
realizeMicro
(arand=0.25, debug=0, kappas=0.75, kappac=0.15, gamma=0.76, eps=0.6, nray=300, minmass=10, maxmass=10, power=-2.35, pixmax=5, pixminx=0, pixminy=0, pixdif=10, fracpixd=0.3, iwrite=0, verbose=False)[source]¶ Creates a microcaustic realization based on Wambsganss 1990 microlens code. All parameters are optional as they have defaults, see Wambsganss documentation for details on parameters.
-
sntd.ml.
microcaustic_field_to_curve
(field, time, zl, zs, velocity=<Quantity 10000. km / s>, M=<Quantity 1.98840987e+30 kg>, loc='Random', plot=False)[source]¶ Convolves an expanding photosphere (achromatic disc) with a microcaustic to generate a magnification curve.
Parameters: - field (
numpy.ndarray
) – An opened fits file of a microcaustic, can be generated by realizeMicro - time (
numpy.array
) – Time array you want for microlensing magnification curve, explosion time is 0 - zl (float) – redshift of the lens
- zs (float) – redshift of the source
- velocity (float*
astropy.units.Unit
) – The average velocity of the expanding photosphere - M (float*
Unit
) – The mass of the deflector - loc (str or tuple) – Random is defualt for location of the supernova, or pixel (x,y) coordiante can be specified
- plot (bool) – If true, plots the expanding photosphere on the microcaustic
Returns: - time (
numpy.array
) – The time array for the magnification curve - dmag (
numpy.array
) – The magnification curve.
- field (