forcepho.sources#

Classes in the forcepho.sources module are used to represent individual galaxies and collections of galaxies (called Scenes).

sources.py

Module for objects describing individual sources and collections of sources (Scenes)

class forcepho.sources.Galaxy(filters=['band'], filternames=None, radii=None, free_sersic=True, splinedata=None, spline_smoothing=None, spline_type='rect')#

Parameters describing a gaussian galaxy in the celestial plane (i.e. the Scene parameters) All 7 Source parameters are relevant: * flux: total flux * ra: right ascension (degrees) * dec: declination (degrees) * q, pa: axis ratio squared and position angle * sersic: sersic index * rhalf: half-light radius (arcsec)

Methods are provided to return the amplitudes and covariance matrices of the constituent gaussians, as well as derivatives of the amplitudes with respect to sersic index and half light radius.

The amplitudes and the derivatives of the amplitudes with respect to the sersic index and half-light radius are based on splines.

Note that only instances of Galaxy with free_sersic = True can generate proposals for the GPU

property amplitudes#

Code here for getting amplitudes from a splined look-up table (dependent on self.n and self.r). Placeholder code gives them all equal amplitudes.

property covariances#

This just constructs a set of covariance matrices based on the fixed radii used in approximating the galaxies.

property damplitude_drh#

Code here for getting amplitude derivatives from a splined look-up table (dependent on self.n and self.r)

property damplitude_dsersic#

Code here for getting amplitude derivatives from a splined look-up table (dependent on self.n and self.r)

get_param_vector(filtername=None)#

Get the relevant source parameters as a simple 1-D ndarray.

initialize_splines(splinedata, spline_smoothing=None, spline_type='rect')#

Initialize Bivariate Splines used to interpolate and get derivatives for gaussian amplitudes as a function of sersic and rhalf

profile(r, band=None, epsilon=0.0025)#

Compute the circularized surface brightness profile.

Parameters:
  • r (ndarray of shape (nr,)) – The radii at which surface brightnesses are to be computed. Units of arcsec.

  • band (string, optional) – The name of the filter for the flux value to normalize the profile. If not given the profile will be normalized to a total flux of 1.

  • epsilon (float) – A small smoothing to apply to the mixture component radii, to handle delta function components.

Returns:

mu – The surface brightness of the profile at the given radii. Units of flux/arcsec^2.

Return type:

ndarray of shape (nr,)

proposal()#

A parameter proposal in the form required for transfer to the GPU

set_params(parvector, filtername=None)#

Set the parameters (flux(es), ra, dec, q, pa, n_sersic, r_h) from a parvector array. Assumes that the order of parameters in the parameter vector is [flux1, flux2…fluxN, ra, dec, q, pa, sersic, rhalf]

Parameters:
  • parvector (Sequence of length n_bands+npos+nshape or 1+npos+nshape) – The source parameter values that are to be set.

  • filtername (string or None (optional, default: None)) – If supplied, the parameter vector is assumed to be 7-element (flux_i, ra, dec, q, pa) where flux_i is the source flux through the filter given by filtername. If None then the parameter vector is assumed to be of length self.n_bands + 6, where the first n_bands elements correspond to the fluxes.

class forcepho.sources.Scene(sources=[], catalog=None, **catkwargs)#

The Scene holds the sources and provides the mapping between a giant 1-d array of parameters and the parameters of each source in each band/image

property active_sources#

A list of the active source objects. Convenience.

property fixed_sources#

A list of the fixed source objects. Convenience.

from_catalog(catalog, filternames=['band'], extra_parameters=[], source_type=None, **source_kwargs)#

Generate a scene from a structured array of source parameters. Convenience.

Parameters:
  • catalog (structured ndarray) – The columns of this array must include the SHAPE_COLS of the specified source type. There must also be flux_<b> columns where <b> are the elements of the provided filternames list

  • source_type (One of the Source subclasses defined here.) – All sources in the scene will be of this class.

  • filternames (list of strings) – A list of the filternames, corresponding to the flux_<b> columns of the supplied catalog

  • source_kwargs (optional) – Extra keyword parameters used to instantiate each Source.

get_all_source_params(active=True)#

Get the scene parameter vector for active sources.

This is convenience (rarely used)

Returns:

Theta – The source parameters for all (active) sources.

Return type:

ndarray of shape (n_source*n_param_per_source)

get_proposal(active=True)#

Get the parameters of all sources in the scene as a GPU-ready propsal structure.

This is important.

Returns:

proposal – An array of source parameters, packed into a Numpy array (and thus ready to send to the GPU).

Return type:

ndarray of dtype source_struct_dtype

identify_sources()#

Give each source in the scene a unique identification number.

property n_active#

Number of active sources. Convenience.

property n_fixed#

Number of fixed sources. Convenience.

param_indices(sid, filtername=None)#

