{ "cells": [ { "cell_type": "markdown", "id": "9f180f4c-0e82-438e-a456-724f3bc7d4d9", "metadata": {}, "source": [ "# Create spherical harmonic coefficients from an ocean mask\n", "*Author: R. Rietbroek Nov 2024 (r.rietbroek@utwente.nl)*\n", "\n", "The ocean function is defined to be one over the ocean and 0 over land areas. This mask function can also be converted to a set of spherical hamronic coefficients. These may for example be used in applying the Sea level equation in the spherical harmonic domain.\n", "\n", "## 1. Obtain a (fine ocean grid)\n", "As a starting point we can take a masked grid which was generated using using [an example recipe from geoslurp](https://github.com/strawpants/geoslurp/blob/master/docs/source/notebooks/OceanFunction.ipynb). " ] }, { "cell_type": "code", "execution_count": 1, "id": "a754d854-6522-451d-baed-b3c5c1eacccb", "metadata": {}, "outputs": [], "source": [ "import requests\n", "import os\n", "import xarray as xr\n", "import shxarray\n", "import matplotlib.pyplot as mpl" ] }, { "cell_type": "code", "execution_count": 2, "id": "47238111-a09f-4b3f-ae2a-ba1556d56e6c", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Downloading ocean grid /tmp/ne_10m_oceangrid_0.125.nc\n" ] }, { "data": { "text/html": [ "
<xarray.Dataset> Size: 33MB\n",
"Dimensions: (latitude: 1440, longitude: 2880)\n",
"Coordinates:\n",
" * longitude (longitude) float64 23kB -179.9 -179.8 -179.7 ... 179.8 179.9\n",
" * latitude (latitude) float64 12kB -89.94 -89.81 -89.69 ... 89.81 89.94\n",
" spatial_ref int64 8B ...\n",
"Data variables:\n",
" oceanfunc (latitude, longitude) float64 33MB 0.0 0.0 0.0 ... 1.0 1.0 1.0\n",
"Attributes:\n",
" Conventions: CF-1.9\n",
" title: Gridded Ocean mask generated from natural earth 10m dataset\n",
" institution: Roelof Rietbroek <r.rietbroek@utwente.nl>, Faculty of Geoin...\n",
" source: geoslurp\n",
" history: 2024-11-26 14:53:20.439413 geoslurp\n",
" references: https://geoslurp.wobbly.earth/en/latest/notebooks/OceanFunc...\n",
" comment: Auto generated<xarray.DataArray (nm: 90601)> Size: 725kB\n",
"array([ 7.11538971e-01, -6.02066955e-02, -1.22835400e-01, ...,\n",
" 3.12961008e-05, -2.97188334e-05, -2.17756304e-04])\n",
"Coordinates:\n",
" * nm (nm) object 725kB MultiIndex\n",
" * n (nm) int64 725kB 0 1 1 1 2 2 2 2 ... 300 300 300 300 300 300 300\n",
" * m (nm) int64 725kB 0 -1 0 1 -2 -1 0 1 ... 294 295 296 297 298 299 300