Sky Model¶
Functionality related to the Sky Model.
Coherency Conversion¶
Utilities for converting back and forth between stokes parameters and correlations
Numpy¶
convert(input, input_schema, output_schema) |
This function converts forward and backward from stokes I,Q,U,V to both linear XX,XY,YX,YY and circular RR, RL, LR, LL correlations. |
-
africanus.model.coherency.convert(input, input_schema, output_schema)[source]¶ This function converts forward and backward from stokes
I,Q,U,Vto both linearXX,XY,YX,YYand circularRR, RL, LR, LLcorrelations.For example, we can convert from stokes parameters to linear correlations:
stokes.shape == (10, 4, 4) corrs = convert(stokes, ["I", "Q", "U", "V"], [['XX', 'XY'], ['YX', 'YY']) assert corrs.shape == (10, 4, 2, 2)
Or circular correlations to stokes:
vis.shape == (10, 4, 2, 2) stokes = convert(vis, [['RR', 'RL'], ['LR', 'LL']], ['I', 'Q', 'U', 'V']) assert stokes.shape == (10, 4, 4)
inputcanoutputcan be arbitrarily nested or ordered lists, but the appropriate inputs must be present to produce the requested outputs.The elements of
inputandoutputmay be strings or integers representing stokes parameters or correlations. See the Notes for a full list.Parameters: input :
numpy.ndarrayComplex or floating point input data of shape
(dim_1, ..., dim_n, icorr_1, ..., icorr_m)input_schema : list of str or int
A schema describing the
icorr_1, ..., icorr_mdimension ofinput. Must have the same shape as the last dimensions ofinput.output_schema : list of str or int
A schema describing the
ocorr_1, ..., ocorr_ndimension of the return value.Returns: result :
numpy.ndarrayResult of shape
(dim_1, ..., dim_n, ocorr_1, ..., ocorr_m)The type may be floating point or promoted to complex depending on the combinations inoutput.Notes
Only stokes parameters, linear and circular correlations are currently handled, but the full list of id’s and strings as defined in the CASA documentation is:
{{ Undefined: 0, I: 1, Q: 2, U: 3, V: 4, RR: 5, RL: 6, LR: 7, LL: 8, XX: 9, XY: 10, YX: 11, YY: 12, RX: 13, RY: 14, LX: 15, LY: 16, XR: 17, XL: 18, YR: 19, YL: 20, PP: 21, PQ: 22, QP: 23, QQ: 24, RCircular: 25, LCircular: 26, Linear: 27, Ptotal: 28, Plinear: 29, PFtotal: 30, PFlinear: 31, Pangle: 32 }}
Cuda¶
convert(inputs, input_schema, output_schema) |
This function converts forward and backward from stokes I,Q,U,V to both linear XX,XY,YX,YY and circular RR, RL, LR, LL correlations. |
-
africanus.model.coherency.cuda.convert(inputs, input_schema, output_schema)[source]¶ This function converts forward and backward from stokes
I,Q,U,Vto both linearXX,XY,YX,YYand circularRR, RL, LR, LLcorrelations.For example, we can convert from stokes parameters to linear correlations:
stokes.shape == (10, 4, 4) corrs = convert(stokes, ["I", "Q", "U", "V"], [['XX', 'XY'], ['YX', 'YY']) assert corrs.shape == (10, 4, 2, 2)
Or circular correlations to stokes:
vis.shape == (10, 4, 2, 2) stokes = convert(vis, [['RR', 'RL'], ['LR', 'LL']], ['I', 'Q', 'U', 'V']) assert stokes.shape == (10, 4, 4)
inputcanoutputcan be arbitrarily nested or ordered lists, but the appropriate inputs must be present to produce the requested outputs.The elements of
inputandoutputmay be strings or integers representing stokes parameters or correlations. See the Notes for a full list.Parameters: input :
cupy.ndarrayComplex or floating point input data of shape
(dim_1, ..., dim_n, icorr_1, ..., icorr_m)input_schema : list of str or int
A schema describing the
icorr_1, ..., icorr_mdimension ofinput. Must have the same shape as the last dimensions ofinput.output_schema : list of str or int
A schema describing the
ocorr_1, ..., ocorr_ndimension of the return value.Returns: result :
cupy.ndarrayResult of shape
(dim_1, ..., dim_n, ocorr_1, ..., ocorr_m)The type may be floating point or promoted to complex depending on the combinations inoutput.Notes
Only stokes parameters, linear and circular correlations are currently handled, but the full list of id’s and strings as defined in the CASA documentation is:
{{ Undefined: 0, I: 1, Q: 2, U: 3, V: 4, RR: 5, RL: 6, LR: 7, LL: 8, XX: 9, XY: 10, YX: 11, YY: 12, RX: 13, RY: 14, LX: 15, LY: 16, XR: 17, XL: 18, YR: 19, YL: 20, PP: 21, PQ: 22, QP: 23, QQ: 24, RCircular: 25, LCircular: 26, Linear: 27, Ptotal: 28, Plinear: 29, PFtotal: 30, PFlinear: 31, Pangle: 32 }}
Dask¶
convert(input, input_schema, output_schema) |
This function converts forward and backward from stokes I,Q,U,V to both linear XX,XY,YX,YY and circular RR, RL, LR, LL correlations. |
-
africanus.model.coherency.dask.convert(input, input_schema, output_schema)[source]¶ This function converts forward and backward from stokes
I,Q,U,Vto both linearXX,XY,YX,YYand circularRR, RL, LR, LLcorrelations.For example, we can convert from stokes parameters to linear correlations:
stokes.shape == (10, 4, 4) corrs = convert(stokes, ["I", "Q", "U", "V"], [['XX', 'XY'], ['YX', 'YY']) assert corrs.shape == (10, 4, 2, 2)
Or circular correlations to stokes:
vis.shape == (10, 4, 2, 2) stokes = convert(vis, [['RR', 'RL'], ['LR', 'LL']], ['I', 'Q', 'U', 'V']) assert stokes.shape == (10, 4, 4)
inputcanoutputcan be arbitrarily nested or ordered lists, but the appropriate inputs must be present to produce the requested outputs.The elements of
inputandoutputmay be strings or integers representing stokes parameters or correlations. See the Notes for a full list.Parameters: input :
dask.array.ArrayComplex or floating point input data of shape
(dim_1, ..., dim_n, icorr_1, ..., icorr_m)input_schema : list of str or int
A schema describing the
icorr_1, ..., icorr_mdimension ofinput. Must have the same shape as the last dimensions ofinput.output_schema : list of str or int
A schema describing the
ocorr_1, ..., ocorr_ndimension of the return value.Returns: result :
dask.array.ArrayResult of shape
(dim_1, ..., dim_n, ocorr_1, ..., ocorr_m)The type may be floating point or promoted to complex depending on the combinations inoutput.Notes
Only stokes parameters, linear and circular correlations are currently handled, but the full list of id’s and strings as defined in the CASA documentation is:
{{ Undefined: 0, I: 1, Q: 2, U: 3, V: 4, RR: 5, RL: 6, LR: 7, LL: 8, XX: 9, XY: 10, YX: 11, YY: 12, RX: 13, RY: 14, LX: 15, LY: 16, XR: 17, XL: 18, YR: 19, YL: 20, PP: 21, PQ: 22, QP: 23, QQ: 24, RCircular: 25, LCircular: 26, Linear: 27, Ptotal: 28, Plinear: 29, PFtotal: 30, PFlinear: 31, Pangle: 32 }}
Spectral Model¶
Functionality for computing a Spectral Model.
Numpy¶
spectral_model(stokes, spi, ref_freq, frequency) |
Compute a spectral model, per polarisation. |
-
africanus.model.spectral.spectral_model(stokes, spi, ref_freq, frequency, base=0)[source]¶ Compute a spectral model, per polarisation.
\begin{eqnarray} I(\lambda) & = & I_0 \prod_{i=1} (\lambda / \lambda_0)^{\alpha_{i}} \\ \ln( I(\lambda) ) & = & \sum_{i=0} \alpha_{i} \ln (\lambda / \lambda_0)^i \, \textrm{where} \, \alpha_0 = \ln I_0 \\ \log_{10}( I(\lambda) ) & = & \sum_{i=0} \alpha_{i} \log_{10} (\lambda / \lambda_0)^i \, \textrm{where} \, \alpha_0 = \log_{10} I_0 \\ \end{eqnarray}Parameters: stokes :
numpy.ndarrayStokes parameters of shape
(source,)or(source, pol). If apoldimension is present, then it must also be present onspi.spi :
numpy.ndarraySpectral index of shape
(source, spi-comps)or(source, spi-comps, pol).ref_freq :
numpy.ndarrayReference frequencies of shape
(source,)frequencies :
numpy.ndarrayFrequencies of shape
(chan,)base : {“std”, “log”, “log10”} or {0, 1, 2} or list.
string or corresponding enumeration specifying the polynomial base. Defaults to 0.
If a list is provided, a polynomial base can be specified for each stokes parameter or polarisation in the
poldimension.string specification of the base is only supported in python 3. while the corresponding integer enumerations are supported on all python versions.
Returns: spectral_model :
numpy.ndarraySpectral Model of shape
(source, chan)or(source, chan, pol).
Dask¶
spectral_model(stokes, spi, ref_freq, …[, …]) |
Compute a spectral model, per polarisation. |
-
africanus.model.spectral.dask.spectral_model(stokes, spi, ref_freq, frequencies, base=0)[source]¶ Compute a spectral model, per polarisation.
\begin{eqnarray} I(\lambda) & = & I_0 \prod_{i=1} (\lambda / \lambda_0)^{\alpha_{i}} \\ \ln( I(\lambda) ) & = & \sum_{i=0} \alpha_{i} \ln (\lambda / \lambda_0)^i \, \textrm{where} \, \alpha_0 = \ln I_0 \\ \log_{10}( I(\lambda) ) & = & \sum_{i=0} \alpha_{i} \log_{10} (\lambda / \lambda_0)^i \, \textrm{where} \, \alpha_0 = \log_{10} I_0 \\ \end{eqnarray}Parameters: stokes :
dask.array.ArrayStokes parameters of shape
(source,)or(source, pol). If apoldimension is present, then it must also be present onspi.spi :
dask.array.ArraySpectral index of shape
(source, spi-comps)or(source, spi-comps, pol).ref_freq :
dask.array.ArrayReference frequencies of shape
(source,)frequencies :
dask.array.ArrayFrequencies of shape
(chan,)base : {“std”, “log”, “log10”} or {0, 1, 2} or list.
string or corresponding enumeration specifying the polynomial base. Defaults to 0.
If a list is provided, a polynomial base can be specified for each stokes parameter or polarisation in the
poldimension.string specification of the base is only supported in python 3. while the corresponding integer enumerations are supported on all python versions.
Returns: spectral_model :
dask.array.ArraySpectral Model of shape
(source, chan)or(source, chan, pol).
Spectral Index¶
Functionality related to the spectral index.
For example, we may want to compute the spectral indices of components in a sky model defined by
where \(\nu\) are frequencies ay
which we want to construct the intensity
of a Stokes I image and the \(\nu_0\)
is the corresponding reference frequency.
The spectral index \(\alpha\)
determines how quickly the intensity grows
or decays as a function of frequency.
Given a list of model image components
(preferably with the residuals added back
in) we can recover the corresponding
spectral indices and reference intensities
using the fit_spi_components()
function. This will also return a lower bound
on the associated uncertainties on these
components.
Numpy¶
fit_spi_components(data, weights, freqs, freq0) |
Computes the spectral indices and the intensity at the reference frequency of a spectral index model: |
-
africanus.model.spi.fit_spi_components(data, weights, freqs, freq0, alphai=None, I0i=None, beam=None, tol=0.0001, maxiter=100)[source]¶ Computes the spectral indices and the intensity at the reference frequency of a spectral index model:
\[I(\nu) = A(\nu) I(\nu_0) \left( \frac{\nu}{\nu_0} \right) ^ \alpha\]where \(I(\nu)\) is the apparent source spectrum, \(A(\nu)\) is the beam model for each component as a function of frequency.
Parameters: data :
numpy.ndarrayarray of shape
(comps, chan)The noisy data as a function of frequency.weights :
numpy.ndarrayarray of shape
(chan,)Inverse of variance on each frequency axis.freqs :
numpy.ndarrayfrequencies of shape
(chan,)freq0 : float
Reference frequency
alphai :
numpy.ndarray, optionalarray of shape
(comps,)Initial guess for the alphas. Defaults to -0.7.I0i :
numpy.ndarray, optionalarray of shape
(comps,)Initial guess for the intensities at the reference frequency. Defaults to 1.0.beam_comps :
numpy.ndarray, optionalarray of shape
(comps, chan)Power beam for each component as a function of frequency.tol : float, optional
Solver absolute tolerance (optional). Defaults to 1e-6.
maxiter : int, optional
Solver maximum iterations (optional). Defaults to 100.
dtype : np.dtype, optional
Datatype of result. Should be either np.float32 or np.float64. Defaults to np.float64.
Returns: out :
numpy.ndarrayarray of shape
(4, comps)The fitted components arranged as [alphas, alphavars, I0s, I0vars]
Dask¶
fit_spi_components(data, weights, freqs, freq0) |
Computes the spectral indices and the intensity at the reference frequency of a spectral index model: |
-
africanus.model.spi.dask.fit_spi_components(data, weights, freqs, freq0, alphai=None, I0i=None, beam=None, tol=1e-05, maxiter=100)[source]¶ Computes the spectral indices and the intensity at the reference frequency of a spectral index model:
\[I(\nu) = A(\nu) I(\nu_0) \left( \frac{\nu}{\nu_0} \right) ^ \alpha\]where \(I(\nu)\) is the apparent source spectrum, \(A(\nu)\) is the beam model for each component as a function of frequency.
Parameters: data :
dask.array.Arrayarray of shape
(comps, chan)The noisy data as a function of frequency.weights :
dask.array.Arrayarray of shape
(chan,)Inverse of variance on each frequency axis.freqs :
dask.array.Arrayfrequencies of shape
(chan,)freq0 : float
Reference frequency
alphai :
dask.array.Array, optionalarray of shape
(comps,)Initial guess for the alphas. Defaults to -0.7.I0i :
dask.array.Array, optionalarray of shape
(comps,)Initial guess for the intensities at the reference frequency. Defaults to 1.0.beam_comps :
dask.array.Array, optionalarray of shape
(comps, chan)Power beam for each component as a function of frequency.tol : float, optional
Solver absolute tolerance (optional). Defaults to 1e-6.
maxiter : int, optional
Solver maximum iterations (optional). Defaults to 100.
dtype : np.dtype, optional
Datatype of result. Should be either np.float32 or np.float64. Defaults to np.float64.
Returns: out :
dask.array.Arrayarray of shape
(4, comps)The fitted components arranged as [alphas, alphavars, I0s, I0vars]
Source Morphology¶
Shape functions for different Source Morphologies
Numpy¶
gaussian(uvw, frequency, shape_params) |
Computes the Gaussian Shape Function. |
-
africanus.model.shape.gaussian(uvw, frequency, shape_params)[source]¶ Computes the Gaussian Shape Function.
\[\begin{split}& \lambda^\prime = 2 \lambda \pi \\ & r = \frac{e_{min}}{e_{maj}} \\ & u_{1} = (u \, e_{maj} \, cos(\alpha) - v \, e_{maj} \, sin(\alpha)) r \lambda^\prime \\ & v_{1} = (u \, e_{maj} \, sin(\alpha) - v \, e_{maj} \, cos(\alpha)) \lambda^\prime \\ & \textrm{shape} = e^{(-u_{1}^2 - v_{1}^2)}\end{split}\]where:
- \(u\) and \(v\) are the UV coordinates and \(\lambda\) the frequency.
- \(e_{maj}\) and \(e_{min}\) are the major and minor axes and \(\alpha\) the position angle.
Parameters: uvw :
numpy.ndarrayUVW coordinates of shape
(row, 3)frequency :
numpy.ndarrayfrequencies of shape
(chan,)shape_param :
numpy.ndarrayGaussian Shape Parameters of shape
(source, 3)where the second dimension contains the (emajor, eminor, angle) parameters describing the shape of the GaussianReturns: gauss_shape :
numpy.ndarrayShape parameters of shape
(source, row, chan)
Dask¶
gaussian(uvw, frequency, shape_params) |
Computes the Gaussian Shape Function. |
-
africanus.model.shape.dask.gaussian(uvw, frequency, shape_params)[source]¶ Computes the Gaussian Shape Function.
\[\begin{split}& \lambda^\prime = 2 \lambda \pi \\ & r = \frac{e_{min}}{e_{maj}} \\ & u_{1} = (u \, e_{maj} \, cos(\alpha) - v \, e_{maj} \, sin(\alpha)) r \lambda^\prime \\ & v_{1} = (u \, e_{maj} \, sin(\alpha) - v \, e_{maj} \, cos(\alpha)) \lambda^\prime \\ & \textrm{shape} = e^{(-u_{1}^2 - v_{1}^2)}\end{split}\]where:
- \(u\) and \(v\) are the UV coordinates and \(\lambda\) the frequency.
- \(e_{maj}\) and \(e_{min}\) are the major and minor axes and \(\alpha\) the position angle.
Parameters: uvw :
dask.array.ArrayUVW coordinates of shape
(row, 3)frequency :
dask.array.Arrayfrequencies of shape
(chan,)shape_param :
dask.array.ArrayGaussian Shape Parameters of shape
(source, 3)where the second dimension contains the (emajor, eminor, angle) parameters describing the shape of the GaussianReturns: gauss_shape :
dask.array.ArrayShape parameters of shape
(source, row, chan)
WSClean Spectral Model¶
Utilities for creating a spectral model from a wsclean component file.
Numpy¶
load(filename) |
Loads wsclean component model. |
spectra(I, coeffs, log_poly, ref_freq, frequency) |
Produces a spectral model from a polynomial expansion of a wsclean file model. |
-
africanus.model.wsclean.load(filename)[source]¶ Loads wsclean component model.
sources = load("components.txt") sources = dict(sources) # Convert to dictionary I = sources["I"] ref_freq = sources["ReferenceFrequency"]
See the WSClean Component List for further details.
Parameters: filename : str or iterable
Filename of wsclean model file or iterable producing the lines of the file.
Returns: list of (name, list of values) tuples
list of column (name, value) tuples
See also
-
africanus.model.wsclean.spectra(I, coeffs, log_poly, ref_freq, frequency)[source]¶ Produces a spectral model from a polynomial expansion of a wsclean file model. Depending on how log_poly is set ordinary or logarithmic polynomials are used to produce the expansion:
\[\begin{split}& flux(\lambda) = I_{0} + \sum\limits_{c=0} \textrm{coeffs}(c) ({\lambda/\lambda_{ref}} - 1)^{c+1} \\ & flux(\lambda) = \exp \left( \log I_{0} + \sum\limits_{c=0} \textrm{coeffs}(c) \log({\lambda/\lambda_{ref}})^{c+1} \right) \\\end{split}\]See the WSClean Component List for further details.
Parameters: I :
numpy.ndarrayflux density in Janskys at the reference frequency of shape
(source,)coeffs :
numpy.ndarrayPolynomial coefficients for each source of shape
(source, comp)log_poly :
numpy.ndarrayor boolboolean array of shape
(source, )indicating whether logarithmic (True) or ordinary (False) polynomials should be used.ref_freq :
numpy.ndarraySource reference frequencies of shape
(source,)frequency :
numpy.ndarrayfrequencies of shape
(chan,)Returns: spectral_model :
numpy.ndarraySpectral Model of shape
(source, chan)See also
Dask¶
spectra(stokes, spi, log_si, ref_freq, frequency) |
Produces a spectral model from a polynomial expansion of a wsclean file model. |
-
africanus.model.wsclean.dask.spectra(stokes, spi, log_si, ref_freq, frequency)[source]¶ Produces a spectral model from a polynomial expansion of a wsclean file model. Depending on how log_poly is set ordinary or logarithmic polynomials are used to produce the expansion:
\[\begin{split}& flux(\lambda) = I_{0} + \sum\limits_{c=0} \textrm{coeffs}(c) ({\lambda/\lambda_{ref}} - 1)^{c+1} \\ & flux(\lambda) = \exp \left( \log I_{0} + \sum\limits_{c=0} \textrm{coeffs}(c) \log({\lambda/\lambda_{ref}})^{c+1} \right) \\\end{split}\]See the WSClean Component List for further details.
Parameters: I :
dask.array.Arrayflux density in Janskys at the reference frequency of shape
(source,)coeffs :
dask.array.ArrayPolynomial coefficients for each source of shape
(source, comp)log_poly :
dask.array.Arrayor boolboolean array of shape
(source, )indicating whether logarithmic (True) or ordinary (False) polynomials should be used.ref_freq :
dask.array.ArraySource reference frequencies of shape
(source,)frequency :
dask.array.Arrayfrequencies of shape
(chan,)Returns: spectral_model :
dask.array.ArraySpectral Model of shape
(source, chan)See also