Skip to content

Commit

Permalink
Use years from KCS recipe (#2223)
Browse files Browse the repository at this point in the history
* use years from cfg for plots and reference period

* trailing whitespaces

* specified control period as flexible

* Remove write_plots option from global_matching diagnostic

* Minor automatic reformatting

Co-authored-by: Klaus Zimmermann <klaus.zimmermann@smhi.se>
Co-authored-by: Manuel Schlund <manuel.schlund@dlr.de>
  • Loading branch information
3 people authored Feb 18, 2022
1 parent 3d34c5b commit 7fad7e8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
2 changes: 1 addition & 1 deletion doc/sphinx/source/recipes/recipe_kcs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The original method created 8 resampled datasets:
* 2 main scenarios: Moderate (M) and Warm (W) (Lenderink 2014 uses "G" instead of "M").
* 2 'sub'scenarios: Relatively high (H) or low (L) changes in seasonal temperature and precipitation
* 2 time horizons: Mid-century (MOC; 2050) and end-of-century (EOC; 2085)
* Each scenario consists of changes calculated between 2 periods: Control (1981-2010) and future (variable).
* Each scenario consists of changes calculated between 2 periods: Control (e.g. 1981-2010) and future (variable).

The configuration settings for these resamples can be found in table 1 of Lenderink 2014's `supplementary data <https://iopscience.iop.org/1748-9326/9/11/115008/media/erl503687suppdata.pdf>`_.

Expand Down
22 changes: 13 additions & 9 deletions esmvaltool/diag_scripts/kcs/global_matching.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
"""Align the target model with the CMIP ensemble."""
import logging
from pathlib import Path
from itertools import product
from pathlib import Path

import matplotlib.pyplot as plt
import pandas as pd
import xarray as xr

from esmvaltool.diag_scripts.shared import (get_diagnostic_filename,
get_plot_filename, run_diagnostic,
select_metadata, ProvenanceLogger)
from esmvaltool.diag_scripts.shared import (
ProvenanceLogger,
get_diagnostic_filename,
get_plot_filename,
run_diagnostic,
select_metadata,
)

logger = logging.getLogger(Path(__file__).name)

Expand Down Expand Up @@ -53,9 +57,9 @@ def get_cmip_dt(metadata, year, percentile):
def get_resampling_period(target_dts, cmip_dt):
"""Return 30-year time bounds of the resampling period.
This is the period for which the target model delta T
matches the cmip delta T for a specific year.
Uses a 30-year rolling window to get the best match.
This is the period for which the target model delta T matches the
cmip delta T for a specific year. Uses a 30-year rolling window to
get the best match.
"""
target_dts = target_dts.rolling(time=30, center=True,
min_periods=30).mean()
Expand Down Expand Up @@ -85,8 +89,8 @@ def _timeline(axes, yloc, interval):
def make_plot(metadata, scenarios, cfg, provenance):
"""Make figure 3, left graph.
Multimodel values as line, reference value in black square,
steering variables in dark dots.
Multimodel values as line, reference value in black square, steering
variables in dark dots.
"""
fig, axes = plt.subplots()
for member in select_metadata(metadata, variable_group='tas_cmip'):
Expand Down
12 changes: 8 additions & 4 deletions esmvaltool/diag_scripts/kcs/local_resampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ def select_final_subset(cfg, subsets, prov=None):
return all_scenarios


def _cmip_envelope(datasetlist, variable, target_year):
def _cmip_envelope(datasetlist, variable, target_year, control_period):
"""Determine the change in <variable> PDF of each CMIP model.
Note: using mf_dataset not possible due to different calendars.
Expand All @@ -333,7 +333,8 @@ def _cmip_envelope(datasetlist, variable, target_year):
ancestors = []
for data_dict in cmip:
dataset = xr.open_dataset(data_dict['filename'])[variable]
control = dataset.sel(time=slice('1981', '2010'))
control = dataset.sel(time=slice(str(control_period[0]),
str(control_period[1])))
future = dataset.sel(time=slice(str(target_year -
15), str(target_year + 15)))

Expand Down Expand Up @@ -437,11 +438,14 @@ def make_plots(cfg, climates):
# tas/pr and once to get the multimodel pdf of the quantile changes
metadata = cfg['input_data'].values()

for year in [2050, 2085]:
years = np.unique([scenario['scenario_year']
for scenario in cfg['scenarios'].values()])
for year in years:
fig, subplots = plt.subplots(2, 2, figsize=(12, 8))

for row, variable in zip(subplots, ['pr', 'tas']):
cmip, prov = _cmip_envelope(metadata, variable, year)
cmip, prov = _cmip_envelope(metadata, variable, year,
cfg['control_period'])

for axes, season in zip(row, ['DJF', 'JJA']):
percentiles = cmip.percentile.values
Expand Down

0 comments on commit 7fad7e8

Please sign in to comment.