CachingSkyMap

class lsst.skymap.cachingSkyMap.CachingSkyMap(numTracts, config=None, version=0)

Bases: lsst.skymap.BaseSkyMap

A SkyMap that generates its tracts on request and caches them.

Parameters:
numTracts : int

Number of tracts to create.

config : lsst.skymap.BaseSkyMapConfig (optional)

The configuration for this SkyMap; if None use the default config.

version : int or tuple of int (optional)

Software version of this class, to retain compatibility with old instances.

Notes

A subclass should define * __init__ to calculate the required number of tracts (and pass it up) * generateTract to generate a tract

Subclassers should also check that the arguments to the constructor are consistent with the below __reduce__ method.

Attributes Summary

SKYMAP_DATASET_TYPE_NAME
SKYMAP_RUN_COLLECTION_NAME

Methods Summary

findClosestTractPatchList(coordList) Find closest tract and patches that overlap coordinates.
findTract(coord) Find the tract whose center is nearest the specified coord.
findTractIdArray(ra, dec[, degrees]) Find array of tract IDs with vectorized operations (where supported).
findTractPatchList(coordList) Find tracts and patches that overlap a region.
generateTract(index) Generate TractInfo for the specified tract index.
getSha1() Return a SHA1 hash that uniquely identifies this SkyMap instance.
logSkyMapInfo(log) Write information about a sky map to supplied log
pack_data_id(tract, patch[, band]) Pack a skymap-based data ID into an integer.
register(name, butler) Add skymap, tract, and patch Dimension entries to the given Gen3 Butler.
updateSha1(sha1) Add subclass-specific state or configuration options to the SHA1.

Attributes Documentation

SKYMAP_DATASET_TYPE_NAME = 'skyMap'
SKYMAP_RUN_COLLECTION_NAME = 'skymaps'

Methods Documentation

findClosestTractPatchList(coordList)

Find closest tract and patches that overlap coordinates.

Parameters:
coordList : lsst.geom.SpherePoint

List of ICRS sky coordinates to search for.

Returns:
retList : list

list of (TractInfo, list of PatchInfo) for tracts and patches that contain, or may contain, the specified region. The list will be empty if there is no overlap.

findTract(coord)

Find the tract whose center is nearest the specified coord.

Parameters:
coord : lsst.geom.SpherePoint

ICRS sky coordinate to search for.

Returns:
result : TractInfo

TractInfo of tract whose center is nearest the specified coord.

Notes

  • If coord is equidistant between multiple sky tract centers then one is arbitrarily chosen.
  • The default implementation is not very efficient; subclasses may wish to override.

Warning: If tracts do not cover the whole sky then the returned tract may not include the coord.

findTractIdArray(ra, dec, degrees=False)

Find array of tract IDs with vectorized operations (where supported).

If a given sky map does not support vectorized operations, then a loop over findTract will be called.

Parameters:
ra : np.ndarray

Array of Right Ascension. Units are radians unless degrees=True.

dec : np.ndarray

Array of Declination. Units are radians unless degrees=True.

degrees : bool, optional

Input ra, dec arrays are degrees if True.

Returns:
tractId : np.ndarray

Array of tract IDs

Notes

  • If coord is equidistant between multiple sky tract centers then one is arbitrarily chosen.

Warning: If tracts do not cover the whole sky then the returned tract may not include the given ra/dec.

findTractPatchList(coordList)

Find tracts and patches that overlap a region.

Parameters:
coordList : list of lsst.geom.SpherePoint

List of ICRS sky coordinates to search for.

Returns:
reList : list of (TractInfo, list of PatchInfo)

For tracts and patches that contain, or may contain, the specified region. The list will be empty if there is no overlap.

Notes

warning:
This uses a naive algorithm that may find some tracts and patches that do not overlap the region (especially if the region is not a rectangle aligned along patch x, y).
generateTract(index)

Generate TractInfo for the specified tract index.

getSha1()

Return a SHA1 hash that uniquely identifies this SkyMap instance.

Returns:
sha1 : bytes

A 20-byte hash that uniquely identifies this SkyMap instance.

Notes

Subclasses should almost always override updateSha1 instead of this function to add subclass-specific state to the hash.

logSkyMapInfo(log)

Write information about a sky map to supplied log

Parameters:
log : lsst.log.Log

Log object that information about skymap will be written

pack_data_id(tract, patch, band=None)

Pack a skymap-based data ID into an integer.

Parameters:
tract : int

Integer ID for the tract.

patch : tuple (int) or int

Either a 2-element (x, y) tuple (Gen2 patch ID) or a single integer (Gen3 patch ID, corresponding to the “sequential” patch index methods in this package).

band : str, optional

If provided, a filter name present in SkyMapDimensionPacker.SUPPORTED_FILTERS (which is aspirationally a list of all Gen3 ‘bands’, but in practice may be missing some; see RFC-785). If not provided, the packing algorithm that does not include the filter will be used.

Returns:
packed : int

Integer that corresponds to the data ID.

max_bits : int

Maximum number of bits that packed could have, assuming this skymap and presence or absence of band.

Notes

This method uses a Gen3 lsst.daf.butler.DimensionPacker object under the hood to guarantee consistency with pure Gen3 code, but it does not require the caller to actually have a Gen3 butler available. It does, however, require a filter value compatible with the Gen3 “band” dimension.

This is a temporary interface intended to aid with the migration from Gen2 to Gen3 middleware. It will be removed with the Gen2 middleware or when DM-31924 provides a longer-term replacement, whichever comes first. Pure Gen3 code should use lsst.daf.butler.DataCoordinate.pack or other lsst.daf.butler.DimensionPacker interfaces.

register(name, butler)

Add skymap, tract, and patch Dimension entries to the given Gen3 Butler.

Parameters:
name : str

The name of the skymap.

butler : lsst.daf.butler.Butler

The butler to add to.

Raises:
lsst.daf.butler.registry.ConflictingDefinitionError

Raised if a different skymap exists with the same name.

Notes

Registering the same skymap multiple times (with the exact same definition) is safe, but inefficient; most of the work of computing the rows to be inserted must be done first in order to check for consistency between the new skymap and any existing one.

Re-registering a skymap with different tract and/or patch definitions but the same summary information may not be detected as a conflict but will never result in updating the skymap; there is intentionally no way to modify a registered skymap (aside from manual administrative operations on the database), as it is hard to guarantee that this can be done without affecting reproducibility.

updateSha1(sha1)

Add subclass-specific state or configuration options to the SHA1.

Parameters:
sha1 : hashlib.sha1

A hashlib object on which update can be called to add additional state to the hash.

Notes

This method is conceptually “protected” : it should be reimplemented by all subclasses, but called only by the base class implementation of getSha1 .