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.PointSource — Type
A single point-like source with no luminosity information.
This is the simplest (exact) source one can define; the corresponding measurement is called PointImageMeasurement.
Member
x: anSPointwith the position of the source
Gravity.LuminousSource — Type
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: AnSPointwith the source positionmag: The source magnitude
Gravity.EllipticalSource — Type
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: anSPointwith the source positionmag: the source magnitudeQ: the quadrupole of the shape measurementA: the Jacobian of the lens equation at the source position; this is needed for the marginalization of the image-plane likelihood onlyQ⁻¹: the inverse of the quadrupole momentQ(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.
Gravity.TimeSource — Type
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: anSPointwith the position of the sourcet: a time associated to some source event
Gravity.TimeDelaySource — Type
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: anSPointwith the position of the sourcet: a time associated to some source event
Gravity.LuminousTimeDelaySource — Type
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: anSPointwith the position of the sourcemag: the magnitude of the sourcet: a time associated to some source event
Gravity.SkyBackgroundSource — Type
A source representing a uniform or linear sky background.
Members
x: anSPointwith the reference positionlevel: the background levelgradient: the background gradient as anSPoint
Constructors
SkyBackgroundSource([x::SPoint,] level::Real [, gradient::SPoint])Gravity.CircularExtendedSource — Type
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: anSPointwith the source positionluminosity: the source luminosityr: 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 radiusr⁻2: the inverse of the square ofr(computed automatically)
Constructors
CircularExtendedSource(x::SPoint, luminosity::Real, r::Real, profile::LuuminosityProfile)Gravity.EllipticalExtendedSource — Type
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: anSPointwith the source positionluminosity: the source luminosityQ: the quadrupole of the shape measurementprofile: aLuminosityProfile, 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 momentQ(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).
Gravity.CompositeExtendedSource — Type
A composite extended source made of multiple extended sources.
Members
components: a vector ofAbstractExtendedSourceobjects
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.
Gravity.VelocityExtendedSource — Type
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: anSPointwith 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ϕ = 0orϕ = π, while an edge-on galaxy will haveϕ = π/2.bulk_velocity: the bulk velocity of the sourceprofile: 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 momentQ(computed automatically)Q⁻¹: the inverse of the galaxy quadrupole momentQ(computed automatically)ϖ: the galaxy velocity projection vector (computed automatically)
Constructor
VelocityExtendedSource(x::SPoint, θ::Real, ϕ::Real, profile, [, bulk_velocity] [, v²profile])Gravity.ExtendedImage — Type
ExtendedImage{T}Type definition for extended images.
Members
flux: AnOffsetMatrix{T}with the surface brightness at the pixel locationsmask: AnOffsetMatrix{Bool}with the mask of the image
Gravity.ExtendedVelocity — Type
ExtendedVelocity{T}Type definition for extended images.
Members
flux: AnOffsetMatrix{T}with the surface brightness at the pixel locationsvelocity: AnOffsetMatrix{T}with the velocity at the pixel locationsmask: AnOffsetMatrix{Bool}with the mask of the image
Gravity.ExtendedLinearImage — Type
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: AnOffsetArray{T, 3}with the surface brightnesses at the pixel locations (first and second axes), for the various bases of the image (third axis)mask: AnOffsetMatrix{Bool}with the mask of the image
Gravity.PixeledSource — Type
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: ABasicGridused 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 regularizerkernels: a 2-tuple ofInterpolationKernels. 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 isnx * 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])Gravity.PixeledImage — Type
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: ASparseMatrixCSC{T, Int}with the mapping from the source pixels to the image pixels.
Single source measurements
Gravity.PointImageMeasurement — Type
PointImageMeasurementA single measurement of a point image, with a position and associated error.
Members
x: AnSPointrepresenting the measured positionicov: A symmetricSPointMaprepresenting the inverse covariance matrix of the Gaussian distribution representing the position measurementlognorm: 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.
Gravity.LuminousImageMeasurement — Type
LuminousImageMeasurementA single measurement of a luminous point image, with a position, magnitude and associated errors.
Members
x: AnSPointrepresenting the measured positionicov: A symmetricSPointMaprepresenting the inverse covariance matrix of the Gaussian distribution representing the position measurementmag: The source measured magnitude, a real valuemag_ivar: The inverse variance of themagmeasurementlognorm: 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.
Gravity.EllipticalImageMeasurement — Type
EllipticalImageMeasurementA single measurement of a small elliptical image, with magnitude and quadrupole moment.
Members
x: AnSPointrepresenting the measured positionicov: A symmetricSPointMaprepresenting the inverse covariance matrix of the Gaussian distribution of the position measurementmag: The source measured magnitude, a real valuemag_ivar: The inverse variance of themagmeasurementQ: the measured quadrupole moment of the image, as a symmetricSPointMapnu: 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 bynu = 2 a² / σₐ², whereais 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.
Gravity.TimeImageMeasurement — Type
TimeImageMeasurementA single measurement of a point image with a time event.
Members
x: AnSPointrepresenting the measured positionicov: A symmetricSPointMaprepresenting the inverse covariance matrix of the Gaussian distribution representing the position measurementt: The time of the eventt_ivar: The inverse variance in the measurement oftlognorm: 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.
Gravity.TimeDelayImageMeasurement — Type
TimeDelayImageMeasurementA single measurement of a point image with time delay.
Members
x: AnSPointrepresenting the measured positionicov: A symmetricSPointMaprepresenting the inverse covariance matrix of the Gaussian distribution representing the position measurementt: The time of the eventt_cov: The covariance in the measurement oftas a vector (see below)t_ivar: The inverse variance of the measurement, automatically computed as1 / 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.
Gravity.LuminousTimeDelayImageMeasurement — Type
LuminousTimeDelayImageMeasurementA single measurement of a point image with time delay.
Members
x: AnSPointrepresenting the measured positionicov: A symmetricSPointMaprepresenting the inverse covariance matrix of the Gaussian distribution representing the position measurementmag: The time of the eventmag_cov: The covariance in the measurement ofmagas a vector (see below)mag_ivar: The inverse variance of the measurement, automatically computed as1 / last(mag_cov)t: The time of the eventt_cov: The covariance in the measurement oftas a vector (see below)t_ivar: The inverse variance of the measurement, automatically computed as1 / last(t_cov)mag_t_cov: The cross-covariance betweenmagandt, 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-tA | tC-tA | magB-magA | magC-magA | |
|---|---|---|---|---|
tB-tA | cov_t(AB,AB) | |||
tC-tA | cov_t(AB,AC) | cov_t(AC,AC) | ||
magB-magA | cov_mag_t(AB,AB) | cov_mag_t(AB,AC) | cov_mag(AB,AB) | |
magC-magA | cov_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.
Gravity.ExtendedImageMeasurement — Type
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 parentDatasetwith the full observationmaskids: the values of the maskids used to build this imageclan: the clan associated to this image, or 0 for no clanflux: aSubImage{T}with the surface brightness at the pixel locationsivar: aSubImage{T}with the inverse variance of the surface brightness at the pixel locationsclan_indices: aSubImage{Int}that replicates thatclan_indicespart of the originalDatasetwithin the boundaries of the imagecoords: an allocatedOffsetMatrix{SPoint{T}}with thesubpredictionpixel coordinates converted into Gravity global coordinatesvcoords: an allocated vector ofSPoint{T}, containing allcoordspixels 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 (throughmorph_dilate) for the PSF. This list is actually given byvsubmask.mask: AnOffsetMatrix{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 (seeconvolve_prepare).vmask: A vector ofCartesianIndex{2}with the mask-selected indicessubmask: the mask of thesubpredictiongrid, which is used to avoid operations in pixels that have been masked: this simplifies operations such as convolutions (seeconvolve_prepare)vsubmask: A vector ofCartesianIndex{2}with the submask-selected indicescorners: A vector ofSPoint{T}with the coordinates of the corners of thesubpredictionpixels that are inside thesubmaskcorner_indices: A vector of 4-tuples ofIntthat provides, for each pixel in the submask, the indices of the associated items in thecornersvector.psf: Eithernothingor anOffsetMatrix{T}with the point spread function (PSF) for the image. The PSF is taken to be centered at the index[0,0]. Moreover, in caseoversampling > 1, the PSF is taken to be oversampled, which can be useful for peaked profiles. The PSF should be normalized to unity, so thatsum(psf) = 1.oversampling: The PSF oversampling, or (in casepsf = nothing) the oversampling requested from the model, as a 2-tuple of odd positive numbers.convolution!: A function that takes twoMatrix{T}arguments and performs the convolution of the second argument with the first one. This function is used to perform the convolution of thesubpredictionwith the PSF and store the result in thepredictionmatrix. Ifpsf == nothing, this function is justblocksum!.
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.
Gravity.ExtendedVelocityMeasurement — Type
ExtendedVelocityMeasurement{T,G}An extended velocity measurement in a masked grid.
Members
parent_flux: ADatasetwith the full flux observationparent_velocity: ADatasetwith the full velocity observationmaskids: the values of the maskids used to build this imageflux: ASubImage{T}with the surface brightness at the pixel locationsvelocity: ASubImage{T}with the weighted velocity at the pixel locationsflux_ivar: ASubImage{T}with the inverse variance of the surface brightness at the pixel locationsvelocity_ivar: ASubImage{T}with the inverse variance of the weighted velocity at the pixel locationscoords: An allocatedOffsetMatrix{SPoint{T}}with thesubpredictionpixel coordinates converted into Gravity global coordinates.vcoords: an allocated vector ofSPoint{T}, containing allcoordspixels 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 (throughmorph_dilate) for the PSF. This list is actually given byvsubmask.mask: AnOffsetMatrix{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 (seeconvolve_prepare).vsubmask: A vector ofCartesianIndix{2}with the mask-selected indices of thesubpredictionpsf: Eithernothingor anOffsetMatrix{T}with the point spread function (PSF) for the image. The PSF is taken to be centered at the index[0,0]. Moreover, in caseoversampling > 1, the PSF is taken to be oversampled, which can be useful for peaked profiles. The PSF should be normalized to unity, so thatsum(psf) = 1.oversampling: The PSF oversampling, or (in casepsf = nothing) the oversampling requested from the model, as a 2-tuple of odd positive numbers.convolution!: A function that takes twoMatrix{T}arguments and performs the convolution of the second argument with the first one. This function is used to perform the convolution of thesubpredictionwith the PSF and store the result in thepredictionmatrix. Ifpsf == nothing, this function is justblocksum!.
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.
Methods for source measurements
Gravity.measure — Function
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.
Gravity.unmeasure — Function
Gravity.sample — Function
sample(image)Sample an the image measurement image.
This function is equivalent to unmeausre(measure(image, image)).
Collection of sources
Gravity.ImageFamily — Type
A family of counter-images of a single source.
This is the kind of object generally returned by lensunmap.
Members
images: A vector ofSingleSource'sprior: 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
Gravity.SourcePlane — Type
SourcePlaneA single source plane (i.e., a vector or SingleSourceFamily's) at a given redshift z.
Members
z: the redshift of the source planeς: the associatedSourceCoeffsources: a tuple of vectors of subtypes ofSingleSourceFamilyrepresenting 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.
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.
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.
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.Dataset — Type
Dataset{T}A full observation of a (possibly very large) image, with associated errors.
Members
indices: AMatrix{Int}with the indices of the observed pixels in the image, i.e. the pixels flagged withmask != 0; the indices are used to map the vectorsflux,ivar, andmaskto the image pixels. The indices are such thatindices[c] = imeans that thei-th pixel in the dataset is at the coordinatescin the image.full: ABool, indicating if the dataset is full, in the sense thatall(indices .!= 0)flux: AVector{T}with the observed flux valuesivar: AVector{T}with the inverse variance of the flux valuesierr: AVector{T}with the inverse errors of the flux values, i.e. sqrt.(ivar)mask: AVector{Int}with the mask of the imageclan_dict: AnOrderedDict{Symbol,Int}used to associate, to each clan id, the clan number (used below for all other fields)mask_dict: ADict{Int,Int}used to associate, to each mask id, the clan it belongs to; contains only mask ids associted to non-parametric extended sourcesclan_indices: A vector ofMatrix{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 ofVector{Int}with the indices (for each clan) in thefluxandivarvectors corresponding to a given pixel of a clan.clan_ierr: A vector ofVector{T}with the inverse errors at the free pixelsclan_indices. Thereforeclan_ierr[f] = sqrt.(ivar[clan_flux_idx[c]])for each clanc.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: AFastWCSthat maps the coordinates used in Gravity to the world coordinates.localwcs: AFastWCSthat maps the dataset pixel coordinates to the world coordinates.psf: Eithernothingor anOffsetMatrix{T}with the point spread function (PSF) for the image. The PSF is taken to be centered at the index[0,0]. Moreover, in caseoversampling > 1, the PSF is taken to be oversampled, which can be useful for peaked profiles. The PSF should be normalized to unity, so thatsum(psf) = 1.oversampling: The PSF oversampling factors alongyandxas a tuple, or (in casepsf = 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.
Gravity.flux — Function
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
Gravity.ivar — Function
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