`Comrade.Comrade`

— Module`Comrade`

Composable Modeling of Radio Emission

`Comrade.AbstractInterferometryDatum`

— Type`abstract type AbstractInterferometryDatum{T}`

An abstract type for all VLBI interfermetry data types. See `Comrade.EHTVisibilityDatum`

for an example.

`Comrade.ArrayBaselineDatum`

— Type`struct ArrayBaselineDatum{T, E, V}`

A single datum of an `ArrayConfiguration`

`Comrade.ArrayConfiguration`

— Type`abstract type ArrayConfiguration`

This defined the abstract type for an array configuration. Namely, baseline times, SEFD's, bandwidth, observation frequencies, etc.

`Comrade.CalPrior`

— Method`CalPrior(dists, cache::JonesCache, reference=:none)`

Creates a distribution for the gain priors for gain cache `cache`

. The `dists`

should be a NamedTuple of `Distributions`

, where each name corresponds to a telescope or station in the observation. The resulting type is a subtype of the `Distributions.AbstractDistribution`

so the usual `Distributions`

interface should work.

**Example**

For the 2017 observations of M87 a common CalPrior call is:

```
julia> gdist = CalPrior((AA = LogNormal(0.0, 0.1),
AP = LogNormal(0.0, 0.1),
JC = LogNormal(0.0, 0.1),
SM = LogNormal(0.0, 0.1),
AZ = LogNormal(0.0, 0.1),
LM = LogNormal(0.0, 1.0),
PV = LogNormal(0.0, 0.1)
), cache)
julia> x = rand(gdist)
julia> logdensityof(gdist, x)
```

`Comrade.CalPrior`

— Method`CalPrior(dist0::NamedTuple, dist_transition::NamedTuple, jcache::SegmentedJonesCache)`

Constructs a calibration prior in two steps. The first two arguments have to be a named tuple of distributions, where each name corresponds to a site. The first argument is gain prior for the first time stamp. The second argument is the segmented gain prior for each subsequent time stamp. For instance, if we have

```
dist0 = (AA = Normal(0.0, 1.0), )
distt = (AA = Normal(0.0, 0.1), )
```

then the gain prior for first time stamp that AA obserserves will be `Normal(0.0, 1.0)`

. The next time stamp gain is the construted from

`g2 = g1 + ϵ1`

where `ϵ1 ~ Normal(0.0, 0.1) = distt.AA`

, and `g1`

is the gain from the first time stamp. In other words `distt`

is the uncorrelated transition probability when moving from timestamp i to timestamp i+1. For the typical pre-calibrated dataset the gain prior on `distt`

can be tighter than the prior on `dist0`

.

`Comrade.CalTable`

— Type`struct CalTable{T, G<:(AbstractVecOrMat)}`

A Tabes of calibration quantities. The columns of the table are the telescope station codes. The rows are the calibration quantities at a specific time stamp. This user should not use this struct directly. Instead that should call `caltable`

.

`Comrade.ClosureConfig`

— Type`struct ClosureConfig{A, D} <: Comrade.ArrayConfiguration`

Array config file for closure quantities. This stores the design matrix `designmat`

that transforms from visibilties to closure products.

**Fields**

`ac`

: Array configuration for visibilities`designmat`

: Closure design matrix

`Comrade.ClosurePhases`

— Type`ClosuresPhases(;kwargs...)`

Type to specify to extract the closure phase table in the `extract_table`

function. Optional keywords are passed through `extract_table`

to specify additional option.

**Special keywords for eht-imaging with Pyehtim.jl**

For a list of potential keyword arguments see `eht-imaging`

and `add_cphase`

command for obsdata. In addition note we have changed the following:

- count: How the closures are formed, the available options are "min-correct", "min", "max"

**Warning**

The `count`

keyword argument is treated specially in `Comrade`

. The default option is "min-correct" and should almost always be used. This option construct a minimal set of closure phases that is valid even when the array isn't fully connected. For testing and legacy reasons we `ehtim`

other count options are also included. However, the current `ehtim`

count="min" option is broken and does construct proper minimal sets of closure quantities if the array isn't fully connected.

`Comrade.Coherencies`

— Type`Coherencies(;kwargs...)`

Type to specify to extract the coherency matrices table in the `extract_table`

function. Optional keywords are passed through `extract_table`

to specify additional option.

**Special keywords for eht-imaging with Pyehtim.jl**

Any keyword arguments are ignored for now. Use eht-imaging directly to modify the data.

`Comrade.ComplexVisibilities`

— Type`ComplexVisibilities(;kwargs...)`

Type to specify to extract the complex visibilities table in the `extract_table`

function. Optional keywords are passed through `extract_table`

to specify additional option.

**Special keywords for eht-imaging with Pyehtim.jl**

Any keyword arguments are ignored for now. Use eht-imaging directly to modify the data.

`Comrade.DesignMatrix`

— Type`struct DesignMatrix{X, M<:AbstractArray{X, 2}, T, S} <: AbstractArray{X, 2}`

Internal type that holds the gain design matrices for visibility corruption.

