Running LISFLOOD model using eWaterCycle package (on Cartesius machine of SURFsara)¶
This notebooks shows how to run LISFLOOD model. Please note that the lisflood-grpc4bmi docker image in eWaterCycle is compatible only with forcing data and parameter set on Cartesius machine of SURFsara. More information about data, configuration and installation instructions can be found in the System setup in the eWaterCycle documentation.
1 In:
import logging
import warnings
logger = logging.getLogger("grpc4bmi")
logger.setLevel(logging.WARNING)
warnings.filterwarnings("ignore", category=UserWarning)
1 In:
import pandas as pd
import ewatercycle.forcing
import ewatercycle.models
import ewatercycle.parameter_sets
Load forcing data¶
For this example notebook, lisflood_ERA-Interim_*_1990_1990.nc
data are copied from /projects/0/wtrcycle/comparison/forcing/lisflood
to /scratch/shared/ewatercycle/lisflood_example/lisflood_forcing_data
. Also the lisvap output files ‘e0’, ‘es0’ and ‘et0’ are generated and stored in the same directory. These data are made by running ESMValTool recipe and lisvap. We can now use those files to run the Lisflood model.
2 In:
forcing = ewatercycle.forcing.load_foreign(
target_model="lisflood",
directory="/scratch/shared/ewatercycle/lisflood_example/lisflood_forcing_data/",
start_time="1990-01-01T00:00:00Z",
end_time="1990-12-31T00:00:00Z",
forcing_info={
"PrefixPrecipitation": "lisflood_ERA-Interim_pr_1990_1990.nc",
"PrefixTavg": "lisflood_ERA-Interim_tas_1990_1990.nc",
"PrefixE0": "lisflood_e0_1990_1990.nc",
"PrefixES0": "lisflood_es0_1990_1990.nc",
"PrefixET0": "lisflood_et0_1990_1990.nc",
},
)
print(forcing)
eWaterCycle forcing
-------------------
start_time=1990-01-01T00:00:00Z
end_time=1990-12-31T00:00:00Z
directory=/scratch/shared/ewatercycle/lisflood_example/lisflood_forcing_data
shape=None
PrefixPrecipitation=lisflood_ERA-Interim_pr_1990_1990.nc
PrefixTavg=lisflood_ERA-Interim_tas_1990_1990.nc
PrefixE0=lisflood_e0_1990_1990.nc
PrefixES0=lisflood_es0_1990_1990.nc
PrefixET0=lisflood_et0_1990_1990.nc
Load parameter set¶
This example uses parameter set on Cartesius machine of SURFsara.
3 In:
parameterset = ewatercycle.parameter_sets.ParameterSet(
name="Lisflood01degree_masked",
directory="/projects/0/wtrcycle/comparison/lisflood_input/Lisflood01degree_masked",
config="/projects/0/wtrcycle/comparison/lisflood_input/settings_templates/settings_lisflood.xml",
target_model="lisflood",
)
print(parameterset)
Parameter set
-------------
name=Lisflood01degree_masked
directory=/lustre1/0/wtrcycle/comparison/lisflood_input/Lisflood01degree_masked
config=/lustre1/0/wtrcycle/comparison/lisflood_input/settings_templates/settings_lisflood.xml
doi=N/A
target_model=lisflood
supported_model_versions=set()
Set up the model¶
To create the model object, we need to select a version.
4 In:
ewatercycle.models.Lisflood.available_versions
4 Out:
('20.10',)
5 In:
model = ewatercycle.models.Lisflood(
version="20.10", parameter_set=parameterset, forcing=forcing
)
print(model)
Model version 20.10 is not explicitly listed in the supported model versions of this parameter set. This can lead to compatibility issues.
eWaterCycle Lisflood
-------------------
Version = 20.10
Parameter set =
Parameter set
-------------
name=Lisflood01degree_masked
directory=/lustre1/0/wtrcycle/comparison/lisflood_input/Lisflood01degree_masked
config=/lustre1/0/wtrcycle/comparison/lisflood_input/settings_templates/settings_lisflood.xml
doi=N/A
target_model=lisflood
supported_model_versions=set()
Forcing =
eWaterCycle forcing
-------------------
start_time=1990-01-01T00:00:00Z
end_time=1990-12-31T00:00:00Z
directory=/scratch/shared/ewatercycle/lisflood_example/lisflood_forcing_data
shape=None
PrefixPrecipitation=lisflood_ERA-Interim_pr_1990_1990.nc
PrefixTavg=lisflood_ERA-Interim_tas_1990_1990.nc
PrefixE0=lisflood_e0_1990_1990.nc
PrefixES0=lisflood_es0_1990_1990.nc
PrefixET0=lisflood_et0_1990_1990.nc
6 In:
model.parameters
6 Out:
[('IrrigationEfficiency', '0.75'),
('MaskMap', '/data/input/areamaps/model_mask'),
('start_time', '1990-01-01T00:00:00Z'),
('end_time', '1990-12-31T00:00:00Z')]
Setup model with model_mask, IrrigationEfficiency of 0.8 instead of 0.75 and an earlier end time, making total model time just 1 month.
7 In:
model_mask = (
"/projects/0/wtrcycle/comparison/recipes_auxiliary_datasets/LISFLOOD/model_mask.nc"
)
config_file, config_dir = model.setup(
IrrigationEfficiency="0.8", end_time="1990-1-31T00:00:00Z", MaskMap=model_mask
)
print(config_file)
print(config_dir)
Running /scratch/shared/ewatercycle/lisflood_example/ewatercycle-lisflood-grpc4bmi_20.10.sif singularity container on port 58991
/scratch/shared/ewatercycle/lisflood_example/lisflood_20210713_121949/lisflood_setting.xml
/scratch/shared/ewatercycle/lisflood_example/lisflood_20210713_121949
8 In:
model.parameters
8 Out:
[('IrrigationEfficiency', '0.8'),
('MaskMap',
'/lustre1/0/wtrcycle/comparison/recipes_auxiliary_datasets/LISFLOOD/model_mask'),
('start_time', '1990-01-01T00:00:00Z'),
('end_time', '1990-01-31T00:00:00Z')]
Initialize the model with the config file:
9 In:
model.initialize(config_file)
Get model variable names
10 In:
model.output_var_names
10 Out:
('Discharge',)
Run the model¶
Store simulated values at one target location until model end time. In this example, we use the coordinates of Merrimack observation station as the target coordinates.
11 In:
target_longitude = [-71.35]
target_latitude = [42.64]
target_discharge = []
time_range = []
end_time = model.end_time
while model.time < end_time:
model.update()
target_discharge.append(
model.get_value_at_coords(
"Discharge", lon=target_longitude, lat=target_latitude
)[0]
)
time_range.append(model.time_as_datetime.date())
print(model.time_as_isostr)
.Simulation started on 2021-07-13 14:20
1 1990-01-03T00:00:00Z
2 (estimated simulation end: 2021-07-13 14:28)1990-01-04T00:00:00Z
3 (estimated simulation end: 2021-07-13 14:25)1990-01-05T00:00:00Z
4 (estimated simulation end: 2021-07-13 14:24)1990-01-06T00:00:00Z
5 (estimated simulation end: 2021-07-13 14:23)1990-01-07T00:00:00Z
6 (estimated simulation end: 2021-07-13 14:23)1990-01-08T00:00:00Z
7 (estimated simulation end: 2021-07-13 14:23)1990-01-09T00:00:00Z
8 (estimated simulation end: 2021-07-13 14:23)1990-01-10T00:00:00Z
9 (estimated simulation end: 2021-07-13 14:22)1990-01-11T00:00:00Z
10 (estimated simulation end: 2021-07-13 14:22)1990-01-12T00:00:00Z
11 (estimated simulation end: 2021-07-13 14:22)1990-01-13T00:00:00Z
12 (estimated simulation end: 2021-07-13 14:22)1990-01-14T00:00:00Z
13 (estimated simulation end: 2021-07-13 14:22)1990-01-15T00:00:00Z
14 (estimated simulation end: 2021-07-13 14:22)1990-01-16T00:00:00Z
15 (estimated simulation end: 2021-07-13 14:22)1990-01-17T00:00:00Z
16 (estimated simulation end: 2021-07-13 14:22)1990-01-18T00:00:00Z
17 (estimated simulation end: 2021-07-13 14:22)1990-01-19T00:00:00Z
18 (estimated simulation end: 2021-07-13 14:22)1990-01-20T00:00:00Z
19 (estimated simulation end: 2021-07-13 14:22)1990-01-21T00:00:00Z
20 (estimated simulation end: 2021-07-13 14:22)1990-01-22T00:00:00Z
21 (estimated simulation end: 2021-07-13 14:22)1990-01-23T00:00:00Z
22 (estimated simulation end: 2021-07-13 14:22)1990-01-24T00:00:00Z
23 (estimated simulation end: 2021-07-13 14:22)1990-01-25T00:00:00Z
24 (estimated simulation end: 2021-07-13 14:22)1990-01-26T00:00:00Z
25 (estimated simulation end: 2021-07-13 14:22)1990-01-27T00:00:00Z
26 (estimated simulation end: 2021-07-13 14:22)1990-01-28T00:00:00Z
27 (estimated simulation end: 2021-07-13 14:22)1990-01-29T00:00:00Z
28 (estimated simulation end: 2021-07-13 14:22)1990-01-30T00:00:00Z
29 (estimated simulation end: 2021-07-13 14:22)1990-01-31T00:00:00Z
Store simulated values for all locations of the model grid at end time.
12 In:
discharge = model.get_value_as_xarray("Discharge")
23 In:
model.__del__()
Inspect the results¶
The discharge time series at Merrimack observation station:
13 In:
simulated_target_discharge = pd.DataFrame(
{"simulation": target_discharge}, index=pd.to_datetime(time_range)
)
simulated_target_discharge.plot(figsize=(12, 8))
13 Out:
<AxesSubplot:>
The lisflood output has a global extent. In this example, we plot the discharge values in Merrimack catchment and at the last time step.
22 In:
lc = discharge.coords["longitude"]
la = discharge.coords["latitude"]
discharge_map = discharge.loc[
dict(longitude=lc[(lc > -73) & (lc < -70)], latitude=la[(la > 42) & (la < 45)])
].plot(robust=True, cmap="GnBu", figsize=(12, 8))
discharge_map.axes.scatter(
target_longitude, target_latitude, s=250, c="r", marker="x", lw=2
)
22 Out:
<matplotlib.collections.PathCollection at 0x2ab893830370>