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

Update recipe_thermodyn_diagtool.yml: code improvements and more user options #1391

Merged
merged 67 commits into from
Jul 13, 2021
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
49f3e3b
Merge branch 'version2_development' into version2_thediato_v2
ValerioLembo Oct 18, 2019
7dfcdac
Added docstring; minor corrections
ValerioLembo Oct 25, 2019
22c545f
Correct some trailing spaces
ValerioLembo Oct 25, 2019
5fc62d3
Address complex warnings. Introduce time series plot for LEC.
ValerioLembo Oct 28, 2019
26f6a44
Minor corrections, prior to yaml
ValerioLembo Oct 28, 2019
36a6af2
Formatting issues fixed with isort
ValerioLembo Oct 29, 2019
fb7541a
Fixes to function comments after prospector
ValerioLembo Oct 29, 2019
47ef348
Address CircleCI complaints about wrong indendations (after yapf).
Oct 29, 2019
fb93d7b
Remove commented models in recipe@
Nov 1, 2019
2f24d40
Remove commented models in recipe
Nov 1, 2019
89cb4a2
One change left behind
Nov 12, 2019
f6594cf
Graphics fixing + trying to fix LEC table printout
ValerioLembo Nov 12, 2019
4ea0e3e
Closing LEC table file
ValerioLembo Nov 12, 2019
ea6f9c0
Closing LEC table file (correct)
ValerioLembo Nov 12, 2019
37dcbab
Troubles with overwriting
ValerioLembo Nov 12, 2019
3cff209
Solved issue with LEC tables
Nov 13, 2019
6aacb02
Completed function headers
ValerioLembo Nov 13, 2019
8990868
One file lagged behind...
ValerioLembo Nov 13, 2019
de7c767
Merge branch 'version2_development' into version2_thediato_v2
ValerioLembo Nov 13, 2019
aa3f53c
Something went wrong...
ValerioLembo Nov 13, 2019
7e3ee94
Bug fixing
ValerioLembo Nov 20, 2019
a543954
Fixed axis in scatter plot d)
ValerioLembo Nov 21, 2019
5b1c59e
Merge branch 'version2_development' into version2_thediato_v2
JaroCamphuijsen Nov 27, 2019
2679bc8
Comment EC-Earth-Veg and HadGEM3-GC31-LL out
Jan 10, 2020
3115c46
Merge branch 'version2_thediato_v2' of https://github.com/ESMValGroup…
Jan 10, 2020
f702d1c
Accounting for grid mismatch in HadGEM2 datasets
Feb 7, 2020
f351671
Remove commented line
Feb 7, 2020
01828d0
Uncomment recipe
Feb 28, 2020
b9a6c04
Merge branch 'master' of github.com:ESMValGroup/ESMValTool into versi…
bouweandela Apr 25, 2020
06ee8bd
Merge branch 'master' of github.com:ESMValGroup/ESMValTool into versi…
bouweandela Apr 28, 2020
8911882
Remove EC-Earth-Veg (dataset issue)
Jun 15, 2020
c992ae6
Merge branch 'version2_thediato_v2' of https://github.com/ESMValGroup…
Jun 15, 2020
a1f7aa2
Parser error
Jun 15, 2020
be2eb1e
Select uas and vas variables explicitly
ValerioLembo Jul 1, 2020
c9fbce4
Dealing with metadata from alternative variable groups
ValerioLembo Sep 3, 2020
58c774c
Back to the previous option for metadata choice in lorenz_cycle.py
ValerioLembo Sep 3, 2020
e2949d7
Test Peter - 1
ValerioLembo Sep 4, 2020
e03e2c2
Working correction suggested by Peter
Sep 4, 2020
46ac856
Working correction suggested by Peter
Sep 4, 2020
7119772
Merge remote-tracking branch 'origin/master' into version2_thediato_v2
Peter9192 Sep 15, 2020
c4b4abb
Pass flake8 checks
Peter9192 Sep 15, 2020
cf68701
Correct grammar spelling
Sep 15, 2020
5354e09
Removed BCC-CSM2-MR from recipe
Oct 14, 2020
8e0719d
Removed GFDL-CM4 from recipe.
Oct 23, 2020
626a41b
Switched HadGEM from p3 to p1
Oct 23, 2020
4af35af
Moved exp to the field specs
Oct 28, 2020
133e671
Back to exp key where it was...
Oct 29, 2020
d940107
Rearranged recipe to account for piControl masks
Oct 29, 2020
acd574b
(Yet) another dataset case for HadGEM3
Oct 30, 2020
a87b750
Including exception for CNRM-ESM1-2 fx
Oct 30, 2020
0a6f22d
Reduce number of years to reduce memory usage
nielsdrost Oct 30, 2020
6bffad3
Reverting last commit
nielsdrost Oct 31, 2020
7c9df29
Update iris documentation URL for sphinx
bouweandela Jan 27, 2021
c538258
Merge branch 'master' into version2_thediato_v2
Feb 3, 2021
0f82f4c
Testing git personal token
Feb 3, 2021
cb29e3c
Testing git personal token
ValerioLembo Feb 3, 2021
0ae8d9a
Merge branch 'version2_thediato_v2' of https://github.com/ESMValGroup…
ValerioLembo Feb 3, 2021
bce2420
Merge remote-tracking branch 'origin/iris-doc-url' into version2_thed…
Peter9192 Feb 3, 2021
a978616
Fix some small codacy issues
Peter9192 Feb 3, 2021
47ec743
Fix yamllint warnings
Peter9192 Feb 3, 2021
0773946
Updated documentation
ValerioLembo Feb 11, 2021
15336fd
Merge branch 'version2_thediato_v2' of https://github.com/ESMValGroup…
ValerioLembo Feb 11, 2021
52041a2
Minor changes to length of lines
ValerioLembo Feb 11, 2021
1254643
Removed trailing spaces
ValerioLembo Feb 11, 2021
9165c87
Merge remote-tracking branch 'origin/master' into version2_thediato_v2
Peter9192 Mar 10, 2021
6bd71c7
Update recipe_thermodyn_diagtool.rst
ValerioLembo Jul 13, 2021
b8e23bb
Update recipe_thermodyn_diagtool.rst
ValerioLembo Jul 13, 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
286 changes: 149 additions & 137 deletions esmvaltool/diag_scripts/thermodyn_diagtool/computations.py

