Skip to main content

pysersic logo featuring a spiral s-galaxy as the S status PyPi version GitHub release Documentation Status tests License

pysersic is a code for fitting sersic profiles to galaxy images using Bayesian Inference. It is written in python using jax with inference performed using numpyro. You can read more about the motivation for this software via the JOSS Paper.

Installation

pysersic now requies at least python version 3.9. To start you should have jax installed. The easiest way to do this is to use pip install 'jax[cpu]', however if you are on windows or planning on running it on a GPU, the installation can be a little more complicated, please see the guide here. The other package dependencies for pysersic are:

  • arviz
  • asdf
  • astropy
  • corner
  • matplotlib
  • numpy
  • numpyro
  • pandas
  • photutils
  • scipy
  • equinox
  • interpax
  • tqdm

Optional

  • jaxopt (only when using the pure minimization option).

There is a provided minimal environment.yml capturing the above in the base repo, as well as an environment-lock.yml which has a full set of versions specified for every dependency --- if you are having trouble with the installation, creating an environment using this file should ensure you have a single set of package versions that pysersic is known to work with. (We don't recommend using the lock yml in general, as pysersic should be kept up to date with new versions of its dependencies.)

Next you can install pysersic! To install the latest stable release, you can simply pip install via

pip install pysersic

If you would like the bleeding edge, development build (or would like to modify, add to, or otherwise access pysersic source files), you can also install from the github:

git clone https://github.com/pysersic/pysersic.git
cd pysersic
pip install -e .

Basic usage

All you need to run pysersic is a cutout of you galaxy of interest, and cutout of the error map, pixelized version of the PSF, and optionally a mask specifying bad pixels or nearby sources. The most basic setup is shown below for many many more details and in depth examples please see the documentation. First we set up a prior.

from pysersic.priors import SourceProperties

props = SourceProperties(img_cutout,mask=mask) # Optional mask
prior = props.generate_prior('sersic', # Other profiles inclues 'exp', 'dev' and 'pointsource'
                          sky_type='none') # Can also use 'flat' or 'tilted-plane' to simultaneously fit a background

Then we initialize the fitting object:

from pysersic import FitSingle
from pysersic.loss import gaussian_loss

fitter = FitSingle(data=img_cutout, # Cutout of galaxy 
                  rms=sig_cutout, # Cutout of pixel errors
                  psf=psf, #Point spread function
                  prior=prior, # Prior that we initialized above
                  mask=mask, #Optional mask
                  loss_func=gaussian_loss) # Can specify loss function! See loss.py for many options or write your own!

Now we can fit!

map_dict = fitter.find_MAP() # Find the 'best-fit' parameters as the maximum-a-posteriori. Returns a dictionary containing the MAP parameters and model image

svi_res = fitter.estimate_posterior('svi-flow') #Train a normalizing flow to estimate the posterior, retruns a PysersicResults object containing the posterior and other helper methods
nuts_res = fitter.sample() #Sample the posterior using the No U-turn sampler (NUTS), retruns a PysersicResults object

Test Suite

There is a growing set of tests that can be used to confirm the behavior of pysersic and its features is as expected. These tests run automatically on each pull request and merge. If you would like to run the tests yourself on your local machine, you can do so with the pytest package. Once installed, you can simply navigate to the tests directory and run:

pytest

Citation

If you use pysersic and find it useful, please do cite it. You can use the following BibTex.

@article{Pasha2023,
        doi = {10.21105/joss.05703},
        url = {https://doi.org/10.21105/joss.05703},
        year = {2023},
        publisher = {The Open Journal},
        volume = {8},
        number = {89},
        pages = {5703},
        author = {Imad Pasha and Tim B. Miller},
        title = {pysersic: A Python package for determining galaxy structural properties via Bayesian inference, accelerated with jax},
        journal = {Journal of Open Source Software} }

Metadata

Release files for pysersic 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pysersic 0.2.0
File Size Uploaded Provenance Actions
pysersic-0.2.0.tar.gz 48.5 kB Without provenance Details for pysersic-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pysersic 0.2.0
File Interpreter ABI Platform Actions
pysersic-0.2.0-py3-none-any.whl Python 3 none any Details for pysersic-0.2.0-py3-none-any.whl

Total release size: 92.9 kB

Release files / pysersic-0.2.0.tar.gz

Download URL pysersic-0.2.0.tar.gz
Size 48.5 kB
Tags Source
SHA-256 checksum
How to use checksums
a316046cb1d85fa695f710fe353a2b3512f425f1db5e836bbfc9c50d9b16eaaa
BLAKE2b-256 checksum
How to use checksums
447a7aaae341a307825b12bdd8256ef2de6d1368cfb8c8c1f6916ce1593c454a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.17

Release files / pysersic-0.2.0-py3-none-any.whl

Download URL pysersic-0.2.0-py3-none-any.whl
Size 44.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
52959ae121a8b8140f8272c24f9b9639b94bf6ab8d8ada775af70f866f5310a1
BLAKE2b-256 checksum
How to use checksums
aca78ca0424d1eba100d945d348d82b51079b3f576b31664fdcf8a4d7fdb9d6a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.17

Security for pysersic 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page