{ "cells": [ { "cell_type": "markdown", "id": "4ec25494-49d2-45d8-b3c3-aa6a5a47632c", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "# Lenapy for spherical harmonics and gravity data\n", "Lenapy includes functions to read and process spherical harmonics and gravity data.\n", "\n", "These function are accessible to be applied to a dataset using *xarray* accessor. With a xr.Dataset instance ds, one can call the function to be applied onto ds with **ds.lnharmo.func()**.\n", "\n", "The corresponding functions are located in the package *lenapy.utils* (for **lnharmo** it corresponds to function mainly from *lenapy.utils.harmo* and *lenapy.utils.gravity*).\n", "\n", "## Imports\n", "Lenapy is an overlayer of xarray. For using lenapy fonctionnalities you need to import both xarray and lenapy." ] }, { "cell_type": "code", "execution_count": 32, "id": "bf0ea491-b215-42d8-9583-90f5935ce724", "metadata": {}, "outputs": [], "source": [ "import xarray as xr\n", "import lenapy\n", "\n", "import os\n", "import numpy as np\n", "\n", "# for plotting:\n", "import matplotlib.pyplot as plt\n", "import cartopy.crs as ccrs" ] }, { "cell_type": "markdown", "id": "4683c0ff-9143-4810-b87f-f74aeae519ae", "metadata": {}, "source": [ "## Reading\n", "Reader implemented in lenapy are an overlayer for the *xr.open_dataset()* function of xarray. To use this reader, you need to modify the argument *engine=* with *'lenapyGfc'* or *'lenapyGraceL2'*.\n", "\n", "The data are loaded into a dataset with 'clm' and 'slm' variables. If errors information are available they are load into 'eclm' and 'eslm' variables.\n", "\n", "Metadata informations are saved into attributs accesible with ds.attrs\n", "\n", "### ascii file with .gfc format reading\n", "File that follow the .gfc format can be read with lenapy (https://icgem.gfz-potsdam.de/docs/ICGEM-Format-2023.pdf) using *engine='lenapyGfc'*.\n", "\n", "If the model name (in the header of the .gfc file) does not contain date information, use no_date=True.\n", "\n", "The reader *'lenapyGfc'* can be given *date_regex* and *date_format* arguments to specify the exact date information. See the function documentation for more details.\n", "\n", "**You can download the corresponding files on the [ICGEM website](https://icgem.gfz-potsdam.de/sl/temporal).**\n", "\n", "### gfct temporal files\n", "If your .gfc file contains temporal informations in the format icgem1.0 or icgem2.0, it can be read with lenapy too.\n", "\n", "You then need to use the function *lenapy.utils.gravity.gfct_field_estimation()* to estimate the gravity field at certain dates." ] }, { "cell_type": "code", "execution_count": 33, "id": "d287106d-dcfe-4552-a9c9-8ec5a7ab2bd1", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
<xarray.Dataset> Size: 266kB\n",
"Dimensions: (l: 91, m: 91, time: 1)\n",
"Coordinates:\n",
" * l (l) int64 728B 0 1 2 3 4 5 6 7 8 ... 82 83 84 85 86 87 88 89 90\n",
" * m (m) int64 728B 0 1 2 3 4 5 6 7 8 ... 82 83 84 85 86 87 88 89 90\n",
" * time (time) datetime64[ns] 8B 2002-08-16T12:00:00\n",
"Data variables:\n",
" clm (l, m, time) float64 66kB ...\n",
" slm (l, m, time) float64 66kB ...\n",
" eclm (l, m, time) float64 66kB ...\n",
" eslm (l, m, time) float64 66kB ...\n",
" begin_time (time) datetime64[ns] 8B ...\n",
" end_time (time) datetime64[ns] 8B ...\n",
" exact_time (time) datetime64[ns] 8B ...\n",
"Attributes:\n",
" product_name: GSM-2_2002213-2002243_GRAC_COSTG_BF01_0100\n",
" earth_gravity_constant: 398600441500000.0\n",
" radius: 6378136.3\n",
" norm: 4pi\n",
" tide_system: tide_free\n",
" max_degree: 90\n",
" errors: empirical\n",
" modelname: GSM-2_2002213-2002243_GRAC_COSTG_BF01_0100<xarray.DataArray (latitude: 180, longitude: 360, time: 216)> Size: 112MB\n",
"array([[[11630332.05892523, 11630332.06934252, 11630332.0597365 , ...,\n",
" 11630332.17015108, 11630332.16923063, 11630332.17156417],\n",
" [11630331.75538494, 11630331.7658193 , 11630331.75623467, ...,\n",
" 11630331.86629094, 11630331.86535558, 11630331.867679 ],\n",
" [11630331.4635765 , 11630331.47402774, 11630331.46446525, ...,\n",
" 11630331.57416799, 11630331.5732176 , 11630331.57553061],\n",
" ...,\n",
" [11630333.03909915, 11630333.04946414, 11630333.03979841, ...,\n",
" 11630333.15131551, 11630333.15043901, 11630333.1528012 ],\n",
" [11630332.70087009, 11630332.71125268, 11630332.7016061 , ...,\n",
" 11630332.81275122, 11630332.8118602 , 11630332.81421313],\n",
" [11630332.37411554, 11630332.38451557, 11630332.3748889 , ...,\n",
" 11630332.48566647, 11630332.4847608 , 11630332.48710418]],\n",
"\n",
" [[11630336.80424296, 11630336.81584806, 11630336.80111835, ...,\n",
" 11630336.87797578, 11630336.87802749, 11630336.88231505],\n",
" [11630335.97134556, 11630335.98300739, 11630335.96834323, ...,\n",
" 11630336.04408688, 11630336.04409055, 11630336.0483456 ],\n",
" [11630335.17584039, 11630335.18755839, 11630335.17296209, ...,\n",
" 11630335.247602 , 11630335.24755729, 11630335.25177895],\n",
"...\n",
" [11631013.40432211, 11631013.40165253, 11631013.4877568 , ...,\n",
" 11631013.46079941, 11631013.4726309 , 11631013.4255675 ],\n",
" [11631014.06285 , 11631014.06016933, 11631014.14607235, ...,\n",
" 11631014.11848184, 11631014.1303246 , 11631014.08329308],\n",
" [11631014.73911098, 11631014.73641958, 11631014.82211618, ...,\n",
" 11631014.79386831, 11631014.80572307, 11631014.75872547]],\n",
"\n",
" [[11630980.07142463, 11630980.06895791, 11630980.1456611 , ...,\n",
" 11630980.07045177, 11630980.08356325, 11630980.04024149],\n",
" [11630980.33002579, 11630980.32755487, 11630980.40418232, ...,\n",
" 11630980.3286939 , 11630980.34181159, 11630980.29850394],\n",
" [11630980.5954498 , 11630980.59297472, 11630980.66952498, ...,\n",
" 11630980.59375007, 11630980.60687415, 11630980.56358121],\n",
" ...,\n",
" [11630979.337243 , 11630979.33478925, 11630979.41171071, ...,\n",
" 11630979.3372936 , 11630979.35038752, 11630979.30702721],\n",
" [11630979.57496637, 11630979.57250824, 11630979.64935845, ...,\n",
" 11630979.57468484, 11630979.58778443, 11630979.54443634],\n",
" [11630979.81971559, 11630979.81725314, 11630979.89403059, ...,\n",
" 11630979.81909289, 11630979.83219833, 11630979.78886309]]])\n",
"Coordinates:\n",
" * longitude (longitude) float64 3kB -179.5 -178.5 -177.5 ... 178.5 179.5\n",
" * latitude (latitude) float64 1kB -89.5 -88.5 -87.5 -86.5 ... 87.5 88.5 89.5\n",
" * time (time) datetime64[ns] 2kB 2002-04-16 ... 2022-12-16T12:00:00\n",
"Attributes:\n",
" units: mewh\n",
" max_degree: 12\n",
" radius: 6378136.3\n",
" earth_gravity_constant: 398600441500000.0<xarray.Dataset> Size: 61kB\n",
"Dimensions: (l: 61, m: 61)\n",
"Coordinates:\n",
" * l (l) int64 488B 0 1 2 3 4 5 6 7 8 9 ... 52 53 54 55 56 57 58 59 60\n",
" * m (m) int64 488B 0 1 2 3 4 5 6 7 8 9 ... 52 53 54 55 56 57 58 59 60\n",
" time datetime64[ns] 8B 2002-04-16\n",
"Data variables:\n",
" clm (l, m) float64 30kB -4.21e-14 0.0 0.0 ... 8.301e-28 -3.514e-28\n",
" slm (l, m) float64 30kB 0.0 0.0 0.0 ... -2.675e-27 4.305e-27 1.3e-27\n",
"Attributes:\n",
" gm_earth: 398600441500000.0\n",
" a_earth: 6378137.0\n",
" max_degree: 60\n",
" norm: 4pi