Concrete sources

In the nomenclature of Gravity.jl, source types are associated to objects without error measurements, while image types have error measurements attached. Each source type has generally an associated image type. For example, a point-like object characterized by its position and luminosity is represented as a LuminousSource; the corresponding object with position and luminosity errors is instead a LuminousImageMeasurement.

Note that both source- and image-types, however, can be used to represent objects in the image plane or in the source plane. For example, a point-like observed image will be described as a PointImageMeasurement, but the same type can be used to represent the inferred position of a source, with associated errors. This is typically done in scheme: sourceplane or scheme: simplified-imageplane. A point source in scheme: imageplane is described as a PointSource; however, the same type is also used to described the associated predicted images.

In addition, Gravity.jl has also a container type to represent an homogeneous collection of source- or image-types. This generally needed to describe image families (i.e, images generated by the same source), and the type is therefore called ImageFamily. Several ImageFamily'ies or single sources at the same redshift are described in terms of a SourcePlane.

Single exact sources

Gravity.LuminousSourceType

A point source with associated photometry.

This type of source has associated position and luminosity, and therefore can provide information on the local lens magnification.

Members

  • x: An SPoint with the source position
  • mag: The source magnitude
source
Gravity.EllipticalSourceType

A point source with associated elliptical shape and photometry.

This type of source has associated position, magnitude, and (elliptical) shape. Hence, it provides information on the local lens magnification matrix.

Members

  • x: an SPoint with the source position
  • mag: the source magnitude
  • Q: the quadrupole of the shape measurement
  • A: the Jacobian of the lens equation at the source position; this is needed for the marginalization of the image-plane likelihood only
  • Q⁻¹: the inverse of the quadrupole moment Q (computed automatically)

Note that Q⁻¹ is stored here only for convenience and for speed.

Constructors

EllipticalSource(x::SPoint, mag::Real, Q::SPointMap [, A::SPointMap=I])
EllipticalSource(x::SPoint, mag::Real, r::Real, q::Real, θ::Real, [A::SPointMap=I])

The second form computes automatically the quadrupole moment from the elliptical radius r = √(ab), the axis ratio q = b/a, and the position angle θ (North to West in astronomical sense, in radians). It uses Gravity.rqθ_to_Q for the conversion.

source
Gravity.TimeSourceType

A single point-like source with time-delay information.

This is a point-like source with associated time delay; the corresponding measurement is called TimeImageMeasurement.

Member

  • x: an SPoint with the position of the source
  • t: a time associated to some source event
source
Gravity.TimeDelaySourceType

A single point-like source with time-delay information.

This is a point-like source with associated time delay; the corresponding measurement is called TimeImageMeasurement.

Member

  • x: an SPoint with the position of the source
  • t: a time associated to some source event
source
Gravity.LuminousTimeDelaySourceType

A single point-like source with time-delay information.

This is a point-like source with associated time delay; the corresponding measurement is called TimeImageMeasurement.

Member

  • x: an SPoint with the position of the source
  • mag: the magnitude of the source
  • t: a time associated to some source event
source
Gravity.SkyBackgroundSourceType

A source representing a uniform or linear sky background.

Members

  • x: an SPoint with the reference position
  • level: the background level
  • gradient: the background gradient as an SPoint

Constructors

SkyBackgroundSource([x::SPoint,] level::Real [, gradient::SPoint])
source
Gravity.CircularExtendedSourceType

A circular parametric source.

This type of source has associated position, luminosity, and circular shape, with a given profile. Hence, it provides information on the local lens magnification matrix.

Members

  • x: an SPoint with the source position
  • luminosity: the source luminosity
  • r: the size of the source (radius)
  • profile: a [LuminosityProfile], i.e. function ϱ² ⟼ SB(ϱ²), returning the source profile (surface brightness) as a function of the square radius
  • r⁻2: the inverse of the square of r (computed automatically)

Constructors

CircularExtendedSource(x::SPoint, luminosity::Real, r::Real, profile::LuuminosityProfile)
source
Gravity.EllipticalExtendedSourceType

An elliptical parametric source.

This type of source has associated position, luminosity, and elliptical shape, with a given profile. Hence, it provides information on the local lens magnification matrix.

