From e697bbf78e1b88a5b605d7f2b62548f4d9146815 Mon Sep 17 00:00:00 2001 From: Maurice Huguenin-Virchaux Date: Mon, 1 Jul 2024 10:44:52 +1000 Subject: [PATCH 1/4] adding some text to contributed example --- .../Cross-slope_section_potrho_cc.ipynb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/ContributedExamples/Cross-slope_section_potrho_cc.ipynb b/ContributedExamples/Cross-slope_section_potrho_cc.ipynb index 4e93b093..158a3479 100644 --- a/ContributedExamples/Cross-slope_section_potrho_cc.ipynb +++ b/ContributedExamples/Cross-slope_section_potrho_cc.ipynb @@ -18,7 +18,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Load modules" + "## Load modules" ] }, { @@ -27,7 +27,7 @@ "metadata": {}, "outputs": [], "source": [ - "# Standard modules\n", + "# Standard modules to query COSIMA outputs\n", "import cosima_cookbook as cc\n", "from cosima_cookbook import explore\n", "\n", @@ -5094,21 +5094,21 @@ ], "metadata": { "kernelspec": { - "display_name": "Python [conda env:analysis3-21.04]", + "display_name": "Python [conda env:analysis27-18.10]", "language": "python", - "name": "conda-env-analysis3-21.04-py" + "name": "conda-env-analysis27-18.10-py" }, "language_info": { "codemirror_mode": { "name": "ipython", - "version": 3 + "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.8.10" + "pygments_lexer": "ipython2", + "version": "2.7.15" }, "other_supplementary_files": [ "images/topographic_gradient_sketch.png" From 8e38c8ec46058587fbaea42a3428eb6a69f5df52 Mon Sep 17 00:00:00 2001 From: Maurice Huguenin-Virchaux Date: Sun, 14 Jul 2024 21:52:33 +1000 Subject: [PATCH 2/4] new cosima animation movie file --- ...h_sea_surface_velocity_ACCESS-OM2-01.ipynb | 1295 +++++++++++++++++ .../Cross-slope_section_potrho_cc.ipynb | 14 +- 2 files changed, 1308 insertions(+), 1 deletion(-) create mode 100644 ContributedExamples/Animation_with_sea_surface_velocity_ACCESS-OM2-01.ipynb diff --git a/ContributedExamples/Animation_with_sea_surface_velocity_ACCESS-OM2-01.ipynb b/ContributedExamples/Animation_with_sea_surface_velocity_ACCESS-OM2-01.ipynb new file mode 100644 index 00000000..5149f78b --- /dev/null +++ b/ContributedExamples/Animation_with_sea_surface_velocity_ACCESS-OM2-01.ipynb @@ -0,0 +1,1295 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "d47f75ba-c80f-4812-a4ab-f41707ca328e", + "metadata": {}, + "source": [ + "### Create a movie of ACCESS-OM2-01 sea surface velocities in a South Polar Stereographic projection" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "9f3b838f-c5ec-400c-9ea4-50e23f88a832", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "
\n", + "
\n", + "

Client

\n", + "

Client-ede1f2be-41d3-11ef-a98d-000007a1fe80

\n", + " \n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "\n", + "
Connection method: Cluster objectCluster type: distributed.LocalCluster
\n", + " Dashboard: /proxy/8787/status\n", + "
\n", + "\n", + " \n", + "
\n", + "

Cluster Info

\n", + "
\n", + "
\n", + "
\n", + "
\n", + "

LocalCluster

\n", + "

7bfaac33

\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "\n", + "\n", + " \n", + "
\n", + " Dashboard: /proxy/8787/status\n", + " \n", + " Workers: 16\n", + "
\n", + " Total threads: 32\n", + " \n", + " Total memory: 251.18 GiB\n", + "
Status: runningUsing processes: True
\n", + "\n", + "
\n", + " \n", + "

Scheduler Info

\n", + "
\n", + "\n", + "
\n", + "
\n", + "
\n", + "
\n", + "

Scheduler

\n", + "

Scheduler-9a4e4ced-1c35-48c1-adfb-fbcd9b1fdd4f

\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
\n", + " Comm: tcp://127.0.0.1:39477\n", + " \n", + " Workers: 16\n", + "
\n", + " Dashboard: /proxy/8787/status\n", + " \n", + " Total threads: 32\n", + "
\n", + " Started: Just now\n", + " \n", + " Total memory: 251.18 GiB\n", + "
\n", + "
\n", + "
\n", + "\n", + "
\n", + " \n", + "

Workers

\n", + "
\n", + "\n", + " \n", + "
\n", + "
\n", + "
\n", + "
\n", + " \n", + "

Worker: 0

\n", + "
\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + "
\n", + " Comm: tcp://127.0.0.1:36485\n", + " \n", + " Total threads: 2\n", + "
\n", + " Dashboard: /proxy/45099/status\n", + " \n", + " Memory: 15.70 GiB\n", + "
\n", + " Nanny: tcp://127.0.0.1:37553\n", + "
\n", + " Local directory: /jobfs/120798923.gadi-pbs/dask-worker-space/worker-q92s_4i8\n", + "
\n", + "
\n", + "
\n", + "
\n", + " \n", + "
\n", + "
\n", + "
\n", + "
\n", + " \n", + "

Worker: 1

\n", + "
\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + "
\n", + " Comm: tcp://127.0.0.1:43071\n", + " \n", + " Total threads: 2\n", + "
\n", + " Dashboard: /proxy/43249/status\n", + " \n", + " Memory: 15.70 GiB\n", + "
\n", + " Nanny: tcp://127.0.0.1:35897\n", + "
\n", + " Local directory: /jobfs/120798923.gadi-pbs/dask-worker-space/worker-t0lji0nw\n", + "
\n", + "
\n", + "
\n", + "
\n", + " \n", + "
\n", + "
\n", + "
\n", + "
\n", + " \n", + "

Worker: 2

\n", + "
\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + "
\n", + " Comm: tcp://127.0.0.1:38419\n", + " \n", + " Total threads: 2\n", + "
\n", + " Dashboard: /proxy/44523/status\n", + " \n", + " Memory: 15.70 GiB\n", + "
\n", + " Nanny: tcp://127.0.0.1:35981\n", + "
\n", + " Local directory: /jobfs/120798923.gadi-pbs/dask-worker-space/worker-i_qxnvxs\n", + "
\n", + "
\n", + "
\n", + "
\n", + " \n", + "
\n", + "
\n", + "
\n", + "
\n", + " \n", + "

Worker: 3

\n", + "
\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + "
\n", + " Comm: tcp://127.0.0.1:38197\n", + " \n", + " Total threads: 2\n", + "
\n", + " Dashboard: /proxy/43653/status\n", + " \n", + " Memory: 15.70 GiB\n", + "
\n", + " Nanny: tcp://127.0.0.1:38467\n", + "
\n", + " Local directory: /jobfs/120798923.gadi-pbs/dask-worker-space/worker-n25qdhj3\n", + "
\n", + "
\n", + "
\n", + "
\n", + " \n", + "
\n", + "
\n", + "
\n", + "
\n", + " \n", + "

Worker: 4

\n", + "
\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + "
\n", + " Comm: tcp://127.0.0.1:44987\n", + " \n", + " Total threads: 2\n", + "
\n", + " Dashboard: /proxy/36243/status\n", + " \n", + " Memory: 15.70 GiB\n", + "
\n", + " Nanny: tcp://127.0.0.1:43113\n", + "
\n", + " Local directory: /jobfs/120798923.gadi-pbs/dask-worker-space/worker-h99i7zpf\n", + "
\n", + "
\n", + "
\n", + "
\n", + " \n", + "
\n", + "
\n", + "
\n", + "
\n", + " \n", + "

Worker: 5

\n", + "
\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + "
\n", + " Comm: tcp://127.0.0.1:43849\n", + " \n", + " Total threads: 2\n", + "
\n", + " Dashboard: /proxy/42741/status\n", + " \n", + " Memory: 15.70 GiB\n", + "
\n", + " Nanny: tcp://127.0.0.1:36673\n", + "
\n", + " Local directory: /jobfs/120798923.gadi-pbs/dask-worker-space/worker-8j0f3w0t\n", + "
\n", + "
\n", + "
\n", + "
\n", + " \n", + "
\n", + "
\n", + "
\n", + "
\n", + " \n", + "

Worker: 6

\n", + "
\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + "
\n", + " Comm: tcp://127.0.0.1:34033\n", + " \n", + " Total threads: 2\n", + "
\n", + " Dashboard: /proxy/33419/status\n", + " \n", + " Memory: 15.70 GiB\n", + "
\n", + " Nanny: tcp://127.0.0.1:41225\n", + "
\n", + " Local directory: /jobfs/120798923.gadi-pbs/dask-worker-space/worker-ye1uc4g0\n", + "
\n", + "
\n", + "
\n", + "
\n", + " \n", + "
\n", + "
\n", + "
\n", + "
\n", + " \n", + "

Worker: 7

\n", + "
\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + "
\n", + " Comm: tcp://127.0.0.1:34185\n", + " \n", + " Total threads: 2\n", + "
\n", + " Dashboard: /proxy/35099/status\n", + " \n", + " Memory: 15.70 GiB\n", + "
\n", + " Nanny: tcp://127.0.0.1:37677\n", + "
\n", + " Local directory: /jobfs/120798923.gadi-pbs/dask-worker-space/worker-yofmwb3j\n", + "
\n", + "
\n", + "
\n", + "
\n", + " \n", + "
\n", + "
\n", + "
\n", + "
\n", + " \n", + "

Worker: 8

\n", + "
\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + "
\n", + " Comm: tcp://127.0.0.1:44973\n", + " \n", + " Total threads: 2\n", + "
\n", + " Dashboard: /proxy/46775/status\n", + " \n", + " Memory: 15.70 GiB\n", + "
\n", + " Nanny: tcp://127.0.0.1:45029\n", + "
\n", + " Local directory: /jobfs/120798923.gadi-pbs/dask-worker-space/worker-mzhnxu1f\n", + "
\n", + "
\n", + "
\n", + "
\n", + " \n", + "
\n", + "
\n", + "
\n", + "
\n", + " \n", + "

Worker: 9

\n", + "
\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + "
\n", + " Comm: tcp://127.0.0.1:45113\n", + " \n", + " Total threads: 2\n", + "
\n", + " Dashboard: /proxy/46335/status\n", + " \n", + " Memory: 15.70 GiB\n", + "
\n", + " Nanny: tcp://127.0.0.1:36241\n", + "
\n", + " Local directory: /jobfs/120798923.gadi-pbs/dask-worker-space/worker-000bj1_k\n", + "
\n", + "
\n", + "
\n", + "
\n", + " \n", + "
\n", + "
\n", + "
\n", + "
\n", + " \n", + "

Worker: 10

\n", + "
\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + "
\n", + " Comm: tcp://127.0.0.1:35195\n", + " \n", + " Total threads: 2\n", + "
\n", + " Dashboard: /proxy/43303/status\n", + " \n", + " Memory: 15.70 GiB\n", + "
\n", + " Nanny: tcp://127.0.0.1:46085\n", + "
\n", + " Local directory: /jobfs/120798923.gadi-pbs/dask-worker-space/worker-s0ysqtr2\n", + "
\n", + "
\n", + "
\n", + "
\n", + " \n", + "
\n", + "
\n", + "
\n", + "
\n", + " \n", + "

Worker: 11

\n", + "
\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + "
\n", + " Comm: tcp://127.0.0.1:34739\n", + " \n", + " Total threads: 2\n", + "
\n", + " Dashboard: /proxy/37453/status\n", + " \n", + " Memory: 15.70 GiB\n", + "
\n", + " Nanny: tcp://127.0.0.1:44911\n", + "
\n", + " Local directory: /jobfs/120798923.gadi-pbs/dask-worker-space/worker-6a091ynt\n", + "
\n", + "
\n", + "
\n", + "
\n", + " \n", + "
\n", + "
\n", + "
\n", + "
\n", + " \n", + "

Worker: 12

