From 12bbe57f91b5c518b2a47318f5382decc3e266ea Mon Sep 17 00:00:00 2001 From: hboisgon Date: Wed, 22 Jan 2025 11:51:11 +0800 Subject: [PATCH 1/3] python 39 support and test --- .github/workflows/test_stable.yml | 2 +- hydromt_wflow/pcrm.py | 9 +++++---- hydromt_wflow/wflow.py | 19 +++++++++++-------- hydromt_wflow/workflows/demand.py | 6 +++--- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/.github/workflows/test_stable.yml b/.github/workflows/test_stable.yml index 2e42e8a8..82f0580a 100644 --- a/.github/workflows/test_stable.yml +++ b/.github/workflows/test_stable.yml @@ -16,7 +16,7 @@ jobs: fail-fast: false matrix: os: ["ubuntu-latest" ] #, "macos-latest", "windows-latest"] - python-version: ['3.10', '3.11'] + python-version: ['3.9', '3.10', '3.11'] include: - os: ubuntu-latest label: linux-64 diff --git a/hydromt_wflow/pcrm.py b/hydromt_wflow/pcrm.py index 95d5ae99..4d7a990d 100644 --- a/hydromt_wflow/pcrm.py +++ b/hydromt_wflow/pcrm.py @@ -5,6 +5,7 @@ import tempfile from os.path import basename, dirname, isdir, isfile, join from pathlib import Path +from typing import Union import numpy as np import pandas as pd @@ -187,7 +188,7 @@ def write_map( def read_staticmaps_pcr( - root: Path | str, crs: int = 4326, obj: object = None, **kwargs + root: Union[Path, str], crs: int = 4326, obj: object = None, **kwargs ): """ Read pcraster staticmaps at and parse to xarray. @@ -196,7 +197,7 @@ def read_staticmaps_pcr( Parameters ---------- - root : Path | str + root : Path, str Path to the root directory of the model. Assumes this folder contains a staticmaps folder with the pcraster maps. crs : int, optional @@ -256,7 +257,7 @@ def read_staticmaps_pcr( def write_staticmaps_pcr( staticmaps: xr.Dataset, - root: Path | str, + root: Union[Path, str], ): """ Write staticmaps at in PCRaster maps format. @@ -265,7 +266,7 @@ def write_staticmaps_pcr( ---------- staticmaps : xr.Dataset Dataset with the staticmaps. - root : Path | str + root : Path, str Path to the root directory of the model. A staticmaps folder will be created in this folder with the pcraster maps. """ diff --git a/hydromt_wflow/wflow.py b/hydromt_wflow/wflow.py index 3641daa4..918841f8 100644 --- a/hydromt_wflow/wflow.py +++ b/hydromt_wflow/wflow.py @@ -2075,7 +2075,7 @@ def setup_soilmaps( def setup_ksathorfrac( self, ksat_fn: Union[str, xr.DataArray], - variable: str | None = None, + variable: Optional[str] = None, resampling_method: str = "average", ): """Set KsatHorFrac parameter values from a predetermined map. @@ -2086,9 +2086,9 @@ def setup_ksathorfrac( Parameters ---------- - ksat_fn : str, optional + ksat_fn : str, xr.DataArray The identifier of the KsatHorFrac dataset in the data catalog. - variable : str | None, optional + variable : str, optional The variable name for the ksathorfrac map to use in ``ksat_fn`` in case \ ``ksat_fn`` contains several variables. By default None. resampling_method : str, optional @@ -4121,7 +4121,7 @@ def read_grid(self, **kwargs): def write_grid( self, - fn_out: Path | str = None, + fn_out: Optional[Union[Path, str]] = None, ): """ Write grid to wflow static data file. @@ -4132,7 +4132,7 @@ def write_grid( Parameters ---------- - fn_out : Path | str, optional + fn_out : Path, str, optional Name or path to the outgoing grid file (including extension). This is the path/name relative to the root folder and if present the ``dir_input`` folder. @@ -4292,7 +4292,7 @@ def read_geoms( def write_geoms( self, geoms_fn: str = "staticgeoms", - precision: int | None = None, + precision: Optional[int] = None, ): """ Write geoms in GeoJSON format. @@ -4306,6 +4306,9 @@ def write_geoms( geoms_fn : str, optional Folder name/path where the static geometries are stored relative to the model root and ``dir_input`` if any. By default "staticgeoms". + precision : int, optional + Decimal precision to write the geometries. By default None to use 1 decimal + for projected crs and 6 for non-projected crs. """ # to write use self.geoms[var].to_file() if not self._write: @@ -4514,10 +4517,10 @@ def write_forcing( # only correct dates in toml for standard calendars: if not hasattr(da.indexes["time"], "to_datetimeindex"): times = da.time.values - if (start < pd.to_datetime(times[0])) | (start not in times): + if (start < pd.to_datetime(times[0])) or (start not in times): start = pd.to_datetime(times[0]) correct_times = True - if (end > pd.to_datetime(times[-1])) | (end not in times): + if (end > pd.to_datetime(times[-1])) or (end not in times): end = pd.to_datetime(times[-1]) correct_times = True # merge, process and write forcing diff --git a/hydromt_wflow/workflows/demand.py b/hydromt_wflow/workflows/demand.py index e0702904..354d4bf5 100644 --- a/hydromt_wflow/workflows/demand.py +++ b/hydromt_wflow/workflows/demand.py @@ -1,7 +1,7 @@ """Workflow for water demand.""" import logging -from typing import List, Optional, Tuple +from typing import List, Optional, Tuple, Union import geopandas as gpd import numpy as np @@ -438,7 +438,7 @@ def classify_pixels( da_irr: xr.DataArray, da_crop_model: xr.DataArray, threshold: float, - nodata_value: float | int = -9999, + nodata_value: Union[float, int] = -9999, ): """Classifies pixels based on a (fractional) threshold. @@ -453,7 +453,7 @@ def classify_pixels( Layer of the masked cropland in wflow model threshold: float Threshold above which pixels are classified as irrigated - nodata_value: float | int = -9999 + nodata_value: float, int = -9999 Value to be used for nodata Returns From c77bee8a3e4610b956dd1e96ee9dae54b86385d8 Mon Sep 17 00:00:00 2001 From: hboisgon Date: Wed, 22 Jan 2025 12:02:32 +0800 Subject: [PATCH 2/3] prepare release --- docs/changelog.rst | 13 +++++-------- hydromt_wflow/__init__.py | 2 +- pyproject.toml | 2 +- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 9cc08fae..6b93a1e5 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -6,20 +6,17 @@ 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.7.1 (22 January 2025) +======================== +Small release to fix temporary support for python 3.9. Added ----- -- **setup_ksatver_vegetation**: method to calculate KsatVer_vegetation to account for biologically-enhanced soil structure in KsatVer. - -Changed -------- -- +- **setup_ksatver_vegetation**: method to calculate KsatVer_vegetation to account for biologically-enhanced soil structure in KsatVer. PR #313 Fixed ----- -- +- Support for python 3.9 v0.7.0 (8 November 2024) ======================== diff --git a/hydromt_wflow/__init__.py b/hydromt_wflow/__init__.py index e4ba09b8..e437b49a 100644 --- a/hydromt_wflow/__init__.py +++ b/hydromt_wflow/__init__.py @@ -1,6 +1,6 @@ """hydroMT plugin for wflow models.""" -__version__ = "0.7.1dev0" +__version__ = "0.7.1" from .naming import * from .utils import * diff --git a/pyproject.toml b/pyproject.toml index 729eca1d..7ef65f83 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,7 +19,7 @@ dependencies = [ "pandas", "pyflwdir>=0.5.7", "pyproj", - "rioxarray", + "rioxarray<=0.17.0", # pin because of xarray pin "scipy", "shapely", "toml", From 015172c98a855f5657532b9473212a130a2d8794 Mon Sep 17 00:00:00 2001 From: hboisgon Date: Thu, 23 Jan 2025 10:12:46 +0800 Subject: [PATCH 3/3] drop python 39 support --- .github/workflows/test_stable.yml | 2 +- docs/changelog.rst | 10 +++++----- pyproject.toml | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test_stable.yml b/.github/workflows/test_stable.yml index 82f0580a..2e42e8a8 100644 --- a/.github/workflows/test_stable.yml +++ b/.github/workflows/test_stable.yml @@ -16,7 +16,7 @@ jobs: fail-fast: false matrix: os: ["ubuntu-latest" ] #, "macos-latest", "windows-latest"] - python-version: ['3.9', '3.10', '3.11'] + python-version: ['3.10', '3.11'] include: - os: ubuntu-latest label: linux-64 diff --git a/docs/changelog.rst b/docs/changelog.rst index 6b93a1e5..022a9281 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -6,17 +6,17 @@ 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`_. -v0.7.1 (22 January 2025) +v0.7.1 (23 January 2025) ======================== -Small release to fix temporary support for python 3.9. +Officially drop support for python 3.9. Added ----- - **setup_ksatver_vegetation**: method to calculate KsatVer_vegetation to account for biologically-enhanced soil structure in KsatVer. PR #313 -Fixed ------ -- Support for python 3.9 +Deprecated +---------- +- Support for python 3.9 (already not supported in previous releases). v0.7.0 (8 November 2024) ======================== diff --git a/pyproject.toml b/pyproject.toml index 7ef65f83..3ddd6c88 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,7 +25,7 @@ dependencies = [ "toml", "xarray<=2024.3.0", # pin xarray to avoid issues with time resampling and NaN interpolation ] -requires-python = ">=3.9" +requires-python = ">=3.10" readme = "README.rst" classifiers = [ "Development Status :: 4 - Beta", @@ -98,7 +98,7 @@ deps_not_in_conda = [ [tool.black] line-length = 88 -target-version = ['py39'] +target-version = ['py310', 'py311'] [tool.ruff] line-length = 88