Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: cd
on:
push:
tags:
- '**'
- '**'

jobs:
pypi_binwheels:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: ci

on:
push:
branches: [ "main", "develop" ]
branches: ["main", "develop"]
pull_request:
branches: [ "main", "develop" ]
branches: ["main", "develop"]

jobs:
qa-pre-commit:
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/downstream-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ on:
# Trigger the workflow on push to master or develop, except tag creation
push:
branches:
- 'main'
- 'develop'
- 'main'
- 'develop'
tags-ignore:
- '**'
- '**'

# Trigger the workflow on pull request
pull_request: ~
pull_request:

# Trigger the workflow manually
workflow_dispatch: ~
workflow_dispatch:

# Trigger after public PR approved for CI
pull_request_target:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: test-cd

on:
pull_request:
branches: [ "main" ]
branches: ["main"]

jobs:
pypi_binwheels:
Expand Down
82 changes: 40 additions & 42 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,45 +1,43 @@
default_language_version:
python: python3
python: python3
default_stages:
- pre-commit
- pre-push
- pre-commit
- pre-push
repos:
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.5.6
hooks:
- id: ruff # fix linting violations
types_or: [ python, pyi, jupyter ]
args: [ --fix ]
# - id: ruff-format # fix formatting
# types_or: [ python, pyi, jupyter ]
- repo: https://github.com/psf/black
rev: 25.1.0
hooks:
- id: black
- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
- repo: https://github.com/pycqa/flake8
rev: 7.0.0
hooks:
- id: flake8
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: detect-private-key
- id: check-ast
- id: end-of-file-fixer
- id: mixed-line-ending
args: [--fix=lf]
- id: trailing-whitespace
- id: check-case-conflict
- repo: local
hooks:
- id: forbid-to-commit
name: Don't commit rej files
entry: |
Cannot commit .rej files. These indicate merge conflicts that arise during automated template updates.
Fix the merge conflicts manually and remove the .rej files.
language: fail
files: '.*\.rej$'
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: detect-private-key
- id: check-ast
- id: end-of-file-fixer
- id: mixed-line-ending
args: [--fix=lf]
- id: trailing-whitespace
- id: check-case-conflict
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.4
hooks:
- id: ruff-check
exclude: '(dev/.*|.*_)\.py$'
args:
- --line-length=120
- --fix
- --exit-non-zero-on-fix
- --preview
- id: ruff-format
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.16.0
hooks:
- id: pretty-format-yaml
args: [--autofix, --preserve-quotes]
- id: pretty-format-toml
args: [--autofix]
- repo: local
hooks:
- id: forbid-to-commit
name: Don't commit rej files
entry: |
Cannot commit .rej files. These indicate merge conflicts that arise during automated template updates.
Fix the merge conflicts manually and remove the .rej files.
language: fail
files: '.*\.rej$'
14 changes: 7 additions & 7 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ build:
python: "3.11"
jobs:
pre_build:
- rm -rf _build
- rm -rf docs/_build
- cd docs && make rst
- rm -rf _build
- rm -rf docs/_build
- cd docs && make rst

python:
install:
- method: pip
path: .
extra_requirements:
- docs
- method: pip
path: .
extra_requirements:
- docs

sphinx:
configuration: docs/source/conf.py
16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
[package]
name = "earthkit-hydro"
version = "0.0.0" # placeholder, will be overwritten
edition = "2021"

[dependencies]
pyo3 = { version = "0.26", features = ["extension-module"] }
fixedbitset = "0.5"
numpy = "0.26"
pyo3 = {version = "0.26", features = ["extension-module"]}
rayon = "1.7"
fixedbitset = "0.5"

[lib]
crate-type = ["cdylib"]
# See https://github.com/PyO3/pyo3 for details
name = "_rust" # private module to be nested into Python package
path = "rust/lib.rs"
crate-type = ["cdylib"]

