#!/usr/bin/env python # coding: utf-8 # In[24]: get_ipython().run_line_magic('matplotlib', 'inline') from datetime import timedelta, datetime import xarray as xr import numpy as np import matplotlib.pyplot as plt import matplotlib from matplotlib.animation import FuncAnimation import matplotlib.animation as animation from IPython.display import HTML import cartopy import cartopy.crs as ccrs from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER import matplotlib.ticker as mticker import cartopy.feature as cfeature # In[4]: get_ipython().run_line_magic('load_ext', 'autoreload') get_ipython().run_line_magic('autoreload', '2') get_ipython().run_line_magic('load_ext', 'version_information') get_ipython().run_line_magic('version_information', 'numpy, matplotlib, xarray, cartopy') # In[1]: rootdir = "/Users/Gomez023/src/git/" # In[9]: filedir = "parcels_gallery/data/" ds_subregion = xr.open_dataset(rootdir + filedir + 'Particle_AZO_grid100000p_wtides_0601_hourly_MONTH_subregion.nc') # In[10]: ds_subregion # # Simulation: # In[11]: outputdt = timedelta(hours=1) timerange = np.arange(np.nanmin(ds_subregion['time'].values), (np.datetime64('2010-06-29T00:30:00.000000000'))+np.timedelta64(outputdt), outputdt) # timerange in nanoseconds # # Just tidal: # In[27]: get_ipython().run_cell_magic('capture', '', "\nfig = plt.figure(figsize=(12, 8))#, constrained_layout=True)\n\nax1 = plt.subplot(111, projection=ccrs.PlateCarree())\n\nax1.set_xlim([-32, -18])\nax1.set_ylim([30, 40])\n\nresol = '10m' # use data at this scale\nland = cartopy.feature.NaturalEarthFeature('physical', 'land', \\\n scale=resol, edgecolor='k', facecolor=cfeature.COLORS['land'])\nocean = cartopy.feature.NaturalEarthFeature('physical', 'ocean', \\\n scale=resol, edgecolor='none', facecolor=cfeature.COLORS['water'])\n\nax1.add_feature(land, facecolor='burlywood', zorder=50) #beige\nax1.add_feature(ocean, linewidth=0.2 )\n\ngl = ax1.gridlines(crs=ccrs.PlateCarree(), draw_labels=True,\n linewidth=2, color='gray', alpha=0.5, linestyle='-')\ngl.xlabels_top = False\ngl.ylabels_right = False\ngl.xlines = False\ngl.ylines = False\ngl.xlocator = mticker.FixedLocator([-35, -30., -25., -20.])\ngl.ylocator = mticker.FixedLocator([30., 33., 36., 39.]) #np.arange(30., 42, 3)\ngl.xformatter = LONGITUDE_FORMATTER\ngl.yformatter = LATITUDE_FORMATTER\ngl.ylabel_style = {'size': 12}#, 'color': 'gray'}\ngl.xlabel_style = {'size': 12}\n\n\ntime_id = np.where(ds_subregion['time'] == timerange[0]) # Indices of the data where time = 0\n\nscatter_subregion = ax1.scatter(ds_subregion['lon'].values[time_id], ds_subregion['lat'].values[time_id], s=1, c='r', transform=ccrs.PlateCarree(), zorder=20)\n\nt = str(timerange[0]) \ntitle = plt.suptitle('Particles at t = ' + str(t[0:10]) + ' ' + str(t[11:16]), size=24)\n\ndef animate(i):\n t = str(timerange[i])\n title.set_text('Particles at t = ' + str(t[0:10]) + ' ' + str(t[11:16]))\n \n time_id = np.where(ds_subregion['time'] == timerange[i])\n scatter_subregion.set_offsets(np.c_[ds_subregion['lon'].values[time_id], ds_subregion['lat'].values[time_id]])\n\nax1.set_title('Tidal', size=20)\n\nanim = FuncAnimation(fig, animate, frames = len(timerange), interval=500)\n") # In[28]: # Set up formatting for the movie files Writer = animation.writers['ffmpeg'] writer = Writer(fps=15, metadata=dict(artist='Me'), bitrate=1800) anim.save(rootdir + 'parcels_gallery/images/anim_June_s1_TIDAL_all_subregion.mp4', writer=writer, dpi=500) # In[1]: pwd # In[ ]: