Skip to content

Commit

Permalink
Merge pull request #19 from Daafip/dev
Browse files Browse the repository at this point in the history
Change finialize
  • Loading branch information
Daafip authored Mar 5, 2024
2 parents 2f15981 + ba35e7e commit 8e5d1b0
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 16 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@ Adding `.finalize()` method - clears up the directory. Especially useful for DA.
### v1.3.4 - 1.3.9
- formalises forcing: either `.txt` or (two) `.nc` forcing supplied & run corresponding code
### v1.4.0
- Refactor `forcing_file` attribute to `camel_file` -> as essentially its now a txt file of specific class which the from_camels functions is run on in model startup
- change selection of dataset period to be inclusive
- Refactor `forcing_file` attribute to `camel_file` -> as essentially it's now a txt file of specific class which the from_camels functions is run on in model startup
- change selection of dataset period to be inclusive
### v.1.4.1
- changes to config file: alpha is not needed in model, only in forcing per definition.
- now removes any netcdf files created when using camels or test data
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ from ewatercycle.models import HBV

For more information on how this plugin works, and on how to implement your own model see the [plugin guide](https://github.com/eWaterCycle/ewatercycle-leakybucket/blob/main/plugin_guide.md)

## Changelog
Changes can be found in [CHANGELOG.md](https://github.com/Daafip/ewatercycle-hbv/blob/main/CHANGELOG.md) on GitHub

## License

This is a `ewatercycle-plugin` & thus this is distributed under the same terms as the template: the [Apache-2.0](https://spdx.org/licenses/Apache-2.0.html) license.
Expand Down
Binary file removed dist/ewatercycle_hbv-1.3.10-py2.py3-none-any.whl
Binary file not shown.
Binary file removed dist/ewatercycle_hbv-1.3.10.tar.gz
Binary file not shown.
Binary file removed dist/ewatercycle_hbv-1.3.9-py2.py3-none-any.whl
Binary file not shown.
Binary file removed dist/ewatercycle_hbv-1.3.9.tar.gz
Binary file not shown.
Binary file removed dist/ewatercycle_hbv-1.4.0.tar.gz
Binary file not shown.
Binary file not shown.
Binary file added dist/ewatercycle_hbv-1.4.1.tar.gz
Binary file not shown.
7 changes: 6 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ name = "ewatercycle-HBV"
description = "Implementation of HBV for eWaterCycle"
readme = "README.md"
license = "Apache-2.0"
version = "1.4.0"
version = "1.4.1"
authors = [
{ name = "David Haasnoot", email = "[email protected]" },
]
Expand All @@ -32,3 +32,8 @@ dependencies = [
# This registers the plugin such that it is discoverable by eWaterCycle
[project.entry-points."ewatercycle.models"]
HBV = "ewatercycle_HBV.model:HBV"
[project.entry-points."ewatercycle.forcings"]
HBVForcing = "ewatercycle_HBV.forcing:HBVForcing"

[project.urls]
homepage = "https://github.com/Daafip/ewatercycle-hbv"
2 changes: 1 addition & 1 deletion src/ewatercycle_HBV/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.4.0"
__version__ = "1.4.1"
23 changes: 11 additions & 12 deletions src/ewatercycle_HBV/model.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""eWaterCycle wrapper for the HBV model."""
import json
import os.path
import warnings
from collections.abc import ItemsView
from pathlib import Path
Expand All @@ -25,8 +26,7 @@ class HBVMethods(eWaterCycleModel):
"potential_evaporation_file": "",
"parameters": "",
"initial_storage": "",
"alpha": 1.26,
}
}

def _make_cfg_file(self, **kwargs) -> Path:
"""Write model configuration file."""
Expand Down Expand Up @@ -59,7 +59,7 @@ def _make_cfg_file(self, **kwargs) -> Path:
# self.forcing.directory / self.forcing.tasmax
# )

for kwarg in kwargs: # Write any kwargs to the config.
for kwarg in kwargs: # Write any kwargs to the config. - doesn't overwrite config?
self._config[kwarg] = kwargs[kwarg]

config_file = self._cfg_dir / "HBV_config.json"
Expand Down Expand Up @@ -87,13 +87,6 @@ def finalize(self) -> None:
self._bmi.finalize()
del self._bmi

# TODO: remove data set file
# TODO maybe change this time aspect? can get quite large - or simply remove in finalize
# ds_name = f"HBV_forcing_CAMELS_{time}.nc"
# out_dir = self.directory / ds_name
# if not out_dir.exists():
# ds.to_netcdf(out_dir)

try:
# remove config file
config_file = self._cfg_dir / "HBV_config.json"
Expand All @@ -108,8 +101,14 @@ def finalize(self) -> None:
warnings.warn(message=f'Config folder not found at {self._cfg_dir.rmdir()}',category=UserWarning)


for file in ["potential_evaporation_file", "precipitation_file"]:
self._config[file]
# NetCDF files created are timestamped and running them a lot creates many files, remove these
if self.forcing.camels_txt_defined() or self.forcing.test_data_bool:
for file in ["potential_evaporation_file", "precipitation_file"]:
path = self.forcing.directory / self._config[file]
if path.is_file(): # often both with be the same, e.g. with camels data.
path.unlink()
else:
pass

class HBV(ContainerizedModel, HBVMethods):
"""The HBV eWaterCycle model, with the Container Registry docker image."""
Expand Down

0 comments on commit 8e5d1b0

Please sign in to comment.