Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
aeea918
change: remove xarray accessor class, move this to martpy wrapper pro…
manlaya Oct 11, 2025
48986d8
fix gridmarthe#3 : add dimensions verification in write_marthe_grid
manlaya Oct 11, 2025
8200249
fix gridmarthe#4 : revert v0.1.3 modification of zone index when drop…
manlaya Oct 11, 2025
7034def
minor updates: docstrings, tests, setup
manlaya Oct 11, 2025
9c2c4da
fix plot oucrop colorbar/cmap, allow custom cmap
manlaya Oct 11, 2025
81a780e
wip: improve raster export
manlaya Oct 11, 2025
08f7066
doc: general update, fix nb dark theme, and update docstrings
manlaya Oct 11, 2025
a78c5c1
better error management in write_marthe_grid, rename args in load_mar…
manlaya Oct 11, 2025
f7864a4
fix gridmarthe #1: fix bad reading of coordinates with exported .sem …
manlaya Oct 11, 2025
e013e7e
add/wip: beta support support for vtk export, ref gridmarthe#2
manlaya Oct 11, 2025
9974ee1
change: rename lig to row in dataset attributes
manlaya Nov 19, 2025
3317c6a
update scripts: add options to modify netcdf
manlaya Nov 19, 2025
20c8630
update netcdf attrs of marthe grids
manlaya Nov 19, 2025
1a10cd5
add: support for reading/plotting velocity
manlaya Nov 19, 2025
e8a23b8
add: (beta) support for cross sections
manlaya Nov 19, 2025
abc95dc
doc: general update (docstrings+ add/update examples)
manlaya Nov 19, 2025
edadc76
build: update build config, editable option, changelog
manlaya Nov 19, 2025
c3238ca
tests: general update + add assign_coords, veloc, cross_sect
manlaya Nov 19, 2025
ba140be
fix: revert change to UTC from datetime if py<311
manlaya Nov 19, 2025
dbd265b
clean main module/attrs
manlaya Dec 6, 2025
ad86191
add data for doc/test, update changelog
manlaya Dec 9, 2025
a0fdbd1
update version to 0.3
manlaya Dec 9, 2025
088eefe
ci: drop macos build (gh ci), add future version of ci with gitlab
manlaya Dec 9, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
matrix:
# mac os 14 at least - runner with Apple Silicon
os: [ubuntu-latest, windows-latest, macos-14]
os: [ubuntu-latest, windows-latest] # macos-14, drop mac-os build
env:
FC: gfortran
GCC_V: 12 # only for MACOS
Expand Down Expand Up @@ -61,7 +61,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
python-version: "3.12"

- name: Install cibuildwheel
run: pip install cibuildwheel
Expand Down
140 changes: 140 additions & 0 deletions .gitlab_brgm-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
# Gitlab CI config - Courtesy of T. Janvier (BRGM)
default: # linux image on linux runnner
image: nexus-docker.brgm.fr/brgm/miniconda3:latest
tags:
- brgm

.windows: # windows image on windows runnner
image: nexus-docker.brgm.fr/brgm/miniconda3:windows
tags:
- windows-2022-docker


stages:
- build
- test
- deploy


.version_tag:
only: # see https://peps.python.org/pep-0440/
variables:
- $CI_COMMIT_TAG =~ /^(?P<epoch>\D+)?(?P<version>(?P<release>\d+(?:\.\d+)*)(?P<pre>(?:a|b|rc)\d+?)?((?P<post>\.post\d+))?(?P<dev>\.dev\d+)?(?P<build>\+\S+)?)$/
except:
- branches


# ----- Build ----- #

.build:
stage: build
extends: .version_tag
when: manual
script:
# build multiple versions using cibuildwheel
# - python -m cibuildwheel --output-dir ./dist
# build standalone environment for testing (current package + all dependencies)
# - python -m pip wheel -w ./dist/wheelhouse .[test]
- python -m pip wheel -w ./dist/ .
artifacts:
paths:
- dist/
expose_as: wheel
expire_in: 12 hours


