Skip to content

Commit

Permalink
Merge branch 'NCAR:main' into restom_as_timeseries
Browse files Browse the repository at this point in the history
  • Loading branch information
brianpm authored Dec 21, 2023
2 parents fb6848d + f45ffbd commit c5b8456
Show file tree
Hide file tree
Showing 7 changed files with 805 additions and 220 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ To run an example of the ADF diagnostics, simply download this repo, setup your

This should generate a collection of time series files, climatology (climo) files, re-gridded climo files, and example ADF diagnostic figures, all in their respective directories.

### ADF Tutorial/Demo

Jupyter Book detailing the ADF including ADF basics, guided examples, quick runs, and references
- https://justin-richling.github.io/ADF-Tutorial/README.html

## Troubleshooting

Any problems or issues with this software should be posted on the ADF discussions page located online [here](https://github.com/NCAR/ADF/discussions).
Expand Down
3 changes: 2 additions & 1 deletion config_amwg_default_plots.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,8 @@ plotting_scripts:
- zonal_mean
- polar_map
- cam_taylor_diagram
#- tem #To plot TEM, please un-comment
#- tem #To plot TEM, please un-comment fill-out
#the "tem_info" section below
#- regional_map_multicase #To use this please un-comment and fill-out
#the "region_multicase" section below

Expand Down
3 changes: 2 additions & 1 deletion config_cam_baseline_example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,8 @@ plotting_scripts:
- polar_map
- cam_taylor_diagram
- qbo
#- tem #To plot TEM, please un-comment
#- tem #To plot TEM, please un-comment fill-out
#the "tem_info" section below
#- regional_map_multicase #To use this please un-comment and fill-out
#the "region_multicase" section below

Expand Down
54 changes: 49 additions & 5 deletions lib/adf_diag.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,9 @@ def call_ncrcat(cmd):
hist_str = 'cam.h0'
#End if

# get info about variable defaults
res = self.variable_defaults

#Loop over cases:
for case_idx, case_name in enumerate(case_names):

Expand Down Expand Up @@ -515,12 +518,24 @@ def call_ncrcat(cmd):

#Loop over CAM history variables:
list_of_commands = []
for var in self.diag_var_list:
vars_to_derive = []
#create copy of var list that can be modified for derivable variables
diag_var_list = self.diag_var_list
for var in diag_var_list:
if var not in hist_file_var_list:
msg = f"WARNING: {var} is not in the file {hist_files[0]}."
msg += " No time series will be generated."
print(msg)
continue
vres = res.get(var, {})
if "derivable_from" in vres:
constit_list = vres['derivable_from']
for constit in constit_list:
if constit not in diag_var_list:
diag_var_list.append(constit)
vars_to_derive.append(var)
continue
else:
msg = f"WARNING: {var} is not in the file {hist_files[0]}."
msg += " No time series will be generated."
print(msg)
continue

#Check if variable has a "lev" dimension according to first file:
has_lev = bool('lev' in hist_file_ds[var].dims)
Expand Down Expand Up @@ -597,6 +612,9 @@ def call_ncrcat(cmd):
#Now run the "ncrcat" subprocesses in parallel:
with mp.Pool(processes=self.num_procs) as mpool:
_ = mpool.map(call_ncrcat, list_of_commands)

if vars_to_derive:
self.derive_variables(vars_to_derive=vars_to_derive,ts_dir=ts_dir[case_idx])
#End with

#Make a time series file for RESTOM
Expand Down Expand Up @@ -945,4 +963,30 @@ def setup_run_cvdp(self):
print('For CVDP information visit: https://www.cesm.ucar.edu/working_groups/CVC/cvdp/')
print(' ')

#########

def derive_variables(self,vars_to_derive=None,ts_dir=None):

"""
Derive variables acccording to steps given here. Since derivations will depend on the
variable, each variable to derive will need its own set of steps below.
"""

for var in vars_to_derive:
if var == "PRECT":
# PRECT can be found by simply adding PRECL and PRECC
# grab file names for the PRECL and PRECC files from the case ts directory
if glob.glob(os.path.join(ts_dir,"*PRECC*")) and glob.glob(os.path.join(ts_dir,"*PRECL*")):
constit_files=sorted(glob.glob(os.path.join(ts_dir,"*PREC*")))
else:
ermsg = "PRECC and PRECL were not both present; PRECT cannot be calculated."
ermsg += " Please remove PRECT from diag_var_list or find the relevant CAM files."
raise FileNotFoundError(ermsg)
# create new file name for PRECT
prect_file = constit_files[0].replace('PRECC','PRECT')
# append PRECC to the file containing PRECL
os.system(f"ncks -A -v PRECC {constit_files[0]} {constit_files[1]}")
# create new file with the sum of PRECC and PRECL
os.system(f"ncap2 -s 'PRECT=(PRECC+PRECL)' {constit_files[1]} {prect_file}")

###############
7 changes: 7 additions & 0 deletions lib/adf_variable_defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@
# category -> The website category the variable will be placed under.
#
#
# DERIVING:
#
# derivable_from -> If not present in the available output files, the variable can be derived from
# other variables that are present (e.g. PRECT can be derived from PRECC and PRECL),
# which are specified in this list
#
# Final Note: Please do not modify this file unless you plan to push your changes back to the ADF repo.
# If you would like to modify this file for your personal ADF runs then it is recommended
# to make a copy of this file, make modifications in that copy, and then point the ADF to
Expand Down Expand Up @@ -445,6 +451,7 @@ PRECT:
obs_name: "ERAI"
obs_var_name: "PRECT"
category: "Hydrologic cycle"
derivable_from: ['PRECL','PRECC']

QFLX:
category: "Hydrologic cycle"
Expand Down
Loading

0 comments on commit c5b8456

Please sign in to comment.