forcepho.storage#

Classes in the forcepho.patches.storage module are used to store all of the pixel data and meta data (WCS, headers) for a given dataset.

storage.py

Interface with data on disk through storage objects.

class forcepho.patches.storage.MetaStore(metastorefile=None, use_gwcs=False, load_all=False)#

Storage for exposure meta data.

headers#

Dictionary of FITS headers, keyed by band and then expID

Type:

dict

wcs#

Dictionary of wcs objects, keyed by band and expID

Type:

dict

add_exposure(imset)#

Add the header for an exposure to the store.

Parameters:

imset (namespace) –

Must have the following attributes: * hdr - a FITS header containing WCS data * band - string, the band of the image * expID - string, unique identifier for the exposure the header

information refers to.

find_exposures(sky, bandlist)#

Find all exposures in the specified bands that cover the given sky position

Parameters:
  • sky (sequence of length 2) – ra, dec in decimal degrees of the target location

  • bandlist (list of strings) – The bands to search for images

Returns:

  • epaths (list of strings) – Exposure IDs for the exposures that cover the target.

  • bands (list of strings) – List of bands from the initial bandlist that actually have relevant images.

populate_wcs(gwcs_file=None)#

Fill the dict of dict with WCS instances (based on either normal astropy WCS objects or gWCS instances)

This is slow, so it;’s better to only make and cache wcs as needed.

read_from_file(filename)#

Read a json serialized dictionary of string headers

to_table(tablename, info=None, **kwargs)#

Write key exposure info to a FITS binary table

write_to_file(filename)#

Convert the FITS headers in the dictionary to strings, and dump the dictionary to a file using JSON.

Parameters:

filename (str) – The name of the file for the metadata. Will be overwritten if it already exists

class forcepho.patches.storage.PSFStore(h5file)#

Assumes existence of a file with the following structure

  • band/detector_locations

  • band/psfs

where psfs is a dataset like: `` >>> psfs = np.zeros(nloc, nradii, ngauss, dtype=pdt) >>> pdt = np.dtype([(‘gauss_params’, np.float32, 6), (‘sersic_bin’, np.int32)]) `` and the order of gauss_params is given in patch.cu; amp, x, y, Cxx, Cyy, Cxy

In principle ngauss can depend on i_radius

get_local_psf(band='F090W', source=None, wcs=None)#
Returns:

  • A structured array of psf parameters for a given source in a given band.

  • The structure of the array is something like

  • (amp, xcen, ycen, Cxx, Cyy Cxy, sersic_radius_index)

  • There are npsf_per_source rows in this array.

lookup(band, xy=None)#

Returns a array of shape (nradii x ngauss,) with dtype

class forcepho.patches.storage.PixelStore(h5file, nside_full=2048, super_pixel_size=8, pix_dtype=<class 'numpy.float32'>)#

Organization of the pixel data store is

bandID/expID/data

where data is an array of shape (nsuper, nsuper, 2*super_pixel_size**2) The first half of the trailing dimension is the pixel flux information, while the second half is the ierr information. Each dataset has attributes that describe the nominal flux calibration that was applied and some information about the subtracted background, mask, etc.

Parameters:
  • nside_full (int or 2-element array of ints, optional (default: 2048)) – The number of pixels along each dimension of the image. Must be an integer multiple of the super_pixel_size

  • super_pixel_size (int, optional (default: 8)) – The number of pixels along each side of a super-pixel

  • pix_dtype (numpy.dtype, optional (default: np.float32)) – The data type of the pixels.

data#

The h5py file handle used to access data on disk

Type:

instance of h5py.File()

xpix#

The (zero-indexed) x pixel coordinates of every pixel in an image, in super-pixel order.

Type:

ndarray of shape (nsuper, nsuper, super_pixel_size**2)

ypix#

The (zero-indexed) y pixel coordinates of every pixel in an image, in super-pixel order.

Type:

ndarray of shape (nsuper, nsuper, super_pixel_size**2)

add_exposure(imset, bitmask=None, do_fluxcal=False)#

Add an exposure to the pixel data store, including background subtraction (if nameset.bkg), flux conversion, setting ierr for masked pixels to 0, and super-pixel ordering. This opens the HDF5 files, adds the image data, and closes the file.

Parameters:

nameset (NamedTuple with attributes im, err, bkg, mask) – A set of names (including path) for a given exposure. Values of None or False for bkg and mask will result in no background subtraction and no masking beyond NaNs and infs

superpixel_corners(imsize=None)#
Returns:

corners – The coordinates in the full array of the corner pixels of each of the superpixels.

Return type:

ndarray of shape (nside_super, nside_super, 4, 2)

superpixelize(im, ierr, pix_dtype=None)#

Take native image data and reshape into super-pixel order.

Parameters:
  • im (ndarray of shape (nx, ny)) – Image pixel values

  • ierr (ndarray of shape (nx, ny)) – Image pixel inverse uncertainties

Returns:

superpixels – The image data and inverse uncdertainties in super-pixel order

Return type:

ndarray of shape (nsuper, nsuper, 2*super_pixel_size**2)