Members

  • x: an SPoint with the source position
  • luminosity: the source luminosity
  • Q: the quadrupole of the shape measurement
  • profile: a LuminosityProfile, i.e. function ϱ² ⟼ SB(ϱ²), returning the source profile (surface brightness) as a function of the square elliptical radius ϱ² = (r - x)ᵀ Q⁻¹ (r - x).
  • Q⁻¹: the inverse of the quadrupole moment Q (computed automatically)

Note that Q⁻¹ is stored here only for convenience and for speed.

Constructors

EllipticalExtendedSource(x, luminosity, Q, profile)
EllipticalExtendedSource(x, luminosity, r, q, θ, profile)

The second form computes automatically the quadrupole moment from the elliptical radius $r = \sqrt(a b)$, the axis ratio $q = b / a$, and the position angle θ (North to West in astronomical sense, in radians).

source
Gravity.CompositeExtendedSourceType

A composite extended source made of multiple extended sources.

Members

Constructors

CompositeExtendedSource(source1 [, source2, ...])
CompositeExtendedSource((source1, source2, ...))
CompositeExtendedSource([source1, source2, ...])

Note that the first two constructors are type-stable, while the third one is not.

source
Gravity.VelocityExtendedSourceType

An extended source with associated radial velocity map.

This type of source has associated position, luminosity, and elliptical shape, with a given profile. Hence, it provides information on the local lens magnification matrix.

Members

  • x: an SPoint with the source position
  • θ: the position angle of the source (North to West in astronomical sense), in radians
  • ϕ: the inclination angle of the object, i.e. the angle between the galaxy angular momentum and the line of sight, in radians. A face-on galaxy will have ϕ = 0 or ϕ = π, while an edge-on galaxy will have ϕ = π/2.
  • bulk_velocity: the bulk velocity of the source
  • profile: a [LuminosityProfile], i.e. function ϱ² ⟼ SB(ϱ²), returning the source profile (surface brightness) as a function of the square elliptical radius ϱ² = (r - x)ᵀ Q⁻¹ (r - x).
  • velocity: a [LuminosityProfile], used to compute the radial velocity² map of the source. Can differ from the profile if, for example, the source surface brightness is associated to a single mass component, while the velocity is associated to the total mass.
  • Q: the galaxy quadrupole moment Q (computed automatically)
  • Q⁻¹: the inverse of the galaxy quadrupole moment Q (computed automatically)
  • ϖ: the galaxy velocity projection vector (computed automatically)

Constructor

VelocityExtendedSource(x::SPoint, θ::Real, ϕ::Real, profile, [, bulk_velocity] [, v²profile])
source
Gravity.ExtendedImageType
ExtendedImage{T}

Type definition for extended images.

Members

  • flux: An OffsetMatrix{T} with the surface brightness at the pixel locations
  • mask: An OffsetMatrix{Bool} with the mask of the image
source
Gravity.ExtendedVelocityType
ExtendedVelocity{T}

Type definition for extended images.

Members

  • flux: An OffsetMatrix{T} with the surface brightness at the pixel locations
  • velocity: An OffsetMatrix{T} with the velocity at the pixel locations
  • mask: An OffsetMatrix{Bool} with the mask of the image
source
Gravity.ExtendedLinearImageType
ExtendedLinearImage{T}

Type definition for extended linear images.

Rather than exteded images in the usual sense, this type encodes a vector of possible extended images which can be linearly combined to produce a standard extended image.

This type is returned by lensunmap when the source is a linear extended source.

Members

  • fluxes: An OffsetArray{T, 3} with the surface brightnesses at the pixel locations (first and second axes), for the various bases of the image (third axis)
  • mask: An OffsetMatrix{Bool} with the mask of the image
source
Gravity.PixeledSourceType

The model for a pixeled source.

This particular source type is used to model pixeled sources. It is based on kernel interpolation: when the pixel an image is mapped to the source plane, the corresponding surface brightness at the mapped location is obtained through interpolation of nearby pixels. This process is usually working well, even for oversampled sources, because it is coupled with a source regularization, which effectively put constraints on all source pixels (even the ones which are not directly hit by a mapped image location).

Members

  • grid: A BasicGrid used to define the source coordinates. Usually, the grid can be modified during the source computation to reflect the actual positions of the mapped images (which of course depend on the specific lensing model used).
  • λ: A positive real used as a scaling factor for the regularizer
  • kernels: a 2-tuple of InterpolationKernels. Generally, spiline kernels are used.
  • geometry: a symbol indicating the method used to accommodate the geometry of the source to the lensed images (see below).
  • rndval: a floating point random value. This is used as a simple trick to easily distinguish sources that could have identical parameters (something not completely unusual in this context).

