Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
a25c521
WIP: Starting calc flow directions
Dec 2, 2025
8411cd0
Update calc_flow_directions help
Dec 2, 2025
7336251
Return xr.Dataset in calc_flow_directions
Dec 8, 2025
f5c5feb
Merge branch 'dev' into calc_dir_drainage-rebase
manlaya Dec 10, 2025
1584e36
Merge branch 'calc_dir_drainage-rebase' into 'dev'
manlaya Dec 10, 2025
d8d9143
change: automatic varname for writer as default #5
manlaya Jan 27, 2026
73ce797
fix: script - display usage if no arg/opt
manlaya Jan 27, 2026
c2bc739
fix y coords order in stack/assign coords #11 - only for regular grids
manlaya Jan 27, 2026
4e52954
code refactoring: reorganization of src, add ruff config
manlaya Jan 31, 2026
3e1da08
add: read shallow to force only 1st grid parsing
manlaya Jan 31, 2026
8bd104d
add: force write full grid if constant
manlaya Jan 31, 2026
edcd530
script: fix regex in cleanmgrid and add some missing variable #10
manlaya Jan 31, 2026
609ea0e
minor fix: get_scale + finish lint/refact attrs
manlaya Feb 2, 2026
ef33497
change: dummy time (param grids) to int + remove default variable 'ch…
manlaya Feb 2, 2026
2d9fe38
hotfix: minor bug in plots with coords attrs and time dimension
manlaya Feb 3, 2026
90360c5
refact: split pkg utils + check valid args in load_marthe_grid
manlaya Mar 7, 2026
fcde93f
River network
Feb 4, 2026
5230a0f
Fix output file UNIT
Feb 4, 2026
97ee8ed
English language messages
Feb 5, 2026
4978dc0
Add calc river network test
Feb 5, 2026
2ffa956
Calc river network docstring
Feb 26, 2026
0be8305
Rebase "river network" into "dev"
Feb 4, 2026
38764eb
Fix output file UNIT
Feb 4, 2026
f0ee010
Rebase banche river network into dev
Mar 11, 2026
58afe14
Correction of river network test after rebase
Mar 11, 2026
8e3fff1
Merge branch 'shuaitao/river_network' into 'dev'
manlaya Mar 16, 2026
46dafc9
add/fix: read grids with bad metadata without cleanmgrid
manlaya Mar 7, 2026
0cfb231
tests: revert bad data modif in read tests + change paths for river
manlaya Mar 21, 2026
4b4bf1f
Merge branch 'fix/read-wrong-metada' into 'dev'
manlaya Mar 21, 2026
890cb84
change: get_active_mask to return mask array + expose get_dims
manlaya Mar 23, 2026
ca78f27
doc minor update
manlaya Mar 21, 2026
7b642db
fix: read dates from pastp - force Series after squeeze
manlaya Mar 31, 2026
8286445
wrap get dims from attrs + minor doc modifs
manlaya Apr 8, 2026
07df4a7
fix compatibility with pathlib objects - fix #14
manlaya Apr 8, 2026
072c3b7
fix: add re.MULTILINE flag to read_rma regex
smagne-brgm Apr 9, 2026
0f2a5d8
fix: tests fails due to deprecated import name. Also fixed a wrong pa…
smagne-brgm Apr 9, 2026
29e6d1e
Merge branch 'fix-test-import' into 'dev'
smagne-brgm Apr 10, 2026
41e912a
Merge branch 'cleanmgrid-fix-regex' into 'dev'
smagne-brgm Apr 10, 2026
719c9a7
doc: update src install instructions, contributors and changelog
manlaya Apr 29, 2026
e384e36
doc: update readthedoc image
manlaya Apr 29, 2026
d1a211b
doc: general minor update
manlaya Apr 30, 2026
b14b181
fix: resolve FileNotFoundError in read_files_from_rma with bare filen…
smagne-brgm May 22, 2026
8596af8
Merge branch 'fix/issue-17-rma-relative-path' into 'dev'
manlaya May 22, 2026
58766f4
test: add conftest for shared config
manlaya May 22, 2026
d4dd145
fix: error when re-writing netcdf #16
manlaya May 22, 2026
ebe5e24
test: add cov and benchmark opt, fix warnings and some linting
manlaya May 26, 2026
ca53832
chore: bump version for 0.4
manlaya May 26, 2026
becb9f1
build: drop python 3.10 support
manlaya May 26, 2026
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
21 changes: 21 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# EditorConfig is awesome: https://editorconfig.org
# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.py]
indent_style = space
indent_size = 4
charset = utf-8

[Makefile]
indent_style = tab

[*.yml,*.yaml]
indent_style = space
indent_size = 2
13 changes: 8 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ __pycache__/
*.py[cod]
*$py.class

# C extensions
# C/F90 extensions
*.so
*.o
*.mod
*.pyd
*.dll
Expand Down Expand Up @@ -114,8 +115,6 @@ celerybeat.pid
env/
venv/
ENV/
env.bak/
venv.bak/
.venvrc

# Spyder project settings
Expand Down Expand Up @@ -145,7 +144,11 @@ cython_debug/
# vscodes
.vscode


*.bak
*.out
dev/
*.out
test-read
Cal_river_network.listing

.benchmarks/

17 changes: 4 additions & 13 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
version: 2

build:
os: "ubuntu-22.04"
os: "ubuntu-24.04"
tools:
python: "3.10"
python: "3.12"
apt_packages:
- gcc
- gfortran
Expand All @@ -15,17 +15,8 @@ build:
jobs:
pre_build:
- pip install numpy charset_normalizer meson meson-python
#- cd src/gridmarthe/lecsem ; CC=gcc FC=gfortran f2py -c lecsem.f90 edsemigl.f90 scan_grid.f90 -m lecsem --backend=meson --lower
- pip install .[gis,doc]
- pip install .[opt,doc]
- python3 -c "import gridmarthe"

# python:
# install:
# - method: pip
# path: .
# extra_requirements:
# - gis
# - doc

sphinx:
configuration: docs/source/conf.py
configuration: docs/source/conf.py
73 changes: 38 additions & 35 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# --------------------------------- #
#####################################
# ONLY FOR LINUX DEVELOP MODE #
# OR CONDA SRC INSTALL #
#####################################

FC := gfortran
Expand All @@ -20,61 +19,63 @@ F2PY = $(PY) -m numpy.f2py

###### SOURCES ########
MAINDIR := $(shell pwd)
F90SRCDIR := $(MAINDIR)/src/gridmarthe/lecsem
F90FILES := lecsem.f90 edsemigl.f90 scan_grid.f90
F90SRCDIR := $(MAINDIR)/src/gridmarthe/core

F90FILES := $(F90SRCDIR)/lecsem/lecsem.f90 \
$(F90SRCDIR)/lecsem/edsemigl.f90 \
$(F90SRCDIR)/utils/xy_dxdy.f90 \
$(F90SRCDIR)/flowdirect/analy_topo.f90 \
$(F90SRCDIR)/flowdirect/calc_direct_drainage.f90 \
$(F90SRCDIR)/flowdirect/num_8_voisins.f90 \
$(F90SRCDIR)/rivernetwork/Cal_reseau_hydro.f90 \
$(F90SRCDIR)/rivernetwork/Convert_Direct_Drain.f90 \
$(F90SRCDIR)/rivernetwork/Definit_Sous_Bassins.f90 \
$(F90SRCDIR)/rivernetwork/Dir_Drain_LigCol_Ava.f90 \
$(F90SRCDIR)/rivernetwork/Direct_Drain_Mai_Ava.f90 \
$(F90SRCDIR)/rivernetwork/Mai_Ava_Strahl_Surf_Drai.f90 \
$(F90SRCDIR)/rivernetwork/Mai_Exu_Surf_Drai.f90 \
$(F90SRCDIR)/rivernetwork/Verif_Surf_Stat_Hydro.f90 \
$(F90SRCDIR)/dessin/colle_segments.f90 \
$(F90SRCDIR)/modgridmarthe.f90
#######################

# editable
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

# These flags are now only used when compiling shared library
# These flags are now only used when compiling shared library for testing
# NOT for install (editable or not): build opt are in meson.build
FFLAGS =
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
# FFLAGS += -shared # => bug
FFLAGS += -ffree-line-length-none
# only gfortran > 12.0
# 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)
# legacy is not really necessary
# FFLAGS += -std=legacy

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

# ------------- Rules ------------- #

.PHONY: all docs clean requirements wheel
# all: clean install bakup_pyproj
.PHONY: all doc clean requirements editable meson wheel sdist
all: clean editable

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


doc:
cd docs; $(MAKE) html

# deprecated
# setuptools: pyproject.toml
# cp pyproject.toml pyproject.bak ; sed -i '16s/# //' pyproject.toml ; sed -i '17s/^/# /' pyproject.toml
# # change to setuptools for editable version
#
# bakup_pyproj: pyproject.toml
# mv pyproject.bak pyproject.toml
# # format pyproject.{toml,bak} non accepté par make ?

requirements:
$(PY) -m pip install charset_normalizer numpy meson meson-python
$(PY) -m pip install charset_normalizer numpy meson meson-python pytest

#install: requirements lecsem.so setuptools bakup_pyproj
# $(PY) -m pip install $(PIPFLAGS) . -vvv
conda-req:
mamba install charset-normalizer numpy meson meson-python pytest h5netcdf xarray pandas geopandas

