Generate forcing in eWaterCycle with ESMValTool

Contents

Generate forcing in eWaterCycle with ESMValTool#

This notebooks shows how to generate forcing data for PCR-GLOBWB model using ERA5 data and ESMValTool hydrological recipes. More information about data, configuration and installation instructions can be found in the System setup in the eWaterCycle documentation.

import logging
import warnings
from pathlib import Path
warnings.filterwarnings("ignore", category=UserWarning)

logger = logging.getLogger("esmvalcore")
logger.setLevel(logging.WARNING)
import xarray as xr
from rich import print

import ewatercycle.forcing

Forcing for PCRGlobWB is created using the ESMValTool recipe. It produces one file per each variable: temperature, and precipitation. You can set the start and end date, and the region. See eWaterCycle documentation for more information.

Bug:#

A shape file needs to be provided to delineate the area of interest. However, the forcing generated in this way will fill a bounding box that is “tight” around the shapefile. PCRGlobWB needs forcing files to be (slightly) larger than the extend of the clonemap. We fix this with “esmavaltool_padding below. Furhtermore, the number of pixels in the lat and lon directions need to be even for the interpolation algorithm that converts forcing data to the grid of the model. Therefore, we use the extract region and hard-code the extend of Great Brittain.

prepared_forcing_path_caravan_central = Path("/data/eurocsdms-data/forcing/camelsgb_73010/caravan")
# option two: load data that you or someone else generated previously
camelsgb_forcing = ewatercycle.forcing.sources['CaravanForcing'].load(directory=prepared_forcing_path_caravan_central)
esmvaltool_padding = 1.5

pcrglobwb_forcing = ewatercycle.forcing.sources["PCRGlobWBForcing"].generate(
    dataset="ERA5",
    start_time="1997-08-01T00:00:00Z",
    end_time="2000-08-31T00:00:00Z",
    start_time_climatology="1997-08-01T00:00:00Z",
    end_time_climatology="1998-08-01T00:00:00Z",
    shape=camelsgb_forcing.shape,
    extract_region={
    "start_longitude": -6-esmvaltool_padding,
    "end_longitude": 3+esmvaltool_padding,
    "start_latitude": 49-esmvaltool_padding,
    "end_latitude": 61+esmvaltool_padding,},
    directory = "/home/rhut/forcing/UK"

)
print(pcrglobwb_forcing)
PCRGlobWBForcing(
    start_time='1997-08-01T00:00:00Z',
    end_time='2000-08-31T00:00:00Z',
    directory=PosixPath('/home/rhut/forcing/UK/work/diagnostic/script'),
    shape=PosixPath('/data/eurocsdms-data/forcing/camelsgb_73010/caravan/camelsgb_73010.shp'),
    filenames={},
    precipitationNC='pcrglobwb_OBS6_ERA5_reanaly_1_day_pr_1997-2000_camelsgb_73010.nc',
    temperatureNC='pcrglobwb_OBS6_ERA5_reanaly_1_day_tas_1997-2000_camelsgb_73010.nc'
)

Plot forcing#

for file_name in [pcrglobwb_forcing.temperatureNC, pcrglobwb_forcing.precipitationNC]:
    dataset = xr.load_dataset(f"{pcrglobwb_forcing.directory}/{file_name}")
    print(dataset)
    print("------------------------")
    var = list(dataset.data_vars.keys())[0]
    dataset[var].isel(time=-1).plot(cmap="coolwarm", robust=True, size=5)
<xarray.Dataset> Size: 22MB
Dimensions:    (time: 1826, lat: 61, lon: 49, bnds: 2)
Coordinates:
  * time       (time) datetime64[ns] 15kB 1996-01-02 1996-01-03 ... 2000-12-31
  * lat        (lat) float32 244B 62.5 62.25 62.0 61.75 ... 48.0 47.75 47.5
  * lon        (lon) float32 196B -7.499 -7.249 -6.999 ... 4.001 4.251 4.501
    height     float64 8B 2.0
Dimensions without coordinates: bnds
Data variables:
    tas        (time, lat, lon) float32 22MB 279.2 279.1 279.0 ... 272.8 272.7
    time_bnds  (time, bnds) datetime64[ns] 29kB 1996-01-01T12:00:00 ... 2000-...
    lat_bnds   (lat, bnds) float32 488B 62.62 62.38 62.38 ... 47.62 47.62 47.38
    lon_bnds   (lon, bnds) float32 392B -7.625 -7.375 -7.375 ... 4.375 4.625
Attributes:
    Conventions:  CF-1.7
    software:     Created with ESMValTool v2.11.0
    caption:      Forcings for the PCR-GLOBWB hydrological model.
------------------------
<xarray.Dataset> Size: 22MB
Dimensions:    (time: 1826, lat: 61, lon: 49, bnds: 2)
Coordinates:
  * time       (time) datetime64[ns] 15kB 1996-01-02 1996-01-03 ... 2000-12-31
  * lat        (lat) float32 244B 62.5 62.25 62.0 61.75 ... 48.0 47.75 47.5
  * lon        (lon) float32 196B -7.499 -7.249 -6.999 ... 4.001 4.251 4.501
Dimensions without coordinates: bnds
Data variables:
    pr         (time, lat, lon) float32 22MB 0.006571 0.006238 ... 2.133e-05
    time_bnds  (time, bnds) datetime64[ns] 29kB 1996-01-01T12:00:00 ... 2000-...
    lat_bnds   (lat, bnds) float32 488B 62.62 62.38 62.38 ... 47.62 47.62 47.38
    lon_bnds   (lon, bnds) float32 392B -7.625 -7.375 -7.375 ... 4.375 4.625
Attributes:
    Conventions:  CF-1.7
    software:     Created with ESMValTool v2.11.0
    caption:      Forcings for the PCR-GLOBWB hydrological model.
------------------------
../../../_images/fc1559aff0b578f030fd7f8b90f7ecfe6cd0a32ec16b83351201b8b8edded10d.png ../../../_images/ca8cb5b745a3de8a464b410f59d825d8001c52894b2f584c94d393fa322ebf84.png