descwl.model module

Model astronomical sources.

class descwl.model.Galaxy(identifier, redshift, ab_magnitude, ri_color, cosmic_shear_g1, cosmic_shear_g2, dx_arcsecs, dy_arcsecs, beta_radians, disk_flux, disk_hlr_arcsecs, disk_q, bulge_flux, bulge_hlr_arcsecs, bulge_q, agn_flux)[source]

Bases: object

Source model for a galaxy.

Galaxies are modeled using up to three components: a disk (Sersic n=1), a bulge (Sersic n=4), and an AGN (PSF-like). Not all components are required. All components are assumed to have the same centroid and the extended (disk,bulge) components are assumed to have the same position angle.

Parameters:
  • identifier (int) – Unique integer identifier for this galaxy in the source catalog.
  • redshift (float) – Catalog redshift of this galaxy.
  • ab_magnitude (float) – Catalog AB magnitude of this galaxy in the filter band being simulated.
  • ri_color (float) – Catalog source color calculated as (r-i) AB magnitude difference.
  • cosmic_shear_g1 (float) – Cosmic shear ellipticity component g1 (+) with |g| = (a-b)/(a+b).
  • cosmic_shear_g2 (float) – Cosmic shear ellipticity component g2 (x) with |g| = (a-b)/(a+b).
  • dx_arcsecs (float) – Horizontal offset of catalog entry’s centroid from image center in arcseconds.
  • dy_arcsecs (float) – Vertical offset of catalog entry’s centroid from image center in arcseconds.
  • beta_radians (float) – Position angle beta of Sersic components in radians, measured anti-clockwise from the positive x-axis. Ignored if disk_flux and bulge_flux are both zero.
  • disk_flux (float) – Total flux in detected electrons of Sersic n=1 component.
  • disk_hlr_arcsecs (float) – Half-light radius sqrt(a*b) of circularized 50% isophote for Sersic n=1 component, in arcseconds. Ignored if disk_flux is zero.
  • disk_q (float) – Ratio b/a of 50% isophote semi-minor (b) to semi-major (a) axis lengths for Sersic n=1 component. Ignored if disk_flux is zero.
  • bulge_flux (float) – Total flux in detected electrons of Sersic n=4 component.
  • bulge_hlr_arcsecs (float) – Half-light radius sqrt(a*b) of circularized 50% isophote for Sersic n=4 component, in arcseconds. Ignored if bulge_flux is zero.
  • bulge_q (float) – Ratio b/a of 50% isophote semi-minor (b) to semi-major (a) axis lengths for Sersic n=4 component. Ignored if bulge_flux is zero.
  • agn_flux (float) – Total flux in detected electrons of PSF-like component.
get_transformed_model(dx=0.0, dy=0.0, ds=0.0, dg1=0.0, dg2=0.0)[source]

Apply transforms to our model.

The nominal model returned by get_transformed_model() is available via the model attribute.

Parameters:
  • dx (float) – Amount to shift centroid in x, in arcseconds.
  • dy (float) – Amount to shift centroid in y, in arcseconds.
  • ds (float) – Relative amount to scale the galaxy profile in the radial direction while conserving flux, before applying shear or convolving with the PSF.
  • dg1 (float) – Amount to adjust the + shear applied to the galaxy profile, with |g| = (a-b)/(a+b), before convolving with the PSF.
  • dg2 (float) – Amount to adjust the x shear applied to the galaxy profile, with |g| = (a-b)/(a+b), before convolving with the PSF.
Returns:

New model constructed using our source profile with the requested transforms applied.

Return type:

galsim.GSObject

class descwl.model.GalaxyBuilder(survey, no_disk, no_bulge, no_agn, verbose_model)[source]

Bases: object

Build galaxy source models.

Parameters:
  • survey (descwl.survey.Survey) – Survey to use for flux normalization and cosmic shear.
  • no_disk (bool) – Ignore any Sersic n=1 component in the model if it is present in the catalog.
  • no_bulge (bool) – Ignore any Sersic n=4 component in the model if it is present in the catalog.
  • no_agn (bool) – Ignore any PSF-like component in the model if it is present in the catalog.
  • verbose_model (bool) – Provide verbose output from model building process.
static add_args(parser)[source]

Add command-line arguments for constructing a new GalaxyBuilder.

The added arguments are our constructor parameters with ‘_’ replaced by ‘-‘ in the names.

Parameters:parser (argparse.ArgumentParser) – Arguments will be added to this parser object using its add_argument method.
classmethod from_args(survey, args)[source]

Create a new GalaxyBuilder object from a set of arguments.

Parameters:
  • survey (descwl.survey.Survey) – Survey to build source models for.
  • args (object) – A set of arguments accessed as a dict using the built-in vars() function. Any extra arguments beyond those defined in add_args() will be silently ignored.
Returns:

A newly constructed Reader object.

Return type:

GalaxyBuilder

from_catalog(entry, dx_arcsecs, dy_arcsecs, filter_band)[source]

Build a :class:Galaxy object from a catalog entry.

Fluxes are distributed between the three possible components (disk,bulge,AGN) assuming that each component has the same spectral energy distribution, so that the resulting proportions are independent of the filter band.

Parameters:
  • entry (astropy.table.Row) – A single row from a galaxy descwl.catalog.
  • dx_arcsecs (float) – Horizontal offset of catalog entry’s centroid from image center in arcseconds.
  • dy_arcsecs (float) – Vertical offset of catalog entry’s centroid from image center in arcseconds.
  • filter_band (str) – The LSST filter band to use for calculating flux, which must be one of ‘u’,’g’,’r’,’i’,’z’,’y’.
Returns:

A newly created galaxy source model.

Return type:

Galaxy

Raises:
  • SourceNotVisible – All of the galaxy’s components are being ignored.
  • RuntimeError – Catalog entry is missing AB flux value in requested filter band.
exception descwl.model.SourceNotVisible[source]

Bases: exceptions.Exception

Custom exception to indicate that a source has no visible model components.

descwl.model.moments_size_and_shape(Q)[source]

Calculate size and shape parameters from a second-moment tensor.

If the input is an array of second-moment tensors, the calculation is vectorized and returns a tuple of output arrays with the same leading dimensions (...).

Parameters:Q (numpy.ndarray) – Array of shape (...,2,2) containing second-moment tensors, which are assumed to be symmetric (only the [0,1] component is used).
Returns:Tuple (sigma_m,sigma_p,a,b,beta,e1,e2) of numpy.ndarray objects with shape (...). Refer to Analysis Results for details on how each of these vectors is defined.
Return type:tuple
descwl.model.sersic_second_moments(n, hlr, q, beta)[source]

Calculate the second-moment tensor of a sheared Sersic radial profile.

Parameters:
  • n (int) – Sersic index of radial profile. Only n = 1 and n = 4 are supported.
  • hlr (float) – Radius of 50% isophote before shearing, in arcseconds.
  • q (float) – Ratio b/a of Sersic isophotes after shearing.
  • beta (float) – Position angle of sheared isophotes in radians, measured anti-clockwise from the positive x-axis.
Returns:

Array of shape (2,2) with values of the second-moments tensor matrix, in units of square arcseconds.

Return type:

numpy.ndarray

Raises:

RuntimeError – Invalid Sersic index n.

descwl.model.sheared_second_moments(Q, g1, g2)[source]

Apply shear to a second moments matrix.

The shear M = ((1-g1,-g2),(-g2,1+g1)) is applied to each Q by calculating Q’ = (M**-1).Q.(M**-1)^t where M**-1 = ((1+g1,g2),(g2,1-g1))/|M|. If the input is an array of second-moment tensors, the calculation is vectorized and returns a tuple of output arrays with the same leading dimensions (...).

Parameters:
  • Q (numpy.ndarray) – Array of shape (...,2,2) containing second-moment tensors, which are assumed to be symmetric.
  • g1 (float) – Shear ellipticity component g1 (+) with |g| = (a-b)/(a+b).
  • g2 (float) – Shear ellipticity component g2 (x) with |g| = (a-b)/(a+b).
Returns:

Array with the same shape as the input Q with the shear (g1,g2) applied to each 2x2 second-moments submatrix.

Return type:

numpy.ndarray