pyimcom.coadd
Driver to coadd a block (2D array of postage stamps).
Classes
- InImage
Input image attached to a Block instance.
- InStamp
Data structure for input pixel positions and signals.
- OutStamp
Driver for postage stamp coaddition.
- Block
Driver for block coaddition.
Classes
Input image attached to a Block instance. |
|
Data structure for input pixel positions and signals. |
|
Driver for postage stamp coaddition. |
|
Driver for block coaddition. |
Module Contents
- class InImage(blk: Block, idsca: tuple[int, int])[source]
Input image attached to a Block instance.
- Parameters:
blk (Block) – The Block instance to which this InImage instance is attached.
idsca ((int, int)) – ID of observation and SCA used.
- static generate_idx_grid(xs: numpy.array, ys: numpy.array) numpy.array[source]
Generate a grid of indices.
- Parameters:
xs (np.array) – x values of the grid, length (nx,)
ys (np.array, shape : (ny,)) – y values of the grid, length (ny,)
- Returns:
All combinations of xs elements and ys elements. Shape (nx*ny,2)
- Return type:
np.array
- _inpix2world2outpix(inxys: numpy.array) numpy.array[source]
Composition of pix2world and world2pix.
- Parameters:
inxys (np.array) – x and y positions in the input image coordinates, shape (npix, 2)
- Returns:
x and y positions in the output block coordinates, shape (npix, 2).
- Return type:
np.array
- outpix2world2inpix(outxys: numpy.array) numpy.array[source]
Inverse function of _inpix2world2outpix.
- Parameters:
outxys (np.array) – x and y positions in the output block coordinates, shape (npix, 2).
- Returns:
x and y positions in the input image coordinates, shape (npix, 2).
- Return type:
np.array
- partition_pixels(sp_res: int = 90, relax_coef: float = 1.05, verbose: bool = False, visualize: bool = False) None[source]
Partition input pixels into postage stamps.
- Parameters:
sp_res (int, optional) – Resolution of the sparse grid.
relax_coef (float, optional) – Coefficient to create enough space for input pixels.
verbose (bool, optional) – Whether to print verbose output.
visualize (bool, optional) – Whether to visualize the partition process and results.
- Return type:
None
- static smooth_and_pad(inArray: numpy.array, tophatwidth: float = 0.0, gaussiansigma: float = 0.0) numpy.array[source]
Utility to smear a PSF with a tophat and a Gaussian.
- Parameters:
inArray (np.array) – Input PSF array to be smeared. Shape (ny, nx)
tophatwidth (float, optional) – Width of the tophat in pixels. The default is 0.0.
gaussiansigma (float, optional) – Both in units of the pixels given (not native pixel).
- Returns:
outArray – Smeared input PSF array, shape (ny+npad*2, nx+npad*2)
- Return type:
np.array
- static LPolyArr(PORDER, u_, v_)[source]
Generates an array of the Legendre polynomials.
- Parameters:
PORDER (int) – >=0, order in each axis
u (float) – x-position on chip scaled to -1..+1
v (float) – y-position on chip scaled to -1..+1
- Returns:
arr – the array of Legendre polynomial products, shape : ((PORDER+1)**2)
- Return type:
np.array, shape : ((PORDER+1)**2)
Notes
The returned array has length (PORDER+1)**2. The constant (1) is first, then increasing x-order, then increasing y-order: for n=0..PORDER { for m=0..PORDER { coef P_m(u_) P_n(v_) }}.
- static psf_filename(inpsf_format, obsid)[source]
PSF file name broker.
- Parameters:
inpsf_format (str) – Format for input PSFs.
obsid (int) – The observation ID number.
- Returns:
File name.
- Return type:
str
- get_psf_pos(psf_compute_point: numpy.array, use_shortrange: bool = False) numpy.array[source]
Get input PSF array at given position.
This is an interface for layer.get_all_data and psfutil.PSFGrp._build_inpsfgrp.
- Parameters:
psf_compute_point (np.array) – Length 2 array, point to compute PSF in RA and Dec.
use_shortrange (bool, optional) – If True and PSFSPLIT is set in the configuration file, then pulls only the short-range PSF G^(S).
- Returns:
Input PSF array at given position (see smooth_and_pad for the shape).
- Return type:
np.array
- class InStamp(blk: Block, j_st: int, i_st: int)[source]
Data structure for input pixel positions and signals.
- Parameters:
blk (Block) – The Block instance to which this InStamp instance is attached.
j_st (int) – InStamp vertical index.
i_st (int) – InStamp horizontal index.
- make_selection(pivot: tuple[float, float] = (None, None), radius: float = None) numpy.array[source]
Return the indices of selected input pixels.
This is an interface for OutStamp._process_input_stamps.
- Parameters:
pivot ((float or None, float or None), optional) – Pivot position in the output block coordinates. If None in one direction, select input pixels according to the other; if None in both directions, select all input pixels.
radius (float or None, optional) – Select input pixels within this radius.
- Returns:
Indices of selected input pixels (if there are any). None if selecting all input pixels.
- Return type:
np.array or None
- get_inpsfgrp(sim_mode: bool = False, visualize: bool = False) None[source]
Get the input PSFGrp attached to this InStamp.
This is an interface for psfutil.SysMatA._compute_iisubmats and psfutil.SysMatB.get_iosubmat.
- Parameters:
sim_mode (bool, optional) – Whether to count references without actually making inpsfgrp. See the docstring of psfutil.SysMatA._compute_iisubmats.
visualize (bool, optional) – Whether to visualize the PSF group.
- Return type:
None
- class OutStamp(blk: Block, j_st: int, i_st: int, visualize: bool = False)[source]
Driver for postage stamp coaddition.
- Parameters:
blk (Block) – The Block instance to which this InStamp instance is attached.
j_st (int) – OutStamp index, vertical direction.
i_st (int) – OutStamp index, horizontal direction.
visualize (bool, optional) – Whether to run visualizations.
- _process_input_stamps(visualize: bool = False) None[source]
Fetch and process input postage stamps.
- Parameters:
visualize (bool, optional) – Whether to visualize the process.
- Return type:
None
Notes
This method selects input pixels to form a region like this: +—–+—–+—–+ | |*****| | | **|*****|** | +—–+—–+—–+ |*****|*****|*****| |*****|*****|*****| +—–+—–+—–+ | **|*****|** | | |*****| | +—–+—–+—–+ where the central postage stamp is the OutStamp we are coadding.
- __call__(visualize: bool = False, save_abc: bool = False, save_t: bool = False) None[source]
Build system matrices and perform coaddition.
- Parameters:
visualize (bool, optional) – Whether to visualize the process.
save_abc (bool, optional) – Whether to save system matrices.
save_t (bool, optional) – Whether to save coaddition matrices.
- Return type:
None
- _build_system_matrices(visualize: bool = False, save_abc: bool = False) None[source]
Build system matrices and coaddition matrices.
- Parameters:
visualize (bool, optional) – Whether to visualize the process.
save_abc (bool, optional) – Whether to save system matrices.
- Return type:
None
- static trapezoid(arr: numpy.array, fade_kernel: int, recover_mode: bool = False, pad_widths: tuple[int, int, int, int] = (0, 0, 0, 0), do_sides: str = 'BTLR', use_trunc_sinc: bool = True) None[source]
Apply a trapezoid filter of width 2*fade_kernel on each side.
- Parameters:
arr (np.array) – The array to apply the trapezoid filter. Shape (…, ny, nx).
fade_kernel (int) – Half the width of the trapezoid filter.
recover_mode (bool, optional) – Whether to recover faded boundaries.
pad_widths ((int, int, int, int), optional) – Padding width on each side (order: bottom, top, left, right).
do_sides (str, optional) – Which sides to apply the trapezoid filter.
use_trunc_sinc (bool, optional) – Whether to use the truncated sinc function.
- Return type:
None
- _perform_coaddition(visualize: bool = False, save_t: bool = False, use_trunc_sinc: bool = True) None[source]
Perform the actual multiplication.
- Parameters:
visualize (bool, optional) – Whether to visualize the process.
save_t (bool, optional) – Whether to save coaddition matrices.
use_trunc_sinc (bool, optional) – Argument for coadd_utils.trapezoid.
- Return type:
None
- class Block(cfg: pyimcom.config.Config = None, this_sub: int = 0, run_coadd: bool = True)[source]
Driver for block coaddition.
- Parameters:
cfg (Config, optional) – Configuration for this Block.
this_sub (int, optional) – Number determining the location of this Block in the mosaic.
run_coadd (bool, optional) – Whether to coadd this block. Turn this off if you want to perform the procedure manually.
- _get_obs_cover(radius: float) None[source]
Get observations relevant to this Block.
- Parameters:
radius (float) – Search for input images within this radius.
- Return type:
None
Notes
This uses the observation table (obsdata), center position (ra, dec), and filter information stored internally to the Block.
- _build_use_instamps() None[source]
Build use_instamps, Boolean array indicating whether to use each input postage stamp.
- _output_stamp_wrapper(i_st, j_st, n_coadded, sim_mode: bool = False, visualize: bool = False)[source]
Wrapper for output stamp coaddition.
- Parameters:
j_st (int) – Vertical OutStamp index.
i_st (int) – Horizontal OutStamp index.
n_coadded (int) – Number of postage stamps to be coadded.
sim_mode (bool, optional) – Whether to count references without actually making inpsfgrp. See the docstring of psfutil.SysMatA._compute_iisubmats.
visualize (bool, optional) – Perform visualizations? (Usually just for testing.)
- Return type:
None
- coadd_output_stamps(sim_mode: bool = False, visualize: bool = False) None[source]
Coadd output stamps using input stamps.
- Parameters:
sim_mode (bool, optional) – Whether to count references without actually making inpsfgrp. See the docstring of psfutil.SysMatA._compute_iisubmats.
visualize (bool, optional) – Perform visualizations? (Usually just for testing.)
- Return type:
None
- static compress_map(map_: numpy.array, coef: int, dtype: type, header: astropy.io.fits.Header = None, EXTNAME: str = None, UNIT: str, str = None) astropy.io.fits.ImageHDU[source]
Compress float32 map to (u)int16 to save storage.
- Parameters:
map (np.array) – Map to be compressed. Shape is usually (NsideP, NsideP).
coef (int) – Coefficient for log10 values.
dtype (type) – Data type of the compressed map, np.(u)int16.
header (fits.Header) – Template header of the HDU. If None, return the compressed map instead of an HDU.
EXTNAME (str) – EXTNAME keyword of the header. If None, return the compressed map instead of an HDU.
UNIT ((str, str)) – UNIT keyword of the header. If None, return the compressed map instead of an HDU.
- Returns:
HDU containing the compressed array.
- Return type:
fits.ImageHDU
- build_output_file(is_final: bool = False) None[source]
Build the output FITS file.
The kappa maps have been unified and merged into the main FITS file.
- Parameters:
is_final (bool, optional) – Whether this is the final (i.e., not intermediate) output. If so, recover the faded block boundaries.
- Return type:
None