{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Example calculations with scalar quantities\n", "\n", "## Objectives\n", "\n", "To demonstrate basic calculations using scalar fields (e.g., SSH, T, S) from the state estimate including: time series of mean quantities, spatial patterns of mean quantities, spatial patterns of linear trends, and spatial patterns of linear trends over different time periods.\n", "\n", "## Introduction\n", "\n", "We will demonstrate global calculations with SSH (global mean sea level time series, mean dynamic topography, global mean sea level trend) and a regional calculation with THETA (The Nino 3.4 index).\n", "\n", "For this tutorial we will need the grid file, monthly SSH and THETA (potential temperature) spanning the years 1993 through 2017, and daily SSH for the year 1994. The ShortNames of the datasets are:\n", "\n", "- **ECCO_L4_GEOMETRY_LLC0090GRID_V4R4**\n", "- **ECCO_L4_SSH_LLC0090GRID_MONTHLY_V4R4** (1993-2017)\n", "- **ECCO_L4_TEMP_SALINITY_LLC0090GRID_MONTHLY_V4R4** (1993-2017)\n", "- **ECCO_L4_SSH_LLC0090GRID_DAILY_V4R4** (1994)\n", "\n", "The `ecco_access` Python package will access the data depending on the `incloud_access` option and access mode specified below; you may need to [install ecco_access](https://ecco-access.readthedocs.io/en/latest/Installation.html).\n", "\n", "## Global calculations with SSH\n", "\n", "First, load SSH and THETA fields and the model grid parameters." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import sys\n", "import xarray as xr\n", "from os.path import join,expanduser\n", "from copy import deepcopy \n", "import matplotlib.pyplot as plt\n", "%matplotlib inline\n", "import glob\n", "import warnings\n", "warnings.filterwarnings('ignore')\n", "\n", "\n", "import ecco_v4_py as ecco\n", "import ecco_access as ea\n", "\n", "\n", "# are you working in the AWS Cloud?\n", "incloud_access = False\n", "\n", "# indicate mode of access from PO.DAAC\n", "# options are:\n", "# 'download': direct download from internet to your local machine\n", "# 'download_ifspace': like download, but only proceeds \n", "# if your machine have sufficient storage\n", "# 's3_open': access datasets in-cloud from an AWS instance\n", "# 's3_open_fsspec': use jsons generated with fsspec and \n", "# kerchunk libraries to speed up in-cloud access\n", "# 's3_get': direct download from S3 in-cloud to an AWS instance\n", "# 's3_get_ifspace': like s3_get, but only proceeds if your instance \n", "# has sufficient storage\n", "user_home_dir = expanduser('~')\n", "download_dir = join(user_home_dir,'Downloads','ECCO_V4r4_PODAAC')\n", "if incloud_access:\n", " access_mode = 's3_open_fsspec'\n", " download_root_dir = None\n", " jsons_root_dir = join(user_home_dir,'MZZ')\n", "else:\n", " access_mode = 'download_ifspace'\n", " download_root_dir = download_dir\n", " jsons_root_dir = None" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Size of files to be downloaded to instance is 6.316 GB,\n", "which is 4.4% of the 143.655 GB available storage.\n", "Proceeding with file downloads via NASA Earthdata URLs\n", "\n", "GRID_GEOMETRY_ECCO_V4r4_native_llc0090.nc already exists, and force=False, not re-downloading\n", "DL Progress: 100%|########################| 1/1 [00:00<00:00, 12483.05it/s]\n", "\n", "=====================================\n", "total downloaded: 0.0 Mb\n", "avg download speed: 0.0 Mb/s\n", "Time spent = 0.0030794143676757812 seconds\n", "\n", "\n", "DL Progress: 100%|#######################| 300/300 [01:38<00:00, 3.04it/s]\n", "\n", "=====================================\n", "total downloaded: 1775.35 Mb\n", "avg download speed: 17.98 Mb/s\n", "Time spent = 98.72319316864014 seconds\n", "\n", "\n", "DL Progress: 100%|#######################| 300/300 [01:26<01:26, 2.59it/s]\n", "\n", "=====================================\n", "total downloaded: 1808.94 Mb\n", "avg download speed: 8.23 Mb/s\n", "Time spent = 219.87921047210693 seconds\n", "\n", "\n", "Size of files to be downloaded to instance is 2.015 GB,\n", "which is 1.47% of the 137.337 GB available storage.\n", "Proceeding with file downloads via NASA Earthdata URLs\n", "DL Progress: 100%|#######################| 365/365 [02:00<00:00, 3.03it/s]\n", "\n", "=====================================\n", "total downloaded: 2163.84 Mb\n", "avg download speed: 17.94 Mb/s\n", "Time spent = 120.64634680747986 seconds\n", "\n", "\n" ] } ], "source": [ "## Access datasets needed for this tutorial\n", "\n", "ShortNames_list = [\"ECCO_L4_GEOMETRY_LLC0090GRID_V4R4\",\\\n", " \"ECCO_L4_SSH_LLC0090GRID_MONTHLY_V4R4\",\\\n", " \"ECCO_L4_TEMP_SALINITY_LLC0090GRID_MONTHLY_V4R4\"]\n", "ShortNames_daily_list = [\"ECCO_L4_SSH_LLC0090GRID_DAILY_V4R4\"]\n", "\n", "ds_dict = ea.ecco_podaac_to_xrdataset(ShortNames_list,\\\n", " StartDate='1993-01',EndDate='2017-12',\\\n", " mode=access_mode,\\\n", " download_root_dir=download_root_dir,\\\n", " jsons_root_dir=jsons_root_dir,\\\n", " max_avail_frac=0.5)\n", "ds_SSH_daily_1994 = ea.ecco_podaac_to_xrdataset(ShortNames_daily_list,\\\n", " StartDate='1994-01-01',EndDate='1994-12-31',\\\n", " mode=access_mode,\\\n", " download_root_dir=download_root_dir,\\\n", " jsons_root_dir=jsons_root_dir,\\\n", " max_avail_frac=0.5)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "scrolled": true }, "outputs": [], "source": [ "## Load the model grid\n", "ecco_grid = ds_dict[ShortNames_list[0]].compute()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now we'll look at a dataset with grid parameters and daily SSH during 1994." ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "CPU times: user 87.7 ms, sys: 4.29 ms, total: 92 ms\n", "Wall time: 315 ms\n" ] }, { "data": { "text/html": [ "
<xarray.Dataset> Size: 242MB\n",
"Dimensions: (tile: 13, j: 90, i: 90, k: 50, k_p1: 51, nb: 4, j_g: 90,\n",
" i_g: 90, nv: 2, k_l: 50, k_u: 50, time: 365)\n",
"Coordinates: (12/22)\n",
" XC (tile, j, i) float32 421kB dask.array<chunksize=(13, 90, 90), meta=np.ndarray>\n",
" XC_bnds (tile, j, i, nb) float32 2MB dask.array<chunksize=(13, 90, 90, 4), meta=np.ndarray>\n",
" XG (tile, j_g, i_g) float32 421kB dask.array<chunksize=(13, 90, 90), meta=np.ndarray>\n",
" YC (tile, j, i) float32 421kB dask.array<chunksize=(13, 90, 90), meta=np.ndarray>\n",
" YC_bnds (tile, j, i, nb) float32 2MB dask.array<chunksize=(13, 90, 90, 4), meta=np.ndarray>\n",
" YG (tile, j_g, i_g) float32 421kB dask.array<chunksize=(13, 90, 90), meta=np.ndarray>\n",
" ... ...\n",
" * k_l (k_l) int32 200B 0 1 2 3 4 5 6 7 8 ... 41 42 43 44 45 46 47 48 49\n",
" * k_p1 (k_p1) int32 204B 0 1 2 3 4 5 6 7 8 ... 43 44 45 46 47 48 49 50\n",
" * k_u (k_u) int32 200B 0 1 2 3 4 5 6 7 8 ... 41 42 43 44 45 46 47 48 49\n",
" * tile (tile) int32 52B 0 1 2 3 4 5 6 7 8 9 10 11 12\n",
" * time (time) datetime64[ns] 3kB 1994-01-01T12:00:00 ... 1994-12-31T1...\n",
" time_bnds (time, nv) datetime64[ns] 6kB dask.array<chunksize=(365, 2), meta=np.ndarray>\n",
"Dimensions without coordinates: nb, nv\n",
"Data variables: (12/22)\n",
" CS (tile, j, i) float32 421kB 0.06158 0.06675 ... -0.9854 -0.9984\n",
" Depth (tile, j, i) float32 421kB 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0\n",
" PHrefC (k) float32 200B 49.05 147.1 245.2 ... 5.357e+04 5.794e+04\n",
" PHrefF (k_p1) float32 204B 0.0 98.1 196.2 ... 5.57e+04 6.018e+04\n",
" SN (tile, j, i) float32 421kB -0.9981 -0.9978 ... -0.1705 -0.05718\n",
" drC (k_p1) float32 204B 5.0 10.0 10.0 10.0 ... 422.0 445.0 228.2\n",
" ... ...\n",
" maskW (k, tile, j, i_g) bool 5MB False False False ... False False\n",
" rA (tile, j, i) float32 421kB 3.623e+08 3.633e+08 ... 3.611e+08\n",
" rAs (tile, j_g, i) float32 421kB 1.802e+08 1.807e+08 ... 3.605e+08\n",
" rAw (tile, j, i_g) float32 421kB 3.617e+08 3.628e+08 ... 3.648e+08\n",
" rAz (tile, j_g, i_g) float32 421kB 1.799e+08 1.805e+08 ... 3.642e+08\n",
" SSH (time, tile, j, i) float32 154MB dask.array<chunksize=(223, 13, 90, 90), meta=np.ndarray>\n",
"Attributes: (12/58)\n",
" Conventions: CF-1.8, ACDD-1.3\n",
" acknowledgement: This research was carried out by the Jet...\n",
" author: Ian Fenty and Ou Wang\n",
" cdm_data_type: Grid\n",
" comment: Fields provided on the curvilinear lat-l...\n",
" coordinates_comment: Note: the global 'coordinates' attribute...\n",
" ... ...\n",
" references: ECCO Consortium, Fukumori, I., Wang, O.,...\n",
" source: The ECCO V4r4 state estimate was produce...\n",
" standard_name_vocabulary: NetCDF Climate and Forecast (CF) Metadat...\n",
" summary: This dataset provides geometric paramete...\n",
" title: ECCO Geometry Parameters for the Lat-Lon...\n",
" uuid: 87ff7d24-86e5-11eb-9c5f-f8f21e2ee3e0<xarray.DataArray ()> Size: 8B\n",
"array(3.21794046)\n",
"Coordinates:\n",
" Z float32 4B dask.array<chunksize=(), meta=np.ndarray>\n",
" k int32 4B 0