cosima-recipes icon indicating copy to clipboard operation
cosima-recipes copied to clipboard

Tutorial: Making animations

Open AndyHoggANU opened this issue 4 years ago • 13 comments

Write a tutorial on how to make simple animations with the cookbook. Examples could be to show the seasonal cycle of Antarctic sea ice, or a transect that is dragged through a static, or moving, ocean...

AndyHoggANU avatar Apr 05 '20 22:04 AndyHoggANU

this notebook might be a good starting point?

navidcy avatar Apr 05 '20 22:04 navidcy

This notebook https://github.com/COSIMA/ACCESS-OM2-1-025-010deg-report/blob/master/figures/vorticity/vorticity.ipynb shows how this movie was done https://youtu.be/jo-xWkU0w6s

aekiss avatar Apr 06 '20 00:04 aekiss

FYI this is how I made gifs @AndyHoggANU

import imageio

from pathlib import Path
image_path = Path('.')
images = list(image_path.glob('*.png'))
image_list = []
for file_name in images:
    image_list.append(imageio.imread(file_name))

This finds all the images in the folder of the notebook, ordered by date made.

images

Lists the pictures, usually I check that the last few ones are the pictures I want to use if they've just been computed and saved using plt.savefig

imageio.mimwrite('drygalskideeper_T-S_monthly_volume.gif', image_list[-12:], fps=0.7)

Makes the gif using the most recent 12 images (e.g. monthly pictures for one year)

claireyung avatar Apr 06 '20 05:04 claireyung

@AndyHoggANU, this is where your code

import numpy as np
from celluloid import Camera
import matplotlib.pyplot as plt
import xarray as xr
import cmocean as cm
from IPython.display import HTML
data = xr.open_dataset('ocean-2d-sfc_hflux_coupler-1-daily-mean-ym_1962_01.nc')
fig = plt.figure(figsize=(12,6.5))
camera = Camera(fig)
for i in range(90):
    array = data.sfc_hflux_coupler.isel(time=i).sel(yt_ocean=slice(-50,-25)).sel(xt_ocean=slice(10,75))
    array.plot(vmin=-300,vmax=300,add_colorbar=False,cmap=cm.cm.curl,)
    camera.snap()
animation=camera.animate()
HTML(animation.to_html5_video())  # shows in notebook
animation.save('out.mp4')         # saves file

could come very handy.

navidcy avatar Nov 26 '20 03:11 navidcy

https://xmovie.readthedocs.io/en/latest/

navidcy avatar Jan 25 '23 20:01 navidcy

Relevant from our recent discussion @Hangyum. Let's make a new example for Hackathon # 4?

adele-morrison avatar Apr 02 '24 04:04 adele-morrison

Yes sure. As it is my first time to do a pull request in COSIMA_recipes, is there any tutorial that tells me how to do this?

Hangyum avatar Apr 04 '24 02:04 Hangyum

Relevant from our recent discussion @Hangyum. Let's make a new example for Hackathon #4?

I see where the confusion stemmed.... @adele-morrison wrote ... for Hackathon #4 meaning the 4th Hackathon that we'll be having in July. But in Github when you write a hash (#) and next to it a number, Github creates a link to the issue or PR of the repository with that number! @Hangyum clicked on that and asked their question...

navidcy avatar Apr 04 '24 13:04 navidcy

Hi all, I've created an animation script. It saves individual daily snapshots of sea surface velocity as .png files and then combines these frames into a .mp4 movie. I am not sure how I can create a pull request with a file I created from scratch.

My script is located here in my own fork of cosima_recipes.

mauricehuguenin avatar Jul 14 '24 12:07 mauricehuguenin

I can help you do that. From Tuesday/Wed?On 14 Jul 2024, at 14:03, Maurice F. Huguenin @.***> wrote: Hi all, I've created an animation script. It saves individual daily snapshots of sea surface velocity as .png files and then combines these frames into a .mp4 movie. I am not sure how I can create a pull request with a file I created from scratch. My script is located here in my own fork of cosima_recipes.

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: @.***>

navidcy avatar Jul 14 '24 13:07 navidcy

SIDE NOTE:

In no way am I making any comment on @mauricehuguenin 's excellent work here. Just wanted to point folks to streamjoy in case there is interest.

https://ahuang11.github.io/streamjoy/example_recipes/oisst_globe/

Thomas-Moore-Creative avatar Jul 15 '24 00:07 Thomas-Moore-Creative

I can help you do that. From Tuesday/Wed?

Sure, I am available tomorrow Navid - preferably after 4:30 pm (I am working in CET at the moment). Great link, thanks Thomas.

mauricehuguenin avatar Jul 15 '24 14:07 mauricehuguenin

@mauricehuguenin add me as a collaborator in your repo and I can open the PR. Or we can zoom and I can help you do it.

Your call ;)

navidcy avatar Jul 19 '24 05:07 navidcy