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

Flow-Dependent, Cross-Timescale Model Diagnostic POD #127

Open
wants to merge 120 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 117 commits
Commits
Show all changes
120 commits
Select commit Hold shift + click to select a range
cfe7d4f
Merge pull request #1 from NOAA-GFDL/develop
Apr 21, 2021
0e67cc2
creating a dummy PR for the 'flow-dependent, cross-timescale model di…
Feb 2, 2021
4110808
renaming files; adding settings file; deleted old directory
Feb 3, 2021
61d7f8b
adding to the settings.jsonc file
Feb 4, 2021
7dede33
added python files for diagnostics
Feb 5, 2021
ff796c9
adding variables to settings document
Feb 10, 2021
488c6ac
changing diagnostics code to start incorporating envt vars; change fi…
Feb 10, 2021
6d1ea26
adding a mostly blank file which will be used as main driver file
Feb 10, 2021
44a6b97
editing files to include environment variables
Feb 19, 2021
64582dc
add in info for envt vars
Mar 8, 2021
d0d2ac2
create new file with working code without env vars
Apr 14, 2021
5736bf4
add function file to calc climatology anomalies
Apr 14, 2021
38faa87
initial redo of settings file
Apr 14, 2021
0c4ce2b
adding environment variables into main code
Apr 15, 2021
4122050
editing environment variables
Apr 15, 2021
2d2ae39
editing environment vars in driver file
Apr 15, 2021
3a071c1
edit variable names to fit convention of example data
Apr 15, 2021
a5ede68
editing environment variables
Apr 16, 2021
b00df52
edit settings file to slice vars at pressure level
Apr 19, 2021
d9f8103
edit settings file
Apr 19, 2021
b85db3c
add .DS_Store to gitignore
Apr 21, 2021
30ce656
Adding variables to fieldlist_NCAR.jsonc
Apr 22, 2021
8c3a03b
add units to varlist; change varlist key structure
Apr 23, 2021
9595c20
making some changes to environment variables to get POD working on mo…
Apr 23, 2021
b11e928
removing progress checks from code
Apr 26, 2021
5edb993
new progress checks added
Apr 26, 2021
16390e1
make a function which runs the diagnostic on model data
Apr 26, 2021
ed31845
changing output file name
Apr 26, 2021
1cc7cac
editing driver script to check for missing files.
Apr 26, 2021
86e8079
adding documentation, removing excess code
Apr 27, 2021
42fb697
Saving climatology anomaly data as new files
Apr 27, 2021
bd736c0
adding in documentation
May 14, 2021
521b525
add yaml file
May 17, 2021
b80a836
add documentation to main file
May 17, 2021
28d0594
adding documentation to file used for preprocessing of data
May 17, 2021
065575c
adding documentation
May 17, 2021
311c0c8
adding documentation
May 17, 2021
dc94dc7
edit casename for sample data
May 17, 2021
8e0bbfd
Merge pull request #2 from NOAA-GFDL/develop
May 17, 2021
94c2f99
Merge branch 'develop' into feature/flow_dep_diags
May 17, 2021
56d8e7e
uncommenting out variables
May 20, 2021
624530b
removing merge conflict notation
May 20, 2021
04ab32a
removing un-needed comment
May 20, 2021
dc063d3
set paths to none for example cropping code
May 20, 2021
446961d
removing template lines
May 20, 2021
2bff623
removing comment
May 20, 2021
0f54445
removing prefix condition from yaml
May 20, 2021
88e7de2
delete old file
May 20, 2021
1c1cf72
deleting unneccessary comment
May 24, 2021
1beb836
delete pandas import from code
May 25, 2021
d667a6a
aditional pandas import deleted
May 25, 2021
0e0fa69
delete unused function
May 25, 2021
183a3bc
minor edits
May 27, 2021
b02c0f5
remove modification from src file
May 28, 2021
d117663
editing long names to fix fieldlist conflict; adding alternative for …
May 28, 2021
8c957df
removing edits from default settings file
May 28, 2021
2bb30d8
edit alternate variable in settings file
May 28, 2021
5a8674c
creating a dummy PR for the 'flow-dependent, cross-timescale model di…
Feb 2, 2021
dc54488
renaming files; adding settings file; deleted old directory
Feb 3, 2021
d60c275
adding to the settings.jsonc file
Feb 4, 2021
b3d9024
added python files for diagnostics
Feb 5, 2021
10625b6
adding variables to settings document
Feb 10, 2021
dac629b
changing diagnostics code to start incorporating envt vars; change fi…
Feb 10, 2021
a616df9
adding a mostly blank file which will be used as main driver file
Feb 10, 2021
683f1ba
editing files to include environment variables
Feb 19, 2021
e12df0a
add in info for envt vars
Mar 8, 2021
11ecd5e
create new file with working code without env vars
Apr 14, 2021
7ce9b5c
add function file to calc climatology anomalies
Apr 14, 2021
b8440df
initial redo of settings file
Apr 14, 2021
99d3d8b
adding environment variables into main code
Apr 15, 2021
9a50ec6
editing environment variables
Apr 15, 2021
e473b59
editing environment vars in driver file
Apr 15, 2021
442b4dc
edit variable names to fit convention of example data
Apr 15, 2021
7c1a43d
editing environment variables
Apr 16, 2021
360b6f7
edit settings file to slice vars at pressure level
Apr 19, 2021
acfb4fb
edit settings file
Apr 19, 2021
902e731
add .DS_Store to gitignore
Apr 21, 2021
0d9259a
Adding variables to fieldlist_NCAR.jsonc
Apr 22, 2021
ad88d93
add units to varlist; change varlist key structure
Apr 23, 2021
9cef3c3
making some changes to environment variables to get POD working on mo…
Apr 23, 2021
bda078b
removing progress checks from code
Apr 26, 2021
3aa47aa
new progress checks added
Apr 26, 2021
de49316
make a function which runs the diagnostic on model data
Apr 26, 2021
55728dd
changing output file name
Apr 26, 2021
7125ec7
editing driver script to check for missing files.
Apr 26, 2021
df4ed16
adding documentation, removing excess code
Apr 27, 2021
825afd5
Saving climatology anomaly data as new files
Apr 27, 2021
63bc1b0
adding in documentation
May 14, 2021
9190b98
add yaml file
May 17, 2021
2ec611c
add documentation to main file
May 17, 2021
15bd2e3
adding documentation to file used for preprocessing of data
May 17, 2021
2768fea
adding documentation
May 17, 2021
385a2f1
adding documentation
May 17, 2021
85ad6cb
edit casename for sample data
May 17, 2021
a73aa69
uncommenting out variables
May 20, 2021
b9c9f7f
removing merge conflict notation
May 20, 2021
5874d29
removing un-needed comment
May 20, 2021
febdf6d
set paths to none for example cropping code
May 20, 2021
cc1a950
removing template lines
May 20, 2021
09a4e98
removing comment
May 20, 2021
e903dec
removing prefix condition from yaml
May 20, 2021
72a26a6
delete old file
May 20, 2021
9ba4694
deleting unneccessary comment
May 24, 2021
45ffc12
delete pandas import from code
May 25, 2021
1c7010c
aditional pandas import deleted
May 25, 2021
3e52efa
delete unused function
May 25, 2021
b4f9766
minor edits
May 27, 2021
824007e
remove modification from src file
May 28, 2021
28c6019
editing long names to fix fieldlist conflict; adding alternative for …
May 28, 2021
3564967
removing edits from default settings file
May 28, 2021
4c9df31
edit alternate variable in settings file
May 28, 2021
0d27e5f
editing variable standard names in settings file
Jun 21, 2021
f313f8a
editing variable standard names in fieldlist file
Jun 21, 2021
89b8d69
Merge branch 'feature/flow_dep_diags' of github.com:drewmresnick/MDTF…
Jun 21, 2021
f5d54e3
minor corrections to documentation
Jun 24, 2021
8454226
reverting default_tests.jsonc back to its original state
Jun 24, 2021
03616ec
removing unused varibales / module
Jun 24, 2021
e342906
change decode_times to use_cftime
Jul 9, 2021
cfb2a4e
edit comments for explaining how grid shift works
Jul 9, 2021
ac57a47
Merge branch 'NOAA-GFDL:main' into feature/flow_dep_diags
Sep 20, 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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,5 @@ pip-log.txt
pip-delete-this-directory.txt

