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

No longer removes config on finalize #54

Merged
merged 1 commit into from
Apr 17, 2024
Merged
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
29 changes: 0 additions & 29 deletions src/ewatercycle_HBV/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,42 +199,13 @@ def finalize(self) -> None:

After finalization, the model should not be used anymore.

ADDED: Remove created config files, especially useful for DA models
"""

# remove bmi
self._bmi.finalize()
del self._bmi

config_file = self._cfg_dir / "HBV_config.json"
try:
# remove config file
config_file.unlink()
except FileNotFoundError:
warnings.warn(message=f'Config not found at {config_file}, removed by user?',category=UserWarning)

try:
# once empty, remove it
self._cfg_dir.rmdir()
except FileNotFoundError:
warnings.warn(message=f'Config folder not found at {self._cfg_dir.rmdir()}',category=UserWarning)

if type(self.forcing).__name__ == 'HBVForcing':
# 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:
self.unlink()

elif type(self.forcing).__name__ == 'LumpedMakkinkForcing':
# we created a temporary file so let's unlink that
self.unlink()

def unlink(self):
for file in ["potential_evaporation_file", "precipitation_file","mean_temperature_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
Loading