solarwindpy.plotting.spiral

Spiral mesh plots and associated binning utilities.

Functions

calculate_bin_number_with_numba(mesh, x, y)

get_counts_per_bin(bins, x, y)

Classes

InitialSpiralEdges(x, y)

SpiralFilterThresholds(density, size)

SpiralMesh(x, y, initial_xedges, initial_yedges)

SpiralMeshBinID(id, fill, visited)

SpiralPlot2D(x, y[, z, logx, logy, ...])

2D spiral plotting with adaptive mesh refinement.

class InitialSpiralEdges(x, y)

Bases: tuple

count(value, /)

Return number of occurrences of value.

index(value, start=0, stop=sys.maxsize, /)

Return first index of value.

Raises ValueError if the value is not present.

x

Alias for field number 0

y

Alias for field number 1

class SpiralMeshBinID(id, fill, visited)

Bases: tuple

count(value, /)

Return number of occurrences of value.

fill

Alias for field number 1

id

Alias for field number 0

index(value, start=0, stop=sys.maxsize, /)

Return first index of value.

Raises ValueError if the value is not present.

visited

Alias for field number 2

class SpiralFilterThresholds(density, size)

Bases: tuple

count(value, /)

Return number of occurrences of value.

density

Alias for field number 0

index(value, start=0, stop=sys.maxsize, /)

Return first index of value.

Raises ValueError if the value is not present.

size

Alias for field number 1

get_counts_per_bin(bins, x, y)[source]
calculate_bin_number_with_numba(mesh, x, y)[source]
class SpiralMesh(x, y, initial_xedges, initial_yedges, min_per_bin=250)[source]

Bases: object

__init__(x, y, initial_xedges, initial_yedges, min_per_bin=250)[source]
property bin_id
property cat

pd.Categorical version of bin_id, with fill bin removed.

property data
property initial_edges
property mesh
property min_per_bin
property cell_filter_thresholds
property cell_filter

Boolean Series identifying properly filled mesh cells.

Series selects mesh cells that meet density and area criteria specified by mesh_cell_filter_thresholds().

Notes

Neither density nor size convert log-scale edges into linear scale. Doing so would overweight the area of mesh cells at larger values on a given axis.

set_cell_filter_thresholds(**kwargs)[source]

Set or update the mesh_cell_filter_thresholds().

Parameters:
  • density (scalar) – The density quantile above which we want to select bins, e.g. above the 0.01 quantile. This ensures that each bin meets some sufficient fill factor.

  • size (scalar) – The size quantile below which we want to select bins, e.g. below the 0.99 quantile. This ensures that the bin isn’t so large that it will appear as an outlier.

set_initial_edges(xedges, yedges)[source]
set_data(x, y)[source]
set_min_per_bin(new)[source]
initialize_bins()[source]
static process_one_spiral_step(bins, x, y, min_per_bin)[source]
generate_mesh()[source]
calculate_bin_number()[source]
place_spectra_in_mesh()[source]
build_cat()[source]
class SpiralPlot2D(x, y, z=None, logx=False, logy=False, initial_bins=5, clip_data=False)[source]

Bases: PlotWithZdata, CbarMaker

2D spiral plotting with adaptive mesh refinement.

Examples

splot = SpiralPlot2D(
) splot.initialize_mesh()

__init__(x, y, z=None, logx=False, logy=False, initial_bins=5, clip_data=False)[source]
property clim
property initial_bins
property grouped
property mesh
agg(fcn=None)[source]

Aggregate the z-values into their bins.

build_grouped()[source]
calc_initial_bins(nbins)[source]
initialize_mesh(**kwargs)[source]
set_clim(lower=None, upper=None)[source]

Set the min (lower) and max (upper) counts per bin.

This limit is applied after the groupby.agg() is run.

