bliss package

BLISS is organized into several subpackages:

  • Core modules: Entry points, catalogs, datasets, and utilities

  • Encoder: Neural network architecture for posterior estimation

  • Simulator: Image generation and prior distributions

  • Surveys: Survey-specific data loaders (SDSS, DES, DC2)

Core Modules

bliss.main module

The main entry point for BLISS workflows: data generation, training, and prediction.

bliss.main.main(cfg)[source]

Main entry point(s) for BLISS.

bliss.catalog module

Tile and full catalog data structures for representing light source parameters.

class bliss.catalog.BaseTileCatalog(d: Dict[str, Tensor])[source]
class bliss.catalog.FullCatalog(height: int, width: int, d: Dict[str, Tensor])[source]
apply_param_bin(pname: str, p_min: float, p_max: float)[source]

Apply magnitude bin to given parameters.

classmethod from_dict(height: int, width: int, d: Dict[str, Tensor]) FullCatalog[source]

Create FullCatalog from unbatched dict by adding batch dimension.

classmethod from_file(cat_path, wcs, height, width, **kwargs) FullCatalog[source]

Loads FullCatalog from disk.

one_source(b: int, s: int)[source]

Return a dict containing all parameter for one specified light source.

static plocs_from_ra_dec(ras, decs, wcs: WCS)[source]

Converts RA/DEC coordinates into BLISS’s pixel coordinates.

BLISS pixel coordinates have (0, 0) as the lower-left corner, whereas standard pixel coordinates begin at (-0.5, -0.5). BLISS pixel coordinates are in row-column order, whereas standard pixel coordinates are in column-row order.

Parameters:
  • ras (Tensor) – (b, n) tensor of RA coordinates in degrees.

  • decs (Tensor) – (b, n) tensor of DEC coordinates in degrees.

  • wcs (WCS) – WCS object to use for transformation.

Returns:

A 1xNx2 tensor containing the locations of the light sources in pixel coordinates. This function does not write self[“plocs”], so you should do that manually if necessary.

to_dict() Dict[str, Tensor][source]

Convert to unbatched dict by removing batch dimension.

to_tile_catalog(tile_slen: int, max_sources_per_tile: int, *, ignore_extra_sources=False, filter_oob=False, stable=True, inter_int_type=torch.int32) TileCatalog[source]

Returns the TileCatalog corresponding to this FullCatalog.

Parameters:
  • tile_slen – The side length of the tiles.

  • max_sources_per_tile – The maximum number of sources in one tile.

  • ignore_extra_sources – If False (default), raises an error if the number of sources in one tile exceeds the max_sources_per_tile. If True, only adds the tile parameters of the first max_sources_per_tile sources to the new TileCatalog.

  • filter_oob – If filter_oob is True (default is False), filter out the sources outside the image. (e.g. In case of data augmentation, there is a chance of some sources located outside the image)

  • stable – It stable is True (default), on tiles with more than one sources, the sources will be arranged in a stable order. Some speedup can be gained if you disable this tag.

  • inter_int_type – The dtype for the tensors counting the sources per tile. Default is torch.int32, and you can change it to torch.int8 to get speedup. But the overflow may happen without any warning.

Returns:

TileCatalog correspond to the each source in the FullCatalog.

Raises:
  • ValueError – If the number of sources in one tile exceeds max_sources_per_tile and ignore_extra_sources is False.

  • KeyError – If the tile_params contain plocs or n_sources.

class bliss.catalog.SourceType(*values)[source]
class bliss.catalog.TileCatalog(d: Dict[str, Tensor])[source]
filter_by_flux(min_flux=0, band=2)[source]

Restricts TileCatalog to sources that have a flux between min_flux and max_flux.

Parameters:
  • min_flux (float) – Minimum flux value to keep. Defaults to 0.

  • band (int) – The band to compare fluxes in. Defaults to 2 (r-band).

Returns:

a new catalog with only sources within the flux range. Note that the size

of the tensors stays the same, but params at sources outside the range are set to 0.

Return type:

TileCatalog

classmethod from_dict(d: Dict[str, Tensor]) TileCatalog[source]

Create TileCatalog from unbatched dict by adding batch dimension.