A PixeledSource generally needs to adapt its geometry (i.e., grid in the source plane) to the lensed images. The way this operation is performed is controlled by the geometry field. The following values are recognized:

  • :fixed: the geometry is not modified (the grid is kept fixed in the source plane);
  • :fixed_nx_ny: the grid is adapted to the mapped images, but the grid sizes are not changed, resulting generally in a grid with rectangular pixels (this is the default);
  • :bounded_n: the grid is adapted so that the total number of pixels, that is nx * ny, do not increase;
  • :fixed_dx_dy: the grid is adapted, with the grid pixels kept fixed, resulting in a varying number of pixels in the grid
  • :snapped_dx_dy: identical to :fixed_dx_dy, but the grid boundaries are snapped to the nearest multiple of the pixel size (useful to combine multiple sources on a common grid)

Constructors

PixeledSource(grid, λ [, kernels] [, geometry])
source
Gravity.PixeledImageType
PixeledImage{T}

The image obtained as inversion of a PixeledSource.

This type is returned by lensunmap for a pixeled source. It represents a linear mapping from the source pixels to the image pixels, expressed as a sparse matrix that maps the source pixels into the image pixels.

Note that the mapping, represented by the lensmapping field, includes the PSF convolution. Note also that the indices of the sparse matrix are built over the active pixels of the entire clan of the dataset. This makes the analysis of pixeled images much simpler.

Member

  • lensmapping: A SparseMatrixCSC{T, Int} with the mapping from the source pixels to the image pixels.
source

Single source measurements

Gravity.PointImageMeasurementType
PointImageMeasurement

A single measurement of a point image, with a position and associated error.

Members

  • x: An SPoint representing the measured position
  • icov: A symmetric SPointMap representing the inverse covariance matrix of the Gaussian distribution representing the position measurement
  • lognorm: The normalizing constant of the Gaussian distribution

Note that the normalizing constant lognorm is defined as

\[\mathtt{lognorm} = \frac{1}{2} \log \biggl\lvert \frac{\mathtt{icov}}{2\pi} \biggr\rvert \; ,\]

or, equivalently, as lognorm = logdet(icov) / 2 - log(2π).

Constructors

PointImageMeasurement(x, icov)

The member lognorm is automatically computed; icov can be a (symmetric, positive definite) matrix, or a single positive scalar representing the inverse variance in both directions.

The special case where icov is vanishing is allowed, and corresponds to an improper flat distribution. It is used to represent the case where no measurement is available, and in this case lognorm is set to zero.

source
Gravity.LuminousImageMeasurementType
LuminousImageMeasurement

A single measurement of a luminous point image, with a position, magnitude and associated errors.

Members

  • x: An SPoint representing the measured position
  • icov: A symmetric SPointMap representing the inverse covariance matrix of the Gaussian distribution representing the position measurement
  • mag: The source measured magnitude, a real value
  • mag_ivar: The inverse variance of the mag measurement
  • lognorm: The normalizing constant of the Gaussian distribution

Note that the normalizing constant lognorm is defined as

\[\mathtt{lognorm} = \frac{1}{2} \log \biggl\lvert \frac{\mathtt{icov}}{2\pi} \biggr\rvert + \frac{1}{2} \log \frac{\mathtt{mag\_ivar}}{2 \pi} \; ,\]

or, equivalently, as lognorm = (logdet(icov) + log(mag_ivar) - 3*log(2π)) / 2.

Constructors

LuminousImageMeasurement(x, icov, mag, mag_ivar)

The member lognorm is automatically computed; icov can be a (symmetric, positive definite) matrix, or a single positive scalar representing the inverse variance in both directions.

The special case where icov is vanishing is allowed, and corresponds to an improper flat distribution. It is used to represent the case where no measurement is available, and in this case the contribution of icov to the normalizing constant lognorm is set to zero. Similarly, the special case where mag_ivar is vanishing is allowed, and corresponds to an improper flat magnitude distribution. Again, in this case the contribution of mag_ivar to the normalizing constant lognorm is set to zero.

source
Gravity.EllipticalImageMeasurementType
EllipticalImageMeasurement

A single measurement of a small elliptical image, with magnitude and quadrupole moment.

