Utils – Utility Modules

paltas.Utils.cosmology_utils module

Add to the functionality of colossus

Useful functions for extra cosmology calculations.

paltas.Utils.cosmology_utils.absolute_to_apparent(mag_absolute, z_light, cosmo, include_k_correction=True)[source]

Converts from absolute magnitude to apparent magnitude.

Parameters:
  • mag_apparent (float) – The absolute magnitude

  • z_light (float) – The redshift of the light

  • cosmo (colossus.cosmology.Cosmology) – An instance of the colossus cosmology object

  • include_k_correction (bool) – If true apply an approximate k correction for a galaxy-like source.

Returns:

The absolute magnitude of the light

Return type:

(float)

paltas.Utils.cosmology_utils.ddt(sample, cosmo)[source]

Calculates time delay distance given lens redshift, source redshift, and cosmology.

Parameters:
  • sample (dict) – Dictionary containing dictionaries of parameters for each model component. Generated using Sampler .sample() method

  • cosmo (colossus.cosmology.Cosmology) – An instance of the colossus cosmology object

Returns:

Time delay distance

Return type:

(float)

paltas.Utils.cosmology_utils.get_cosmology(cosmology_parameters)[source]

Returns colossus cosmology

Parameters:

cosmology_parameters (str,dict, or colossus.cosmology.Cosmology) – Either a name of colossus cosmology, a dict with ‘cosmology name’: name of colossus cosmology, an instance of colussus cosmology, or a dict with H0 and Om0 ( other parameters will be set to defaults).

Returns:

A corresponding instance of the colossus cosmology class.

Return type:

(colossus.cosmology.cosmology.Cosmology)

paltas.Utils.cosmology_utils.get_k_correction(z_light)[source]

Get the k correction for a galaxy source of light at a given redshift.

Parameters:

z_light (float) – The redshift of the light

Returns:

The k correction such that m_apparent = M_absolute + DM + K_corr.

Return type:

(float)

Notes

This code assumes the galaxy has a flat spectral wavelength density (and therefore 1/nu^2 spectral frequency density) and that the bandpass used for the absolute and apparent magntidue is the same.

paltas.Utils.cosmology_utils.kpc_per_arcsecond(z, cosmo)[source]

Calculates the physical kpc per arcsecond at a given redshift and cosmology

Parameters:
  • z (float) – The redshift to calculate the distance at

  • cosmo (colossus.cosmology.cosmology.Cosmology) – An instance of the colossus cosmology object.

Returns:

The kpc per arcsecond

Return type:

(float)

paltas.Utils.hubble_utils module

Utility functions for producing Hubble drizzled images.

paltas.Utils.hubble_utils.degrade_image(image, degrade_factor)[source]

Degrade an image by the specified integer factor.

Parameters:
  • image (np.array) – The 2D numpy image to degrade

  • degrade_factor (int) – The integer factor by which to degrade the image.

Returns:

A degraded version of the input image.

Return type:

(np.array)

paltas.Utils.hubble_utils.distort_image(img_high_res, w_high_res, w_dither, offset_pattern, psf_supersample_factor)[source]

Create distorted Hubble image in _flt frame

Parameters:
  • img_high_res (np.array) – A high resolution image that will be downsampled to produce each of the dithered images.

  • w_high_res (astropy.wcs.wcs.WCS) – The WCS class for the high resolution image. This should not include any distortion effects.

  • w_dither (astropy.wcs.wcs.WCS) – The WCS class for the dithered image. This should have the same pixel scale as the camera and should be centered at the same point as w_high_res. The offsets will be accounted for in the function call.

  • offset_pattern ([tuple,...]) – A list of tuples, each containing an x,y pair of offsets in pixel coordinates.

  • psf_supersample_factor (int) – The supersampled resolution at which to apply the psf model. If greater than 1 the distorted images will be returned at that supersampled scale to allow for psf convolution. Nothing needs to be changed about the WCS inputs.

Returns:

A len(offset_pattern) x dither_image.shape sized numpy array for each of the dithered images. dither_image shape will depend on the w_dither WCS object and the psf_supersample_factor.

Return type:

(np.array)

paltas.Utils.hubble_utils.generate_downsampled_wcs(high_res_shape, high_res_pixel_scale, low_res_pixel_scale, wcs_distortion)[source]

Generate a wcs mapping onto the specified lower resolution. If specified, geometric distortions will be included in the wcs object.

Parameters:
  • high_res_shape ([int,..]) – The shape of the high resolution image

  • high_res_pixel_scale (float) – The pixel width of the high resolution image in units of arcseconds.

  • low_res_pixel_scale (float) – The pixel width of the lower resolution target image in units of arcseconds.

  • wcs_distortion (astropy.wcs.wcs.WCS) – An instance of the WCS class that includes the desired gemoetric distortions as SIP coefficients. Note that the parameters relating to pixel scale, size of the image, and reference pixels will be overwritten. If None no gemoetric distortions will be applied.

Returns:

The wcs object corresponding to the downsampled image.

Return type:

astropy.wcs.wcs.WCS

paltas.Utils.hubble_utils.hubblify(img_high_res, high_res_pixel_scale, detector_pixel_scale, drizzle_pixel_scale, noise_model, psf_model, offset_pattern, wcs_distortion=None, pixfrac=1.0, kernel='square', psf_supersample_factor=1)[source]

Generates a simulated drizzled HST image, accounting for gemoetric distortions, the dithering pattern, and correlated read noise from drizzling.

Parameters:
  • img_high_res (np.array) – A high resolution image that will be downsampled to produce each of the dithered images.

  • high_res_pixel_scale (float) – The pixel width of the high resolution image in units of arcseconds.

  • detector_pixel_scale (float) – The pixel width of the detector in units of arcseconds.

  • drizzle_pixel_scale (float) – The pixel width of the final drizzled product in units of arcseconds.

  • noise_model (function) – A function that maps from an input numpy array of the image to a realization of the noise. This should operate on the degraded images.

  • psf_model (function) – A function that maps from an input image to an output psf-convovled image. The resolution on which this operates is set by psf_supersample_factor. Default is the resolution of the detector.

  • offset_pattern ([tuple,...]) – A list of x,y coordinate pairs specifying the offset of each dithered image from the coordinate frame used to generate the high resolution image. Specifying shifts that place the degraded image outside of the high resolution image will cause interpolation errors.

  • wcs_distortion (astropy.wcs.wcs.WCS) – An instance of the WCS class that includes the desired gemoetric distortions. Note that the parameters relating to pixel scale, size of the image, and reference pixels will be overwritten. If None no gemoetric distortions will be applied.

  • pixfrac (float) – The fraction of the pixel that the pixel flux is contained in. Passed to the drizzle algorithm.

  • kernel (str) – The string for the kernel to be used by the drizzle algorithm.

  • psf_supersample_factor (int) – The supersampled resolution at which to apply the psf model. 1 by default (the resolution of the detector).

Returns:

The drizzled image produced from len(offset_pattern) number of dithered exposures of img_high_res. Note that this means that the drizzled image will have the noise statistics and flux of len(offset_pattern) combined exposures.

Return type:

(np.array)

paltas.Utils.hubble_utils.offset_wcs(w, pixel_offset, reverse=False)[source]

Return wcs w shifted by pixel_offset pixels.

Parameters:
  • w (astropy.wcs.wcs.WCS) – An istance of the WCS class that will be copied and offset.

  • pixel_offset (tuple) – The x,y offset to apply in pixel units.

Returns:

The offset WCS object.

Return type:

(astropy.wcs.wcs.WCS)

paltas.Utils.hubble_utils.upsample_image(image, upsample_factor)[source]

Create an upsampled image by repeating the same pixel value multiple times.

Parameters:
  • image (np.array) – The 2D numpy image to degrade

  • upsample_factor (int) – The integer factor by which to upsample the image.

Returns:

A degraded version of the input image.

Return type:

(np.array)

paltas.Utils.lenstronomy_utils module

Utility functions for simplifying interactions with lenstronomy classes.

class paltas.Utils.lenstronomy_utils.PSFHelper(data_class, psf_model, kwargs_numerics)[source]

Bases: object

Class for simplifying interactions with the lenstronomy PSF class when using 2d images generated outside lenstronomy.

Parameters:
  • data_class (lenstronomy.Data.imaging_data.ImageData) – An instance of the lenstronomy ImageData class, likely spawned from the lenstronomy DataAPI class. It will be used to define the grid onto which the PSF will be mapped.

  • psf_model (lenstronomy.Data.psf.PSF) – An instance of the lenstronomy PSF class that will be used to convolve the image.

  • kwargs_numerics (dict) – A dict containing the numerics kwargs to pass to lenstronomy

psf_model(image)[source]

Apply the psf model to the given image.

Parameters:

image (np.array) – The image that will be convolved with the psf. It must have dimensions and resolution matching those specified in the production of the data_class provided when PSFHelper was initialized.

Returns:

The image convolved with the psf.

Return type:

(np.array)

paltas.Utils.power_law module

Draw from and integrate power laws

Useful equations to draw from and integrate power law distributions.

paltas.Utils.power_law.power_law_draw(p_min, p_max, slope, norm)[source]

Samples from a power law

Parameters:
  • p_min (float) – The lower bound of the power law

  • p_max (float) – The upper bound of the power law

  • slope (float) – The slope of the power law

  • norm (float) – The overall normalization of the power law

Returns:

A list of values drawn from the power law

Return type:

[float,…]

paltas.Utils.power_law.power_law_integrate(p_min, p_max, slope)[source]

Integrates a power law

Parameters:
  • p_min (float) – The lower bound of the power law

  • p_max (float) – The upper bound of the power law

  • slope (float) – The slope of the power law

Returns:

The integral of the power law x^slope from p_min to p_max

Return type:

(float)