\n", + "
\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + "
\n", + " Comm: tcp://127.0.0.1:35019\n", + " \n", + " Total threads: 2\n", + "
\n", + " Dashboard: /proxy/40781/status\n", + " \n", + " Memory: 15.70 GiB\n", + "
\n", + " Nanny: tcp://127.0.0.1:34635\n", + "
\n", + " Local directory: /jobfs/120798923.gadi-pbs/dask-worker-space/worker-tv9meidt\n", + "
\n", + "
\n", + "
\n", + "
\n", + " \n", + "
\n", + "
\n", + "
\n", + "
\n", + " \n", + "

Worker: 13

\n", + "
\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + "
\n", + " Comm: tcp://127.0.0.1:37369\n", + " \n", + " Total threads: 2\n", + "
\n", + " Dashboard: /proxy/43313/status\n", + " \n", + " Memory: 15.70 GiB\n", + "
\n", + " Nanny: tcp://127.0.0.1:37041\n", + "
\n", + " Local directory: /jobfs/120798923.gadi-pbs/dask-worker-space/worker-310ov9d3\n", + "
\n", + "
\n", + "
\n", + "
\n", + " \n", + "
\n", + "
\n", + "
\n", + "
\n", + " \n", + "

Worker: 14

\n", + "
\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + "
\n", + " Comm: tcp://127.0.0.1:42769\n", + " \n", + " Total threads: 2\n", + "
\n", + " Dashboard: /proxy/34445/status\n", + " \n", + " Memory: 15.70 GiB\n", + "
\n", + " Nanny: tcp://127.0.0.1:42611\n", + "
\n", + " Local directory: /jobfs/120798923.gadi-pbs/dask-worker-space/worker-hf6o3tle\n", + "
\n", + "
\n", + "
\n", + "
\n", + " \n", + "
\n", + "
\n", + "
\n", + "
\n", + " \n", + "

Worker: 15