Large diffs are not rendered by default.

133 changes: 67 additions & 66 deletions esmvaltool/diag_scripts/thermodyn_diagtool/fourier_coefficients.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@
def fourier_coeff(tadiagfile, outfile, ta_input, tas_input):
"""Compute Fourier coefficients in lon direction.

Receive as input:
- tadiagfile: the name of a file to store modified t fields;
- outfile: the name of a file to store the Fourier coefficients;
- ta_input: the name of a file containing t,u,v,w fields;
- tas_input: the name of a file containing t2m field.
Arguments:
---------
tadiagfile: the name of a file to store modified t fields;
outfile: the name of a file to store the Fourier coefficients;
ta_input: the name of a file containing t,u,v,w fields;
tas_input: the name of a file containing t2m field.
"""
with Dataset(ta_input) as dataset:
lon = dataset.variables['lon'][:]
Expand Down Expand Up @@ -59,10 +60,10 @@ def fourier_coeff(tadiagfile, outfile, ta_input, tas_input):
deltat[:, i - 1, :, :] = np.where(ta1_fx[:, i - 1, :, :] != 0,
deltat[:, i - 1, :, :],
(ta1_fx[:, i, :, :] - tas))
deltat[:, i - 1, :, :] = (
(1 * np.array(h_1.mask)) * np.array(deltat[:, i - 1, :, :]))
d_p = -(
(P_0 * G_0 / (GAM * GAS_CON)) * deltat[:, i - 1, :, :] / tas)
deltat[:, i - 1, :, :] = ((1 * np.array(h_1.mask)) *
np.array(deltat[:, i - 1, :, :]))
d_p = -((P_0 * G_0 /
(GAM * GAS_CON)) * deltat[:, i - 1, :, :] / tas)
p_s = np.where(ta1_fx[:, i - 1, :, :] != 0, p_s, lev[i - 1] + d_p)
for k in np.arange(0, nlev - i - 1, 1):
h_3 = np.ma.masked_where(ta1_fx[:, i + k, :, :] != 0,
Expand All @@ -84,10 +85,11 @@ def fourier_coeff(tadiagfile, outfile, ta_input, tas_input):
deltap[:, i, :, :] = p_s - lev[i]
h_2 = np.ma.masked_where(ta2_fx[:, i, :, :] == 0, ta2_fx[:, i, :, :])
mask[i, :, :, :] = np.array(h_2.mask)
tafr_bar[i, :, :, :] = (1 * np.array(mask[i, :, :, :]) * (
tas - GAM * GAS_CON / (G_0 * p_s) * deltap[:, i, :, :] * tas))
dat[i, :, :, :] = (
ta2_fx[:, i, :, :] * (1 - 1 * np.array(mask[i, :, :, :])))
tafr_bar[i, :, :, :] = (1 * np.array(mask[i, :, :, :]) *
(tas - GAM * GAS_CON /
(G_0 * p_s) * deltap[:, i, :, :] * tas))
dat[i, :, :, :] = (ta2_fx[:, i, :, :] *
(1 - 1 * np.array(mask[i, :, :, :])))
t_a[:, i, :, :] = dat[i, :, :, :] + tafr_bar[i, :, :, :]
pr_output_diag(t_a, ta_input, tadiagfile, 'ta')
tafft_p = np.fft.fft(t_a, axis=3)[:, :, :, :int(trunc / 2)] / (nlon)
Expand Down Expand Up @@ -117,19 +119,19 @@ def pr_output(dict_v, nc_f, fileo, file_desc, wave2):
Save fields to NetCDF, retrieving information from an existing
NetCDF file. Metadata are transferred from the existing file to the
new one.

Arguments:
- var1, var2, var3, var4: the fields to be stored, with shape
(time,level,wave,lon);
- nc_f: the existing dataset, from where the metadata are
retrieved. Coordinates time,level and lon have to be the same
dimension as the fields to be saved to the new files;
- fileo: the name of the output file;
- wave2: an array containing the zonal wavenumbers;
- name1, name2, name3, name4: the name of the variables to be
saved;

PROGRAMMER(S)
Chris Slocum (2014), modified by Valerio Lembo (2018).
---------
var1, var2, var3, var4: the fields to be stored, with shape
(time,level,wave,lon);
nc_f: the existing dataset, from where the metadata are retrieved.
Coordinates time,level and lon have to be the same dimension as the
fields to be saved to the new files;
fileo: the name of the output file;
wave2: an array containing the zonal wavenumbers;
name1, name2, name3, name4: the name of the variables to be saved;

@author: Chris Slocum (2014), modified by Valerio Lembo (2018).
"""
# Writing NetCDF files
with Dataset(fileo, 'w', format='NETCDF4') as var_nc_fid:
Expand Down Expand Up @@ -157,16 +159,17 @@ def pr_output_diag(var1, nc_f, fileo, name1):
Save fields to NetCDF, retrieving information from an existing
NetCDF file. Metadata are transferred from the existing file to the
new one.

Arguments:
- var1: the field to be stored, with shape (time,level,lat,lon);
- nc_f: the existing dataset, from where the metadata are
retrieved. Coordinates time,level, lat and lon have to be the
same dimension as the fields to be saved to the new files;
- fileo: the name of the output file;
- name1: the name of the variable to be saved;

PROGRAMMER(S)
Chris Slocum (2014), modified by Valerio Lembo (2018).
---------
var1: the field to be stored, with shape (time,level,lat,lon);
nc_f: the existing dataset, from where the metadata are retrieved.
Coordinates time,level, lat and lon have to be the same dimension as
the fields to be saved to the new files;
fileo: the name of the output file;
name1: the name of the variable to be saved;

@author: Chris Slocum (2014), modified by Valerio Lembo (2018).
"""
with Dataset(fileo, 'w', format='NETCDF4') as var_nc_fid:
var_nc_fid.description = "Fourier coefficients"
Expand All @@ -180,20 +183,18 @@ def pr_output_diag(var1, nc_f, fileo, name1):
('time', 'plev', 'lat', 'lon'))
varatts(var1_nc_var, name1)
var_nc_fid.variables[name1][:, :, :, :] = var1
var_nc_fid.close() # close the new file


