<commit_before><commit_msg>Add the code to create the homepage animation<commit_after>{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib qt\n",
    "import xarray as xr\n",
    "from matplotlib import colors\n",
    "from matplotlib.animation import FuncAnimation, writers, PillowWriter\n",
    "import matplotlib.gridspec as gridspec\n",
    "import matplotlib.pyplot as plt\n",
    "import matplotlib.image as mpimg\n",
    "import cmocean\n",
    "import cartopy.crs as ccrs\n",
    "import cartopy\n",
    "import numpy as np\n",
    "import copy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Load in particle data, define the time range at which to plot (**`plottimes`**) and select the indices of the first timestep in the variable `'b'`. Then load the OceanParcels logo."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "filename = 'medusarun.nc'\n",
    "pfile = xr.open_dataset(str(filename), decode_cf=True)\n",
    "lon = np.ma.filled(pfile.variables['lon'], np.nan)\n",
    "lat = np.ma.filled(pfile.variables['lat'], np.nan)\n",
    "time = np.ma.filled(pfile.variables['time'], np.nan)\n",
    "\n",
    "pfile.close()\n",
    "\n",
    "plottimes = np.arange(time[0,0], np.nanmax(time), np.timedelta64(10, 'D'))\n",
    "starttime = 20\n",
    "b = time == plottimes[0+starttime]\n",
    "\n",
    "img = mpimg.imread('parcelslogo.png')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The animation consists of three figures: the northern hemisphere, the southern hemisphere and the oceanparcels logo. To organize their locations we use [matplotlib.gridspec](https://matplotlib.org/tutorials/intermediate/gridspec.html). The animation spans 12 frames and updates the particle positions based on the timestep in `plottimes`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "fig = plt.figure(figsize=(20,4))\n",
    "gs = gridspec.GridSpec(ncols=60, nrows=12, figure=fig)\n",
    "\n",
    "### Northern Hemisphere\n",
    "ax1 = fig.add_subplot(gs[:, 18:30],projection=ccrs.NearsidePerspective(central_latitude=90, central_longitude=-30, satellite_height=15000000))\n",
    "ax1.set_facecolor('#190C38')\n",
    "ax1.add_feature(cartopy.feature.LAND,zorder=1)\n",
    "ax1.coastlines()\n",
    "scat1 = ax1.scatter(lon[b], lat[b], marker='.', s=25, c='maroon',edgecolor='white', linewidth=0.15, transform=ccrs.PlateCarree())\n",
    "\n",
    "### Southern Hemisphere\n",
    "ax2 = fig.add_subplot(gs[:, 30:42],projection=ccrs.NearsidePerspective(central_latitude=-90, central_longitude=-30, satellite_height=15000000))\n",
    "ax2.set_facecolor('#190C38')\n",
    "ax2.add_feature(cartopy.feature.LAND,zorder=1)\n",
    "ax2.coastlines()\n",
    "scat2 = ax2.scatter(lon[b], lat[b], marker='.', s=25, c='maroon',edgecolor='white', linewidth=0.15, transform=ccrs.PlateCarree())\n",
    "\n",
    "### OceanParcels logo\n",
    "ax3 = fig.add_subplot(gs[1:3,27:33])\n",
    "ax3.tick_params(\n",
    "    axis='both',         \n",
    "    which='both',      # both major and minor ticks are affected\n",
    "    bottom=False,      # ticks along the bottom edge are off\n",
    "    top=False,         # ticks along the top edge are off\n",
    "    labelbottom=False,\n",
    "    left=False,\n",
    "    labelleft=False) # labels along the bottom edge are off\n",
    "ax3.imshow(img)\n",
    "ax3.spines[\"left\"].set_visible(False)\n",
    "ax3.spines[\"top\"].set_visible(False)\n",
    "ax3.spines[\"right\"].set_visible(False)\n",
    "ax3.spines[\"bottom\"].set_visible(False)\n",
    "\n",
    "frames = np.arange(0, 12)\n",
    "\n",
    "def animate(t):\n",
    "    b = time == plottimes[t+start]\n",
    "    scat1.set_offsets(np.vstack((lon[b], lat[b])).transpose())\n",
    "    scat2.set_offsets(np.vstack((lon[b], lat[b])).transpose())\n",
    "    return scat1, scat2\n",
    "\n",
    "anim = animation.FuncAnimation(fig, animate, frames=frames, interval=200, blit=True)\n",
    "anim\n",
    "fig.canvas.draw()  # needed for tight_layout to work with cartopy\n",
    "plt.tight_layout()\n",
    "# writergif = PillowWriter(fps=7) \n",
    "# anim.save('Homepagegif.gif',writer=writergif)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
{'fraction_non_alphanumeric': 0.20092425155716295, 'fraction_numerical': 0.02471368294153104, 'mean_word_length': 3.3975265017667846, 'pattern_counts': {'":': 44, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5438683', 'n_tokens_mistral': 1979, 'n_tokens_neox': 1888, 'n_words': 346}