pyimcom.layer
Utilities to generate additional layers and handle masks.
Classes
- GalSimInject
Utilities to inject objects using GalSim.
- GridInject
Utilities to inject stars using furry-parakeet C routine.
- CplxNoise
Utilities to generate 1/f noise.
- Mask
Utilities for permanent and cosmic ray masks.
Functions
- _get_sca_imagefile
Returns path to required SCA image file.
- check_if_idsca_exists
Determines whether an observation (id,sca) pair exists.
- get_all_data
Makes a 3D array of the image data.
Classes
Utilities to inject objects on a HEALPix grid using GalSim into an SCA image. |
|
Utilities to inject stars using furry-parakeet C routine. |
|
Utilities to generate 1/f noise. |
|
Utilities for permanent and cosmic ray masks. |
Functions
|
Main function to get input file names. |
|
Determines whether an observation (id,sca) pair exists. |
|
Makes a 3D array of all the layers of an input image. |
Module Contents
- class GalSimInject[source]
Utilities to inject objects on a HEALPix grid using GalSim into an SCA image.
- subgen_multirow()[source]
Helper function to generate multiple subsequences of a random number set (staticmethod).
Notes
The random number tools are designed to consistently generate the same objects when called with different SCAs (so a different set of HEALPix pixels is chosen).
Based on fluffy-garbanzo/inject_galsim_obj.py (fluffy-garbanzo is now deprecated).
- static galsim_star_grid(res, mywcs, inpsf, idsca, obsdata, sca_nside, inpsf_oversamp, extraargs=None)[source]
Draws a grid of stars on an SCA image.
- Parameters:
res (int) – HEALPix resolution (nside = 2**res).
mywcs (astropy.wcs.WCS or pyimcom.wcsutil.PyIMCOM_WCS) – The WCS object for the SCA.
inpsf (function) – A function that takes a position and returns a PSF (normally an InImage.get_psf_pos method).
idsca ((int,int)) – Tuple of observation ID and SCA number (SCA in 1..18)
obsdata (astropy.io.fits.FITS_rec) – Observation table (needed for some data formats).
sca_nside (int) – Side length of the SCA (4088 for Roman).
inpsf_oversamp (float or int) – Oversampling factor of the PSF image (relative to native).
extraargs (dict or None, optional) – If a dictionary, then contains more parameters to pass to some of the functions..
- Returns:
An array of shape (nside,nside) containing the image of all the objects drawn.
- Return type:
np.array
Notes
The following parameters are allowed as keys in extraargs:
angleTransient : bool
If True, then includes a transient source that is on or off depending on the roll angle (maps to time of year). Odd pixels are on for PA=0, even for PA=180.
FieldDependentModulation : float
If provided, then changes the apparent flux of the drawn stars depending on where they are in the field. The flux varies from 1 at the center of the focal plane up to 1 + FieldDependentModulation at the corners.
- static _advance(rngX, delta)[source]
Advances the random number generator.
Using
GalSimInject._advance(rngX, delta)should be equivalent torngX.advance(delta), but this is designed to work with a 32-bit limit on advance (so needed on some platforms).- Parameters:
rngX (np.random.BitGenerator) – The random number generator; must support the advance method.
delta (int) – The number of steps to advance. Must be >=0.
- Return type:
None
- static subgen(rngX, lenpix, subpix)[source]
Returns a subset of the next large block of random numbers.
This is designed to work even when the number of random numbers requested (lenpix) is too large for memory. It assumes no repeated entries in subpix (but these don’t have to be sorted).
- Parameters:
rngX (np.random.BitGenerator) – The random number generator; must support the advance method.
lenpix (int) – Number of random numbers to draw.
subpix (np.array) – 1D array of integers indicating which entries to return.
- Returns:
The array of
R[subpix[0]] .. R[subpix[-1]], whereR[0] .. R[lenpix-1]would be the full-length sequence of random numbers.- Return type:
np.array
See also
subgen_multirowGenerate multiple rows.
- static subgen_multirow(rngX, lenpix, subpix, P)[source]
Returns multiple subsets of the next large block of random numbers.
This is designed to work even when the number of random numbers requested in each row (lenpix) is too large for memory. It assumes no repeated entries in subpix (but these don’t have to be sorted).
- Parameters:
rngX (np.random.BitGenerator) – The random number generator; must support the advance method.
lenpix (int) – Number of random numbers to draw.
subpix (np.array) – 1D array of integers indicating which entries to return.
P (int) – Number of repititions to generate.
- Returns:
Shape (P, len(subpix)). Each row is an array
R[subpix[0]] .. R[subpix[-1]], whereR[0] .. R[lenpix-1]would be a full-length sequence of random numbers.- Return type:
np.array
See also
subgenGenerate a single row.
- static genobj(lenpix, subpix, galstring, seed, morph_extraargs={})[source]
Generates parameters for a set of random galaxies to draw on specific pixels.
- Parameters:
lenpix (int) – Number of pixels (should be 12 * 4**nside for HEALPix applications).
subpix (np.array) – Pixel indices that we want to draw. Array of integers, shape (nobj,). Does not need to be sorted, but repititions are not allowed.
galstring (str) – String specifying the type.
seed (int) – Random number generator seed.
morph_extraargs (dict) – Dictionary of galaxy morphology: sersic index, effective radius, and intrinsic shape
- Returns:
A dictionary containing a bunch of arrays of galaxy information.
- Return type:
dict
Notes
The possible galstring values, and the keyword/value returned, are as follows:
'exp1': exponential profile, random shear (up to 0.5), log distribution radius in 0.125 .. 0.5 arcsec. Keyword/values:'sersic': Sersic profile arrays.'n': Sersic index; float or array of float, shape (nobj,).'r': Effective radius in arcsec; float or array of float, shape (nobj,).'t__r': Truncation in effective radii; float or array of float, shape (nobj,).'g': Ellipticity (g-convention); array of float, shape (2,nobj).
- static _value(obj, n)[source]
Helper function to get obj if it is a scalar or obj[n] if it is an array.
- static galsim_extobj_grid(res, mywcs, inpsf, sca_nside, inpsf_oversamp, extraargs=[])[source]
Draws a grid of galaxies on an SCA image.
- Parameters:
res (int) – HEALPix resolution (nside = 2**res).
mywcs (astropy.wcs.WCS or pyimcom.wcsutil.PyIMCOM_WCS) – The WCS object for the SCA.
inpsf (function) – A function that takes a position and returns a PSF (normally an InImage.get_psf_pos method).
sca_nside (int) – Side length of the SCA (4088 for Roman).
inpsf_oversamp (int or float) – PSF oversampling factor.
extraargs (list of str, optional) – List of extra arguments to pass for drawing galaxies. An example would be
extraargs=['seed=12345', 'rot=90', 'shear=0.2:0.1'].
- Returns:
An array of shape (nside,nside) containing the image of all the objects drawn.
- Return type:
np.array
Notes
The extra arguments that can be given include:
“seed=n” (n : int) : use n as the random number generator seed
“rot=theta” (theta : float) : rotate the galaxies by theta degrees prior to any shear
“shear=g1:g2” (g1, g2 : float) : shear the galaxies by (g1,g2), conserving area
“n=n” (n : int) : Sersic index
“hlr=hlr” (hlr : float) : Effective radius in arcsec
“shape=g1:g2” (g1, g2 : float) : intrinsi galaxy shape by (g1,g2), conserving area
- class GridInject[source]
Utilities to inject stars using furry-parakeet C routine.
Based on fluffy-garbanzo/grid_inject.py.
- generate_star_grid()[source]
Make a table of star parameters that are in a circular region (staticmethod).
- static make_sph_grid(res, ra, dec, radius)[source]
Get Healpix pixels at resolution res that are within the given radius of (ra, dec).
- Parameters:
res (int) – HEALPix resolution (nside == 2**res).
ra (float) – Right ascension of patch center in radians.
dec (float) – Declination of patch center in radians.
radius (float) – Radius of patch in radians.
- Returns:
The output contains a dictionary of: * ‘npix’ : int, number of pixels used * ‘ipix’ : np.array of int, pixel indices found * ‘rapix’ : np.array of float, right ascension of pixels, in radians * ‘decpix’ : np.array of float, declination of pixels, in radians
- Return type:
dict
- static generate_star_grid(res, myWCS, scapar={'nside': 4088, 'pix_arcsec': 0.11})[source]
Makes a grid of positions to inject simulated sources into an SCA image.
- Parameters:
res (int) – HEALPix resolution (nside == 2**res)
myWCS (astropy.wcs.WCS or pyimcom.wcsutil.PyIMCOM_WCS) – World coordinate system for the SCA
scapar (dict, optional) – Should have keyword/values: * ‘sca_nside’ : int, side length of SCA * ‘pix_arcsec’ : float, reference pixel scale in arcsec
- Returns:
np.array of int – array of HEALPix pixel indices
np.array of float – x positions on the SCA
np.array of float – y positions on the SCA
np.array of float – right ascensions of the pixels drawn
np.array of float – declinations of the pixels drawn
- static make_image_from_grid(res, inpsf, idsca, obsdata, mywcs, nside_sca, inpsf_oversamp)[source]
Make an SCA image with this grid of stars with a PSF from a specified file with unit flux.
- Parameters:
res (int) – HEALPix resolution (nside == 2**res)
inpsf (function) – Should be an InImage.get_psf_pos method
idsca ((int,int)) – Observation ID, SCA pair (SCA in 1 .. 18)
obsdata (astropy.io.fits.FITS_rec) – Observation table (needed for some data formats).
mywcs (astropy.wcs.WCS or pyimcom.wcsutil.PyIMCOM_WCS) – World coordinate system for the SCA
nside_sca (int) – Side length of the SCA (in pixels)
inpsf_oversamp (float or int) – Oversampling factor of the PSF image (relative to native).
- Returns:
The image of the SCA with the stars drawn. Shape (nside_sca, nside_sca).
- Return type:
np.array
- class CplxNoise[source]
Utilities to generate 1/f noise.
Based on fluffy-garbanzo/inject_complex_noise.py.
- class Mask[source]
Utilities for permanent and cosmic ray masks.
- static randmask(idsca, pcut, hitinfo=None)[source]
Makes a psuedorandom mask that randomly removes groups of pixels (intended for CR simulation).
- Parameters:
idsca ((int, int)) – Observation ID, SCA pair.
pcut (float) – Probability that any given pixel is hit.
hitinfo (dict or None, optional) – For future expansion, right now always use None.
- Returns:
An image of True for good pixels and False for CR-affected pixels.
- Return type:
np.array of bool
- static load_permanent_mask(block)[source]
Builds a permanent mask from a FITS file referenced in the configuration.
- Parameters:
block (pyimcom.coadd.Block) – The block that we are coadding.
- Returns:
An image of True for good pixels and False for bad pixels.
- Return type:
np.array of bool
- static load_mask_from_maskfile(cfg, obsdata, idsca)[source]
Loads a mask from a cached mask file.
- Parameters:
cfg (pyimcom.config.Config) – The configuration file.
obsdata (astropy.io.fits.FITS_rec) – Observation table (needed for some data formats).
idsca ((int,int)) – Tuple of observation ID and SCA number (SCA in 1..18)
- Returns:
An image of True for good pixels and False for bad pixels.
- Return type:
np.array of bool
- static load_cr_mask(inimage)[source]
Generates a cosmic ray mask for an image (including lab noise CRs, if labnoise is used).
- Parameters:
inimage (pyimcom.coadd.InImage) – An input image structure.
- Returns:
An image of True for good pixels and False for CR-affected pixels.
- Return type:
np.array of bool
- _get_sca_imagefile(path, idsca, obsdata, format_, extraargs=None)[source]
Main function to get input file names.
- Parameters:
path (str) – Directory for the files.
idsca ((int, int)) – Observation ID, SCA pair.
obsdata (astropy.io.fits.FITS_rec) – Observation table (needed for some data formats).
format (str) – Input file format type identifier from the configuration.
extraargs (dict or None, optional) – Additional arguments that can be provided for some types of files. Default is None.
- Returns:
The file name (returns None if unrecognized format).
- Return type:
str or None
Notes
The valid formats are currently: * dc2_imsim * anlsim * L2_2506
If sca is -1, then returns a format string (i.e., with ‘{:d}’ or similar instead of the number itself).
- check_if_idsca_exists(cfg, obsdata, idsca)[source]
Determines whether an observation (id,sca) pair exists.
- Parameters:
cfg (pyimcom.config.Config) – Configuration information.
obsdata (astropy.io.fits.FITS_rec) – Observation table (needed for some data formats).
idsca ((int, int)) – Observation ID, SCA pair.
Returns
exists (bool) – Whether the file exists.
fname (str) – The file name.
- get_all_data(inimage)[source]
Makes a 3D array of all the layers of an input image.
The indexing of the return array is [input layer (e.g., 0=sci or sim), y, x].
- Parameters:
inimage (pyimcom.coadd.InImage) – An input image structure.
- Returns:
The input image; shape = (nlayer, nside_sca, nside_sca)
- Return type:
np.array