{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Command line executable to convert Marthe Grid file to netCDF\n", "\n", "At the installation an executable `ncmart` is added to `PATH` and can be used to easily convert\n", "a Marthe grid file to NetCDF format.\n", "\n", "\n", "*nb: the next commands are shell commands, the '!' mark is only here for the python notebook version.*" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "vscode": { "languageId": "shellscript" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "usage: ncmart [-h] [--output OUTPUT] [--variable VARIABLE] [--as2d]\n", " [--xyfactor XYFACTOR] [--version]\n", " [grid timesteps ...]\n", "\n", "Convert a Marthe GridFile to netCDF format.\n", "\n", "positional arguments:\n", " grid timesteps Paths to grid and timesteps files are expected\n", "\n", "options:\n", " -h, --help show this help message and exit\n", " --output OUTPUT, -o OUTPUT\n", " Output filename. Default is input.nc\n", " --variable VARIABLE, -v VARIABLE\n", " Variable (field) to read, default is None; i.e\n", " variable will be parsed from file and ONLY the first\n", " variable will be read.\n", " --as2d, -d Store grid as 2D (or more), default is 1D for space\n", " dimension\n", " --xyfactor XYFACTOR, -x XYFACTOR\n", " Transformation factor for coordinates. Optionnal,\n", " default is 1 (no transformation).\n", " --version, -V Show version and exit\n", "\n", "gridmarthe Copyright (C) 2024 BRGM.\n", "This program comes with ABSOLUTELY NO WARRANTY.\n", "This is free software, see GNU General Public Lisence v3 for copying.\n" ] } ], "source": [ "# how to use: print help message\n", "!ncmart -h" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "vscode": { "languageId": "shellscript" } }, "outputs": [], "source": [ "# minimal setup: call ncmart with a grid file and a timestep file\n", "# this will write the output with input filename and 'nc' extension\n", "!ncmart ./data/chasim_hallue.out ./data/hallue.pastp" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "vscode": { "languageId": "shellscript" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "netcdf chasim_hallue {\n", "dimensions:\n", "\ttime = 205 ;\n", "\tzone = 927 ;\n", "variables:\n", "\tdouble charge(time, zone) ;\n", "\t\tcharge:_FillValue = NaN ;\n", "\t\tstring charge:varname = \"CHARGE\" ;\n", "\t\tstring charge:units = \"m\" ;\n", "\t\tcharge:missing_value = 9999. ;\n", "\t\tstring charge:standard_name = \"water_table_level\" ;\n", "\t\tstring charge:long_name = \"groundwater head\" ;\n", "\tfloat x(zone) ;\n", "\t\tx:_FillValue = NaNf ;\n", "\t\tstring x:units = \"m\" ;\n", "\t\tstring x:axis = \"X\" ;\n", "\t\tstring x:coverage_content_type = \"coordinate\" ;\n", "\tfloat y(zone) ;\n", "\t\ty:_FillValue = NaNf ;\n", "\t\tstring y:units = \"m\" ;\n", "\t\tstring y:axis = \"Y\" ;\n", "\t\tstring y:coverage_content_type = \"coordinate\" ;\n", "\tfloat dx(zone) ;\n", "\t\tdx:_FillValue = NaNf ;\n", "\tfloat dy(zone) ;\n", "\t\tdy:_FillValue = NaNf ;\n", "\tint64 time(time) ;\n", "\t\tstring time:units = \"days since 1995-07-31 00:00:00\" ;\n", "\t\tstring time:calendar = \"proleptic_gregorian\" ;\n", "\tint zone(zone) ;\n", "\n", "// global attributes:\n", "\t\tstring :conventions = \"CF-1.10\" ;\n", "\t\tstring :title = \"Modélisation du bassin de la SOMME Nappe_Libre\" ;\n", "\t\t:marthe_grid_version = 9. ;\n", "\t\tstring :original_dimensions = \"x,y,z [grids]: 53 54 1\" ;\n", "\t\tstring :lon_resolution = \"0.5\" ;\n", "\t\tstring :lat_resolution = \"0.5\" ;\n", "\t\t:scale_factor = 1. ;\n", "\t\tstring :nested_grid = \"False\" ;\n", "\t\tstring :extend = \"xymin : 596.75 2542.25; xymax: 622.75 2568.75\" ;\n", "\t\tstring :period = \"1995-2012\" ;\n", "\t\tstring :frequency = \"30 day(s)\" ;\n", "\t\tstring :creation_date = \"Created on 2025-03-26T13:28:35Z UTC\" ;\n", "\t\tstring :institution = \"BRGM, French Geological Survey, Orléans, France\" ;\n", "\t\tstring :comment = \"Hydrogeological model created with MARTHE code (Thiery, D. 2020. Guidelines for MARTHE v7.8 computer codefor hydro-systems modelling. report BRGM/RP-69660-FR).\" ;\n", "\t\tstring :resolution_units = \"m\" ;\n", "\t\tstring :projection = \"epsg:27572\" ;\n", "\t\tstring :domain = \"FR-France\" ;\n", "}\n" ] } ], "source": [ "# print variables headers and dimensions with netcdf/nco tools\n", "!ncdump -h ./data/chasim_hallue.nc" ] } ], "metadata": { "kernelspec": { "display_name": "gm", "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.11.2" } }, "nbformat": 4, "nbformat_minor": 2 }