`Comrade.EHTArrayConfiguration`

— Type`struct EHTArrayConfiguration{F, T, S, D<:AbstractArray} <: Comrade.ArrayConfiguration`

Stores all the non-visibility data products for an EHT array. This is useful when evaluating model visibilities.

**Fields**

`bandwidth`

: Observing bandwith (Hz)

`tarr`

: Telescope array file

`scans`

: Scan times

`data`

: A struct array of`ArrayBaselineDatum`

holding time, freq, u, v, baselines.

`Comrade.EHTClosurePhaseDatum`

— Type`struct EHTClosurePhaseDatum{S<:Number} <: Comrade.ClosureProducts{S<:Number}`

A Datum for a single closure phase.

**Fields**

`measurement`

: closure phase (rad)

`error`

: error of the closure phase assuming the high-snr limit

`U1`

: u (λ) of first station

`V1`

: v (λ) of first station

`U2`

: u (λ) of second station

`V2`

: v (λ) of second station

`U3`

: u (λ) of third station

`V3`

: v (λ) of third station

`T`

: Measured time of closure phase in hours

`F`

: Measured frequency of closure phase in Hz

`triangle`

: station baselines used

`Comrade.EHTCoherencyDatum`

— Type`struct EHTCoherencyDatum{S, B1, B2, M<:(StaticArraysCore.SArray{Tuple{2, 2}, Complex{S}, 2}), E<:(StaticArraysCore.SArray{Tuple{2, 2}, S, 2})} <: Comrade.AbstractInterferometryDatum{S}`

A Datum for a single coherency matrix

**Fields**

`measurement`

: coherency matrix, with entries in Jy

`error`

: visibility uncertainty matrix, with entries in Jy

`U`

: x-direction baseline length, in λ

`V`

: y-direction baseline length, in λ

`T`

: Timestamp, in hours

`F`

: Frequency, in Hz

`baseline`

: station baseline codes

`polbasis`

: polarization basis for each station

`Comrade.EHTLogClosureAmplitudeDatum`

— Type`struct EHTLogClosureAmplitudeDatum{S<:Number} <: Comrade.ClosureProducts{S<:Number}`

A Datum for a single log closure amplitude.

`measurement`

: log-closure amplitude

`error`

: log-closure amplitude error in the high-snr limit

`U1`

: u (λ) of first station

`V1`

: v (λ) of first station

`U2`

: u (λ) of second station

`V2`

: v (λ) of second station

`U3`

: u (λ) of third station

`V3`

: v (λ) of third station

`U4`

: u (λ) of fourth station

`V4`

: v (λ) of fourth station

`T`

: Measured time of closure phase in hours

`F`

: Measured frequency of closure phase in Hz

`quadrangle`

: station codes for the quadrangle

`Comrade.EHTObservation`

— Type`struct EHTObservation{F, T<:Comrade.AbstractInterferometryDatum{F}, S<:(StructArrays.StructArray{T<:Comrade.AbstractInterferometryDatum{F}}), A, N} <: Comrade.Observation{F}`

The main data product type in `Comrade`

this stores the `data`

which can be a StructArray of any `AbstractInterferometryDatum`

type.

**Fields**

`data`

: StructArray of data productts

`config`

: Array config holds ancillary information about array

`mjd`

: modified julia date of the observation

`ra`

: RA of the observation in J2000 (deg)

`dec`

: DEC of the observation in J2000 (deg)

`bandwidth`

: bandwidth of the observation (Hz)

`source`

: Common source name

`timetype`

: Time zone used.

`Comrade.EHTVisibilityAmplitudeDatum`

— Type`struct EHTVisibilityAmplitudeDatum{S<:Number} <: Comrade.AbstractVisibilityDatum{S<:Number}`

A struct holding the information for a single measured visibility amplitude.

**FIELDS**

`measurement`

: amplitude (Jy)

`error`

: error of the visibility amplitude (Jy)

`U`

: u position of the data point in λ

`V`

: v position of the data point in λ

`T`

: time of the data point in (Hr)

`F`

: frequency of the data point (Hz)

`baseline`

: station baseline codes

`Comrade.EHTVisibilityDatum`

— Type`struct EHTVisibilityDatum{S<:Number} <: Comrade.AbstractVisibilityDatum{S<:Number}`

A struct holding the information for a single measured complex visibility.

**FIELDS**

`measurement`

: Complex Vis. measurement (Jy)

`error`

: error of the complex vis (Jy)

`U`

: u position of the data point in λ

`V`

: v position of the data point in λ

`T`

: time of the data point in (Hr)

`F`

: frequency of the data point (Hz)

`baseline`

: station baseline codes

`Comrade.FixedSeg`

— Type`struct FixedSeg{T} <: Comrade.ObsSegmentation`

Enforces that the station calibraton value will have a fixed `value`

. This is most commonly used when enforcing a reference station for gain phases.

`Comrade.GainSchema`

— Type`GainSchema(sites, times)`

Constructs a schema for the gains of an observation. The `sites`

and `times`

correspond to the specific site and time for each gain that will be modeled.