\n", + "
\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + "
\n", + " Comm: tcp://127.0.0.1:38785\n", + " \n", + " Total threads: 2\n", + "
\n", + " Dashboard: /proxy/40805/status\n", + " \n", + " Memory: 15.70 GiB\n", + "
\n", + " Nanny: tcp://127.0.0.1:39833\n", + "
\n", + " Local directory: /jobfs/120798923.gadi-pbs/dask-worker-space/worker-tubkqhtc\n", + "
\n", + "
\n", + "
\n", + "
\n", + " \n", + "\n", + "
\n", + "
\n", + "\n", + "
\n", + "
\n", + "
\n", + "
\n", + " \n", + "\n", + "
\n", + "
" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import xarray as xr # for working with labelled multi-dimensional arrays\n", + "import numpy as np # for numerical operations \n", + "from pathlib import Path # to check if path already exists\n", + "\n", + "import matplotlib.pyplot as plt # for matlab-like plotting \n", + "import cartopy.crs as ccrs # for maps \n", + "import cosima_cookbook as cc # for loading in data\n", + "import matplotlib.path as mpath\n", + "import time\n", + "import matplotlib.patheffects as PathEffects\n", + "from matplotlib import ticker\n", + "import cftime\n", + "import cartopy.mpl.ticker as cticker\n", + "import cartopy.feature as cfeature\n", + "from matplotlib import gridspec\n", + "import os\n", + "\n", + "import warnings; warnings.filterwarnings('ignore') # suppress warnings\n", + "\n", + "from dask.distributed import Client\n", + "client = Client(n_workers=16) \n", + "client" + ] + }, + { + "cell_type": "markdown", + "id": "0727562e-511d-46fd-acfe-746279392bb6", + "metadata": {}, + "source": [ + "### Global options to change according to user" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "id": "41e6c04d-d529-45d2-b34e-b4131dd427a5", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "/g/data/e14/mv7494/movie_frames/10m_speed_ACCESS-OM2-01/\n" + ] + } + ], + "source": [ + "# change this path to the one where you'd like to save your output files\n", + "project = 'e14'\n", + "username = 'mv7494'\n", + "frame_rate = 30 # 30 fps is a good option\n", + "resolution = 1080\n", + "movie_name='test.mp4'\n", + "\n", + "save = '/g/data/'+project+'/'+username+'/movie_frames/10m_speed_ACCESS-OM2-01/'; print(save)\n", + "Path(save).mkdir(parents=True, exist_ok=True) # create folder if it does not yet exist" + ] + }, + { + "cell_type": "markdown", + "id": "d5f2a9ac-5d17-4fb1-8f31-bd509c3940f1", + "metadata": { + "tags": [] + }, + "source": [ + "### Using the cosima cookbook to load in daily sea surface velocity maps and save them as individual figures" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "id": "41506486-1e10-4e10-add1-6f52a02aaf30", + "metadata": { + "tags": [] + }, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "Exception during reset or similar\n", + "Traceback (most recent call last):\n", + " File \"/g/data/hh5/public/apps/miniconda3/envs/analysis3-22.04/lib/python3.9/site-packages/sqlalchemy/pool/base.py\", line 697, in _finalize_fairy\n", + " fairy._reset(pool)\n", + " File \"/g/data/hh5/public/apps/miniconda3/envs/analysis3-22.04/lib/python3.9/site-packages/sqlalchemy/pool/base.py\", line 893, in _reset\n", + " pool._dialect.do_rollback(self)\n", + " File \"/g/data/hh5/public/apps/miniconda3/envs/analysis3-22.04/lib/python3.9/site-packages/sqlalchemy/engine/default.py\", line 558, in do_rollback\n", + " dbapi_connection.rollback()\n", + "sqlite3.ProgrammingError: SQLite objects created in a thread can only be used in that same thread. The object was created in thread id 22841001015104 and this is thread id 22838090901248.\n", + "Exception closing connection \n", + "Traceback (most recent call last):\n", + " File \"/g/data/hh5/public/apps/miniconda3/envs/analysis3-22.04/lib/python3.9/site-packages/sqlalchemy/pool/base.py\", line 697, in _finalize_fairy\n", + " fairy._reset(pool)\n", + " File \"/g/data/hh5/public/apps/miniconda3/envs/analysis3-22.04/lib/python3.9/site-packages/sqlalchemy/pool/base.py\", line 893, in _reset\n", + " pool._dialect.do_rollback(self)\n", + " File \"/g/data/hh5/public/apps/miniconda3/envs/analysis3-22.04/lib/python3.9/site-packages/sqlalchemy/engine/default.py\", line 558, in do_rollback\n", + " dbapi_connection.rollback()\n", + "sqlite3.ProgrammingError: SQLite objects created in a thread can only be used in that same thread. The object was created in thread id 22841001015104 and this is thread id 22838090901248.\n", + "\n", + "During handling of the above exception, another exception occurred:\n", + "\n", + "Traceback (most recent call last):\n", + " File \"/g/data/hh5/public/apps/miniconda3/envs/analysis3-22.04/lib/python3.9/site-packages/sqlalchemy/pool/base.py\", line 270, in _close_connection\n", + " self._dialect.do_close(connection)\n", + " File \"/g/data/hh5/public/apps/miniconda3/envs/analysis3-22.04/lib/python3.9/site-packages/sqlalchemy/engine/default.py\", line 564, in do_close\n", + " dbapi_connection.close()\n", + "sqlite3.ProgrammingError: SQLite objects created in a thread can only be used in that same thread. The object was created in thread id 22841001015104 and this is thread id 22838090901248.\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Frame for 2011-12-01 already done\n", + "Frame for 2011-12-02 already done\n", + "Frame for 2011-12-03 already done\n", + "Frame for 2011-12-04 already done\n", + "Frame for 2011-12-05 already done\n", + "Frame for 2011-12-06 already done\n", + "Frame for 2011-12-07 already done\n", + "Frame for 2011-12-08 already done\n", + "Frame for 2011-12-09 already done\n", + "Frame for 2011-12-10 already done\n", + "-------------------------\n", + "CPU times: user 15.4 s, sys: 2.43 s, total: 17.8 s\n", + "Wall time: 20.3 s\n" + ] + } + ], + "source": [ + "%%time\n", + "session = cc.database.create_session()\n", + "def fancy_plot(ax):\n", + " ax.gridlines(color='grey', linewidth=1, alpha=1, # dots as grid lines\n", + " xlocs=range(-180, 180, 60), # longitude grid lines\n", + " ylocs= np.linspace(-45, -90, num=4)) # latitude grid lines\n", + " # ax.coastlines(); # add coast lines\n", + " theta = np.linspace(0, 2*np.pi, 100); center, radius = [0.5, 0.5], .5\n", + " verts = np.vstack([np.sin(theta), np.cos(theta)]).T\n", + " circle = mpath.Path(verts * radius + center)\n", + " ax.set_boundary(circle, transform=ax.transAxes)\n", + " \n", + " # add labels manually\n", + " xlab = [ .99, 0, 1.01, -.01, .5, .55, .55, .55] # x-position of labels\n", + " ylab = [ .75, .75, .24, .24, -.05, .725, .85, .605] # y-position of labels\n", + " txt_lab = ['60°E', '60°W', '120°E', '120°W', '180°', '60°S', '45°S', '75°S'] # label text\n", + "\n", + " # loop through the 7 labels and surround with white space for higher visibility\n", + " for l in range(len(txt_lab)):\n", + " ax1.text(xlab[l], ylab[l], txt_lab[l], horizontalalignment='center', transform=ax1.transAxes, \n", + " fontsize=16).set_path_effects([PathEffects.withStroke(linewidth=2, foreground='w')]) \n", + " \n", + "# ----------------------------------------------------------------------------------------------------------- #\n", + "depth = [ 17] # 48.98 m depth, subsurface to avoid flickering from high-frequency surface variability #\n", + "sel_lat = [0, 940] # 81.09°S - 29.15°S #\n", + "# ----------------------------------------------------------------------------------------------------------- #\n", + "for t in range(10):#range(365): # loop through the time dimension, creating a frame for each daily output field\n", + " filename = save + '10m_speed_frame_' + str('%03d' % (t,))+'.png' # name of frame to save as .png file\n", + "\n", + " for f in range(2): # loop through the two variables, u and v to calculate the speed (speed = u^2+v^2)\n", + " variables = ['u', 'v']\n", + " field = cc.querying.getvar(expt='01deg_jra55v140_iaf', variable=variables[f], \n", + " session=session, frequency='1 daily',\n", + " attrs={'cell_methods': 'time: mean'},\n", + " start_time='2012-01-01 00:00:00', \n", + " end_time='2012-12-31 00:00:00', \n", + " chunks = {'yu_ocean': '200MB', 'xu_ocean': '200MB'})[t,depth[0],sel_lat[0]:sel_lat[1],:]\n", + " if f == 0: u = field # zonal velocity\n", + " if f == 1: v = field # meridional velocity\n", + " speed = (u * u + v * v).load() # load 2D wind speed magnitude field into memory\n", + " \n", + " if os.path.isfile(filename) == True: # skip iteration if final .png file already exists\n", + " print('Frame for '+str(speed.time)[36:46] + ' already done')\n", + " continue \n", + " \n", + " # initialise figure\n", + " fig = plt.figure(figsize=(8,8),tight_layout=True,facecolor='w',edgecolor='k')\n", + " gs = gridspec.GridSpec(1,1) \n", + " \n", + " ax1 = plt.subplot(gs[0,0], projection=ccrs.SouthPolarStereo(central_longitude=0))\n", + " ax1.set_extent([-180, 180, -90, -30], crs=ccrs.PlateCarree()) # extent of plot\n", + "\n", + " blue_marble = plt.imread('/g/data/ik11/grids/BlueMarble.tiff')\n", + " blue_marble_extent = (-180, 180, -90, 90) # extent of the land surface figure (same as above)\n", + " # Add pretty land using the COSIMA recipe: https://cosima-recipes.readthedocs.io/en/latest/DocumentedExamples/Bathymetry.html\n", + "\n", + " # ---------------------------------------------------------------------------------------------------------------- #\n", + " ax1.imshow(blue_marble, extent=blue_marble_extent, transform=ccrs.PlateCarree(), origin='upper')\n", + " p1 = speed.plot.contourf(ax=ax1,levels=np.linspace(-0,.8,21),cmap='Blues_r',\n", + " add_colorbar=False,extend='max',transform=ccrs.PlateCarree())\n", + " # use function to add info (labels, land, etc), add title with date\n", + " fancy_plot(ax1); plt.title('ACCESS-OM2-01, 50 m subsurface speed, '+str(speed.time)[36:46]+'\\n', fontsize=16)\n", + " # ---------------------------------------------------------------------------------------------------------------- #\n", + "\n", + " # add colour bar\n", + " cax = fig.add_axes([.312, 0, .4, .012]) # position: [x0, y0, width, height] centered colour bar\n", + " cb = plt.colorbar(p1, cax = cax, shrink=.5, orientation='horizontal') \n", + " cb.set_label(label='(m s$^{-1}$)', size=16) # colour bar label\n", + " cb.ax.tick_params(labelsize=16); tick_locator = ticker.MaxNLocator(nbins=5) # five ticks\n", + " cb.locator = tick_locator;cb.update_ticks()\n", + "\n", + " # --- saving as 300 dpi .PNG image in specified folder ----------------------------------------------- #\n", + " plt.savefig(filename, dpi=300, facecolor='w', edgecolor='w', orientation='landscape', format=None, #\n", + " transparent=False, bbox_inches='tight', pad_inches=0.1, metadata=None) #\n", + " # --- end of script ---------------------------------------------------------------------------------- # \n", + " print('Frame for '+str(speed.time)[36:46] + ' done')\n", + " if t != 1: plt.close(fig) # close figure if it's not the first one.\n", + "print('-------------------------') \n", + "# Wall time: 2.33 s for just the frame of the figure\n", + "# Wall time: 1min 47s for one frame" + ] + }, + { + "cell_type": "markdown", + "id": "68c8f7dd-7c5a-4483-a93e-aa5ddbc93d88", + "metadata": {}, + "source": [ + "### Creating the animation from the individually saved figures\n", + "- Warning if file already exists" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "id": "79d9d2d9-d302-4e04-aafa-25dfe4b2adc6", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "ffmpeg version 4.4.1 Copyright (c) 2000-2021 the FFmpeg developers\n", + " built with gcc 10.3.0 (GCC)\n", + " configuration: --prefix=/home/conda/feedstock_root/build_artifacts/ffmpeg_1645746662877/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_plac --cc=/home/conda/feedstock_root/build_artifacts/ffmpeg_1645746662877/_build_env/bin/x86_64-conda-linux-gnu-cc --disable-doc --disable-openssl --enable-avresample --enable-demuxer=dash --enable-gnutls --enable-gpl --enable-hardcoded-tables --enable-libfreetype --enable-libopenh264 --enable-vaapi --enable-libx264 --enable-libx265 --enable-libaom --enable-libsvtav1 --enable-libxml2 --enable-libvpx --enable-pic --enable-pthreads --enable-shared --disable-static --enable-version3 --enable-zlib --enable-libmp3lame --pkg-config=/home/conda/feedstock_root/build_artifacts/ffmpeg_1645746662877/_build_env/bin/pkg-config\n", + " libavutil 56. 70.100 / 56. 70.100\n", + " libavcodec 58.134.100 / 58.134.100\n", + " libavformat 58. 76.100 / 58. 76.100\n", + " libavdevice 58. 13.100 / 58. 13.100\n", + " libavfilter 7.110.100 / 7.110.100\n", + " libavresample 4. 0. 0 / 4. 0. 0\n", + " libswscale 5. 9.100 / 5. 9.100\n", + " libswresample 3. 9.100 / 3. 9.100\n", + " libpostproc 55. 9.100 / 55. 9.100\n", + "Input #0, image2, from '/g/data/e14/mv7494/movie_frames/10m_speed_ACCESS-OM2-01//10m_speed_frame_*.png':\n", + " Duration: 00:00:00.33, start: 0.000000, bitrate: N/A\n", + " Stream #0:0: Video: png, rgba(pc), 2377x2597 [SAR 11811:11811 DAR 2377:2597], 30 fps, 30 tbr, 30 tbn, 30 tbc\n", + "Stream mapping:\n", + " Stream #0:0 -> #0:0 (png (native) -> h264 (libx264))\n", + "Press [q] to stop, [?] for help\n", + "[libx264 @ 0x55cdcb5a0840] using SAR=1/1\n", + "[libx264 @ 0x55cdcb5a0840] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2\n", + "[libx264 @ 0x55cdcb5a0840] profile High 4:4:4 Predictive, level 3.2, 4:4:4, 8-bit\n", + "[libx264 @ 0x55cdcb5a0840] 264 - core 161 r3030M 8bd6d28 - H.264/MPEG-4 AVC codec - Copyleft 2003-2020 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=4 threads=34 lookahead_threads=5 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00\n", + "Output #0, mp4, to '/g/data/e14/mv7494/movie_frames/10m_speed_ACCESS-OM2-01/test.mp4':\n", + " Metadata:\n", + " encoder : Lavf58.76.100\n", + " Stream #0:0: Video: h264 (avc1 / 0x31637661), yuv444p(tv, progressive), 988x1080 [SAR 1:1 DAR 247:270], q=2-31, 30 fps, 15360 tbn\n", + " Metadata:\n", + " encoder : Lavc58.134.100 libx264\n", + " Side data:\n", + " cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A\n", + "frame= 1 fps=0.0 q=0.0 size= 0kB time=00:00:00.00 bitrate=N/A speed= 0x \r" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "CPU times: user 116 ms, sys: 62.4 ms, total: 179 ms\n", + "Wall time: 1.01 s\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "frame= 10 fps=0.0 q=-1.0 Lsize= 110kB time=00:00:00.23 bitrate=3860.9kbits/s speed=0.309x \n", + "video:109kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.894817%\n", + "[libx264 @ 0x55cdcb5a0840] frame I:1 Avg QP:23.37 size: 66885\n", + "[libx264 @ 0x55cdcb5a0840] frame P:4 Avg QP:26.97 size: 8733\n", + "[libx264 @ 0x55cdcb5a0840] frame B:5 Avg QP:31.23 size: 1827\n", + "[libx264 @ 0x55cdcb5a0840] consecutive B-frames: 20.0% 40.0% 0.0% 40.0%\n", + "[libx264 @ 0x55cdcb5a0840] mb I I16..4: 5.3% 60.1% 34.6%\n", + "[libx264 @ 0x55cdcb5a0840] mb P I16..4: 0.4% 0.6% 0.1% P16..4: 7.8% 6.0% 4.7% 0.0% 0.0% skip:80.4%\n", + "[libx264 @ 0x55cdcb5a0840] mb B I16..4: 0.0% 0.2% 0.0% B16..8: 7.4% 1.1% 0.4% direct: 0.9% skip:89.9% L0:22.8% L1:56.3% BI:20.9%\n", + "[libx264 @ 0x55cdcb5a0840] 8x8 transform intra:60.1% inter:49.7%\n", + "[libx264 @ 0x55cdcb5a0840] coded y,u,v intra: 31.5% 18.2% 19.6% inter: 4.2% 0.6% 1.0%\n", + "[libx264 @ 0x55cdcb5a0840] i16 v,h,dc,p: 56% 26% 19% 0%\n", + "[libx264 @ 0x55cdcb5a0840] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 58% 15% 17% 2% 2% 1% 2% 1% 2%\n", + "[libx264 @ 0x55cdcb5a0840] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 33% 19% 13% 6% 6% 5% 7% 5% 6%\n", + "[libx264 @ 0x55cdcb5a0840] Weighted P-Frames: Y:0.0% UV:0.0%\n", + "[libx264 @ 0x55cdcb5a0840] ref P L0: 79.6% 12.6% 6.1% 1.8%\n", + "[libx264 @ 0x55cdcb5a0840] ref B L0: 91.1% 7.1% 1.8%\n", + "[libx264 @ 0x55cdcb5a0840] ref B L1: 98.3% 1.7%\n", + "[libx264 @ 0x55cdcb5a0840] kb/s:2662.87\n" + ] + }, + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 40, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "%%time\n", + "from subprocess import check_call\n", + "check_call('ffmpeg -framerate '+str(frame_rate)+\n", + " ' -pattern_type glob -i \"'+\n", + " save+'/10m_speed_frame_*.png\" -vf scale=-2:'+str(resolution)+',setsar=1 '+\n", + " save+movie_name, shell=True)" + ] + }, + { + "cell_type": "markdown", + "id": "2cc69928-b7b3-4b82-a61f-abdd5a213ee0", + "metadata": {}, + "source": [ + "### Play the video\n", + "- this works when using Google Chrome\n", + "- this does not work when using Mozilla Firefox" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "id": "4c8b68ee-4999-4235-b3e3-240c4a4b033c", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "CPU times: user 0 ns, sys: 1.27 ms, total: 1.27 ms\n", + "Wall time: 964 µs\n" + ] + }, + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 41, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "%%time\n", + "from IPython.display import Video\n", + "Video(save + movie_name, embed=True, height=500)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b999adb0-6521-4ab0-9e66-53f1dc96d710", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "cb0f1b9c-b0cd-4f66-90e5-14aad52f6f4e", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "597c90b1-96d1-4a54-bd67-ad3e2bacd5df", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "12a25bdc-2f95-487b-9cc5-8feaf94a6224", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4b06cfff-43f3-400e-8868-7842091a5e19", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python [conda env:analysis3-22.04]", + "language": "python", + "name": "conda-env-analysis3-22.04-py" + }, + "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.9.13" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/ContributedExamples/Cross-slope_section_potrho_cc.ipynb b/ContributedExamples/Cross-slope_section_potrho_cc.ipynb index 158a3479..3fb7243d 100644 --- a/ContributedExamples/Cross-slope_section_potrho_cc.ipynb +++ b/ContributedExamples/Cross-slope_section_potrho_cc.ipynb @@ -25,7 +25,19 @@ "cell_type": "code", "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "ImportError", + "evalue": "No module named cosima_cookbook", + "output_type": "error", + "traceback": [ + "\u001b[0;31m\u001b[0m", + "\u001b[0;31mImportError\u001b[0mTraceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;31m# Standard modules to query COSIMA outputs\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0;32mimport\u001b[0m \u001b[0mcosima_cookbook\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mcc\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 3\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mcosima_cookbook\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mexplore\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mdask\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdistributed\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mClient\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mImportError\u001b[0m: No module named cosima_cookbook" + ] + } + ], "source": [ "# Standard modules to query COSIMA outputs\n", "import cosima_cookbook as cc\n", From d8f457eb921d08bfd09a5d54d5573d253cd26f7a Mon Sep 17 00:00:00 2001 From: Maurice Huguenin-Virchaux Date: Sun, 14 Jul 2024 22:01:24 +1000 Subject: [PATCH 3/4] comment that script also works in MS Edge --- .../Animation_with_sea_surface_velocity_ACCESS-OM2-01.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ContributedExamples/Animation_with_sea_surface_velocity_ACCESS-OM2-01.ipynb b/ContributedExamples/Animation_with_sea_surface_velocity_ACCESS-OM2-01.ipynb index 5149f78b..81e12e16 100644 --- a/ContributedExamples/Animation_with_sea_surface_velocity_ACCESS-OM2-01.ipynb +++ b/ContributedExamples/Animation_with_sea_surface_velocity_ACCESS-OM2-01.ipynb @@ -1189,7 +1189,7 @@ "metadata": {}, "source": [ "### Play the video\n", - "- this works when using Google Chrome\n", + "- this works when using Google Chrome or Microsoft Edge\n", "- this does not work when using Mozilla Firefox" ] }, From f5a45308f5e869432e33eb3ecb28b6df7171476f Mon Sep 17 00:00:00 2001 From: "Navid C. Constantinou" Date: Fri, 19 Jul 2024 22:13:58 +1000 Subject: [PATCH 4/4] add Animation tutorial --- ...h_sea_surface_velocity_ACCESS-OM2-01.ipynb | 1295 ----------------- Tutorials/Animations.ipynb | 907 ++++++++++++ 2 files changed, 907 insertions(+), 1295 deletions(-) delete mode 100644 ContributedExamples/Animation_with_sea_surface_velocity_ACCESS-OM2-01.ipynb create mode 100644 Tutorials/Animations.ipynb diff --git a/ContributedExamples/Animation_with_sea_surface_velocity_ACCESS-OM2-01.ipynb b/ContributedExamples/Animation_with_sea_surface_velocity_ACCESS-OM2-01.ipynb deleted file mode 100644 index 81e12e16..00000000 --- a/ContributedExamples/Animation_with_sea_surface_velocity_ACCESS-OM2-01.ipynb +++ /dev/null @@ -1,1295 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "d47f75ba-c80f-4812-a4ab-f41707ca328e", - "metadata": {}, - "source": [ - "### Create a movie of ACCESS-OM2-01 sea surface velocities in a South Polar Stereographic projection" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "id": "9f3b838f-c5ec-400c-9ea4-50e23f88a832", - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "
\n", - "
\n", - "

Client

\n", - "

Client-ede1f2be-41d3-11ef-a98d-000007a1fe80

\n", - " \n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "\n", - "
Connection method: Cluster objectCluster type: distributed.LocalCluster
\n", - " Dashboard: /proxy/8787/status\n", - "
\n", - "\n", - " \n", - "
\n", - "

Cluster Info

\n", - "
\n", - "
\n", - "
\n", - "
\n", - "

LocalCluster

\n", - "

7bfaac33

\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "\n", - "\n", - " \n", - "
\n", - " Dashboard: /proxy/8787/status\n", - " \n", - " Workers: 16\n", - "
\n", - " Total threads: 32\n", - " \n", - " Total memory: 251.18 GiB\n", - "
Status: runningUsing processes: True
\n", - "\n", - "
\n", - " \n", - "

Scheduler Info

\n", - "
\n", - "\n", - "
\n", - "
\n", - "
\n", - "
\n", - "

Scheduler

\n", - "

Scheduler-9a4e4ced-1c35-48c1-adfb-fbcd9b1fdd4f

\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
\n", - " Comm: tcp://127.0.0.1:39477\n", - " \n", - " Workers: 16\n", - "
\n", - " Dashboard: /proxy/8787/status\n", - " \n", - " Total threads: 32\n", - "
\n", - " Started: Just now\n", - " \n", - " Total memory: 251.18 GiB\n", - "
\n", - "
\n", - "
\n", - "\n", - "
\n", - " \n", - "

Workers

\n", - "
\n", - "\n", - " \n", - "
\n", - "
\n", - "
\n", - "
\n", - " \n", - "

Worker: 0

\n", - "
\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "\n", - " \n", - "\n", - " \n", - "\n", - "
\n", - " Comm: tcp://127.0.0.1:36485\n", - " \n", - " Total threads: 2\n", - "
\n", - " Dashboard: /proxy/45099/status\n", - " \n", - " Memory: 15.70 GiB\n", - "
\n", - " Nanny: tcp://127.0.0.1:37553\n", - "
\n", - " Local directory: /jobfs/120798923.gadi-pbs/dask-worker-space/worker-q92s_4i8\n", - "
\n", - "
\n", - "
\n", - "
\n", - " \n", - "
\n", - "
\n", - "
\n", - "
\n", - " \n", - "

Worker: 1

\n", - "
\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "\n", - " \n", - "\n", - " \n", - "\n", - "
\n", - " Comm: tcp://127.0.0.1:43071\n", - " \n", - " Total threads: 2\n", - "
\n", - " Dashboard: /proxy/43249/status\n", - " \n", - " Memory: 15.70 GiB\n", - "
\n", - " Nanny: tcp://127.0.0.1:35897\n", - "
\n", - " Local directory: /jobfs/120798923.gadi-pbs/dask-worker-space/worker-t0lji0nw\n", - "
\n", - "
\n", - "
\n", - "
\n", - " \n", - "
\n", - "
\n", - "
\n", - "
\n", - " \n", - "

Worker: 2

\n", - "
\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "\n", - " \n", - "\n", - " \n", - "\n", - "
\n", - " Comm: tcp://127.0.0.1:38419\n", - " \n", - " Total threads: 2\n", - "
\n", - " Dashboard: /proxy/44523/status\n", - " \n", - " Memory: 15.70 GiB\n", - "
\n", - " Nanny: tcp://127.0.0.1:35981\n", - "
\n", - " Local directory: /jobfs/120798923.gadi-pbs/dask-worker-space/worker-i_qxnvxs\n", - "
\n", - "
\n", - "
\n", - "
\n", - " \n", - "
\n", - "
\n", - "
\n", - "
\n", - " \n", - "

Worker: 3

\n", - "
\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "\n", - " \n", - "\n", - " \n", - "\n", - "
\n", - " Comm: tcp://127.0.0.1:38197\n", - " \n", - " Total threads: 2\n", - "
\n", - " Dashboard: /proxy/43653/status\n", - " \n", - " Memory: 15.70 GiB\n", - "
\n", - " Nanny: tcp://127.0.0.1:38467\n", - "
\n", - " Local directory: /jobfs/120798923.gadi-pbs/dask-worker-space/worker-n25qdhj3\n", - "
\n", - "
\n", - "
\n", - "
\n", - " \n", - "
\n", - "
\n", - "
\n", - "
\n", - " \n", - "

Worker: 4

\n", - "
\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "\n", - " \n", - "\n", - " \n", - "\n", - "
\n", - " Comm: tcp://127.0.0.1:44987\n", - " \n", - " Total threads: 2\n", - "
\n", - " Dashboard: /proxy/36243/status\n", - " \n", - " Memory: 15.70 GiB\n", - "
\n", - " Nanny: tcp://127.0.0.1:43113\n", - "
\n", - " Local directory: /jobfs/120798923.gadi-pbs/dask-worker-space/worker-h99i7zpf\n", - "
\n", - "
\n", - "
\n", - "
\n", - " \n", - "
\n", - "
\n", - "
\n", - "
\n", - " \n", - "

Worker: 5

\n", - "
\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "\n", - " \n", - "\n", - " \n", - "\n", - "
\n", - " Comm: tcp://127.0.0.1:43849\n", - " \n", - " Total threads: 2\n", - "
\n", - " Dashboard: /proxy/42741/status\n", - " \n", - " Memory: 15.70 GiB\n", - "
\n", - " Nanny: tcp://127.0.0.1:36673\n", - "
\n", - " Local directory: /jobfs/120798923.gadi-pbs/dask-worker-space/worker-8j0f3w0t\n", - "
\n", - "
\n", - "
\n", - "
\n", - " \n", - "
\n", - "
\n", - "
\n", - "
\n", - " \n", - "

Worker: 6

\n", - "
\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "\n", - " \n", - "\n", - " \n", - "\n", - "
\n", - " Comm: tcp://127.0.0.1:34033\n", - " \n", - " Total threads: 2\n", - "
\n", - " Dashboard: /proxy/33419/status\n", - " \n", - " Memory: 15.70 GiB\n", - "
\n", - " Nanny: tcp://127.0.0.1:41225\n", - "
\n", - " Local directory: /jobfs/120798923.gadi-pbs/dask-worker-space/worker-ye1uc4g0\n", - "
\n", - "
\n", - "
\n", - "
\n", - " \n", - "
\n", - "
\n", - "
\n", - "
\n", - " \n", - "

Worker: 7

\n", - "
\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "\n", - " \n", - "\n", - " \n", - "\n", - "
\n", - " Comm: tcp://127.0.0.1:34185\n", - " \n", - " Total threads: 2\n", - "
\n", - " Dashboard: /proxy/35099/status\n", - " \n", - " Memory: 15.70 GiB\n", - "
\n", - " Nanny: tcp://127.0.0.1:37677\n", - "
\n", - " Local directory: /jobfs/120798923.gadi-pbs/dask-worker-space/worker-yofmwb3j\n", - "
\n", - "
\n", - "
\n", - "
\n", - " \n", - "
\n", - "
\n", - "
\n", - "
\n", - " \n", - "

Worker: 8

\n", - "
\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "\n", - " \n", - "\n", - " \n", - "\n", - "
\n", - " Comm: tcp://127.0.0.1:44973\n", - " \n", - " Total threads: 2\n", - "
\n", - " Dashboard: /proxy/46775/status\n", - " \n", - " Memory: 15.70 GiB\n", - "
\n", - " Nanny: tcp://127.0.0.1:45029\n", - "
\n", - " Local directory: /jobfs/120798923.gadi-pbs/dask-worker-space/worker-mzhnxu1f\n", - "
\n", - "
\n", - "
\n", - "
\n", - " \n", - "
\n", - "
\n", - "
\n", - "
\n", - " \n", - "

Worker: 9

\n", - "
\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "\n", - " \n", - "\n", - " \n", - "\n", - "
\n", - " Comm: tcp://127.0.0.1:45113\n", - " \n", - " Total threads: 2\n", - "
\n", - " Dashboard: /proxy/46335/status\n", - " \n", - " Memory: 15.70 GiB\n", - "
\n", - " Nanny: tcp://127.0.0.1:36241\n", - "
\n", - " Local directory: /jobfs/120798923.gadi-pbs/dask-worker-space/worker-000bj1_k\n", - "
\n", - "
\n", - "
\n", - "
\n", - " \n", - "
\n", - "
\n", - "
\n", - "
\n", - " \n", - "

Worker: 10

\n", - "
\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "\n", - " \n", - "\n", - " \n", - "\n", - "
\n", - " Comm: tcp://127.0.0.1:35195\n", - " \n", - " Total threads: 2\n", - "
\n", - " Dashboard: /proxy/43303/status\n", - " \n", - " Memory: 15.70 GiB\n", - "
\n", - " Nanny: tcp://127.0.0.1:46085\n", - "
\n", - " Local directory: /jobfs/120798923.gadi-pbs/dask-worker-space/worker-s0ysqtr2\n", - "
\n", - "
\n", - "
\n", - "
\n", - " \n", - "
\n", - "
\n", - "
\n", - "
\n", - " \n", - "

Worker: 11

\n", - "
\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "\n", - " \n", - "\n", - " \n", - "\n", - "
\n", - " Comm: tcp://127.0.0.1:34739\n", - " \n", - " Total threads: 2\n", - "
\n", - " Dashboard: /proxy/37453/status\n", - " \n", - " Memory: 15.70 GiB\n", - "
\n", - " Nanny: tcp://127.0.0.1:44911\n", - "
\n", - " Local directory: /jobfs/120798923.gadi-pbs/dask-worker-space/worker-6a091ynt\n", - "
\n", - "
\n", - "
\n", - "
\n", - " \n", - "
\n", - "
\n", - "
\n", - "
\n", - " \n", - "

Worker: 12

\n", - "
\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "\n", - " \n", - "\n", - " \n", - "\n", - "
\n", - " Comm: tcp://127.0.0.1:35019\n", - " \n", - " Total threads: 2\n", - "
\n", - " Dashboard: /proxy/40781/status\n", - " \n", - " Memory: 15.70 GiB\n", - "
\n", - " Nanny: tcp://127.0.0.1:34635\n", - "
\n", - " Local directory: /jobfs/120798923.gadi-pbs/dask-worker-space/worker-tv9meidt\n", - "
\n", - "
\n", - "
\n", - "
\n", - " \n", - "
\n", - "
\n", - "
\n", - "
\n", - " \n", - "

Worker: 13

\n", - "
\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "\n", - " \n", - "\n", - " \n", - "\n", - "
\n", - " Comm: tcp://127.0.0.1:37369\n", - " \n", - " Total threads: 2\n", - "
\n", - " Dashboard: /proxy/43313/status\n", - " \n", - " Memory: 15.70 GiB\n", - "
\n", - " Nanny: tcp://127.0.0.1:37041\n", - "
\n", - " Local directory: /jobfs/120798923.gadi-pbs/dask-worker-space/worker-310ov9d3\n", - "
\n", - "
\n", - "
\n", - "
\n", - " \n", - "
\n", - "
\n", - "
\n", - "
\n", - " \n", - "

Worker: 14

\n", - "
\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "\n", - " \n", - "\n", - " \n", - "\n", - "
\n", - " Comm: tcp://127.0.0.1:42769\n", - " \n", - " Total threads: 2\n", - "
\n", - " Dashboard: /proxy/34445/status\n", - " \n", - " Memory: 15.70 GiB\n", - "
\n", - " Nanny: tcp://127.0.0.1:42611\n", - "
\n", - " Local directory: /jobfs/120798923.gadi-pbs/dask-worker-space/worker-hf6o3tle\n", - "
\n", - "
\n", - "
\n", - "
\n", - " \n", - "
\n", - "
\n", - "
\n", - "
\n", - " \n", - "

Worker: 15

\n", - "
\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "\n", - " \n", - "\n", - " \n", - "\n", - "
\n", - " Comm: tcp://127.0.0.1:38785\n", - " \n", - " Total threads: 2\n", - "
\n", - " Dashboard: /proxy/40805/status\n", - " \n", - " Memory: 15.70 GiB\n", - "
\n", - " Nanny: tcp://127.0.0.1:39833\n", - "
\n", - " Local directory: /jobfs/120798923.gadi-pbs/dask-worker-space/worker-tubkqhtc\n", - "
\n", - "
\n", - "
\n", - "
\n", - " \n", - "\n", - "
\n", - "
\n", - "\n", - "
\n", - "
\n", - "
\n", - "
\n", - " \n", - "\n", - "
\n", - "
" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 1, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "import xarray as xr # for working with labelled multi-dimensional arrays\n", - "import numpy as np # for numerical operations \n", - "from pathlib import Path # to check if path already exists\n", - "\n", - "import matplotlib.pyplot as plt # for matlab-like plotting \n", - "import cartopy.crs as ccrs # for maps \n", - "import cosima_cookbook as cc # for loading in data\n", - "import matplotlib.path as mpath\n", - "import time\n", - "import matplotlib.patheffects as PathEffects\n", - "from matplotlib import ticker\n", - "import cftime\n", - "import cartopy.mpl.ticker as cticker\n", - "import cartopy.feature as cfeature\n", - "from matplotlib import gridspec\n", - "import os\n", - "\n", - "import warnings; warnings.filterwarnings('ignore') # suppress warnings\n", - "\n", - "from dask.distributed import Client\n", - "client = Client(n_workers=16) \n", - "client" - ] - }, - { - "cell_type": "markdown", - "id": "0727562e-511d-46fd-acfe-746279392bb6", - "metadata": {}, - "source": [ - "### Global options to change according to user" - ] - }, - { - "cell_type": "code", - "execution_count": 38, - "id": "41e6c04d-d529-45d2-b34e-b4131dd427a5", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "/g/data/e14/mv7494/movie_frames/10m_speed_ACCESS-OM2-01/\n" - ] - } - ], - "source": [ - "# change this path to the one where you'd like to save your output files\n", - "project = 'e14'\n", - "username = 'mv7494'\n", - "frame_rate = 30 # 30 fps is a good option\n", - "resolution = 1080\n", - "movie_name='test.mp4'\n", - "\n", - "save = '/g/data/'+project+'/'+username+'/movie_frames/10m_speed_ACCESS-OM2-01/'; print(save)\n", - "Path(save).mkdir(parents=True, exist_ok=True) # create folder if it does not yet exist" - ] - }, - { - "cell_type": "markdown", - "id": "d5f2a9ac-5d17-4fb1-8f31-bd509c3940f1", - "metadata": { - "tags": [] - }, - "source": [ - "### Using the cosima cookbook to load in daily sea surface velocity maps and save them as individual figures" - ] - }, - { - "cell_type": "code", - "execution_count": 39, - "id": "41506486-1e10-4e10-add1-6f52a02aaf30", - "metadata": { - "tags": [] - }, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "Exception during reset or similar\n", - "Traceback (most recent call last):\n", - " File \"/g/data/hh5/public/apps/miniconda3/envs/analysis3-22.04/lib/python3.9/site-packages/sqlalchemy/pool/base.py\", line 697, in _finalize_fairy\n", - " fairy._reset(pool)\n", - " File \"/g/data/hh5/public/apps/miniconda3/envs/analysis3-22.04/lib/python3.9/site-packages/sqlalchemy/pool/base.py\", line 893, in _reset\n", - " pool._dialect.do_rollback(self)\n", - " File \"/g/data/hh5/public/apps/miniconda3/envs/analysis3-22.04/lib/python3.9/site-packages/sqlalchemy/engine/default.py\", line 558, in do_rollback\n", - " dbapi_connection.rollback()\n", - "sqlite3.ProgrammingError: SQLite objects created in a thread can only be used in that same thread. The object was created in thread id 22841001015104 and this is thread id 22838090901248.\n", - "Exception closing connection \n", - "Traceback (most recent call last):\n", - " File \"/g/data/hh5/public/apps/miniconda3/envs/analysis3-22.04/lib/python3.9/site-packages/sqlalchemy/pool/base.py\", line 697, in _finalize_fairy\n", - " fairy._reset(pool)\n", - " File \"/g/data/hh5/public/apps/miniconda3/envs/analysis3-22.04/lib/python3.9/site-packages/sqlalchemy/pool/base.py\", line 893, in _reset\n", - " pool._dialect.do_rollback(self)\n", - " File \"/g/data/hh5/public/apps/miniconda3/envs/analysis3-22.04/lib/python3.9/site-packages/sqlalchemy/engine/default.py\", line 558, in do_rollback\n", - " dbapi_connection.rollback()\n", - "sqlite3.ProgrammingError: SQLite objects created in a thread can only be used in that same thread. The object was created in thread id 22841001015104 and this is thread id 22838090901248.\n", - "\n", - "During handling of the above exception, another exception occurred:\n", - "\n", - "Traceback (most recent call last):\n", - " File \"/g/data/hh5/public/apps/miniconda3/envs/analysis3-22.04/lib/python3.9/site-packages/sqlalchemy/pool/base.py\", line 270, in _close_connection\n", - " self._dialect.do_close(connection)\n", - " File \"/g/data/hh5/public/apps/miniconda3/envs/analysis3-22.04/lib/python3.9/site-packages/sqlalchemy/engine/default.py\", line 564, in do_close\n", - " dbapi_connection.close()\n", - "sqlite3.ProgrammingError: SQLite objects created in a thread can only be used in that same thread. The object was created in thread id 22841001015104 and this is thread id 22838090901248.\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Frame for 2011-12-01 already done\n", - "Frame for 2011-12-02 already done\n", - "Frame for 2011-12-03 already done\n", - "Frame for 2011-12-04 already done\n", - "Frame for 2011-12-05 already done\n", - "Frame for 2011-12-06 already done\n", - "Frame for 2011-12-07 already done\n", - "Frame for 2011-12-08 already done\n", - "Frame for 2011-12-09 already done\n", - "Frame for 2011-12-10 already done\n", - "-------------------------\n", - "CPU times: user 15.4 s, sys: 2.43 s, total: 17.8 s\n", - "Wall time: 20.3 s\n" - ] - } - ], - "source": [ - "%%time\n", - "session = cc.database.create_session()\n", - "def fancy_plot(ax):\n", - " ax.gridlines(color='grey', linewidth=1, alpha=1, # dots as grid lines\n", - " xlocs=range(-180, 180, 60), # longitude grid lines\n", - " ylocs= np.linspace(-45, -90, num=4)) # latitude grid lines\n", - " # ax.coastlines(); # add coast lines\n", - " theta = np.linspace(0, 2*np.pi, 100); center, radius = [0.5, 0.5], .5\n", - " verts = np.vstack([np.sin(theta), np.cos(theta)]).T\n", - " circle = mpath.Path(verts * radius + center)\n", - " ax.set_boundary(circle, transform=ax.transAxes)\n", - " \n", - " # add labels manually\n", - " xlab = [ .99, 0, 1.01, -.01, .5, .55, .55, .55] # x-position of labels\n", - " ylab = [ .75, .75, .24, .24, -.05, .725, .85, .605] # y-position of labels\n", - " txt_lab = ['60°E', '60°W', '120°E', '120°W', '180°', '60°S', '45°S', '75°S'] # label text\n", - "\n", - " # loop through the 7 labels and surround with white space for higher visibility\n", - " for l in range(len(txt_lab)):\n", - " ax1.text(xlab[l], ylab[l], txt_lab[l], horizontalalignment='center', transform=ax1.transAxes, \n", - " fontsize=16).set_path_effects([PathEffects.withStroke(linewidth=2, foreground='w')]) \n", - " \n", - "# ----------------------------------------------------------------------------------------------------------- #\n", - "depth = [ 17] # 48.98 m depth, subsurface to avoid flickering from high-frequency surface variability #\n", - "sel_lat = [0, 940] # 81.09°S - 29.15°S #\n", - "# ----------------------------------------------------------------------------------------------------------- #\n", - "for t in range(10):#range(365): # loop through the time dimension, creating a frame for each daily output field\n", - " filename = save + '10m_speed_frame_' + str('%03d' % (t,))+'.png' # name of frame to save as .png file\n", - "\n", - " for f in range(2): # loop through the two variables, u and v to calculate the speed (speed = u^2+v^2)\n", - " variables = ['u', 'v']\n", - " field = cc.querying.getvar(expt='01deg_jra55v140_iaf', variable=variables[f], \n", - " session=session, frequency='1 daily',\n", - " attrs={'cell_methods': 'time: mean'},\n", - " start_time='2012-01-01 00:00:00', \n", - " end_time='2012-12-31 00:00:00', \n", - " chunks = {'yu_ocean': '200MB', 'xu_ocean': '200MB'})[t,depth[0],sel_lat[0]:sel_lat[1],:]\n", - " if f == 0: u = field # zonal velocity\n", - " if f == 1: v = field # meridional velocity\n", - " speed = (u * u + v * v).load() # load 2D wind speed magnitude field into memory\n", - " \n", - " if os.path.isfile(filename) == True: # skip iteration if final .png file already exists\n", - " print('Frame for '+str(speed.time)[36:46] + ' already done')\n", - " continue \n", - " \n", - " # initialise figure\n", - " fig = plt.figure(figsize=(8,8),tight_layout=True,facecolor='w',edgecolor='k')\n", - " gs = gridspec.GridSpec(1,1) \n", - " \n", - " ax1 = plt.subplot(gs[0,0], projection=ccrs.SouthPolarStereo(central_longitude=0))\n", - " ax1.set_extent([-180, 180, -90, -30], crs=ccrs.PlateCarree()) # extent of plot\n", - "\n", - " blue_marble = plt.imread('/g/data/ik11/grids/BlueMarble.tiff')\n", - " blue_marble_extent = (-180, 180, -90, 90) # extent of the land surface figure (same as above)\n", - " # Add pretty land using the COSIMA recipe: https://cosima-recipes.readthedocs.io/en/latest/DocumentedExamples/Bathymetry.html\n", - "\n", - " # ---------------------------------------------------------------------------------------------------------------- #\n", - " ax1.imshow(blue_marble, extent=blue_marble_extent, transform=ccrs.PlateCarree(), origin='upper')\n", - " p1 = speed.plot.contourf(ax=ax1,levels=np.linspace(-0,.8,21),cmap='Blues_r',\n", - " add_colorbar=False,extend='max',transform=ccrs.PlateCarree())\n", - " # use function to add info (labels, land, etc), add title with date\n", - " fancy_plot(ax1); plt.title('ACCESS-OM2-01, 50 m subsurface speed, '+str(speed.time)[36:46]+'\\n', fontsize=16)\n", - " # ---------------------------------------------------------------------------------------------------------------- #\n", - "\n", - " # add colour bar\n", - " cax = fig.add_axes([.312, 0, .4, .012]) # position: [x0, y0, width, height] centered colour bar\n", - " cb = plt.colorbar(p1, cax = cax, shrink=.5, orientation='horizontal') \n", - " cb.set_label(label='(m s$^{-1}$)', size=16) # colour bar label\n", - " cb.ax.tick_params(labelsize=16); tick_locator = ticker.MaxNLocator(nbins=5) # five ticks\n", - " cb.locator = tick_locator;cb.update_ticks()\n", - "\n", - " # --- saving as 300 dpi .PNG image in specified folder ----------------------------------------------- #\n", - " plt.savefig(filename, dpi=300, facecolor='w', edgecolor='w', orientation='landscape', format=None, #\n", - " transparent=False, bbox_inches='tight', pad_inches=0.1, metadata=None) #\n", - " # --- end of script ---------------------------------------------------------------------------------- # \n", - " print('Frame for '+str(speed.time)[36:46] + ' done')\n", - " if t != 1: plt.close(fig) # close figure if it's not the first one.\n", - "print('-------------------------') \n", - "# Wall time: 2.33 s for just the frame of the figure\n", - "# Wall time: 1min 47s for one frame" - ] - }, - { - "cell_type": "markdown", - "id": "68c8f7dd-7c5a-4483-a93e-aa5ddbc93d88", - "metadata": {}, - "source": [ - "### Creating the animation from the individually saved figures\n", - "- Warning if file already exists" - ] - }, - { - "cell_type": "code", - "execution_count": 40, - "id": "79d9d2d9-d302-4e04-aafa-25dfe4b2adc6", - "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "ffmpeg version 4.4.1 Copyright (c) 2000-2021 the FFmpeg developers\n", - " built with gcc 10.3.0 (GCC)\n", - " configuration: --prefix=/home/conda/feedstock_root/build_artifacts/ffmpeg_1645746662877/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_plac --cc=/home/conda/feedstock_root/build_artifacts/ffmpeg_1645746662877/_build_env/bin/x86_64-conda-linux-gnu-cc --disable-doc --disable-openssl --enable-avresample --enable-demuxer=dash --enable-gnutls --enable-gpl --enable-hardcoded-tables --enable-libfreetype --enable-libopenh264 --enable-vaapi --enable-libx264 --enable-libx265 --enable-libaom --enable-libsvtav1 --enable-libxml2 --enable-libvpx --enable-pic --enable-pthreads --enable-shared --disable-static --enable-version3 --enable-zlib --enable-libmp3lame --pkg-config=/home/conda/feedstock_root/build_artifacts/ffmpeg_1645746662877/_build_env/bin/pkg-config\n", - " libavutil 56. 70.100 / 56. 70.100\n", - " libavcodec 58.134.100 / 58.134.100\n", - " libavformat 58. 76.100 / 58. 76.100\n", - " libavdevice 58. 13.100 / 58. 13.100\n", - " libavfilter 7.110.100 / 7.110.100\n", - " libavresample 4. 0. 0 / 4. 0. 0\n", - " libswscale 5. 9.100 / 5. 9.100\n", - " libswresample 3. 9.100 / 3. 9.100\n", - " libpostproc 55. 9.100 / 55. 9.100\n", - "Input #0, image2, from '/g/data/e14/mv7494/movie_frames/10m_speed_ACCESS-OM2-01//10m_speed_frame_*.png':\n", - " Duration: 00:00:00.33, start: 0.000000, bitrate: N/A\n", - " Stream #0:0: Video: png, rgba(pc), 2377x2597 [SAR 11811:11811 DAR 2377:2597], 30 fps, 30 tbr, 30 tbn, 30 tbc\n", - "Stream mapping:\n", - " Stream #0:0 -> #0:0 (png (native) -> h264 (libx264))\n", - "Press [q] to stop, [?] for help\n", - "[libx264 @ 0x55cdcb5a0840] using SAR=1/1\n", - "[libx264 @ 0x55cdcb5a0840] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2\n", - "[libx264 @ 0x55cdcb5a0840] profile High 4:4:4 Predictive, level 3.2, 4:4:4, 8-bit\n", - "[libx264 @ 0x55cdcb5a0840] 264 - core 161 r3030M 8bd6d28 - H.264/MPEG-4 AVC codec - Copyleft 2003-2020 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=4 threads=34 lookahead_threads=5 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00\n", - "Output #0, mp4, to '/g/data/e14/mv7494/movie_frames/10m_speed_ACCESS-OM2-01/test.mp4':\n", - " Metadata:\n", - " encoder : Lavf58.76.100\n", - " Stream #0:0: Video: h264 (avc1 / 0x31637661), yuv444p(tv, progressive), 988x1080 [SAR 1:1 DAR 247:270], q=2-31, 30 fps, 15360 tbn\n", - " Metadata:\n", - " encoder : Lavc58.134.100 libx264\n", - " Side data:\n", - " cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A\n", - "frame= 1 fps=0.0 q=0.0 size= 0kB time=00:00:00.00 bitrate=N/A speed= 0x \r" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "CPU times: user 116 ms, sys: 62.4 ms, total: 179 ms\n", - "Wall time: 1.01 s\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "frame= 10 fps=0.0 q=-1.0 Lsize= 110kB time=00:00:00.23 bitrate=3860.9kbits/s speed=0.309x \n", - "video:109kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.894817%\n", - "[libx264 @ 0x55cdcb5a0840] frame I:1 Avg QP:23.37 size: 66885\n", - "[libx264 @ 0x55cdcb5a0840] frame P:4 Avg QP:26.97 size: 8733\n", - "[libx264 @ 0x55cdcb5a0840] frame B:5 Avg QP:31.23 size: 1827\n", - "[libx264 @ 0x55cdcb5a0840] consecutive B-frames: 20.0% 40.0% 0.0% 40.0%\n", - "[libx264 @ 0x55cdcb5a0840] mb I I16..4: 5.3% 60.1% 34.6%\n", - "[libx264 @ 0x55cdcb5a0840] mb P I16..4: 0.4% 0.6% 0.1% P16..4: 7.8% 6.0% 4.7% 0.0% 0.0% skip:80.4%\n", - "[libx264 @ 0x55cdcb5a0840] mb B I16..4: 0.0% 0.2% 0.0% B16..8: 7.4% 1.1% 0.4% direct: 0.9% skip:89.9% L0:22.8% L1:56.3% BI:20.9%\n", - "[libx264 @ 0x55cdcb5a0840] 8x8 transform intra:60.1% inter:49.7%\n", - "[libx264 @ 0x55cdcb5a0840] coded y,u,v intra: 31.5% 18.2% 19.6% inter: 4.2% 0.6% 1.0%\n", - "[libx264 @ 0x55cdcb5a0840] i16 v,h,dc,p: 56% 26% 19% 0%\n", - "[libx264 @ 0x55cdcb5a0840] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 58% 15% 17% 2% 2% 1% 2% 1% 2%\n", - "[libx264 @ 0x55cdcb5a0840] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 33% 19% 13% 6% 6% 5% 7% 5% 6%\n", - "[libx264 @ 0x55cdcb5a0840] Weighted P-Frames: Y:0.0% UV:0.0%\n", - "[libx264 @ 0x55cdcb5a0840] ref P L0: 79.6% 12.6% 6.1% 1.8%\n", - "[libx264 @ 0x55cdcb5a0840] ref B L0: 91.1% 7.1% 1.8%\n", - "[libx264 @ 0x55cdcb5a0840] ref B L1: 98.3% 1.7%\n", - "[libx264 @ 0x55cdcb5a0840] kb/s:2662.87\n" - ] - }, - { - "data": { - "text/plain": [ - "0" - ] - }, - "execution_count": 40, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "%%time\n", - "from subprocess import check_call\n", - "check_call('ffmpeg -framerate '+str(frame_rate)+\n", - " ' -pattern_type glob -i \"'+\n", - " save+'/10m_speed_frame_*.png\" -vf scale=-2:'+str(resolution)+',setsar=1 '+\n", - " save+movie_name, shell=True)" - ] - }, - { - "cell_type": "markdown", - "id": "2cc69928-b7b3-4b82-a61f-abdd5a213ee0", - "metadata": {}, - "source": [ - "### Play the video\n", - "- this works when using Google Chrome or Microsoft Edge\n", - "- this does not work when using Mozilla Firefox" - ] - }, - { - "cell_type": "code", - "execution_count": 41, - "id": "4c8b68ee-4999-4235-b3e3-240c4a4b033c", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "CPU times: user 0 ns, sys: 1.27 ms, total: 1.27 ms\n", - "Wall time: 964 µs\n" - ] - }, - { - "data": { - "text/html": [ - "" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 41, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "%%time\n", - "from IPython.display import Video\n", - "Video(save + movie_name, embed=True, height=500)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "b999adb0-6521-4ab0-9e66-53f1dc96d710", - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "cb0f1b9c-b0cd-4f66-90e5-14aad52f6f4e", - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "597c90b1-96d1-4a54-bd67-ad3e2bacd5df", - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "12a25bdc-2f95-487b-9cc5-8feaf94a6224", - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "4b06cfff-43f3-400e-8868-7842091a5e19", - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python [conda env:analysis3-22.04]", - "language": "python", - "name": "conda-env-analysis3-22.04-py" - }, - "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.9.13" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/Tutorials/Animations.ipynb b/Tutorials/Animations.ipynb new file mode 100644 index 00000000..a6455d88 --- /dev/null +++ b/Tutorials/Animations.ipynb @@ -0,0 +1,907 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "d47f75ba-c80f-4812-a4ab-f41707ca328e", + "metadata": {}, + "source": [ + "# A movie of sea-surface velocities with cartopy" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "9f3b838f-c5ec-400c-9ea4-50e23f88a832", + "metadata": {}, + "outputs": [], + "source": [ + "import xarray as xr\n", + "import numpy as np\n", + "import time\n", + "import cftime\n", + "import matplotlib.pyplot as plt\n", + "import cosima_cookbook as cc\n", + "import matplotlib.path as mpath\n", + "import matplotlib.patheffects as PathEffects\n", + "from matplotlib import ticker\n", + "import cartopy.crs as ccrs\n", + "import cartopy.mpl.ticker as cticker\n", + "import cartopy.feature as cfeature\n", + "from matplotlib import gridspec\n", + "import os\n", + "from pathlib import Path\n", + "\n", + "import warnings\n", + "warnings.filterwarnings('ignore') # suppress warnings\n", + "\n", + "from dask.distributed import Client" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "9473b31e-8259-4eef-8033-1ed1def44c3c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "
\n", + "
\n", + "

Client

\n", + "

Client-38c58fab-45c8-11ef-82e1-00000083fe80

\n", + " \n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "\n", + "
Connection method: Cluster objectCluster type: distributed.LocalCluster
\n", + " Dashboard: /proxy/8787/status\n", + "
\n", + "\n", + " \n", + " \n", + " \n", + "\n", + " \n", + "
\n", + "

Cluster Info

\n", + "
\n", + "
\n", + "
\n", + "
\n", + "

LocalCluster

\n", + "

5813c2ae

\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "\n", + "\n", + " \n", + "
\n", + " Dashboard: /proxy/8787/status\n", + " \n", + " Workers: 8\n", + "
\n", + " Total threads: 48\n", + " \n", + " Total memory: 188.55 GiB\n", + "
Status: runningUsing processes: True
\n", + "\n", + "
\n", + " \n", + "

Scheduler Info

\n", + "
\n", + "\n", + "
\n", + "
\n", + "
\n", + "
\n", + "

Scheduler

\n", + "

Scheduler-035a4d8a-bf78-4dd8-a743-62fd9e644576

\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
\n", + " Comm: tcp://127.0.0.1:34441\n", + " \n", + " Workers: 8\n", + "
\n", + " Dashboard: /proxy/8787/status\n", + " \n", + " Total threads: 48\n", + "
\n", + " Started: Just now\n", + " \n", + " Total memory: 188.55 GiB\n", + "
\n", + "
\n", + "
\n", + "\n", + "
\n", + " \n", + "

Workers

\n", + "
\n", + "\n", + " \n", + "
\n", + "
\n", + "
\n", + "
\n", + " \n", + "

Worker: 0

\n", + "
\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + "
\n", + " Comm: tcp://127.0.0.1:36601\n", + " \n", + " Total threads: 6\n", + "
\n", + " Dashboard: /proxy/36835/status\n", + " \n", + " Memory: 23.57 GiB\n", + "
\n", + " Nanny: tcp://127.0.0.1:34765\n", + "
\n", + " Local directory: /jobfs/121310839.gadi-pbs/dask-scratch-space/worker-wwnfn3z2\n", + "
\n", + "
\n", + "
\n", + "
\n", + " \n", + "
\n", + "
\n", + "
\n", + "
\n", + " \n", + "

Worker: 1

\n", + "
\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + "
\n", + " Comm: tcp://127.0.0.1:35045\n", + " \n", + " Total threads: 6\n", + "
\n", + " Dashboard: /proxy/45971/status\n", + " \n", + " Memory: 23.57 GiB\n", + "
\n", + " Nanny: tcp://127.0.0.1:45999\n", + "
\n", + " Local directory: /jobfs/121310839.gadi-pbs/dask-scratch-space/worker-9__gcziw\n", + "
\n", + "
\n", + "
\n", + "
\n", + " \n", + "
\n", + "
\n", + "
\n", + "
\n", + " \n", + "

Worker: 2

\n", + "
\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + "
\n", + " Comm: tcp://127.0.0.1:41979\n", + " \n", + " Total threads: 6\n", + "
\n", + " Dashboard: /proxy/39153/status\n", + " \n", + " Memory: 23.57 GiB\n", + "
\n", + " Nanny: tcp://127.0.0.1:35065\n", + "
\n", + " Local directory: /jobfs/121310839.gadi-pbs/dask-scratch-space/worker-b9pjk2w7\n", + "
\n", + "
\n", + "
\n", + "
\n", + " \n", + "
\n", + "
\n", + "
\n", + "
\n", + " \n", + "

Worker: 3

\n", + "
\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + "
\n", + " Comm: tcp://127.0.0.1:41471\n", + " \n", + " Total threads: 6\n", + "
\n", + " Dashboard: /proxy/36033/status\n", + " \n", + " Memory: 23.57 GiB\n", + "
\n", + " Nanny: tcp://127.0.0.1:43831\n", + "
\n", + " Local directory: /jobfs/121310839.gadi-pbs/dask-scratch-space/worker-qd67sjlj\n", + "
\n", + "
\n", + "
\n", + "
\n", + " \n", + "
\n", + "
\n", + "
\n", + "
\n", + " \n", + "

Worker: 4

\n", + "
\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + "
\n", + " Comm: tcp://127.0.0.1:35635\n", + " \n", + " Total threads: 6\n", + "
\n", + " Dashboard: /proxy/41647/status\n", + " \n", + " Memory: 23.57 GiB\n", + "
\n", + " Nanny: tcp://127.0.0.1:42801\n", + "
\n", + " Local directory: /jobfs/121310839.gadi-pbs/dask-scratch-space/worker-b4fuyv7r\n", + "
\n", + "
\n", + "
\n", + "
\n", + " \n", + "
\n", + "
\n", + "
\n", + "
\n", + " \n", + "

Worker: 5

\n", + "
\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + "
\n", + " Comm: tcp://127.0.0.1:37721\n", + " \n", + " Total threads: 6\n", + "
\n", + " Dashboard: /proxy/43921/status\n", + " \n", + " Memory: 23.57 GiB\n", + "
\n", + " Nanny: tcp://127.0.0.1:34647\n", + "
\n", + " Local directory: /jobfs/121310839.gadi-pbs/dask-scratch-space/worker-e1w35_lv\n", + "
\n", + "
\n", + "
\n", + "
\n", + " \n", + "
\n", + "
\n", + "
\n", + "
\n", + " \n", + "

Worker: 6

\n", + "
\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + "
\n", + " Comm: tcp://127.0.0.1:39793\n", + " \n", + " Total threads: 6\n", + "
\n", + " Dashboard: /proxy/38245/status\n", + " \n", + " Memory: 23.57 GiB\n", + "
\n", + " Nanny: tcp://127.0.0.1:34165\n", + "
\n", + " Local directory: /jobfs/121310839.gadi-pbs/dask-scratch-space/worker-zcrr4pq2\n", + "
\n", + "
\n", + "
\n", + "
\n", + " \n", + "
\n", + "
\n", + "
\n", + "
\n", + " \n", + "

Worker: 7

\n", + "
\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "\n", + " \n", + "\n", + " \n", + "\n", + "
\n", + " Comm: tcp://127.0.0.1:38549\n", + " \n", + " Total threads: 6\n", + "
\n", + " Dashboard: /proxy/41669/status\n", + " \n", + " Memory: 23.57 GiB\n", + "
\n", + " Nanny: tcp://127.0.0.1:37635\n", + "
\n", + " Local directory: /jobfs/121310839.gadi-pbs/dask-scratch-space/worker-5bzo6_ym\n", + "
\n", + "
\n", + "
\n", + "
\n", + " \n", + "\n", + "
\n", + "
\n", + "\n", + "
\n", + "
\n", + "
\n", + "
\n", + " \n", + "\n", + "
\n", + "
" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-07-19 22:13:02,960 - distributed.scheduler - ERROR - Task 'getattr-519bb2b8-96ea-4c1d-a278-70058e201647' has 81.47 GiB worth of input dependencies, but worker tcp://127.0.0.1:41471 has memory_limit set to 23.57 GiB.\n", + "2024-07-19 22:13:02,962 - distributed.scheduler - ERROR - Task '_preprocess-37faa17d-ec1d-457d-9d1c-9d03422df321' has 81.47 GiB worth of input dependencies, but worker tcp://127.0.0.1:41471 has memory_limit set to 23.57 GiB.\n" + ] + } + ], + "source": [ + "client = Client() \n", + "client" + ] + }, + { + "cell_type": "markdown", + "id": "0727562e-511d-46fd-acfe-746279392bb6", + "metadata": {}, + "source": [ + "### Some options for the animation" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "41e6c04d-d529-45d2-b34e-b4131dd427a5", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "movie frames will be saved in: ./movie_frames/\n" + ] + } + ], + "source": [ + "frame_rate = 30 # frames-per-second\n", + "resolution = 1080\n", + "\n", + "movie_name = 'test.mp4'\n", + "\n", + "frame_directory = './movie_frames/'\n", + "print(\"movie frames will be saved in:\", frame_directory)" + ] + }, + { + "cell_type": "markdown", + "id": "6c307687-7985-478a-97e7-e5020c42a043", + "metadata": {}, + "source": [ + "If the directory to save movie frames doesn't exist we create it." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "3dec6754-69f3-45c7-87db-c46330a3b859", + "metadata": {}, + "outputs": [], + "source": [ + "Path(frame_directory).mkdir(parents=True, exist_ok=True)" + ] + }, + { + "cell_type": "markdown", + "id": "d5f2a9ac-5d17-4fb1-8f31-bd509c3940f1", + "metadata": { + "tags": [] + }, + "source": [ + "### Load in daily sea-surface velocity and save them as individual figures" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "41506486-1e10-4e10-add1-6f52a02aaf30", + "metadata": { + "tags": [] + }, + "outputs": [ + { + "ename": "MemoryError", + "evalue": "Task '_preprocess-37faa17d-ec1d-457d-9d1c-9d03422df321' has 81.47 GiB worth of input dependencies, but worker tcp://127.0.0.1:41471 has memory_limit set to 23.57 GiB.", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mMemoryError\u001b[0m Traceback (most recent call last)", + "File \u001b[0;32m:32\u001b[0m\n", + "File \u001b[0;32m/g/data/hh5/public/apps/miniconda3/envs/analysis3-24.04/lib/python3.10/site-packages/cosima_cookbook/querying.py:368\u001b[0m, in \u001b[0;36mgetvar\u001b[0;34m(expt, variable, session, ncfile, start_time, end_time, n, frequency, attrs, attrs_unique, return_dataset, **kwargs)\u001b[0m\n\u001b[1;32m 364\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m d[variables]\n\u001b[1;32m 366\u001b[0m ncfiles \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mlist\u001b[39m(\u001b[38;5;28mstr\u001b[39m(f\u001b[38;5;241m.\u001b[39mNCFile\u001b[38;5;241m.\u001b[39mncfile_path) \u001b[38;5;28;01mfor\u001b[39;00m f \u001b[38;5;129;01min\u001b[39;00m ncfiles)\n\u001b[0;32m--> 368\u001b[0m ds \u001b[38;5;241m=\u001b[39m \u001b[43mxr\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mopen_mfdataset\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 369\u001b[0m \u001b[43m \u001b[49m\u001b[43mncfiles\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 370\u001b[0m \u001b[43m \u001b[49m\u001b[43mparallel\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[1;32m 371\u001b[0m \u001b[43m \u001b[49m\u001b[43mcombine\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mby_coords\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 372\u001b[0m \u001b[43m \u001b[49m\u001b[43mpreprocess\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m_preprocess\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 373\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mxr_kwargs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 374\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 376\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m return_dataset:\n\u001b[1;32m 377\u001b[0m da \u001b[38;5;241m=\u001b[39m ds\n", + "File \u001b[0;32m/g/data/hh5/public/apps/miniconda3/envs/analysis3-24.04/lib/python3.10/site-packages/xarray/backends/api.py:1062\u001b[0m, in \u001b[0;36mopen_mfdataset\u001b[0;34m(paths, chunks, concat_dim, compat, preprocess, engine, data_vars, coords, combine, parallel, join, attrs_file, combine_attrs, **kwargs)\u001b[0m\n\u001b[1;32m 1057\u001b[0m datasets \u001b[38;5;241m=\u001b[39m [preprocess(ds) \u001b[38;5;28;01mfor\u001b[39;00m ds \u001b[38;5;129;01min\u001b[39;00m datasets]\n\u001b[1;32m 1059\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m parallel:\n\u001b[1;32m 1060\u001b[0m \u001b[38;5;66;03m# calling compute here will return the datasets/file_objs lists,\u001b[39;00m\n\u001b[1;32m 1061\u001b[0m \u001b[38;5;66;03m# the underlying datasets will still be stored as dask arrays\u001b[39;00m\n\u001b[0;32m-> 1062\u001b[0m datasets, closers \u001b[38;5;241m=\u001b[39m \u001b[43mdask\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcompute\u001b[49m\u001b[43m(\u001b[49m\u001b[43mdatasets\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mclosers\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 1064\u001b[0m \u001b[38;5;66;03m# Combine all datasets, closing them in case of a ValueError\u001b[39;00m\n\u001b[1;32m 1065\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n", + "File \u001b[0;32m/g/data/hh5/public/apps/miniconda3/envs/analysis3-24.04/lib/python3.10/site-packages/dask/base.py:662\u001b[0m, in \u001b[0;36mcompute\u001b[0;34m(traverse, optimize_graph, scheduler, get, *args, **kwargs)\u001b[0m\n\u001b[1;32m 659\u001b[0m postcomputes\u001b[38;5;241m.\u001b[39mappend(x\u001b[38;5;241m.\u001b[39m__dask_postcompute__())\n\u001b[1;32m 661\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m shorten_traceback():\n\u001b[0;32m--> 662\u001b[0m results \u001b[38;5;241m=\u001b[39m \u001b[43mschedule\u001b[49m\u001b[43m(\u001b[49m\u001b[43mdsk\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mkeys\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 664\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m repack([f(r, \u001b[38;5;241m*\u001b[39ma) \u001b[38;5;28;01mfor\u001b[39;00m r, (f, a) \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mzip\u001b[39m(results, postcomputes)])\n", + "File \u001b[0;32m/g/data/hh5/public/apps/miniconda3/envs/analysis3-24.04/lib/python3.10/site-packages/distributed/client.py:2234\u001b[0m, in \u001b[0;36mClient._gather\u001b[0;34m(self, futures, errors, direct, local_worker)\u001b[0m\n\u001b[1;32m 2232\u001b[0m exc \u001b[38;5;241m=\u001b[39m CancelledError(key)\n\u001b[1;32m 2233\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m-> 2234\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m exception\u001b[38;5;241m.\u001b[39mwith_traceback(traceback)\n\u001b[1;32m 2235\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m exc\n\u001b[1;32m 2236\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m errors \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mskip\u001b[39m\u001b[38;5;124m\"\u001b[39m:\n", + "\u001b[0;31mMemoryError\u001b[0m: Task '_preprocess-37faa17d-ec1d-457d-9d1c-9d03422df321' has 81.47 GiB worth of input dependencies, but worker tcp://127.0.0.1:41471 has memory_limit set to 23.57 GiB." + ] + } + ], + "source": [ + "%%time\n", + "\n", + "session = cc.database.create_session()\n", + "\n", + "def fancy_plot(ax):\n", + " ax.gridlines(color='grey', linewidth=1, alpha=1, # dots as grid lines\n", + " xlocs=range(-180, 180, 60), # longitude grid lines\n", + " ylocs= np.linspace(-45, -90, num=4)) # latitude grid lines\n", + " # ax.coastlines(); # add coast lines\n", + " theta = np.linspace(0, 2*np.pi, 100); center, radius = [0.5, 0.5], .5\n", + " verts = np.vstack([np.sin(theta), np.cos(theta)]).T\n", + " circle = mpath.Path(verts * radius + center)\n", + " ax.set_boundary(circle, transform=ax.transAxes)\n", + " \n", + " # add labels manually\n", + " xlab = [ .99, 0, 1.01, -.01, .5, .55, .55, .55] # x-position of labels\n", + " ylab = [ .75, .75, .24, .24, -.05, .725, .85, .605] # y-position of labels\n", + " txt_lab = ['60°E', '60°W', '120°E', '120°W', '180°', '60°S', '45°S', '75°S'] # label text\n", + "\n", + " # loop through the 7 labels and surround with white space for higher visibility\n", + " for l in range(len(txt_lab)):\n", + " ax1.text(xlab[l], ylab[l], txt_lab[l], horizontalalignment='center', transform=ax1.transAxes, \n", + " fontsize=16).set_path_effects([PathEffects.withStroke(linewidth=2, foreground='w')]) \n", + " \n", + "# ----------------------------------------------------------------------------------------------------------- #\n", + "depth = [ 17] # 48.98 m depth, subsurface to avoid flickering from high-frequency surface variability #\n", + "sel_lat = [0, 940] # 81.09°S - 29.15°S #\n", + "# ----------------------------------------------------------------------------------------------------------- #\n", + "for t in range(10):#range(365): # loop through the time dimension, creating a frame for each daily output field\n", + " filename = frame_directory + '10m_speed_frame_' + str('%03d' % (t,))+'.png' # name of frame to save as .png file\n", + "\n", + " for f in range(2): # loop through the two variables, u and v to calculate the speed (speed = u^2+v^2)\n", + " variables = ['u', 'v']\n", + " field = cc.querying.getvar(expt='01deg_jra55v140_iaf', variable=variables[f], \n", + " session=session, frequency='1 daily',\n", + " attrs={'cell_methods': 'time: mean'},\n", + " start_time='2012-01-01 00:00:00', \n", + " end_time='2012-12-31 00:00:00', \n", + " chunks = {'yu_ocean': '200MB', 'xu_ocean': '200MB'})[t, depth[0], sel_lat[0]:sel_lat[1], :]\n", + "\n", + " if f == 0: u = field # zonal velocity\n", + " if f == 1: v = field # meridional velocity\n", + "\n", + " speed = (u**2 + v**2).load() # load 2D wind speed magnitude field into memory\n", + " \n", + " if os.path.isfile(filename) == True: # skip iteration if final .png file already exists\n", + " print('Frame for '+str(speed.time)[36:46] + ' already done')\n", + " continue\n", + "\n", + " # initialise figure\n", + " fig = plt.figure(figsize=(8, 8), tight_layout=True, facecolor='w', edgecolor='k')\n", + " gs = gridspec.GridSpec(1, 1)\n", + "\n", + " ax1 = plt.subplot(gs[0, 0], projection=ccrs.SouthPolarStereo(central_longitude=0))\n", + " ax1.set_extent([-180, 180, -90, -30], crs=ccrs.PlateCarree()) # extent of plot\n", + "\n", + " blue_marble = plt.imread('/g/data/ik11/grids/BlueMarble.tiff')\n", + " blue_marble_extent = (-180, 180, -90, 90) # extent of the land surface figure (same as above)\n", + " \n", + " # Add pretty land using the COSIMA recipe: https://cosima-recipes.readthedocs.io/en/latest/DocumentedExamples/Bathymetry.html\n", + "\n", + " # ---------------------------------------------------------------------------------------------------------------- #\n", + " ax1.imshow(blue_marble, extent=blue_marble_extent, transform=ccrs.PlateCarree(), origin='upper')\n", + " p1 = speed.plot.contourf(ax=ax1, levels=np.linspace(-0, 0.8, 21), cmap='Blues_r',\n", + " add_colorbar=False, extend='max', transform=ccrs.PlateCarree())\n", + "\n", + " # use function to add info (labels, land, etc), add title with date\n", + " fancy_plot(ax1); plt.title('ACCESS-OM2-01, 50 m subsurface speed, ' + str(speed.time)[36:46]+'\\n', fontsize=16)\n", + " # ---------------------------------------------------------------------------------------------------------------- #\n", + "\n", + " # add colorbar\n", + " cax = fig.add_axes([0.312, 0, 0.4, 0.012]) # position: [x0, y0, width, height] centered colour bar\n", + " cb = plt.colorbar(p1, cax = cax, shrink=.5, orientation='horizontal') \n", + " cb.set_label(label='(m s$^{-1}$)', size=16) # colour bar label\n", + " cb.ax.tick_params(labelsize=16)\n", + " tick_locator = ticker.MaxNLocator(nbins=5) # five ticks\n", + " cb.locator = tick_locator\n", + " cb.update_ticks()\n", + "\n", + " # --- saving as 300 dpi .PNG image in specified folder ----------------------------------------------- #\n", + " plt.savefig(filename, dpi=300, facecolor='w', edgecolor='w', orientation='landscape', format=None, #\n", + " transparent=False, bbox_inches='tight', pad_inches=0.1, metadata=None) #\n", + " # --- end of script ---------------------------------------------------------------------------------- # \n", + " print('Frame for '+str(speed.time)[36:46] + ' done')\n", + " if t != 1: plt.close(fig) # close figure if it's not the first one.\n", + "print('-------------------------') \n", + "# Wall time: 2.33 s for just the frame of the figure\n", + "# Wall time: 1min 47s for one frame" + ] + }, + { + "cell_type": "markdown", + "id": "68c8f7dd-7c5a-4483-a93e-aa5ddbc93d88", + "metadata": {}, + "source": [ + "### Creat animation from the individually saved frames\n", + "- Warning if file already exists" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "79d9d2d9-d302-4e04-aafa-25dfe4b2adc6", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "ffmpeg version 6.1.1 Copyright (c) 2000-2023 the FFmpeg developers\n", + " built with gcc 12.3.0 (conda-forge gcc 12.3.0-7)\n", + " configuration: --prefix=/home/conda/feedstock_root/build_artifacts/ffmpeg_1716145014501/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_plac --cc=/home/conda/feedstock_root/build_artifacts/ffmpeg_1716145014501/_build_env/bin/x86_64-conda-linux-gnu-cc --cxx=/home/conda/feedstock_root/build_artifacts/ffmpeg_1716145014501/_build_env/bin/x86_64-conda-linux-gnu-c++ --nm=/home/conda/feedstock_root/build_artifacts/ffmpeg_1716145014501/_build_env/bin/x86_64-conda-linux-gnu-nm --ar=/home/conda/feedstock_root/build_artifacts/ffmpeg_1716145014501/_build_env/bin/x86_64-conda-linux-gnu-ar --disable-doc --disable-openssl --enable-demuxer=dash --enable-hardcoded-tables --enable-libfreetype --enable-libharfbuzz --enable-libfontconfig --enable-libopenh264 --enable-libdav1d --enable-gnutls --enable-libmp3lame --enable-libvpx --enable-libass --enable-pthreads --enable-vaapi --enable-libopenvino --enable-gpl --enable-libx264 --enable-libx265 --enable-libaom --enable-libsvtav1 --enable-libxml2 --enable-pic --enable-shared --disable-static --enable-version3 --enable-zlib --enable-libopus --pkg-config=/home/conda/feedstock_root/build_artifacts/ffmpeg_1716145014501/_build_env/bin/pkg-config\n", + " libavutil 58. 29.100 / 58. 29.100\n", + " libavcodec 60. 31.102 / 60. 31.102\n", + " libavformat 60. 16.100 / 60. 16.100\n", + " libavdevice 60. 3.100 / 60. 3.100\n", + " libavfilter 9. 12.100 / 9. 12.100\n", + " libswscale 7. 5.100 / 7. 5.100\n", + " libswresample 4. 12.100 / 4. 12.100\n", + " libpostproc 57. 3.100 / 57. 3.100\n", + "[image2 @ 0x56209779b980] Could not open file : ./movie_frames//10m_speed_frame_*.png\n", + "[image2 @ 0x56209779b980] Could not find codec parameters for stream 0 (Video: png, none(pc)): unspecified size\n", + "Consider increasing the value for the 'analyzeduration' (0) and 'probesize' (5000000) options\n", + "Input #0, image2, from './movie_frames//10m_speed_frame_*.png':\n", + " Duration: 00:00:00.03, start: 0.000000, bitrate: N/A\n", + " Stream #0:0: Video: png, none(pc), 30 fps, 30 tbr, 30 tbn\n", + "Output #0, mp4, to './movie_frames/test.mp4':\n", + "[out#0/mp4 @ 0x56209779fb40] Output file does not contain any stream\n", + "Error opening output file ./movie_frames/test.mp4.\n", + "Error opening output files: Invalid argument\n" + ] + }, + { + "ename": "CalledProcessError", + "evalue": "Command 'ffmpeg -framerate 30 -pattern_type glob -i \"./movie_frames//10m_speed_frame_*.png\" -vf scale=-2:1080,setsar=1 ./movie_frames/test.mp4' returned non-zero exit status 234.", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mCalledProcessError\u001b[0m Traceback (most recent call last)", + "File \u001b[0;32m:3\u001b[0m\n", + "File \u001b[0;32m/g/data/hh5/public/apps/miniconda3/envs/analysis3-24.04/lib/python3.10/subprocess.py:369\u001b[0m, in \u001b[0;36mcheck_call\u001b[0;34m(*popenargs, **kwargs)\u001b[0m\n\u001b[1;32m 367\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m cmd \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 368\u001b[0m cmd \u001b[38;5;241m=\u001b[39m popenargs[\u001b[38;5;241m0\u001b[39m]\n\u001b[0;32m--> 369\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m CalledProcessError(retcode, cmd)\n\u001b[1;32m 370\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;241m0\u001b[39m\n", + "\u001b[0;31mCalledProcessError\u001b[0m: Command 'ffmpeg -framerate 30 -pattern_type glob -i \"./movie_frames//10m_speed_frame_*.png\" -vf scale=-2:1080,setsar=1 ./movie_frames/test.mp4' returned non-zero exit status 234." + ] + } + ], + "source": [ + "%%time\n", + "\n", + "from subprocess import check_call\n", + "\n", + "check_call('ffmpeg -framerate ' + str(frame_rate) + \n", + " ' -pattern_type glob -i \"'+\n", + " frame_directory + '/10m_speed_frame_*.png\" -vf scale=-2:' + str(resolution) + ',setsar=1 '+\n", + " frame_directory + movie_name, shell=True)" + ] + }, + { + "cell_type": "markdown", + "id": "2cc69928-b7b3-4b82-a61f-abdd5a213ee0", + "metadata": {}, + "source": [ + "### Play the video\n", + "- this works when using Google Chrome or Microsoft Edge\n", + "- this does not work when using Mozilla Firefox" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "4c8b68ee-4999-4235-b3e3-240c4a4b033c", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "CPU times: user 0 ns, sys: 793 μs, total: 793 μs\n", + "Wall time: 564 μs\n" + ] + }, + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "%%time\n", + "\n", + "from IPython.display import Video\n", + "Video(frame_directory + movie_name, embed=True, height=500)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b999adb0-6521-4ab0-9e66-53f1dc96d710", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "cb0f1b9c-b0cd-4f66-90e5-14aad52f6f4e", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "597c90b1-96d1-4a54-bd67-ad3e2bacd5df", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "12a25bdc-2f95-487b-9cc5-8feaf94a6224", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4b06cfff-43f3-400e-8868-7842091a5e19", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python [conda env:analysis3-24.04] *", + "language": "python", + "name": "conda-env-analysis3-24.04-py" + }, + "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.10.14" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}