Members

  • x: An SPoint representing the measured position
  • icov: A symmetric SPointMap representing the inverse covariance matrix of the Gaussian distribution of the position measurement
  • mag: The source measured magnitude, a real value
  • mag_ivar: The inverse variance of the mag measurement
  • Q: the measured quadrupole moment of the image, as a symmetric SPointMap
  • nu: The number of degrees of freedom of the quadrupole distribution, a positive real value; it is related to the inverse of the variance of the quadrupole moment by nu = 2 a² / σₐ², where a is the semi-major axis and σₐ is its measurement error.
  • lognorm: The normalizing constant of the full distribution

Note that the normalizing constant lognorm is defined as

\[\mathtt{lognorm} = \frac{1}{2} \log \biggl\lvert \frac{\mathtt{icov}}{2\pi} \biggr\rvert + \frac{1}{2} \log \frac{\mathtt{mag\_ivar}}{2 \pi} + \frac{\mathtt{nu} - 3}{2} \log \lvert \mathtt{Q} \rvert + \mathtt{nu} \log \mathtt{nu} - \log \bigl[4 \pi \Gamma(\mathtt{nu} - 1) \bigr] \; ,\]

or, equivalently, as lognorm = (logdet(icov) + log(mag_ivar) - 3*log(2π) + (nu - 3)*logdet(Q)) / 2 + nu*log(nu) - loggamma(nu-1) - log(4π).

Constructors

EllipticalImageMeasurement(x, icov, mag, mag_ivar, Q, nu)

The member lognorm is automatically computed; icov can be a (symmetric, positive definite) matrix, or a single positive scalar representing the inverse variance in both directions.

The special case where icov is vanishing is allowed, and corresponds to an improper flat distribution. It is used to represent the case where no measurement is available, and in this case the contribution of icov to the normalizing constant lognorm is set to zero. Similarly, the special case where mag_ivar is vanishing is allowed, and corresponds to an improper flat magnitude distribution. Again, in this case the contribution of mag_ivar to the normalizing constant lognorm is set to zero. Finally, if nu is vanishing, the last two terms of the normalizing constant lognorm are set to zero.

source
Gravity.TimeImageMeasurementType
TimeImageMeasurement

A single measurement of a point image with a time event.

Members

  • x: An SPoint representing the measured position
  • icov: A symmetric SPointMap representing the inverse covariance matrix of the Gaussian distribution representing the position measurement
  • t: The time of the event
  • t_ivar: The inverse variance in the measurement of t
  • lognorm: The normalizing constant of the Gaussian distribution

Note that the normalizing constant lognorm is defined as

\[\mathtt{lognorm} = \frac{1}{2} \log \biggl\lvert \frac{\mathtt{icov}}{2\pi} \biggr\rvert + \frac{1}{2} \log \frac{\mathtt{t\_ivar}}{2 \pi} \; ,\]

or, equivalently, as lognorm = (logdet(icov) + log(t_ivar) - 3*log(2π)) / 2.

Constructors

TimeImageMeasurement(x, icov, t, t_ivar)

Notice that the member lognorm is automatically computed; icov can be a (symmetric, positive definite) matrix, or a single positive scalar representing the inverse variance in both directions.

source
Gravity.TimeDelayImageMeasurementType
TimeDelayImageMeasurement

A single measurement of a point image with time delay.

Members

  • x: An SPoint representing the measured position
  • icov: A symmetric SPointMap representing the inverse covariance matrix of the Gaussian distribution representing the position measurement
  • t: The time of the event
  • t_cov: The covariance in the measurement of t as a vector (see below)
  • t_ivar: The inverse variance of the measurement, automatically computed as 1 / last(t_cov)
  • lognorm: The normalizing constant of the Gaussian distribution

Note that the normalizing constant lognorm is defined as

\[\mathtt{lognorm} = \frac{1}{2} \log \biggl\lvert \frac{\mathtt{icov}}{2\pi} \biggr\rvert \; ,\]

or, equivalently, as lognorm = logdet(icov) / 2 - log(2π). This constant does not include any term associated to the time covariance, as the associated normalization needs to be computed at the family level.

The t_cov member stores a row of the lower triangular part of the covariance matrix. The convension is to have the reference image (that is, the image used to measure time delays) with empty covariance, as in t_cov = Float64[]. All other images in the same family will have increasingly longer t_cov vectors, storing the various parts of the time delay. Specifically, suppose we have 4 images A, B, C, and D. Then the four associated values for t_cov will be

