pynrc.maths.image_manip.subtract_psf

pynrc.maths.image_manip.subtract_psf(image, psf, osamp=1, bpmask=None, rin=None, rout=None, xyshift=(0, 0), psf_scale=None, psf_offset=0, method='fourier', interp='lanczos', pad=True, cval=0, kipc=None, kppc=None, diffusion_sigma=None, psf_corr_over=None, weights=None, return_sum2=False, return_scale=False, **kwargs)[source]

Subtract PSF from image

Provide scale, offset, and shift values to PSF before subtraction. Uses fractional_image_shift function to shift PSF.

Parameters:
  • image (ndarray) – Observed science image.

  • psf (ndarray) – Oversampled PSF (shifted and scaled to match).

  • osamp (int) – Oversampling factor of PSF.

  • bpmask (bool array) – Bad pixel mask indicating pixels in input image to ignore.

  • rin (float) – Inner radius of annulus for subtraction. Default is None.

  • rout (float) – Outer radius of annulus for subtraction. Default is None.

  • xyshift (tuple) – Shift values in (x,y) directions. Units of pixels.

  • psf_scale (float) – Scale factor to apply to PSF. If set to None, then will find the best scaling factor.

  • psf_offset (float) – Offset to apply to PSF.

  • psf_corr_over (ndarray) – Oversampled PSF correction image. If provided, then this image is multiplied with the PSF after diffusion. These are empirical corrections to the STPSF model to better match the observed PSF.

  • kipc (ndarray) – 3x3 array of IPC kernel values. If None, then no IPC is applied.

  • kppc (ndarray) – 3x3 array of PPC kernel values. If None, then no PPC is applied. Should already be oriented along readout direction of PSF.

  • diffusion_sigma (float) – Sigma value for Gaussian diffusion kernel. If None, then no diffusion is applied. In units of detector pixels.

  • weights (ndarray) – Array of weights to use during the fitting process. Useful if you have bad pixels to mask out (ie., set them to zero). Default is None (no weights). Should be same size as image. Recommended is inverse variance map.

  • method (str) – Method to use for shifting. Options are: - ‘fourier’ : Shift in Fourier space - ‘fshift’ : Shift using interpolation - ‘opencv’ : Shift using OpenCV warpAffine

  • interp (str) – Interpolation method to use for shifting using ‘fshift’ or ‘opencv. Default is ‘cubic’. For ‘opencv’, valid options are ‘linear’, ‘cubic’, and ‘lanczos’. for ‘fshift’, valid options are ‘linear’, ‘cubic’, and ‘quintic’.

  • pad (bool) – Should we pad the array before shifting, then truncate? Otherwise, the image is wrapped.

  • cval (sequence or float, optional) – The values to set the padded values for each axis. Default is 0. ((before_1, after_1), … (before_N, after_N)) unique pad constants for each axis. ((before, after),) yields same before and after constants for each axis. (constant,) or int is a shortcut for before = after = constant for all axes.

  • return_sum2 (bool) – Return the sum of the squared difference between the image and PSF. Default is False.

Keyword Arguments:
  • gstd_pix (float) – Standard deviation of Gaussian kernel to blur PSF during shift.

  • oversample (int) – Oversampling factor for fractional shift. Default is 1.

  • order (int) – Interpolation order for oversampling during shifting. Default is 1.

  • rescale_pix (bool) – Explicitly rescale the pixel values during resampling to ensure that the flux within a superpixel is preserved. Default is False (zoom default behavior).