get_brightest_sources_per_tile(top_k=1, exclude_num=0, band=2)[source]

Restrict TileCatalog to only the brightest ‘on’ source per tile.

Parameters:
  • top_k (int) – The number of sources to keep per tile. Defaults to 1.

  • exclude_num (int) – A number of the brightest sources to exclude. Defaults to 0.

  • band (int) – The band to compare fluxes in. Defaults to 2 (r-band).

Returns:

a new catalog with only one source per tile

Return type:

TileCatalog

get_indices_of_on_sources() Tuple[Tensor, Tensor][source]

Get the indices of detected sources from each tile.

Returns:

A 2-D tensor of integers with shape n_samples x max(n_sources), where max(n_sources) is the maximum number of sources detected across all samples.

Each element of this tensor is an index of a particular source within a particular tile. For a particular sample i that had N detections, the first N indices of indices_sorted[i. :] will be the detected sources. This is accomplished by flattening the n_tiles_per_image and max_detections. For example, if we had 3 tiles with a maximum of two sources each, the elements of this tensor would take values from 0 up to and including 5.

property is_on_mask: Tensor

Provides tensor which indicates how many sources are present for each batch.

Return a boolean array of shape=(*n_sources.shape, max_sources) whose (*,l)th entry indicates whether there are more than l sources on the *th index.

Returns:

Tensor indicating how many sources are present for each batch.

to_dict() Dict[str, Tensor][source]

Convert to unbatched dict by removing batch dimension.

to_full_catalog(tile_slen)[source]

Converts image parameters in tiles to parameters of full image.

Parameters:

tile_slen – The side length of the square tiles (in pixels).

Returns:

The FullCatalog instance corresponding to the TileCatalog instance.

NOTE: The locations (“locs”) are between 0 and 1. The output also contains pixel locations (“plocs”) that are between 0 and slen.

union(other, disjoint=False)[source]

Returns a new TileCatalog containing the union of the sources in self and other.

The maximum number of sources in the returned catalog is the sum of the maximum number of sources in self and other if disjoint is false, otherwise it is unchanged.

Parameters:
  • other – Another TileCatalog.

  • disjoint – whether the catalogs cannot have sources in the same tiles

Returns:

A new TileCatalog containing the union of the sources in self and other.

bliss.catalog.convert_flux_to_magnitude(flux, zero_point)[source]

Convert from flux to magnitude.

For DC2, please set c to 3631e9. The conversion is described in “2.10 AB magnitudes” at https://pstn-001.lsst.io/fluxunits.pdf

Parameters:
  • flux – the flux in any linear unit

  • zero_point – you may change this according to your survey dataset;

Returns:

Tensor indicating fluxes in magnitude

bliss.cached_dataset module

Dataset classes for loading cached simulated or survey data.

class bliss.cached_dataset.CachedSimulatedDataModule(splits: str, batch_size: int, num_workers: int, cached_data_path: str, train_transforms: List, nontrain_transforms: List, subset_fraction: float = None, shuffle_file_order: bool = True)[source]
predict_dataloader()[source]

An iterable or collection of iterables specifying prediction samples.

For more information about multiple dataloaders, see this section.

It’s recommended that all data downloads and preparation happen in prepare_data().

Note

Lightning tries to add the correct sampler for distributed and arbitrary hardware There is no need to set it yourself.

Returns:

A torch.utils.data.DataLoader or a sequence of them specifying prediction samples.

setup(stage: str) None[source]

Called at the beginning of fit (train + validate), validate, test, or predict. This is a good hook when you need to build models dynamically or adjust something about them. This hook is called on every process when using DDP.

Parameters:

stage – either 'fit', 'validate', 'test', or 'predict'

Example:

class LitModel(...):
    def __init__(self):
        self.l1 = None

    def prepare_data(self):
        download_data()
        tokenize()

        # don't do this
        self.something = else

    def setup(self, stage):
        data = load_data(...)
        self.l1 = nn.Linear(28, data.num_classes)
test_dataloader()[source]

An iterable or collection of iterables specifying test samples.

For more information about multiple dataloaders, see this section.

For data processing use the following pattern:

  • download in prepare_data()

  • process and split in setup()

