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

Add PRIMAVERA Eady Growth Rate diagnostic #1285

Merged
merged 57 commits into from
Feb 17, 2021
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
3b6f87f
First working version
sloosvel Jul 12, 2019
b22adde
Perform temporal mean
sloosvel Jul 12, 2019
41a832b
Fix some lint issues
sloosvel Jul 12, 2019
36c5444
Extract season properly
sloosvel Jul 15, 2019
81e1e87
Add recipe documentation
sloosvel Jul 15, 2019
5ad70ba
Load vars by shortname
sloosvel Aug 12, 2019
4f4bb8c
Fix winter script
sloosvel Aug 28, 2019
5be048a
Improve output file name
sloosvel Aug 28, 2019
9339c6f
Update preproc names
sloosvel Oct 11, 2019
3bca0ac
Merge branch 'version2_development' into PRIMAVERA_eady_growth
sloosvel Oct 14, 2019
e72f4df
Update recipe
sloosvel Oct 14, 2019
a28c926
Add provenance
sloosvel Oct 15, 2019
cf00614
Fix lint issues
sloosvel Oct 15, 2019
ee46ae3
Fix identation
sloosvel Oct 16, 2019
b2ffc0b
Fix lint issues
sloosvel Oct 16, 2019
5dab19c
Merge branch 'version2_development' into PRIMAVERA_eady_growth
bouweandela Oct 17, 2019
e02c406
Fix identation
sloosvel Oct 18, 2019
24c2e27
Update esmvaltool/diag_scripts/primavera/eady_growth_rate.py
sloosvel Oct 18, 2019
e3c4693
Update recipe with PRIMAVERA datasets
sloosvel Oct 18, 2019
37cdb16
Consider models that need ua to be regridded
sloosvel Oct 18, 2019
ddf46fd
Update references properly
sloosvel Oct 18, 2019
0c6d509
Fix yamllint issues
sloosvel Oct 23, 2019
4d4dd0c
Remove institute
sloosvel Nov 7, 2019
dae04f4
Reorder files
sloosvel Nov 19, 2019
1bdbf78
Fix provenance
sloosvel Nov 20, 2019
f5a3c12
Merge branch 'version2_development' into PRIMAVERA_eady_growth
sloosvel Nov 21, 2019
ac958d4
Merge remote-tracking branch 'origin/master' into PRIMAVERA_eady_growth
sloosvel Feb 20, 2020
777a7bc
Compute climatology as an option
sloosvel Feb 20, 2020
f7b1a74
Add option to compute means at the end
sloosvel Feb 20, 2020
2080b89
Merge remote-tracking branch 'origin/master' into PRIMAVERA_eady_growth
sloosvel Feb 20, 2020
895d26c
Fix style issues
sloosvel Feb 21, 2020
f254642
First version of plot, pending to clean
sloosvel Sep 15, 2020
c84f10b
Merge remote-tracking branch 'origin/master' into PRIMAVERA_eady_growth
sloosvel Sep 22, 2020
aeaf4c6
Clean recipe and diag
sloosvel Sep 22, 2020
babbcc5
Add documentation, pending to add figure
sloosvel Sep 22, 2020
fad670b
Add figure to documentation
sloosvel Sep 23, 2020
9ad2a42
Merge remote-tracking branch 'origin/master' into PRIMAVERA_eady_growth
sloosvel Nov 24, 2020
44fde95
Add missing author
sloosvel Nov 24, 2020
47d9154
Fix documentation
sloosvel Nov 24, 2020
bc35afb
Fix more documentation
sloosvel Nov 24, 2020
ab9a78f
Address suggestions from code review
sloosvel Nov 24, 2020
ba32f33
Fix style issues
sloosvel Nov 25, 2020
063d0ef
Update doc/sphinx/source/recipes/recipe_eady_growth_rate.rst
sloosvel Nov 25, 2020
2ae2cdd
Fix more style issues
sloosvel Nov 25, 2020
27a9efc
Merge branch 'PRIMAVERA_eady_growth' of https://github.com/ESMValGrou…
sloosvel Nov 25, 2020
c22825e
Fix documentation
sloosvel Nov 25, 2020
1d009ca
Fix more style issues
sloosvel Nov 25, 2020
fa2b287
Apply suggestions from code review
sloosvel Dec 2, 2020
8c4f27a
Fix more style issues
sloosvel Dec 9, 2020
fd5e1f0
More codacy issues
sloosvel Dec 10, 2020
20248c1
Merge remote-tracking branch 'origin/master' into PRIMAVERA_eady_growth
sloosvel Feb 15, 2021
3516985
Add suggestion fro scientific review
sloosvel Feb 15, 2021
3b81d94
Codacy
sloosvel Feb 15, 2021
17a3f0c
Remove uneeded parenthesis
sloosvel Feb 15, 2021
4a950f0
Merge remote-tracking branch 'origin/master' into PRIMAVERA_eady_growth
sloosvel Feb 16, 2021
5d02859
Fix doc format
Feb 16, 2021
d6d1d62
Fix doc format
Feb 16, 2021
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
11 changes: 11 additions & 0 deletions esmvaltool/config-references.yml
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,11 @@ authors:
lledo_llorenc:
name: Lledo, Llorenc
institute: BSC, Spain
orcid:
email:
loosveldt-tomas_saskia:
name: Loosveldt-Tomas, Saskia
institute: BSC, Spain
orcid:
lorenz_ruth:
name: Lorenz, Ruth
Expand Down Expand Up @@ -338,6 +343,10 @@ authors:
name: Roehrig, Romain
institute: MeteoFr, France
orcid: https://orcid.org/0000-0002-3903-3841
sanchez-gomez_emilia:
name: Sanchez, Emilia
institute: CERFACS, France
orcid:
serva_federico:
name: Serva, Federico
institute: CNR, Italy
Expand Down Expand Up @@ -690,6 +699,7 @@ references:
uwisc: "O'Dell et al., J. Clim., doi:10.1175/2007JCLI1958.1, 2008."
woa: "Locarnini et al., World Ocean Atlas 2013, Volume 1: Temperature, NOAA Atlas NESDIS 73, 2013."