Get the indices of the relevant parameters in the giant Theta vector. Assumes that the order of parameters for each source is is [flux1, flux2…fluxN, pos1, pos2, shape1, shape2, …, shapeN]

This used in the SLOW likelihoods.

Parameters:
  • sid (int) – Source ID

  • filtername (string or None (optional, default: None)) – The name of the filter for which you want the corresponding flux parameter index. If None (default) then indices for all fluxes are returned

Returns:

inds – Indices of the parameters for this source.

Return type:

ndarray of ints

property parameter_names#

Get names for all the parameters in the scene

set_all_source_params(Theta)#

Loop over active sources in the scene, setting the parameters in each source based on the relevant subset of Theta parameters.

This is important.

Parameters:

Theta (list or ndarray) – List of all active source parameters

to_catalog(extra_cols=[])#

Get a structured array of parameters corresponding to the sources in the scene. Convenience.

Returns:

catalog – Each row of the structured array is a source, the columns have the names of the source parameters, with one column for each flux element, having the name of the filter. Extra columns or source attributes spoecified by ‘extra_cols’ will be included.

Return type:

structured ndarray

class forcepho.sources.Source(filters=['band'], radii=None)#

Parameters describing a source in the celestial plane. For each galaxy there are 7 parameters, only some of which may be relevant for changing the apparent flux: * flux: total flux (possibly a vector) * ra: right ascension (degrees) * dec: declination (degrees) * q, pa: axis ratio squared and position angle * n: sersic index * r: half-light radius (arcsec)

Methods are provided to return the amplitudes and covariance matrices of the constituent gaussians, as well as derivatives of the amplitudes with respect to sersic index and half light radius.

property amplitudes#

Code here for getting amplitudes from a splined look-up table (dependent on self.n and self.r). Placeholder code gives them all equal amplitudes.

property damplitude_drh#

Code here for getting amplitude derivatives from a splined look-up table (dependent on self.sersic and self.rhalf)

property damplitude_dsersic#

Code here for getting amplitude derivatives from a splined look-up table (dependent on self.sersic and self.rhalf)

filter_index(filtername)#

Returns the index of the element of the flux array that corresponds to the supplied filtername.

Parameters:

filtername (string) – The name of the filter for which you want the corresponding flux vector index.

Returns:

index – An index that when used to subscript the flux attribute gives the source flux in filtername

Return type:

int

from_catalog_row(row, extra_parameters=[], filternames=None)#

Set source parameters from the row of a structured array. Convenience.

get_param_vector(filtername=None)#

Get the relevant source parameters as a simple 1-D ndarray.

Returns:

parvector – The source parameters as a simple vector

Return type:

ndarray of shape (self.n_bands + self.nshape)

property n_bands#

Number of elements of the flux vector (corresponding to the filters in filternames)

property n_gauss#

Total number of gaussians used to describe the source.

property n_params#

Total number of source parameters, including position, shape, and flux(es)

psfgauss(e, psf_dtype=None)#

Pack the source and exposure specific PSF parameters into a simple array. This assumes that the stamp_psfs attribute has been populated with an NEXPOSURE length list, where each element of the list is in turn a list of the the n_gauss PointSpreadFunction objects for this source and exposure. Used for filling StaticPatch

Parameters:
  • e (int) – The exposure number

  • psf_dtype (optional) – The data type of the returned array

Returns:

psf_params – The PSF parameters, in the format `[((a, x, y, cxx, cyy, cxy), radius_index), ((a, x, y, cxx, cyy, cxy), radius_index), .....] `

Return type:

list of tuples or ndarray

render(stamp, compute_deriv=True, **compute_keywords)#

Render a source on a PostageStamp. This uses slow methods. Convenience.

Parameters:
  • stamp (An instance of stamp.PostageStamp())

  • compute_deriv (bool (optional, default: True)) – If True, return the gradients of the image with respect to the relevant free parameters for the source.

Returns:

  • image (ndarray of shape (stamp.npix)) – The flux of this source in each pixel of the stamp

  • gradients (ndarray of shape (nderiv, stamp.npix). Optional.) – The gradients of the source flux in each pixel with respect to source parameters

set_params(parvector, filtername=None)#

Set the relevant parameter attributes from a sequence of parameters.

Parameters:
  • parvector (Sequence of length n_bands+nshape or 1+nshape) – The source parameter values that are to be set.

  • filtername (string or None (optional, default: None)) – If supplied, the given vector is assumed to be of length 1 + self.nshape where the first element is the source flux through the filter given by filtername. If None then the vector is assumed to be of length self.n_bands + self.nshape, where the first n_bands elements correspond to the fluxes.

to_catalog_row(extra_cols=[])#

Output source parameters as the row of a structured array

property use_gradients#

Which of the 7 gradients (d/dFlux, d/dRA, d/dDec, d/dq, d/dpa, d/dsersic, d/drh) will you actually use?

Used by SLOW likelihoods