BlendingToolKit
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
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:
- Ask or Answer questions on the Discussions Q&A page.
- Report a bug by opening a GitHub issue.
- Open a GitHub issue or Discussions to ask for feedback on a planned contribution.
- Submit a Pull Request to contribute to the code.
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{article,
author = {Mendoza, Ismael and Torchylo, Andrii and Sainrat, Thomas and Guinot, Axel and Boucaud, Alexandre and Paillasa, 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 and Merz, Grant and Miyatake, Hironao and Roucelle, Cécile and Zhang, Tianqing},
year = {2025},
month = {02},
pages = {},
title = {The Blending ToolKit: A simulation framework for evaluation of galaxy detection and deblending},
volume = {8},
journal = {The Open Journal of Astrophysics},
doi = {10.33232/001c.129699}
}
Metadata
Release files for blending-toolkit 1.0.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| blending_toolkit-1.0.9.tar.gz | 47.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| blending_toolkit-1.0.9-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 95.1 kB
Release files / blending_toolkit-1.0.9.tar.gz
| Download URL | blending_toolkit-1.0.9.tar.gz |
|---|---|
| Size | 47.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b70599b41a0533fb2d143cc71037588003502b1075177400063c5a074cdfc8e2
|
|
BLAKE2b-256 checksum How to use checksums |
8257e46562765aa4118a8e8d29af386d2ada6f6e26145096df205c7b0b71f55b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 29, 2025.
Transparency logRelease files / blending_toolkit-1.0.9-py3-none-any.whl
| Download URL | blending_toolkit-1.0.9-py3-none-any.whl |
|---|---|
| Size | 48.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dae5f804978b2617a7a230636fc5eae0147828b6cc71a67bac90f5659b9d2b26
|
|
BLAKE2b-256 checksum How to use checksums |
dcc6843055f4054db1eef49bd8ed2f190a823a7ef44bee22593d1fd7270b9cd4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 29, 2025.
Transparency log