However, the above are only necessary for distributed processing.

Warning

do not assign state in prepare_data

Note

Lightning tries to add the correct sampler for distributed and arbitrary hardware. There is no need to set it yourself.

Note

If you don’t need a test dataset and a test_step(), you don’t need to implement this method.

train_dataloader()[source]

An iterable or collection of iterables specifying training samples.

For more information about multiple dataloaders, see this section.

The dataloader you return will not be reloaded unless you set :paramref:`~pytorch_lightning.trainer.trainer.Trainer.reload_dataloaders_every_n_epochs` to a positive integer.

For data processing use the following pattern:

  • download in prepare_data()

  • process and split in setup()

However, the above are only necessary for distributed processing.

Warning

do not assign state in prepare_data

Note

Lightning tries to add the correct sampler for distributed and arbitrary hardware. There is no need to set it yourself.

val_dataloader()[source]

An iterable or collection of iterables specifying validation samples.

For more information about multiple dataloaders, see this section.

The dataloader you return will not be reloaded unless you set :paramref:`~pytorch_lightning.trainer.trainer.Trainer.reload_dataloaders_every_n_epochs` to a positive integer.

It’s recommended that all data downloads and preparation happen in prepare_data().

  • fit()

  • validate()

  • prepare_data()

  • setup()

Note

Lightning tries to add the correct sampler for distributed and arbitrary hardware There is no need to set it yourself.

Note

If you don’t need a validation dataset and a validation_step(), you don’t need to implement this method.

class bliss.cached_dataset.ChunkingDataset(file_paths, shuffle=False, transform=None)[source]
class bliss.cached_dataset.ChunkingSampler(dataset: Dataset)[source]
class bliss.cached_dataset.DistributedChunkingSampler(dataset: Dataset, num_replicas: int | None = None, rank: int | None = None, shuffle: bool = False, seed: int = 0, drop_last: bool = False)[source]
class bliss.cached_dataset.FluxFilterTransform(reference_band, min_flux)[source]
class bliss.cached_dataset.FullCatalogToTileTransform(tile_slen, max_sources, filter_oob=False)[source]
class bliss.cached_dataset.OneBandTransform(band_idx)[source]

bliss.align module

Image alignment utilities for multi-band reprojection.

bliss.align.align(img: ndarray, wcs_list, ref_band: int, ref_depth: int = 0) ndarray[source]

Reproject images based on some reference WCS for pixel alignment.

Parameters:
  • img – 4D array of shape (coadd_depth, n_bands, h, w)

  • wcs_list – list of lists, wcs_list[d][b] is the WCS for depth d, band b

  • ref_band – reference band for alignment

  • ref_depth – reference depth for alignment

Returns:

Reprojected images as 4D array of shape (coadd_depth, n_bands, h, w)

bliss.data_augmentation module

Data augmentation transforms for training.

class bliss.data_augmentation.RandomShiftTransform(tile_slen, max_sources_per_tile)[source]
class bliss.data_augmentation.RotateFlipTransform(*args, **kwargs)[source]

bliss.global_env module

Global environment variables for distributed training.

Encoder Package

Neural network components for variational inference.

bliss.encoder.encoder module

Main Encoder class implementing the neural posterior estimator.

class bliss.encoder.encoder.Encoder(survey_bands: list, tile_slen: int, image_normalizers: dict, var_dist: VariationalDist, matcher: CatalogMatcher, sample_image_renders: MetricCollection, mode_metrics: MetricCollection, sample_metrics: MetricCollection | None = None, optimizer_params: dict | None = None, scheduler_params: dict | None = None, use_double_detect: bool = False, use_checkerboard: bool = True, n_sampler_colors: int = 4, reference_band: int = 2, predict_mode_not_samples: bool = True, minimalist_conditioning: bool = False, any_order_training: bool = True)[source]

Encodes the distribution of a latent variable representing an astronomical image.

This class implements the source encoder, which is supposed to take in an astronomical image of size slen * slen and returns a NN latent variable representation of this image.

configure_optimizers()[source]

Configure optimizers for training (pytorch lightning).

on_fit_start()[source]

Called at the very beginning of fit.

If on DDP it is called on every process

on_test_epoch_end()[source]

