OversampledImagePSF

class snappl.psf.OversampledImagePSF(oversample_factor=1.0, data=None, enforce_odd=True, normalize=False, _parent_class=False, **kwargs)[source]

Bases: PSF

A PSF stored internally in an image which is (possibly) oversampled.

This one requires an odd integral oversampling factor. If your PSF is not intrinsically undersampled, you may be able to get away with using the faster and more flexible Sampling_OversampledImagePSF.

get_stamp will tophat-convolve and interpolate the internally stored oversampled image to get an source-image-scale sampled PSF using an interpolation algorithm that’s close to what PSFex uses.

The internally stored data array is a copy of what is passed. So, if you have an OversampledImagePSF oipsf and do:

oipsf.oversampled_data = data

it does not work the way you’d usually expect for arrays. (That is, if you change elements of data thereafter, it will not be reflected in the data array stored inside OversampledImagePSF.)

If you have an oversampled image PSF, this is the class that you want to use for things like scene modelling.

WARNING : I don’t think using these PSFs with get_stamp() will do the right thing with photutils for intrinsically undersampled PSFs (e.g. a Gaussian with σ=0.3pix). See Issue #157.

Make an OversampledImagePSF.

Parameters:
  • x (float) –

    Required. Position on the source image where this PSF is evaluated. Most of the time, but not always, you probably want x and y to be integer values. (As in, not integer typed, but floats that satisfy x-floor(x)=0.) These are also the defaults that get_stamp will use if x and y are not passed to get_stamp.

    If x and/or y have nonzero fractional parts, then the data array must be consistent. First consider non-oversampled data. Suppose you pass a 11×11 array with x=1022.5 and y=1023.25. In this case, the peak of a perfectly symmetric PSF image on data would be at (4.5, 5.25). (Not (5.5, 5.25)! If something’s at exactly .5, always round down here regardless of wheter the integer part is even or odd.) The center pixel and the one to the right of it should have the same brightness, and the pixel just below center should be dimmer than the pixel just above center.

    For oversampled psfs, the data array must be properly shifted to account for non-integral x and y. The shift will be as in non-oversampled data, only multiplied by the oversampling factor. So, in the same example, if you specify a peak of (4.5, 5.25), and you have an oversampling factor of 3, you should pass a 33×33 array with the peak of the PSF (assuming a symmetric PSF) at (14.5, 16.75).

    Note that for off-centered PSFs (meaning the PSF is not centered on the passed data array), the meaning of (x, y) in this constructor is different from the meaning of (x, y) in the photutilsImagePSF constructor. Use intrinsically off-center PSFs at your own peril. (Note that you can always render stamps with off-centered PSFs in get_stamp(), regardless of whether the PSF itself is intrinsically centered or not.)

  • y (float) –

    Required. Position on the source image where this PSF is evaluated. Most of the time, but not always, you probably want x and y to be integer values. (As in, not integer typed, but floats that satisfy x-floor(x)=0.) These are also the defaults that get_stamp will use if x and y are not passed to get_stamp.

    If x and/or y have nonzero fractional parts, then the data array must be consistent. First consider non-oversampled data. Suppose you pass a 11×11 array with x=1022.5 and y=1023.25. In this case, the peak of a perfectly symmetric PSF image on data would be at (4.5, 5.25). (Not (5.5, 5.25)! If something’s at exactly .5, always round down here regardless of wheter the integer part is even or odd.) The center pixel and the one to the right of it should have the same brightness, and the pixel just below center should be dimmer than the pixel just above center.

    For oversampled psfs, the data array must be properly shifted to account for non-integral x and y. The shift will be as in non-oversampled data, only multiplied by the oversampling factor. So, in the same example, if you specify a peak of (4.5, 5.25), and you have an oversampling factor of 3, you should pass a 33×33 array with the peak of the PSF (assuming a symmetric PSF) at (14.5, 16.75).

    Note that for off-centered PSFs (meaning the PSF is not centered on the passed data array), the meaning of (x, y) in this constructor is different from the meaning of (x, y) in the photutilsImagePSF constructor. Use intrinsically off-center PSFs at your own peril. (Note that you can always render stamps with off-centered PSFs in get_stamp(), regardless of whether the PSF itself is intrinsically centered or not.)

  • data (2d numpy array or None) –

    The image data of the oversampled PSF. If None, then this needs, somehow, to be set later. (Usually that will be handled by something in a subclass of OversampledImagePSF; if you’re setting it manually, you’re probably doing something wrong.) data.sum() should be equal to the fraction of the PSF flux captured within the boundaries of the data array. (However, see “normalize” below.) The array must be square, and unless enforce_odd is false, the length of one side must be an odd number. Usually the peak of the PSF (assuming a symmetric PSF– if not, replace “peak” with “center” or “fiducial point” or however you think about it) will be centered on the center pixel fo the array. ALWAYS the peak of the PSF must be centered within 0.5 non-oversampled pixels of the center of the array. (That is, if the oversampling factor is 3, the peak of the PSF will be centered within 1.5 pixels of the center of the passed array.) See (x,y) below for discussion of positioning the PSF on the passed data array.

    A copy of the passed data is stored, not the actual passed data, so if you change elements of the array you passed after making the OversampledImagePSF, it won’t be reflected inside the OversampledImagePSF.

  • oversample_factor (float, default 1, must be odd) – There are this many pixels along one axis in data for one pixel in the original image. Doesn’t have to be an integer (e.g. if you used PSFex to find the PSF, it usually won’t be— though if you used PSFex to find the PSF, really we should be writing a subclass to handle that!).

  • enforce_odd (bool, default True) – Enforce the requirement that the data array have an odd length along each axis.

  • normalize (bool, default False) – Ignored if data is not None. If True, then this constructor will make sure that data sums to 1 (modifying the passed data array in so doing!). If you think that the data array is big enough that you’re effectively capturing 100% of the PSF flux, then you should set normalize to True. If not, then you should make sure that the data array you pass sums to the fraction of the PSF flux that you’re passing, and set normalize to False. Usually you don’t want to change this, and you want to trust subclases to do the Right Thing.

  • _parent_class (bool, default False) – Used internally, do not use.

Return type:

object of type cls

Attributes Summary

oversample_factor

oversampled_data

stamp_size

The size of the PSF image stamp at image resolution.

Methods Summary

getImagePSF([imagesampled])

Return a photutils.psf.ImagePSF model.

get_stamp([x, y, x0, y0, flux])

See PSF.get_stamp for documentation.

Attributes Documentation

oversample_factor
oversampled_data
stamp_size

The size of the PSF image stamp at image resolution. Is always odd.

Methods Documentation

getImagePSF(imagesampled=True)[source]

Return a photutils.psf.ImagePSF model. See PSF.getImagePSF.

get_stamp(x=None, y=None, x0=None, y0=None, flux=1.0)[source]

See PSF.get_stamp for documentation.