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:
objectRepresents 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 columnsra,dec(by default assumed to be in degrees) and optionallyweights,redshiftif 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 coordinatesra,decare 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
SphericalKDTreefrom the patch data coordiantes.Whether the patch data include redshifts.
Whether the patch data include weights.
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.
Raise a
CachingErrorif the data is not present in memory.unload()Drop the data from memory.
Attributes
The patch to the cached .feather data file if caching is enabled.
Get the patch centers in radians.
Direct access to the underlying
pandas.DataFramewhich holds the patch data.Get an array of the declination values in radians.
Unique index of the patch.
Get a vector of the object sky positions in radians.
Get an array of the right ascension values in radians.
Get the patch size in radians.
Get the redshifts as array or
Noneif not available.Get the sum of weights or the number of objects if weights are not available.
Get the object weights as array or
Noneif 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:
- property data: DataFrame#
Direct access to the underlying
pandas.DataFramewhich holds the patch data.
- property dec: NDArray[np.float64]#
Get an array of the declination values in radians.
Raises a
CachingErrorif 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
SphericalKDTreefrom the patch data coordiantes.
- id = 0#
Unique index of the patch.
- 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
CachingErrorif no cache file is sepcified.
- property pos: CoordSky#
Get a vector of the object sky positions in radians.
Raises a
CachingErrorif data is not loaded.- Returns:
- property ra: NDArray[np.float64]#
Get an array of the right ascension values in radians.
Raises a
CachingErrorif data is not loaded.
- property radius: DistSky#
Get the patch size in radians.
Available even if no data is loaded.
- Returns:
- property redshifts: NDArray[np.float64]#
Get the redshifts as array or
Noneif not available.Raises a
CachingErrorif data is not loaded.
- 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
CachingErrorif no cache file is sepcified.
- property weights: NDArray[np.float64]#
Get the object weights as array or
Noneif not available.Raises a
CachingErrorif data is not loaded.