Called in the test loop at the very end of the epoch.

on_train_epoch_start()[source]

Called in the training loop at the very beginning of the epoch.

on_validation_epoch_end()[source]

Called in the validation loop at the very end of the epoch.

predict_step(batch, batch_idx, dataloader_idx=0)[source]

Pytorch lightning method.

test_step(batch, batch_idx)[source]

Pytorch lightning method.

training_step(batch, batch_idx)[source]

Training step (pytorch lightning).

validation_step(batch, batch_idx)[source]

Pytorch lightning method.

bliss.encoder.variational_dist module

Variational distribution factors for different latent variables.

class bliss.encoder.variational_dist.DiscretizedUnitBox(logits)[source]

A continuous bivariate distribution over the 2d unit box, with a discretized density.

log_prob(value)[source]

Returns the log of the probability density/mass function evaluated at value.

Parameters:

value (Tensor)

property mode

Returns the mode of the distribution.

sample(sample_shape=())[source]

Generates a sample_shape shaped sample or sample_shape shaped batch of samples if the distribution parameters are batched.

class bliss.encoder.variational_dist.GalaxyGating[source]
class bliss.encoder.variational_dist.LogNormalEpsilon(loc: Tensor | float, scale: Tensor | float, validate_args: bool | None = None)[source]
log_prob(value)[source]

Scores the sample by inverting the transform(s) and computing the score using the score of the base distribution and the log abs det jacobian.

sample(sample_shape=())[source]

Generates a sample_shape shaped sample or sample_shape shaped batch of samples if the distribution parameters are batched. Samples first from base distribution and applies transform() for every transform in the list.

class bliss.encoder.variational_dist.NllGating[source]
class bliss.encoder.variational_dist.NullGating[source]
class bliss.encoder.variational_dist.RescaledLogitNormal(mu, sigma, low=0, high=1)[source]
log_prob(value)[source]

Returns the log of the probability density/mass function evaluated at value.

Parameters:

value (Tensor)

property mode

Returns the mode of the distribution.

sample()[source]

Generates a sample_shape shaped sample or sample_shape shaped batch of samples if the distribution parameters are batched.

class bliss.encoder.variational_dist.SourcesGating[source]
class bliss.encoder.variational_dist.StarGating[source]
class bliss.encoder.variational_dist.TDBNFactor(*args, low_clamp=-6, high_clamp=3, **kwargs)[source]

Produces truncated bivariate normal distributions from unconstrained parameters.

class bliss.encoder.variational_dist.TruncatedDiagonalMVN(mu, sigma)[source]

A truncated diagonal multivariate normal distribution.

property batch_shape

Returns the shape over which parameters are batched.

cdf(value)[source]

Returns the cumulative density/mass function evaluated at value.

Parameters:

value (Tensor)

property event_shape

Returns the shape of a single sample (without batching).

log_prob(value)[source]

Returns the log of the probability density/mass function evaluated at value.

Parameters:

value (Tensor)

property mean

Returns the mean of the distribution.

property mode

Returns the mode of the distribution.

sample(sample_shape=())[source]

Generate sample.

Parameters:

sample_shape (Tuple) – Shape of samples to draw

Returns:

(sample_shape, self.batch_shape, self.event_shape) shaped sample

Return type:

Tensor

property stddev

Returns the standard deviation of the distribution.

class bliss.encoder.variational_dist.VariationalDist(factors, tile_slen)[source]

bliss.encoder.metrics module

Evaluation metrics for detection, classification, and flux estimation.

class bliss.encoder.metrics.CatFilter[source]
abstractmethod get_cur_filter_bools(true_cat, est_cat)[source]

Get filter bools.

abstractmethod get_cur_postfix()[source]

Get postfix for the output metric name.

class bliss.encoder.metrics.DetectionPerformance(base_flux_bin_cutoffs: list = None, mag_zero_point: int = None, ref_band: int = 2, report_bin_unit: str = 'flux', exclude_last_bin: bool = False, filter_list: List[CatFilter] = None)[source]
compute()[source]

Override this method to compute the final metric value.

This method will automatically synchronize state variables when running in distributed backend.

update(true_cat, est_cat, matching)[source]

