Skip to content

Commit

Permalink
Merge branch 'main' into pre-commit-ci-update-config
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeitsperre committed Apr 16, 2024
2 parents c64f463 + a27ddd2 commit b05e489
Show file tree
Hide file tree
Showing 10 changed files with 318 additions and 94 deletions.
2 changes: 1 addition & 1 deletion .cruft.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"project_slug": "xhydro",
"project_short_description": "Hydrological analysis library built with xarray.",
"pypi_username": "TC-FF",
"version": "0.3.6-dev.1",
"version": "0.3.6-dev.2",
"use_pytest": "y",
"use_black": "y",
"use_conda": "y",
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/scorecard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,6 @@ jobs:

# Upload the results to GitHub's code scanning dashboard.
- name: Upload to code-scanning
uses: github/codeql-action/upload-sarif@1b1aada464948af03b950897e5eb522f92603cc2 # 3.24.9
uses: github/codeql-action/upload-sarif@df5a14dc28094dc936e103b37d749c6628682b60 # 3.25.0
with:
sarif_file: results.sarif
19 changes: 19 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@
Changelog
=========

v0.4.0 (unreleased)
-------------------
Contributors to this version: Gabriel Rondeau-Genesse (:user:`RondeauG`), Richard Arsenault (:user:`richardarsenault`).

New features and enhancements
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
* Added support for the Hydrotel hydrological model. (:pull:`18`).
* Added optimal interpolation functions for time-series and streamflow indicators. (:pull:`88`, :pull:`129`).
* Added optimal interpolation notebooks. (:pull:`123`).

Breaking changes
^^^^^^^^^^^^^^^^
* Hydrological models are now classes instead of functions and dictionaries. (:issue:`93`, :pull:`18`).

Internal changes
^^^^^^^^^^^^^^^^
* N/A


v0.3.5 (2024-03-20)
-------------------
Contributors to this version: Trevor James Smith (:user:`Zeitsperre`), Thomas-Charles Fortier Filion (:user:`TC-FF`), Sébastien Langlois (:user:`sebastienlanglois`), Gabriel Rondeau-Genesse (:user:`RondeauG`).
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ target-version = [
]

[tool.bumpversion]
current_version = "0.3.6-dev.1"
current_version = "0.3.6-dev.2"
commit = true
commit_args = "--no-verify"
tag = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ class TestOptimalInterpolationIntegrationCorrectedFiles:
percentiles = [25.0, 50.0, 75.0]
variogram_bins = 10

form = 3
hmax_divider = 2.0
p1_bnds = [0.95, 1]
hmax_mult_range_bnds = [0.05, 3]

def test_cross_validation_execute(self):
"""Test the cross validation of optimal interpolation."""
# Get the required times only
Expand All @@ -80,6 +85,10 @@ def test_cross_validation_execute(self):
parallelize=False,
max_cores=1,
leave_one_out_cv=True,
form=self.form,
hmax_divider=self.hmax_divider,
p1_bnds=self.p1_bnds,
hmax_mult_range_bnds=self.hmax_mult_range_bnds,
)

# Test some output flow values
Expand Down Expand Up @@ -112,6 +121,10 @@ def test_cross_validation_execute(self):
parallelize=False,
max_cores=1,
leave_one_out_cv=True,
form=self.form,
hmax_divider=self.hmax_divider,
p1_bnds=self.p1_bnds,
hmax_mult_range_bnds=self.hmax_mult_range_bnds,
)

# Verify results
Expand All @@ -131,7 +144,7 @@ def test_cross_validation_execute(self):

def test_cross_validation_execute_parallel(self):
"""Test the parallel version of the optimal interpolation cross validation."""
# Run the interpolation and get flows
# Run the interpolation and obtain the resulting flows.
ds = opt.execute_interpolation(
self.qobs.sel(time=slice(self.start_date, self.end_date)),
self.qsim.sel(time=slice(self.start_date, self.end_date)),
Expand All @@ -143,6 +156,10 @@ def test_cross_validation_execute_parallel(self):
parallelize=True,
max_cores=3,
leave_one_out_cv=True,
form=self.form,
hmax_divider=self.hmax_divider,
p1_bnds=self.p1_bnds,
hmax_mult_range_bnds=self.hmax_mult_range_bnds,
)

# Test some output flow values
Expand Down Expand Up @@ -174,6 +191,10 @@ def test_operational_optimal_interpolation_run(self):
parallelize=False,
max_cores=1,
leave_one_out_cv=False,
form=self.form,
hmax_divider=self.hmax_divider,
p1_bnds=self.p1_bnds,
hmax_mult_range_bnds=self.hmax_mult_range_bnds,
)