[package]
edition = "2021"
name = "earthkit-hydro"
version = "0.0.0" # placeholder, will be overwritten

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
31 changes: 17 additions & 14 deletions docs/source/tutorials/array_backend.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
"metadata": {},
"outputs": [],
"source": [
"import earthkit.hydro as ekh\n",
"import numpy as np\n",
"import cupy as cp\n",
"import numpy as np\n",
"import torch\n",
"import xarray as xr"
"import xarray as xr\n",
"\n",
"import earthkit.hydro as ekh"
]
},
{
Expand Down Expand Up @@ -208,7 +209,9 @@
}
],
"source": [
"ekh.upstream.array.sum(torch_network, torch.ones(numpy_network.shape, device=torch_network.device), return_type=\"masked\")"
"ekh.upstream.array.sum(\n",
" torch_network, torch.ones(numpy_network.shape, device=torch_network.device), return_type=\"masked\"\n",
")"
]
},
{
Expand All @@ -231,24 +234,24 @@
"example_arr_numpy = np.random.rand(10, *numpy_network.shape)\n",
"example_arr_cupy = cp.random.rand(10, *numpy_network.shape)\n",
"\n",
"lat = numpy_network.coords['lat']\n",
"lon = numpy_network.coords['lon']\n",
"lat = numpy_network.coords[\"lat\"]\n",
"lon = numpy_network.coords[\"lon\"]\n",
"step = np.arange(10)\n",
"\n",
"example_da_numpy = xr.DataArray(\n",
" example_arr_numpy,\n",
" dims = [\"step\", \"lat\", \"lon\"],\n",
" coords = {\"step\": step, \"lat\": lat, \"lon\": lon},\n",
" name = \"precip\",\n",
" attrs={\"units\": \"m\", \"description\": \"Sample precipitation data\"}\n",
" dims=[\"step\", \"lat\", \"lon\"],\n",
" coords={\"step\": step, \"lat\": lat, \"lon\": lon},\n",
" name=\"precip\",\n",
" attrs={\"units\": \"m\", \"description\": \"Sample precipitation data\"},\n",
")\n",
"\n",
"example_da_cupy = xr.DataArray(\n",
" example_arr_cupy,\n",
" dims = [\"step\", \"lat\", \"lon\"],\n",
" coords = {\"step\": step, \"lat\": lat, \"lon\": lon},\n",
" name = \"precip\",\n",
" attrs={\"units\": \"m\", \"description\": \"Sample precipitation data\"}\n",
" dims=[\"step\", \"lat\", \"lon\"],\n",
" coords={\"step\": step, \"lat\": lat, \"lon\": lon},\n",
" name=\"precip\",\n",
" attrs={\"units\": \"m\", \"description\": \"Sample precipitation data\"},\n",
")"
]
},
Expand Down
10 changes: 4 additions & 6 deletions docs/source/tutorials/catchment_statistics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
}
],
"source": [
"import earthkit.hydro as ekh\n",
"import numpy as np\n",
"\n",
"import earthkit.hydro as ekh\n",
"\n",
"network = ekh.river_network.load(\"efas\", \"5\", use_cache=False)"
]
},
Expand Down Expand Up @@ -507,12 +508,9 @@
}
],
"source": [
"field = np.ones(network.shape) # or load array/xarray from file\n",
"field = np.ones(network.shape) # or load array/xarray from file\n",
"\n",
"ekh.catchments.sum(network, field, locations = {\n",
" \"gauge_1\": (70.475, 28.32),\n",
" \"gauge_2\": (42.225, 50.24)\n",
"})"
"ekh.catchments.sum(network, field, locations={\"gauge_1\": (70.475, 28.32), \"gauge_2\": (42.225, 50.24)})"
]
}
],
Expand Down
7 changes: 4 additions & 3 deletions docs/source/tutorials/computing_accumulations.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
}
],
"source": [
"import earthkit.hydro as ekh\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"import earthkit.hydro as ekh\n",
"\n",
"network = ekh.river_network.load(\"efas\", \"5\", use_cache=False)"
]
Expand Down Expand Up @@ -64,7 +65,7 @@
}
],
"source": [
"field = np.ones(network.shape) # or load array/xarray from file\n",
"field = np.ones(network.shape) # or load array/xarray from file\n",
"\n",
"da = ekh.upstream.sum(network, field)\n",
"\n",
Expand Down
7 changes: 4 additions & 3 deletions docs/source/tutorials/creating_subnetworks.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
}
],
"source": [
"import earthkit.hydro as ekh\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"import earthkit.hydro as ekh\n",
"\n",
"network = ekh.river_network.load(\"efas\", \"5\", use_cache=False)"
]
Expand Down Expand Up @@ -64,7 +65,7 @@
}
],
"source": [
"node_mask = ekh.catchments.array.find(network, locations = {\"gauge_1\": (42.225, 50.24)})\n",
"node_mask = ekh.catchments.array.find(network, locations={\"gauge_1\": (42.225, 50.24)})\n",
"# has nans for missing, and 0s for the catchment\n",
"# => convert to boolean mask\n",
"node_mask = node_mask == 0\n",
Expand Down
Loading
Loading