# Jupyter Notebook
.ipynb_checkpoints
.ipynb_checkpoints
.DS_Store
17 changes: 16 additions & 1 deletion data/fieldlist_NCAR.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@
"ndim": 3
},
"TREFHT" : {
// correct name? CMIP6 equivalent should be tas, temp at 2m ref height
"standard_name": "air_temperature",
"units": "K",
"ndim": 3
Expand Down Expand Up @@ -157,6 +156,22 @@
"units": "W m-2",
"ndim": 3
},
// Variables for flow_dep_diag module:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to add in the companion fields to the GFDL and CMIP fieldlists

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jkrasting Is this then not something I need to worry about?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@drewmresnick This is a todo for the framework team, so one of us will take care of it.

Copy link
Contributor

@tsjackson-noaa tsjackson-noaa Jul 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for bringing this to my attention. Unfortunately constructions of the from variable_at_XX_mbar aren't CF standard names [*].

The way variables on pressure levels are intended to be specified in the settings file is described in the documentation: the level is specified separately with a scalar_coordinate attribute, which refers to a vertical coordinate axis defined in the dimensions section of the file. By spelling out what's meant in more detail like this, it e.g. enables the framework to extract levels from 3D data on the fly in a fully units-aware way.

For more examples of how this is set up, look at the settings file for the Wheeler-Kiladis diagnostic.

[*]: I haven't been able to find a concise reference for this: the upshot is that standard names are meant to identify physical quantities, independently of how that quantity is sampled in space or time (but there are exceptions to this, such as air_pressure_at_sea_level, which deal with physical rather than mathematical boundaries). Variables on pressure levels in the CMIP6 data request don't use different standard names in this way (example), and pressure levels aren't one of the cases covered in construction of derived standard names.

"Z250": {
"standard_name": "geopotential_height_250_mbar",
"units": "m",
"ndim": 3
},
"T250": {
"standard_name": "temperature_250_mbar",
"units": "K",
"ndim": 3
},
"T500": {
"standard_name": "temperature_500_mbar",
"units": "K",
"ndim": 3
},
// Variables for AMOC_3D_Structure module:
// "uo": {
// "standard_name": "sea_water_x_velocity",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# This file is part of the convective_transition_diag module of the MDTF code package (see LICENSE.txt)

# This file is part of the convective_transition_diag module of the MDTF code package (see mdtf/MDTF_v2.0/LICENSE.txt)
# ======================================================================
# convecTransCriticalCollapse_usp.py
#
# Called by convecTransCriticalCollapse.py
# Provides User-Specified Parameters for Fitting and Plotting
#
# This file is part of the Convective Transition Diagnostic Package
# This file is part of the Convective Transition Diagnostic Package
# and the MDTF code package. See LICENSE.txt for the license.
#
import json
Expand All @@ -32,7 +31,7 @@

TAVE_VAR=os.environ["tave_var"]
QSAT_INT_VAR=os.environ["qsat_int_var"]
# Use 1:tave, or 2:qsat_int as Bulk Tropospheric Temperature Measure
# Use 1:tave, or 2:qsat_int as Bulk Tropospheric Temperature Measure
BULK_TROPOSPHERIC_TEMPERATURE_MEASURE=int(os.environ["BULK_TROPOSPHERIC_TEMPERATURE_MEASURE"])

# Directory & Filename for saving binned results (netCDF4)
Expand All @@ -53,7 +52,7 @@
# List binned data file (with filename corresponding to casename)
bin_output_list=sorted(glob.glob(BIN_OUTPUT_DIR+"/"+BIN_OUTPUT_FILENAME+".nc"))

# Directory & Filename for saving figures
# Directory & Filename for saving figures
# convecTransCriticalCollapse.py generates 2 sets figures for MODEL
FIG_OUTPUT_DIR=os.environ["WK_DIR"]+"/model/PS"
# Figure filename for Convective Transition Statistics (CTS)
Expand Down Expand Up @@ -87,7 +86,7 @@
##### Start: FITTING-REQUIRED PARAMETERS #####
# Use PRECIP_REF (units: mm/hr) to find a 0-th order approximation of Critical CWV w_c
# and PRECIP_FIT_MIN<precip<PRECIP_FIT_MAX (units: mm/hr) for Fitting
# Different values for MODEL & OBS
# Different values for MODEL & OBS
# Change values for MODEL if necessary
PRECIP_REF_MODEL=1
PRECIP_FIT_MIN_MODEL=1.5
Expand Down Expand Up @@ -118,7 +117,7 @@
marker_size = 40 # size of markers in scatter plots
xtick_pad = 10 # padding between x tick labels and actual plot
figsize1 = 14 # figure size set by figsize=(figsize1,figsize2)
figsize2 = 12
figsize2 = 12

### There are 4+2 figures in level 2 diagnostics ###
### Choose the plot parameters for each figure below ###
Expand All @@ -137,7 +136,7 @@
#==========================================
##### Figure 1 : Precip vs. CWV-w_c #######
#==========================================
xlim1['f1']=-45
xlim1['f1']=-45
xlim2['f1']=15