`Comrade.IntegSeg`

— Type`struct IntegSeg{S} <: Comrade.ObsSegmentation`

Data segmentation such that the quantity is constant over a correlation integration.

`Comrade.IsCube`

— Type`struct IsCube`

Specifies that the sampling algorithm usually expects a hypercube transform

`Comrade.IsFlat`

— Type`struct IsFlat`

Specifies that the sampling algorithm usually expects a uncontrained transform

`Comrade.JonesCache`

— Type`struct JonesCache{D1, D2, S, Sc, R} <: Comrade.AbstractJonesCache`

Holds the ancillary information for a the design matrix cache for Jones matrices. That is, it defines the cached map that moves from model visibilities to the corrupted voltages that are measured from the telescope.

**Fields**

`m1`

: Design matrix for the first station

`m2`

: Design matrix for the second station

`seg`

: Segmentation schemes for this cache

`schema`

: Gain Schema

`references`

: List of Reference stations

`Comrade.JonesModel`

— Method```
JonesModel(jones::JonesPairs, refbasis = CirBasis())
JonesModel(jones::JonesPairs, tcache::ResponseCache)
```

Constructs the intrument corruption model using pairs of jones matrices `jones`

and a reference basis

`Comrade.JonesPairs`

— Type`struct JonesPairs{T, M1<:AbstractArray{T, 1}, M2<:AbstractArray{T, 1}}`

Holds the pairs of Jones matrices for the first and second station of a baseline.

**Fields**

`m1`

: Vector of jones matrices for station 1

`m2`

: Vector of jones matrices for station 2

`Comrade.LogClosureAmplitudes`

— Type`LogClosureAmplitudes(;kwargs...)`

Type to specify to extract the log closure amplitudes table in the `extract_table`

function. Optional keywords are passed through `extract_table`

to specify additional option.

**Special keywords for eht-imaging with Pyehtim.jl**

For a list of potential keyword arguments see `eht-imaging`

and `add_cphase`

command for obsdata. In addition note we have changed the following:

- count: How the closures are formed, the available options are "min-correct", "min", "max"

Returns an EHTObservation with log-closure amp. datums

**Warning**

The `count`

keyword argument is treated specially in `Comrade`

. The default option is "min-correct" and should almost always be used. This option construct a minimal set of closure phases that is valid even when the array isn't fully connected. For testing and legacy reasons we `ehtim`

other count options are also included. However, the current `ehtim`

count="min" option is broken and does construct proper minimal sets of closure quantities if the array isn't fully connected.

`Comrade.MultiRadioLikelihood`

— Type`MultiRadioLikelihood(lklhd1, lklhd2, ...)`

Combines multiple likelihoods into one object that is useful for fitting multiple days/frequencies.

```
julia> lklhd1 = RadioLikelihood(dcphase1, dlcamp1)
julia> lklhd2 = RadioLikelihood(dcphase2, dlcamp2)
julia> MultiRadioLikelihood(lklhd1, lklhd2)
```

`Comrade.ObsSegmentation`

— Type`abstract type ObsSegmentation`

The data segmentation scheme to use. This is important for constructing a `JonesCache`

`Comrade.Posterior`

— Type`Posterior(lklhd, prior)`

Creates a Posterior density that follows obeys DensityInterface. The `lklhd`

object is expected to be a `VLB`

object. For instance, these can be created using `RadioLikelihood`

. `prior`

**Notes**

Since this function obeys `DensityInterface`

you can evaluate it with

```
julia> ℓ = logdensityof(post)
julia> ℓ(x)
```

or using the 2-argument version directly

`julia> logdensityof(post, x)`

where `post::Posterior`

.

To generate random draws from the prior see the `prior_sample`

function.

`Comrade.RIMEModel`

— Type`abstract type RIMEModel <: ComradeBase.AbstractModel`

Abstract type that encompasses all RIME style corruptions.

`Comrade.RadioLikelihood`

— Method```
RadioLikelihood(skymodel, instumentmodel, dataproducts::EHTObservation...;
skymeta=nothing,
instrumentmeta=nothing)
```

Creates a RadioLikelihood using the `skymodel`

its related metadata `skymeta`

and the `instrumentmodel`

and its metadata `instumentmeta`

. . The `model`

is a function that converts from parameters `θ`

to a Comrade AbstractModel which can be used to compute `visibilities`

and a set of `metadata`

that is used by `model`

to compute the model.

**Warning**

The `model`

itself must be a two argument function where the first argument is the set of model parameters and the second is a container that holds all the additional information needed to construct the model. An example of this is when the model needs some precomputed cache to define the model.

**Example**

```
dlcamp, dcphase = extract_table(obs, LogClosureAmplitude(), ClosurePhases())
cache = create_cache(NFFTAlg(dlcamp), IntensityMap(zeros(128,128), μas2rad(100.0), μas2rad(100.0)))
function skymodel(θ, metadata)
(; r, a) = θ
(; cache) = metadata
m = stretched(ExtendedRing(a), r, r)
return modelimage(m, metadata.cache)
end
function instrumentmodel(g, metadata)
(;lg, gp) = g
(;gcache) = metadata
jonesStokes(lg.*exp.(1im.*gp), gcache)
end
prior = (
r = Uniform(μas2rad(10.0), μas2rad(40.0)),
a = Uniform(0.1, 5.0)
)
RadioLikelihood(skymodel, instrumentmodel, dataproducts::EHTObservation...;
skymeta=(;cache,),
instrumentmeta=(;gcache))
```

