BayeSN SNIa

[1]:
import numpy as np
import matplotlib.pyplot as plt

from lightcurvelynx.astro_utils.passbands import PassbandGroup
from lightcurvelynx.astro_utils.pzflow_node import PZFlowNode
from lightcurvelynx.astro_utils.snia_utils import (
    DistModFromRedshift,
)
from lightcurvelynx.math_nodes.np_random import NumpyRandomFunc
from lightcurvelynx.models.bayesn import BayesnModel
from lightcurvelynx.obstable.opsim import OpSim
from lightcurvelynx.simulate import simulate_lightcurves
from lightcurvelynx.models.snia_host import SNIaHost
from lightcurvelynx.survey_info import SurveyInfo
from lightcurvelynx.utils.plotting import plot_lightcurves

from lightcurvelynx import _LIGHTCURVELYNX_BASE_DATA_DIR

Load Data Files

We start by loading the files we will need for running the simulation: the OpSim database and the passband information. Both of these live in the data/ directory in the root directory. Note that nothing in this directory is saved to github, so the files might have to be downloaded initially.

[2]:
# Load the OpSim data.
opsim_db = OpSim.from_url(
    "https://s3df.slac.stanford.edu/data/rubin/sim-data/sims_featureScheduler_runs5.3/baseline/baseline_v5.3.0_10yrs.db",
)
t_min, t_max = opsim_db.time_bounds()
print(f"Loaded OpSim with {len(opsim_db)} rows and times [{t_min}, {t_max}]")

# Load the passband data for the griz filters only.
passband_group = PassbandGroup.from_preset(
    preset="LSST",
    filters=["g", "r", "i", "z"],
    trim_quantile=0.001,
    delta_wave=1,
)
# passband_group = PassbandGroup.from_preset(preset="LSST", table_dir=table_dir)
print(f"Loaded Passbands: {passband_group}")
Loaded OpSim with 1844571 rows and times [61208.201382236985, 64860.44487408427]
Loaded Passbands: PassbandGroup containing 4 passbands: LSST_g, LSST_r, LSST_i, LSST_z
[3]:
# Create a mask of matching filters.
filter_mask = passband_group.mask_by_filter(opsim_db["filter"])

# Filter the OpSim
opsim_db = opsim_db.filter_rows(filter_mask)
t_min, t_max = opsim_db.time_bounds()
print(f"Filtered OpSim to {len(opsim_db)} rows and times [{t_min}, {t_max}]")
Filtered OpSim to 1421879 rows and times [61208.42731204634, 64860.44487408427]

Create the model

To generate simulationed light curves we need to define the proporties of the object from which to sample. We start by creating a host based on a pre-trained pzflow model.

[4]:
# Load the Flow model into a PZFlow node. This gives access to all of the outputs of the
# flow model as attributes of the PZFlowNode.
pz_node = PZFlowNode.from_file(
    _LIGHTCURVELYNX_BASE_DATA_DIR / "model_files" / "snia_hosts_test_pzflow.pkl",  # filename
    node_label="pznode",
)

# Create a model for the host of the SNIa. The attributes will be sampled via
# the PZFlowNode's model. So each host instantiation will have its own properties.
# Note: This requires the user to know the output names from the underlying flow model.
host = SNIaHost(
    ra=pz_node.RA_GAL,
    dec=pz_node.DEC_GAL,
    hostmass=pz_node.LOGMASS,
    redshift=NumpyRandomFunc("uniform", low=0.1, high=0.6),
    node_label="host",
)

Here we define the Amplitude class with the purpose to create the distance modulus normalization factor to be added as a parameter to the bayesn model.

[5]:
from lightcurvelynx.base_models import FunctionNode


class AmplitudeFromDistMod(FunctionNode):
    def __init__(self, distmod, m_abs, **kwargs):
        # Call the super class's constructor with the needed information.
        super().__init__(
            func=self._amplitude_given_distmod,
            distmod=distmod,
            m_abs=m_abs,
            **kwargs,
        )

    def _amplitude_given_distmod(self, distmod, m_abs):
        """Compute distance modulus given redshift and cosmology.

        Parameters
        ----------
        distmod: float or numpy.ndarray
            The distance modulus (in mag)
        m_abs: float or numpy.ndarry
            The absolute magnitude modulus (in mag)

        Returns
        -------
        amplitude : float or numpy.ndarray
            The distance modulus effect
        """
        return np.power(10.0, -0.4 * (distmod + m_abs))

Next we create the SNIa model itself. We use bayeSN model with parameters randomly generated from realistic distributions.

Note that some attributes, such as (RA, dec), are sampled relative to the host’s properties.

[6]:
bayesian_model_name = "bayesnModel"
distmod_func = DistModFromRedshift(host.redshift, H0=73.0, Omega_m=0.3)
m_abs_func = NumpyRandomFunc("normal", loc=-19.3, scale=0.1)
amplitude_func = AmplitudeFromDistMod(distmod_func, m_abs_func)
source = BayesnModel(
    theta=NumpyRandomFunc("uniform", low=-1.74, high=2.10),
    Av=NumpyRandomFunc("uniform", low=0.01, high=0.3),
    Rv=NumpyRandomFunc("uniform", low=3, high=3),
    t0=NumpyRandomFunc("uniform", low=t_min, high=t_max),
    ra=NumpyRandomFunc("normal", loc=host.ra, scale=0.01),
    dec=NumpyRandomFunc("normal", loc=host.dec, scale=0.01),
    redshift=host.redshift,
    node_label="source",
    Amplitude=amplitude_func,
)

Generate the simulations

