Skip to content

Commit

Permalink
Merge pull request #250 from justin-richling/tem-diagnostics
Browse files Browse the repository at this point in the history
TEM diagnostics
  • Loading branch information
justin-richling authored Sep 22, 2023
2 parents da404e8 + 14fda5f commit 36c3558
Show file tree
Hide file tree
Showing 8 changed files with 1,123 additions and 68 deletions.
53 changes: 43 additions & 10 deletions config_amwg_default_plots.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ user: 'USER-NAME-NOT-SET'
diag_basic_info:

#History file string to match (eg. cam.h0 or ocn.pop.h.ecosys.nday1)
# Only affects timeseries as everything else uses timeseries
# Only affects timeseries as everything else uses timeseries
# Leave off trailing '.'
#Default: cam.h0
hist_str: cam.h0
hist_str: cam.h0

#Is this a model vs observations comparison?
#If "false" or missing, then a model-model comparison is assumed:
Expand Down Expand Up @@ -96,14 +96,10 @@ diag_basic_info:
#Location where diagnostic plots are stored:
cam_diag_plot_loc: /glade/scratch/${user}/ADF/plots

#Use default variable plot settings?
#If "true", then variable-specific plotting attributes as defined in
#ADF/lib/adf_variable_defaults.yaml will be used:
use_defaults: true

#Location of ADF variable plotting defaults YAML file
#if not using the one in ADF/lib:
# defaults_file: /some/path/to/defaults/file
#Location of ADF variable plotting defaults YAML file:
#If left blank or missing, ADF/lib/adf_variable_defaults.yaml will be used
#Uncomment and change path for custom variable defaults file
#defaults_file: /some/path/to/defaults/file.yaml

#Vertical pressure levels (in hPa) on which to plot 3-D variables
#when using horizontal (e.g. lat/lon) map projections.
Expand Down Expand Up @@ -281,6 +277,7 @@ diag_cvdp_info:
#These scripts must be located in "scripts/averaging":
time_averaging_scripts:
- create_climo_files
#- create_TEM_files #To generate TEM files, please un-comment

#Name of regridding scripts being used.
#These scripts must be located in "scripts/regridding":
Expand All @@ -300,6 +297,9 @@ plotting_scripts:
- zonal_mean
- polar_map
- cam_taylor_diagram
#- tem #To plot TEM, please un-comment
#- regional_map_multicase #To use this please un-comment and fill-out
#the "region_multicase" section below

#List of CAM variables that will be processesd:
#If CVDP is to be run PSL, TREFHT, TS and PRECT (or PRECC and PRECL) should be listed
Expand Down Expand Up @@ -347,4 +347,37 @@ diag_var_list:

#<Add more variables here.>

# Options for multi-case regional contour plots (./plotting/regional_map_multicase.py)
# region_multicase:
# region_spec: [slat, nlat, wlon, elon]
# region_time_option: <calendar | zeroanchor> # If calendar, will look for specified years. If zeroanchor will use a nyears starting from year_offset from the beginning of timeseries
# region_start_year:
# region_end_year:
# region_nyear:
# region_year_offset:
# region_month: <NULL means look for season>
# region_season: <NULL means use annual mean>
# region_variables: <list of variables to try to use; allows for a subset of the total diag variables>

# Options for TEM diagnostics (./averaging/create_TEM_files.py and ./plotting/temp.py)
#tem_info:
#Location where TEM files are stored:
#If path not specified or commented out, TEM calculation/plots will be skipped
# tem_loc: /glade/scratch/richling/adf-output/ADF-data/TEM/

#TEM history file number
#If missing or blank, ADF will default to h4
# hist_num: h4

#Overwrite TEM files, if found?
#If set to false, then TEM creation will be skipped if files are found:
# overwrite_tem_case: false

#For multi-case
#overwrite_tem_case:
# - false
# - true

# overwrite_tem_base: false

#END OF FILE
41 changes: 29 additions & 12 deletions config_cam_baseline_example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,10 @@ diag_basic_info:
#Location where diagnostic plots are stored:
cam_diag_plot_loc: /glade/scratch/${user}/ADF/plots

#Use default variable plot settings?
#If "true", then variable-specific plotting attributes as defined in
#ADF/lib/adf_variable_defaults.yaml will be used:
use_defaults: true

