Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
66bde8c
Clean up defaults and expand TEM variables
justin-richling Dec 19, 2024
db53f40
Update adf_variable_defaults.yaml
justin-richling Dec 19, 2024
a4c5757
Add extension arg to plot page name
justin-richling Dec 19, 2024
521479a
Make use of new extension for plot page
justin-richling Dec 19, 2024
518d702
Update plotting_functions.py
justin-richling Dec 19, 2024
ea2cb23
Include Zonal mean potential temp
justin-richling Dec 19, 2024
6ba8b0e
Improve TEM plots
justin-richling Dec 19, 2024
82ea271
Keep PMID from plotting
justin-richling Dec 19, 2024
85f15bf
Fix potential temp to temp for title
justin-richling Dec 19, 2024
cb27e05
Merge branch 'main' into tem-updates
justin-richling Feb 7, 2025
820047a
Update tem.py
justin-richling Feb 7, 2025
636a006
Update tem.py
justin-richling Apr 17, 2025
6f757bd
undo print statements
justin-richling Apr 17, 2025
32c64fe
Add check for time bounds name
justin-richling Apr 18, 2025
6f81409
Update create_TEM_files.py
justin-richling Apr 18, 2025
4e32c0a
Update adf_variable_defaults.yaml
justin-richling Apr 18, 2025
646b010
Update create_TEM_files.py
justin-richling Apr 18, 2025
d192b36
Update tem.py
justin-richling Apr 18, 2025
1f17fb6
update TEM variables list
justin-richling Apr 18, 2025
c247e4b
Update tem.py
justin-richling Apr 18, 2025
0f54bda
Update tem.py
justin-richling Apr 18, 2025
b006a1f
Update tem.py
justin-richling Apr 18, 2025
126d3d7
Update tem.py
justin-richling Apr 18, 2025
0d3860c
Merge branch 'main' into tem-updates
justin-richling Mar 16, 2026
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
379 changes: 117 additions & 262 deletions lib/adf_variable_defaults.yaml

Large diffs are not rendered by default.

