From 555e902d11f4c67e9d674e8ba47e42d632902d67 Mon Sep 17 00:00:00 2001 From: suryadheeshjith Date: Tue, 23 Apr 2024 20:04:53 -0400 Subject: [PATCH 1/2] WIP: Ocean momentum --- .gitignore | 2 + book/notebooks/Ocean_Momentum.ipynb | 506 ++++++++++++++++++++++++++++ 2 files changed, 508 insertions(+) create mode 100644 book/notebooks/Ocean_Momentum.ipynb diff --git a/.gitignore b/.gitignore index dc5b00e..02a6072 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,5 @@ src/notebooks/*.npy src/notebooks/*.gif token.txt upload_to_leap.py +gz21_ocean_momentum +gz21-forcing-cm26 diff --git a/book/notebooks/Ocean_Momentum.ipynb b/book/notebooks/Ocean_Momentum.ipynb new file mode 100644 index 0000000..2b79989 --- /dev/null +++ b/book/notebooks/Ocean_Momentum.ipynb @@ -0,0 +1,506 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Cloning into 'gz21-forcing-cm26'...\n", + "remote: Enumerating objects: 433, done.\u001b[K\n", + "remote: Total 433 (delta 0), reused 0 (delta 0), pack-reused 433\u001b[K\n", + "Receiving objects: 100% (433/433), 60.56 KiB | 8.65 MiB/s, done.\n", + "Resolving deltas: 100% (2/2), done.\n", + "Filtering content: 100% (420/420), 268.35 MiB | 22.80 MiB/s, done.\n" + ] + } + ], + "source": [ + "# !git clone https://huggingface.co/datasets/M2LInES/gz21-forcing-cm26" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Cloning into 'gz21_ocean_momentum'...\n", + "remote: Enumerating objects: 2190, done.\u001b[K\n", + "remote: Counting objects: 100% (781/781), done.\u001b[K\n", + "remote: Compressing objects: 100% (312/312), done.\u001b[K\n", + "remote: Total 2190 (delta 545), reused 470 (delta 469), pack-reused 1409\u001b[K\n", + "Receiving objects: 100% (2190/2190), 33.50 MiB | 32.15 MiB/s, done.\n", + "Resolving deltas: 100% (1142/1142), done.\n" + ] + } + ], + "source": [ + "# !git clone https://github.com/m2lines/gz21_ocean_momentum.git" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "To load the net from the paper, use the function load_paper_net().\n" + ] + } + ], + "source": [ + "from gz21_ocean_momentum.common.bounding_box import BoundingBox\n", + "\n", + "bboxes = [\n", + " BoundingBox(35, 50, -50, -20),\n", + " BoundingBox(-40, -25, -180, -162),\n", + " BoundingBox(-20, -5, -110, -92),\n", + " BoundingBox(-0, 15, -48, -30),\n", + "]" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from gz21_ocean_momentum.data.pangeo_catalog import get_patch, get_whole_data\n", + "import gz21_ocean_momentum.analysis.utils as analysisutils\n", + "\n", + "import xarray as xr\n", + "from dask.diagnostics import ProgressBar\n", + "import numpy as np\n", + "import cmocean\n", + "from cartopy.crs import PlateCarree\n", + "from scipy.ndimage import gaussian_filter\n", + "from matplotlib import colors\n", + "import matplotlib.pyplot as plt\n", + "\n", + "# from imptortlib import reload\n", + "# reload(pl)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [], + "source": [ + "forcings_path = (\n", + " \"/Users/suryad/GitProjects/data-gallery/book/notebooks/gz21-forcing-cm26/forcing\"\n", + ")\n", + "data = xr.open_dataset(forcings_path, engine=\"zarr\")" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [], + "source": [ + "plt.rcParams[\"figure.figsize\"] = (4, 4 / 1.618)\n", + "\n", + "%matplotlib widget\n", + "# %matplotlib inline #this option does not work with jupyterlab\n", + "\n", + "CATALOG_URL = \"https://raw.githubusercontent.com/pangeo-data/pangeo-datastore\\\n", + "/master/intake-catalogs/master.yaml\"\n", + "\n", + "\n", + "class GlobalPlotter:\n", + " \"\"\"General class to make plots for global data. Handles masking of\n", + " continental data + showing a band near coastlines.\"\"\"\n", + "\n", + " def __init__(self, margin: int = 10, cbar: bool = True, ice: bool = True):\n", + " self.mask = self._get_global_u_mask()\n", + " self.margin = margin\n", + " self.cbar = cbar\n", + " self.ticks = dict(x=None, y=None)\n", + " self.ice = ice\n", + "\n", + " @property\n", + " def mask(self):\n", + " return self._mask\n", + "\n", + " @mask.setter\n", + " def mask(self, value):\n", + " self._mask = value\n", + "\n", + " @property\n", + " def borders(self):\n", + " return self._borders\n", + "\n", + " @borders.setter\n", + " def borders(self, value):\n", + " self._borders = value\n", + "\n", + " @property\n", + " def margin(self):\n", + " return self._margin\n", + "\n", + " @margin.setter\n", + " def margin(self, margin):\n", + " self._margin = margin\n", + " self.borders = self._get_continent_borders(self.mask, self.margin)\n", + "\n", + " @property\n", + " def x_ticks(self):\n", + " return self.ticks[\"x\"]\n", + "\n", + " @x_ticks.setter\n", + " def x_ticks(self, value):\n", + " self.ticks[\"x\"] = value\n", + "\n", + " @property\n", + " def y_ticks(self):\n", + " return self.ticks[\"y\"]\n", + "\n", + " @y_ticks.setter\n", + " def y_ticks(self, value):\n", + " self.ticks[\"y\"] = value\n", + "\n", + " def plot(\n", + " self,\n", + " u: xr.DataArray = None,\n", + " projection_cls=PlateCarree,\n", + " lon: float = -100.0,\n", + " lat: float = None,\n", + " ax=None,\n", + " animated=False,\n", + " borders_color=\"grey\",\n", + " borders_alpha=1.0,\n", + " **plot_func_kw\n", + " ):\n", + " \"\"\"\n", + " Plots the passed velocity component on a map, using the specified\n", + " projection. Uses the instance's mask to set as nan some values.\n", + "\n", + " Parameters\n", + " ----------\n", + " u : xr.DataArray\n", + " Velocity array. The default is None.\n", + " projection : Projection\n", + " Projection used for the 2D plot.\n", + " lon : float, optional\n", + " Central longitude. The default is -100.0.\n", + " lat : float, optional\n", + " Central latitude. The default is None.\n", + "\n", + " Returns\n", + " -------\n", + " None.\n", + "\n", + " \"\"\"\n", + "\n", + " fig = plt.figure()\n", + " projection = projection_cls(lon)\n", + " if ax is None:\n", + " ax = plt.axes(projection=projection)\n", + " mesh_x, mesh_y = np.meshgrid(u[\"xu_ocean\"], u[\"yu_ocean\"])\n", + " if u is not None:\n", + " extra = self.mask.isel(xu_ocean=slice(0, 10))\n", + " extra[\"xu_ocean\"] = extra[\"xu_ocean\"] + 360\n", + " mask = xr.concat((self.mask, extra), dim=\"xu_ocean\")\n", + " mask = mask.interp({k: u.coords[k] for k in (\"xu_ocean\", \"yu_ocean\")})\n", + " u = u * mask\n", + " im = ax.pcolormesh(\n", + " mesh_x,\n", + " mesh_y,\n", + " u.values,\n", + " transform=PlateCarree(),\n", + " animated=animated,\n", + " **plot_func_kw\n", + " )\n", + " if self.x_ticks is not None:\n", + " ax.set_xticks(self.x_ticks)\n", + " if self.y_ticks is not None:\n", + " ax.set_yticks(self.y_ticks)\n", + " ax.set_global()\n", + " ax.coastlines()\n", + " # \"Gray-out\" near continental locations\n", + " if self.margin > 0:\n", + " extra = self.borders.isel(longitude=slice(0, 10))\n", + " extra[\"xu_ocean\"] = extra[\"xu_ocean\"] + 360\n", + " borders = xr.concat((self.borders, extra), dim=\"xu_ocean\")\n", + " borders = borders.interp({k: u.coords[k] for k in (\"xu_ocean\", \"yu_ocean\")})\n", + " borders_cmap = colors.ListedColormap(\n", + " [\n", + " borders_color,\n", + " ]\n", + " )\n", + " ax.pcolormesh(\n", + " mesh_x,\n", + " mesh_y,\n", + " borders,\n", + " animated=animated,\n", + " transform=PlateCarree(),\n", + " alpha=borders_alpha,\n", + " cmap=borders_cmap,\n", + " )\n", + " # Add locations of ice\n", + " if self.ice:\n", + " ice = self._get_ice_border()\n", + " ice = xr.where(ice, 1.0, 0.0)\n", + " ice = ice.interp({k: u.coords[k] for k in (\"xu_ocean\", \"yu_ocean\")})\n", + " ice = xr.where(ice != 0, 1.0, 0.0)\n", + " ice = abs(ice.diff(dim=\"xu_ocean\")) + abs(ice.diff(dim=\"yu_ocean\"))\n", + " ice = xr.where(ice != 0.0, 1, np.nan)\n", + " ice_cmap = colors.ListedColormap(\n", + " [\n", + " \"black\",\n", + " ]\n", + " )\n", + " ax.pcolormesh(\n", + " mesh_x,\n", + " mesh_y,\n", + " ice,\n", + " animated=animated,\n", + " transform=PlateCarree(),\n", + " alpha=0.5,\n", + " cmap=ice_cmap,\n", + " )\n", + " if u is not None and self.cbar:\n", + " cbar = plt.colorbar(im, shrink=0.6)\n", + " cbar.set_label(\"m/s\")\n", + " return ax\n", + "\n", + " @staticmethod\n", + " def _get_global_u_mask(factor: int = 4, base_mask: xr.DataArray = None):\n", + " \"\"\"\n", + " Return the global mask of the low-resolution surface velocities for\n", + " plots. While the coarse-grained velocities might be defined on\n", + " continental points due to the coarse-graining procedures, these are\n", + " not shown as we do not use them -- the mask for the forcing is even\n", + " more restrictive, as it removes any point within some margin of the\n", + " velocities mask.\n", + "\n", + " Parameters\n", + " ----------\n", + " factor : int, optional\n", + " Coarse-graining factor. The default is 4.\n", + "\n", + " base_mask: xr.DataArray, optional\n", + " # TODO\n", + " Not implemented for now.\n", + "\n", + " Returns\n", + " -------\n", + " None.\n", + "\n", + " \"\"\"\n", + " if base_mask is not None:\n", + " mask = base_mask\n", + " else:\n", + " _, grid_info = get_whole_data(CATALOG_URL, 0)\n", + " mask = grid_info[\"wet\"]\n", + " mask = mask.coarsen(dict(xt_ocean=factor, yt_ocean=factor))\n", + " mask_ = mask.max()\n", + " mask_ = mask_.where(mask_ > 0.1)\n", + " mask_ = mask_.rename(dict(xt_ocean=\"xu_ocean\", yt_ocean=\"yu_ocean\"))\n", + " return mask_.compute()\n", + "\n", + " @staticmethod\n", + " def _get_ice_border():\n", + " \"\"\"Return an xarray.DataArray that indicates the locations of ice\n", + " in the oceans.\"\"\"\n", + " temperature, _ = get_patch(CATALOG_URL, 1, None, 0, \"surface_temp\")\n", + " temperature = temperature.rename(dict(xt_ocean=\"xu_ocean\", yt_ocean=\"yu_ocean\"))\n", + " temperature = temperature[\"surface_temp\"].isel(time=0)\n", + " ice = xr.where(temperature <= 0.0, True, False)\n", + " return ice\n", + "\n", + " @staticmethod\n", + " def _get_continent_borders(base_mask: xr.DataArray, margin: int):\n", + " \"\"\"\n", + " Returns a boolean xarray DataArray corresponding to a mask of the\n", + " continents' coasts, which we do not process.\n", + " Hence margin should be set according to the model.\n", + "\n", + " Parameters\n", + " ----------\n", + " mask : xr.DataArray\n", + " Mask taking value 1 where coarse velocities are defined and used\n", + " as input and nan elsewhere.\n", + " margin : int\n", + " Margin imposed by the model used, i.e. number of points lost on\n", + " one side of a square.\n", + "\n", + " Returns\n", + " -------\n", + " mask : xr.DataArray\n", + " Boolean DataArray taking value True for continents.\n", + "\n", + " \"\"\"\n", + " assert margin >= 0, \"The margin parameter should be a non-negative\" \" integer\"\n", + " assert base_mask.ndim <= 2, \"Velocity array should have two\" \" dims\"\n", + " # Small trick using the guassian filter function\n", + " mask = xr.apply_ufunc(\n", + " lambda x: gaussian_filter(x, 1.0, truncate=margin), base_mask\n", + " )\n", + " mask = np.logical_and(np.isnan(mask), ~np.isnan(base_mask))\n", + " mask = mask.where(mask)\n", + " return mask.compute()" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "ename": "TypeError", + "evalue": "__init__() got an unexpected keyword argument 'consolidated'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[15], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m plotter \u001b[38;5;241m=\u001b[39m \u001b[43mGlobalPlotter\u001b[49m\u001b[43m(\u001b[49m\u001b[43mcbar\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmargin\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[1;32m 2\u001b[0m plotter\u001b[38;5;241m.\u001b[39mx_ticks \u001b[38;5;241m=\u001b[39m np\u001b[38;5;241m.\u001b[39marange(\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m150.\u001b[39m, \u001b[38;5;241m151.\u001b[39m, \u001b[38;5;241m50\u001b[39m)\n\u001b[1;32m 3\u001b[0m plotter\u001b[38;5;241m.\u001b[39my_ticks \u001b[38;5;241m=\u001b[39m np\u001b[38;5;241m.\u001b[39marange(\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m80.\u001b[39m, \u001b[38;5;241m81.\u001b[39m, \u001b[38;5;241m20\u001b[39m)\n", + "Cell \u001b[0;32mIn[14], line 15\u001b[0m, in \u001b[0;36mGlobalPlotter.__init__\u001b[0;34m(self, margin, cbar, ice)\u001b[0m\n\u001b[1;32m 14\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m__init__\u001b[39m(\u001b[38;5;28mself\u001b[39m, margin: \u001b[38;5;28mint\u001b[39m \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m10\u001b[39m, cbar: \u001b[38;5;28mbool\u001b[39m \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mTrue\u001b[39;00m, ice: \u001b[38;5;28mbool\u001b[39m \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mTrue\u001b[39;00m):\n\u001b[0;32m---> 15\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mmask \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_get_global_u_mask\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 16\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mmargin \u001b[38;5;241m=\u001b[39m margin\n\u001b[1;32m 17\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcbar \u001b[38;5;241m=\u001b[39m cbar\n", + "Cell \u001b[0;32mIn[14], line 163\u001b[0m, in \u001b[0;36mGlobalPlotter._get_global_u_mask\u001b[0;34m(factor, base_mask)\u001b[0m\n\u001b[1;32m 161\u001b[0m mask \u001b[38;5;241m=\u001b[39m base_mask\n\u001b[1;32m 162\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m--> 163\u001b[0m _, grid_info \u001b[38;5;241m=\u001b[39m \u001b[43mget_whole_data\u001b[49m\u001b[43m(\u001b[49m\u001b[43mCATALOG_URL\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[1;32m 164\u001b[0m mask \u001b[38;5;241m=\u001b[39m grid_info[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mwet\u001b[39m\u001b[38;5;124m'\u001b[39m]\n\u001b[1;32m 165\u001b[0m mask \u001b[38;5;241m=\u001b[39m mask\u001b[38;5;241m.\u001b[39mcoarsen(\u001b[38;5;28mdict\u001b[39m(xt_ocean\u001b[38;5;241m=\u001b[39mfactor, yt_ocean\u001b[38;5;241m=\u001b[39mfactor))\n", + "File \u001b[0;32m~/GitProjects/data-gallery/book/notebooks/gz21_ocean_momentum/data/pangeo_catalog.py:109\u001b[0m, in \u001b[0;36mget_whole_data\u001b[0;34m(url, c02_level)\u001b[0m\n\u001b[1;32m 90\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mget_whole_data\u001b[39m(url, c02_level):\n\u001b[1;32m 91\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m 92\u001b[0m \u001b[38;5;124;03m Obtain all surface data and grid data for a given CO2 level.\u001b[39;00m\n\u001b[1;32m 93\u001b[0m \n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 107\u001b[0m \u001b[38;5;124;03m xarray dataset with the grid details.\u001b[39;00m\n\u001b[1;32m 108\u001b[0m \u001b[38;5;124;03m \"\"\"\u001b[39;00m\n\u001b[0;32m--> 109\u001b[0m data, grid \u001b[38;5;241m=\u001b[39m \u001b[43mget_patch\u001b[49m\u001b[43m(\u001b[49m\u001b[43murl\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mc02_level\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43musurf\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mvsurf\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[1;32m 110\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m data, grid\n", + "File \u001b[0;32m~/GitProjects/data-gallery/book/notebooks/gz21_ocean_momentum/data/pangeo_catalog.py:49\u001b[0m, in \u001b[0;36mget_patch\u001b[0;34m(catalog_url, ntimes, bounds, CO2_level, *selected_vars)\u001b[0m\n\u001b[1;32m 47\u001b[0m catalog \u001b[38;5;241m=\u001b[39m intake\u001b[38;5;241m.\u001b[39mopen_catalog(catalog_url)\n\u001b[1;32m 48\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m CO2_level \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m0\u001b[39m:\n\u001b[0;32m---> 49\u001b[0m source \u001b[38;5;241m=\u001b[39m \u001b[43mcatalog\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mocean\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mGFDL_CM2_6\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mGFDL_CM2_6_control_ocean_surface\u001b[49m\n\u001b[1;32m 50\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m CO2_level \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m1\u001b[39m:\n\u001b[1;32m 51\u001b[0m source \u001b[38;5;241m=\u001b[39m catalog\u001b[38;5;241m.\u001b[39mocean\u001b[38;5;241m.\u001b[39mGFDL_CM2_6\u001b[38;5;241m.\u001b[39mGFDL_CM2_6_one_percent_ocean_surface\n", + "File \u001b[0;32m~/opt/anaconda3/envs/DGM2lines/lib/python3.9/site-packages/intake/catalog/base.py:427\u001b[0m, in \u001b[0;36mCatalog.__getattr__\u001b[0;34m(self, item)\u001b[0m\n\u001b[1;32m 424\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m item\u001b[38;5;241m.\u001b[39mstartswith(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m_\u001b[39m\u001b[38;5;124m\"\u001b[39m):\n\u001b[1;32m 425\u001b[0m \u001b[38;5;66;03m# Fall back to __getitem__.\u001b[39;00m\n\u001b[1;32m 426\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m--> 427\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m[\u001b[49m\u001b[43mitem\u001b[49m\u001b[43m]\u001b[49m \u001b[38;5;66;03m# triggers reload_on_change\u001b[39;00m\n\u001b[1;32m 428\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mKeyError\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[1;32m 429\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mAttributeError\u001b[39;00m(item) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01me\u001b[39;00m\n", + "File \u001b[0;32m~/opt/anaconda3/envs/DGM2lines/lib/python3.9/site-packages/intake/catalog/base.py:472\u001b[0m, in \u001b[0;36mCatalog.__getitem__\u001b[0;34m(self, key)\u001b[0m\n\u001b[1;32m 463\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"Return a catalog entry by name.\u001b[39;00m\n\u001b[1;32m 464\u001b[0m \n\u001b[1;32m 465\u001b[0m \u001b[38;5;124;03mCan also use attribute syntax, like ``cat.entry_name``, or\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 468\u001b[0m \u001b[38;5;124;03mcat['name1', 'name2']\u001b[39;00m\n\u001b[1;32m 469\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m 470\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(key, \u001b[38;5;28mlist\u001b[39m) \u001b[38;5;129;01mand\u001b[39;00m key \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m:\n\u001b[1;32m 471\u001b[0m \u001b[38;5;66;03m# triggers reload_on_change\u001b[39;00m\n\u001b[0;32m--> 472\u001b[0m s \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_get_entry\u001b[49m\u001b[43m(\u001b[49m\u001b[43mkey\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 473\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m s\u001b[38;5;241m.\u001b[39mcontainer \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcatalog\u001b[39m\u001b[38;5;124m\"\u001b[39m:\n\u001b[1;32m 474\u001b[0m s\u001b[38;5;241m.\u001b[39mname \u001b[38;5;241m=\u001b[39m key\n", + "File \u001b[0;32m~/opt/anaconda3/envs/DGM2lines/lib/python3.9/site-packages/intake/catalog/utils.py:43\u001b[0m, in \u001b[0;36mreload_on_change..wrapper\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m 40\u001b[0m \u001b[38;5;129m@functools\u001b[39m\u001b[38;5;241m.\u001b[39mwraps(f)\n\u001b[1;32m 41\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mwrapper\u001b[39m(\u001b[38;5;28mself\u001b[39m, \u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs):\n\u001b[1;32m 42\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mreload()\n\u001b[0;32m---> 43\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mf\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\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", + "File \u001b[0;32m~/opt/anaconda3/envs/DGM2lines/lib/python3.9/site-packages/intake/catalog/base.py:355\u001b[0m, in \u001b[0;36mCatalog._get_entry\u001b[0;34m(self, name)\u001b[0m\n\u001b[1;32m 353\u001b[0m ups \u001b[38;5;241m=\u001b[39m [up \u001b[38;5;28;01mfor\u001b[39;00m name, up \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39muser_parameters\u001b[38;5;241m.\u001b[39mitems() \u001b[38;5;28;01mif\u001b[39;00m name \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;129;01min\u001b[39;00m up_names]\n\u001b[1;32m 354\u001b[0m entry\u001b[38;5;241m.\u001b[39m_user_parameters \u001b[38;5;241m=\u001b[39m ups \u001b[38;5;241m+\u001b[39m (entry\u001b[38;5;241m.\u001b[39m_user_parameters \u001b[38;5;129;01mor\u001b[39;00m [])\n\u001b[0;32m--> 355\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mentry\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n", + "File \u001b[0;32m~/opt/anaconda3/envs/DGM2lines/lib/python3.9/site-packages/intake/catalog/entry.py:60\u001b[0m, in \u001b[0;36mCatalogEntry.__call__\u001b[0;34m(self, persist, **kwargs)\u001b[0m\n\u001b[1;32m 58\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m__call__\u001b[39m(\u001b[38;5;28mself\u001b[39m, persist\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs):\n\u001b[1;32m 59\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"Instantiate DataSource with given user arguments\"\"\"\u001b[39;00m\n\u001b[0;32m---> 60\u001b[0m s \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget\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 61\u001b[0m s\u001b[38;5;241m.\u001b[39m_entry \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\n\u001b[1;32m 62\u001b[0m s\u001b[38;5;241m.\u001b[39m_passed_kwargs \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mlist\u001b[39m(kwargs)\n", + "File \u001b[0;32m~/opt/anaconda3/envs/DGM2lines/lib/python3.9/site-packages/intake/catalog/local.py:313\u001b[0m, in \u001b[0;36mLocalCatalogEntry.get\u001b[0;34m(self, **user_parameters)\u001b[0m\n\u001b[1;32m 310\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_default_source\n\u001b[1;32m 312\u001b[0m plugin, open_args \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_create_open_args(user_parameters)\n\u001b[0;32m--> 313\u001b[0m data_source \u001b[38;5;241m=\u001b[39m \u001b[43mplugin\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mopen_args\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 314\u001b[0m data_source\u001b[38;5;241m.\u001b[39mcatalog_object \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_catalog\n\u001b[1;32m 315\u001b[0m data_source\u001b[38;5;241m.\u001b[39mname \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mname\n", + "\u001b[0;31mTypeError\u001b[0m: __init__() got an unexpected keyword argument 'consolidated'" + ] + } + ], + "source": [ + "plotter = GlobalPlotter(cbar=True, margin=0)\n", + "plotter.x_ticks = np.arange(-150.0, 151.0, 50)\n", + "plotter.y_ticks = np.arange(-80.0, 81.0, 20)\n", + "\n", + "analysisutils.plot_training_subdomains(\n", + " plotter,\n", + " bboxes,\n", + " bg_variable=data[\"usurf\"].isel(time=0),\n", + " facecolor=\"green\",\n", + " edgecolor=\"black\",\n", + " linewidth=2,\n", + " fill=False,\n", + " vmin=-0.5,\n", + " vmax=0.5,\n", + " lon=0.0,\n", + " cmap=cmocean.cm.balance,\n", + ")\n", + "print(analysisutils.training_subdomains_latex(bboxes))" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Requirement already satisfied: aiohttp in /Users/suryad/opt/anaconda3/envs/DGM2lines/lib/python3.9/site-packages (3.9.5)\n", + "Requirement already satisfied: aiosignal>=1.1.2 in /Users/suryad/opt/anaconda3/envs/DGM2lines/lib/python3.9/site-packages (from aiohttp) (1.3.1)\n", + "Requirement already satisfied: attrs>=17.3.0 in /Users/suryad/opt/anaconda3/envs/DGM2lines/lib/python3.9/site-packages (from aiohttp) (23.2.0)\n", + "Requirement already satisfied: frozenlist>=1.1.1 in /Users/suryad/opt/anaconda3/envs/DGM2lines/lib/python3.9/site-packages (from aiohttp) (1.4.1)\n", + "Requirement already satisfied: multidict<7.0,>=4.5 in /Users/suryad/opt/anaconda3/envs/DGM2lines/lib/python3.9/site-packages (from aiohttp) (6.0.5)\n", + "Requirement already satisfied: yarl<2.0,>=1.0 in /Users/suryad/opt/anaconda3/envs/DGM2lines/lib/python3.9/site-packages (from aiohttp) (1.9.4)\n", + "Requirement already satisfied: async-timeout<5.0,>=4.0 in /Users/suryad/opt/anaconda3/envs/DGM2lines/lib/python3.9/site-packages (from aiohttp) (4.0.3)\n", + "Requirement already satisfied: idna>=2.0 in /Users/suryad/opt/anaconda3/envs/DGM2lines/lib/python3.9/site-packages (from yarl<2.0,>=1.0->aiohttp) (3.4)\n", + "Collecting intake-xarray\n", + " Downloading intake_xarray-0.7.0-py3-none-any.whl.metadata (1.5 kB)\n", + "Requirement already satisfied: intake>=0.6.6 in /Users/suryad/opt/anaconda3/envs/DGM2lines/lib/python3.9/site-packages (from intake-xarray) (2.0.4)\n", + "Requirement already satisfied: xarray>=02022 in /Users/suryad/opt/anaconda3/envs/DGM2lines/lib/python3.9/site-packages (from intake-xarray) (2023.10.1)\n", + "Requirement already satisfied: zarr in /Users/suryad/opt/anaconda3/envs/DGM2lines/lib/python3.9/site-packages (from intake-xarray) (2.17.2)\n", + "Requirement already satisfied: dask>=2.2 in /Users/suryad/opt/anaconda3/envs/DGM2lines/lib/python3.9/site-packages (from intake-xarray) (2024.2.1)\n", + "Requirement already satisfied: netcdf4 in /Users/suryad/opt/anaconda3/envs/DGM2lines/lib/python3.9/site-packages (from intake-xarray) (1.6.2)\n", + "Requirement already satisfied: fsspec>2022 in /Users/suryad/opt/anaconda3/envs/DGM2lines/lib/python3.9/site-packages (from intake-xarray) (2024.2.0)\n", + "Requirement already satisfied: msgpack in /Users/suryad/opt/anaconda3/envs/DGM2lines/lib/python3.9/site-packages (from intake-xarray) (1.0.3)\n", + "Requirement already satisfied: requests in /Users/suryad/opt/anaconda3/envs/DGM2lines/lib/python3.9/site-packages (from intake-xarray) (2.31.0)\n", + "Requirement already satisfied: click>=8.1 in /Users/suryad/opt/anaconda3/envs/DGM2lines/lib/python3.9/site-packages (from dask>=2.2->intake-xarray) (8.1.7)\n", + "Requirement already satisfied: cloudpickle>=1.5.0 in /Users/suryad/opt/anaconda3/envs/DGM2lines/lib/python3.9/site-packages (from dask>=2.2->intake-xarray) (3.0.0)\n", + "Requirement already satisfied: packaging>=20.0 in /Users/suryad/opt/anaconda3/envs/DGM2lines/lib/python3.9/site-packages (from dask>=2.2->intake-xarray) (23.1)\n", + "Requirement already satisfied: partd>=1.2.0 in /Users/suryad/opt/anaconda3/envs/DGM2lines/lib/python3.9/site-packages (from dask>=2.2->intake-xarray) (1.4.1)\n", + "Requirement already satisfied: pyyaml>=5.3.1 in /Users/suryad/opt/anaconda3/envs/DGM2lines/lib/python3.9/site-packages (from dask>=2.2->intake-xarray) (6.0.1)\n", + "Requirement already satisfied: toolz>=0.10.0 in /Users/suryad/opt/anaconda3/envs/DGM2lines/lib/python3.9/site-packages (from dask>=2.2->intake-xarray) (0.12.0)\n", + "Requirement already satisfied: importlib-metadata>=4.13.0 in /Users/suryad/opt/anaconda3/envs/DGM2lines/lib/python3.9/site-packages (from dask>=2.2->intake-xarray) (7.0.1)\n", + "Requirement already satisfied: appdirs in /Users/suryad/opt/anaconda3/envs/DGM2lines/lib/python3.9/site-packages (from intake>=0.6.6->intake-xarray) (1.4.4)\n", + "Requirement already satisfied: numpy>=1.22 in /Users/suryad/opt/anaconda3/envs/DGM2lines/lib/python3.9/site-packages (from xarray>=02022->intake-xarray) (1.26.1)\n", + "Requirement already satisfied: pandas>=1.4 in /Users/suryad/opt/anaconda3/envs/DGM2lines/lib/python3.9/site-packages (from xarray>=02022->intake-xarray) (2.1.3)\n", + "Requirement already satisfied: cftime in /Users/suryad/opt/anaconda3/envs/DGM2lines/lib/python3.9/site-packages (from netcdf4->intake-xarray) (1.6.2)\n", + "Requirement already satisfied: charset-normalizer<4,>=2 in /Users/suryad/opt/anaconda3/envs/DGM2lines/lib/python3.9/site-packages (from requests->intake-xarray) (2.0.4)\n", + "Requirement already satisfied: idna<4,>=2.5 in /Users/suryad/opt/anaconda3/envs/DGM2lines/lib/python3.9/site-packages (from requests->intake-xarray) (3.4)\n", + "Requirement already satisfied: urllib3<3,>=1.21.1 in /Users/suryad/opt/anaconda3/envs/DGM2lines/lib/python3.9/site-packages (from requests->intake-xarray) (1.26.18)\n", + "Requirement already satisfied: certifi>=2017.4.17 in /Users/suryad/opt/anaconda3/envs/DGM2lines/lib/python3.9/site-packages (from requests->intake-xarray) (2024.2.2)\n", + "Requirement already satisfied: asciitree in /Users/suryad/opt/anaconda3/envs/DGM2lines/lib/python3.9/site-packages (from zarr->intake-xarray) (0.3.3)\n", + "Requirement already satisfied: numcodecs>=0.10.0 in /Users/suryad/opt/anaconda3/envs/DGM2lines/lib/python3.9/site-packages (from zarr->intake-xarray) (0.12.1)\n", + "Requirement already satisfied: fasteners in /Users/suryad/opt/anaconda3/envs/DGM2lines/lib/python3.9/site-packages (from zarr->intake-xarray) (0.19)\n", + "Requirement already satisfied: zipp>=0.5 in /Users/suryad/opt/anaconda3/envs/DGM2lines/lib/python3.9/site-packages (from importlib-metadata>=4.13.0->dask>=2.2->intake-xarray) (3.17.0)\n", + "Requirement already satisfied: python-dateutil>=2.8.2 in /Users/suryad/opt/anaconda3/envs/DGM2lines/lib/python3.9/site-packages (from pandas>=1.4->xarray>=02022->intake-xarray) (2.9.0.post0)\n", + "Requirement already satisfied: pytz>=2020.1 in /Users/suryad/opt/anaconda3/envs/DGM2lines/lib/python3.9/site-packages (from pandas>=1.4->xarray>=02022->intake-xarray) (2024.1)\n", + "Requirement already satisfied: tzdata>=2022.1 in /Users/suryad/opt/anaconda3/envs/DGM2lines/lib/python3.9/site-packages (from pandas>=1.4->xarray>=02022->intake-xarray) (2024.1)\n", + "Requirement already satisfied: locket in /Users/suryad/opt/anaconda3/envs/DGM2lines/lib/python3.9/site-packages (from partd>=1.2.0->dask>=2.2->intake-xarray) (1.0.0)\n", + "Requirement already satisfied: six>=1.5 in /Users/suryad/opt/anaconda3/envs/DGM2lines/lib/python3.9/site-packages (from python-dateutil>=2.8.2->pandas>=1.4->xarray>=02022->intake-xarray) (1.16.0)\n", + "Downloading intake_xarray-0.7.0-py3-none-any.whl (28 kB)\n", + "Installing collected packages: intake-xarray\n", + "Successfully installed intake-xarray-0.7.0\n" + ] + } + ], + "source": [ + "!pip install aiohttp\n", + "!pip install intake-xarray" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "DGM2lines", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.18" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} From a76187141b96ca6f3f255433a313627c719de2f4 Mon Sep 17 00:00:00 2001 From: suryadheeshjith Date: Tue, 23 Apr 2024 20:07:40 -0400 Subject: [PATCH 2/2] More installs --- book/notebooks/Ocean_Momentum.ipynb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/book/notebooks/Ocean_Momentum.ipynb b/book/notebooks/Ocean_Momentum.ipynb index 2b79989..eec9210 100644 --- a/book/notebooks/Ocean_Momentum.ipynb +++ b/book/notebooks/Ocean_Momentum.ipynb @@ -471,7 +471,9 @@ ], "source": [ "!pip install aiohttp\n", - "!pip install intake-xarray" + "!pip install intake-xarray\n", + "!pip install mlflow\n", + "!pip install zarr" ] }, {