Skip to main content

Blending ToolKit

Project description

BlendingToolKit

tests notebooks docs codecov pre-commit PyPI

Summary

Framework for fast generation and analysis of galaxy blends catalogs. This toolkit is a convenient way of producing multi-band postage stamp images of blend scenes and evaluate the performance of deblending algorithms.

Documentation can be found at https://lsstdesc.org/BlendingToolKit/index.html.

Workflow

btk workflow

In red are components of the BTK pipeline that are intended to be easily customized by users to meet their science needs.

Code example

In what follows we illustrate how to use BTK to generate blended images, run a deblender on them, and evaluate the performance of the deblender using metrics. For more details on this example see our quick-start notebook at notebooks/00-quickstart.ipynb.

import btk

# setup CATSIM catalog
catalog_name = "../data/input_catalog.fits"
catalog = btk.catalog.CatsimCatalog.from_file(catalog_name)

# setup survey parameters
survey = btk.survey.get_surveys("LSST")

# setup sampling function
# this function determines how to organize galaxies in catalog into blends
stamp_size = 24.0
sampling_function = btk.sampling_functions.DefaultSampling(
    catalog=catalog, max_number=5, max_mag=25.3, stamp_size=stamp_size
)

# setup generator to create batches of blends
batch_size = 100
draw_generator = btk.draw_blends.CatsimGenerator(
    catalog, sampling_function, survey, batch_size
)

# get batch of blends
blend_batch = next(draw_generator)

# setup deblender (we use SEP in this case)
deblender = btk.deblend.SepSingleBand(max_n_sources=5,
                          use_band=2 # measure on 'r' band
                          )

# run deblender on generated blend images (all batches)
deblend_batch = deblender(blend_batch)

# setup matcher
matcher = btk.match.PixelHungarianMatcher(pixel_max_sep=5.0 # maximum separation in pixels for matching
)

# match true and predicted catalogs
truth_catalogs = blend_batch.catalog_list
pred_catalogs = deblend_batch.catalog_list
matching = matcher(truth_catalogs, pred_catalogs) # object with matching information

# compute detection performance on this batch
recall = btk.metrics.detection.Recall(batch_size)
precision = btk.metrics.detection.Precision(batch_size)
print("Recall: ", recall(matching.tp, matching.t, matching.p))
print("Precision: ", precision(matching.tp, matching.t, matching.p))

Installation

BTK is pip installable, with the following command:

pip install blending-toolkit

In case of any issues and for details of required packages, please see the more detailed installation instructions here.

Contributing

Everyone can contribute to this project, please refer to the CONTRIBUTING.md document for details.

In short, to interact with the project you can:

Issues marked with contributions welcome or good first issue are particularly good places to start. These are great ways to learn more about the inner workings of BTK.

Citing BTK

If you use this software for your research, please cite using the following bibtex entry:

@ARTICLE{mendoza2024btk,
       author = {{Mendoza}, Ismael and {Torchylo}, Andrii and {Sainrat}, Thomas and {Guinot}, Axel and {Boucaud}, Alexandre and {Paillassa}, Maxime and {Avestruz}, Camille and {Adari}, Prakruth and {Aubourg}, Eric and {Biswas}, Biswajit and {Buchanan}, James and {Burchat}, Patricia and {Doux}, Cyrille and {Joseph}, Remy and {Kamath}, Sowmya and {Malz}, Alex I. and {Merz}, Grant and {Miyatake}, Hironao and {Roucelle}, C{\'e}cile and {Zhang}, Tianqing and {the LSST Dark Energy Science Collaboration}},
        title = "{The Blending ToolKit: A simulation framework for evaluation of galaxy detection and deblending}",
      journal = {arXiv e-prints},
     keywords = {Astrophysics - Instrumentation and Methods for Astrophysics, Astrophysics - Cosmology and Nongalactic Astrophysics},
         year = 2024,
        month = sep,
          eid = {arXiv:2409.06986},
        pages = {arXiv:2409.06986},
          doi = {10.48550/arXiv.2409.06986},
archivePrefix = {arXiv},
       eprint = {2409.06986},
 primaryClass = {astro-ph.IM},
       adsurl = {https://ui.adsabs.harvard.edu/abs/2024arXiv240906986M},
      adsnote = {Provided by the SAO/NASA Astrophysics Data System}
}

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

blending_toolkit-1.0.6.tar.gz (44.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

blending_toolkit-1.0.6-py3-none-any.whl (43.0 kB view details)

Uploaded Python 3

File details

Details for the file blending_toolkit-1.0.6.tar.gz.

File metadata

  • Download URL: blending_toolkit-1.0.6.tar.gz
  • Upload date:
  • Size: 44.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for blending_toolkit-1.0.6.tar.gz
Algorithm Hash digest
SHA256 cd7de01027d257052a1d39ecea5100615fd5062dec8b899409b986712ccf95d2
MD5 7d6cb286d63cf853e9af866fc6aa69f3
BLAKE2b-256 ae2cdfe2858bbddfcaa5910b5c515ce6dbc2b4597d661776c06045e2a6fd6562

See more details on using hashes here.

Provenance

The following attestation bundles were made for blending_toolkit-1.0.6.tar.gz:

Publisher: publish.yml on LSSTDESC/BlendingToolKit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file blending_toolkit-1.0.6-py3-none-any.whl.

File metadata

File hashes

Hashes for blending_toolkit-1.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 4e5c73070ac7c8ef84e4e69e78998cc9157e480be8e77c58c5a2dca8e52870b5
MD5 2caeb90f2e30e0f6fb7ff56c97a5bae4
BLAKE2b-256 0ab0af535959f54a4a7207331ea8f3aebc84ee0de030ab7ba4dba3d0c96d5147

See more details on using hashes here.

Provenance

The following attestation bundles were made for blending_toolkit-1.0.6-py3-none-any.whl:

Publisher: publish.yml on LSSTDESC/BlendingToolKit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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