scarlet2 Documentation#

scarlet2 is an open-source python library for modeling astronomical sources from multi-band, multi-epoch, and multi-instrument data. It provides non-parametric and parametric models, can handle source overlap (aka blending), and can integrate neural network priors. It’s designed to be modular, flexible, and powerful.

scarlet2 is implemented in jax, layered on top of the equinox library. It can be deployed to GPUs and TPUs and supports optimization and sampling approaches.

Installation#

For performance reasons, you should first install jax with the suitable jaxlib for your platform. After that

pip install scarlet2

should do. If you want the latest development version, use

pip install git+https://github.com/pmelchior/scarlet2.git

This will allow you to evaluate source models and compute likelihoods of observed data, so you can run your own optimizer/sampler. If you want a fully fledged library out of the box, you need to install optax, numpyro, and h5py as well.

Usage#

Differences between scarlet and scarlet2#

scarlet was introduced by Melchior et al. (2018) to solve the deblending problem for the Rubin Observatory. A stripped down version of it (developed by Fred Moolekamp) runs as part of the Rubin Observatory software stack and is used for their data releases. We now call this version scarlet1.

scarlet2 follows very similar concepts. So, what’s different?

Model specification#

scarlet1 is designed for a specific purpose: deblending for the Rubin Observatory. That has implications for the quality and type of data it needs to work with. scarlet2 is much more flexible to handle complex sources configurations, e.g. strong-lensing systems, supernova host galaxies, transient sources, etc.

This flexibility led us to carefully design a “language” to construct sources. It allows new source combinations and is more explicit about the parameters and their initialization.

Compute#

Because some of the constraints in scarlet1 are expensive to evaluate, they are implemented in C++, which requires the installation of a lot of additional code just to get it to run. scarlet2 is implemented entirely in jax. A combination of conda and pip will get it installed. Unlike scarlet1, it will also run on GPUs and TPUs, and performs just-in-time compilation of the model evaluation.

In addition, we can now interface with deep learning methods. In particular, we can employ neural networks as data-driven priors, which helps break the degeneracies that arise when multiple components need to be fit at the same time.

Constraints#

scarlet1 uses constrained optimization to help with fitting degeneracies, but that requires non-standard (namely proximal) optimization because these constraints are not differentiable. That can lead to problems with calibration, but, more importantly, it prevents the use of gradient-based optimization or sampling. As a result, we could never calculate errors for scarlet1 models. scarlet2 uses only constraints that can be differentiated. It supports any continuous optimization or sampling method, including error estimates.

Ideas, Questions or Problems?#

If you have any of those, head over to our github repo and create an issue. For other ways to contribute, check out our contributing guide.