Skip to content

Conversation

@astjoephysics
Copy link
Collaborator

Beginning of #17. Adds some barebones visualisation functionality. Can take in a .csv (and I assume .hdf5, although I haven't tested it) of orbits (assuming BKEP input) and plot orbits in either plotly or matplot (default to matplot).

WIP, needs orbit conversion functionality and actual command line inputs + any tidying up of code.

@mschwamb mschwamb changed the title add some visualisation functionality WIP - add some visualisation functionality Apr 9, 2025
@astjoephysics
Copy link
Collaborator Author

Currently added:

  1. 2D matplot plotting with flags for:
  • describing what planet orbits you want plotted (must be in form 'Me', 'V', 'E', 'Ma', 'J', 'S', 'U', 'N', basic circular orbit assumed for now)
  • turning on or off the sun, planets
  • turning on or off the object orbits being faded
  1. 3D matplot plotting with all of above
  2. 3D plotly plotting

Todo:

  • Add functionality to convert orbit types. Currently assumed BKEP input orbit type so will need to check input file for orbit format and convert if necessary

@astjoephysics astjoephysics changed the title WIP - add some visualisation functionality add some visualisation functionality May 6, 2025
import matplotlib.pyplot as plt
from matplotlib.collections import LineCollection

plt.style.use("./src/layup/matplot2d.mplstyle")
Copy link
Collaborator

@mschwamb mschwamb May 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in the package content we can't import like this. Is that right, @drewoldag ? Do you suggestions?

@astjoephysics
Copy link
Collaborator Author

the mpl style file should be edited so that there is a function that takes in the figure axes and sets up the plotting visual tools

@astjoephysics astjoephysics requested a review from mschwamb May 20, 2025 21:03
@mschwamb
Copy link
Collaborator

@bernardinelli says he's on deck to review this when he has time post this talk at a conference this week

axs[1].add_collection(lc)

# add the sun
if not no_sun:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpicking, because I've made this mistake before: instead of using if not no_sun, wouldn't it be better to just check if sun? xD

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d.art3d import Line3DCollection

fig = plt.figure(figsize=(15, 9))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest instead of creating the figure and axis object, we could have the user send their own too. For example, if I want to use my own plot style, or plot other things in parallel

# mean anomaly via fixed point iteration and then wrap the linspace
# around this value from 0 to 2pi
E_init = M # initial guesses using mean anomaly (shouldn't be too far off)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should assert e<1 here

"axes.titlesize": 32,
}
)
def matplot_2D(orb_array, planets, no_planets, no_sun, output, fade):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think it’s a bad idea to create and destroy the Matplotlib fig and ax objects inside the function entirely. For the CLI, this can be done outside the function call, these objects passed and then closed afterwards, as it doesn’t matter. But allowing me to pass and close my own object is a lot more flexible, as I can add other things I want to my own figure

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the same spirit as before, I think that the Matplotlib rc parameters should only be changed if I’m using the CLI, I think it’s rude to change those otherwise (eg I use my own custom set of parameters)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(A better implementation option than what I suggested earlier for the fig and axs business is to have them be None as defaults, and instantiate them if they’re none)

@astjoephysics
Copy link
Collaborator Author

Also begins to addresses the hyperbolic orbit stuff from #18 in lines 168-170

@mschwamb mschwamb requested review from Little-Ryugu and removed request for mschwamb October 23, 2025 17:38
sys.exit("ERROR: File format must be 'csv' or 'hdf5'")

# check for overwriting output file
warn_or_remove_file(str(output_file), args.force, logger)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The force command -f doesn't work. The output files are defined as output.csv or output.h5 for the args.force check instead of checking for output.png in the function warn_or_remove_files.

if args.i.lower() == "csv":
output_file = args.o + ".csv"
elif args.i.lower() == "hdf5":
output_file = args.o + ".h5"
else:
sys.exit("ERROR: File format must be 'csv' or 'hdf5'")

default="csv",
required=False,
)
optional.add_argument(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When --orbit_type is not called in cmd line, args.orbit_type defaults to None. then it's called as None in:

visualize_cli(
input=args.input,
output_file_stem=args.o,
planets=args.planets,
input_format=args.orbit_type,
backend=args.b,
dimensions=args.d,
num_orbs=args.n,
plot_planets=args.plot_planets,
plot_sun=args.plot_sun,
fade=args.fade,
)

and this default value being set in visualize_cli is ignored

input_format: Literal["BCART", "BCOM", "BKEP", "CART", "COM", "KEP"] = "BKEP",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants