Skip to content

Commit

Permalink
tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
nabobalis committed Jun 12, 2024
1 parent 2d63031 commit 90fd0f6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions changelog/137.doc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added a new gallery example (:ref:`sphx_glr_generated_gallery_floating_sphere.py`) that plots a volume of points from the solar surface.
18 changes: 13 additions & 5 deletions examples/floating_sphere.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
"""
===========================================
Plotting A Volume from a cloud of SkyCoords
Plotting a volume from a cloud of SkyCoords
===========================================
This example demonstrates how to take a collection of points which you want to
visualise as either a cloud of points or a surface.
visualize as either a cloud of points or a surface.
"""

import astropy.units as u
import numpy as np
import sunpy.map
Expand All @@ -17,30 +18,36 @@

################################################################################
# Let's start by loading a map to give the visualization some context.

aia = sunpy.map.Map(LOW_RES_AIA_193)

################################################################################
# Next let's generate some point data.
#
# For this example we are going to generate a could which is roughly spherical.
# We start by defining the center of our sphere.

sphere_center = SkyCoord(10 * u.deg, 10 * u.deg, 1.2 * Rsun, frame="heliographic_stonyhurst")

################################################################################
# Let's generate some spherical coordinates for theta and phi, with 50 points in
# each coordinate. Then we generate a sphere of radius 0.05 RSun but with some
# each coordinate. Then we generate a sphere of radius 0.05 RSun but with some
# random noise.

theta, phi = np.mgrid[0:360:50j, -90:90:50j] * u.deg
radius = 0.05 * Rsun + np.random.random(theta.shape) * 0.01 * Rsun
rng = np.random.default_rng()
radius = 0.05 * Rsun + rng.random(theta.shape) * 0.01 * Rsun

################################################################################
# Next we use these vectors to make a SkyCoord around the defined sphere center.

vectors = SphericalRepresentation(theta, phi, radius)
new_points = sphere_center.cartesian + vectors.to_cartesian()
point_cloud = sphere_center.frame.realize_frame(new_points)

################################################################################
# Now we setup the pyvista visualization.
# For the coordinate conversions to work we need to set the obstime correctly
# For the coordinate conversions to work we need to set the ``obstime`` correctly
# for the visualization frame.

# sphinx_gallery_defer_figures
Expand Down Expand Up @@ -72,6 +79,7 @@

################################################################################
# Finally set up the camera position and focus.

plotter.set_camera_focus(sphere_center)
cam_coord = SkyCoord(0 * u.deg, 0 * u.deg, 5 * Rsun, frame="heliographic_stonyhurst")
plotter.set_camera_coordinate(cam_coord)
Expand Down
3 changes: 2 additions & 1 deletion sunkit_pyvista/plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ class SunpyPlotter:

def __init__(self, *, coordinate_frame=None, obstime=None, **kwargs):
if coordinate_frame is not None and obstime is not None:
raise ValueError("Only coordinate_frame or obstime can be specified, not both.")
msg = "Only coordinate_frame or obstime can be specified, not both."
raise ValueError(msg)

Check warning on line 51 in sunkit_pyvista/plotter.py

View check run for this annotation

Codecov / codecov/patch

sunkit_pyvista/plotter.py#L50-L51

Added lines #L50 - L51 were not covered by tests
if coordinate_frame is None:
coordinate_frame = HeliocentricInertial(obstime=obstime)
self._coordinate_frame = coordinate_frame
Expand Down

0 comments on commit 90fd0f6

Please sign in to comment.