[]
[Cov(AB,AB)]
[Cov(AB,AC), Cov(AC,AC)]
[Cov(AB,AD), Cov(AC,AD), Cov(AD,AD)]

Constructors

TimeDelayImageMeasurement(x, icov, t, t_cov)

Notice that the member lognorm is automatically computed; icov can be a (symmetric, positive definite) matrix, or a single positive scalar representing the inverse variance in both directions.

source
Gravity.LuminousTimeDelayImageMeasurementType
LuminousTimeDelayImageMeasurement

A single measurement of a point image with time delay.

Members

  • x: An SPoint representing the measured position
  • icov: A symmetric SPointMap representing the inverse covariance matrix of the Gaussian distribution representing the position measurement
  • mag: The time of the event
  • mag_cov: The covariance in the measurement of mag as a vector (see below)
  • mag_ivar: The inverse variance of the measurement, automatically computed as 1 / last(mag_cov)
  • t: The time of the event
  • t_cov: The covariance in the measurement of t as a vector (see below)
  • t_ivar: The inverse variance of the measurement, automatically computed as 1 / last(t_cov)
  • mag_t_cov: The cross-covariance between mag and t, as a vector (see below)
  • lognorm: The normalizing constant of the Gaussian distribution

Note that the normalizing constant lognorm is defined as

\[\mathtt{lognorm} = \frac{1}{2} \log \biggl\lvert \frac{\mathtt{icov}}{2\pi} \biggr\rvert \; ,\]

or, equivalently, as lognorm = logdet(icov) / 2 - log(2π). This constant does not include any term associated to the magnitude or time covariance, as the associated normalization needs to be computed at the family level.

The t_cov member stores a row of the lower triangular part of the covariance matrix. The convension is to have the reference image (that is, the image used to measure time delays) with empty covariance, as in t_cov = Float64[]. All other images in the same family will have increasingly longer t_cov vectors, storing the various parts of the time delay. Specifically, suppose we have 4 images A, B, C, and D. Then the four associated values for t_cov will be

[]
[Cov(AB,AB)]
[Cov(AB,AC), Cov(AC,AC)]
[Cov(AB,AD), Cov(AC,AD), Cov(AD,AD)]

The mag_cov member, similarly to t_cov, stores a row of the lower triangular part of the magnitude covariance matrix. Magnitudes of time-variable sources can only be obtained with a fit of the various light-curves. Moreover, what really matters are only magnitude differences among the various images of the same family. For this reason, analogously to t_cov, mag_cov for the first image in a family must be empty.

The cross-correlation between the magnitude and time is stored in the mag_t_cov vector, which must always be as long as the length of the entire family minus one. Note that the convension is to have the j-th element of the mag_t_cov vector for the image i+1 to save the covariance between the magnitude difference between image i+1 and the reference image 1, and the time-delay between image j+1 and the reference image 1.

For example, given 3 images A, B, and C, we will build the full time-magnitude covariance matrix as

tB-tAtC-tAmagB-magAmagC-magA
tB-tAcov_t(AB,AB)
tC-tAcov_t(AB,AC)cov_t(AC,AC)
magB-magAcov_mag_t(AB,AB)cov_mag_t(AB,AC)cov_mag(AB,AB)
magC-magAcov_mag_t(AC,AB)cov_mag_t(AC,AC)cov_mag(AB,AC)cov_mag(AC,AC)

In other words, the second element of cov_mag_t for the source B will be the term noted cov_mag_t(AB,AC) above, and will store the covariance between the magnitude difference magB - magA and the time-delay tC - tA.

Constructors

LuminousTimeDelayImageMeasurement(x, icov, mag, mag_cov, t, t_cov, mag_t_cov)

Notice that the member lognorm is automatically computed; icov can be a (symmetric, positive definite) matrix, or a single positive scalar representing the inverse variance in both directions.

source
Gravity.ExtendedImageMeasurementType
ExtendedImageMeasurement{T}

An extended image measurement in a masked array.

The ExtendedImageMeasurement is usually derived from a Dataset by selecting a subset of pixels with a given mask. If a PSF is provided, or if oversampling is requested, the ExtendedImageMeasurement will prepare computions an a larger (for PSF convolution) and finer (for oversampling) grid than the original Dataset subgrid. This refined grid is called subprediction below and is computed using the convolution_input function.

