mirage.vis package#

Submodules#

mirage.vis.visualization module#

mirage.vis.visualization.celestial_grid(lat_interval_deg: float = 30.0, lon_interval_deg: float = 30.0, line_resolution: int = 100, return_labels: bool = False) ndarray | Tuple[ndarray, list[str], ndarray]#

Creates a unit-length grid of points on the celestial sphere for constant latitude/longitude, azimuth/elevation, or ra/dec lines

Parameters:
  • lat_interval_deg (float, optional) – Interval between latitude lines [deg], defaults to 30.0

  • lon_interval_deg (float, optional) – Interval between longitude lines [deg], defaults to 30.0

  • line_resolution (int, optional) – Number of points within each line, defaults to 100

  • return_labels (bool, optional) – Whether to return label information, defaults to False

Returns:

Points ready for mrv.plot3(), label strings (if requested), and label positions (if requested)

Return type:

Union[np.ndarray, Tuple[np.ndarray, list[str], np.ndarray]

mirage.vis.visualization.earth_border_points() ndarray#

Returns an array of points representing country borders

Returns:

Country borders, separated by np.nan rows so they can be plotted all at once

Return type:

np.ndarray [n,3]

mirage.vis.visualization.get_cbar_ax(ax: Axes | None = None, side: str = 'right') Axes#

Returns an axis to the right of a plot to use for a colorbar

Parameters:

ax (plt.Axes, optional) – matplotlib axes, defaults to None

Returns:

The appended colorbar axes

Return type:

plt.Axes

mirage.vis.visualization.orbit_plotter(pl: Plotter, frames: int = 60, fps: int = 20, shift: float = 0.0, focus: ndarray | None = None, gif_name: str = 'test.gif', factor: int = 2.0)#

Orbits a plotter and saves a gif of the path

Parameters:
  • pl (pv.Plotter) – PyVista plotter to use

  • frames (int, optional) – Number of frames in the gif for 1 revolution around the scene, defaults to 60

  • fps (int, optional) – Frames per second of the resulting render, defaults to 20

  • shift (float, optional) – Vertical shift above the scene, defaults to 0.0

  • focus (np.ndarray, optional) – The focus point of the render, defaults to None

  • gif_name (str, optional) – Name of the gif file, saved to the current working directory, defaults to “test.gif”

  • factor (int, optional) – Factor to multiply greatest extent from the origin when making the camera positions, defaults to 2.0

mirage.vis.visualization.plot3(pl: Plotter, v: ndarray, use_spline: bool = False, **kwargs) PolyData#

Replicates MATLAB’s plot3() with a pyvista backend, please use densely scattered points to avoid confusing splines

Parameters:
  • pl (pv.Plotter) – Plotter object to add line to

  • v (np.ndarray [n,3]) – Vector to plot

  • use_spline (bool) – Whether to plot as a spline, defaults to False

  • **kwargs – Additional arguments passed to pl.add_mesh()

Returns:

Plotted spline

Return type:

pv.PolyData

mirage.vis.visualization.plot_angle_between(pl: Plotter, v1: ndarray, v2: ndarray, center: ndarray, dist: float = 1.0, linewidth: float = 10.0)#

Plots an arc between two vectors

Parameters:
  • pl (pv.Plotter) – Plotter to add to

  • v1 (np.ndarray [1x3]) – First vector

  • v2 (np.ndarray [1x3]) – Second vector

  • center (np.ndarray [1x3]) – Center point of the arc

  • dist (float, optional) – Distance from the center to the arc, defaults to 1.0

  • linewidth (float, optional) – Line width, defaults to 10.0

mirage.vis.visualization.plot_arrow(pl: Plotter, origin: ndarray, direction: ndarray, scale: float = 1, color: str = 'tan', label: str | None = None, shape_opacity: float = 0.0, font_size: int = 36, name: str | None = None, **arrows_kwargs) None#

Plots a single arrow to the PyVista scene

Parameters:
  • pl (pv.Plotter) – Plotter to add to

  • origin (np.ndarray [1x3]) – Origin point of the arrow

  • direction (np.ndarray [1x3]) – Direction of the vector

  • scale (float, optional) – Scale of the vector applied to the direction, defaults to 1

  • color (str, optional) – Color of the arrow, defaults to “tan”

  • label (str, optional) – Label of the arrow tip, defaults to None

  • shape_opacity (float, optional) – Opacity of the arrow shape, defaults to 0.0

  • font_size (int, optional) – Font size of the label, defaults to 36

  • name (str, optional) – Actor name for PyVista’s use, defaults to None

mirage.vis.visualization.plot_balltree(pl: Plotter, tree)#
mirage.vis.visualization.plot_basis(pl: Plotter, dcm: ndarray, labels: str | list[str] | None = None, origin: ndarray = array([0, 0, 0]), scale: float = 1, color: str = 'tan', shape_opacity: float = 0.0, font_size: int = 36)#

Plots a set of basis vectors using a given direction cosine matrix (DCM)

Parameters:
  • pl (pv.Plotter) – PyVista plotter to add the basis to

  • dcm (np.ndarray) – DCM to plot the basis vectors of

  • labels (Union[str, list[str]], optional) – Labels to use for each unit vector, defaults to None

  • origin (np.ndarray, optional) – Origin point of the frame, defaults to np.array([0, 0, 0])

  • scale (float, optional) – Scale of the basis vectors arrows, defaults to 1

  • color (str, optional) – Color of the basis vector arrows, defaults to “tan”

  • shape_opacity (float, optional) – Opacity of the basis vector arrows, defaults to 0.0

  • font_size (int, optional) – Font size of the labels, defaults to 36

mirage.vis.visualization.plot_conic_sensor(pl: Plotter, station: Station, date: datetime, look_dir_eci: ndarray, half_angle_deg: float, extent: float = 1000, show_edges: bool = False, **mesh_kwargs) None#

Plots a conic (cone-shaped) sensor volume, highlighting all positions that can be seen by the sensor withun a certain extent

Parameters:
  • pl (pv.Plotter) – pyvista plotter to add the mesh to

  • station (Station) – Station performing the observation

  • date (datetime.datetime) – Date and time of the observation

  • look_dir_eci (np.ndarray) – Look direction of the sensor in ECI (J2000)

  • half_angle_deg (float) – The half angle of the conic sensor in [deg]

  • extent (float, optional) – The distance extent of the sensor in [km], defaults to 1000

  • show_edges (bool, optional) – Whether to show the border of the extent, defaults to False

mirage.vis.visualization.plot_egi(pl: Plotter, obj: SpaceObject, egi: ndarray, scale: float = 1.5, plot_stems: bool = True, plot_sphere: bool = True, scale_opacity: bool = True) None#

Plots an Extended Gaussian Image (EGI)

Parameters:
  • pl (pv.Plotter) – PyVista plotter to add the EGI to

  • obj (SpaceObject) – Object to plot the EGI for

  • egi (np.ndarray) – The EGI, likely taken from obj.egi

  • scale (float, optional) – Scale of the EGI with respect to the furthest object vertex from the origin, defaults to 1.5

  • plot_stems (bool, optional) – Whether to plot the stems of the EGI, defaults to True

  • plot_sphere (bool, optional) – Whether to plot scaled spheres at the end of each stem, defaults to True

  • scale_opacity (bool, optional) – Whether to scale the opacity of the EGI spheres with the face area, defaults to True

mirage.vis.visualization.plot_kdtree(pl: Plotter, tree)#
mirage.vis.visualization.plot_map_with_grid(grid: ndarray, title: str, cbar_label: str, alpha: float | None = None, cmap: str | None = None, borders: bool = False, border_color: str = 'black', cbar_tick_labels: list[Any] | None = None, set_plot_size: bool = True, hillshade: bool = False, **im_kwargs) None#

Plots a global map of the Earth and overlays a transparent, colormapped grid with formatting

Parameters:
  • grid (np.ndarray) – 2D grid, assumed to span [-90, 90] deg in first dimension, [-180, 180] deg in the second

  • title (str) – Title string for the plot

  • cbar_label (str) – Label for the colorbar

  • alpha (float, optional) – Transparency of the grid on top of the map, defaults to None

  • cmap (str, optional) – Colormap to use, defaults to None

  • borders (bool, optional) – Whether to use borders instead of a background image, defaults to False

  • border_color (list[Any], optional) – The color of the borders, defaults to “black”

  • cbar_tick_labels – The tick labels to use in the colorbar, defaults to None

  • set_plot_size (bool, optional) – Whether to set the size of the plot within this function, defaults to True

  • hillshade (bool, optional) – Whether to shade the slopes, defaults to False

mirage.vis.visualization.plot_visible_band(lambdas: ndarray, ys: ndarray)#

Adds the visible band colors to a 2D spectra plot

Parameters:
  • lambdas (np.ndarray) – Wavelengths to plot for

  • ys (np.ndarray) – Y-levels to end the color at (usually the height of the spectrum at each wavelength)

mirage.vis.visualization.render_observation_scenario(pl: Plotter, dates: ndarray[datetime, Any], station: Station, look_dirs_eci: ndarray, sensor_extent_km: float = 10000.0, sensor_half_angle_deg: float = 1.0, render_catalog: bool = True, up_dirs_eci: ndarray = None, **plot_earth_kwargs) None#

Renders a scene for a set of observations

Parameters:
  • dates (np.ndarray[datetime.datetime, Any]) – Dates (UTC)

  • station (Station) – Station performing the observation

  • look_dirs_eci (np.ndarray) – Unit vector directions the station looks in, ECI

  • sensor_extent_km (float, optional) – Extent of the sensor cone [km], defaults to 1e4

  • sensor_half_angle_deg (float, optional) – Half angle of the sensor, approximated as a conic [deg], defaults to 1.0

  • render_catalog (bool, optional) – Whether to render the catalog, defaults to True

  • up_dirs_eci (np.ndarray, optional) – Unit vector directions the station ups in, ECI, defaults to None

mirage.vis.visualization.render_spaceobject(pl: Plotter, obj: SpaceObject, origin: ndarray = array([0, 0, 0]), scale: float = 1, quat: ndarray = array([0., 0., 0., 1.]), feature_edges: bool = False, face_normals: bool = False, feature_edge_angle: float = 45, feature_edge_color: str = 'r', **kwargs) Actor#

Plots the object mesh using pyvista

Parameters:
  • pl (pv.Plotter) – Plotter to render object with

  • obj (SpaceObject) – Object to render

  • origin (np.ndarray, optional) – Origin point of the model, defaults to np.array([0, 0, 0])

  • scale (float, optional) – Scale of the model applied to its vertices, defaults to 1

  • quat (np.ndarray, optional) – Orientation quaternion of the model, defaults to np.array([[0, 0, 0, 1]])

  • feature_edges (bool, optional) – Whether to plot feature edges, defaults to False

  • face_normals (bool, optional) – Whether to plot the face normals, defaults to False

  • feature_edge_angle (float, optional) – Tolerance angle of the feature edges, defaults to 45

  • feature_edge_color (str, optional) – Color of the feature edges, defaults to “r”

Returns:

The actor of the mesh in the plotter

Return type:

pv.Actor

mirage.vis.visualization.render_video(pre_render_fcn: Callable, render_fcn: Callable, post_render_fcn: Callable, frame_count: int, fname: str | None = None, framerate: int = 60, quality: int = 9, background_color: str = 'white') None#

Renders a video given callables each stage of the recording

Parameters:
  • pre_render_fcn (Callable(pl: pv.Plotter)) – Called once before the first frame

  • render_fcn (Callable(pl: pv.Plotter, i: int)) – Called each frame

  • post_render_fcn (Callable(pl: pv.Plotter, i: int)) – Called after each frame, before the next (only needed for niche effects)

  • frame_count (int) – Number of frames to render

  • fname (str, optional) – File name to save as, defaults to None

  • framerate (int, optional) – Frame rate of movie [frames/second], defaults to 60

  • quality (int, optional) – Quality of movie file, defaults to 9, less than 10

  • background_color (str, optional) – Background color of plot window, defaults to “white”

mirage.vis.visualization.scatter3(pl: Plotter, v: ndarray, **kwargs) PolyData#

Replicates MATLAB’s scatter3() with pyvista backend

Parameters:
  • pl (pv.Plotter) – Plotter object to add points to

  • v (np.ndarray [n,3]) – Vector to scatter

  • **kwargs – Additional arguments passed to pl.add_mesh()

Returns:

Handle to plotted data

Return type:

pv.PolyData

mirage.vis.visualization.show_and_copy(ch: Chart2D) None#

Shows and copies a pyvista plot to the clipboard using ffmpeg

Parameters:

ch (pv.Chart2D) – Chart object to copy

mirage.vis.visualization.texit(title: str, xlabel: str, ylabel: str, legend: list[str] | None = None, axis_label_font_size: int = 12, title_font_size: int = 15, grid: bool = True)#

All my prefered plot formatting, all in one place

Parameters:
  • title (str) – Title string

  • xlabel (str) – X-axis label

  • ylabel (str) – Y-axis label

mirage.vis.visualization.textured_ellipsoid(a: float, f: float, rotm: ndarray = array([[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]])) ParametricEllipsoid#

Returns a parametric ellipsoid based on the given semimajor axis and flattening ratio, ready for texturing

Parameters:
  • a (float) – Semimajor axis of the body

  • f (float) – Flattening ratio of the body

  • rotm (np.ndarray [3,3]) – Rotation matrix to apply to the body points, defaults to np.eye(3)

Returns:

Ellipsoid parametrized by a, f

Return type:

pv.ParametricEllipsoid

mirage.vis.visualization.two_sphere(pl: Plotter, radius: float = 1.0, origin: ndarray = array([0, 0, 0]), **kwargs)#

Plots a sphere \(S^2\) in \(R^3\)

Parameters:
  • pl (pv.Plotter) – Plotter to add sphere to

  • radius (float, optional) – Radius of sphere mesh, defaults to 1.0

  • origin (np.ndarray, optional) – Origin of sphere mesh, defaults to np.array([0.0, 0.0, 0.0])

mirage.vis.visualization.vis_attitude_motion(obj: SpaceObject, quat: ndarray, fname: str | None = None, framerate: int = 60, quality: int = 9, background_color: str = 'white') None#

Visualizes attitude motion in terms of quaternions, applied to a 3D model

Parameters:
  • obj (SpaceObject) – Object to visualize orientations with

  • quat (np.ndarray [n,4]) – Orientation history

  • fname (str, optional) – File name to save movie to, defaults to None. If None, no video saved

  • framerate (int, optional) – Frame rate of movie [frames/second], defaults to 60

  • quality (int, optional) – Quality of movie file, defaults to 9, less than 10

  • background_color (str, optional) – Background color of plot window, defaults to “white”

mirage.vis.visualization.wavelength_to_rgb(wavelengths: ndarray) ndarray#

Convert an array of wavelengths in the 380-750 nm range to RGB colors, from codingmess

Parameters:

wavelengths (np.ndarray) – Wavelengths [nm]

Returns:

RGBs, out of 255

Return type:

np.ndarray [n,3]

Module contents#