Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unpin numpy #244

Merged
merged 13 commits into from
Mar 6, 2025
3 changes: 2 additions & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ jobs:
miniforge-version: latest
use-mamba: true

## mamba required to install pandoc with nbsphinx (does not work via pip)
- name: Setup env
run: |
python make_env.py full -p 3.11 -n hydromt-sfincs -o environment-doc.yml
python make_env.py doc,examples -p 3.11 -n hydromt-sfincs -o environment-doc.yml
mamba env create -f environment-doc.yml
mamba run -n hydromt-sfincs pip install -e .

Expand Down
111 changes: 55 additions & 56 deletions .github/workflows/tests_dev.yml
Original file line number Diff line number Diff line change
@@ -1,63 +1,62 @@
# Uncomment when we move to HydroMT v1
# name: Tests with HydroMT dev
name: Tests with HydroMT dev

# on:
# # trigger weekly on monday at 00:00 UTC
# schedule:
# - cron: '0 0 * * 1'
# push:
# branches: [main]
# paths:
# - .github/workflows/tests_dev.yml
# - tests/*
# - hydromt_sfincs/*
# - pyproject.toml
# pull_request:
# branches: [main]
# paths:
# - .github/workflows/tests_dev.yml
# - tests/*
# - hydromt_sfincs/*
# - pyproject.toml
on:
# trigger weekly on monday at 00:00 UTC
schedule:
- cron: '0 0 * * 1'
push:
branches: [main]
paths:
- .github/workflows/tests_dev.yml
- tests/*
- hydromt_sfincs/*
- pyproject.toml
pull_request:
branches: [main]
paths:
- .github/workflows/tests_dev.yml
- tests/*
- hydromt_sfincs/*
- pyproject.toml

# jobs:
# build:
# defaults:
# run:
# shell: bash -l {0}
# strategy:
# fail-fast: false
# runs-on: ubuntu-latest
# timeout-minutes: 30
# concurrency:
# group: ${{ github.workflow }}-${{ matrix.python-version }}-${{ github.ref }}
# cancel-in-progress: true
# steps:
jobs:
build:
defaults:
run:
shell: bash -l {0}
strategy:
fail-fast: false
runs-on: ubuntu-latest
timeout-minutes: 30
concurrency:
group: ${{ github.workflow }}-${{ matrix.python-version }}-${{ github.ref }}
cancel-in-progress: true
steps:

# - uses: actions/checkout@v3
- uses: actions/checkout@v3

# - uses: actions/setup-python@v5
# id: pip
# with:
# # caching, see https://github.com/actions/setup-python/blob/main/docs/advanced-usage.md#caching-packages
# cache: 'pip'
# python-version: '3.9' # 3.9 is not supported by last released version of hydromt
# cache-dependency-path: pyproject.toml
- uses: actions/setup-python@v5
id: pip
with:
# caching, see https://github.com/actions/setup-python/blob/main/docs/advanced-usage.md#caching-packages
cache: 'pip'
python-version: '3.11'
cache-dependency-path: pyproject.toml

# # true if cache-hit occurred on the primary key
# - name: Cache hit
# run: echo '${{ steps.pip.outputs.cache-hit }}'
# true if cache-hit occurred on the primary key
- name: Cache hit
run: echo '${{ steps.pip.outputs.cache-hit }}'

# # build environment with pip
# - name: Install hydromt-sfincs
# run: |
# pip install --upgrade pip
# pip install .[test,examples]
# pip install git+https://github.com/Deltares/hydromt.git
# pip list
# build environment with pip
- name: Install hydromt-sfincs
run: |
pip install --upgrade pip
pip install .[test,examples]
pip install git+https://github.com/Deltares/hydromt.git@v0.10.1
pip list

# # run test
# - name: Test
# run: |
# export NUMBA_DISABLE_JIT=1
# python -m pytest --verbose
# run test
- name: Test
run: |
export NUMBA_DISABLE_JIT=1
python -m pytest --verbose
4 changes: 2 additions & 2 deletions hydromt_sfincs/regulargrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def create_mask_active(
_msk1 = np.logical_xor(
da_mask, ndimage.binary_fill_holes(da_mask, structure=s)
)
regions = ndimage.measurements.label(_msk1, structure=s)[0]
regions = ndimage.label(_msk1, structure=s)[0]
# TODO check if region_area works for rotated grids!
lbls, areas = region_area(regions, self.transform, latlon)
n = int(sum(areas / 1e6 < fill_area))
Expand All @@ -237,7 +237,7 @@ def create_mask_active(
da_mask, np.isin(regions, lbls[areas / 1e6 < fill_area])
)
if drop_area > 0:
regions = ndimage.measurements.label(da_mask.values, structure=s)[0]
regions = ndimage.label(da_mask.values, structure=s)[0]
lbls, areas = region_area(regions, self.transform, latlon)
_msk = np.isin(regions, lbls[areas / 1e6 >= drop_area])
n = int(sum(areas / 1e6 < drop_area))
Expand Down
11 changes: 6 additions & 5 deletions hydromt_sfincs/sfincs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2876,11 +2876,12 @@ def write(self):
self.write_states()
# config last; might be udpated when writing maps, states or forcing
self.write_config()
# write data catalog with used data sources
try:
self.write_data_catalog() # new in hydromt v0.4.4
except Exception as e:
self.logger.error(f"Error writing data catalog: {str(e)}")
# FIXME - erroneous data catalog writing should be avoided to prevent errors later on
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this better than try-except? It only seemed to go wrong for certain CRSs?

# # write data catalog with used data sources
# try:
# self.write_data_catalog() # new in hydromt v0.4.4
# except Exception as e:
# self.logger.error(f"Error writing data catalog: {str(e)}")

def read_grid(self, data_vars: Union[List, str] = None) -> None:
"""Read SFINCS binary grid files and save to `grid` attribute.
Expand Down
2 changes: 1 addition & 1 deletion hydromt_sfincs/workflows/curvenumber.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def scs_recovery_determination(
).load()

# Curve numbers to grid: go over NLCD classes and HSG classes
da_CN = xr.full_like(da_landuse, np.NaN, dtype=np.float32)
da_CN = xr.full_like(da_landuse, np.nan, dtype=np.float32)
for i in range(df_map.index.size):
for j in range(df_map.columns.size):
ind = (da_landuse == df_map.index[i]) & (
Expand Down
4 changes: 2 additions & 2 deletions make_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def _parse_profile(profile_str: str, opt_deps: dict, project_name: str) -> List[

parser = argparse.ArgumentParser()

parser.add_argument("profile", default="dev,test", nargs="?")
parser.add_argument("profile", default="test,examples,doc", nargs="?")
parser.add_argument("--output", "-o", default="environment.yml")
parser.add_argument("--channels", "-c", default=None)
parser.add_argument("--name", "-n", default=None)
Expand Down Expand Up @@ -86,7 +86,7 @@ def _parse_profile(profile_str: str, opt_deps: dict, project_name: str) -> List[
conda_deps = []
pip_deps = []
for dep in deps_to_install:
if dep in deps_not_in_conda:
if any([dep.startswith(pypi_dep) for pypi_dep in deps_not_in_conda]):
pip_deps.append(dep)
else:
conda_deps.append(dep)
Expand Down
8 changes: 5 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ authors = [
dependencies = [
"affine",
"geopandas>1.0",
"hydromt>=0.10, <0.11",
"hydromt>=0.10.1,<1.0",
"numba",
"numpy<2.0", # temp pin until bottleneck release v1.4
"numpy",
"pandas",
"pillow",
"pyflwdir>=0.5.5, <0.5.9",
"pyflwdir>=0.5.10",
"pyproj",
"rasterio",
"scipy",
Expand Down Expand Up @@ -86,6 +86,8 @@ channels = ["conda-forge"]
deps_not_in_conda = [
"sphinx_design",
"black[jupyter]",
"hydromt", # temporary until hydromt v0.10.1 is released
"pyflwdir", # temporary until pyflwdir v0.5.10 is released on conda-forge
]

[tool.pytest.ini_options]
Expand Down
Loading