Skip to main content

Blending ToolKit

Project description

BlendingToolKit

tests notebooks docs codecov Code style: black 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, stamp_size
)

# get batch of blends
blend_batch = next(draw_generator)

# setup deblender (we use SEP in this case)
deblender = 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 = 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.detected, matching.matched))
print("Precision: ", precision(matching.detected, matching.matched))

Installation

BTK is pip installable, with the following command:

pip install blending-toolkit==1.0.0b2

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

Contributing

See our contributing guidelines at CONTRIBUTING.md

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.0b2.tar.gz (35.9 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.0b2-py3-none-any.whl (41.5 kB view details)

Uploaded Python 3

File details

Details for the file blending_toolkit-1.0.0b2.tar.gz.

File metadata

  • Download URL: blending_toolkit-1.0.0b2.tar.gz
  • Upload date:
  • Size: 35.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.10.12 Linux/5.15.0-1042-azure

File hashes

Hashes for blending_toolkit-1.0.0b2.tar.gz
Algorithm Hash digest
SHA256 34c4cfb5cff341131009c0d27ef6bde881931825e88b50dee8f5a96b7127d1ba
MD5 804df430dfb65079190b9d9d9b40d02f
BLAKE2b-256 4f58c51eb0049e65d583d21ed44446a3c7f8e567395427649635872677760b84

See more details on using hashes here.

File details

Details for the file blending_toolkit-1.0.0b2-py3-none-any.whl.

File metadata

  • Download URL: blending_toolkit-1.0.0b2-py3-none-any.whl
  • Upload date:
  • Size: 41.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.10.12 Linux/5.15.0-1042-azure

File hashes

Hashes for blending_toolkit-1.0.0b2-py3-none-any.whl
Algorithm Hash digest
SHA256 f7e5964c76139ac6e3ef8dd64915675eca84271658b6fb1f8ce4760a3cd22fd0
MD5 04b263e6650059776e2adbe48278333e
BLAKE2b-256 8f4f4e387a34912d2d6c30b4cbd895a92b9363f42415cb7263083713de98f1c3

See more details on using hashes here.

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