webbpsf_ext.image_manip.crop_observation

webbpsf_ext.image_manip.crop_observation(im_full, ap, xysub, xyloc=None, delx=0, dely=0, shift_func=<function fourier_imshift>, interp='cubic', return_xy=False, fill_val=nan, **kwargs)[source]

Crop around aperture reference location

xysub specifies the desired crop size. if xysub is an array, dimension order should be [nysub,nxsub]. Crops at pixel boundaries (no interpolation) unless delx and dely are specified for pixel shifting.

xyloc provides a way to manually supply the central position. Set ap to None will crop around xyloc or center of array.

delx and delx will shift array by some offset before cropping to allow for sub-pixel shifting. To change integer crop positions, recommend using xyloc instead.

Shift function can be fourier_imshfit, fshift, or cv_shift. The interp keyword only works for the latter two options. Consider ‘lanczos’ for cv_shift.

Setting return_xy to True will also return the indices used to perform the crop.

Parameters:
  • im_full (ndarray) – Input image.

  • ap (pysiaf aperture) – Aperture to use for cropping. Will crop around the aperture reference point by default. Will be overridden by xyloc.

  • xysub (int, tuple, or list) – Size of subarray to extract. If a single integer is provided, then a square subarray is extracted. If a tuple or list is provided, then it should be of the form (ny, nx).

  • xyloc (tuple or list) – (x,y) pixel location around which to crop the image. If None, then the image aperture refernece point is used.

Keyword Arguments:
  • delx (int or float) – Pixel offset in x-direction. This shifts the image by some number of pixels in the x-direction. Positive values shift the image to the right.

  • dely (int or float) – Pixel offset in y-direction. This shifts the image by some number of pixels in the y-direction. Positive values shift the image up.

  • shift_func (function) – Function to use for shifting. Default is fourier_imshift. If delx and dely are both integers, then fshift is used.

  • interp (str) – Interpolation method to use for shifting. Default is ‘cubic’. Options are ‘nearest’, ‘linear’, ‘cubic’, and ‘quadratic’ for fshift.

  • return_xy (bool) – If True, then return the x and y indices used to crop the image prior to any shifting from delx and dely; (x1, x2, y1, y2). Default is False.

  • fill_val (float) – Value to use for filling in the empty pixels after shifting. Default = np.nan.