`Comrade.RadioLikelihood`

— Method`RadioLikelihood(skymodel, dataproducts::EHTObservation...; skymeta=nothing)`

Forms a radio likelihood from a set of data products using only a sky model. This intrinsically assumes that the instrument model is not required since it is perfect. This is useful when fitting closure quantities which are independent of the instrument.

If you want to form a likelihood from multiple arrays such as when fitting different wavelengths or days, you can combine them using `MultiRadioLikelihood`

**Example**

`julia> RadioLikelihood(skymodel, dcphase, dlcamp)`

`Comrade.RandomReference`

— Method`RandomReference(val::Number)`

For each timestamp select a random reference station whose station gain will be set to `val`

.

**Notes**

This is useful when there isn't a single site available for all scans and you want to split up the choice of reference site. We recommend only using this option for Stokes I fitting.

`Comrade.ResponseCache`

— Type`struct ResponseCache{M, B<:PolBasis} <: Comrade.AbstractJonesCache`

Holds various transformations that move from the measured telescope basis to the **chosen** on sky reference basis.

**Fields**

`T1`

: Transform matrices for the first stations

`T2`

: Transform matrices for the second stations

`refbasis`

: Reference polarization basis

`Comrade.ResponseCache`

— Method`ResponseCache(obs::EHTObservation; add_fr=true, ehtim_fr_convention=false, ref::PolBasis=CirBasis())`

Constructs the cache that holds the transformation from the **chosen** on-sky reference basis to the basis that the telescope measures the electric fields given an observation `obs`

. Our convention is that the feed rotations are included in the transformation cache with the `add_fr`

toggle. The user can specify the reference basis using the keyword argument `ref`

which is the (R,L) circular basis by default.

**Notes**

We use the following definition for our feed rotations in circular basis

```
exp(-iθ) 0
0 exp(iθ)
```

and in the linear feed basis

```
cos(θ) sin(θ)
-sin(θ) cos(θ)
```

**Warning**

eht-imaging can sometimes pre-rotate the coherency matrices. As a result the field rotation can sometimes be applied twice. To compensate for this we have added a `ehtim_fr_convention`

which will fix this.

`Comrade.SEFDReference`

— Type`SiteOrderReference(val::Number, sefd_index = 1)`

Selects the reference site based on the SEFD of each telescope, where the smallest SEFD is preferentially selected. The reference gain is set to `val`

and the user can select to use the `n`

lowest SEFD site by passing `sefd_index = n`

.

**Notes**

This is done on a per-scan basis so if a site is missing from a scan the next highest SEFD site will be used.

`Comrade.Scan`

— Type`struct Scan{T, I, S}`

Composite type that holds information for a single scan of the telescope.

**Fields**

`time`

: Scan time

`index`

: Scan indices which are (scan index, data start index, data end index)

`scan`

: Scan data usually a StructArray of a <:AbstractVisibilityDatum

`Comrade.ScanSeg`

— Type`struct ScanSeg{S} <: Comrade.ObsSegmentation`

Data segmentation such that the quantity is constant over a `scan`

.

**Warning**

Currently we do not explicity track the telescope scans. This will be fixed in a future version. Right now `ScanSeg`

and `TrackSeg`

are the same

`Comrade.ScanTable`

— Type`struct ScanTable{O<:Union{Comrade.ArrayConfiguration, Comrade.Observation}, T, S}`

Wraps EHTObservation in a table that separates the observation into scans. This implements the table interface. You can access scans by directly indexing into the table. This will create a view into the table not copying the data.

**Example**

```
julia> st = scantable(obs)
julia> st[begin] # grab first scan
julia> st[end] # grab last scan
```

`Comrade.SegmentedJonesCache`

— Type`struct SegmentedJonesCache{D, S<:Comrade.ObsSegmentation, ST, Ti} <: Comrade.AbstractJonesCache`

Holds the ancillary information for a the design matrix cache for Jones matrices. That is, it defines the cached map that moves from model visibilities to the corrupted voltages that are measured from the telescope. This uses a segmented decomposition so that the gain at a single timestamp is the sum of the previous gains. In this formulation the gains parameters are the segmented gain offsets from timestamp to timestamp

**Fields**

`m1`

: Design matrix for the first station

`m2`

: Design matrix for the second station

`seg`

: Segmentation scheme for this cache

`stations`

: station codes

`times`

: times

`Comrade.SingleReference`

— Method`SingleReference(site::Symbol, val::Number)`

Use a single site as a reference. The station gain will be set equal to `val`

.

`Comrade.TrackSeg`

— Type`struct TrackSeg <: Comrade.ObsSegmentation`

Data segmentation such that the quantity is constant over a `track`

, i.e., the observation "night".

`Comrade.TransformedPosterior`

— Type`Comrade.VLBIModel`

— Type`VLBIModel(skymodel, instrumentmodel)`

Constructs a `VLBIModel`

from a `jones`

pairs that describe the intrument model and the `model`

which describes the on-sky polarized visibilities. The third argument can either be the `tcache`

that converts from the model coherency basis to the instrumental basis, or just the `refbasis`

that will be used when constructing the model coherency matrices.

`Comrade.VisibilityAmplitudes`

— Type`ComplexVisibilities(;kwargs...)`

Type to specify to extract the log closure amplitudes table in the `extract_table`

function. Optional keywords are passed through `extract_table`

to specify additional option.

**Special keywords for eht-imaging with Pyehtim.jl**

For a list of potential keyword arguments see `eht-imaging`

and `add_amp`

command for obsdata.

`VLBISkyModels.DFTAlg`

— Method`DFTAlg(ac::ArrayConfiguration)`

Create an algorithm object using the direct Fourier transform object from the array configuration `ac`

. This will extract the uv positions from the observation to allow for a more efficient FT cache.

`VLBISkyModels.DFTAlg`

— Method`DFTAlg(obs::EHTObservation)`

Create an algorithm object using the direct Fourier transform object from the observation `obs`

. This will extract the uv positions from the observation to allow for a more efficient FT cache.

`VLBISkyModels.NFFTAlg`

— Method`NFFTAlg(ac::ArrayConfiguration; kwargs...)`

Create an algorithm object using the non-unform Fourier transform object from the array configuration `ac`

. This will extract the uv positions from the observation to allow for a more efficient FT cache.

The optional arguments are: `padfac`

specifies how much to pad the image by, and `m`

is an internal variable for `NFFT.jl`

.

`VLBISkyModels.NFFTAlg`

— Method`NFFTAlg(obs::EHTObservation; kwargs...)`

Create an algorithm object using the non-unform Fourier transform object from the observation `obs`

. This will extract the uv positions from the observation to allow for a more efficient FT cache.

The possible optional arguments are given in the `NFFTAlg`

struct.

`Base.map`

— Method`map(f, args::JonesPairs...) -> JonesPairs`

Maps over a set of `JonesPairs`

applying the function f to each element. This returns a collected JonesPair. This us useful for more advanced operations on Jones matrices.

**Examples**

```
map(G, D, F) do g, d, f
return f'*exp.(g)*d*f
end
```

`Comrade.arrayconfig`

— Method```
arrayconfig(vis)
```

Extract the array configuration from a EHT observation.

`Comrade.baselines`

— Method`baselines(CP::EHTClosurePhaseDatum)`

Returns the baselines used for a single closure phase datum

`Comrade.baselines`

— Method`baselines(CP::EHTLogClosureAmplitudeDatum)`

Returns the baselines used for a single closure phase datum

`Comrade.baselines`

— Method`baselines(scan::Scan)`

Return the baselines for each datum in a scan

`Comrade.beamsize`

— Method`beamsize(ac::ArrayConfiguration)`

Calculate the approximate beam size of the array `ac`

as the inverse of the longest baseline distance.

`Comrade.beamsize`

— Method`beamsize(obs::EHTObservation)`

Calculate the approximate beam size of the observation `obs`

as the inverse of the longest baseline distance.

`Comrade.caltable`

— Function`caltable(obs::EHTObservation, gains::AbstractVector)`

Create a calibration table for the observations `obs`

with `gains`

. This returns a `CalTable`

object that satisfies the `Tables.jl`

interface. This table is very similar to the `DataFrames`

interface.

**Example**

```
ct = caltable(obs, gains)
# Access a particular station (here ALMA)
ct[:AA]
ct.AA
# Access a the first row
ct[1, :]
```

`Comrade.caltable`

— Function`caltable(g::JonesCache, jterms::AbstractVector)`

Convert the JonesCache `g`

and recovered Jones/corruption elements `jterms`

into a `CalTable`

which satisfies the `Tables.jl`

interface.

**Example**

```
ct = caltable(gcache, gains)
# Access a particular station (here ALMA)
ct[:AA]
ct.AA
# Access a the first row
ct[1, :]
```

`Comrade.caltable`

— Function`caltable(args...)`

Creates a calibration table from a set of arguments. The specific arguments depend on what calibration you are applying.

`Comrade.dataproducts`

— Method`dataproducts(d::Posterior)`

Returns the data products you are fitting as a tuple. The order of the tuple corresponds to the order of the `dataproducts`

argument in `RadioLikelihood`

.

`Comrade.dataproducts`

— Method`dataproducts(d::RadioLikelihood)`

Returns the data products you are fitting as a tuple. The order of the tuple corresponds to the order of the `dataproducts`

argument in `RadioLikelihood`

.

`Comrade.dirty_beam`

— Method`dirty_beam(fov::Real, npix::Int, obs::EHTObservation{T,<:EHTVisibilityDatum}) where T`

