Skip to content
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

Animation generation #39

Merged
merged 10 commits into from
Nov 28, 2024
Merged

Conversation

ShaunD137
Copy link
Contributor

Add a generate animation plotting function for displaying videos of 2D simulations, includes option to move window along with simulation (predominatly used in wakefield simulations).

@JoelLucaAdams JoelLucaAdams added the enhancement New feature or request label Nov 20, 2024
Copy link
Contributor

@LiamPattinson LiamPattinson left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution!

I've had a glance over things and left a few comments, though I've not looked too deeply into how things are working here.

One thing to look into are Xarray 'accessors', which allow you to add custom functionality to the datasets themselves. These could be used to add new syntax such as:

import xarray as xr
from sdf_xarray import SDFPreprocess

ds = xr.open_mfdataset("./*.sdf", preprocess=SDFPreprocess())
ds.epoch.animate(...)
# Or maybe:
ds.sdf.animate(...)

src/sdf_xarray/plotting.py Outdated Show resolved Hide resolved
src/sdf_xarray/plotting.py Outdated Show resolved Hide resolved
import matplotlib.pyplot as plt
import numpy as np
import xarray as xr
from IPython.display import HTML
Copy link
Contributor

Choose a reason for hiding this comment

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

See the Matplotlib comment above: IPython is not a dependency of the project.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We should probably put it in a try: catch or even better would be to follow the approach you listed below on returning the fig + ani. It is also an optional dependency under the jupyter flag and gets installed via ipykernel

jupyter = ["dask[diagnostics]", "ipykernel>=6.29.5"]

Copy link
Contributor

Choose a reason for hiding this comment

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

The solution at the end of this StackOverflow answer looks promising if you want to add some nice functions for use in notebooks but emit sensible errors if the user tries to run them in regular code.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure if we still want to include matplolib as an optional dependency as the normal plotting function from xarray fails anyways. I think we can leave it as is

src/sdf_xarray/plotting.py Outdated Show resolved Hide resolved
src/sdf_xarray/plotting.py Outdated Show resolved Hide resolved
@LiamPattinson
Copy link
Contributor

Raised a counter-PR to implement the recommendations: ShaunD137#1

If that's merged, the changes should make it to this PR automatically. Feel free to request any changes on the other PR.

@ShaunD137
Copy link
Contributor Author

I'm happy for you to merge these in, thanks for fixing these issues.

@JoelLucaAdams
Copy link
Collaborator

@ZedThree can we get an approval for this?

Copy link
Member

@ZedThree ZedThree left a comment

Choose a reason for hiding this comment

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

Could really do with some tests, though I appreciate these are hard for animations!

@JoelLucaAdams JoelLucaAdams merged commit a6d3037 into PlasmaFAIR:main Nov 28, 2024
5 checks passed
@JoelLucaAdams
Copy link
Collaborator

Agreed, would be nice but already spent way too much time on this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants