descwl.render module

Render source models as simulated survey observations.

class descwl.render.Engine(survey, min_snr, truncate_radius, no_margin, verbose_render)[source]

Bases: object

Rendering engine to simulate survey observations.

Any pixels outside of the truncation radius or below the minimum S/N cut will have their flux set to zero in the rendered image. As a result the total rendered flux may be below the total model flux.

  • survey (descwl.survey.Survey) – Survey that rendered images will simulate.
  • min_snr (float) – Simulate signals from individual sources down to this S/N threshold, where the signal N is calculated for the full exposure time and the noise N is set by the expected fluctuations in the sky background during a full exposure.
  • truncate_radius (float) – All extended sources are truncated at this radius in arcseconds.
  • no_margin (bool) – Do not simulate the tails of objects just outside the field.
  • verbose_render (bool) – Provide verbose output on rendering process.
static add_args(parser)[source]

Add command-line arguments for constructing a new Engine.

The added arguments are our constructor parameters with ‘_’ replaced by ‘-‘ in the names. Note that constructor parameter defaults are specified here rather than in the constructor, so that they are included in command-line help.

Parameters:parser (argparse.ArgumentParser) – Arguments will be added to this parser object using its add_argument method.

Describe our rendering configuration.

Description of the rendering configuration that we be used to simulate
the survey.
Return type:str
classmethod from_args(survey, args)[source]

Create a new Engine object from a set of arguments.

  • survey (descwl.survey.Survey) – Survey that rendered images will simulate.
  • 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.

A newly constructed Engine object.

Return type:


render_galaxy(galaxy, no_partials=False, calculate_bias=False)[source]

Render a galaxy model for a simulated survey.

  • galaxy (descwl.model.Galaxy) – Model of the galaxy to render.
  • no_partials (bool) – Do not calculate partial derivative images.

(stamps,bounds) where stamps is a numpy.ndarray of shape

(nstamp,width,height) pixel values that represents nstamp postage-stamp images with the same dimensions (width,height) determined by the rendering options provided. The returned bounds give the position of these stamps within the full simulated survey image as a galsim.BoundsI object. Note that these bounds might extend beyond the survey image, but will always have some overlap where the source is above threshold.

Return type:



SourceNotVisible – Galaxy has no pixels above threshold that are visible in the simulated survey.

class descwl.render.GalaxyRenderer(galaxy, stamp, survey)[source]

Bases: object

Rendering engine for a single galaxy.

  • galaxy (descwl.model.Galaxy) – Model of the galaxy we will render.
  • stamp (galsim.Image) – Previously rendered image of this galaxy with no transforms applied. Zero pixels in this image are used to define a mask where all subsequently rendered images will have pixels values set to zero. The input stamp is copied and not modified. The stamp bounds determine the region of the full survey image that we will render into.
  • survey (descwl.survey.Survey) – Survey that rendered images will simulate. Used to determine the mapping from survey positions to stamp positions and specify the PSF to use.
draw(df=0.0, dx=0.0, dy=0.0, ds=0.0, dg1=0.0, dg2=0.0)[source]

Draw the galaxy with the specified transforms applied.

We use descwl.galaxy.Galaxy.get_transformed_model() to apply all transforms except for df, which we implement internally using rescaling. The transformed model is convolved with the survey PSF, rendered into the stamp specified in our constructor, and masked (zero pixels in the untransformed rendering are forced to zero). Repeated calls with the same transform parameters return a cached image immediately. The same is true if only the df parameter is changed from the last call.

  • df (float) – Relative amount to scale the total galaxy flux.
  • 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.

Rendering of the transformed galaxy.

Return type:


exception descwl.render.SourceNotVisible[source]

Bases: exceptions.Exception

Custom exception to indicate that a source has no visible pixels above threshold.