Simple plotting functions

The hera_pspec.plot module contains functions for making simple plots of delay power spectra.

The following example plots the power spectra from a UVPSpec object, averaged over baseline-pairs and times.

# Load or generate a UVPSpec object containing delay power spectra
uvp = ...

# Set which baseline-pairs should be included in the plot.
# uvp.get_blpairs() returns nested tuples like ((ant1, ant2), (ant3, ant4)).
blpairs = uvp.get_blpairs()

# Plot the delay spectrum, averaged over all blpairs and times
# (for the spectral-window index 0, and auto-polarization 'xx')
fig = hp.plot.delay_spectrum(uvp, [blpairs], 0, 'xx',
                             average_blpairs=True, average_times=True,
                             delay=False)

# Setting delay=False plots the power spectrum in cosmological units
# Use times=uvp.time_avg_array[...] to select specific integrations.
# By default, static metadata is written to the title and only the
# varying metadata is written to the legend. Pass title_legend=False
# to disable the automatic title/legend text entirely.

For a more extensive worked example, see this example Jupyter notebook.

The only plotting function currently available in the hera_pspec.plot module is delay_spectrum().

hera_pspec.plot.delay_spectrum(uvp, blpairs, spw, pol, average_blpairs=False, average_times=False, fold=False, plot_noise=False, delay=True, deltasq=False, legend=False, title_legend=True, ax=None, component='real', lines=True, markers=False, error=None, times=None, logscale=True, force_plot=False, label_type='auto', plot_stats=None, **kwargs)[source]

Plot a 1D delay spectrum (or spectra) for a group of baselines.

Parameters:
  • uvp (UVPspec) – UVPSpec object, containing delay spectra for a set of baseline-pairs, times, polarizations, and spectral windows.

  • blpairs (sequence of baseline-pair identifiers) – Sequence of blpair integers, nested baseline-pair tuples like ((ant1, ant2), (ant3, ant4)), or lists containing either form. A list element is treated as one plotted/averaged group, so use [blpair1, blpair2] to plot two blpairs separately and [[blpair1, blpair2]] to average them together when average_blpairs=True.

  • spw (int) – Spectral-window index to plot.

  • pol (tuple or str) – Polarization pair to plot. A string is interpreted as an auto-polarization, e.g. "xx" becomes ("xx", "xx").

  • average_blpairs (bool, optional) – If True, average over the baseline pairs within each group.

  • average_times (bool, optional) – If True, average spectra over the time axis. Default: False.

  • fold (bool, optional) – Whether to fold the power spectrum in \(|k_\parallel|\). Default: False.

  • plot_noise (bool, optional) – Whether to plot noise power spectrum curves or not. Default: False.

  • delay (bool, optional) – Whether to plot the power spectrum in delay units (ns) or cosmological units (h/Mpc). Default: True.

  • deltasq (bool, optional) – If True, plot dimensionless power spectra, Delta^2. This is ignored if delay=True. Default: False.

  • legend (bool, optional) – Whether to enable the plot legend. When label_type='auto' (the default), a legend is only rendered if there are varying metadata fields across the plotted spectra (e.g., multiple baseline-pairs or LSTs). With any other label_type value, the legend is always rendered when legend=True. Has no effect when title_legend=False. Default: False.

  • title_legend (bool, optional) – If True, generate delay-spectrum title/legend metadata. When label_type="auto", static fields are written to the title and varying fields are written to the legend. If False, do not create the title or legend text automatically. Default: True.

  • ax (matplotlib.axes, optional) – Use this to pass in an existing Axes object, which the power spectra will be added to. The smart title/legend behavior also applies when using a provided Axes unless title_legend=False. If None, a new Axes object will be created. Default: None.

  • component (str, optional) – Component of complex spectra to plot, options=[‘abs’, ‘real’, ‘imag’]. Default: ‘real’.

  • lines (bool, optional) – If True, plot lines between bandpowers for a given pspectrum. Default: True.

  • markers (bool, optional) – If True, plot circles at bandpowers. Filled for positive, empty for negative. Default: False.

  • error (str, optional) – If not None and if error exists in uvp stats_array, plot errors on bandpowers. Default: None.

  • times (array_like, optional) – Values from uvp.time_avg_array to plot. Use this to select which integrations appear; if label_type="blpairt", the legend labels include the selected time for each spectrum.

  • logscale (bool, optional) – If True, put plot on a log-scale. Else linear scale. Default: True.

  • force_plot (bool, optional) – If plotting a large number of spectra (>100), this function will error. Set this to True to override this large plot error and force plot. Default: False.

  • label_type (str, optional) – Line label type in legend. Options are: 'auto' to put static metadata in the title and varying metadata in the legend; 'key' to label lines by (spw, blpair, pol); 'blpair' to label by blpair; and 'blpairt' to label by blpair-time.

  • plot_stats (string, optional) – If not None, plot an entry in uvp.stats_array instead of power spectrum in uvp.data_array.

  • kwargs (dict, optional) – Extra kwargs to pass to _all_ ax.plot calls.

Returns:

fig – Matplotlib Figure instance.

Return type:

matplotlib.pyplot.Figure