projects:
c3s-magic: Copernicus Climate Change Service 34a Lot 2 (MAGIC) project
climval: BMBF MiKlip Project ClimVal
Expand All @@ -703,6 +713,7 @@ projects:
eval4cmip: DLR and University of Bremen project funded by the Initiative and Networking Fund of the Helmholtz Society
ewatercycle: eWaterCycle project
qa4ecv: QA4ECV
primavera: EU H2020 project PRIMAVERA
trr181: DFG Project TRR-181
ukesm: UKESM, UK Earth System Model project (NERC)

Expand Down
181 changes: 181 additions & 0 deletions esmvaltool/diag_scripts/primavera/eady_growth_rate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
import os
import logging

import iris
import iris.cube
import iris.analysis
import iris.util

import numpy as np

from dask import array as da

import esmvaltool.diag_scripts.shared
import esmvaltool.diag_scripts.shared.names as n
from esmvaltool.diag_scripts.shared import group_metadata
from esmvaltool.diag_scripts.shared._base import ProvenanceLogger
sloosvel marked this conversation as resolved.
Show resolved Hide resolved


logger = logging.getLogger(os.path.basename(__file__))


class EadyGrowthRate(object):
def __init__(self, config):
self.cfg = config
self.filenames = esmvaltool.diag_scripts.shared.Datasets(self.cfg)
self.fill_value = 1e20
self.ref_p = 1000.0
self.g = 9.80665
self.con = 0.3098
self.omega = 7.292e-5

def compute(self):
data = group_metadata(self.cfg['input_data'].values(), 'alias')
for alias in data:
var = group_metadata(data[alias], 'short_name')
ta = iris.load_cube(var['ta'][0]['filename'])
plev = ta.coord('air_pressure')

theta = self.potential_temperature(ta, plev)

del ta

zg = iris.load_cube(var['zg'][0]['filename'])

brunt = self.brunt_vaisala_frq(theta, zg)

lats = zg.coord('latitude')
fcor = self.coriolis(lats, zg.shape)

ua = iris.load_cube(var['ua'][0]['filename'])

egr = self.eady_growth_rate(fcor, ua, zg, brunt)

cube_egr = ua.copy(egr * 86400)

cube_egr = cube_egr.collapsed('time', iris.analysis.MEAN)

self.save(cube_egr, alias, data)

def potential_temperature(self, ta, plev):
p0 = iris.coords.AuxCoord(self.ref_p,
long_name='reference_pressure',
units='hPa')
p0.convert_units(plev.units)
p = (p0.points/plev.points)**(2/7)
theta = ta * iris.util.broadcast_to_shape(
p,
ta.shape,
ta.coord_dims('air_pressure')
)
theta.long_name = 'potential_air_temperature'

return theta

def vertical_integration(self, x, y):
# Perform a non-cyclic centered finite-difference to integrate
# along pressure levels

plevs = x.shape[1]

dxdy_0 = ((x[:, 1, :, :].lazy_data() - x[:, 0, :, :].lazy_data()) /
(y[:, 1, :, :].lazy_data() - y[:, 0, :, :].lazy_data()))

