Closed joecabz1985 closed 1 year ago
Hi, can you pleasy explain more precisely what you are trying to do?
To save to mp4, you provide filename="file.mp4"
to animation method.
I am start learning python. I want to save the animation in this code. Which part should I need to modify and what exactly the code? Thank you for helping me.
"""
from datetime import timedelta import cmocean import xarray as xr from opendrift.readers import reader_netCDF_CF_generic from opendrift.models.leeway import Leeway
lw = Leeway(loglevel=20) # Set loglevel to 0 for debug information
reader_arome = reader_netCDF_CF_generic.Reader(lw.test_data_folder() + '16Nov2015_NorKyst_z_surface/arome_subset_16Nov2015.nc')
reader_norkyst = reader_netCDF_CF_generic.Reader(lw.test_data_folder() + '16Nov2015_NorKyst_z_surface/norkyst800_subset_16Nov2015.nc')
lw.add_reader(reader_norkyst, variables=['x_sea_water_velocity', 'y_sea_water_velocity']) lw.add_reader(reader_arome, variables=['x_wind', 'y_wind']) lw.set_config('environment:fallback:x_sea_water_velocity', 0) lw.set_config('environment:fallback:y_sea_water_velocity', 0)
object_type = 26 # 26 = Life-raft, no ballast lw.seed_elements(lon=4.5, lat=59.6, radius=100, number=1000, time=reader_arome.start_time, object_type=object_type)
lw.run(duration=timedelta(hours=48), time_step=900, time_step_output=3600)
print(lw)
lw.animation(background=['x_sea_water_velocity', 'y_sea_water_velocity'], skip=5, # show every 5th vector cmap=cmocean.cm.speed, vmin=0, vmax=.8, bgalpha=.7, land_color='#666666', fast=True)
lw.plot(fast=True)
d, dsub, dstr, lon, lat = lw.get_density_array(pixelsize_m=3000) strand_density = xr.DataArray(dstr[-1,:,:], coords={'lon_bin': lon[0:-1], 'lat_bin': lat[0:-1]}) lw.plot(fast=True, background=strand_density.where(strand_density>0), vmin=0, vmax=20, clabel='Density of stranded elements', show_elements=False, linewidth=0)
thank you very much. I found how to do it. thank you very much
Very good
I am new in python and opendrift. I want to save the animation of the model. I enable the image but not working. Kindly help me please. image:: /gallery/animations/example_leeway_0.gif