Plotting#
- mpol.plot.get_image_cmap_norm(image, stretch='power', gamma=1.0, asinh_a=0.02, symmetric=False)[source]#
Get a colormap normalization to apply to an image.
- imagearray
2D image array.
- stretchstring, default = ‘power’
Transformation to apply to the colormap. ‘power’ is a power law stretch; ‘asinh’ is an arcsinh stretch.
- gammafloat, default = 1.0
Index of power law normalization (see matplotlib.colors.PowerNorm). gamma=1.0 yields a linear colormap.
- asinh_afloat, default = 0.02
Scale parameter for an asinh stretch.
- symmetricbool, default=False
Whether the colormap is symmetric about 0
- mpol.plot.plot_image(image, extent, cmap='inferno', norm=None, ax=None, clab='I [Jy arcsec$^{-2}$]', xlab='$\\Delta \\alpha \\cos \\delta$ [${}^{\\prime\\prime}$]', ylab='$\\Delta \\delta$ [${}^{\\prime\\prime}$]')[source]#
Wrapper for plt.imshow, with colorbar and colormap normalization.
- Parameters:
image (array) – 2D image array.
extent (list, len=4) – x- and y-extents of image: [x-min, x-max, y-min, y-max] (see plt.imshow)
cmap (str, default="inferno) – Matplotlib colormap.
norm (Matplotlib colormap normalization, default=None) – Image colormap norm. If None, a linear normalization is generated with mpol.plot.get_image_cmap_norm
ax (Matplotlib axis instance, default=None) – Axis on which to plot the image. If None, a new figure is created.
clab (str, default=r"Jy arcsec$^{-2}$") – Colorbar axis label
xlab (str, default="RA offset [arcsec]") – Image x-axis label.
ylab (str, default="Dec offset [arcsec]") – Image y-axis label.
- Returns:
im (Matplotlib imshow instance) – The plotted image.
cbar (Matplotlib colorbar instance) – Colorbar for the image.
- mpol.plot.vis_histogram_fig(dataset, bin_quantity='count', bin_label=None, q_edges=None, phi_edges=None, q_edges1d=None, show_datapoints=False, save_prefix=None)[source]#
Generate a figure with 1d and 2d histograms of (u,v)-plane coverage. Histograms can show different data; see bin_quantity parameter.
- Parameters:
dataset (mpol.datasets.GriddedDataset object)
bin_quantity (str or numpy.ndarray, default='count') –
- Which quantity to bin:
’count’ bins (u,v) points by their count
’weight’ bins points by the data weight (inherited from dataset)
’vis_real’ bins points by data Re(V)
’vis_imag’ bins points by data Im(V)
A user-supplied numpy.ndarray to be used as ‘weights’ in np.histogram
bin_label (str, default=None) – Label for 1d histogram y-axis and 2d histogram colorbar.
q_edges (array, optional (default=None), unit=:math:[klambda]) – Radial bin edges for the 1d and 2d histogram. If None, defaults to 12 log-linearly radial bins over [0, 1.1 * maximum baseline in dataset].
phi_edges (array, optional (default=None), unit=[rad]) – Azimuthal bin edges for the 2d histogram. If None, defaults to 16 bins over [-pi, pi]
q_edges1d (array, optional (default=None), unit=:math:[klambda]) – Radial bin edges for a second 1d histogram. If None, defaults to 50 bins equispaced over [0, 1.1 * maximum baseline in dataset].
show_datapoints (bool, default = False) – Whether to overplot the raw visibilities in dataset on the 2d histogram.
save_prefix (string, default = None) – Prefix for saved figure name. If None, the figure won’t be saved
- Returns:
fig (Matplotlib .Figure instance) – The generated figure
axes (Matplotlib ~.axes.Axes class) – Axes of the generated figure
Notes
No assumption or correction is made concerning whether the (u,v) distances are projected or deprojected.
- mpol.plot.split_diagnostics_fig(splitter, channel=0, save_prefix=None)[source]#
Generate a figure showing (u,v) coverage in train and test sets split from a parent dataset.
- Parameters:
splitter (mpol.crossval.RandomCellSplitGridded object) – Iterator that returns a (train, test) pair of GriddedDataset for each iteration.
channel (int, default=0) – Channel (of the datasets in splitter) to use to generate figure
save_prefix (string, default = None) – Prefix for saved figure name. If None, the figure won’t be saved
- Returns:
fig (Matplotlib .Figure instance) – The generated figure
axes (Matplotlib ~.axes.Axes class) – Axes of the generated figure
Notes
No assumption or correction is made concerning whether the (u,v) distances are projected or deprojected.
- mpol.plot.train_diagnostics_fig(model, losses=None, learn_rates=None, fluxes=None, old_model_image=None, old_model_epoch=None, kfold=None, epoch=None, channel=0, save_prefix=None)[source]#
Figure for model diagnostics at a given model state during an optimization loop.
- Plots:
model image
flux of model image
gradient image
difference image between old_model_image and current model image
loss function
learning rate
- Parameters:
model (torch.nn.Module object) – A neural network module; instance of the mpol.precomposed.GriddedNet class.
losses (list) – Loss value at each epoch in the training loop
learn_rates (list) – Learning rate at each epoch in the training loop
fluxes (list) – Total flux in model image at each epoch in the training loop
old_model_image (2D image array, default=None) – Model image of a previous epoch for comparison to current image
old_model_epoch (int) – Epoch of old_model_image
kfold (int, default=None) – Current cross-validation k-fold
epoch (int, default=None) – Current training epoch
channel (int, default=0) – Channel (of the datasets in splitter) to use to generate figure
save_prefix (str, default = None) – Prefix for saved figure name. If None, the figure won’t be saved
- Returns:
fig (Matplotlib .Figure instance) – The generated figure
axes (Matplotlib ~.axes.Axes class) – Axes of the generated figure
- mpol.plot.crossval_diagnostics_fig(cv, title='', save_prefix=None)[source]#
Figure for model diagnostics of a cross-validation run.
- Plots:
loss evolution for each k-fold
cross-validation score per k-fold
- Parameters:
cv (mpol.crossval.CrossValidate object) – Instance of the CrossValidate class produced by a cross-validation loop
title (str, default="") – Figure super-title
save_prefix (string, default = None) – Prefix for saved figure name. If None, the figure won’t be saved
- Returns:
fig (Matplotlib .Figure instance) – The generated figure
axes (Matplotlib ~.axes.Axes class) – Axes of the generated figure
- mpol.plot.vis_1d_fig(model, uu, vv, V, weights, geom=None, rescale_flux=False, bin_width=20000000.0, q_logx=True, title='', channel=0, save_prefix=None)[source]#
- Figure for comparison of 1D projected MPoL model visibilities and observed
visibilities.
- Plots:
Re(V): observed and MPoL model (projected unless geom is supplied)
Residual Re(V): observed - MPoL model (projected unless geom is supplied)
Im(V): observed and MPoL model (projected unless geom is supplied)
Residual Im(V): observed - MPoL model (projected unless geom is supplied)
- Parameters:
model (torch.nn.Module object) – A neural network; instance of the mpol.precomposed.GriddedNet class.
uu (array, unit=[\(\lambda\)]) – Data u- and v-coordinates
vv (array, unit=[\(\lambda\)]) – Data u- and v-coordinates
V (array, unit=[Jy]) – Data visibility amplitudes
weights (array, unit=[Jy^-2]) – Data weights
geom (dict) –
- Dictionary of source geometry. If passed in, visibilities will be
- deprojected prior to plotting. Keys:
- ”incl”float, unit=[deg]
Inclination
- ”Omega”float, unit=[deg]
Position angle of the ascending node
- ”omega”float, unit=[deg]
Argument of periastron
- ”dRA”float, unit=[arcsec]
Phase center offset in right ascension. Positive is west of north.
- ”dDec”float, unit=[arcsec]
Phase center offset in declination.
rescale_flux (bool) –
- If True, the visibility amplitudes are rescaled to account
for the difference between the inclined (observed) brightness and the assumed face-on brightness, assuming the emission is optically thick. The source’s integrated (2D) flux is assumed to be: \(F = \cos(i) \int_r^{r=R}{I(r) 2 \pi r dr}\). No rescaling would be appropriate in the optically thin limit.
bin_width (float, default=20e3) – Bin size [\(\lambda\)] for baselines
q_logx (bool, default=True) – Whether to plot visibilities in log-baseline
title (str, default="") – Figure super-title
channel (int, default=0) – Channel of the model to use to generate figure
save_prefix (string, default = None) – Prefix for saved figure name. If None, the figure won’t be saved
- Returns:
fig (Matplotlib .Figure instance) – The generated figure
axes (Matplotlib ~.axes.Axes class) – Axes of the generated figure
Notes
This routine requires the frank package
- mpol.plot.radial_fig(model, geom, u=None, v=None, V=None, weights=None, dist=None, rescale_flux=False, bin_width=20000.0, q_logx=True, title='', channel=0, save_prefix=None)[source]#
Figure for analysis of 1D (radial) brightness profile of MPoL model image, using a user-supplied geometry.
- Plots:
MPoL model image
1D (radial) brightness profile extracted from MPoL image (supply dist to show second x-axis in [AU])
Deprojectd Re(V): binned MPoL model and observations (if u, v, V, weights supplied)
Deprojected Im(V): binned MPoL model and observations (if u, v, V, weights supplied)
- Parameters:
model (torch.nn.Module object) – A neural network; instance of the mpol.precomposed.GriddedNet class.
geom (dict) –
- Dictionary of source geometry. Used to deproject image and visibilities.
- Keys:
- ”incl”float, unit=[deg]
Inclination
- ”Omega”float, unit=[deg]
Position angle of the ascending node
- ”omega”float, unit=[deg]
Argument of periastron
- ”dRA”float, unit=[arcsec]
Phase center offset in right ascension. Positive is west of north.
- ”dDec”float, unit=[arcsec]
Phase center offset in declination.
u (array, optional, unit=[\(\lambda\)], default=None) – Data u- and v-coordinates
v (array, optional, unit=[\(\lambda\)], default=None) – Data u- and v-coordinates
V (array, optional, unit=[Jy], default=None) – Data visibility amplitudes
weights (array, optional, unit=[Jy^-2], default=None) – Data weights
dist (float, optional, unit = [AU], default = None) – Distance to source, used to show second x-axis for I(r) in [AU]
rescale_flux (bool) – If True, the visibility amplitudes are rescaled to account for the difference between the inclined (observed) brightness and the assumed face-on brightness, assuming the emission is optically thick. The source’s integrated (2D) flux is assumed to be: \(F = \cos(i) \int_r^{r=R}{I(r) 2 \pi r dr}\). No rescaling would be appropriate in the optically thin limit.
bin_width (float, default=20e3) – Bin size [klambda] in which to bin observed visibility points
q_logx (bool, default=True) – Whether to plot visibilities in log-baseline
title (str, default="") – Figure super-title
channel (int, default=0) – Channel of the model to use to generate figure
save_prefix (string, default = None) – Prefix for saved figure name. If None, the figure won’t be saved
- Returns:
fig (Matplotlib .Figure instance) – The generated figure
axes (Matplotlib ~.axes.Axes class) – Axes of the generated figure
Notes
This routine requires the frank package