Members

  • parent: the parent Dataset with the full observation
  • maskids: the values of the maskids used to build this image
  • clan: the clan associated to this image, or 0 for no clan
  • flux: a SubImage{T} with the surface brightness at the pixel locations
  • ivar: a SubImage{T} with the inverse variance of the surface brightness at the pixel locations
  • clan_indices: a SubImage{Int} that replicates that clan_indices part of the original Dataset within the boundaries of the image
  • coords: an allocated OffsetMatrix{SPoint{T}} with the subprediction pixel coordinates converted into Gravity global coordinates
  • vcoords: an allocated vector of SPoint{T}, containing all coords pixels coordinates (thus Gravity global cooordinates) needed for the computation of the flux of the source. This includes all the mask-selected pixels of the source, with oversampling included, and enlarged (through morph_dilate) for the PSF. This list is actually given by vsubmask.
  • mask: An OffsetMatrix{Bool} with the mask of the image. This mask is used to avoid operations in pixels that have been masked: this simplifies operations such as convolutions (see convolve_prepare).
  • vmask: A vector of CartesianIndex{2} with the mask-selected indices
  • submask: the mask of the subprediction grid, which is used to avoid operations in pixels that have been masked: this simplifies operations such as convolutions (see convolve_prepare)
  • vsubmask: A vector of CartesianIndex{2} with the submask-selected indices
  • corners: A vector of SPoint{T} with the coordinates of the corners of the subprediction pixels that are inside the submask
  • corner_indices: A vector of 4-tuples of Int that provides, for each pixel in the submask, the indices of the associated items in the corners vector.
  • psf: Either nothing or an OffsetMatrix{T} with the point spread function (PSF) for the image. The PSF is taken to be centered at the index [0,0]. Moreover, in case oversampling > 1, the PSF is taken to be oversampled, which can be useful for peaked profiles. The PSF should be normalized to unity, so that sum(psf) = 1.
  • oversampling: The PSF oversampling, or (in case psf = nothing) the oversampling requested from the model, as a 2-tuple of odd positive numbers.
  • convolution!: A function that takes two Matrix{T} arguments and performs the convolution of the second argument with the first one. This function is used to perform the convolution of the subprediction with the PSF and store the result in the prediction matrix. If psf == nothing, this function is just blocksum!.

Constructors

ExtendedImageMeasurement(dataset, maskids [, oversampling])

Build an ExtendedImageMeasurement from a Dataset, by including all pixels whose mask value is in the list of maskids. The optional oversampling argument can be used to request a different oversampling than the one in the dataset. In case it is specified, it must be a 2-tuple of odd positive numbers, or a single odd positive number.

source
Gravity.ExtendedVelocityMeasurementType
ExtendedVelocityMeasurement{T,G}

An extended velocity measurement in a masked grid.

Members

  • parent_flux: A Dataset with the full flux observation
  • parent_velocity: A Dataset with the full velocity observation
  • maskids: the values of the maskids used to build this image
  • flux: A SubImage{T} with the surface brightness at the pixel locations
  • velocity: A SubImage{T} with the weighted velocity at the pixel locations
  • flux_ivar: A SubImage{T} with the inverse variance of the surface brightness at the pixel locations
  • velocity_ivar: A SubImage{T} with the inverse variance of the weighted velocity at the pixel locations
  • coords: An allocated OffsetMatrix{SPoint{T}} with the subprediction pixel coordinates converted into Gravity global coordinates.
  • vcoords: an allocated vector of SPoint{T}, containing all coords pixels coordinates (thus Gravity global cooordinates) needed for the computation of the flux of the source. This includes all the mask-selected pixels of the source, with oversampling included, and enlarged (through morph_dilate) for the PSF. This list is actually given by vsubmask.
  • mask: An OffsetMatrix{Bool} with the mask of the image. This mask is used to avoid operations in pixels that have been masked: this simplifies operations such as convolutions (see convolve_prepare).
  • vsubmask: A vector of CartesianIndix{2} with the mask-selected indices of the subprediction
  • psf: Either nothing or an OffsetMatrix{T} with the point spread function (PSF) for the image. The PSF is taken to be centered at the index [0,0]. Moreover, in case oversampling > 1, the PSF is taken to be oversampled, which can be useful for peaked profiles. The PSF should be normalized to unity, so that sum(psf) = 1.
  • oversampling: The PSF oversampling, or (in case psf = nothing) the oversampling requested from the model, as a 2-tuple of odd positive numbers.
  • convolution!: A function that takes two Matrix{T} arguments and performs the convolution of the second argument with the first one. This function is used to perform the convolution of the subprediction with the PSF and store the result in the prediction matrix. If psf == nothing, this function is just blocksum!.

