yaw.catalogs.scipy.PatchCatalog#

class yaw.catalogs.scipy.PatchCatalog(id: int, data: DataFrame, cachefile: str | None = None, center: Coordinate | None = None, radius: Distance | None = None, degrees: bool = True)[source]#

Bases: object

Represents a single spatial patch of a ScipyCatalog.

A patch holds the data from single patch of the catalogue and provides method to access this data. Furthermore, it implements the caching to and restoring from disk. Data is temporarily saved to a .feather file, making it easy to pass patches to new threads and processes, which can, load the data back into memory if necessary.

Create a new patch from a data frame.

Coordiantes are converted to radian. If a cache path is provided, a cache file is created and the data is dropped from memory.

Parameters:
  • id (int) – Unique index of the patch.

  • data (pandas.DataFrame) – Data frame with columns ra, dec (by default assumed to be in degrees) and optionally weights, redshift if either data is available.

  • cachefile (str, optional) – If provided, the data is cached as .feather file at this path.

  • center (yaw.core.coordiante.Coordiante, optional) – Center coordinates of the patch. Computed automatically if not provided.

  • radius (yaw.core.coordiante.Distance, optional) – The angular size of the patch. Computed automatically if not provided.

  • degrees (bool) – Whether the input coordinates ra, dec are in degrees.

Methods

__init__(id, data[, cachefile, center, ...])

Create a new patch from a data frame.

from_cached(cachefile[, center, radius])

Restore the patch instance from its cache file.

get_tree(**kwargs)

Build a SphericalKDTree from the patch data coordiantes.

has_redshifts()

Whether the patch data include redshifts.

has_weights()

Whether the patch data include weights.

is_loaded()

Whether the data is present in memory

iter_bins(z_bins[, allow_no_redshift])

Iterate the patch in bins of redshift.

load([use_threads])

Load the data from the cache file into memory.

require_loaded()

Raise a CachingError if the data is not present in memory.

unload()

Drop the data from memory.

Attributes

cachefile

The patch to the cached .feather data file if caching is enabled.

center

Get the patch centers in radians.

data

Direct access to the underlying pandas.DataFrame which holds the patch data.

dec

Get an array of the declination values in radians.

id

Unique index of the patch.

pos

Get a vector of the object sky positions in radians.

ra

Get an array of the right ascension values in radians.

radius

Get the patch size in radians.

redshifts

Get the redshifts as array or None if not available.

total

Get the sum of weights or the number of objects if weights are not available.

weights

Get the object weights as array or None if not available.

cachefile = None#

The patch to the cached .feather data file if caching is enabled.

property center: CoordSky#

Get the patch centers in radians.

Available even if no data is loaded.

Returns:

yaw.core.coordinates.CoordSky

property data: DataFrame#

Direct access to the underlying pandas.DataFrame which holds the patch data.

property dec: NDArray[np.float64]#

Get an array of the declination values in radians.

Raises a CachingError if data is not loaded.

classmethod from_cached(cachefile: str, center: Coordinate | None = None, radius: Distance | None = None) PatchCatalog[source]#

Restore the patch instance from its cache file.

Optionally, the center and radius of the patch can be provided to avoid recomputing these quantities.

Parameters:
  • cachefile (str) – Path to the cach file (.feather)

  • center (yaw.core.coordiante.Coordiante, optional) – Center coordinates of the patch. Computed automatically if not provided.

  • radius (yaw.core.coordiante.Distance, optional) – The angular size of the patch. Computed automatically if not provided.

get_tree(**kwargs) SphericalKDTree[source]#

Build a SphericalKDTree from the patch data coordiantes.

has_redshifts() bool[source]#

Whether the patch data include redshifts.

has_weights() bool[source]#

Whether the patch data include weights.

id = 0#

Unique index of the patch.

is_loaded() bool[source]#

Whether the data is present in memory

iter_bins(z_bins: NDArray[np.float64], allow_no_redshift: bool = False) Iterator[tuple[Interval, PatchCatalog]][source]#

Iterate the patch in bins of redshift.

Parameters:
  • z_bins (NDArray) – Edges of the redshift bins.

  • allow_no_redshift (bool) – If true and the data has no redshifts, the iterator yields the whole patch at each iteration step.

Yields:

(tuple)

tuple containing:
  • intv (pandas.Interval): the selection for this bin.

  • cat (PatchCatalog): instance containing the data for this bin.

load(use_threads: bool = True) None[source]#

Load the data from the cache file into memory.

Raises a CachingError if no cache file is sepcified.

property pos: CoordSky#

Get a vector of the object sky positions in radians.

Raises a CachingError if data is not loaded.

Returns:

yaw.core.coordinates.CoordSky

property ra: NDArray[np.float64]#

Get an array of the right ascension values in radians.

Raises a CachingError if data is not loaded.

property radius: DistSky#

Get the patch size in radians.

Available even if no data is loaded.

Returns:

yaw.core.coordinates.DistSky

property redshifts: NDArray[np.float64]#

Get the redshifts as array or None if not available.

Raises a CachingError if data is not loaded.

require_loaded() None[source]#

Raise a CachingError if the data is not present in memory.

property total: float#

Get the sum of weights or the number of objects if weights are not available.

Available even if no data is loaded.

unload() None[source]#

Drop the data from memory.

Raises a CachingError if no cache file is sepcified.

property weights: NDArray[np.float64]#

Get the object weights as array or None if not available.

Raises a CachingError if data is not loaded.