build-linux:
when: manual
extends: .build
before_script:
- echo "gridmarthe ci/cd pipeline"
- python --version
- mamba install gfortran
- gfortran --version
- python -m pip install --upgrade pip setuptools wheel
- python -m pip install cibuildwheel build
# uncomment next line if you need internal dependencies
# - python -m pip config set global.index-url ${REGISTRY_NEXUS}/pypi-all/simple

build-windows:
when: manual
extends:
- .windows
- .build
before_script:
- echo "gridmarthe ci/cd pipeline"
- python --version
- gfortran --version
- pip install --upgrade pip setuptools wheel
- pip install cibuildwheel build


# ----- Test config ----- #

.test:
stage: test
extends: .version_tag
when: manual
script:
# - python -c 'import gridmarthe'
- pytest tests/
# allow_failure: true


test-linux:
needs: ["build-linux"]
extends: .test
before_script:
- echo "gridmarthe ci/cd pipeline"
- python --version
- mamba install gfortran
- gfortran --version
- python -m pip install --no-index --no-deps dist/*none*.whl # no-index: avoid search pypi index ; no-deps, wheels already build
- python -m pip install --no-index --no-deps dist/*linux*.whl


test-windows:
needs: ["build-windows"]
extends:
- .windows
- .test
before_script:
- echo "gridmarthe ci/cd pipeline"
- python --version
- gfortran --version
- pip install --no-index --no-deps dist/*none*.whl
- pip install --no-index --no-deps dist/*win*.whl



# ----- Publish ----- #

.deploy:
extends: .version_tag
stage: deploy
except:
- branches


deploy-nexus_snapshot:
needs: ["build-linux", "build-windows"]
extends: .deploy
before_script:
- echo ${NEXUS_URL}
- echo ${REGISTRY_NEXUS_USER}
- echo ${REGISTRY_NEXUS}
- pip install twine
script:
- twine upload -u ${REGISTRY_NEXUS_USER} -p ${REGISTRY_NEXUS_PASSWORD} --repository-url ${REGISTRY_NEXUS}/pypi-snapshots/ dist/*.whl
when: manual


deploy-pip:
needs: ["build-linux", "build-windows"]
extends: .deploy
before_script:
- pip install twine
script:
- twine upload --skip-existing --verbose dist/*.whl
when: manual

42 changes: 25 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# --------------------------------- #
#####################################
# ONLY FOR LINUX DEVELOP MODE #
# OR CONDA INSTALL #
# OR CONDA SRC INSTALL #
#####################################

FC := gfortran
Expand All @@ -25,21 +25,25 @@ F90FILES := lecsem.f90 edsemigl.f90 scan_grid.f90
#######################

# editable
# PIPFLAGS ?= --no-build-isolation --editable # meson build version / not functionnal
PIPFLAGS ?= -e
#Flags: Warning: flags significantly increase wall-clock and CPU time.
#Flags are primarily useful for initial check that code compiles correctly
F2PYOPT =--backend=meson --lower

FFLAGS = -fdefault-real-8
# These flags are now only used when compiling shared library
# NOT for install (editable or not): build opt are in meson.build
FFLAGS =
FFLAGS += -fdefault-real-8
# already O3 in f2py, change it here
FFLAGS += -O2
# FFLAGS += -O2
# Position-Independent Code, si shared library, utile
# FFLAGS +=-fPIC -shared
FFLAGS +=-fPIC -shared
FFLAGS += -ffree-line-length-none
# FFLAGS +=-fallow-argument-mismatch # only gfortran > 12.0
# FFLAGS += -std=legacy # not really necessary
# FFLAGS +=-static # only windows // and not for dev
# only gfortran > 12.0
FFLAGS +=-fallow-argument-mismatch
# legacy is not really necessary ?
FFLAGS += -std=legacy


COMPILE = CC=$(CC) FC=$(FC) FFLAGS="$(FFLAGS)" $(F2PY) -c $(F90FILES) -m lecsem $(F2PYOPT)

Expand All @@ -49,6 +53,7 @@ COMPILE = CC=$(CC) FC=$(FC) FFLAGS="$(FFLAGS)" $(F2PY) -c $(F90FILES) -m lecsem
.PHONY: all docs clean requirements wheel
# all: clean install bakup_pyproj
all: clean editable

# only compile with f2py for develop purpose
lib: lecsem.so

Expand Down Expand Up @@ -78,15 +83,18 @@ lecsem.pyf:
lecsem.so:
cd $(F90SRCDIR); echo "******** Building F2PY Library ********"; \
$(COMPILE)
# cd $(MAINDIR)
# use of `cd` and not $(F90SRCDIR)/lecsem, even if not a good practice in Makefile,
# because meson/f2py does not allow path separator in files.
# FC="$(FC)" FFLAGS="$(FFLAGS)" python -m numpy.f2py -c lecsem.pyf lecsem.f90 edsemigl.f90 scan_grid.f90 -m lecsem --backend=meson --lower

# meson editable for test
editable: requirements
$(PY) -m pip install --no-build-isolation --config-settings=editable-verbose=true --editable . -vvv
# meson version of editable - for future replacement of setuptools

# use of `cd` and not $(F90SRCDIR)/lecsem, even if not a good practice in Makefile,
# because meson/f2py does not allow path separator in files.
# FC="$(FC)" FFLAGS="$(FFLAGS)" python -m numpy.f2py -c lecsem.pyf lecsem.f90 edsemigl.f90 scan_grid.f90 -m lecsem --backend=meson --lower

# meson editable for dev/testing
editable: #requirements
$(PY) -m pip install --no-build-isolation \
--config-settings=editable-verbose=true \
--config-settings=setup-args='-Dpip_edit_mode=true' \
--editable . \
-vvv

wheel:
$(PY) -m pip install build
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ The package also install different command line tools: `ncmart` to convert Marth

Full documentation and tutorials can be founded at https://gridmarthe.readthedocs.io

Grids are stored as a 2 dimensions matrix composed of a 1D spatial vector and a time dimension
(Reduced Horizontal Grid, as recommended for lossless compression by gathering
in cf-conventions: see [cf-compression-gathering](https://cfconventions.org/Data/cf-conventions/cf-conventions-1.11/cf-conventions.html#compression-by-gathering)
and [cf-reduced-horizontal-grid](https://cfconventions.org/Data/cf-conventions/cf-conventions-1.11/cf-conventions.html#reduced-horizontal-grid)).
This means that the spatial domain is flatten in grid, and each point is associated
with a index, a x coordinate, a y coordinate, eventually a z coordinate (number of layer
in most cases), and dx, dy values.

Still, as Marthe meshes are always parallelepiped, the array does *not* necessarily follow the
[ugrid convention](https://ugrid-conventions.github.io/ugrid-conventions/).
This may be an evolution for future version if required.

The x, and y coordinates are the center of cell. Dx, Dy are the dimension of the cell.


## Installation

Expand Down
43 changes: 39 additions & 4 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,54 @@
<!-- gridmarthe changelog -->

v0.3.0
------

Released on 2025-12-09

* add: beta support for vtk export, based on [vtkwriters](https://gitlab.com/brgm/geomodelling/io/vtkwriters) from ComPass code python ecosystem
* add: support for reading/plotting velocity field : `gm.read_velocity`, `gm.plot_veloc_quiver`
* add: beta support for cross section
* change: attributes in netcdf to be more CF-Conventions compliant:
- add crs attributes using `pyrpoj.CRS().to_cf()` for QGIS view compatibilty --> add argument `epsg` in `gm.load_grid_marthe`
- add `compress` attribute for zone [https://cfconventions.org](https://cfconventions.org/Data/cf-conventions/cf-conventions-1.11/cf-conventions.html#reduced-horizontal-grid),
- fix attributes for coordinates x,y,z / add argument `full_3d` to set z attributes
- force attributes for x,y,z to be kept when `gm.assign_coords`
* add: options to `ncmart` script:
- `--dump` (`-H`) to mimic `ncdump -H` command (netcdf CLI tools).
- `--attrs` (`-a`) to add global attributes
- treat input if already in netcdf fmt (modify it, with scale factor or attrs, to 2D, etc)


v0.2.0
------

<!-- Released on 2025-XX-XX -->
Unreleased - dev version.

* fix: error when writing grid with time slice (cf. [issue #3](https://gitlab.com/brgm/hydrogeological-modelling/marthe-tools/gridmarthe/-/issues/3))
* fix: REVERT change from 0.1.3 : zone index is NOT reset (as in 0.1.2 and previous versions).
when the `drop_nan` option is used in `load_grid_marthe()`.
A new variable 'izone' store the reset form.
See [issue #4](https://gitlab.com/brgm/hydrogeological-modelling/marthe-tools/gridmarthe/-/issues/4)
* change: `nanval` argument in `load_marthe_grid` is rename to `nan_value` as in `write_marthe_grid`
* change: `keepligcol` argument in `load_marthe_grid` is rename to `add_col_row` to be more coherent with `add_id_grid`
* change: `xr.Dataset.mart` class accessor is removed. It will be included as wrapper in future marthe python library.


v0.1.3
------

Released on 2025-09-02

* add geometry functions (get_mask_array, compute_geometry)
* minor fixes in plot method
* add geometry functions (`get_mask_array`, `compute_geometry`)
* add reprojection functions (still experimental)
* add `martshp` script to easily convert a marthe grid file into a shp/gpkg file in command line
* code refactoring (lecsem module and global organization)
* add automatic tests
* minor fixes in plot method
* change: rename function to write raster: `to_raster()` instead of `write_raster_from_da()`
* change: zone index is reset when the `drop_nan` option is used in `load_grid_marthe()`. A new
variable 'zone_all' store the old index for the `reset_geometry()` method
* code refactoring (lecsem module and global organization)
* add automatic tests


v0.1.2
Expand Down
51 changes: 14 additions & 37 deletions docs/source/_static/custom.css
Original file line number Diff line number Diff line change
@@ -1,47 +1,24 @@
/* Main index page overview cards */
.sd-card-img-top {
width: 33% !important;
display: block;
margin-left: auto;
margin-right: auto;
margin-top: 10px;
}

