btk.draw_blends module

The draw_blends module defines the DrawBlendsGenerator class, which is used for generating blended stamps. It also features implementations of this class for Catsim and COSMOS.

A custom class may be created by an experienced user to modify the way blends are rendered; we advise to modify only the render_single() method if possible.

Module for generating batches of drawn blended images.

class btk.draw_blends.CatsimGenerator(catalog: Catalog, sampling_function: SamplingFunction, surveys: List[Survey] | Survey, batch_size: int = 8, stamp_size: float = 24.0, njobs: int = 1, verbose: bool = False, use_bar: bool = False, add_noise: str = 'all', seed: int = 0, apply_shear: bool = False, augment_data: bool = False)

Bases: DrawBlendsGenerator

Implementation of DrawBlendsGenerator for drawing galaxies from a Catsim-like catalog.

The code for drawing these galaxies and the default PSF is taken almost directly from WeakLensingDeblending (https://github.com/LSSTDESC/WeakLensingDeblending).

compatible_catalogs = ('CatsimCatalog',)
render_single(entry: Catalog, filt: Filter, psf: GSObject, survey: Survey)

Returns the Galsim Image of an isolated galaxy.

class btk.draw_blends.CosmosGenerator(catalog: CosmosCatalog, sampling_function: SamplingFunction, surveys: List[Survey], batch_size: int = 8, stamp_size: float = 24.0, njobs: int = 1, verbose: bool = False, add_noise: str = 'all', seed: int = 0, use_bar: bool = False, apply_shear: bool = False, augment_data: bool = False, gal_type: str = 'real', noise_pad_size: float = 0)

Bases: DrawBlendsGenerator

Subclass of DrawBlendsGenerator for drawing galaxies from the COSMOS catalog.

__init__(catalog: CosmosCatalog, sampling_function: SamplingFunction, surveys: List[Survey], batch_size: int = 8, stamp_size: float = 24.0, njobs: int = 1, verbose: bool = False, add_noise: str = 'all', seed: int = 0, use_bar: bool = False, apply_shear: bool = False, augment_data: bool = False, gal_type: str = 'real', noise_pad_size: float = 0)

Initializes the CosmosGenerator class. See parent class for most attributes.

Parameters:
  • catalog – See parent class.

  • sampling_function – See parent class.

  • surveys – See parent class.

  • batch_size – See parent class.

  • stamp_size – See parent class.

  • njobs – See parent class.

  • verbose – See parent class.

  • add_noise – See parent class.

  • seed – See parent class.

  • use_bar – See parent class.

  • apply_shear – See parent class.

  • augment_data – See parent class.

  • gal_type – string to specify the type of galaxy simulations. Either “real” (default) or “parametric”.

  • noise_pad_size – For realistic galaxies, the size of region to pad with noise for each individual galaxy before forming the blend. This is the argument to the COSMOSCatalog.makeGalaxy function inside galsim. In BTK, we add noise after the blend is produced according to the sky_level, so the default for this argument is 0, as otherwise, noise would be added to the image twice.

compatible_catalogs = ('CosmosCatalog',)
render_single(entry: Table, filt: Filter, psf: GSObject, survey: Survey)

Returns the Galsim Image of an isolated galaxy.

class btk.draw_blends.DrawBlendsGenerator(catalog: Catalog, sampling_function: SamplingFunction, surveys: List[Survey] | Survey, batch_size: int = 8, stamp_size: float = 24.0, njobs: int = 1, verbose: bool = False, use_bar: bool = False, add_noise: str = 'all', seed: int = 0, apply_shear: bool = False, augment_data: bool = False)

Bases: ABC

Class that generates images of blends and individual isolated objects in batches.

Batch is divided into ‘mini-batches’ of size batch_size//njobs and each mini-batch analyzed separately. The results are then combined to output a dict with results of entire batch. If the number of njobs is greater than one, then each of the mini-batches are run in parallel.

__init__(catalog: Catalog, sampling_function: SamplingFunction, surveys: List[Survey] | Survey, batch_size: int = 8, stamp_size: float = 24.0, njobs: int = 1, verbose: bool = False, use_bar: bool = False, add_noise: str = 'all', seed: int = 0, apply_shear: bool = False, augment_data: bool = False)

Initializes the DrawBlendsGenerator class.

Parameters:
  • catalog – BTK catalog object from which galaxies are taken.

  • sampling_function – BTK sampling function to use.

  • surveys – List of BTK Survey objects or single BTK Survey object.

  • batch_size – Number of blends generated per batch

  • stamp_size – Size of the stamps, in arcseconds

  • njobs – Number of njobs to use; defines the number of minibatches

  • verbose – Indicates whether additionnal information should be printed

  • use_bar – Whether to use progress bar (default: False)

  • add_noise – Indicates if the blends should be generated with noise. “all” indicates that all the noise should be applied, “background” adds only the background noise, “galaxy” only the galaxy noise, and “none” gives noiseless images.

  • seed – Integer seed for reproducible random noise realizations.

  • apply_shear – Whether to apply the shear specified in catalogs to galaxies. If set to True, sampling function must add ‘g1’, ‘g2’ columns.

  • augment_data – If set to True, augment data by adding a random rotation to every galaxy drawn. Rotation added is stored in the btk_rotation column.

compatible_catalogs = ('Catalog',)
render_blend(blend_catalog: Table, psf: GSObject, filt: Filter, survey: Survey, seedseq_blend: SeedSequence) Tuple[ndarray, ndarray]

Draws image of isolated galaxies along with the blend image in the single input band.

The WLDeblending package (descwl) renders galaxies corresponding to the blend_catalog entries and with observing conditions determined by cutout. The rendered objects are stored in the observing conditions class. So as to not overwrite images across different blends, we make a copy of the cutout while drawing each galaxy. Images of isolated galaxies are drawn with the WLDeblending and them summed to produce the blend image.

A column ‘not_drawn_{band}’ is added to blend_catalog initialized as zero. If a galaxy was not drawn by descwl, then this flag is set to 1.

Parameters:
  • blend_catalog – Catalog with entries corresponding to one blend.

  • psf – Galsim object containing the psf for the given filter

  • filt – BTK Filter object

  • survey – BTK Survey object

  • seedseq_blend – Seed sequence for the noise generation.

Returns:

Images of blend and isolated galaxies as numpy.ndarray.

abstract render_single(entry: Table, filt: Filter, psf: GSObject, survey: Survey)

Renders single galaxy in single band in the location given by its entry.

The image created must be in a stamp of size stamp_size / cutout.pixel_scale. The image must be drawn according to information provided by filter, psf, and survey.

Parameters:
  • entry – Line from astropy describing the galaxy to draw

  • filt – BTK Filter object corresponding to the band where the image is drawn.

  • psf – Galsim object containing the PSF relative to the chosen filter

  • survey – BTK Survey object

Returns:

galsim.Image object

exception btk.draw_blends.SourceNotVisible

Bases: Exception

Custom exception to indicate that a source has no visible model components.

btk.draw_blends.get_catsim_galaxy(entry: Table, filt: Filter, survey: Survey, no_disk: bool = False, no_bulge: bool = False, no_agn: bool = False)

Returns a bulge/disk/agn Galsim galaxy profile based on entry.

This function returns a composite galsim galaxy profile with bulge, disk and AGN based on the parameters in entry, and using observing conditions defined by the survey and the filter.

Credit: WeakLensingDeblending (https://github.com/LSSTDESC/WeakLensingDeblending)

Parameters:
  • entry – single astropy line containing information on the galaxy

  • filt – BTK Filter object

  • survey – BTK Survey object

  • no_disk – Sets the flux for the disk to zero

  • no_bulge – Sets the flux for the bulge to zero

  • no_agn – Sets the flux for the AGN to zero

Returns:

Galsim galaxy profile

Return type:

galsim.GSObject

btk.draw_blends.render_single_catsim_galaxy(entry: Table, filt: Filter, survey: Survey, psf: GSObject, slen: int, apply_shear: bool = False)

Render an image of a single galsim galaxy from a CATSIM entry.