yaw.randoms.UniformRandoms#

class yaw.randoms.UniformRandoms(ra_min: float, ra_max: float, dec_min: float, dec_max: float, seed: int = 12345)[source]#

Bases: object

Generator for uniform randoms on a rectangular footprint.

Generates points uniform in right ascension and declination. Additional features can be cloned by sampling values from an external data catalogue (e.g. spectroscopic or photometric redshifts).

Internally uses cylindrical coordinates \((x, y)\), which are an equal area projection. Point are generated in cylindrical coordinates and transformed back to spherical coordinates \((\alpha, \delta)\):

\(\alpha \leftrightarrow x \quad \sin{\delta} \leftrightarrow y\)

Create a new generator for a the given footprint.

Parameters:
  • ra_min (float) – Minimum right ascenion to generate, in degrees.

  • ra_max (float) – Maximum right ascenion to generate, in degrees.

  • dec_min (float) – Minimum declination to generate, in degrees.

  • dec_max (float) – Maximum declination to generate, in degrees.

  • seed (int, optional) – Seed to use for the random generator.

Methods

__init__(ra_min, ra_max, dec_min, dec_max[, ...])

Create a new generator for a the given footprint.

cylinder2sky(x, y)

Conversion from cylindrical to spherical coordinates.

from_catalog(cat[, seed])

Create a new generator with a rectangular footprint obtained from the coordinate range of a given data catalogue.

generate(size[, names, draw_from, n_threads])

Generate new random points.

sky2cylinder(ra, dec)

Conversion from spherical to cylindrical coordinates.

static cylinder2sky(x: float | NDArray[np.float64], y: float | NDArray[np.float64]) float | NDArray[np.float64][source]#

Conversion from cylindrical to spherical coordinates.

Parameters:
  • x (float, NDArray) – x-coordinate(s) to convert to spherical coordinates.

  • y (float, NDArray) – y-coordinate(s) to convert to spherical coordinates.

Returns:

Array with of points in spherical coordinates of shape (N, 2).

Return type:

NDArray

classmethod from_catalog(cat: BaseCatalog, seed: int = 12345) UniformRandoms[source]#

Create a new generator with a rectangular footprint obtained from the coordinate range of a given data catalogue.

Parameters:
  • cat (yaw.catalogs.BaseCatalog) – Catalog instance from which the right ascension and declination range is computed.

  • seed (int, optional) – Seed to use for the random generator.

generate(size: int, names: list[str, str] | None = None, draw_from: dict[str, NDArray] | None = None, n_threads: int = 1) DataFrame[source]#

Generate new random points.

Generate a specified number of points, additionally draw extra data features form a list of input values. Results are returned in a data frame.

Parameters:
  • size (int) – Number of random points to generate.

  • name (tuple[str, str], optional) – Name of the right ascension and declination columns in the output data frame. Default is ra and dec.

  • draw_from (dict[str, NDArray], optional) – Dictionary of data arrays. If provided, a random sample (with repetition) is drawn from these arrays and assigned to the output data frame. The dictionary keys are used to name the columns in the output.

  • n_threads (int, optional) –

    Generate data in parallel using subprocesses, default is parallel processing disabled.

    Deprecated since version 2.3.2: No performance gain observed. May be removed in a future version.

Returns:

Data frame with uniform random coordinates and optionally additional features draw from input data.

Return type:

pandas.DataFrame

static sky2cylinder(ra: float | NDArray[np.float64], dec: float | NDArray[np.float64]) NDArray[source]#

Conversion from spherical to cylindrical coordinates.

Parameters:
  • ra (float, NDArray) – Right ascension(s) to convert to cylindrical coordinates.

  • dec (float, NDArray) – Right ascension(s) to convert to cylindrical coordinates.

Returns:

Array with of points in cylindrical coordinates of shape (N, 2).

Return type:

NDArray