scopesim.optics.image_plane_utils module¶
- scopesim.optics.image_plane_utils.add_imagehdu_to_imagehdu(image_hdu, canvas_hdu, spline_order=1, wcs_suffix='', conserve_flux=True)[source]¶
Re-project one
fits.ImageHDU
onto anotherfits.ImageHDU
..assumption:: of equal grid coordinate lengths
- Parameters:
- image_hdufits.ImageHDU
The
ImageHDU
which will be reprojected onto canvas_hdu- canvas_hdufits.ImageHDU
The
ImageHDU
onto which the image_hdu should be projected. This must include a valid WCS- spline_orderint, optional
Default is 1. The order of the spline interpolator used by the
scipy.ndimage
functions- wcs_suffixstr
To determine which WCS to use. “” for sky HDUs and “D” for ImagePlane HDUs
- conserve_fluxbool
Default is True. Used when zooming and rotating to keep flux constant.
- Returns:
- canvas_hdufits.ImageHDU
- scopesim.optics.image_plane_utils.add_table_to_imagehdu(table, canvas_hdu, sub_pixel=True, wcs_suffix='')[source]¶
Add files from an astropy.Table to the image of an fits.ImageHDU
- Parameters:
- tableastropy.Table
Must contain the columns “x_mm”, “y_mm”, “flux” with the units in the column attribute .unit, or in the table.meta dictionary as “<colname>_unit”. Default units are
mm
andph / s / pix
- canvas_hdufits.ImageHDU
The ImageHDU onto which the table files should be projected. This must include a valid WCS
- sub_pixelbool, optional
Default is True. If True, sub-pixel shifts of files will be taken into account when projecting onto the canvas pixel grid. This takes about 5x longer than ignoring the sub-pixel shifts
- wcs_suffixstr, optional
- Returns:
- canvas_hdufits.ImageHDU
- scopesim.optics.image_plane_utils.affine_map(input, matrix=None, rotation_angle=0, shear_angle=0, scale_factor=None, reshape=True, spline_order=3)[source]¶
Applies an affine transformation matrix to an image around its centre
Similar functionality to
scipy.ndimage.rotate
but for theaffine_transformation
functionEither a 2x2 affine transformation matrix can be supplied, or the rotation, shear, and scaling values which are the basis of an affine transformation.
- Parameters:
- inputarray_like
The input array
- matrixndarray, optional
A 2x2 affine transformation matrix
- rotation_anglefloat, optional
[deg] If matrix==None, a rotation matrix is built from this angle
- shear_anglefloat, optional
[deg] If matrix==None, a y-axis shear matrix is built from this angle
- scale_factorlist, array
[mx, my] If matrix==None, a scaling matrix is built from this list
- reshapebool, optional
If True, the array is re-sized to contain the whole transformed image
- spline_orderint, optional
Default is 3. Spline interpolation order
- Returns:
- outputarray-like
The new mapping of the image
- scopesim.optics.image_plane_utils.calc_footprint(header, wcs_suffix='')[source]¶
Returns the sky/detector positions [deg/mm] of the corners of a header WCS
The positions returned correspond to the corners of the header’s image array, in this order:
(ra, dec) = (0,0), (w, 0), (w, h), (0, h) (x, y) = (0,0), (w, 0), (w, h), (0, h)
where
w
,h
are equal to NAXIS1 and NAXIS2 from the header.- Parameters:
- headerfits.Header
- wcs_suffixstr
Letter suffix for the WCS keywords, e.g. CDELT1D for image-plane coords
- Returns:
- x, yarrays of floats
[deg or mm] x are the coordinates for pixels [0, w, w, 0] [deg or mm] y are the coordinates for pixels [0, 0, h, h]
- scopesim.optics.image_plane_utils.get_canvas_header(hdu_or_table_list, pixel_scale=<Quantity 1. arcsec>)[source]¶
Generate a fits.Header with a WCS that covers everything in the FOV
- Parameters:
- hdu_or_table_listlist
A list of Tables and/or ImageHDU py_objects
- pixel_scaleastropy.Quantity
[arcsec] The pixel scale of the projection. Default in 1 arcsec
- Returns:
- headerfits.Header
A Header containing a WCS and NAXISn values to build an ImageHDU
- scopesim.optics.image_plane_utils.header_from_list_of_xy(x, y, pixel_scale, wcs_suffix='')[source]¶
Makes a header large enough to contain all x,y on-sky coordinates
- Parameters:
- x, ylist of floats
[deg, mm] List of sky coordinates to be bounded by the NAXISn keys
- pixel_scalefloat
[deg, mm]
- Returns:
- hdrfits.Header
- scopesim.optics.image_plane_utils.overlay_image(small_im, big_im, coords, mask=None, sub_pixel=False)[source]¶
Overlay small_im on top of big_im at the position specified by coords
small_im
will be centred atcoords
Adapted from:
https://stackoverflow.com/questions/14063070/overlay-a-smaller-image-on-a-larger-image-python-opencv
- scopesim.optics.image_plane_utils.pix2val(header, x, y, wcs_suffix='')[source]¶
Returns the real coordinates [deg, mm] for coordinates from a Header WCS
- Parameters:
- headerfits.Header
- x, yfloat, list, array
- wcs_suffixstr
- Returns:
- a, bfloat, array
[deg, mm] Real coordinates as given by the Header WCS
- scopesim.optics.image_plane_utils.reorient_imagehdu(imagehdu, wcs_suffix='', conserve_flux=True, spline_order=1)[source]¶
Applies an affine transformation to the image, as given in its header
- Parameters:
- imagehdufits.ImageHDU
- wcs_suffixstr
- conserve_fluxbool
- spline_orderint
[1..5] Order of the spline interpolation used by
scipy.ndimage.rotate
- Returns:
- imagehdufits.ImageHDU
- scopesim.optics.image_plane_utils.rescale_imagehdu(imagehdu, pixel_scale, wcs_suffix='', conserve_flux=True, spline_order=1)[source]¶
Scales the .data array by the ratio of pixel_scale [deg] and CDELTn
pixel_scale
should NOT be passed as a Quantity!- Parameters:
- imagehdufits.ImageHDU
- pixel_scalefloat
[deg] NOT to be passed as a Quantity
- wcs_suffixstr
- conserve_fluxbool
- spline_orderint
[1..5] Order of the spline interpolation used by
scipy.ndimage.rotate
- Returns:
- imagehdufits.ImageHDU
- scopesim.optics.image_plane_utils.split_header(hdr, chunk_size, wcs_suffix='')[source]¶
Splits a header into many smaller parts of the chunk_size
- Parameters:
- hdr
- chunk_size
- wcs_suffix
- Returns:
- scopesim.optics.image_plane_utils.sub_pixel_fractions(x, y)[source]¶
Makes a list of pixel coordinates and weights to reflect sub-pixel shifts
A point source which isn’t centred on a pixel can be modelled by a centred PSF convolved with a shifted delta function. A fraction of the delta function in moved into each of the adjoining pixels. For example, a star at
(x,y)=(0.2, 0.2)
would be represented by a following pixel weights:--------------- | 0.16 | 0.04 | --------------- | 0.64 | 0.16 | ---------------
where (0,0) is the centre of the bottom-left pixel
Given (x,y) pixel coordinates, this function returns the fractions of flux that should go into the surrounding pixels, as well as the coordinates of those neighbouring pixels.
- Parameters:
- x, yfloat
- Returns:
- x_pix, y_pix, fracslist of (int, int, float)
The x and y pixel coordinates and their corresponding flux fraction