#Location of ADF variable plotting defaults YAML file
#if not using the one in ADF/lib:
# defaults_file: /some/path/to/defaults/file
#Location of ADF variable plotting defaults YAML file:
#If left blank or missing, ADF/lib/adf_variable_defaults.yaml will be used
#Uncomment and change path for custom variable defaults file
#defaults_file: /some/path/to/defaults/file.yaml

#Vertical pressure levels (in hPa) on which to plot 3-D variables
#when using horizontal (e.g. lat/lon) map projections.
Expand All @@ -131,7 +127,6 @@ diag_basic_info:
#If set to false, then if a plot is found it will be skipped:
redo_plot: false


#This second set of variables provides info for the CAM simulation(s) being diagnosed:
diag_cam_climo:

Expand Down Expand Up @@ -223,8 +218,8 @@ diag_cam_climo:
# - /glade/p/cesm/ADF/b1850.f19_g17.validation_mct.004

#cam_climo_loc:
# -/some/where/you/want/to/have/climo_files/ #MUST EDIT!
# -/the/same/or/some/other/climo/files/location
# - /some/where/you/want/to/have/climo_files/ #MUST EDIT!
# - /the/same/or/some/other/climo/files/location

#start_year:
# - 1990
Expand All @@ -247,7 +242,7 @@ diag_cam_climo:
# - false

#cam_ts_loc:
# - /some/where/you/want/to/have/time_series_files/
# - /some/where/you/want/to/have/time_series_files
# - /same/or/different/place/you/want/files

#----------------------
Expand Down Expand Up @@ -346,6 +341,7 @@ diag_cvdp_info:
#These scripts must be located in "scripts/averaging":
time_averaging_scripts:
- create_climo_files
#- create_TEM_files #To generate TEM files, please un-comment

#Name of regridding scripts being used.
#These scripts must be located in "scripts/regridding":
Expand All @@ -367,6 +363,7 @@ plotting_scripts:
- polar_map
- cam_taylor_diagram
- qbo
#- tem #To plot TEM, please un-comment
#- regional_map_multicase #To use this please un-comment and fill-out
#the "region_multicase" section below

Expand Down Expand Up @@ -404,5 +401,25 @@ diag_var_list:
# region_season: <NULL means use annual mean>
# region_variables: <list of variables to try to use; allows for a subset of the total diag variables>

# Options for TEM diagnostics (./averaging/create_TEM_files.py and ./plotting/temp.py)
#tem_info:
#Location where TEM files are stored:
#If path not specified or commented out, TEM calculation/plots will be skipped
# tem_loc: /glade/scratch/richling/adf-output/ADF-data/TEM/

#TEM history file number
#If missing or blank, ADF will default to h4
# hist_num: h4

#Overwrite TEM files, if found?
#If set to false, then TEM creation will be skipped if files are found:
# overwrite_tem_case: false

#For multi-case
#overwrite_tem_case:
# - false
# - true

# overwrite_tem_base: false

#END OF FILE
12 changes: 9 additions & 3 deletions lib/adf_diag.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import glob
import subprocess
import multiprocessing as mp
import copy

import importlib

Expand Down Expand Up @@ -181,6 +182,14 @@ def __init__(self, config_file, debug=False):
#Add plotting script names:
self.__plotting_scripts = self.read_config_var('plotting_scripts')

# Create property needed to return "plotting_scripts" variable to user:
@property
def plotting_scripts(self):
"""Return a copy of the '__plotting_scripts' string list to user if requested."""
#Note that a copy is needed in order to avoid having a script mistakenly
#modify this variable:
return copy.copy(self.__plotting_scripts)

#########
#Variable extraction functions
#########
Expand Down Expand Up @@ -387,9 +396,6 @@ def call_ncrcat(cmd):
start_year = start_years[case_idx]
end_year = end_years[case_idx]

print(type(start_year))
print(type(end_year))

#Create path object for the CAM history file(s) location:
starting_location = Path(cam_hist_locs[case_idx])

Expand Down
10 changes: 7 additions & 3 deletions lib/adf_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,6 @@ def __init__(self, config_file, debug=False):
#Case names:
case_names = self.get_cam_info('cam_case_name', required=True)

print(case_names)

#Grab test case nickname(s)
test_nicknames = self.get_cam_info('case_nickname')
if test_nicknames is None:
Expand Down Expand Up @@ -209,6 +207,11 @@ def __init__(self, config_file, debug=False):
#End if
#End if