ylim1['f1']=0
Expand All @@ -156,7 +155,7 @@
#========================================================
##### Figure 2 : Probability of precip vs. CWV-w_c ######
#========================================================
xlim1['f2']=-45
xlim1['f2']=-45
xlim2['f2']=15

ylim1['f2']=0
Expand Down Expand Up @@ -321,7 +320,7 @@
fig_params={}

fig_params['f0']=[axes_fontsize,legend_fontsize,marker_size,xtick_pad,figsize1,figsize2]
for i in ['f1','f2','f3','f4','f5','f6']:
for i in ['f1','f2','f3','f4','f5','f6']:
fig_params[i]=[[xlim1[i],xlim2[i]],[ylim1[i],ylim2[i]],xlabel[i],ylabel[i],xticks[i],yticks[i]]

data["plot_params"]=fig_params
Expand Down
94 changes: 46 additions & 48 deletions diagnostics/example/example_diag.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,75 +2,75 @@
# ================================================================================
# This script does a simple diagnostic calculation to illustrate how to adapt code
# for use in the MDTF diagnostic framework. The main change is to set input/output
# paths, variable names etc. from shell environment variables the framework
# paths, variable names etc. from shell environment variables the framework
# provides, instead of hard-coding them.
#
# Below, this script consists of 2 parts: (1) a template of comprehensive header POD
# developers must include in their POD's main driver script, (2) actual code, and
# developers must include in their POD's main driver script, (2) actual code, and
# (3) extensive in-line comments.
# ================================================================================
#
#
# This file is part of the Example Diagnostic POD of the MDTF code package (see mdtf/MDTF-diagnostics/LICENSE.txt)
#
#
# Example Diagnostic POD
#
#
# Last update: 8/1/2020
#
#
# This is a example POD that you can use as a template for your diagnostics.
# If this were a real POD, you'd place a one-paragraph synopsis of your
# diagnostic here (like an abstract).
#
# If this were a real POD, you'd place a one-paragraph synopsis of your
# diagnostic here (like an abstract).
#
# Version & Contact info
#
#
# Here you should describe who contributed to the diagnostic, and who should be
# contacted for further information:
#
#
# - Version/revision information: version 1 (5/06/2020)
# - PI (name, affiliation, email)
# - Developer/point of contact (name, affiliation, email)
# - Other contributors
#
#
# Open source copyright agreement
#
# The MDTF framework is distributed under the LGPLv3 license (see LICENSE.txt).
#
# The MDTF framework is distributed under the LGPLv3 license (see LICENSE.txt).
# Unless you've distirbuted your script elsewhere, you don't need to change this.
#
#
# Functionality
#
# In this section you should summarize the stages of the calculations your
# diagnostic performs, and how they translate to the individual source code files
# provided in your submission. This will, e.g., let maintainers fixing a bug or
#
# In this section you should summarize the stages of the calculations your
# diagnostic performs, and how they translate to the individual source code files
# provided in your submission. This will, e.g., let maintainers fixing a bug or
# people with questions about how your code works know where to look.
#
#
# Required programming language and libraries
#
# In this section you should summarize the programming languages and third-party
# libraries used by your diagnostic. You also provide this information in the
# ``settings.jsonc`` file, but here you can give helpful comments to human
#
# In this section you should summarize the programming languages and third-party
# libraries used by your diagnostic. You also provide this information in the
# ``settings.jsonc`` file, but here you can give helpful comments to human
# maintainers (eg, "We need at least version 1.5 of this library because we call
# this function.")
#
#
# Required model output variables
#
# In this section you should describe each variable in the input data your
# diagnostic uses. You also need to provide this in the ``settings.jsonc`` file,
# but here you should go into detail on the assumptions your diagnostic makes
#
# In this section you should describe each variable in the input data your
# diagnostic uses. You also need to provide this in the ``settings.jsonc`` file,
# but here you should go into detail on the assumptions your diagnostic makes
# about the structure of the data.
#
#
# References
#
# Here you should cite the journal articles providing the scientific basis for
#
# Here you should cite the journal articles providing the scientific basis for
# your diagnostic.
#
#
# Maloney, E. D, and Co-authors, 2019: Process-oriented evaluation of climate
# and wether forcasting models. BAMS, 100(9), 1665-1686,
# doi:10.1175/BAMS-D-18-0042.1.
#
import os
import matplotlib
matplotlib.use('Agg') # non-X windows backend
# Commands to load third-party libraries. Any code you don't include that's
# not part of your language's standard library should be listed in the
# Commands to load third-party libraries. Any code you don't include that's
# not part of your language's standard library should be listed in the
# settings.jsonc file.
import xarray as xr # python library we use to read netcdf files
import matplotlib.pyplot as plt # python library we use to make plots
Expand All @@ -80,24 +80,22 @@
#
# The framework copies model data to a regular directory structure of the form
# <DATADIR>/<frequency>/<CASENAME>.<variable_name>.<frequency>.nc
# Here <variable_name> and frequency are requested in the "varlist" part of
# Here <variable_name> and frequency are requested in the "varlist" part of
# settings.json.

