forcepho.patches#
Classes in the forcepho.patches module are used to organize pixel and
meta data for small regions on the sky, and to communicate that data to the GPU
when required.
- class forcepho.patches.FITSPatch(fitsfiles='', psfstore='', splinedata='', spline_smoothing=None, return_residual=False, sci_ext='SCI', unc_ext='ERR', meta_dtype=<class 'numpy.float32'>, pix_dtype=<class 'numpy.float32'>, debug=0)#
This class converts pixel data and meta-data (WCS) information stored in FITS files and headers to the data formats required by the device-side code.
- Parameters:
fitsfiles (list of string) – Paths to the FITS image and uncertainty data.
- find_exposures(region, bandlist, do_check=True)#
Return a list of headers (dict-like objects of wcs, filter, and exposure id) and exposureIDs for all exposures that overlap the region. These should then be sorted by integer band_id.
- Parameters:
region (region.Region instance) – Exposures will be found which overlap this region
bandlist (list of str) – A list of band names to search for images.
- Return type:
hdrs, wcses, epaths, bands
- class forcepho.patches.Patch(psfstore='', splinedata='', spline_smoothing=None, return_residual=False, meta_dtype=<class 'numpy.float32'>, pix_dtype=<class 'numpy.float32'>, debug=0)#
Subclass of PatchBase that includes logic for setting meta data arrays given
forcepho.sources.Sceneinstances and lists of FITS header dictionaries and WCS instances.- Parameters:
psfstore (string) – Path to HDF5 file with PSF gaussian mixture parameters, stored as datasets for each band.
splinedata (string) – Path to HDF5 file with Gaussian mixture parameters for Sersic profile approximations.
- bandlist#
- Type:
list of str
- pack_meta(scene)#
This method packs all the exposure and source metadata. Most of this data is scene/source dependent, so in this way we can change the scene without repacking the pixel data. This requires the following attributes to have been set: * uniq_bands [NBAND] * bandlist [NBAND] * n_exp_per_band [ NBAND] * n_exp [1] * wcses [NEXP] * hdrs [NEXP] * bands [NEXP]
- Parameters:
scene (instance of
forcepho.sources.Scene) – The scene to use for generating metadata.
- set_scene(sourcecat, splinedata=None)#
Build a scene made of sources with the appropriate filters using
- Parameters:
sourcecat (structured ndarray of shape (n_sources,)) – A structured array of source parameters. The fields of the of the structured array must correspond to the fundamental parameters of the Galaxy sourcetype (‘ra’, ‘dec’, ‘q’, ‘pa’, ‘sersic’, ‘rhalf’) as well as have flux fields with the same column names as self.bandlist.
- Returns:
scene
- Return type:
An instance of sources.Scene
- split_band(attr)#
Split the pixel data into separate arrays for each band.
- Parameters:
attr (string) – The Patch attribute to split into separate exposures. One of xpix | ypix | data | ierr
- Returns:
asplit – List of N_band ndarrays of shape (n_pix_band,) each containing the attr pixel information for that band. List order is the same as self.bandlist
- Return type:
list of ndarrays
- split_pix(attr)#
Split the pixel data into separate arrays for each exposure.
- Returns:
pixdat – List of N_exp ndarrays, each containing the attr pixel information for that exposure. List order is the same as self.epaths
- Return type:
list of ndarray
- zerocoords(scene, sky_zero=None)#
Reset (in-place) the celestial zero point of the image metadata and the source coordinates to avoid catastrophic cancellation errors in coordinates when using single precision.
- Parameters:
scene (sources.Scene() instance) – A Scene object, where each source has the attributes ra, dec,
sky_zero (optional, 2-tuple of float64) – The (ra, dec) values defining the new central coordinates. These will be subtracted from the relevant source and stamp coordinates. If not given, the median coordinates of the scene will be used.
- Returns:
reference_coordinates – The new reference coordinates, all source positions are offsets from this. This should be subtracted from crval coordinates.
- Return type:
ndaray of shape (2,)
- class forcepho.patches.StorePatch(pixelstore='', metastore='', psfstore='', splinedata='', spline_smoothing=None, return_residual=False, meta_dtype=<class 'numpy.float32'>, pix_dtype=<class 'numpy.float32'>, debug=0)#
This class converts between JADES-like exposure level pixel data, meta-data (WCS), and PSF information stored in HDF5 pixel and meta stores to the data formats required by the device-side code.
- Parameters:
pixelstore (string) – Path to HDF5 file to be used for
forcepho.patches.storage.PixelStoremetastore (string) – Path to json file containing associated metadata for the pixel store. Used to instantiate
forcepho.patches.storage.MetaStore.
- find_exposures(region, bandlist)#
Return a list of headers (dict-like objects of wcs, filter, and exposure id) and exposureIDs for all exposures that overlap the region. These should be sorted by integer band_id.
- Parameters:
region (region.Region instance) – Exposures will be found which overlap this region
bandlist (list of str) – A list of band names to search for images.
- Return type:
hdrs, wcses, epaths, bands
- find_pixels(epath, wcs, region)#
Find all super-pixels in an image described by hdr that are within a given region, and return lists of the super-pixel data
- Parameters:
epath (string) – The path to the exposure data in the HDF5 pixelstore, in the form “[band]/[expID]”
wcs (An instance of astropy.wcs.WCS) – The WCS for the exposure.
region (An instance of region.Region) – The sky region within which to find pixels
- Returns:
data (ndarray of shape (npix,)) – The fluxes of the valid pixels
ierr (ndarray of dhape (npix,)) – The inverse errors of the valid pixels
xpix (ndarray of shape (npix,)) – The x pixel coordinates in the exposure of the valid pixels
ypix (ndarray of shape (npix,)) – The y-pixel coordinates in the exposure of the valid pixels