Skip to content

Commit

Permalink
Merge pull request #58 from Daafip/dev
Browse files Browse the repository at this point in the history
add UID to forcing generation
  • Loading branch information
Daafip authored May 16, 2024
2 parents 6807489 + 5f85490 commit 4f5850c
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 11 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,6 @@ Adding `.finalize()` method - clears up the directory. Especially useful for DA.
#### 1.8.2
- No longer removes config on `finalize`, should be up to user
#### 1.8.3
- Local model: `HBVLocal` also availible in wrapper
- Local model: `HBVLocal` also availible in wrapper
#### 1.8.4
- On generation of forcing adds a unique id (string) to be able to generate a lot of forcing at once
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

This package is based on the [Leaky bucket](https://github.com/eWaterCycle/ewatercycle-leakybucket/tree/main) & is a wrapper for the [HBV-bmi](https://github.com/Daafip/HBV-bmi) model.

HBV (Hydrologiska Byråns Vattenbalansavdelning) is a conceptual hydrological model. For more information on it's history, see this [paper](https://hess.copernicus.org/articles/26/1371/2022/).

This current implementation is _without_ a snow reservoir.
HBV (Hydrologiska Byråns Vattenbalansavdelning) is a conceptual hydrological model. For more information on its history, see this [paper](https://hess.copernicus.org/articles/26/1371/2022/).
The actual model implemented here sit looks most like the original model from [1976](https://urn.kb.se/resolve?urn=urn:nbn:se:smhi:diva-5738).
See documentation for schematic of model layout.

## Installation
Install this package alongside your eWaterCycle installation
Expand Down
Binary file modified docs/_images/model_layout.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion docs/model.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ Model
HBV (Hydrologiska Byråns Vattenbalansavdelning) is a conceptual
hydrological model. For more information on it’s history, see this
`paper <https://hess.copernicus.org/articles/26/1371/2022/>`__.
The actual model implemented here sit looks most like the original model from `1976 <https://urn.kb.se/resolve?urn=urn:nbn:se:smhi:diva-573>`__.

This current implementation is *without* a snow reservoir as shown in the diagram below.

This current implementation is with a snow reservoir as shown in the diagram below.

.. image:: _images/model_layout.png
:width: 600
Expand Down
2 changes: 1 addition & 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.8.3"
version = "1.8.4"
authors = [
{ name = "David Haasnoot", email = "[email protected]" },
]
Expand Down
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.8.3"
__version__ = "1.8.4"
12 changes: 8 additions & 4 deletions src/ewatercycle_HBV/forcing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
from datetime import datetime
from pathlib import Path
from typing import Optional
import random
import string

import pandas as pd
import xarray as xr
import numpy as np

from ewatercycle.base.forcing import DefaultForcing
from ewatercycle.util import get_time


RENAME_CAMELS = {'total_precipitation_sum':'pr',
Expand Down Expand Up @@ -260,13 +263,14 @@ def from_external_source(self):
return ds_pr, ds_evspsblpot, ds_tas

def crop_ds(self, ds: xr.Dataset, name: str):
start = np.datetime64(self.start_time)
end = np.datetime64(self.end_time)
start = pd.Timestamp(get_time(self.start_time)).tz_convert(None)
end = pd.Timestamp(get_time(self.end_time)).tz_convert(None)
ds = ds.isel(time=(ds['time'].values >= start) & (ds['time'].values <= end))

time = str(datetime.now())[:-10].replace(":", "_")
# TODO maybe change this time aspect? can get quite large - or simply remove in finalize
ds_name = f"HBV_forcing_{name}_{time}.nc"
letters = string.ascii_lowercase + string.ascii_uppercase
unique_identifier = ''.join((random.choice(letters)) for _ in range(5))
ds_name = f"HBV_forcing_{name}_{time}_{unique_identifier}.nc"
out_dir = self.directory / ds_name
if not out_dir.exists():
ds.to_netcdf(out_dir)
Expand Down

0 comments on commit 4f5850c

Please sign in to comment.