def extr_lat(nc_fid, var_nc_fid, latn):
"""Extract lat coord. from NC files and save them to a new NC file.

Arguments:
- nc_f: the existing dataset, from where the metadata are
retrieved. Time,level and lon dimensions
are retrieved;
- var_nc_fid: the id of the new NC dataset previously created;
- latn: the name of the latitude dimension;
---------
nc_f: the existing dataset, from where the metadata are
retrieved. Time,level and lon dimensions are retrieved;
var_nc_fid: the id of the new NC dataset previously created;
latn: the name of the latitude dimension;
"""
# Extract coordinates from NetCDF file
lats = nc_fid.variables['lat'][:]
var_nc_fid.createDimension(latn, len(lats))
var_nc_dim = var_nc_fid.createVariable(latn, nc_fid.variables['lat'].dtype,
Expand All @@ -207,16 +208,16 @@ def extr_lon(nc_fid, var_nc_fid):
"""Extract lat coord. from NC files and save them to a new NC file.

Arguments:
- nc_f: the existing dataset, from where the metadata are
retrieved. Time,level and lon dimensions
are retrieved;
- var_nc_fid: the id of the new NC dataset previously created;
---------
nc_f: the existing dataset, from where the metadata are
retrieved. Time,level and lon dimensions are retrieved;
var_nc_fid: the id of the new NC dataset previously created;
"""
# Extract coordinates from NetCDF file
lons = nc_fid.variables['lon'][:]
var_nc_fid.createDimension('lon', len(lons))
var_nc_dim = var_nc_fid.createVariable(
'lon', nc_fid.variables['lon'].dtype, ('lon', ))
var_nc_dim = var_nc_fid.createVariable('lon',
nc_fid.variables['lon'].dtype,
('lon', ))
for ncattr in nc_fid.variables['lon'].ncattrs():
var_nc_dim.setncattr(ncattr, nc_fid.variables['lon'].getncattr(ncattr))
var_nc_fid.variables['lon'][:] = lons
Expand All @@ -226,15 +227,16 @@ def extr_plev(nc_fid, var_nc_fid):
"""Extract plev coord. from NC files and save them to a new NC file.

Arguments:
- nc_f: the existing dataset, from where the metadata are
retrieved. Time,level and lon dimensions
are retrieved;
- var_nc_fid: the id of the new NC dataset previously created;
---------
nc_f: the existing dataset, from where the metadata are
retrieved. Time,level and lon dimensions are retrieved;
var_nc_fid: the id of the new NC dataset previously created;
"""
plev = nc_fid.variables['plev'][:]
var_nc_fid.createDimension('plev', len(plev))
var_nc_dim = var_nc_fid.createVariable(
'plev', nc_fid.variables['plev'].dtype, ('plev', ))
var_nc_dim = var_nc_fid.createVariable('plev',
nc_fid.variables['plev'].dtype,
('plev', ))
for ncattr in nc_fid.variables['plev'].ncattrs():
var_nc_dim.setncattr(ncattr,
nc_fid.variables['plev'].getncattr(ncattr))
Expand All @@ -245,17 +247,16 @@ def extr_time(nc_fid, var_nc_fid):
"""Extract time coord. from NC files and save them to a new NC file.

Arguments:
- nc_f: the existing dataset, from where the metadata are
retrieved. Time,level and lon dimensions
are retrieved;
- var_nc_fid: the id of the new NC dataset previously created;
---------
nc_f: the existing dataset, from where the metadata are
retrieved. Time,level and lon dimensions are retrieved;
var_nc_fid: the id of the new NC dataset previously created;
"""
# Extract coordinates from NetCDF file
time = nc_fid.variables['time'][:]
# Using our previous dimension info, we can create the new dimensions.
var_nc_fid.createDimension('time', len(time))
var_nc_dim = var_nc_fid.createVariable(
'time', nc_fid.variables['time'].dtype, ('time', ))
var_nc_dim = var_nc_fid.createVariable('time',
nc_fid.variables['time'].dtype,
('time', ))
for ncattr in nc_fid.variables['time'].ncattrs():
var_nc_dim.setncattr(ncattr,
nc_fid.variables['time'].getncattr(ncattr))
Expand All @@ -266,8 +267,9 @@ def varatts(w_nc_var, varname):
"""Add attibutes to the variables, depending on their name.

Arguments:
- w_nc_var: a variable object;
- varname: the name of the variable, among ta, ua, va and wap.
---------
w_nc_var: a variable object;
varname: the name of the variable, among ta, ua, va and wap.
"""
if varname == 'ta':
w_nc_var.setncatts({
Expand All @@ -289,8 +291,7 @@ def varatts(w_nc_var, varname):
})
elif varname == 'wap':
w_nc_var.setncatts({
'long_name': 'Lagrangian tendency of '
'air pressure',
'long_name': 'Lagrangian tendency of air pressure',
'units': "Pa s-1",
'level_desc': 'pressure levels'
})
Loading