Constructors

ExtendedVelocityMeasurement(data_flux, data_velocity, maskids [, oversampling])

Build an ExtendedVelocityMeasurement from two Datasets, by including all pixels whose mask value is in the list of maskids. The optional oversampling argument can be used to request a different oversampling than the one in the dataset. In case it is specified, it must be a 2-tuple of odd positive numbers, or a single odd positive number.

source

Methods for source measurements

Gravity.measureFunction
measure([rng,] image, measurement)

Simulate the measurement of an image or ImageFamily.

This function returns an image measurement obtained by simulating the measurement of image with associated measurement errors taken from measurement. For example in case of a simple point image, the call

Gravity.measure(PointSource(SPoint(1.0, 2.0)), PointImageMeasurement(SPoint(3.0, 6.0), 4.0))

would simulate the measurement of a source with average position (1.0, 2.0) and scatter 0.5 (4.0 represents the inverse variance). This call, is in fact equivalent to

PointImageMeasurement(SPoint(1.0 + 0.5 * randn(), 2.0 + 0.5 * randn()), 5.0)

The first optional parameters rng, can be an Random.AbstractRNG; if not provided, the default random number generator Random.default_rng() is used.

See also: unmeasure, sample

source

Collection of sources

Gravity.ImageFamilyType

A family of counter-images of a single source.

This is the kind of object generally returned by lensunmap.

Members

  • images: A vector of SingleSource's
  • prior: The prior for the image family: for point-like sources, the prior is just a source with associated errors; for linear sources, it is a more complicated object
Warning

This parametric type includes, as last parameter, a Val specification used to indicate the inference scheme to use for the family of images. By default this is Val{:nothing}, but one can set to more sensible values such as Val{:sourceplane}, Val{:imageplane} and so on.

source
Gravity.SourcePlaneType
SourcePlane