lecsem.pyf:
cd $(F90SRCDIR); echo "******** Generating signature ********"; \
Expand All @@ -83,19 +84,22 @@ lecsem.pyf:
lecsem.so:
cd $(F90SRCDIR); echo "******** Building F2PY Library ********"; \
$(COMPILE)
# use of `cd` and not $(F90SRCDIR)/lecsem, even if not a good practice in Makefile,

# 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 \
editable:
$(PY) -m pip install --no-build-isolation --no-deps \
--config-settings=editable-verbose=true \
--config-settings=setup-args='-Dpip_edit_mode=true' \
--editable . \
-vvv

meson:
rm -rf build/ ; meson setup build; cd build; meson compile

wheel:
$(PY) -m pip install build
$(PY) -m build -w
Expand All @@ -108,4 +112,3 @@ clean:
cd $(F90SRCDIR); \
rm -f *.so *.o *.mod *.c *pywrappers* *.dll *.pyd ; \
cd $(MAINDIR)

66 changes: 38 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,39 +36,36 @@ Still, as Marthe meshes are always parallelepiped, the array does *not* necessar
[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.
The `x`, and `y` coordinates are the center of cell. `dx`, `dy` are the dimensions of the cell.


## Installation

### From pip


On pip, `gridmarthe` is available for GNU/Linux, macOS and Windows for python >=3.10.
On pip, `gridmarthe` is available for GNU/Linux, and Windows for python >=3.10.
Users can install it with:

```bash
pip install gridmarthe
# or with all optional dependencies
pip install gridmarthe[opt]
```

For GNU/Linux and MacOS, the package needs gfotran/gcc to run.

Linux, example with debian/ubuntu:
For UNIX systems, the package needs gfortran/gcc shared libraries to run.
For example, using a Debian-based GNU/Linux distribution, one can install
gcc with:

```bash
sudo apt install gcc gfortran
```


MacOS:

```bash
brew install gcc gfortran
```

### From conda-forge

`gridmarthe` is also available in the `conda-forge` channel. Conda users can install it with:
`gridmarthe` is also available in the `conda-forge` channel (Linux, Windows).
Conda users can install it with:

```bash
conda install gridmarthe
Expand All @@ -79,8 +76,8 @@ mamba install gridmarthe

### From sources

`gridmarthe` use some Fortran modules which need
to be compiled before local installation.
`gridmarthe` use some Fortran modules which need to be compiled before local installation,
hence user/developer who want to install from sources will need a Fortran and a C compiler.

#### Compilation and installation

Expand All @@ -93,49 +90,54 @@ cd gridmarthe

##### With pip (Unix-like OS)

On a Unix-like machine, with gfortran, ninja-build, python3, the project `Makefile` will compile Fortran sources and install
**in development mode** the package.
On a Unix-like machine, with gfortran, ninja-build, python3, the project `Makefile` will compile
Fortran sources and install **in development mode** (i.e. **with** editable flag) the package.

```bash
make requirements
make
```

or, without the development mode :
or, *without* the development/editable mode :

```bash
pip install .
```

On a windows machine, it is possible to compile with gfortran
(mingw project https://mingw-w64.org/ or https://winlibs.com/#download-release ; or `choco install mingw`).
Neverless, the simpliest way is to use a conda environment (miniforge with mambalib is recommended) to install gcc/gfortran,
and install the project.
On a Windows machine, it is possible to compile with gfortran/gcc
(mingw project https://mingw-w64.org/ or https://winlibs.com/#download-release ;
it can also be installed with chocolatey `choco install mingw`, or with conda
with conda-forge packages `mingw-w64`, `gcc` and `gfortran`).


##### With conda (recommended on Windows)

It is also possible to install gridmarthe in a conda environment. An environment file is provided (example with mamba):
It is also possible to install gridmarthe in a conda environment.
An environment file is provided (example with mamba):

```bash
mamba env create -n gm -f environment.yml
mamba activate gm
pip install --no-deps .
make
```

Here, the development mode is *not* available (yet, with the meson build).
One can add the `-e` flag in pip command, or use `conda-build`:
This will install the library using pip editable mode, but with dependencies
installed from conda-forge.

Alternatively, you can use `conda-build`:

```bash
mamba env create -n gm -f environment.yml
mamba activate gm
mamba install conda-build
make lib
make lib # only compile shared library for python bindings
conda develop src/
```


## Usage

Simple examples can be found in the
Simple examples can be found in the
[documentation](https://gridmarthe.readthedocs.io/en/stable/user_guide/index.html).


Expand All @@ -147,7 +149,15 @@ This program is free software and released under the terms of the

## Authors and acknowledgment

A. Manlay and J.P. Vergnes, (c) BRGM
gridmarthe is released by (C) BRGM, French Geological Survey

Authors and contributors:

- A. Manlay,
- J.P. Vergnes,
- S. Wang,
- S. Lopez,
- S. Magne


## References
Expand Down
Loading
Loading