virgil.plotting
Plotting functions for virgil models, data and grid results.
plot_grid_mapdraws a grid result andplot_contrast_curvea radial contrast curve.plot_null_distribution,plot_rocandplot_completenessdraw aDetectionMC; see detection limits.plot_field_drawsshows draws from a Gaussian-process image prior or posterior, with cuts through them.
units="flux" | "contrast" | "delta_mag" shows contrasts as companion/primary
flux, primary/companion, or magnitudes. Sky images have East (positive dra)
to the left and North up. Importing this module leaves matplotlib's global
settings alone; set_style opts in to the virgil look.
set_style()
Apply the virgil matplotlib style globally.
The plotting functions in this module already use this style for the figures they create, without touching global settings. Call this to use it for your own figures too.
plot_grid_map(values, grid, kind='loglike', *, units='flux', sigma=None, percentile=None, truth=None, best=None, star=True, flux_param=None, ax=None, cmap=None, log=None, label=None, title=None, figsize=(7, 6))
Plot a grid result as a sky map (or a 1D profile).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
array - like
|
Grid result with one axis per coordinate key of |
required |
grid
|
dict[str, array - like]
|
The grid axes used to compute |
required |
kind
|
(loglike, flux, sigma, snr, limit)
|
What |
"loglike"
|
units
|
(flux, contrast, delta_mag)
|
For |
"flux"
|
sigma
|
float
|
Confidence of a |
None
|
percentile
|
float
|
Confidence of a |
None
|
truth
|
dict or sequence
|
Coordinates to mark with a cross (truth) or circle (best fit). |
None
|
best
|
dict or sequence
|
Coordinates to mark with a cross (truth) or circle (best fit). |
None
|
star
|
bool
|
Mark the primary at the origin of sky maps (default True). |
True
|
flux_param
|
str
|
Key of the flux axis, if it is not the one key ending in |
None
|
ax
|
optional
|
Axes to draw on (default: a new figure of this size). |
None
|
figsize
|
optional
|
Axes to draw on (default: a new figure of this size). |
None
|
cmap
|
optional
|
Override the defaults for |
None
|
log
|
optional
|
Override the defaults for |
None
|
label
|
optional
|
Override the defaults for |
None
|
title
|
optional
|
Override the defaults for |
None
|
Returns:
| Type | Description |
|---|---|
tuple
|
|
Examples:
>>> plot_grid_map(limits, grid, kind="limit", units="delta_mag", sigma=5)
plot_contrast_curve(values, grid=None, *, units='delta_mag', sigma=None, percentile=None, label=None, band=True, truth=None, center=(0.0, 0.0), r_max=None, bins=20, ax=None, color=None, figsize=(8, 4))
Plot a radial contrast curve: the median limit against separation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
array - like or dict
|
A limit map (companion/primary flux ratios, one axis per coordinate key
of |
required |
grid
|
dict[str, array - like]
|
The grid axes of a limit map; must contain |
None
|
units
|
(delta_mag, contrast, flux)
|
Magnitude differences (default), contrasts or flux ratios. Deeper limits are always drawn lower down. |
"delta_mag"
|
sigma
|
optional
|
Legend label; by default built from |
None
|
percentile
|
optional
|
Legend label; by default built from |
None
|
label
|
optional
|
Legend label; by default built from |
None
|
band
|
bool
|
Shade the 16-84 percentile range of each annulus (default True). |
True
|
truth
|
tuple
|
|
None
|
center
|
optional
|
Annuli, passed to |
(0.0, 0.0)
|
r_max
|
optional
|
Annuli, passed to |
(0.0, 0.0)
|
bins
|
optional
|
Annuli, passed to |
(0.0, 0.0)
|
ax
|
optional
|
Axes to draw on, e.g. to overlay several curves (default: a new figure of this size). |
None
|
figsize
|
optional
|
Axes to draw on, e.g. to overlay several curves (default: a new figure of this size). |
None
|
color
|
optional
|
Line and band colour. |
None
|
Returns:
| Type | Description |
|---|---|
tuple
|
|
plot_null_distribution(mc, stat='delta_chi2', *, observed=None, fap=None, reference=True, ax=None, title=None, figsize=(7, 4.5))
Plot how often companion-free searches exceed each threshold.
The empirical exceedance function of the statistic over the null simulations, on a log scale. See detection limits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mc
|
DetectionMC
|
Simulated searches, from
|
required |
stat
|
str
|
|
'delta_chi2'
|
observed
|
float
|
The statistic of the real data: a vertical line, with its false-alarm probability and 95% interval. |
None
|
fap
|
float
|
A false-alarm probability to draw as a horizontal line, with the threshold that reaches it. |
None
|
reference
|
bool
|
Draw the single-position reference curve (default True; none for
|
True
|
title
|
optional
|
Title (default: statistic and number of draws), axes, and size of a new figure. |
None
|
ax
|
optional
|
Title (default: statistic and number of draws), axes, and size of a new figure. |
None
|
figsize
|
optional
|
Title (default: statistic and number of draws), axes, and size of a new figure. |
None
|
Returns:
| Type | Description |
|---|---|
tuple
|
|
Examples:
>>> plot_null_distribution(mc, "delta_chi2", observed=21.3)
plot_roc(mc, stat, *, flux=None, sep_bin=None, ax=None, log_fpr=True, mark_wilks=(3.0, 5.0), title=None, figsize=(7, 4.5))
Plot ROC curves: completeness against false-alarm probability.
A useless statistic lies on TPR = FPR; see detection limits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mc
|
DetectionMC
|
Simulated searches, from
|
required |
stat
|
str or sequence of str
|
|
required |
flux
|
(float, (float, float) or list)
|
Only injections of this flux or in this range, as for
|
None
|
sep_bin
|
(float, float) or list of them
|
Only injections with separation in |
None
|
log_fpr
|
bool
|
Logarithmic false-positive axis. |
True
|
mark_wilks
|
sequence of float
|
Local significances at which to mark the single-position false-alarm
probability and its threshold on each curve (the gap is the
look-elsewhere effect); |
(3.0, 5.0)
|
title
|
optional
|
Title (default: what the curves share), axes, and size of a new figure. |
None
|
ax
|
optional
|
Title (default: what the curves share), axes, and size of a new figure. |
None
|
figsize
|
optional
|
Title (default: what the curves share), axes, and size of a new figure. |
None
|
Returns:
| Type | Description |
|---|---|
tuple
|
|
Examples:
>>> plot_roc(mc, ["delta_chi2", "max_snr"], flux=4e-3)
plot_completeness(mc, stat, fap, *, units='delta_mag', contours=(0.5, 0.9), sep_bins=None, flux_bins=None, ax=None, cmap='viridis', colorbar=True, title=None, figsize=(8, 4.5))
Plot a completeness map against separation and companion brightness.
Each cell is the fraction of injections detected at false-alarm probability
fap (DetectionMC.completeness);
lines mark contours. See
detection limits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mc
|
DetectionMC
|
Simulated searches with injections, from
|
required |
stat
|
str
|
The detection statistic, e.g. |
required |
fap
|
float
|
False-alarm probability of the threshold, e.g. 1.35e-3 (3σ). |
required |
units
|
(delta_mag, contrast, flux)
|
The y-axis, as in
|
"delta_mag"
|
contours
|
sequence of float
|
Completeness levels to draw as lines (default 50% and 90%). |
(0.5, 0.9)
|
sep_bins
|
array - like
|
Bin edges (mas, and flux); by default every injected value is a cell. |
None
|
flux_bins
|
array - like
|
Bin edges (mas, and flux); by default every injected value is a cell. |
None
|
cmap
|
str or Colormap
|
Colour map of the completeness, from 0 to 1. |
'viridis'
|
colorbar
|
bool
|
Add a colour bar. |
True
|
title
|
optional
|
Title (default: statistic and FAP), axes, and size of a new figure. |
None
|
ax
|
optional
|
Title (default: statistic and FAP), axes, and size of a new figure. |
None
|
figsize
|
optional
|
Title (default: statistic and FAP), axes, and size of a new figure. |
None
|
Returns:
| Type | Description |
|---|---|
tuple
|
|
Examples:
>>> plot_completeness(mc, "delta_chi2", 1.35e-3)
plot_orbit_ensemble(orbits, positions=None, truth=None, *, n_points=400, n_sigma=1.0, color='#3c6e9f', alpha=None, truth_color='#d1495b', cmap='viridis', ax=None, figsize=(6.5, 6))
Draw orbits on the sky, e.g. draws from a posterior, with the data.
East is to the left and North up, the primary at the origin. Each orbit is drawn over one period; measured positions are coloured by time, with error ellipses.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
orbits
|
KeplerOrbit
|
One orbit, or many as one |
required |
positions
|
PositionData
|
Measured positions to overlay, with |
None
|
truth
|
KeplerOrbit
|
A reference orbit, drawn as a thicker contrasting line. |
None
|
n_points
|
int
|
Points along each orbit. |
400
|
n_sigma
|
float
|
Size of the error ellipses, in standard deviations. |
1.0
|
color
|
optional
|
Colours of the ensemble and of the reference orbit. |
'#3c6e9f'
|
truth_color
|
optional
|
Colours of the ensemble and of the reference orbit. |
'#3c6e9f'
|
alpha
|
float
|
Opacity of each line; by default it falls with the number of orbits. |
None
|
cmap
|
str
|
Colour map for the epochs' times. |
'viridis'
|
ax
|
Axes
|
Axes to draw on. |
None
|
figsize
|
tuple
|
Size of a new figure. |
(6.5, 6)
|
Returns:
| Type | Description |
|---|---|
tuple
|
|
plot_field_draws(field=None, pixel_scale_mas=None, key=None, *, latents=None, images=None, n=100, cuts=None, axes_pa=((0.0, 'vertical'), (90.0, 'horizontal')), mmax=3, npix=64, truth=None, snr=False, beam=None, snr_scale='linear', snr_vmax=None, n_cuts=100, title=None, figsize=(9, 6))
Draws from a Gaussian-process image prior or posterior, with cuts.
Provisional
May change in any 0.4.x release without a deprecation cycle.
Three draws (abc) above cuts through many (ddd), one in bold.
Posterior draws are unit-sum on a shared colour scale; prior draws have
unit peak.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
(GaussianField, MultipoleField or MultipoleDisk)
|
Alone, prior draws from |
None
|
pixel_scale_mas
|
float
|
Pixel scale, mas. |
None
|
key
|
Array
|
PRNG key (prior). |
None
|
latents
|
(array - like, shape(n, *shape) or dict)
|
Posterior latents, e.g. from
|
None
|
images
|
(array - like, shape(n, nrow, ncol))
|
Rendered images instead of a field (not for |
None
|
n
|
int
|
Prior draws (default 100). |
100
|
cuts
|
(principal, axes, multipole)
|
Panel d. |
"principal"
|
axes_pa
|
sequence of (float, str)
|
|
((0.0, 'vertical'), (90.0, 'horizontal'))
|
npix
|
int
|
Image side in pixels for a disk (default 64). |
64
|
truth
|
(array - like, shape(nrow, ncol))
|
True image (posterior only): dashed in the cuts; the reference peak. |
None
|
snr
|
bool
|
Posterior only. Panel c: mean over standard deviation of each pixel (grey where no spread); per-pixel S/N, not a detection significance. |
False
|
beam
|
Beam
|
Drawn on the map panels, as in |
None
|
snr_scale
|
optional
|
S/N scale ( |
'linear'
|
snr_vmax
|
optional
|
S/N scale ( |
'linear'
|
n_cuts
|
optional
|
S/N scale ( |
'linear'
|
title
|
optional
|
S/N scale ( |
'linear'
|
figsize
|
optional
|
S/N scale ( |
'linear'
|
Returns:
| Type | Description |
|---|---|
tuple
|
|
plot_model(model, fov_mas, npix=256, ax=None, title=None, saturate=None, cmap='magma', beam=None, convolve=False)
Show a source model's rendered image with sky axes (East left, North up).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
SourceModel
|
Model to render. |
required |
fov_mas
|
float
|
Width of the field of view in milliarcseconds. |
required |
npix
|
int
|
Number of pixels on a side. |
256
|
ax
|
Axes
|
Axes to draw on; a new figure is made if omitted. |
None
|
title
|
str
|
Axes title. |
None
|
saturate
|
float
|
Quantile (e.g. |
None
|
cmap
|
str
|
Matplotlib colour map. |
'magma'
|
beam
|
Beam
|
The data's resolution, from |
None
|
convolve
|
bool
|
Show the image convolved with |
False
|
Returns:
| Type | Description |
|---|---|
Axes
|
The axes drawn on. |
plot_residual_map(residual, fov_mas, sigma=None, ax=None, title=None, cmap='RdBu_r')
Show a signed residual image on a symmetric, diverging colour scale.
Use it next to an image and its reconstruction (or data and a model)
to see where they agree. Without sigma the map is the plain signed
residual, as for a maximum a posteriori image with no uncertainty.
With sigma it is the z-score residual / sigma. The colour scale
is centred on zero in either case, with East to the left and North up.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
residual
|
(array - like, shape(npix, npix))
|
E.g. |
required |
fov_mas
|
float
|
Width of the field of view in milliarcseconds. |
required |
sigma
|
array - like or float
|
Uncertainty of the residual, per pixel or overall; if given, the map shows z-scores. |
None
|
ax
|
Axes
|
Axes to draw on; a new figure is made if omitted. |
None
|
title
|
str
|
Axes title. |
None
|
cmap
|
str
|
A diverging Matplotlib colour map. |
'RdBu_r'
|
Returns:
| Type | Description |
|---|---|
Axes
|
The axes drawn on (with a colour bar). |
plot_uv_coverage(data, ax=None, cmap='viridis', figsize=(6, 5.5))
Plot the uv coverage of data, coloured by wavelength.
Each sample is drawn at (u, v) and at its mirror (-u, -v)
(the visibility there is the conjugate), in units of millions of
wavelengths, with East (positive u) to the left as on the sky.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
OIData
|
Data to show. Flagged samples are drawn too: the coverage is that of the observation. |
required |
ax
|
Axes
|
Axes to draw on; a new figure is made if omitted. |
None
|
cmap
|
str
|
Colour map of the wavelength, used when the data have more than one wavelength (one colour otherwise). |
'viridis'
|
figsize
|
tuple
|
Size of a new figure. |
(6, 5.5)
|
Returns:
| Type | Description |
|---|---|
tuple
|
|
plot_oidata_overview(oidata, figsize=(15, 4.5))
Plot uv coverage, visibilities and phases of an OIData object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
oidata
|
OIData
|
Data to show. Flagged samples are left out. Projected observables
( |
required |
figsize
|
tuple
|
Figure size. |
(15, 4.5)
|
Returns:
| Type | Description |
|---|---|
tuple
|
|
plot_data_model_correlation(oidata, predictions_by_label, colors=None, figsize=(10, 5), phase_title='Phase correlation', square_axes=True, vis_label=None)
Plot data-vs-model correlation panels for visibility and phase observables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
oidata
|
OIData
|
Observed data container. |
required |
predictions_by_label
|
dict
|
Mapping |
required |
colors
|
list
|
Matplotlib color list. If omitted, cycle |
None
|
figsize
|
tuple
|
Figure size. |
(10, 5)
|
phase_title
|
str
|
Title for the phase panel. |
'Phase correlation'
|
square_axes
|
bool
|
If |
True
|
vis_label
|
str
|
Axis label for the visibility observable. By default it follows
|
None
|
Returns:
| Type | Description |
|---|---|
tuple
|
|
plot_chainconsumer_diagnostics(chains_by_label, columns, truth=None, colors=None, walk_columns=None)
Plot comparison diagnostics using ChainConsumer for multiple posterior chains.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chains_by_label
|
dict
|
Mapping |
required |
columns
|
list[str]
|
Columns used for contour/corner plotting. |
required |
truth
|
dict
|
Truth mapping for columns displayed. When omitted, no truth overlay is drawn. |
None
|
colors
|
list[str]
|
Per-chain colors. |
None
|
walk_columns
|
list[str]
|
Columns to show in walk plots. Defaults to |
None
|
Returns:
| Type | Description |
|---|---|
tuple
|
|
diagnostics_table_from_samples(samples, dra_key='dra', ddec_key='ddec', flux_key='flux', log10_flux=False)
Build a standardized diagnostics table from posterior sample arrays.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
samples
|
dict - like
|
Mapping of sample arrays. |
required |
dra_key
|
str
|
Key for right-ascension offsets. |
'dra'
|
ddec_key
|
str
|
Key for declination offsets. |
'ddec'
|
flux_key
|
str
|
Key for flux or log10-flux samples. |
'flux'
|
log10_flux
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Table with |
truth_cartesian_and_polar(truth)
Return truth mappings for shared ChainConsumer Cartesian and polar interfaces.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
truth
|
dict
|
Mapping with |
required |
Returns:
| Type | Description |
|---|---|
tuple[dict, dict]
|
Cartesian and polar truth dictionaries. |