#Grab baseline nickname
base_nickname = self.get_baseline_info('case_nickname')
if base_nickname == None:
base_nickname = data_name

#Update baseline case name:
data_name += f"_{syear_baseline}_{eyear_baseline}"
#End if (compare_obs)
Expand Down Expand Up @@ -451,7 +454,8 @@ def climo_yrs(self):
return {"syears":syears,"eyears":eyears,
"syear_baseline":self.__syear_baseline, "eyear_baseline":self.__eyear_baseline}

# Create property needed to return the climo start (syear) and end (eyear) years to user:

# Create property needed to return the case nicknames to user:
@property
def case_nicknames(self):
"""Return the test case and baseline nicknames to the user if requested."""
Expand Down
56 changes: 16 additions & 40 deletions lib/adf_obs.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,24 +66,21 @@ def __init__(self, config_file, debug=False):
#Determine local directory:
_adf_lib_dir = Path(__file__).parent

#Determine if variable defaults will be used:
self.__use_defaults = self.get_basic_info('use_defaults')

# Check whether user wants to use defaults:
#-----------------------------------------
if self.__use_defaults:
#Determine whether to use adf defaults or custom:
_defaults_file = self.get_basic_info('defaults_file')
if _defaults_file is None:
_defaults_file = _adf_lib_dir/'adf_variable_defaults.yaml'

#Open YAML file:
with open(_defaults_file, encoding='UTF-8') as dfil:
self.__variable_defaults = yaml.load(dfil, Loader=yaml.SafeLoader)
#Determine whether to use adf defaults or custom:
_defaults_file = self.get_basic_info('defaults_file')
if _defaults_file is None:
_defaults_file = _adf_lib_dir/'adf_variable_defaults.yaml'
else:
#Set variable_defaults to empty dictionary:
self.__variable_defaults = {}
print(f"\n\t Not using ADF default variables yaml file, instead using {_defaults_file}\n")
#End if

#Open YAML file:
with open(_defaults_file, encoding='UTF-8') as dfil:
self.__variable_defaults = yaml.load(dfil, Loader=yaml.SafeLoader)

_variable_defaults = self.__variable_defaults
#-----------------------------------------

#Check if land or ocean mask is requested, and if so then add OCNFRAC
Expand All @@ -96,11 +93,11 @@ def __init__(self, config_file, debug=False):
for var in self.diag_var_list:
#Check if any variable wants a land or ocean mask:
if var in self.__variable_defaults:
if 'mask' in self.__variable_defaults[var]:
#Variable needs a mask, so add "OCNFRAC" to
#the variable list:
self.add_diag_var('OCNFRAC')
break
if 'mask' in self.__variable_defaults[var]:
#Variable needs a mask, so add "OCNFRAC" to
#the variable list:
self.add_diag_var('OCNFRAC')
break
#End if
#End if
#End for
Expand All @@ -118,21 +115,6 @@ def __init__(self, config_file, debug=False):
#Extract the "obs_data_loc" default observational data location:
obs_data_loc = self.get_basic_info("obs_data_loc")

#Check that a variable defaults file exists (as it is currently needed to extract obs data):
if not self.__variable_defaults:
#Determine whether to use adf defaults or custom:
_defaults_file = self.get_basic_info('defaults_file')
if _defaults_file is None:
_defaults_file = _adf_lib_dir/'adf_variable_defaults.yaml'

#Open YAML file (but don't assign to object):
with open(_defaults_file, encoding='UTF-8') as nfil:
_variable_defaults = yaml.load(nfil, Loader=yaml.SafeLoader)
else:
#Set local variable to stored variable defaults dictionary:
_variable_defaults = self.__variable_defaults
#End if

#Loop over variable list:
for var in self.diag_var_list:

Expand Down Expand Up @@ -229,12 +211,6 @@ def variable_defaults(self):
#modify this variable, as it is mutable and thus passed by reference:
return copy.copy(self.__variable_defaults)

# Create property needed to return "use_defaults" variable to user:
@property
def use_defaults(self):
"""Return the '__use_defaults' logical to the user if requested."""
return self.__use_defaults

# Create property needed to return "var_obs_dict" dictionary to user:
@property
def var_obs_dict(self):
Expand Down
Loading

0 comments on commit 36c3558

Please sign in to comment.