LevelMatchStep

This step matches relative levels between tiles, using an algorithm very similar to Montage. We reproject tiles to a common astrometric grid, and then for each overlapping pair find the median per-pixel difference, and minimize for that. We do this in a two-pass process, firstly for dithers within a mosaic tile, and then for all mosaic tiles (creating stacked images). This maximises overlaps between mosaic tiles and produces better results from our testing.

N.B. This should be run once you have good local astrometry, and before you do MultiTileDestripeStep.

API

class pjpipe.LevelMatchStep(in_dir, out_dir, step_ext, procs, do_local_subtraction=True, sigma=3, npixels=3, dilate_size=7, max_iters=20, max_points=10000, do_sigma_clip=False, weight_method='equal', min_area_percent=0.002, min_linear_frac=0.25, rms_sig_limit=2, overwrite=False)[source]

Perform background matching between tiles

This step performs background matching by minimizing the per-pixel differences between overlapping tiles. It does this first for dither groups, before creating a stacked image of these (to maximize areal coverage) and minimizing between all stacked images within a mosaic. This is necessary for observations that don’t really have a background, and performs significantly better than the JWST implementation.

N.B. If you use this, skymatch in the level 3 pipeline stage should be global or off, to avoid undoing this work

Parameters:
  • in_dir – Input directory

  • out_dir – Output directory

  • step_ext – .fits extension for the files going into the step

  • procs – Number of parallel processes to run

  • do_local_subtraction – Whether to do a sigma-clipped local median subtraction. Defaults to True

  • sigma – Sigma for sigma-clipping. Defaults to 3

  • npixels – Pixels to grow for masking. Defaults to 5

  • dilate_size – make_source_mask dilation size. Defaults to 7

  • max_iters – Maximum sigma-clipping iterations. Defaults to 20

  • max_points – Maximum points to include in histogram plots. This step can be slow so this speeds it up. Defaults to 10000

  • do_sigma_clip – Whether to do sigma-clipping on data when reprojecting. Defaults to False

  • weight_method – How to weight in least-squares minimization. Options are ‘equal’ (equal weighting), ‘npix’ (weight by number of pixels), and ‘rms’ (weight by rms of the delta values). Defaults to ‘equal’

  • min_area_percent – Minimum percentage of average areal overlap to remove tiles. Defaults to 0.002 (0.2%)

  • min_linear_frac – Minimum linear overlap in any direction to keep tiles. Defaults to 0.25

  • rms_sig_limit – Sigma limit for cutting off noisy fits. Defaults to 2

  • overwrite – Whether to overwrite or not. Defaults to False

calculate_delta(files, stacked_image=False, procs=None)[source]

Match relative offsets between tiles

Parameters:
  • files (list) – List of files to match

  • stacked_image – Whether this is a stacked image or not. Default to False

  • procs (int, optional) – Number of processes to run in parallel. Defaults to None, which is series

do_step()[source]

Run level matching

find_optimum_deltas(delta_mat, npix_mat, rms_mat, lin_size_mat)[source]

Get optimum deltas from a delta/weight matrix.

Taken from the JWST skymatch step, with some edits to remove potentially bad fits due to small areal overlaps, or noisy diffs, and various weighting schemes

Parameters:
  • delta_mat (np.ndarray) – Matrix of delta values

  • npix_mat (np.ndarray) – Matrix of number of pixel values for calculating delta

  • rms_mat (np.ndarray) – Matrix of RMS values

  • lin_size_mat (np.ndarray) – 1/0 array for whether overlaps pass minimum linear extent

get_level_match(files1, files2, plot_name=None, maxiters=10)[source]

Calculate relative difference between groups of files on the same pixel grid

Parameters:
  • files1 – List of files to get difference from

  • files2 – List of files to get relative difference to

  • plot_name – Output plot name. Defaults to None

  • maxiters – Maximum iterations for the sigma-clipping. Defaults to 10

get_per_dither_delta(dithers, procs=1)[source]

Function to parallelise getting the delta for each observation in a dither sequence

Parameters:
  • dithers – List of dithers to get deltas for

  • procs – Number of processes to run simultaneously. Defaults to 1

get_plot_name(files1, files2)[source]

Make a plot name from list of files for level matching

Parameters:
  • files1 – First list of files

  • files2 – Second list of files

get_reproject(file, optimal_wcs, optimal_shape, stacked_image=False)[source]

Reproject files, maintaining list structure

Parameters:
  • file – List or single file to reproject

  • optimal_wcs – WCS to reproject to

  • optimal_shape – output array shape for the WCS

  • stacked_image (bool) – Whether this is a stacked image or not. Defaults to False

make_stacked_images(dithers, stacked_dir, procs=1)[source]

Function to parallellise up making stacked dither images

Parameters:
  • dithers – List of dithers to go

  • stacked_dir – Where to save stacked images to

  • procs – Number of simultaneous processes to run. Defaults to 1

parallel_delta_matrix(ij, file_reproj, files)[source]

Function to parallelise up getting delta matrix values

Parameters:
  • ij – List of matrix (i, j) values

  • file_reproj – Reprojected file

  • files – Full list of files

parallel_get_reproject(idx, files, optimal_wcs, optimal_shape, stacked_image=False)[source]

Light function to parallelise get_dither_reproject

Parameters:
  • idx – File idx to reproject

  • files – Full file list

  • optimal_wcs – Optimal WCS for input stack of images

  • optimal_shape – Optimal shape for input stack of images

  • stacked_image – Stacked image or not? Defaults to False

parallel_make_stacked_image(dither, out_dir)[source]

Light wrapper around parallelising the stacked image

Parameters:
  • dither – Dither to stack

  • out_dir – Directory to save to

parallel_per_dither_delta(dither)[source]

Function to parallelise up matching dithers

Parameters:

dither – Input dither