Override this method to update the state variables of your metric class.

class bliss.encoder.metrics.FluxBinMetric(base_flux_bin_cutoffs: list, mag_zero_point: int, report_bin_unit: str, exclude_last_bin: bool)[source]
class bliss.encoder.metrics.FluxBinMetricWithFilter(base_flux_bin_cutoffs: list, mag_zero_point: int, report_bin_unit: str, exclude_last_bin: bool, filter_list: List[CatFilter])[source]
class bliss.encoder.metrics.FluxError(survey_bands, base_flux_bin_cutoffs: list, mag_zero_point: int, ref_band: int = 2, report_bin_unit: str = 'mag', exclude_last_bin: bool = False)[source]
compute()[source]

Override this method to compute the final metric value.

This method will automatically synchronize state variables when running in distributed backend.

update(true_cat, est_cat, matching)[source]

Override this method to update the state variables of your metric class.

class bliss.encoder.metrics.GalaxyShapeError(base_flux_bin_cutoffs, mag_zero_point: int, ref_band=2, report_bin_unit='mag', exclude_last_bin=False)[source]
compute()[source]

Override this method to compute the final metric value.

This method will automatically synchronize state variables when running in distributed backend.

update(true_cat, est_cat, matching)[source]

Override this method to update the state variables of your metric class.

class bliss.encoder.metrics.GeneralBinMetric(bin_cutoffs: list, exclude_last_bin: bool)[source]
class bliss.encoder.metrics.NullFilter[source]
get_cur_filter_bools(true_cat, est_cat)[source]

Get filter bools.

get_cur_postfix()[source]

Get postfix for the output metric name.

class bliss.encoder.metrics.SourceTypeAccuracy(base_flux_bin_cutoffs: list, mag_zero_point: int, ref_band: int = 2, report_bin_unit: str = 'flux', exclude_last_bin: bool = False, filter_list: List[CatFilter] = None)[source]
compute()[source]

Override this method to compute the final metric value.

This method will automatically synchronize state variables when running in distributed backend.

update(true_cat, est_cat, matching)[source]

Override this method to update the state variables of your metric class.

class bliss.encoder.metrics.SourceTypeFilter(filter_type: str)[source]
get_cur_filter_bools(true_cat, est_cat)[source]

Get filter bools.

get_cur_postfix()[source]

Get postfix for the output metric name.

bliss.encoder.convnets module

Feature extraction neural networks.