We can now generate random simulations with all the information defined above. The light curves are written in the nested-pandas format for easy analysis.

[7]:
lightcurves = simulate_lightcurves(
    source,
    num_samples=10,
    survey_info=SurveyInfo(opsim_db, passbands=passband_group),
    rest_time_window_offset=(-20, 50),
)
lightcurves
Simulating: 100%|██████████| 10/10 [00:18<00:00,  1.84s/obj]
[7]:
  id ra dec nobs t0 z lightcurve params
0 0 55.259294 -43.240763 10 62351.152174 0.425789
mjd filter ... obs_idx is_saturated
62398.404937 r ... 458559 False
+9 rows ... ... ... ...
{'pznode.RA_GAL': 55.26490020751953, 'pznode.DEC_GAL': -43.237937927246094, 'pznode.u_obs': 22.307029724121094, 'pznode.g_obs': 23.271221160888672, 'pznode.r_obs': 7.236503601074219, 'pznode.i_obs': 20.85927391052246, 'pznode.z_obs': 20.864112854003906, 'pznode.Y_obs': 20.206809997558594, 'pznode.LOGMASS': 10.362591743469238, 'pznode.LOG_SFR': -0.6209337711334229, 'pznode.ZPHOT': 0.46209776401519775, 'pznode.ZTRUE': 0.48372942209243774, 'host.ra': 55.26490020751953, 'host.dec': -43.237937927246094, 'host.redshift': 0.4257886641014482, 'host.t0': None, 'host.distance': None, 'host.hostmass': 10.362591743469238, 'NumpyRandomFunc:uniform_4.low': 0.1, 'NumpyRandomFunc:uniform_4.high': 0.6, 'NumpyRandomFunc:uniform_4.function_node_result': 0.4257886641014482, 'NumpyRandomFunc:normal_1.loc': 55.26490020751953, 'NumpyRandomFunc:normal_1.scale': 0.01, 'NumpyRandomFunc:normal_1.function_node_result': 55.25929386686556, 'source.ra': 55.25929386686556, 'source.dec': -43.240763206094485, 'source.redshift': 0.4257886641014482, 'source.t0': 62351.15217385594, 'source.distance': None, 'source.theta': -0.18105904461332875, 'source.Av': 0.18451517397652298, 'source.Rv': 3.0, 'source.Amplitude': 1.0079142844071924e-09, 'NumpyRandomFunc:normal_5.loc': -43.237937927246094, 'NumpyRandomFunc:normal_5.scale': 0.01, 'NumpyRandomFunc:normal_5.function_node_result': -43.240763206094485, 'NumpyRandomFunc:uniform_6.low': 61208.42731204634, 'NumpyRandomFunc:uniform_6.high': 64860.44487408427, 'NumpyRandomFunc:uniform_6.function_node_result': 62351.15217385594, 'NumpyRandomFunc:uniform_7.low': -1.74, 'NumpyRandomFunc:uniform_7.high': 2.1, 'NumpyRandomFunc:uniform_7.function_node_result': -0.18105904461332875, 'NumpyRandomFunc:uniform_8.low': 0.01, 'NumpyRandomFunc:uniform_8.high': 0.3, 'NumpyRandomFunc:uniform_8.function_node_result': 0.18451517397652298, 'NumpyRandomFunc:uniform_9.low': 3, 'NumpyRandomFunc:uniform_9.high': 3, 'NumpyRandomFunc:uniform_9.function_node_result': 3.0, 'DistModFromRedshift:_distmod_from_redshift_11.redshift': 0.4257886641014482, 'DistModFromRedshift:_distmod_from_redshift_11.function_node_result': 41.753860183435194, 'AmplitudeFromDistMod:_amplitude_given_distmod_10.distmod': 41.753860183435194, 'AmplitudeFromDistMod:_amplitude_given_distmod_10.m_abs': -19.262419183868154, 'AmplitudeFromDistMod:_amplitude_given_distmod_10.function_node_result': 1.0079142844071924e-09, 'NumpyRandomFunc:normal_12.loc': -19.3, 'NumpyRandomFunc:normal_12.scale': 0.1, 'NumpyRandomFunc:normal_12.function_node_result': -19.262419183868154}
1 1 55.181456 -43.358792 27 64580.558818 0.232236
mjd filter ... obs_idx is_saturated
64585.400444 i ... 1295049 False
+26 rows ... ... ... ...
{'pznode.RA_GAL': 55.17133331298828, 'pznode.DEC_GAL': -43.35248947143555, 'pznode.u_obs': 99.03945922851562, 'pznode.g_obs': 28.64394760131836, 'pznode.r_obs': 32.80780792236328, 'pznode.i_obs': 25.614362716674805, 'pznode.z_obs': 24.444149017333984, 'pznode.Y_obs': 24.364742279052734, 'pznode.LOGMASS': 8.879286766052246, 'pznode.LOG_SFR': -4.448701858520508, 'pznode.ZPHOT': 1.0792193412780762, 'pznode.ZTRUE': 1.0579993724822998, 'host.ra': 55.17133331298828, 'host.dec': -43.35248947143555, 'host.redshift': 0.23223614469177314, 'host.t0': None, 'host.distance': None, 'host.hostmass': 8.879286766052246, 'NumpyRandomFunc:uniform_4.low': 0.1, 'NumpyRandomFunc:uniform_4.high': 0.6, 'NumpyRandomFunc:uniform_4.function_node_result': 0.23223614469177314, 'NumpyRandomFunc:normal_1.loc': 55.17133331298828, 'NumpyRandomFunc:normal_1.scale': 0.01, 'NumpyRandomFunc:normal_1.function_node_result': 55.18145600367855, 'source.ra': 55.18145600367855, 'source.dec': -43.3587921984891, 'source.redshift': 0.23223614469177314, 'source.t0': 64580.55881849967, 'source.distance': None, 'source.theta': -0.9185193060030535, 'source.Av': 0.17043806853542348, 'source.Rv': 3.0, 'source.Amplitude': 4.0547532153338545e-09, 'NumpyRandomFunc:normal_5.loc': -43.35248947143555, 'NumpyRandomFunc:normal_5.scale': 0.01, 'NumpyRandomFunc:normal_5.function_node_result': -43.3587921984891, 'NumpyRandomFunc:uniform_6.low': 61208.42731204634, 'NumpyRandomFunc:uniform_6.high': 64860.44487408427, 'NumpyRandomFunc:uniform_6.function_node_result': 64580.55881849967, 'NumpyRandomFunc:uniform_7.low': -1.74, 'NumpyRandomFunc:uniform_7.high': 2.1, 'NumpyRandomFunc:uniform_7.function_node_result': -0.9185193060030535, 'NumpyRandomFunc:uniform_8.low': 0.01, 'NumpyRandomFunc:uniform_8.high': 0.3, 'NumpyRandomFunc:uniform_8.function_node_result': 0.17043806853542348, 'NumpyRandomFunc:uniform_9.low': 3, 'NumpyRandomFunc:uniform_9.high': 3, 'NumpyRandomFunc:uniform_9.function_node_result': 3.0, 'DistModFromRedshift:_distmod_from_redshift_11.redshift': 0.23223614469177314, 'DistModFromRedshift:_distmod_from_redshift_11.function_node_result': 40.229660289005004, 'AmplitudeFromDistMod:_amplitude_given_distmod_10.distmod': 40.229660289005004, 'AmplitudeFromDistMod:_amplitude_given_distmod_10.m_abs': -19.24957135616195, 'AmplitudeFromDistMod:_amplitude_given_distmod_10.function_node_result': 4.0547532153338545e-09, 'NumpyRandomFunc:normal_12.loc': -19.3, 'NumpyRandomFunc:normal_12.scale': 0.1, 'NumpyRandomFunc:normal_12.function_node_result': -19.24957135616195}
2 2 55.101210 -43.259578 13 63064.735957 0.416405
mjd filter ... obs_idx is_saturated
63114.366143 r ... 730399 False
+12 rows ... ... ... ...
{'pznode.RA_GAL': 55.093379974365234, 'pznode.DEC_GAL': -43.25621795654297, 'pznode.u_obs': 98.98821258544922, 'pznode.g_obs': 23.77337646484375, 'pznode.r_obs': 23.870712280273438, 'pznode.i_obs': 22.352130889892578, 'pznode.z_obs': 22.264705657958984, 'pznode.Y_obs': 21.88471221923828, 'pznode.LOGMASS': 9.272039413452148, 'pznode.LOG_SFR': -1.3258743286132812, 'pznode.ZPHOT': 0.38161134719848633, 'pznode.ZTRUE': 0.42054283618927, 'host.ra': 55.093379974365234, 'host.dec': -43.25621795654297, 'host.redshift': 0.4164050229925993, 'host.t0': None, 'host.distance': None, 'host.hostmass': 9.272039413452148, 'NumpyRandomFunc:uniform_4.low': 0.1, 'NumpyRandomFunc:uniform_4.high': 0.6, 'NumpyRandomFunc:uniform_4.function_node_result': 0.4164050229925993, 'NumpyRandomFunc:normal_1.loc': 55.093379974365234, 'NumpyRandomFunc:normal_1.scale': 0.01, 'NumpyRandomFunc:normal_1.function_node_result': 55.10120968239728, 'source.ra': 55.10120968239728, 'source.dec': -43.25957779008213, 'source.redshift': 0.4164050229925993, 'source.t0': 63064.73595671526, 'source.distance': None, 'source.theta': -0.2832709318727057, 'source.Av': 0.07149971132660317, 'source.Rv': 3.0, 'source.Amplitude': 1.0681609124554752e-09, 'NumpyRandomFunc:normal_5.loc': -43.25621795654297, 'NumpyRandomFunc:normal_5.scale': 0.01, 'NumpyRandomFunc:normal_5.function_node_result': -43.25957779008213, 'NumpyRandomFunc:uniform_6.low': 61208.42731204634, 'NumpyRandomFunc:uniform_6.high': 64860.44487408427, 'NumpyRandomFunc:uniform_6.function_node_result': 63064.73595671526, 'NumpyRandomFunc:uniform_7.low': -1.74, 'NumpyRandomFunc:uniform_7.high': 2.1, 'NumpyRandomFunc:uniform_7.function_node_result': -0.2832709318727057, 'NumpyRandomFunc:uniform_8.low': 0.01, 'NumpyRandomFunc:uniform_8.high': 0.3, 'NumpyRandomFunc:uniform_8.function_node_result': 0.07149971132660317, 'NumpyRandomFunc:uniform_9.low': 3, 'NumpyRandomFunc:uniform_9.high': 3, 'NumpyRandomFunc:uniform_9.function_node_result': 3.0, 'DistModFromRedshift:_distmod_from_redshift_11.redshift': 0.4164050229925993, 'DistModFromRedshift:_distmod_from_redshift_11.function_node_result': 41.69651838923554, 'AmplitudeFromDistMod:_amplitude_given_distmod_10.distmod': 41.69651838923554, 'AmplitudeFromDistMod:_amplitude_given_distmod_10.m_abs': -19.268110093362598, 'AmplitudeFromDistMod:_amplitude_given_distmod_10.function_node_result': 1.0681609124554752e-09, 'NumpyRandomFunc:normal_12.loc': -19.3, 'NumpyRandomFunc:normal_12.scale': 0.1, 'NumpyRandomFunc:normal_12.function_node_result': -19.268110093362598}
3 3 55.089268 -43.266136 1 62715.453591 0.227707
mjd filter ... obs_idx is_saturated
62764.397908 i ... 604328 False
{'pznode.RA_GAL': 55.08926010131836, 'pznode.DEC_GAL': -43.27314376831055, 'pznode.u_obs': 99.16358184814453, 'pznode.g_obs': 57.14149856567383, 'pznode.r_obs': 26.12176513671875, 'pznode.i_obs': 23.341304779052734, 'pznode.z_obs': 23.93375015258789, 'pznode.Y_obs': 23.457977294921875, 'pznode.LOGMASS': 9.565752983093262, 'pznode.LOG_SFR': -1.5455996990203857, 'pznode.ZPHOT': 0.923058807849884, 'pznode.ZTRUE': 0.8810091614723206, 'host.ra': 55.08926010131836, 'host.dec': -43.27314376831055, 'host.redshift': 0.2277067272540322, 'host.t0': None, 'host.distance': None, 'host.hostmass': 9.565752983093262, 'NumpyRandomFunc:uniform_4.low': 0.1, 'NumpyRandomFunc:uniform_4.high': 0.6, 'NumpyRandomFunc:uniform_4.function_node_result': 0.2277067272540322, 'NumpyRandomFunc:normal_1.loc': 55.08926010131836, 'NumpyRandomFunc:normal_1.scale': 0.01, 'NumpyRandomFunc:normal_1.function_node_result': 55.08926791920324, 'source.ra': 55.08926791920324, 'source.dec': -43.266136246156904, 'source.redshift': 0.2277067272540322, 'source.t0': 62715.45359050943, 'source.distance': None, 'source.theta': -0.9101774867316894, 'source.Av': 0.21386794293040068, 'source.Rv': 3.0, 'source.Amplitude': 4.855231653582422e-09, 'NumpyRandomFunc:normal_5.loc': -43.27314376831055, 'NumpyRandomFunc:normal_5.scale': 0.01, 'NumpyRandomFunc:normal_5.function_node_result': -43.266136246156904, 'NumpyRandomFunc:uniform_6.low': 61208.42731204634, 'NumpyRandomFunc:uniform_6.high': 64860.44487408427, 'NumpyRandomFunc:uniform_6.function_node_result': 62715.45359050943, 'NumpyRandomFunc:uniform_7.low': -1.74, 'NumpyRandomFunc:uniform_7.high': 2.1, 'NumpyRandomFunc:uniform_7.function_node_result': -0.9101774867316894, 'NumpyRandomFunc:uniform_8.low': 0.01, 'NumpyRandomFunc:uniform_8.high': 0.3, 'NumpyRandomFunc:uniform_8.function_node_result': 0.21386794293040068, 'NumpyRandomFunc:uniform_9.low': 3, 'NumpyRandomFunc:uniform_9.high': 3, 'NumpyRandomFunc:uniform_9.function_node_result': 3.0, 'DistModFromRedshift:_distmod_from_redshift_11.redshift': 0.2277067272540322, 'DistModFromRedshift:_distmod_from_redshift_11.function_node_result': 40.18137343094158, 'AmplitudeFromDistMod:_amplitude_given_distmod_10.distmod': 40.18137343094158, 'AmplitudeFromDistMod:_amplitude_given_distmod_10.m_abs': -19.396898320605434, 'AmplitudeFromDistMod:_amplitude_given_distmod_10.function_node_result': 4.855231653582422e-09, 'NumpyRandomFunc:normal_12.loc': -19.3, 'NumpyRandomFunc:normal_12.scale': 0.1, 'NumpyRandomFunc:normal_12.function_node_result': -19.396898320605434}
4 4 55.120553 -43.263459 2 64796.260883 0.578737
mjd filter ... obs_idx is_saturated
64853.434059 i ... 1420551 False
64854.418652 z ... 1421463 False
{'pznode.RA_GAL': 55.12704849243164, 'pznode.DEC_GAL': -43.271392822265625, 'pznode.u_obs': 30.18134307861328, 'pznode.g_obs': 98.16014099121094, 'pznode.r_obs': 31.227588653564453, 'pznode.i_obs': 25.307376861572266, 'pznode.z_obs': 25.019371032714844, 'pznode.Y_obs': 28.092796325683594, 'pznode.LOGMASS': 9.387049674987793, 'pznode.LOG_SFR': -2.2297112941741943, 'pznode.ZPHOT': 2.3318114280700684, 'pznode.ZTRUE': 1.3448920249938965, 'host.ra': 55.12704849243164, 'host.dec': -43.271392822265625, 'host.redshift': 0.5787373898521264, 'host.t0': None, 'host.distance': None, 'host.hostmass': 9.387049674987793, 'NumpyRandomFunc:uniform_4.low': 0.1, 'NumpyRandomFunc:uniform_4.high': 0.6, 'NumpyRandomFunc:uniform_4.function_node_result': 0.5787373898521264, 'NumpyRandomFunc:normal_1.loc': 55.12704849243164, 'NumpyRandomFunc:normal_1.scale': 0.01, 'NumpyRandomFunc:normal_1.function_node_result': 55.120553360380626, 'source.ra': 55.120553360380626, 'source.dec': -43.26345904305536, 'source.redshift': 0.5787373898521264, 'source.t0': 64796.26088251783, 'source.distance': None, 'source.theta': 0.5283782418433832, 'source.Av': 0.1419708627955989, 'source.Rv': 3.0, 'source.Amplitude': 4.6138073019497894e-10, 'NumpyRandomFunc:normal_5.loc': -43.271392822265625, 'NumpyRandomFunc:normal_5.scale': 0.01, 'NumpyRandomFunc:normal_5.function_node_result': -43.26345904305536, 'NumpyRandomFunc:uniform_6.low': 61208.42731204634, 'NumpyRandomFunc:uniform_6.high': 64860.44487408427, 'NumpyRandomFunc:uniform_6.function_node_result': 64796.26088251783, 'NumpyRandomFunc:uniform_7.low': -1.74, 'NumpyRandomFunc:uniform_7.high': 2.1, 'NumpyRandomFunc:uniform_7.function_node_result': 0.5283782418433832, 'NumpyRandomFunc:uniform_8.low': 0.01, 'NumpyRandomFunc:uniform_8.high': 0.3, 'NumpyRandomFunc:uniform_8.function_node_result': 0.1419708627955989, 'NumpyRandomFunc:uniform_9.low': 3, 'NumpyRandomFunc:uniform_9.high': 3, 'NumpyRandomFunc:uniform_9.function_node_result': 3.0, 'DistModFromRedshift:_distmod_from_redshift_11.redshift': 0.5787373898521264, 'DistModFromRedshift:_distmod_from_redshift_11.function_node_result': 42.552883934924594, 'AmplitudeFromDistMod:_amplitude_given_distmod_10.distmod': 42.552883934924594, 'AmplitudeFromDistMod:_amplitude_given_distmod_10.m_abs': -19.21303256499961, 'AmplitudeFromDistMod:_amplitude_given_distmod_10.function_node_result': 4.6138073019497894e-10, 'NumpyRandomFunc:normal_12.loc': -19.3, 'NumpyRandomFunc:normal_12.scale': 0.1, 'NumpyRandomFunc:normal_12.function_node_result': -19.21303256499961}
5 5 55.175367 -43.178190 0 63368.857610 0.207158 None {'pznode.RA_GAL': 55.18111801147461, 'pznode.DEC_GAL': -43.18240737915039, 'pznode.u_obs': 23.93056869506836, 'pznode.g_obs': 22.08507537841797, 'pznode.r_obs': 23.171226501464844, 'pznode.i_obs': 20.924755096435547, 'pznode.z_obs': 15.34736156463623, 'pznode.Y_obs': 20.158931732177734, 'pznode.LOGMASS': 9.464842796325684, 'pznode.LOG_SFR': -4.171128273010254, 'pznode.ZPHOT': 0.5466651916503906, 'pznode.ZTRUE': 0.4703814387321472, 'host.ra': 55.18111801147461, 'host.dec': -43.18240737915039, 'host.redshift': 0.20715764790347488, 'host.t0': None, 'host.distance': None, 'host.hostmass': 9.464842796325684, 'NumpyRandomFunc:uniform_4.low': 0.1, 'NumpyRandomFunc:uniform_4.high': 0.6, 'NumpyRandomFunc:uniform_4.function_node_result': 0.20715764790347488, 'NumpyRandomFunc:normal_1.loc': 55.18111801147461, 'NumpyRandomFunc:normal_1.scale': 0.01, 'NumpyRandomFunc:normal_1.function_node_result': 55.175367036857786, 'source.ra': 55.175367036857786, 'source.dec': -43.17818992734612, 'source.redshift': 0.20715764790347488, 'source.t0': 63368.857610386236, 'source.distance': None, 'source.theta': 0.22889200247264563, 'source.Av': 0.2292543406027105, 'source.Rv': 3.0, 'source.Amplitude': 5.489955894947477e-09, 'NumpyRandomFunc:normal_5.loc': -43.18240737915039, 'NumpyRandomFunc:normal_5.scale': 0.01, 'NumpyRandomFunc:normal_5.function_node_result': -43.17818992734612, 'NumpyRandomFunc:uniform_6.low': 61208.42731204634, 'NumpyRandomFunc:uniform_6.high': 64860.44487408427, 'NumpyRandomFunc:uniform_6.function_node_result': 63368.857610386236, 'NumpyRandomFunc:uniform_7.low': -1.74, 'NumpyRandomFunc:uniform_7.high': 2.1, 'NumpyRandomFunc:uniform_7.function_node_result': 0.22889200247264563, 'NumpyRandomFunc:uniform_8.low': 0.01, 'NumpyRandomFunc:uniform_8.high': 0.3, 'NumpyRandomFunc:uniform_8.function_node_result': 0.2292543406027105, 'NumpyRandomFunc:uniform_9.low': 3, 'NumpyRandomFunc:uniform_9.high': 3, 'NumpyRandomFunc:uniform_9.function_node_result': 3.0, 'DistModFromRedshift:_distmod_from_redshift_11.redshift': 0.20715764790347488, 'DistModFromRedshift:_distmod_from_redshift_11.function_node_result': 39.95054443522147, 'AmplitudeFromDistMod:_amplitude_given_distmod_10.distmod': 39.95054443522147, 'AmplitudeFromDistMod:_amplitude_given_distmod_10.m_abs': -19.299466573824894, 'AmplitudeFromDistMod:_amplitude_given_distmod_10.function_node_result': 5.489955894947477e-09, 'NumpyRandomFunc:normal_12.loc': -19.3, 'NumpyRandomFunc:normal_12.scale': 0.1, 'NumpyRandomFunc:normal_12.function_node_result': -19.299466573824894}
6 6 55.060813 -43.350258 2 64418.709687 0.541426
mjd filter ... obs_idx is_saturated
64401.042787 i ... 1221100 False
64401.066389 z ... 1221152 False
{'pznode.RA_GAL': 55.074851989746094, 'pznode.DEC_GAL': -43.34992980957031, 'pznode.u_obs': 106.65057373046875, 'pznode.g_obs': 16.109569549560547, 'pznode.r_obs': 25.83334732055664, 'pznode.i_obs': 23.567974090576172, 'pznode.z_obs': 22.430566787719727, 'pznode.Y_obs': 108.51424407958984, 'pznode.LOGMASS': 9.008270263671875, 'pznode.LOG_SFR': -2.135087490081787, 'pznode.ZPHOT': 1.5610201358795166, 'pznode.ZTRUE': 1.1591060161590576, 'host.ra': 55.074851989746094, 'host.dec': -43.34992980957031, 'host.redshift': 0.5414256839477007, 'host.t0': None, 'host.distance': None, 'host.hostmass': 9.008270263671875, 'NumpyRandomFunc:uniform_4.low': 0.1, 'NumpyRandomFunc:uniform_4.high': 0.6, 'NumpyRandomFunc:uniform_4.function_node_result': 0.5414256839477007, 'NumpyRandomFunc:normal_1.loc': 55.074851989746094, 'NumpyRandomFunc:normal_1.scale': 0.01, 'NumpyRandomFunc:normal_1.function_node_result': 55.060812689013304, 'source.ra': 55.060812689013304, 'source.dec': -43.350258083245734, 'source.redshift': 0.5414256839477007, 'source.t0': 64418.70968700891, 'source.distance': None, 'source.theta': -1.3539005218369555, 'source.Av': 0.2340755751331847, 'source.Rv': 3.0, 'source.Amplitude': 6.581495818721008e-10, 'NumpyRandomFunc:normal_5.loc': -43.34992980957031, 'NumpyRandomFunc:normal_5.scale': 0.01, 'NumpyRandomFunc:normal_5.function_node_result': -43.350258083245734, 'NumpyRandomFunc:uniform_6.low': 61208.42731204634, 'NumpyRandomFunc:uniform_6.high': 64860.44487408427, 'NumpyRandomFunc:uniform_6.function_node_result': 64418.70968700891, 'NumpyRandomFunc:uniform_7.low': -1.74, 'NumpyRandomFunc:uniform_7.high': 2.1, 'NumpyRandomFunc:uniform_7.function_node_result': -1.3539005218369555, 'NumpyRandomFunc:uniform_8.low': 0.01, 'NumpyRandomFunc:uniform_8.high': 0.3, 'NumpyRandomFunc:uniform_8.function_node_result': 0.2340755751331847, 'NumpyRandomFunc:uniform_9.low': 3, 'NumpyRandomFunc:uniform_9.high': 3, 'NumpyRandomFunc:uniform_9.function_node_result': 3.0, 'DistModFromRedshift:_distmod_from_redshift_11.redshift': 0.5414256839477007, 'DistModFromRedshift:_distmod_from_redshift_11.function_node_result': 42.37798479766521, 'AmplitudeFromDistMod:_amplitude_given_distmod_10.distmod': 42.37798479766521, 'AmplitudeFromDistMod:_amplitude_given_distmod_10.m_abs': -19.423796321969313, 'AmplitudeFromDistMod:_amplitude_given_distmod_10.function_node_result': 6.581495818721008e-10, 'NumpyRandomFunc:normal_12.loc': -19.3, 'NumpyRandomFunc:normal_12.scale': 0.1, 'NumpyRandomFunc:normal_12.function_node_result': -19.423796321969313}
7 7 55.190365 -43.318969 18 63470.445146 0.480715
mjd filter ... obs_idx is_saturated
63460.402728 z ... 859516 False
+17 rows ... ... ... ...
{'pznode.RA_GAL': 55.188385009765625, 'pznode.DEC_GAL': -43.32014083862305, 'pznode.u_obs': 99.26716613769531, 'pznode.g_obs': 26.809545516967773, 'pznode.r_obs': 17.139633178710938, 'pznode.i_obs': 24.707874298095703, 'pznode.z_obs': 24.09677505493164, 'pznode.Y_obs': 23.891754150390625, 'pznode.LOGMASS': 8.845505714416504, 'pznode.LOG_SFR': -3.775341272354126, 'pznode.ZPHOT': 0.8514092564582825, 'pznode.ZTRUE': 0.9355717301368713, 'host.ra': 55.188385009765625, 'host.dec': -43.32014083862305, 'host.redshift': 0.48071485544821, 'host.t0': None, 'host.distance': None, 'host.hostmass': 8.845505714416504, 'NumpyRandomFunc:uniform_4.low': 0.1, 'NumpyRandomFunc:uniform_4.high': 0.6, 'NumpyRandomFunc:uniform_4.function_node_result': 0.48071485544821, 'NumpyRandomFunc:normal_1.loc': 55.188385009765625, 'NumpyRandomFunc:normal_1.scale': 0.01, 'NumpyRandomFunc:normal_1.function_node_result': 55.19036466819472, 'source.ra': 55.19036466819472, 'source.dec': -43.318968820386026, 'source.redshift': 0.48071485544821, 'source.t0': 63470.44514585318, 'source.distance': None, 'source.theta': -0.4918060737346335, 'source.Av': 0.07870635486838888, 'source.Rv': 3.0, 'source.Amplitude': 5.801856254651969e-10, 'NumpyRandomFunc:normal_5.loc': -43.32014083862305, 'NumpyRandomFunc:normal_5.scale': 0.01, 'NumpyRandomFunc:normal_5.function_node_result': -43.318968820386026, 'NumpyRandomFunc:uniform_6.low': 61208.42731204634, 'NumpyRandomFunc:uniform_6.high': 64860.44487408427, 'NumpyRandomFunc:uniform_6.function_node_result': 63470.44514585318, 'NumpyRandomFunc:uniform_7.low': -1.74, 'NumpyRandomFunc:uniform_7.high': 2.1, 'NumpyRandomFunc:uniform_7.function_node_result': -0.4918060737346335, 'NumpyRandomFunc:uniform_8.low': 0.01, 'NumpyRandomFunc:uniform_8.high': 0.3, 'NumpyRandomFunc:uniform_8.function_node_result': 0.07870635486838888, 'NumpyRandomFunc:uniform_9.low': 3, 'NumpyRandomFunc:uniform_9.high': 3, 'NumpyRandomFunc:uniform_9.function_node_result': 3.0, 'DistModFromRedshift:_distmod_from_redshift_11.redshift': 0.48071485544821, 'DistModFromRedshift:_distmod_from_redshift_11.function_node_result': 42.067725765173336, 'AmplitudeFromDistMod:_amplitude_given_distmod_10.distmod': 42.067725765173336, 'AmplitudeFromDistMod:_amplitude_given_distmod_10.m_abs': -18.97664317674292, 'AmplitudeFromDistMod:_amplitude_given_distmod_10.function_node_result': 5.801856254651969e-10, 'NumpyRandomFunc:normal_12.loc': -19.3, 'NumpyRandomFunc:normal_12.scale': 0.1, 'NumpyRandomFunc:normal_12.function_node_result': -18.97664317674292}
8 8 55.215060 -43.273217 19 61357.107281 0.199914
mjd filter ... obs_idx is_saturated
61335.342615 z ... 33635 False
+18 rows ... ... ... ...
{'pznode.RA_GAL': 55.22351837158203, 'pznode.DEC_GAL': -43.270076751708984, 'pznode.u_obs': 99.1616439819336, 'pznode.g_obs': 27.866424560546875, 'pznode.r_obs': 27.86051368713379, 'pznode.i_obs': 24.215261459350586, 'pznode.z_obs': 23.754379272460938, 'pznode.Y_obs': 22.937694549560547, 'pznode.LOGMASS': 9.123161315917969, 'pznode.LOG_SFR': -4.242527961730957, 'pznode.ZPHOT': 1.0032448768615723, 'pznode.ZTRUE': 0.9157136082649231, 'host.ra': 55.22351837158203, 'host.dec': -43.270076751708984, 'host.redshift': 0.19991351455882053, 'host.t0': None, 'host.distance': None, 'host.hostmass': 9.123161315917969, 'NumpyRandomFunc:uniform_4.low': 0.1, 'NumpyRandomFunc:uniform_4.high': 0.6, 'NumpyRandomFunc:uniform_4.function_node_result': 0.19991351455882053, 'NumpyRandomFunc:normal_1.loc': 55.22351837158203, 'NumpyRandomFunc:normal_1.scale': 0.01, 'NumpyRandomFunc:normal_1.function_node_result': 55.21505958962774, 'source.ra': 55.21505958962774, 'source.dec': -43.273217431230464, 'source.redshift': 0.19991351455882053, 'source.t0': 61357.10728125783, 'source.distance': None, 'source.theta': 0.8963599365333159, 'source.Av': 0.15158201761823478, 'source.Rv': 3.0, 'source.Amplitude': 5.979170185791111e-09, 'NumpyRandomFunc:normal_5.loc': -43.270076751708984, 'NumpyRandomFunc:normal_5.scale': 0.01, 'NumpyRandomFunc:normal_5.function_node_result': -43.273217431230464, 'NumpyRandomFunc:uniform_6.low': 61208.42731204634, 'NumpyRandomFunc:uniform_6.high': 64860.44487408427, 'NumpyRandomFunc:uniform_6.function_node_result': 61357.10728125783, 'NumpyRandomFunc:uniform_7.low': -1.74, 'NumpyRandomFunc:uniform_7.high': 2.1, 'NumpyRandomFunc:uniform_7.function_node_result': 0.8963599365333159, 'NumpyRandomFunc:uniform_8.low': 0.01, 'NumpyRandomFunc:uniform_8.high': 0.3, 'NumpyRandomFunc:uniform_8.function_node_result': 0.15158201761823478, 'NumpyRandomFunc:uniform_9.low': 3, 'NumpyRandomFunc:uniform_9.high': 3, 'NumpyRandomFunc:uniform_9.function_node_result': 3.0, 'DistModFromRedshift:_distmod_from_redshift_11.redshift': 0.19991351455882053, 'DistModFromRedshift:_distmod_from_redshift_11.function_node_result': 39.8641078103577, 'AmplitudeFromDistMod:_amplitude_given_distmod_10.distmod': 39.8641078103577, 'AmplitudeFromDistMod:_amplitude_given_distmod_10.m_abs': -19.30571009777917, 'AmplitudeFromDistMod:_amplitude_given_distmod_10.function_node_result': 5.979170185791111e-09, 'NumpyRandomFunc:normal_12.loc': -19.3, 'NumpyRandomFunc:normal_12.scale': 0.1, 'NumpyRandomFunc:normal_12.function_node_result': -19.30571009777917}
9 9 55.162162 -43.370029 0 63363.935186 0.390348 None {'pznode.RA_GAL': 55.1679573059082, 'pznode.DEC_GAL': -43.36502456665039, 'pznode.u_obs': 99.3812026977539, 'pznode.g_obs': 26.091419219970703, 'pznode.r_obs': 26.148996353149414, 'pznode.i_obs': 23.97878074645996, 'pznode.z_obs': 24.299236297607422, 'pznode.Y_obs': 23.068737030029297, 'pznode.LOGMASS': 9.164170265197754, 'pznode.LOG_SFR': -2.074599266052246, 'pznode.ZPHOT': 0.8532838821411133, 'pznode.ZTRUE': 0.798516571521759, 'host.ra': 55.1679573059082, 'host.dec': -43.36502456665039, 'host.redshift': 0.39034782482267383, 'host.t0': None, 'host.distance': None, 'host.hostmass': 9.164170265197754, 'NumpyRandomFunc:uniform_4.low': 0.1, 'NumpyRandomFunc:uniform_4.high': 0.6, 'NumpyRandomFunc:uniform_4.function_node_result': 0.39034782482267383, 'NumpyRandomFunc:normal_1.loc': 55.1679573059082, 'NumpyRandomFunc:normal_1.scale': 0.01, 'NumpyRandomFunc:normal_1.function_node_result': 55.1621622429012, 'source.ra': 55.1621622429012, 'source.dec': -43.37002925582934, 'source.redshift': 0.39034782482267383, 'source.t0': 63363.93518575111, 'source.distance': None, 'source.theta': 1.8738864705355547, 'source.Av': 0.15516886077075423, 'source.Rv': 3.0, 'source.Amplitude': 1.3330704450065095e-09, 'NumpyRandomFunc:normal_5.loc': -43.36502456665039, 'NumpyRandomFunc:normal_5.scale': 0.01, 'NumpyRandomFunc:normal_5.function_node_result': -43.37002925582934, 'NumpyRandomFunc:uniform_6.low': 61208.42731204634, 'NumpyRandomFunc:uniform_6.high': 64860.44487408427, 'NumpyRandomFunc:uniform_6.function_node_result': 63363.93518575111, 'NumpyRandomFunc:uniform_7.low': -1.74, 'NumpyRandomFunc:uniform_7.high': 2.1, 'NumpyRandomFunc:uniform_7.function_node_result': 1.8738864705355547, 'NumpyRandomFunc:uniform_8.low': 0.01, 'NumpyRandomFunc:uniform_8.high': 0.3, 'NumpyRandomFunc:uniform_8.function_node_result': 0.15516886077075423, 'NumpyRandomFunc:uniform_9.low': 3, 'NumpyRandomFunc:uniform_9.high': 3, 'NumpyRandomFunc:uniform_9.function_node_result': 3.0, 'DistModFromRedshift:_distmod_from_redshift_11.redshift': 0.39034782482267383, 'DistModFromRedshift:_distmod_from_redshift_11.function_node_result': 41.53079244250622, 'AmplitudeFromDistMod:_amplitude_given_distmod_10.distmod': 41.53079244250622, 'AmplitudeFromDistMod:_amplitude_given_distmod_10.m_abs': -19.342925192389774, 'AmplitudeFromDistMod:_amplitude_given_distmod_10.function_node_result': 1.3330704450065095e-09, 'NumpyRandomFunc:normal_12.loc': -19.3, 'NumpyRandomFunc:normal_12.scale': 0.1, 'NumpyRandomFunc:normal_12.function_node_result': -19.342925192389774}
10 rows x 8 columns

