tools.utils#

This module provides utility functions for drawing sky coordinates, and applying observational noise.

skysurvey.tools.utils.get_skynoise_from_maglimit(maglim, zp=30)[source]#

Get the noise associated to the 5-sigma limit magnitude.

Parameters:
  • maglim (float) – 5-sigma limiting magnitude.

  • zp (float, optional) – Zero point. Default is 30.

Returns:

Sky noise.

Return type:

float

skysurvey.tools.utils.build_covariance(as_dataframe=False, **kwargs)[source]#

Convert kwargs into covariance matrix.

Parameters:
  • as_dataframe (bool) – should this return a np.array (False) or build a dataframe from it ? (True)

  • kwargs

    the format is the following:

    {‘{key1}’: err, ‘{key2}’: err, ‘cov_{key1}{key2}’: covariance, # or ‘cov_{key2}{key1}’ both are looked for }

Returns:

See as_dataframe.

Return type:

array or dataframe, param_names

skysurvey.tools.utils.apply_gaussian_noise(target_or_data, seed=None, **kwargs)[source]#

Apply random gaussian noise to the target.

Pass the entries error and covariance as kwargs following this format:

{‘{key1}’: err, ‘{key2}’: err, ‘cov_{key1}{key2}’: covariance, # or ‘cov_{key2}{key1}’ both are looked for }

Parameters:

target_or_data (skysurvey.Target or pandas.DataFrame) – a target (of child of) or directly it’s target.data This will affect what is returned.

Returns:

According to input.

Return type:

target or dataframe

skysurvey.tools.utils.random_radec(size=None, skyarea=None, ra_range=[0, 360], dec_range=[-90, 90], rng=None)[source]#

Draw the sky positions.

Parameters:
  • size (int, None) – number of draw

  • ra_range (2d-array) – = ignored if skyarea given = right-accension boundaries (min, max)

  • dec_range (2d-array) – = ignored if skyarea given = declination boundaries

  • skyarea (shapely.geometry.(Multi)Polyon) – Area to consider. Default is None. If skyarea is given, ra_range, dec_range is ignored.

  • rng (None, int, (Bit)Generator, optional) – seed for the random number generator. (doc adapted from numpy’s np.random.default_rng docstring. See that documentation for details.) If None, an unpredictable entropy will be pulled from the OS. If an int, (>0), it will set the initial BitGenerator state. If a (Bit)Generator, it will be returned as a Generator unaltered.

Returns:

list of ra, list of dec.

Return type:

2d-array

skysurvey.tools.utils.surface_of_skyarea(skyarea, incl_projection=True)[source]#

Convert input skyarea into deg**2.

Parameters:
  • skyarea (shapely.geometry.(Multi)Polyon) – Area to consider.

  • incl_projection (bool, optional) – If True, correct for spherical sky projection before computing the area, returning the true solid angle. If False, return the raw area in flat Ra/Dec space. Default is True.

Returns:

Area in deg**2 of the input skyarea, with or without sky projection correction.

Return type:

float

skysurvey.tools.utils.parse_skyarea(skyarea)[source]#

Pass through the skyarea as a shapely geometry.

Parameters:

skyarea (shapely.geometry.(Multi)Polyon) – Area to consider.

Returns:

The input skyarea unchanged.

Return type:

shapely.geometry.(Multi)Polygon

skysurvey.tools.utils.random_radecz_skymap(size=None, skymap={}, filename=None, do_3d=True, nside=512, ra_range=None, dec_range=None, zcmb_range=None, cosmo=FlatLambdaCDM(name='Planck15', H0=<Quantity 67.74 km / (Mpc s)>, Om0=0.3075, Tcmb0=<Quantity 2.7255 K>, Neff=3.046, m_nu=<Quantity [0., 0., 0.06] eV>, Ob0=0.0486), batch_size=1000, rng=None)[source]#

Draw random (RA, Dec, redshift) coordinates from a 3D gravitational wave sky map.

Parameters:
  • size (int) – Number of samples to draw. Default is None.

  • skymap (dict or astropy Table, optional) – Pre-loaded sky map in moc format (as returned by ligo.skymap.io.read_sky_map). Ignored if filename is provided.

  • filename (str, optional) – Path to a LIGO/Virgo sky map fits file. If provided, the sky map is loaded from this file. Default is None.

  • do_3d (bool, optional) – If True, load the sky map with 3D distance information. Default is True.

  • nside (int, optional) – HEALPix resolution parameter used to rasterize the sky map. Default is 512.

  • ra_range (2-element array, optional) – Right ascension range [min, max] in degrees to restrict the draw. Pixels outside this range have their probability set to 0. Default is None.

  • dec_range (2-element array, optional) – Declination range [min, max] in degrees to restrict the draw. Pixels outside this range have their probability set to 0. Default is None.

  • zcmb_range (2-element array, optional) – Redshift range [zmin, zmax] to restrict the distance sampling. If None, no redshift restriction is applied. Default is None.

  • cosmo (astropy.cosmology, optional) – Cosmology used to convert luminosity distances to redshifts. Default is Planck15.

  • batch_size (int, optional) – Number of pixels drawn per batch (to avoid memory issues for large size). Default is 1000.

  • rng (None, int, or (Bit)Generator, optional) – Seed for the random number generator. If None, an unpredictable entropy will be pulled from the OS. If an int (>0), it sets the initial BitGenerator state. If a (Bit)Generator, it is returned unaltered.

Returns:

  • ra (array) – Right ascension of the sampled positions, in degrees.

  • dec (array) – Declination of the sampled positions, in degrees.

  • zs (array) – Redshifts of the sampled positions.