class bliss.encoder.convnets.FeaturesNet(n_bands, ch_per_band, num_features, double_downsample=False)[source]
forward(x)[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

bliss.encoder.convnet_layers module

Building blocks for convolutional networks.

class bliss.encoder.convnet_layers.Bottleneck(c1, c2, shortcut=True, e=0.5, gn=True, spatial=True)[source]
forward(x)[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class bliss.encoder.convnet_layers.C3(c1, c2, n=1, shortcut=True, e=0.5, gn=True, spatial=True)[source]
forward(x)[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class bliss.encoder.convnet_layers.ConvBlock(in_channels, out_channels, kernel_size=3, stride=1, gn=True)[source]
forward(x)[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class bliss.encoder.convnet_layers.Detect(in_channels, out_channels)[source]
forward(x)[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

bliss.encoder.image_normalizer module

Image normalization strategies (CLAHE, asinh, PSF).

class bliss.encoder.image_normalizer.AsinhQuantileNormalizer(q, pixel_shift=1)[source]
num_channels_per_band()[source]

Number of input channels for model based on this input normalizer.

class bliss.encoder.image_normalizer.ClaheNormalizer(min_stdev, kernel_size=9, padding=4)[source]
get_input_tensor(batch)[source]

Perform Contrast Limited Adaptive Histogram Equalization (CLAHE) on input images.

num_channels_per_band()[source]

Number of input channels for model based on this input normalizer.

class bliss.encoder.image_normalizer.NullNormalizer(*args, **kwargs)[source]
class bliss.encoder.image_normalizer.PsfAsImage(num_psf_params)[source]
num_channels_per_band()[source]

Number of input channels for model based on this input normalizer.

bliss.encoder.sample_image_renders module

Visualization utilities for sample predictions.

class bliss.encoder.sample_image_renders.PlotSampleImages(frequency: int = 1, restrict_batch: int = 0, tiles_to_crop: int = 0, tile_slen: int = 0)[source]

Metric wrapper for plotting sample images.

compute()[source]

Override this method to compute the final metric value.

This method will automatically synchronize state variables when running in distributed backend.

plot()[source]

Override this method plot the metric value.

update(batch, target_cat_cropped, sample_with_mode_tile, sample_with_mode, current_epoch, batch_idx)[source]

Override this method to update the state variables of your metric class.

bliss.encoder.sample_image_renders.plot_detections(images, true_cat, est_cat, margin_px, ticks=None, figsize=None)[source]

Plots an image of true and estimated sources.

bliss.encoder.sample_image_renders.plot_plocs(catalog, ax, idx, filter_by='all', bp=0, **kwargs)[source]

Plots pixel coordinates of sources on given axis.

Parameters:
  • catalog – FullCatalog to get sources from

  • ax – Matplotlib axes to plot on

  • idx – index of the image in the batch to plot sources of

  • filter_by – Which sources to plot. Can be either a string specifying the source type (either ‘galaxy’, ‘star’, or ‘all’), or a list of indices. Defaults to “all”.

  • bp – Offset added to locations, used for adjusting for cropped tiles. Defaults to 0.

  • **kwargs – Keyword arguments to pass to scatter plot.

Raises:

NotImplementedError – If object_type is not one of ‘galaxy’, ‘star’, ‘all’, or a List.

Surveys Package

Survey-specific data loaders and utilities.

bliss.surveys.survey module

Base class for survey implementations.

class bliss.surveys.survey.Survey[source]
static coadd_images(constituent_images)[source]

Coadd the constituent images into a single image.

abstractmethod idx(image_id)[source]

Return the index for the given image_id.

abstractmethod image_id(idx: int)[source]

Return the image_id for the given index.

abstractmethod image_ids() list[source]

Return a list of all image_ids.

predict_dataloader()[source]

Return a DataLoader for prediction.

abstractmethod prepare_data()[source]

pl.LightningDataModule override.

bliss.surveys.sdss module

Sloan Digital Sky Survey data loader.

class bliss.surveys.sdss.PhotoFullCatalog(height: int, width: int, d: Dict[str, Tensor])[source]

Class for the SDSS PHOTO Catalog.

Some resources: - https://www.sdss.org/dr12/algorithms/classify/ - https://www.sdss.org/dr12/algorithms/resolve/

classmethod from_file(cat_path, wcs: WCS, height, width)[source]

Instantiates PhotoFullCatalog with RCF and WCS information from disk.

restrict_by_ra_dec(ra_lim, dec_lim)[source]

Helper function to restrict photo catalog to within RA and DEC limits.

class bliss.surveys.sdss.SDSSDownloader(image_ids, download_dir)[source]

Class for downloading SDSS data.

classmethod field_extents() Table[source]

Get field extents table.

class bliss.surveys.sdss.SloanDigitalSkySurvey(psf_config: PSFConfig, fields, dir_path='data/sdss', load_image_data: bool = False, background_offset=0.0, align_to_band=None, crop_to_bands=None, crop_to_hw=None)[source]
idx(image_id: Tuple[int, int, int]) int[source]

Return the index for the given image_id.

image_id(idx) Tuple[int, int, int][source]

Return the image_id for the given index.

image_ids() List[Tuple[int, int, int]][source]

Return all image_ids.

Note: Parallel to rcfgcs.

Returns:

List of (run, camcol, field) image_ids.

Return type:

List[Tuple[int, int, int]]

prepare_data()[source]

pl.LightningDataModule override.

static radec_for_rcf(run, camcol, field) Tuple[float, float][source]

Get center (RA, DEC) for a given run, camcol, field.

static rcf_for_radec(ra, dec) Tuple[int, int, int][source]

Get run, camcol, field for a given RA, DEC.

bliss.surveys.des module

Dark Energy Survey data loader.

bliss.surveys.des.DES

alias of DarkEnergySurvey

class bliss.surveys.des.DESDownloader(image_ids: List[DESImageID], download_dir)[source]

Class for downloading DECaLS data.

download_background(brickname, image_filename_no_ext)[source]

Download sky params for specified band, for this brick/ccd.

download_backgrounds()[source]

Download sky params for all image_ids.

download_catalog(des_image_id) str[source]

Download tractor catalog given tractor-<brick_name>.fits filename.

static download_catalog_from_filename(tractor_filename: str)[source]

Download tractor catalog given tractor-<brick_name>.fits filename.

download_image(brickname, sky_coord, image_basename)[source]

Download image for specified band, for this brick/ccd.

download_images()[source]

Download images for all bands, for all image_ids.

download_psfex(brickname, image_filename_no_ext)[source]

Download psfex file for specified band, for this brick/ccd.

download_psfexs()[source]

Download psfex files for all image_ids.

class bliss.surveys.des.DESImageID
class bliss.surveys.des.DarkEnergySurvey(psf_config: PSFConfig, dir_path='data/des', image_ids: Tuple[DESImageID] = ({'ccdname': 'S28', 'decals_brickname': '3366m010', 'g': 'decam/CP/V4.8.2a/CP20171108/c4d_171109_002003_ooi_g_ls9', 'i': '', 'r': 'decam/CP/V4.8.2a/CP20170926/c4d_170927_025457_ooi_r_ls9', 'sky_coord': {'dec': -0.9316385797930247, 'ra': 336.6643042496718}, 'z': 'decam/CP/V4.8.2a/CP20170926/c4d_170927_025655_ooi_z_ls9'},), load_image_data: bool = False)[source]
idx(image_id: DESImageID) int[source]

Return the index for the given image_id.

image_id(idx) DESImageID[source]

Return the image_id for the given index.

image_ids() List[DESImageID][source]

Return a list of all image_ids.

prepare_data()[source]

pl.LightningDataModule override.

static zpt_to_scale(zpt)[source]

Converts a magnitude zero point per sec to nelec/nmgy scale.

See also https://github.com/dstndstn/tractor/blob/ cdb82000422e85c9c97b134edadff31d68bced0c/tractor/brightness.py#L217C6-L217C6

Parameters:

zpt (float) – magnitude zero point per sec

Returns:

nelec/nmgy scale

Return type:

float

class bliss.surveys.des.SkyCoord
class bliss.surveys.des.TractorFullCatalog(height: int, width: int, d: Dict[str, Tensor])[source]

Class for the DECaLS Tractor Catalog.

Some resources: - https://portal.nersc.gov/cfs/cosmo/data/legacysurvey/dr9/south/sweep/9.0/ - https://www.legacysurvey.org/dr9/files/#sweep-catalogs-region-sweep - https://www.legacysurvey.org/dr5/description/#photometry - https://www.legacysurvey.org/dr9/bitmasks/

classmethod from_file(cat_path, wcs: WCS, height, width, band: str = 'r')[source]

Loads DECaLS catalog from FITS file.

Parameters:
  • cat_path (str) – Path to .fits file.

  • band (str) – Band to read from. Defaults to “r”.

  • wcs (WCS) – WCS object for the image.

  • height (int) – Height of the image.

  • width (int) – Width of the image.

Returns:

A TractorFullCatalog containing data from the provided file.

bliss.surveys.dc2 module

DESC DC2 simulated survey data loader.

class bliss.surveys.dc2.DC2DataModule(dc2_image_dir: str, dc2_cat_path: str, image_lim: List[int], n_image_split: int, tile_slen: int, max_sources_per_tile: int, catalog_min_r_flux: float, prepare_data_processes_num: int, data_in_one_cached_file: int, splits: str, batch_size: int, num_workers: int, cached_data_path: str, train_transforms: List, nontrain_transforms: List, subset_fraction: float = None, shuffle_file_order: bool = True)[source]
prepare_data()[source]

Use this to download and prepare data. Downloading and saving data with multiple processes (distributed settings) will result in corrupted data. Lightning ensures this method is called only within a single process, so you can safely add your downloading logic within.

Warning

DO NOT set state to the model (use setup instead) since this is NOT called on every device

Example:

def prepare_data(self):
    # good
    download_data()
    tokenize()
    etc()

    # bad
    self.split = data_split
    self.some_state = some_other_state()

In a distributed environment, prepare_data can be called in two ways (using prepare_data_per_node)

  1. Once per node. This is the default and is only called on LOCAL_RANK=0.

  2. Once in total. Only called on GLOBAL_RANK=0.

Example:

# DEFAULT
# called once per node on LOCAL_RANK=0 of that node
class LitDataModule(LightningDataModule):
    def __init__(self):
        super().__init__()
        self.prepare_data_per_node = True


# call on GLOBAL_RANK=0 (great for shared file systems)
class LitDataModule(LightningDataModule):
    def __init__(self):
        super().__init__()
        self.prepare_data_per_node = False

This is called before requesting the dataloaders:

model.prepare_data()
initialize_distributed()
model.setup(stage)
model.train_dataloader()
model.val_dataloader()
model.test_dataloader()
model.predict_dataloader()
class bliss.surveys.dc2.DC2FullCatalog(height: int, width: int, d: Dict[str, Tensor])[source]
classmethod from_file(cat_path, wcs, height, width, **kwargs)[source]

Loads FullCatalog from disk.

bliss.surveys.download_utils module

Utilities for downloading survey data.

Simulator Package

Image simulation and prior distributions.

bliss.simulator.decoder module

Image decoder for rendering synthetic telescope images.

class bliss.simulator.decoder.Decoder(tile_slen: int, survey: Survey, use_survey_background: bool = True, with_dither: bool = True, with_noise: bool = True)[source]
pixel_shifts()[source]

Generate random pixel shifts and corresponding WCS list.

This function generates n_shifts random pixel shifts shifts and corresponding WCS list wcs to undo these shifts, relative to wcs[ref_band].

Returns:

array of pixel shifts wcs (List[WCS]): list of WCS objects

Return type:

shifts (np.ndarray)

render_bulge_plus_disk(band, source_params)[source]

Render a galaxy with given params.

Parameters:
  • band (int) – band

  • source_params (Tensor) – Tensor containing the parameters for a particular source (see prior.py for details about these parameters)

Returns:

a galsim representation of the rendered galaxy

Return type:

GSObject

render_galaxy(psf, band, source_params)[source]

Render a galaxy with given params and PSF.

Parameters:
  • psf (List) – a list of PSFs for each band

  • band (int) – band

  • source_params (Tensor) – Tensor containing the parameters for a particular source (see prior.py for details about these parameters)

Returns:

a galsim representation of the rendered galaxy convolved with the PSF

Return type:

GSObject

render_image(tile_cat)[source]

Render a single image from a tile catalog.

render_images(tile_cat)[source]

Render images from a tile catalog.

render_star(psf, band, source_params)[source]

Render a star with given params and PSF.

Parameters:
  • source_params (Tensor) – Tensor containing the parameters for a particular source (see prior.py for details about these parameters)

  • psf (List) – a list of PSFs for each band

  • band (int) – band

Returns:

a galsim representation of the rendered star convolved with the PSF

Return type:

GSObject

bliss.simulator.prior module

Prior distributions over light source catalogs.

class bliss.simulator.prior.CatalogPrior(survey_bands: list, n_tiles_h: int, n_tiles_w: int, batch_size: int, min_sources: int, max_sources: int, mean_sources: float, prob_galaxy: float, star_flux: dict, galaxy_flux: dict, galaxy_a_concentration: float, galaxy_a_loc: float, galaxy_a_scale: float, galaxy_a_bd_ratio: float, star_color_model_path: str, gal_color_model_path: str, reference_band: int)[source]

Prior distribution of objects in an astronomical image.

After the module is initialized, sampling is done with the sample method. The input parameters correspond to the number of sources, the fluxes, whether an object is a galaxy or star, and the distributions of galaxy and star shapes.

sample() TileCatalog[source]

Samples latent variables from the prior of an astronomical image.

Returns:

A dictionary of tensors. Each tensor is a particular per-tile quantity; i.e. the first three dimensions of each tensor are (batch_size, self.n_tiles_h, self.n_tiles_w). The remaining dimensions are variable-specific.

bliss.simulator.psf module

Point spread function utilities.

class bliss.simulator.psf.PSFConfig