dxdy_centre = ((x[:, 2:plevs, :, :].lazy_data() -
x[:, 0:plevs-2, :, :].lazy_data()) /
(y[:, 2:plevs, :, :].lazy_data() -
y[:, 0:plevs-2, :, :].lazy_data()))

dxdy_end = ((x[:, plevs-1, :, :].lazy_data() -
x[:, plevs-2, :, :].lazy_data()) /
(y[:, plevs-1, :, :].lazy_data() -
y[:, plevs-2, :, :].lazy_data()))

bounds = [dxdy_end, dxdy_0]
stacked_bounds = da.stack(bounds, axis=1)
total = [dxdy_centre, stacked_bounds]

# Concatenate arrays where the last slice is dxdy_0
dxdy = da.concatenate(total, axis=1)

# Move dxdy_0 to the beggining of the array
dxdy = da.roll(dxdy, 1, axis=1)

return dxdy

def brunt_vaisala_frq(self, theta, zg):
dthdz = self.vertical_integration(theta, zg)
dthdz = da.where(dthdz > 0, dthdz, 0)
buoy = (self.g / theta.lazy_data()) * dthdz
brunt = da.sqrt(buoy)
brunt = da.where(brunt != 0, brunt, self.fill_value)

return brunt

def coriolis(self, lats, ndim):
fcor = 2.0 * self.omega * np.sin(np.radians(lats.points))
fcor = fcor[np.newaxis, np.newaxis, :, np.newaxis]
fcor = da.broadcast_to(fcor, ndim)

return fcor

def eady_growth_rate(self, fcor, ua, zg, brunt):
dudz = self.vertical_integration(ua, zg)
egr = self.con * abs(fcor) * abs(dudz) / brunt

return egr

def save(self, egr, alias, data):
egr.standard_name = None
egr.long_name = 'eady_growth_rate'
egr.var_name = 'egr'
egr.units = 'day-1'

script = self.cfg[n.SCRIPT]
project = data[alias][0]['project']
dataset = data[alias][0]['dataset']
exp = data[alias][0]['exp']
start = data[alias][0]['start_year']
end = data[alias][0]['end_year']
output_name = '{project}_' \
'{dataset}_' \
'{exp}_' \
'{script}_' \
'{start}_' \
'{end}.nc'.format(project=project,
dataset=dataset,
exp=exp,
script=script,
start=start,
end=end)
output_file = os.path.join(self.cfg[n.WORK_DIR], output_name)
iris.save(egr, output_file)

caption = ("{script} between {start} and {end}"
"according to {dataset}").format(
script=script.split('_'),
start=start,
end=end,
dataset=dataset
)
for i in range(len(data[alias])):
ancestors = [data[alias][i]['filename']]

record = {
'caption': caption,
'domains': ['global'],
'autors': ['sanchez-gomez_emilia'],
'references': ['acknow_project'],
'ancestors': ancestors
}
with ProvenanceLogger(self.cfg) as provenance_logger:
provenance_logger.log(output_file, record)


def main():
with esmvaltool.diag_scripts.shared.run_diagnostic() as config:
EadyGrowthRate(config).compute()


if __name__ == "__main__":
main()
69 changes: 69 additions & 0 deletions esmvaltool/recipes/recipe_eady_growth_rate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# ESMValTool
---
documentation:
description: |
Recipe to compute the annual, summer and winter Eady Growth Rates. The
output produces netcdf files for each model and season.


authors:
- sanchez-gomez_emilia

maintainer:
- loosveldt-tomas_saskia

projects:
- primavera

datasets:
- {dataset: CNRM-CM5, project: CMIP5, exp: historical, ensemble: r1i1p1,
mip: Amon, start_year: 1979, end_year: 2005}

preprocessors:
annual_mean:
annual_statistics:
summer_mean:
extract_season:
season: 'JJA'
seasonal_statistics:
winter_mean:
extract_season:
season: 'DJF'
seasonal_statistics:

diagnostics:
annual_egr:
variables:
ta:
preprocessor: annual_mean
zg:
preprocessor: annual_mean
ua:
preprocessor: annual_mean
scripts:
annual_eady_growth_rate:
script: primavera/eady_growth_rate.py

summer_egr:
variables:
ta:
preprocessor: summer_mean
zg:
preprocessor: summer_mean
ua:
preprocessor: summer_mean
scripts:
summer_eady_growth_rate:
script: primavera/eady_growth_rate.py

winter_egr:
variables:
ta:
preprocessor: winter_mean
zg:
preprocessor: winter_mean
ua:
preprocessor: winter_mean
scripts:
winter_eady_growth_rate:
script: primavera/eady_growth_rate.py