# Test some output flow values
Expand Down Expand Up @@ -204,6 +225,62 @@ def test_compare_result_compare(self):
show_comparison=False,
)

def test_optimal_interpolation_single_time_dim(self):
"""Test the OI for data with no time dimension such as indicators."""
# Get the required times only
qobs = self.qobs.sel(time=dt.datetime(2018, 12, 20))
qsim = self.qsim.sel(time=dt.datetime(2018, 12, 20))

# TODO: Generate better data to make sure results compute accurately
# Run the code and ensure dataset is of correct size and code does not crash.
ds = opt.execute_interpolation(
qobs,
qsim,
self.station_correspondence,
self.observation_stations,
ratio_var_bg=self.ratio_var_bg,
percentiles=self.percentiles,
variogram_bins=self.variogram_bins,
parallelize=False,
max_cores=1,
leave_one_out_cv=True,
form=self.form,
hmax_divider=self.hmax_divider,
p1_bnds=self.p1_bnds,
hmax_mult_range_bnds=self.hmax_mult_range_bnds,
)

assert "time" not in ds
assert len(ds.percentile) == 3

def test_optimal_interpolation_no_time_dim(self):
"""Test the OI for data with no time dimension such as indicators."""
# Get the required times only
qobs = self.qobs.isel(time=10).drop("time")
qsim = self.qsim.isel(time=10).drop("time")

# TODO: Generate better data to make sure results compute accurately
# Run the code and ensure dataset is of correct size and code does not crash.
ds = opt.execute_interpolation(
qobs,
qsim,
self.station_correspondence,
self.observation_stations,
ratio_var_bg=self.ratio_var_bg,
percentiles=self.percentiles,
variogram_bins=self.variogram_bins,
parallelize=False,
max_cores=1,
leave_one_out_cv=True,
form=self.form,
hmax_divider=self.hmax_divider,
p1_bnds=self.p1_bnds,
hmax_mult_range_bnds=self.hmax_mult_range_bnds,
)

assert "time" not in ds
assert len(ds.percentile) == 3


class TestOptimalInterpolationIntegrationOriginalDEHFiles:

Expand Down Expand Up @@ -299,6 +376,11 @@ class TestOptimalInterpolationIntegrationOriginalDEHFiles:
percentiles = [25.0, 50.0, 75.0]
variogram_bins = 10

form = 3
hmax_divider = 2.0
p1_bnds = [0.95, 1]
hmax_mult_range_bnds = [0.05, 3]

def test_cross_validation_execute(self):
"""Test the cross validation of optimal interpolation."""
# Get the required times only
Expand All @@ -317,6 +399,10 @@ def test_cross_validation_execute(self):
parallelize=False,
max_cores=1,
leave_one_out_cv=True,
form=self.form,
hmax_divider=self.hmax_divider,
p1_bnds=self.p1_bnds,
hmax_mult_range_bnds=self.hmax_mult_range_bnds,
)

# Test some output flow values
Expand Down Expand Up @@ -349,6 +435,10 @@ def test_cross_validation_execute(self):
parallelize=False,
max_cores=1,
leave_one_out_cv=True,
form=self.form,
hmax_divider=self.hmax_divider,
p1_bnds=self.p1_bnds,
hmax_mult_range_bnds=self.hmax_mult_range_bnds,
)

# Verify results
Expand Down Expand Up @@ -380,6 +470,10 @@ def test_cross_validation_execute_parallel(self):
parallelize=True,
max_cores=3,
leave_one_out_cv=True,
form=self.form,
hmax_divider=self.hmax_divider,
p1_bnds=self.p1_bnds,
hmax_mult_range_bnds=self.hmax_mult_range_bnds,
)

# Test some output flow values
Expand Down
2 changes: 1 addition & 1 deletion tests/test_xhydro.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ def test_package_metadata():
contents = f.read()
assert """Thomas-Charles Fortier Filion""" in contents
assert '__email__ = "tcff_hydro@outlook.com"' in contents
assert '__version__ = "0.3.6-dev.1"' in contents
assert '__version__ = "0.3.6-dev.2"' in contents
2 changes: 1 addition & 1 deletion xhydro/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

__author__ = """Thomas-Charles Fortier Filion"""
__email__ = "tcff_hydro@outlook.com"
__version__ = "0.3.6-dev.1"
__version__ = "0.3.6-dev.2"
Loading

0 comments on commit b05e489

Please sign in to comment.