set_data(x, y, z, clip)[source]
make_plot(ax=None, cbar=True, limit_color_norm=False, cbar_kwargs=None, fcn=None, alpha_fcn=None, **kwargs)[source]
plot_contours(ax=None, method='rbf', rbf_neighbors=50, rbf_smoothing=1.0, rbf_kernel='thin_plate_spline', grid_resolution=100, gaussian_filter_std=1.5, interpolation='cubic', nan_aware_filter=True, label_levels=True, cbar=True, cbar_kwargs=None, fcn=None, clabel_kwargs=None, skip_max_clbl=True, use_contourf=False, **kwargs)[source]

Make a contour plot from adaptive mesh data with optional smoothing.

Supports three interpolation methods for generating contours from the irregular adaptive mesh:

  • "rbf": Sparse RBF interpolation (default, fastest with built-in smoothing)

  • "grid": Grid interpolation + Gaussian smoothing (matches Hist2D API)

  • "tricontour": Direct triangulated contours (no smoothing, for debugging)

Parameters:
  • ax (mpl.axes.Axes, None) – If None, create an Axes instance from plt.subplots.

  • method ({"rbf", "grid", "tricontour"}) – Interpolation method. Default is "rbf" (fastest with smoothing).

  • Parameters (Common)

  • ---------------------

  • rbf_neighbors (int) – Number of nearest neighbors for sparse RBF. Higher = smoother but slower. Default is 50.

  • rbf_smoothing (float) – RBF smoothing parameter. Higher values produce smoother surfaces. Default is 1.0.

  • rbf_kernel (str) – RBF kernel type. Options: “thin_plate_spline”, “cubic”, “quintic”, “multiquadric”, “inverse_multiquadric”, “gaussian”.

  • Parameters

  • ----------------------

  • grid_resolution (int) – Number of grid points along each axis. Default is 100.

  • gaussian_filter_std (float) – Standard deviation for Gaussian smoothing. Default is 1.5. Set to 0 to disable smoothing.

  • interpolation ({"linear", "cubic", "nearest"}) – Interpolation method for griddata. Default is “cubic”.

  • nan_aware_filter (bool) – If True, use NaN-aware Gaussian filtering. Default is True.

  • Parameters

  • -----------------

  • label_levels (bool) – If True, add labels to contours with ax.clabel. Default is True.

  • cbar (bool) – If True, create a colorbar. Default is True.

  • cbar_kwargs (dict, None) – Keyword arguments passed to self._make_cbar.

  • fcn (callable, None) – Aggregation function. If None, automatically select in agg().

  • clabel_kwargs (dict, None) – Keyword arguments passed to ax.clabel.

  • skip_max_clbl (bool) – If True, don’t label the maximum contour level. Default is True.

  • use_contourf (bool) – If True, use filled contours. Default is False.

  • **kwargs – Additional arguments passed to the contour function. Common options: levels, cmap, norm, linestyles.

Returns:

  • ax (mpl.axes.Axes) – The axes containing the plot.

  • lbls (list or None) – Contour labels if label_levels=True, else None.

  • cbar_or_mappable (Colorbar or QuadContourSet) – The colorbar if cbar=True, else the contour set.

  • qset (QuadContourSet) – The contour set object.

Examples

>>> # Default: sparse RBF (fastest)
>>> ax, lbls, cbar, qset = splot.plot_contours()
>>> # Grid interpolation with Gaussian smoothing
>>> ax, lbls, cbar, qset = splot.plot_contours(
...     method='grid',
...     grid_resolution=100,
...     gaussian_filter_std=2.0
... )
>>> # Debug: see raw triangulation
>>> ax, lbls, cbar, qset = splot.plot_contours(method='tricontour')
property clip
property data
property labels
property log
property logger
property path

Path for saving figure.

set_labels(**kwargs)

Set or update x, y, or z labels. Any label not specified in kwargs.

is propagated from self.labels.<x, y, or z>.

set_log(x=None, y=None)
set_path(new, add_scale=True)

Build the plot save path.

Parameters:
  • new (str or Path) – If str and == “auto”, then build path from self.labels. Otherwise, assume parameter specifies the desired path and use Path(new).

  • add_scale (bool) – If True, add information about the axis scales to the end of the path.