SunpyPlotter#

class sunkit_pyvista.SunpyPlotter(*args, **kwargs)[source]#

Bases: SaveMixIn, Plotter

A plotter for 3D data.

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

Parameters:
  • coordinate_frame (astropy.coordinates.BaseCoordinateFrame) – 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.

  • obstime (astropy.time.Time) – The obstime to use for the default coordinate frame if coordinate_frame= is not specified. Must not be specified if coordinate_frame is given.

  • kwargs (dict) – All other keyword arguments are passed through to pyvista.Plotter.

all_meshes#

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

Type:

dict

Attributes Summary

coordinate_frame

Coordinate frame of the plot.

Methods Summary

coordinates_to_polydata(coords)

Convert a set of coordinates in a SkyCoord to a pyvista.PolyData mesh.

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_current_sheet(pfss_out, **kwargs)

Plot current sheet, where \(B_r=0\).

plot_field_lines(field_lines, *[, color_func])

Plot magnetic field lines.

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_camera_focus(coord)

Set the camera focus.

set_view_angle(angle)

Set the camera view angle.

Attributes Documentation

coordinate_frame#

Coordinate frame of the plot.

Methods Documentation

coordinates_to_polydata(coords)[source]#

Convert a set of coordinates in a SkyCoord to a pyvista.PolyData mesh.

Parameters:

coords (astropy.coordinates.SkyCoord) – Coordinates to convert.

Return type:

pyvista.PolyData

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_current_sheet(pfss_out, **kwargs)[source]#

Plot current sheet, where \(B_r=0\).

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

Plot magnetic field lines.

Parameters:
  • field_lines (sunkit_magex.pfss.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: sunkit_magex.pfss.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:
plot_map(
m,
*,
clip_interval: Unit('%') = None,
assume_spherical_screen=True,
**kwargs,
)[source]#

Plot a sunpy map.

Parameters:
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 (SkyCoord) – The bottom-left coordinate of the quadrangle. It can have shape (2,) to simultaneously define top_right.

  • top_right (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_camera_focus(coord)[source]#

Set the camera focus.

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.