/* customise nbsphinx ----------------------------------------------- */
div.nbinput.container div.prompt pre,
div.nbinput.container div.prompt pre > code {
color: var(--pst-color-primary);
}

div.nboutput.container div.prompt pre,
div.nboutput.container div.prompt pre > code {
color: var(--pst-color-secondary);
}

div.nbinput.container div.input_area {
border: 1px solid var(--pst-color-border);
}

div.rendered_html table {
color: var(--pst-color-text-base);
}

div.rendered_html thead {
border-bottom: 1px solid var(--pst-color-border);
/* More prominent card borders */
.sd-card {
border: 2px solid var(--pst-color-border) !important;
border-radius: 3px !important;
}

div.rendered_html tbody tr:nth-child(odd) {
background: var(--pst-color-surface);
/* fly you fool ! survol */
.sd-card:hover {
border-color: var(--bs-purple) !important;
/* sinon voir les couleurs de _static/pydata-sphinx-theme.css à la build */
}

div.rendered_html tbody tr:hover {
background: var(--pst-color-accent-bg);
}

html[data-theme="dark"] .bd-content .nboutput .output_area.rendered_html {
background-color: transparent;
/* from xarray's doc */
html[data-theme="dark"] div.cell_output .text_html:has(div.xr-wrap) {
background-color: var(--pst-color-on-background) !important;
color: var(--pst-color-text-base) !important;
}

/* Modified from Rameau's doc */
/* customise footer ------------------------------------------------- */
.bd-footer .footer-items__end, .bd-footer .footer-items__start {
gap: 0;
Expand Down Expand Up @@ -84,4 +61,4 @@ a.navbar-corporate, a.navbar-corporate:hover {
/* reduce margin */
.navbar-nav {
margin: 0;
}
}
1 change: 1 addition & 0 deletions docs/source/api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ left-hand menu you will find the different categories of the API documentation.
:maxdepth: 2

io_operations
utils_func
operasem
plotting
2 changes: 2 additions & 0 deletions docs/source/api/io_operations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ IO operations
load_marthe_grid

write_marthe_grid

read_velocity
Loading
Loading