SunpyPlotter#

class sunkit_pyvista.SunpyPlotter(*, coordinate_frame=None)[source]#

Bases: object

A plotter for 3D data.

This class wraps pyvsita.Plotter to provide coordinate-aware plotting. For now, all coordinates are converted to a specific frame (~sunpy.coordinates.HeliocentricInertial by default), and distance units are such that \(R_{sun} = 1\).

Parameters:

coordinate_frame (astropy.coordinates.BaseFrame) – Coordinate frame of the plot. The x, y, z axes of the pyvista plotter will be the x, y, z axes in this coordinate system.

all_meshes#

Stores a reference to all the plotted meshes in a dictionary.

Type:

dict

Attributes Summary

coordinate_frame

Coordinate frame of the plot.

plotter

pyvista.Plotter.

Methods Summary

load(filepath)

Load saved meshes into this plotter.

plot_coordinates(coords, *[, radius])

Plot a sphere if a single coordinate is passed and plots a line if multiple coordinates are passed.

plot_field_lines(field_lines, *[, color_func])

Plot magnetic field lines from pfsspy.

plot_limb(m, *[, radius])

Draws the solar limb as seen by the map's observer.

plot_map(m, *[, clip_interval, ...])

Plot a sunpy map.

plot_quadrangle(bottom_left, *[, top_right, ...])

Plot a quadrangle.

plot_solar_axis(*[, length, arrow_kwargs])

Plot the solar rotation axis as an arrow.

save(filepath, *[, overwrite])

Save all the meshes.

set_camera_coordinate(coord)

Set the camera position.

set_view_angle(angle)

Set the camera view angle.

show(*args, **kwargs)

Show the plot.

Attributes Documentation

coordinate_frame#

Coordinate frame of the plot.

plotter#

pyvista.Plotter.

Methods Documentation

load(filepath)[source]#

Load saved meshes into this plotter.

Parameters:

filepath (str or pathlib.Path) – Name of the file to load, should have vtm or vtmb as an extension.

plot_coordinates(coords, *, radius=0.05, **kwargs)[source]#

Plot a sphere if a single coordinate is passed and plots a line if multiple coordinates are passed.

Parameters:
  • coords (astropy.coordinates.SkyCoord) – Coordinate(s) to plot as a center of sphere or line.

  • radius (int, optional) – Radius of the sphere times the radius of the sun to be plotted when a single coordinate is passed. Defaults to 0.05 times the radius of the sun.

  • **kwargs – Keyword arguments are passed to pyvista.Plotter.add_mesh.

Notes

This plots a pyvista.Sphere object if a single coordinate is passed and plots a pyvista.Spline object if multiple coordinates are passed. radius is only considered when a sphere is plotted.

plot_field_lines(field_lines, *, color_func=None, **kwargs)[source]#

Plot magnetic field lines from pfsspy.

Parameters:
  • field_lines (pfsspy.fieldline.FieldLines) – Field lines to be plotted.

  • color_func (function) –

    Function to get the color for each field line. If not given, defaults to showing closed field lines in black, and open field lines in blue (positive polarity) or red (negative polarity). The function must have the signature:

       def color_func(field_line: pfsspy.fieldline.FieldLine) -> color:
    
    Where ``color`` is any color that `pyvista` recognises
    (e.g. a RGBA tuple, a RGB tuple, a color string)
    

  • **kwargs – Keyword arguments are handed to pyvista.Plotter.add_mesh.

plot_limb(m, *, radius=0.02, **kwargs)[source]#

Draws the solar limb as seen by the map’s observer.

Parameters:
  • m (sunpy.map.Map) – Map’s limb to be plotted.

  • radius (float) – Radius of the pyvista.Spline used to create the limb. Defaults to 0.02 times the radius of the sun.

  • **kwargs (Keyword arguments are handed to pyvista.Plotter.add_mesh.) –

plot_map(m, *, clip_interval: Unit('%') = None, assume_spherical_screen=True, **kwargs)[source]#

Plot a sunpy map.

Parameters:
  • m (sunpy.map.Map) – Map to be plotted.

  • clip_interval (two-element ~astropy.units.Quantity, optional) – If provided, the data will be clipped to the percentile interval bounded by the two numbers.

  • assume_spherical_screen (bool, optional) – If True (default) then off-limb pixels are plotted using sunpy.coordinates.Helioprojective.assume_spherical_screen(). If False, off-limb pixels are not plotted.

  • **kwargs – Keyword arguments are handed to pyvista.Plotter.add_mesh.

plot_quadrangle(bottom_left, *, top_right=None, width: Unit('deg') = None, height: Unit('deg') = None, radius=0.01, **kwargs)[source]#

Plot a quadrangle.

This draws a quadrangle that has corners at (bottom_left, top_right), if width and height are specified, they are respectively added to the longitude and latitude of the bottom_left coordinate to calculate a top_right coordinate.

Parameters:
  • bottom_left (~astropy.coordinates.SkyCoord) – The bottom-left coordinate of the quadrangle. It can have shape (2,) to simultaneously define top_right.

  • top_right (~astropy.coordinates.SkyCoord) – The top-right coordinate of the quadrangle.

  • width (astropy.units.Quantity, optional) – The width of the quadrangle. Required if top_right is omitted.

  • height (astropy.units.Quantity) – The height of the quadrangle. Required if top_right is omitted.

  • radius (float) – Radius of the pyvista.Spline used to create the quadrangle. Defaults to 0.01 times the radius of the sun.

  • **kwargs (Keyword arguments are handed to pyvista.Plotter.add_mesh.) –

plot_solar_axis(*, length=2.5, arrow_kwargs=None, **kwargs)[source]#

Plot the solar rotation axis as an arrow.

Parameters:
  • length (float) – Length of the arrow in multiples of solar radii.

  • arrow_kwargs (dict) – Keyword arguments to be handed to pyvista.Arrow. start, direction, and scale cannot be manually specified, as they are automatically set.

  • **kwargs – Keyword arguments are handed to pyvista.Plotter.add_mesh.

save(filepath, *, overwrite=False)[source]#

Save all the meshes.

This saves the rendered plot as a vtm extended file as well as a directory of the individual meshes with the specified name.

Parameters:

filepath (str or pathlib.Path) – Name of the file to save as, should have vtm or vtmb as an extension.

Examples

>>> from sunkit_pyvista import SunpyPlotter
>>> plotter = SunpyPlotter()
>>> plotter.plot_solar_axis()
>>> plotter.save('./filename.vtm') 
set_camera_coordinate(coord)[source]#

Set the camera position.

Parameters:

coords (astropy.coordinates.SkyCoord) – Camera coordinate.

set_view_angle(angle: Unit('deg'))[source]#

Set the camera view angle.

Parameters:

angle (astropy.units.Quantity) – The viewing angle.

show(*args, **kwargs)[source]#

Show the plot.

See pyvista.Plotter.show for accepted arguments.