8000 Fix LISFLOOD Errors when no lakes or reservoirs in the domain. by nicola-martin · Pull Request #3 · SEED-FD/lisflood-code · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix LISFLOOD Errors when no lakes or reservoirs in the domain. #3

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

Open
wants to merge 3 commits into
base: seedfd_develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
8000 Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/lisflood/global_modules/checkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,38 @@
import inspect
import warnings

from pcraster.operations import boolean
import numpy as np

from .errors import LisfloodError, LisfloodWarning
from .add1 import loadmap, loadsetclone, compressArray
from ..hydrological_modules import HydroModule
from ..hydrological_modules import (surface_routing, evapowater, snow, routing, leafarea, inflow, waterlevel,
waterbalance, wateruse, waterabstraction, lakes, riceirrigation, indicatorcalc,
landusechange, frost, groundwater, miscInitial, soilloop, soil,
reservoir, transmission)


def lakes_present(lake_type):
"""Check whether there are any lakes/reservoirs."""
present = True
sites_dict = {'lakes': 'LakeSites', 'reservoir': 'ReservoirSites'}
MaskMap = loadsetclone('MaskMap') # need to define mask map to use loadmap
LakeSitesC = loadmap(sites_dict[lake_type])
LakeSitesC[LakeSitesC < 1] = 0

# Get rid of any lakes/reservoirs that are not part of the channel network
IsChannelPcr = boolean(loadmap('Channels', pcr=True))
IsChannel = np.bool8(compressArray(IsChannelPcr))
LakeSitesC[IsChannel == 0] = 0

LakeSitesCC = np.compress(LakeSitesC > 0, LakeSitesC)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually there is a missing step to really evaluate if the lake/reservoir should be simulated:

LakeSitesC[IsChannel == 0] = 0

The "IsChannel" array can be retrieved as follows:

IsChannelPcr = boolean(loadmap('Channels', pcr=True))
IsChannel = np.bool8(compressArray(IsChannelPcr))

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the code for the missing step @doc78!
I have added this to the lakes_present() function.
I tested to make sure the check still behaves as expected for domains without lakes/reservoirs. I also did a test using a Channels map file set to all zeros to make sure that lakes/reservoir simulation is switched off in this case. This worked as expected (though the model failed, which I think is because the file I modified did not match with the rest of the input map files).

if LakeSitesCC.size == 0:
present = False

return present


class ModulesInputs:
root_package = 'lisflood.hydrological_modules'
# dict representing modules activated per option
Expand Down Expand Up @@ -82,6 +106,12 @@ def check(cls, settings):
and obj is not HydroModule and str(obj.__module__) == hydro_module.__name__]
total_checks += len(clzzs)
for clz in clzzs:
if clz.__name__ in ['lakes', 'reservoir']:
if not lakes_present(clz.__name__):
# No lakes/reservoirs so skip the check for these input files.
successful_checks += 1
continue

errors = clz.check_input_files(option)
successful_checks += int(bool(not errors))
all_errors += errors
Expand Down
0