Skip to main content

Kilonova surrogate modelling via cVAE

Project description

KilonovaNet: Kilonova Surrogate Modelling

A conditional variational autoencoder (cVAE) framework for producing continuous surrogate spectra for kilonova models.

This package provides the interface to predict spectra. It does not provide an interface to do the data prep for training and training itself. The currently trained and provided models are:

This work requires the use of pyphot and therefore there are a number of dependencies that are needed to just get pyphot working, i.e. astropy, pytables, etc. My environment.yml for conda environments should handle those but you will need to install pyphot before using this work.

Installation

Install from source: download and run python setup.py install.

Install via pip: pip install kilonovanet

Usage

In order to produce surrogate spectra (see eventual paper for discussion about how good these spectra are or are not, though), use:

import kilonovanet
import numpy as np

metadata_file = "data/metadata_bulla_bns.json"
torch_file = "models/bulla-bns-latent-20-hidden-1000-CV-4-2021-04-21-epoch-200.pt"
times = np.array([1.2, 2.2])
physical_parameters = np.array([1.0e-2, 9.0e-2, 3.0e1, 3.0e-1])

model = kilonovanet.Model(metadata_file, torch_file)
spectra = model.predict_spectra(physical_parameters, times)

In order to produce some photometric observations, the following have to be specified:

  • the model
  • the corresponding parameters of the model (see their papers, repositories, etc.)
  • the times post-merger to produce the observations
  • the filters in which to produce the observations

The general use is then as follows:

import kilonovanet
import numpy as np
 
metadata_file = "data/metadata_bulla_bns.json"
torch_file = "models/bulla-bns-latent-20-hidden-1000-CV-4-2021-04-21-epoch-200.pt"
filter_lib = "data/filter_data"

times = np.array([1.2, 1.2, 1.2, 2.2, 2.2, 2.2, 2.2])
filters = np.array(["LSST_u", "LSST_z", "LSST_y", "LSST_u", "LSST_z", "LSST_y"])
distance = 40.0 * 10 ** 6 * 3.086e18 # 40 Mpc in cm
physical_parameters = np.array([1.0e-2, 9.0e-2, 3.0e1, 3.0e-1])

model = kilonovanet.Model(metadata_file, torch_file, filter_library_path=filter_lib)
mags = model.predict_magnitudes(physical_parameters, times=times, filters=filters,
distance=distance)

If you intend to use the same set of observations often, e.g. when doing an MCMC-based fit, you can specify all of them in an Observations object and then simply call model.predict_magnitudes(physical_parameters).

Warnings

  • All specified model parameter values have to lie within the ranges of the original radiative transport simulations! This code will not throw errors if you do not do this but will instead return nonsense results, so be mindful to read their papers.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kilonovanet-0.1.0.tar.gz (6.4 kB view hashes)

Uploaded Source

Built Distribution

kilonovanet-0.1.0-py3-none-any.whl (7.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page