Computes the dirty beam of the complex visibilities assuming a field of view of `fov`

and number of pixels `npix`

using baseline coverage found in `obs`

.

The `dirty beam`

is the inverse Fourier transform of the (u,v) coverage assuming every visibility is unity and everywhere else is zero.

`Comrade.dirty_image`

— Method`dirty_image(fov::Real, npix::Int, obs::EHTObservation{T,<:EHTVisibilityDatum}) where T`

Computes the dirty image of the complex visibilities assuming a field of view of `fov`

and number of pixels `npix`

using the complex visibilities found in the observation `obs`

.

The `dirty image`

is the inverse Fourier transform of the measured visibilties assuming every other visibility is zero.

`Comrade.extract_FRs`

— Method`extract_FRs`

Extracts the feed rotation Jones matrices (returned as a `JonesPair`

) from an EHT observation `obs`

.

**Warning**

eht-imaging can sometimes pre-rotate the coherency matrices. As a result the field rotation can sometimes be applied twice. To compensate for this we have added a `ehtim_fr_convention`

which will fix this.

`Comrade.extract_amp`

— Function`extract_amp(obs; kwargs...)`

Extracts the visibility amplitudes from an `obs`

. This is an internal method for dispatch. Only use this if interfacing Comrade with a new data type.

`Comrade.extract_coherency`

— Function`extract_coherency(obs; kwargs...)`

Extracts the full coherency matrix from an observation. This is an internal method for dispatch. Only use this if interfacing Comrade with a new data type.

`Comrade.extract_cphase`

— Function`extract_cphase(obs; kwargs...)`

Extracts the closure phases from an `obs`

. This is an internal method for dispatch. Only use this if interfacing Comrade with a new data type.

`Comrade.extract_lcamp`

— Function`extract_lcamp(obs; kwargs...)`

Extracts the log-closure amplitudes from an `obs`

. This is an internal method for dispatch. Only use this if interfacing Comrade with a new data type.

`Comrade.extract_table`

— Method`extract_table(obs, dataproducts::VLBIDataProducts)`

Extract an `Comrade.EHTObservation`

table of data products `dataproducts`

. To pass additional keyword for the data products you can pass them as keyword arguments to the data product type. For a list of potential data products see `subtypes(Comrade.VLBIDataProducts)`

.

**Example**

```
julia> dlcamp, dcphase = extract_table(obs, LogClosureAmplitudes(;snrcut=3.0), ClosurePhases(;snrcut=3.0, cut_trivial=true))
julia> dcoh = extract_table(obs, Coherencies())
julia> dvis = extract_table(obs, VisibilityAmplitudes())
```

`Comrade.extract_vis`

— Function`extract_vis(obs; kwargs...)`

Extracts the stokes I complex visibilities from an obs. This is an internal method for dispatch. Only use this if interfacing Comrade with a new data type.

`Comrade.getdata`

— Method`getdata(obs::EHTObservation, s::Symbol)`

Pass-through function that gets the array of `s`

from the EHTObservation. For example say you want the times of all measurement then

`getdata(obs, :time)`

`Comrade.getuv`

— Method`getuv`

Get the u, v positions of the array.

`Comrade.getuvtimefreq`

— Method```
getuvtimefreq(ac)
```

Get the u, v, time, freq of the array as a tuple.

`Comrade.instrumentmodel`

— Method`skymodel(post::Posterior, θ)`

Returns the instrument model of a posterior using the parameter values`θ`

`Comrade.instrumentmodel`

— Method`skymodel(lklhd::RadioLikelihood, θ)`

Returns the instrument model of a lklhderior using the parameter values`θ`

`Comrade.jonesD`

— Method```
jonesD(d1::AbstractVector, d2::AbstractVector, jcache::AbstractJonesCache)
jonesD(f, d1::AbstractVector, d2::AbstractVector, jcache::AbstractJonesCache)
```

Constructs the pairs Jones `D`

matrices for each pair of stations. The `d1`

are the d-termsfor the first polarization basis and `d2`

are the d-terms for the other polarization. The first argument is optional and denotes a function that is applied to every element of jones cache. For instance if `d1`

and `d2`

are the log-dterms then `f=exp`

will convert them into the dterms.

The layout for each matrix is as follows:

```
1 d1
d2 1
```

`Comrade.jonesG`

— Method```
jonesG(g1::AbstractVector, g2::AbstractVector, jcache::AbstractJonesCache)
jonesG(f, g1::AbstractVector, g2::AbstractVector, jcache::AbstractJonesCache)
```

Constructs the pairs Jones `G`

matrices for each pair of stations. The `g1`

are the gains for the first polarization basis and `g2`

are the gains for the other polarization. The first argument is optional and denotes a function that is applied to every element of jones cache. For instance if `g1`

and `g2`

are the log-gains then `f=exp`

will convert them into the gains.

The layout for each matrix is as follows:

```
g1 0
0 g2
```

`Comrade.jonesR`

— Method`jonesR(tcache::ResponseCache)`

Returns a `JonesPair`

of matrices that transform from the model coherency matrices basis to the on-sky coherency basis, this includes the feed rotation and choice of polarization feeds.

`Comrade.jonesStokes`

— Method```
jonesStokes(g1::AbstractArray, gcache::AbstractJonesCache)
jonesStokes(f, g1::AbstractArray, gcache::AbstractJonesCache)
```

Construct the Jones Pairs for the stokes I image only. That is, we only need to pass a single vector corresponding to the gain for the stokes I visibility. This is for when you only want to image Stokes I. The first argument is optional and denotes a function that is applied to every element of jones cache. For instance if `g1`

and `g2`

are the log-gains then `f=exp`

will convert them into the gains.

**Warning**

In the future this functionality may be removed when stokes I fitting is replaced with the more correct `trace(coherency)`

, i.e. RR+LL for a circular basis.

`Comrade.jonescache`

— Method```
jonescache(obs::EHTObservation, segmentation::ObsSegmentation)
jonescache(obs::EHTObservatoin, segmentation::NamedTuple)
```

Constructs a `JonesCache`

from a given observation `obs`

using the segmentation scheme `segmentation`

. If `segmentation`

is a named tuple it is assumed that each symbol in the named tuple corresponds to a segmentation for thes sites in `obs`

.

**Example**

```
# coh is a EHTObservation
julia> jonescache(coh, ScanSeg())
julia> segs = (AA = ScanSeg(), AP = TrachSeg(), AZ=FixedSegSeg())
julia> jonescache(coh, segs)
```

`Comrade.likelihood`

— Method`likelihood(d::ConditionedLikelihood, μ)`

Returns the likelihood of the model, with parameters μ. That is, we return the distribution of the data given the model parameters μ. This is an actual probability distribution.

`Comrade.prior_sample`

— Method`prior_sample([rng::AbstractRandom], post::Posterior, args...)`

Samples the prior distribution from the posterior. The `args...`

are forwarded to the `Base.rand`

method.

`Comrade.prior_sample`

— Method`prior_sample([rng::AbstractRandom], post::Posterior)`

Returns a single sample from the prior distribution.

`Comrade.samplertype`

— Method`samplertype(::Type)`

Sampler type specifies whether to use a unit hypercube or unconstrained transformation.

`Comrade.scantable`

— Method`scantable(obs::EHTObservation)`

Reorganizes the observation into a table of scans, where scan are defined by unique timestamps. To access the data you can use scalar indexing

**Example**

```
st = scantable(obs)
# Grab the first scan
scan1 = st[1]
# Acess the detections in the scan
scan1[1]
# grab e.g. the baselines
scan1[:baseline]
```

`Comrade.simulate_observation`

— Method`simulate_observation([rng::Random.AbstractRNG], post::Posterior, θ)`

Create a simulated observation using the posterior and its data `post`

using the parameter values `θ`

. In Bayesian terminology this is a draw from the posterior predictive distribution.

`Comrade.skymodel`

— Method`skymodel(post::Posterior, θ)`

Returns the sky model or image of a posterior using the parameter values`θ`

`Comrade.skymodel`

— Method`skymodel(post::RadioLikelihood, θ)`

Returns the sky model or image of a posterior using the parameter values`θ`

`Comrade.station_tuple`

— Method```
station_tuple(stations, default; reference=nothing kwargs...)
station_tuple(obs::EHTObservation, default; reference=nothing, kwargs...)
```

Convienence function that will construct a `NamedTuple`

of objects whose names are the `stations`

in the observation `obs`

or explicitly in the argument `stations`

. The `NamedTuple`

will be filled with `default`

if no kwargs are defined otherwise each kwarg (key, value) pair denotes a station and value pair.

Optionally the user can specify a `reference`

station that will be dropped from the tuple. This is useful for selecting a reference station for gain phases

**Examples**

```
julia> stations = (:AA, :AP, :LM, :PV)
julia> station_tuple(stations, ScanSeg())
(AA = ScanSeg(), AP = ScanSeg(), LM = ScanSeg(), PV = ScanSeg())
julia> station_tuple(stations, ScanSeg(); AA = FixedSeg(1.0))
(AA = FixedSeg(1.0), AP = ScanSeg(), LM = ScanSeg(), PV = ScanSeg())
julia> station_tuple(stations, ScanSeg(); AA = FixedSeg(1.0), PV = TrackSeg())
(AA = FixedSeg(1.0), AP = ScanSeg(), LM = ScanSeg(), PV = TrackSeg())
julia> station_tuple(stations, Normal(0.0, 0.1); reference=:AA, LM = Normal(0.0, 1.0))
(AP = Normal(0.0, 0.1), LM = Normal(0.0, 1.0), PV = Normal(0.0, 0.1))
```

`Comrade.stations`

— Method`stations(g::CalTable)`

Return the stations in the calibration table

`Comrade.stations`

— Method`stations(d::EHTObservation)`

Get all the stations in a observation. The result is a vector of symbols.

`Comrade.uvpositions`

— Method`uvpositions(datum::AbstractVisibilityDatum)`

Get the uvp positions of an inferometric datum.

`Comrade.vlbimodel`