37 changes: 19 additions & 18 deletions lib/adf_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class _WebData:
needed by the website generator.
"""

def __init__(self, web_data, web_name, case_name,
def __init__(self, web_data, web_name, case_name,ext="Mean",
category = None,
season = None,
non_season = False,
Expand All @@ -74,6 +74,7 @@ def __init__(self, web_data, web_name, case_name,
self.season = season
self.non_season = non_season
self.plot_type = plot_type
self.ext = ext
self.data_frame = data_frame
self.html_file = html_file
self.asset_path = asset_path
Expand Down Expand Up @@ -299,7 +300,7 @@ def _write_run_info_to_log(self, config_file, active_env):

self.debug_log(log_msg)

def add_website_data(self, web_data, web_name, case_name,
def add_website_data(self, web_data, web_name, case_name,ext="Mean",
category = None,
season = None,
non_season = False,
Expand Down Expand Up @@ -413,6 +414,7 @@ def add_website_data(self, web_data, web_name, case_name,
season = season,
non_season = non_season,
plot_type = plot_type,
ext = ext,
data_frame = data_frame,
html_file = html_file,
asset_path = asset_path,
Expand Down Expand Up @@ -659,7 +661,6 @@ def jinja_enumerate(arg):
#Initialize Ordered Dictionary for season:
mean_html_info[ptype][category][var][season] = web_data.html_file.name


#Initialize Ordered Dictionary for non season kwarg:
if ptype not in non_seasons:
non_seasons[ptype] = OrderedDict()
Expand Down Expand Up @@ -733,7 +734,6 @@ def jinja_enumerate(arg):

#Check if the mean plot type page exists for this case (or for multi-case):
mean_table_file = table_pages_dir / "mean_tables.html"

#Construct mean_table.html
mean_table_tmpl = jinenv.get_template('template_mean_tables.html')
#Reuse the rend_kwarg_dict
Expand All @@ -742,7 +742,6 @@ def jinja_enumerate(arg):
with open(mean_table_file, 'w', encoding='utf-8') as ofil:
ofil.write(mean_table_rndr)
#End with

#End if (tables)

else: #Plot image
Expand All @@ -761,20 +760,21 @@ def jinja_enumerate(arg):
plot_types = plot_type_html
#End if

rend_kwarg_dict = {"title": main_title,
"var_title": web_data.name,
"season_title": web_data.season,
"case_name": web_data.case,
"case_yrs": case_yrs,
"base_name": data_name,
"baseline_yrs": baseline_yrs,
"plottype_title": web_data.plot_type,
"imgs": img_data,
"mydata": mean_html_info[web_data.plot_type],
"plot_types": plot_types,
"seasons": seasons,
"non_seasons": non_seasons[web_data.plot_type]}

rend_kwarg_dict = {"title": main_title,
"var_title": web_data.name,
"ext": web_data.ext,
"season_title": web_data.season,
"case_name": web_data.case,
"case_yrs": case_yrs,
"base_name": data_name,
"baseline_yrs": baseline_yrs,
"plottype_title": web_data.plot_type,
"imgs": img_data,
"mydata": mean_html_info[web_data.plot_type],
"plot_types": plot_types,
"seasons": seasons,
"non_seasons": non_seasons[web_data.plot_type]}
tmpl = jinenv.get_template('template.html') #Set template
rndr = tmpl.render(rend_kwarg_dict) #The template rendered

Expand Down Expand Up @@ -831,6 +831,7 @@ def jinja_enumerate(arg):
if web_data.case == 'multi-case':
plot_types = multi_plot_type_html
else:
case1 = web_data.case
plot_types = plot_type_html
plot_types = plot_type_html
#End if
Expand Down
5 changes: 2 additions & 3 deletions lib/plotting_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import numpy as np
import xarray as xr
import matplotlib as mpl
import matplotlib.cm as cm
import cartopy.crs as ccrs
#nice formatting for tick labels
from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter
Expand Down Expand Up @@ -70,7 +71,6 @@
"SON": [9, 10, 11]
}


#################
#HELPER FUNCTIONS
#################
Expand Down Expand Up @@ -829,7 +829,6 @@ def plot_map_and_save(wks, case_nickname, base_nickname,
borderpad=0,
)
fig.colorbar(img[1], cax=cb_mean_ax, **cp_info['colorbar_opt'])


cb_pct_ax = inset_axes(ax3,
width="5%", # width = 5% of parent_bbox width
Expand Down Expand Up @@ -1451,7 +1450,7 @@ def square_contour_difference(fld1, fld2, **kwargs):
else:
dnorm = mpl.colors.TwoSlopeNorm(vmin=dmin, vcenter=0, vmax=dmax)
cmap = mpl.cm.RdBu_r

img3 = ax3.contourf(xx, yy, diff.transpose(), cmap=cmap, norm=dnorm)
if (coord1 == 'month') and (fld1.shape[0] ==12):
ax3.set_xticks(np.arange(1,13))
Expand Down
4 changes: 2 additions & 2 deletions lib/website_templates/template_mean_diag.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ <h3 class="block">{{ category }}</h3>
{% for i,season in enumerate(ptype_seas.keys()) %}
{% if i==0 %}<!-- Grab first available season to make as default -->
<div class="grid-item-diag">
<a href="../html_img/plot_page_{{ var_name }}_{{ season }}_{{ plottype_title }}_Mean.html"> {{var_name}} </a><br>
<a href="../html_img/plot_page_{{ var_name }}_{{ season }}_{{ plottype_title }}_{{ ext }}.html"> {{var_name}} </a><br>
</div><!--grid-item2-->
{% endif %}
{% endfor %}<!-- ptype_seas.keys() -->
Expand All @@ -62,7 +62,7 @@ <h3 class="block">{{ category }}</h3>
{% for season in ptype_seas.keys() %}
{% if season == list(ptype_seas.keys())[0] %}
<div class="grid-item-diag">
<a href="../html_img/plot_page_{{ var_name }}_{{ season }}_{{ plottype_title }}_Mean.html"> {{var_name}} </a><br>
<a href="../html_img/plot_page_{{ var_name }}_{{ season }}_{{ plottype_title }}_{{ ext }}.html"> {{var_name}} </a><br>
</div><!--grid-item2-->
{% endif %}
{% endfor %}<!-- ptype_seas.keys() -->
Expand Down
53 changes: 33 additions & 20 deletions scripts/averaging/create_TEM_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ def create_TEM_files(adf):
res = adf.variable_defaults # will be dict of variable-specific plot preferences

if "qbo" in adf.plotting_scripts:
var_list = ['uzm','epfy','epfz','vtem','wtem',
'psitem','utendepfd','utendvtem','utendwtem']
var_list = ["UZM","THZM","EPFY","EPFZ","VTEM","WTEM",
"PSITEM","UTENDEPFD","UTENDVTEM","UTENDWTEM"]
else:
var_list = ['uzm','epfy','epfz','vtem','wtem','psitem','utendepfd']
var_list = ["UZM","THZM","EPFY","EPFZ","VTEM","WTEM","PSITEM","UTENDEPFD"]

tem_locs = []

Expand All @@ -62,9 +62,9 @@ def create_TEM_files(adf):
#End for

#Set default to h4
hist_nums = adf.get_cam_info("tem_hist_str")
hist_nums = adf.get_cam_info("tem_hist_str")[0]
if hist_nums is None:
hist_nums = ["h4"]*len(case_names)
hist_nums = ["h4a"]*len(case_names)

#Get test case(s) tem over-write boolean and force to list if not by default
overwrite_tem_cases = adf.get_cam_info("overwrite_tem")
Expand Down Expand Up @@ -154,7 +154,7 @@ def create_TEM_files(adf):
#Set default to h4
hist_num = adf.get_baseline_info("tem_hist_str")
if hist_num is None:
hist_num = "h4"
hist_num = "h4a"

#Extract baseline years (which may be empty strings if using Obs):
syear_baseline = adf.climo_yrs["syear_baseline"]
Expand Down Expand Up @@ -200,8 +200,9 @@ def create_TEM_files(adf):
#End if

#Check if history files actually exist. If not then kill script:
hist_str = f"*{hist_nums[case_idx]}"
if not list(starting_location.glob(hist_str+'.*.nc')):

hist_str = f"{hist_nums[case_idx]}"
if not list(starting_location.glob("*"+hist_str+'.*.nc')):
emsg = f"No CAM history {hist_str} files found in '{starting_location}'."
emsg += " Script is ending here."
adf.end_diag_fail(emsg)
Expand Down Expand Up @@ -237,7 +238,7 @@ def create_TEM_files(adf):

#Grab all leading zeros for climo year just in case
yr = f"{str(yr).zfill(4)}"
hist_files.append(glob(f"{starting_location}/{hist_str}.{yr}*.nc"))
hist_files.append(glob(f"{starting_location}/*{hist_str}.{yr}*.nc"))

#Flatten list of lists to 1d list
hist_files = sorted(list(chain.from_iterable(hist_files)))
Expand Down Expand Up @@ -423,6 +424,9 @@ def calc_tem(ds):
vzm.attrs['long_name'] = 'Zonal-Mean meridional wind'
vzm.attrs['units'] = 'm/s'

thzm.attrs['long_name'] = 'Zonal-Mean potential temperature'
thzm.attrs['units'] = 'K'

epfy.attrs['long_name'] = 'northward component of E-P flux'
epfy.attrs['units'] = 'm3/s2'

Expand Down Expand Up @@ -455,19 +459,28 @@ def calc_tem(ds):
utendvtem.values = np.float32(utendvtem.values)
utendwtem.values = np.float32(utendwtem.values)

#Average time dimension over time bounds, if bounds exist:
if 'time_bnds' in ds:
time_bounds_name = 'time_bnds'
elif 'time_bounds' in ds:
time_bounds_name = 'time_bounds'

dstem = xr.Dataset(data_vars=dict(date = ds.date,
datesec = ds.datesec,
time_bnds = ds.time_bnds,
uzm = uzm,
vzm = vzm,
epfy = epfy,
epfz = epfz,
vtem = vtem,
wtem = wtem,
psitem = psitem,
utendepfd = utendepfd,
utendvtem = utendvtem,
utendwtem = utendwtem
time_bnds = time_bounds_name,
hybm=ds.hybm,
hyam=ds.hyam,
UZM = uzm,
VZM = vzm,
THZM = thzm,
EPFY = epfy,
EPFZ = epfz,
VTEM = vtem,
WTEM = wtem,
PSITEM = psitem,
UTENDEPFD = utendepfd,
UTENDVTEM = utendvtem,
UTENDWTEM = utendwtem
))

return dstem
5 changes: 5 additions & 0 deletions scripts/plotting/global_latlon_vect_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ def global_latlon_vect_map(adfobj):
#
# Use ADF api to get all necessary information
#
#Variable list
var_list = adfobj.diag_var_list
#Remove unneccasry vairbale from plotting
if "PMID" in var_list:
var_list.remove("PMID")

model_rgrid_loc = adfobj.get_basic_info("cam_regrid_loc", required=True)

#Special ADF variable which contains the output path for
Expand Down
5 changes: 5 additions & 0 deletions scripts/plotting/meridional_mean.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ def meridional_mean(adfobj):

#Extract needed quantities from ADF object:
#-----------------------------------------
#Variable list
var_list = adfobj.diag_var_list
#Remove unneccasry vairbale from plotting
if "PMID" in var_list:
var_list.remove("PMID")

model_rgrid_loc = adfobj.get_basic_info("cam_regrid_loc", required=True)

#Special ADF variable which contains the output paths for
Expand Down
Loading
Loading