# The following command sets input_path to the value of the shell environment
# variable called TAS_FILE. This variable is set by the framework to let the
# variable called TAS_FILE. This variable is set by the framework to let the
# script know where the locally downloaded copy of the data for this variable
# (which we called "tas") is.
input_path = os.environ["TAS_FILE"]

# command to load the netcdf file
model_dataset = xr.open_dataset(input_path)


### 2) Doing computations: #####################################################
#
# Diagnostics in the framework are intended to work with native output from a
# variety of models. For this reason, variable names should not be hard-coded
# but instead set from environment variables.
# but instead set from environment variables.
#
tas_var_name = os.environ["tas_var"]
# For safety, don't even assume that the time dimension of the input file is
Expand All @@ -117,10 +115,10 @@

### 3) Saving output data: #####################################################
#
# Diagnostics should write output data to disk to a) make relevant results
# Diagnostics should write output data to disk to a) make relevant results
# available to the user for further use or b) to pass large amounts of data
# between stages of a calculation run as different sub-scripts. Data can be in
# any format (as long as it's documented) and should be written to the
# any format (as long as it's documented) and should be written to the
# directory <WK_DIR>/model/netCDF (created by the framework).
#
out_path = "{WK_DIR}/model/netCDF/temp_means.nc".format(**os.environ)
Expand All @@ -131,9 +129,9 @@

### 4) Saving output plots: ####################################################
#
# Plots should be saved in EPS or PS format at <WK_DIR>/<model or obs>/PS
# (created by the framework). Plots can be given any filename, but should have
# the extension ".eps" or ".ps". To make the webpage output, the framework will
# Plots should be saved in EPS or PS format at <WK_DIR>/<model or obs>/PS
# (created by the framework). Plots can be given any filename, but should have
# the extension ".eps" or ".ps". To make the webpage output, the framework will
# convert these to bitmaps with the same name but extension ".png".

# Define a python function to make the plot, since we'll be doing it twice and
Expand All @@ -160,14 +158,14 @@ def plot_and_save_figure(model_or_obs, title_string, dataset):

### 5) Loading obs data files & plotting obs figures: ##########################
#
# If your diagnostic uses any model-independent supporting data (eg. reference
# If your diagnostic uses any model-independent supporting data (eg. reference
# or observational data) larger than a few kB of text, it should be provided via
# the observational data distribution instead of being included with the source
# code. This data can be in any format: the framework doesn't process it. The
# code. This data can be in any format: the framework doesn't process it. The
# environment variable OBS_DATA will be set to a path where the framework has
# copied a directory containing your supplied data.
#
# The following command replaces the substring "{OBS_DATA}" with the value of
# The following command replaces the substring "{OBS_DATA}" with the value of
# the OBS_DATA environment variable.
input_path = "{OBS_DATA}/example_tas_means.nc".format(**os.environ)

Expand Down
23 changes: 23 additions & 0 deletions diagnostics/flow_dep_diag/ClimAnom_func.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import os
import xarray as xr
import numpy as np
from datetime import datetime
np.seterr(divide='ignore', invalid='ignore')

### Function to calculate climatology anomalies for each variable in the diagnostic.

time_var = os.environ["time_coord"] #set environment variable for time equal to var for function
#function to calculate climatology anomalies for eah variable
def climAnom(var_path, var_name):

ds = xr.open_dataset(var_path, decode_times = True)
wrongkindofdoctor marked this conversation as resolved.
Show resolved Hide resolved
ds[time_var] = ds.indexes[time_var].to_datetimeindex() #convert time to datetime so we can use groupby functionality
# Drop 1 dimensional coordinates
ds = ds.squeeze()
da = ds[var_name]
da_ensmean = da.copy()
da_day_clim = da_ensmean.groupby('{time_coord}.dayofyear'.format(**os.environ)).mean(time_var)
da_day_anom = da.groupby('{time_coord}.dayofyear'.format(**os.environ)) - da_day_clim
da_day_anom = da_day_anom.drop('dayofyear')
da_day_anom.to_netcdf("{WK_DIR}/model/netCDF/".format(**os.environ) + var_name + "_climAnom.nc")
return da_day_anom
Loading