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

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.

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.

__init__()[source]

Constructor.

generate_idx_grid()[source]

Generate a grid of indices (staticmethod).

_inpix2world2outpix()[source]

Composition of pix2world and world2pix.

outpix2world2inpix()[source]

Inverse function of _inpix2world2outpix.

partition_pixels()[source]

Partition input pixels into postage stamps.

extract_layers()[source]

Extract input layers.

clear()[source]

Free up memory space.

smooth_and_pad()[source]

Utility to smear a PSF with a tophat and a Gaussian (staticmethod).

LPolyArr()[source]

Utility to generate an array of Legendre polynomials (staticmethod).

psf_filename()[source]

PSF file name broker (staticmethod).

get_psf_pos()[source]

Get input PSF array at given position.

blk[source]
idsca[source]
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

extract_layers(verbose: bool = False) None[source]

Extract input layers.

Return type:

None

clear() None[source]

Free up memory space.

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.

__init__()[source]

Constructor.

make_selection()[source]

Return the indices of selected input pixels.

get_inpsfgrp()[source]

Get the input PSFGrp attached to this InStamp.

clear()[source]

Free up memory space.

blk[source]
j_st[source]
i_st[source]
pix_count[source]
pix_cumsum[source]
y_val[source]
x_val[source]
data[source]
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) 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.

Return type:

None

clear() None[source]

Free up memory space.

class OutStamp(blk: Block, j_st: int, i_st: int)[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.

__init__()[source]

Constructor.

_process_input_stamps()[source]

Fetch and process input postage stamps.

__call__()[source]

Build system matrices and perform coaddition.

_build_system_matrices()[source]

Build system matrices and coaddition matrices.

_visualize_system_matrices()[source]

Visualize system matrices.

_visualize_coadd_matrices()[source]

Visualize coaddition matrices.

trapezoid()[source]

Apply a trapezoid filter to transition pixels (staticmethod).

_perform_coaddition()[source]

Perform the actual multiplication.

_visualize_weight_computations()[source]

Display weight computations.

_show_in_and_out_images()[source]

Display input and output images.

_study_individual_pixels()[source]

Study individual input and output pixels.

clear()[source]

Free up memory space.

LAKERNEL[source]
blk[source]
j_st[source]
i_st[source]
ji_st_in_s[source]
no_qlt_ctrl = False[source]
bottom[source]
top[source]
left[source]
right[source]
yx_val[source]
_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

_visualize_system_matrices() None[source]

Visualize system matrices.

_visualize_coadd_matrices() None[source]

Visualize coaddition matrices.

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

_visualize_weight_computations() None[source]

Display weight computations.

_show_in_and_out_images() None[source]

Display input and output images.

_study_individual_pixels() None[source]

Study individual input and output pixels.

clear() None[source]

Free up memory space.

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.

__init__()[source]

Constructor.

__call__()[source]

Coadd this block.

parse_config()[source]

Parse the configuration.

_get_obs_cover()[source]

Get observations relevant to this Block.

_build_use_instamps()[source]

Build the Boolean array use_instamps.

_handle_postage_pad()[source]

Handle the postage padding.

process_input_images()[source]

Process input images.

build_input_stamps()[source]

Build input stamps from input images.

_output_stamp_wrapper()[source]

Wrapper for output stamp coaddition.

coadd_output_stamps()[source]

Coadd output stamps using input stamps.

compress_map()[source]

Compress float32 map to (u)int16 to save storage.

build_output_file()[source]

Build the output FITS file.

clear_all()[source]

Free up all memory spaces.

timer[source]
cfg = None[source]
this_sub = 0[source]
__call__() None[source]

Coadd this block.

parse_config() None[source]

Parse the configuration.

_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.

_handle_postage_pad() None[source]

Handle the postage padding.

process_input_images(visualize: bool = False) None[source]

Process input images.

build_input_stamps() None[source]

Build input stamps from input images.

_output_stamp_wrapper(i_st, j_st, n_coadded, sim_mode: 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.

Return type:

None

coadd_output_stamps(sim_mode: 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.

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

clear_all() None[source]

Free up all memory spaces.