Now let’s plot some random light curves

[8]:
for idx in range(len(lightcurves)):
    # Extract the row for this object.
    lc = lightcurves.loc[idx]

    if lc["nobs"] > 0:
        # Unpack the nested columns (filters, mjd, flux, and flux error).
        lc_filters = np.asarray(lc["lightcurve"]["filter"], dtype=str)
        lc_mjd = np.asarray(lc["lightcurve"]["mjd"], dtype=float)
        lc_flux = np.asarray(lc["lightcurve"]["flux"], dtype=float)
        lc_fluxerr = np.asarray(lc["lightcurve"]["fluxerr"], dtype=float)

        plot_lightcurves(
            fluxes=lc_flux,
            times=lc_mjd,
            fluxerrs=lc_fluxerr,
            filters=lc_filters,
        )
../../_images/notebooks_pre_executed_bayeSN_example_14_0.png
../../_images/notebooks_pre_executed_bayeSN_example_14_1.png
../../_images/notebooks_pre_executed_bayeSN_example_14_2.png
../../_images/notebooks_pre_executed_bayeSN_example_14_3.png
../../_images/notebooks_pre_executed_bayeSN_example_14_4.png
../../_images/notebooks_pre_executed_bayeSN_example_14_5.png
../../_images/notebooks_pre_executed_bayeSN_example_14_6.png
../../_images/notebooks_pre_executed_bayeSN_example_14_7.png

We can also plot the light curves in magnitude

[9]:
lc_mag = -2.5 * np.log10(lc_flux) + 31.4
lc_magerr = np.absolute(1.086 * lc_fluxerr / lc_flux)

plot_lightcurves(
    fluxes=lc_mag,
    times=lc_mjd,
    fluxerrs=lc_magerr,
    filters=lc_filters,
)
plt.title(lc["z"])
plt.ylabel("Mag")
plt.ylim(plt.ylim()[::-1])
[9]:
(28.4051582657045, 20.59886978703065)
../../_images/notebooks_pre_executed_bayeSN_example_16_1.png