— Method`vlbimodel(post::Posterior, θ)`

Returns the instrument model and sky model as a `VLBIModel`

of a posterior using the parameter values `θ`

`Comrade.vlbimodel`

— Method`vlbimodel(post::Posterior, θ)`

Returns the instrument model and sky model as a `VLBIModel`

of a posterior using the parameter values `θ`

`ComradeBase.amplitude`

— Method`amplitude(d::EHTVisibilityDatum)`

Get the amplitude of a visibility datum

`ComradeBase.bispectrum`

— Method`bispectrum(d1::T, d2::T, d3::T) where {T<:EHTVisibilityDatum}`

Finds the bispectrum of three visibilities. We will assume these form closed triangles, i.e. the phase of the bispectrum is a closure phase.

`ComradeBase.closure_phase`

— Method```
closure_phase(D1::EHTVisibilityDatum,
D2::EHTVisibilityDatum,
D3::EHTVisibilityDatum
)
```

Computes the closure phase of the three visibility datums.

**Notes**

We currently use the high SNR Gaussian error approximation for the closure phase. In the future we may use the moment matching from Monte Carlo sampling.

`ComradeBase.closure_phases`

— Method`closure_phases(vis::AbstractArray, ac::ArrayConfiguration)`

Compute the closure phases for a set of visibilities and an array configuration

**Notes**

This uses a closure design matrix for the computation.

`ComradeBase.closure_phases`

— Method`closure_phases(m::AbstractModel, ac::ClosureConfig)`

Computes the closure phases of the model `m`

using the array configuration `ac`

.

**Notes**

This is faster than the `closure_phases(m, u1, v1, ...)`

method since it only computes as many visibilities as required thanks to the closure design matrix formalism from Blackburn et al.^{[1]}

`ComradeBase.logclosure_amplitudes`

— Method`logclosure_amplitudes(vis::AbstractArray, ac::ArrayConfiguration)`

Compute the log-closure amplitudes for a set of visibilities and an array configuration

**Notes**

This uses a closure design matrix for the computation.

`ComradeBase.logclosure_amplitudes`

— Method`logclosure_amplitudes(m::AbstractModel, ac::ClosureConfig)`

Computes the log closure amplitudes of the model `m`

using the array configuration `ac`

.

**Notes**

This is faster than the `logclosure_amplitudes(m, u1, v1, ...)`

method since it only computes as many visibilities as required thanks to the closure design matrix formalism from Blackburn et al.^{[1]}

`ComradeBase.visibility`

— Method`visibility(d::EHTVisibilityDatum)`

Return the complex visibility of the visibility datum

`HypercubeTransform.ascube`

— Method`ascube(post::Posterior)`

Construct a flattened version of the posterior where the parameters are transformed to live in (0, 1), i.e. the unit hypercube.

This returns a `TransformedPosterior`

that obeys the `DensityInterface`

and can be evaluated in the usual manner, i.e. `logdensityof`

. Note that the transformed posterior automatically includes the terms log-jacobian terms of the transformation.

**Example**

```
julia> tpost = ascube(post)
julia> x0 = prior_sample(tpost)
julia> logdensityof(tpost, x0)
```

**Notes**

This is the transform that should be used if using typical NestedSampling methods, i.e. `ComradeNested`

. For the transformation to unconstrained space see `asflat`

`HypercubeTransform.asflat`

— Method`asflat(post::Posterior)`

Construct a flattened version of the posterior where the parameters are transformed to live in (-∞, ∞).

This returns a `TransformedPosterior`

that obeys the `DensityInterface`

and can be evaluated in the usual manner, i.e. `logdensityof`

. Note that the transformed posterior automatically includes the terms log-jacobian terms of the transformation.

**Example**

```
julia> tpost = ascube(post)
julia> x0 = prior_sample(tpost)
julia> logdensityof(tpost, x0)
```

**Notes**

This is the transform that should be used if using typical MCMC methods, i.e. `ComradeAHMC`

. For the transformation to the unit hypercube see `ascube`

`ParameterHandling.flatten`

— Method`flatten(post::Posterior)`

Construct a flattened version of the posterior but **do not** transform to any space, i.e. use the support specified by the prior.

This returns a `TransformedPosterior`

that obeys the `DensityInterface`

and can be evaluated in the usual manner, i.e. `logdensityof`

. Note that the transformed posterior automatically includes the terms log-jacobian terms of the transformation.

**Example**

```
julia> tpost = flatten(post)
julia> x0 = prior_sample(tpost)
julia> logdensityof(tpost, x0)
```

**Notes**

This is the transform that should be used if using typical MCMC methods, i.e. `ComradeAHMC`

. For the transformation to the unit hypercube see `ascube`

`StatsBase.sample`

— Method`sample(post::Posterior, sampler::S, args...; initial_params=nothing, kwargs...)`

Sample a posterior `post`

using the `sampler`

. You can optionally pass the starting location of the sampler using `initial_params`

, otherwise a random draw from the prior will be used.

`TransformVariables.inverse`

— Method`TransformVariables.transform`

— Method