{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Assigning coords as dimension coordinates\n", "\n", "The `gridmarthe` package use \"horizontally reduced\" grids, which means that\n", "the spatial dimension is flattened. This is a common practice in geophysical\n", "modeling (meteorology, oceanography, land surface modelling, etc.), where the\n", "grid is often represented as a 1D array of points.\n", "\n", "Grids are often 2D in space (or 3D), but here represented as 1D vector of size\n", "`Nx*Ny` (or `Nx*Ny*Nz`). Each grid point is associated to an index and a set of\n", "coordinates (and `dx`, `dy`).\n", "\n", "This is particularly useful and efficient for computing on grids. But as a\n", "consequence, it is not straightforward to work with such data, especially when\n", "plotting.\n", "\n", "This notebooks explore how to move coordinates from variables (1D associated to\n", "indices) to coordinates (2D associated to dimensions)." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "# import package\n", "import gridmarthe as gm" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "# reading data and storing into Dataset object (with xarray)\n", "ds = gm.load_marthe_grid(\n", " './data/chasim_hallue.out', 'CHARGE',\n", " fpastp='./data/hallue.pastp',\n", " drop_nan=True\n", ")" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
<xarray.Dataset> Size: 2MB\n",
"Dimensions: (time: 205, zone: 927)\n",
"Coordinates:\n",
" * time (time) datetime64[ns] 2kB 1995-07-31 1995-08-01 ... 2012-07-01\n",
" * zone (zone) int32 4kB 255 256 257 258 259 ... 2722 2723 2724 2725 2726\n",
"Data variables:\n",
" charge (time, zone) float64 2MB 100.0 100.6 101.1 ... 27.0 26.0 26.35\n",
" x (zone) float32 4kB 617.8 618.2 618.8 619.2 ... 606.8 607.2 607.8\n",
" y (zone) float32 4kB 2.567e+03 2.567e+03 ... 2.543e+03 2.543e+03\n",
" dx (zone) float32 4kB 0.5 0.5 0.5 0.5 0.5 0.5 ... 0.5 0.5 0.5 0.5 0.5\n",
" dy (zone) float32 4kB 0.5 0.5 0.5 0.5 0.5 0.5 ... 0.5 0.5 0.5 0.5 0.5\n",
" izone (zone) int32 4kB 1 2 3 4 5 6 7 8 ... 921 922 923 924 925 926 927\n",
"Attributes: (12/17)\n",
" conventions: CF-1.10\n",
" title: Modélisation du bassin de la SOMME Nappe_Libre\n",
" marthe_grid_version: 9.0\n",
" original_dimensions: x,y,z [grids]: 53 54 1\n",
" crs: {'crs_wkt': 'PROJCRS["NTF (Paris) / Lambert zone II...\n",
" lon_resolution: 0.5\n",
" ... ...\n",
" period: 1995-2012\n",
" frequency: 30 day(s)\n",
" creation_date: Created on 2026-07-16T11:04:28Z UTC\n",
" comment: Hydrogeological model created with MARTHE code (Thi...\n",
" domain: FR-France\n",
" institution: BRGM, French Geological Survey, Orléans, France<xarray.Dataset> Size: 3MB\n",
"Dimensions: (y: 48, x: 44, time: 205)\n",
"Coordinates:\n",
" * y (y) float32 192B 2.567e+03 2.566e+03 ... 2.544e+03 2.543e+03\n",
" * x (x) float32 176B 599.2 599.8 600.2 600.8 ... 619.8 620.2 620.8\n",
" * time (time) datetime64[ns] 2kB 1995-07-31 1995-08-01 ... 2012-07-01\n",
"Data variables:\n",
" charge (time, y, x) float64 3MB nan nan nan nan nan ... nan nan nan nan\n",
" dx (y, x) float32 8kB nan nan nan nan nan nan ... nan nan nan nan nan\n",
" dy (y, x) float32 8kB nan nan nan nan nan nan ... nan nan nan nan nan\n",
" izone (y, x) float64 17kB nan nan nan nan nan nan ... nan nan nan nan nan\n",
"Attributes: (12/17)\n",
" conventions: CF-1.10\n",
" title: Modélisation du bassin de la SOMME Nappe_Libre\n",
" marthe_grid_version: 9.0\n",
" original_dimensions: x,y,z [grids]: 53 54 1\n",
" crs: {'crs_wkt': 'PROJCRS["NTF (Paris) / Lambert zone II...\n",
" lon_resolution: 0.5\n",
" ... ...\n",
" period: 1995-2012\n",
" frequency: 30 day(s)\n",
" creation_date: Created on 2026-07-16T11:04:28Z UTC\n",
" comment: Hydrogeological model created with MARTHE code (Thi...\n",
" domain: FR-France\n",
" institution: BRGM, French Geological Survey, Orléans, France<xarray.Dataset> Size: 2MB\n",
"Dimensions: (time: 205, zone: 927)\n",
"Coordinates:\n",
" * time (time) datetime64[ns] 2kB 1995-07-31 1995-08-01 ... 2012-07-01\n",
" * zone (zone) int64 7kB 38 39 40 41 42 43 ... 2082 2083 2084 2085 2086\n",
"Data variables:\n",
" charge (time, zone) float64 2MB 100.0 100.6 101.1 ... 27.0 26.0 26.35\n",
" dx (zone) float32 4kB 0.5 0.5 0.5 0.5 0.5 0.5 ... 0.5 0.5 0.5 0.5 0.5\n",
" dy (zone) float32 4kB 0.5 0.5 0.5 0.5 0.5 0.5 ... 0.5 0.5 0.5 0.5 0.5\n",
" izone (zone) float64 7kB 1.0 2.0 3.0 4.0 5.0 ... 924.0 925.0 926.0 927.0\n",
" y (zone) float32 4kB 2.567e+03 2.567e+03 ... 2.543e+03 2.543e+03\n",
" x (zone) float32 4kB 617.8 618.2 618.8 619.2 ... 606.8 607.2 607.8\n",
"Attributes: (12/17)\n",
" conventions: CF-1.10\n",
" title: Modélisation du bassin de la SOMME Nappe_Libre\n",
" marthe_grid_version: 9.0\n",
" original_dimensions: x,y,z [grids]: 53 54 1\n",
" crs: {'crs_wkt': 'PROJCRS["NTF (Paris) / Lambert zone II...\n",
" lon_resolution: 0.5\n",
" ... ...\n",
" period: 1995-2012\n",
" frequency: 30 day(s)\n",
" creation_date: Created on 2026-07-16T11:04:28Z UTC\n",
" comment: Hydrogeological model created with MARTHE code (Thi...\n",
" domain: FR-France\n",
" institution: BRGM, French Geological Survey, Orléans, France