Skip to content

Commit

Permalink
Merge pull request #86 from Deltares/experimental-release
Browse files Browse the repository at this point in the history
Experimental release
  • Loading branch information
xldeltares authored Sep 22, 2023
2 parents b8aef16 + fc53afc commit 791d5c5
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 25 deletions.
117 changes: 117 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
---
name: Build and Upload hydromt-delft3dfm to PyPI

on:
release:
types:
- published
push:
tags:
- 'v*'


jobs:
build-artifacts:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: actions/setup-python@v4
name: Install Python
with:
python-version: 3.9

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flit wheel twine
- name: Build tarball and wheels
run: |
git clean -xdf
git restore -SW .
flit build
- name: Check built artifacts
run: |
python -m twine check dist/*
pwd
- uses: actions/upload-artifact@v3
with:
name: releases
path: dist

test-built-dist:
needs: build-artifacts
runs-on: ubuntu-latest
defaults:
run:
shell: bash -l {0}
steps:
- uses: actions/checkout@v2
- uses: actions/download-artifact@v3
with:
name: releases
path: dist
- name: List contents of built dist
run: |
ls -ltrh
ls -ltrh dist
- name: Setup environment
uses: conda-incubator/setup-miniconda@v2
with:
python-version: "3.9"
mamba-version: "*"
channels: conda-forge,defaults
channel-priority: true
environment-file: envs/hydromt-delft3dfm-min.yml
activate-environment: hydromt-delft3dfm

- name: Conda info
run: |
conda info
conda list
- name: Verify the built dist/wheel is valid
run: |
python -m pip install dist/hydromt_delft3dfm*.whl
python -c 'from hydromt_delft3dfm import __version__ as v; print(v)'
echo "hydromt --models"
upload-to-test-pypi:
needs: test-built-dist
if: github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v3
with:
name: releases
path: dist
- name: Publish package to TestPyPI
uses: pypa/[email protected]
with:
user: __token__
password: ${{ secrets.PYPI_TEST_TOKEN }}
repository_url: https://test.pypi.org/legacy/
verbose: true
skip_existing: true

upload-to-pypi:
needs: test-built-dist
if: github.event_name == 'release'
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v3
with:
name: releases
path: dist
- name: Publish package to PyPI
uses: pypa/[email protected]
with:
user: __token__
password: ${{ secrets.PYPI_TOKEN }}
verbose: true
18 changes: 10 additions & 8 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@ All notable changes to this project will be documented in this page.
The format is based on `Keep a Changelog`_, and this project adheres to
`Semantic Versioning`_.

Unreleased
==========
v0.1.0 (22 September 2023)
==========================
First experimental release of functionalities to build and update Delft3D FM 1D2D models.

Added
-----

Changed
-------

Fixed
-----
- Setup 1D network including rivers, channels and pipes;
- Setup 1D network components including manholes, bridges and culverts
- Setup 1D forcings including boundary and laterals.
- Setup 2D mesh and refine 2D mesh.
- Setup 2D maps including bedlevels, roughness, infiltration capacity, etc.
- Setup 2D forcings including boundary and precipitation.
- Setup 1D2D links.

.. _Keep a Changelog: http://keepachangelog.com/en/1.0.0/
.. _Semantic Versioning: http://semver.org/spec/v2.0.0.html
27 changes: 27 additions & 0 deletions envs/hydromt-delft3dfm-min.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
# note that these are the developer dependencies
name: hydromt-delft3dfm

channels:
- conda-forge

dependencies:
- flit>=3.4
- geopandas
- hydromt>= 0.8.0
- numpy
- pandas
- pip
- pyflwdir >=0.5.4
- pyproj
- python=3.9.*
- scipy
- shapely>=2.0.0
- xarray
- xugrid
- networkx
- llvmlite>=0.39.1 # hydrolib-core
- pip:
- git+https://github.com/Deltares/hydromt.git
- hydrolib-core==0.5.2
- meshkernel==2.0.2 # temp pin because of hydrolib-core
2 changes: 1 addition & 1 deletion hydromt_delft3dfm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from os.path import abspath, dirname, join

__version__ = "0.1.0.dev"
__version__ = "0.1.0"

DATADIR = join(dirname(abspath(__file__)), "data")

Expand Down
22 changes: 11 additions & 11 deletions hydromt_delft3dfm/dflowfm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2515,7 +2515,7 @@ def write_config(self) -> None:
"""From config dict to Hydrolib MDU."""
# Not sure if this is worth it compared to just calling write_config super method
# advantage is the validator but the whole model is then read when initialising FMModel
self._assert_write_mode
self._assert_write_mode()

cf_dict = self._config.copy()
# Need to switch to dflowfm folder for files to be found and properly added
Expand All @@ -2533,7 +2533,7 @@ def write_config(self) -> None:

def read_maps(self) -> Dict[str, Union[xr.Dataset, xr.DataArray]]:
"""Read maps from initialfield and parse to dict of xr.DataArray."""
self._assert_read_mode
self._assert_read_mode()
# Read initial fields
inifield_model = self.dfmmodel.geometry.inifieldfile
if inifield_model is not None:
Expand Down Expand Up @@ -2590,7 +2590,7 @@ def write_maps(self) -> None:
if len(self._maps) == 0:
self.logger.debug("No maps data found, skip writing.")
return
self._assert_write_mode
self._assert_write_mode()
# Global parameters
mapsroot = join(self.root, "maps")
inilist = []
Expand Down Expand Up @@ -2688,7 +2688,7 @@ def read_geoms(self) -> None: # FIXME: gives an error when only 2D model.
For branches / boundaries etc... the reading of hydrolib-core objects happens in read_mesh
There the geoms geojson copies are re-set based on dflowfm files content.
"""
self._assert_read_mode
self._assert_read_mode()
super().read_geoms(fn="geoms/region.geojson")

if self.dfmmodel.geometry.crosslocfile is not None:
Expand Down Expand Up @@ -2721,7 +2721,7 @@ def read_geoms(self) -> None: # FIXME: gives an error when only 2D model.

def write_geoms(self, write_mesh_gdf=True) -> None:
"""Write model geometries to a GeoJSON file at <root>/<geoms>."""
self._assert_write_mode
self._assert_write_mode()

# Optional: also write mesh_gdf object
if write_mesh_gdf:
Expand Down Expand Up @@ -2779,7 +2779,7 @@ def read_forcing(
self,
) -> None: # FIXME reading of forcing should include boundary, lateral and meteo
"""Read forcing at <root/?/> and parse to dict of xr.DataArray."""
self._assert_read_mode
self._assert_read_mode()
# Read external forcing
ext_model = self.dfmmodel.external_forcing.extforcefilenew
if ext_model is not None:
Expand Down Expand Up @@ -2835,7 +2835,7 @@ def write_forcing(self) -> None:
if len(self._forcing) == 0:
self.logger.debug("No forcing data found, skip writing.")
else:
self._assert_write_mode
self._assert_write_mode()
self.logger.info("Writting forcing files.")
savedir = dirname(join(self.root, self._config_fn))
# create new external forcing file
Expand All @@ -2849,7 +2849,7 @@ def write_forcing(self) -> None:

def read_mesh(self):
"""Read network file with Hydrolib-core and extract mesh/branches info."""
self._assert_read_mode
self._assert_read_mode()

# Read mesh
# hydrolib-core convention
Expand Down Expand Up @@ -2892,7 +2892,7 @@ def read_mesh(self):

def write_mesh(self, write_gui=True):
"""Write 1D branches and 2D mesh at <root/dflowfm/fm_net.nc> in model ready format."""
self._assert_write_mode
self._assert_write_mode()
savedir = dirname(join(self.root, self._config_fn))
mesh_filename = "fm_net.nc"

Expand Down Expand Up @@ -2986,7 +2986,7 @@ def init_dfmmodel(self):
self.logger.info(f"Reading mdu file at {mdu_fn}")
self._dfmmodel = FMModel(filepath=mdu_fn)
else: # use hydrolib template
self._assert_write_mode
self._assert_write_mode()
self.logger.info("Initialising empty mdu file")
self._dfmmodel = FMModel()
self._dfmmodel.filepath = mdu_fn
Expand All @@ -3008,7 +3008,7 @@ def read_dimr(self, dimr_fn: Optional[str] = None) -> None:
dimr = DIMR(filepath=Path(dimr_fn))
# else initialise
else:
self._assert_write_mode
self._assert_write_mode()
self.logger.info("Initialising empty dimr file")
dimr = DIMR()
self._dimr = dimr
Expand Down
8 changes: 3 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ authors = [
{ name = "Hélène Boisgontier", email = "[email protected]" },
]
dependencies = [
"hydromt >=0.7.0",
"dask",
"hydromt >=0.8.0",
"geopandas >=0.10",
"numpy",
"pandas",
"xarray",
"hydrolib-core",
"hydrolib-core >=0.5.2",
"xugrid",
"meshkernel",
"meshkernel <=2.0.2",
"pyproj",
"shapely >=0.2.0",
"scipy",
Expand All @@ -37,7 +36,6 @@ classifiers = [
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
]
dynamic = ['version', 'description']

Expand Down

0 comments on commit 791d5c5

Please sign in to comment.