A single source plane (i.e., a vector or SingleSourceFamily's) at a given redshift z.

Members

  • z: the redshift of the source plane
  • ς: the associated SourceCoeff
  • sources: a tuple of vectors of subtypes of SingleSourceFamily representing the sources in the plane

Constructors

SourcePlane(ς, sources...)
SourcePlane(z, lens_system, sources...)

In both constructors, sources can be a tuple or a vector of SingleSourceFamily's.

Info

Note that this structure is used for both the source-plane and the image-plane. In the former case, the elements of sources will be subtypes of SingleSource, while in the latter case the elements will be an ImageFamily.

Note

The particular structure of the sources field is a design choice to make computations fast. A natural choice would have been to set sources just as a vector of concrete SingleSourceFamily'es. Unfortunately, this way we would be unable to perform type inference on the various methods (potential, deflection...) as this would require a precise knowledge of the type of each element of sources (unavailable to the compiler). An alternative would have been to define sources as a simple tuple of concrete SingleSourceFamily'es, but this technique would be very expensinve computationally in case the number of sources is more than a handful. The solution is to use for sources a tuple of vectors, with each vector composed of just one specific kind of concrete SingleSourceFamily: since there are a limited number SingleSourceFamily types, and since it is anyway unlikely that one would want to use more than a handful different kind of SingleSourceFamily'es in a lensing model, this approach works nicely.

source

Datasets

Datasets are necessary for the description of extended sources. They are two-dimensional surface-brightness measurements of the sky, with associated astrometry and optional point-spread function. Note that datasets can be also saved to FITS file together with their astrometry using Gravity.fits_write.

Gravity.DatasetType
Dataset{T}

A full observation of a (possibly very large) image, with associated errors.

Members

  • indices: A Matrix{Int} with the indices of the observed pixels in the image, i.e. the pixels flagged with mask != 0; the indices are used to map the vectors flux, ivar, and mask to the image pixels. The indices are such that indices[c] = i means that the i-th pixel in the dataset is at the coordinates c in the image.
  • full: A Bool, indicating if the dataset is full, in the sense that all(indices .!= 0)
  • flux: A Vector{T} with the observed flux values
  • ivar: A Vector{T} with the inverse variance of the flux values
  • ierr: A Vector{T} with the inverse errors of the flux values, i.e. sqrt.(ivar)
  • mask: A Vector{Int} with the mask of the image
  • clan_dict: An OrderedDict{Symbol,Int} used to associate, to each clan id, the clan number (used below for all other fields)
  • mask_dict: A Dict{Int,Int} used to associate, to each mask id, the clan it belongs to; contains only mask ids associted to non-parametric extended sources
  • clan_indices: A vector of Matrix{Int}, with each element saving the indices of the observed pixels in the image that include a specific clan of linear (non-parametric) sources, i.e. sources whose flux is marginalized automatically in the code. Different clans must be independent of each other (that is, must have non-overlapping pixels within a resolution radius).
  • clan_flux_idx: A vector of Vector{Int} with the indices (for each clan) in the flux and ivar vectors corresponding to a given pixel of a clan.
  • clan_ierr: A vector of Vector{T} with the inverse errors at the free pixels clan_indices. Therefore clan_ierr[f] = sqrt.(ivar[clan_flux_idx[c]]) for each clan c.
  • lognorm: The logarithm of the normalization factor for the likelihood function, computed as sum(log(ivar / 2π)); this factor is used to normalize the likelihood function.
  • globalwcs: A FastWCS that maps the coordinates used in Gravity to the world coordinates.
  • localwcs: A FastWCS that maps the dataset pixel coordinates to the world coordinates.
  • psf: Either nothing or an OffsetMatrix{T} with the point spread function (PSF) for the image. The PSF is taken to be centered at the index [0,0]. Moreover, in case oversampling > 1, the PSF is taken to be oversampled, which can be useful for peaked profiles. The PSF should be normalized to unity, so that sum(psf) = 1.
  • oversampling: The PSF oversampling factors along y and x as a tuple, or (in case psf = nothing) the oversampling requested from the model. Both oversampling factors must be odd positive numbers.

Constructor

Dataset(flux, ivar, mask [, clans, globalwcs, localwcs, psf, oversampling])

Build a Dataset from the observed flux, ivar, and mask images (which must all be matrices of the same size). The routine computes indices matrix from mask (by keeping only mask values that are non-zero), and converts the flux, ivar, and mask images into vectors.

The optional clans can be an ordered dict or a named tuple with clan names and the mask ids associated to non-parametric clans. For example (a=(2, 3), b=(4,)) indicates that the mask ids 2 and 3 are associated to non-parametric sources that must be jointly modeled (because their images overlap), while 4 is associted to another non-parametric source producing isolated images.

The optional globalwcs and localwcs arguments are used to specify the global coordinate system (that is, the one used throughout the configuration file) and the local coordinate system (specific to the dataset), respectively.

The optional psf indicates the point spread function of the image, and must be either nothing or an OffsetMatrix{T} with the PSF values. The psf is taken to be centered at the index [0,0].

oversampling must be a 2-tuple of odd positive numbers, or a single odd positive number. In case it is specified, it is used to request a different oversampling than the one in the dataset. In this case, the psf is taken to be oversampled by the factors specified in oversampling.

source
Gravity.fluxFunction
flux(dataset, [xrange, yrange])

Return a matrix with the datasets flux.

If just one argument is used, the function returns a matrix built using the entire dataset. If dataset.full is true (that is, that dataset's mask does not have any zero), a reshaped array is returned.

If xrange and yrange are provided, this function always returns a freshly allocated matrix containing a copy of the dataset flux inside the provided boundaries. This is operationally equivalent to flux(dataset)[xrange, yrange] but faster. Note that for this to work properly, both xrange and yrange must be Base.IdentityUnitRange.

See also: Gravity.ivar, Gravity.mask

source
Gravity.ivarFunction
ivar(dataset)

Return a matrix with the datasets inverse variance.

If just one argument is used, the function returns a matrix built using the entire dataset. If dataset.full is true (that is, that dataset's mask does not have any zero), a reshaped array is returned.

If xrange and yrange are provided, this function always returns a freshly allocated matrix containing a copy of the dataset inverse variance inside the provided boundaries. This is operationally equivalent to ivar(dataset)[xrange, yrange] but faster. Note that for this to work properly, both xrange and yrange must be Base.IdentityUnitRange.

See also: Gravity.flux, Gravity.mask

source