-
Notifications
You must be signed in to change notification settings - Fork 1
add some visualisation functionality #111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
update remote branch
|
Currently added:
Todo:
|
src/layup/visualize.py
Outdated
| import matplotlib.pyplot as plt | ||
| from matplotlib.collections import LineCollection | ||
|
|
||
| plt.style.use("./src/layup/matplot2d.mplstyle") |
There was a problem hiding this comment.
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?
|
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 |
|
@bernardinelli says he's on deck to review this when he has time post this talk at a conference this week |
src/layup/visualize.py
Outdated
| axs[1].add_collection(lc) | ||
|
|
||
| # add the sun | ||
| if not no_sun: |
There was a problem hiding this comment.
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
src/layup/visualize.py
Outdated
| import matplotlib.pyplot as plt | ||
| from mpl_toolkits.mplot3d.art3d import Line3DCollection | ||
|
|
||
| fig = plt.figure(figsize=(15, 9)) |
There was a problem hiding this comment.
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) | ||
|
|
There was a problem hiding this comment.
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
src/layup/visualize.py
Outdated
| "axes.titlesize": 32, | ||
| } | ||
| ) | ||
| def matplot_2D(orb_array, planets, no_planets, no_sun, output, fade): |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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)
|
Also begins to addresses the hyperbolic orbit stuff from #18 in lines 168-170 |
| 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) |
There was a problem hiding this comment.
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.
layup/src/layup_cmdline/visualize.py
Lines 124 to 130 in ef98cb1
| 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( |
There was a problem hiding this comment.
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:
layup/src/layup_cmdline/visualize.py
Lines 144 to 155 in ef98cb1
| 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
Line 510 in ef98cb1
| input_format: Literal["BCART", "BCOM", "BKEP", "CART", "COM", "KEP"] = "BKEP", |
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.