Skip to content

Commit

Permalink
Merge pull request #336 from justin-richling/aod-4-panel
Browse files Browse the repository at this point in the history
Add AOD 4 panel plots of difference with MERRA and MODIS data
  • Loading branch information
justin-richling authored Nov 20, 2024
2 parents 16331ef + 698227f commit 02ebd3d
Show file tree
Hide file tree
Showing 8 changed files with 620 additions and 46 deletions.
6 changes: 6 additions & 0 deletions lib/adf_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@ def get_climo_file(self, case, variablename):


# Reference case (baseline/obs)
def load_reference_climo_da(self, case, variablename):
"""Return DataArray from reference (aka baseline) climo file"""
add_offset, scale_factor = self.get_value_converters(case, variablename)
fils = self.get_reference_climo_file(variablename)
return self.load_da(fils, variablename, add_offset=add_offset, scale_factor=scale_factor)

def get_reference_climo_file(self, var):
"""Return a list of files to be used as reference (aka baseline) for variable var."""
if self.adf.compare_obs:
Expand Down
20 changes: 11 additions & 9 deletions lib/adf_diag.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def call_ncrcat(cmd):
case_names = [self.get_baseline_info("cam_case_name", required=True)]
cam_ts_done = [self.get_baseline_info("cam_ts_done")]
cam_hist_locs = [self.get_baseline_info("cam_hist_loc")]
ts_dir = [self.get_baseline_info("cam_ts_loc", required=True)]
ts_dirs = [self.get_baseline_info("cam_ts_loc", required=True)]
overwrite_ts = [self.get_baseline_info("cam_overwrite_ts")]
start_years = [self.climo_yrs["syear_baseline"]]
end_years = [self.climo_yrs["eyear_baseline"]]
Expand All @@ -359,16 +359,12 @@ def call_ncrcat(cmd):
case_names = self.get_cam_info("cam_case_name", required=True)
cam_ts_done = self.get_cam_info("cam_ts_done")
cam_hist_locs = self.get_cam_info("cam_hist_loc")
ts_dir = self.get_cam_info("cam_ts_loc", required=True)
ts_dirs = self.get_cam_info("cam_ts_loc", required=True)
overwrite_ts = self.get_cam_info("cam_overwrite_ts")
start_years = self.climo_yrs["syears"]
end_years = self.climo_yrs["eyears"]
case_type_string="case"
hist_str_list = self.hist_string["test_hist_str"]

# Notify user that script has started:
print(f"\n Writing time series files to {ts_dir}")

# End if

# Read hist_str (component.hist_num) from the yaml file, or set to default
Expand Down Expand Up @@ -402,6 +398,9 @@ def call_ncrcat(cmd):
self.end_diag_fail(emsg)
# End if

# Extract time series file location
ts_dir = ts_dirs[case_idx]

# Check if history files actually exqist. If not then kill script:
hist_str_case = hist_str_list[case_idx]
for hist_str in hist_str_case:
Expand All @@ -415,6 +414,9 @@ def call_ncrcat(cmd):
self.end_diag_fail(emsg)
# End if

# Notify user that script has started:
print(f"\n Writing time series files to {ts_dir}")

# Create empty list:
files_list = []

Expand Down Expand Up @@ -497,7 +499,7 @@ def call_ncrcat(cmd):

# Check if time series directory exists, and if not, then create it:
# Use pathlib to create parent directories, if necessary.
Path(ts_dir[case_idx]).mkdir(parents=True, exist_ok=True)
Path(ts_dir).mkdir(parents=True, exist_ok=True)

# INPUT NAME TEMPLATE: $CASE.$scomp.[$type.][$string.]$date[$ending]
first_file_split = str(hist_files[0]).split(".")
Expand Down Expand Up @@ -631,7 +633,7 @@ def call_ncrcat(cmd):
# $cam_case_name.$hist_str.$variable.YYYYMM-YYYYMM.nc

ts_outfil_str = (
ts_dir[case_idx]
ts_dir
+ os.sep
+ ".".join([case_name, hist_str, var, time_string, "nc"])
)
Expand Down Expand Up @@ -748,7 +750,7 @@ def call_ncrcat(cmd):
if vars_to_derive:
self.derive_variables(
res=res, hist_str=hist_str, vars_to_derive=vars_to_derive,
constit_dict=constit_dict, ts_dir=ts_dir[case_idx]
constit_dict=constit_dict, ts_dir=ts_dir
)
# End with
# End for hist_str
Expand Down
1 change: 1 addition & 0 deletions lib/adf_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ def __init__(self, config_file, debug=False):
#Grab first possible hist string, just looking for years of run
base_hist_str = baseline_hist_str[0]
starting_location = Path(baseline_hist_locs)
print(f"Checking history files in '{starting_location}'")
file_list = sorted(starting_location.glob("*" + base_hist_str + ".*.nc"))

#Check if the history file location exists
Expand Down
23 changes: 23 additions & 0 deletions lib/adf_variable_defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2433,4 +2433,27 @@ budget_tables:
AEROSOLS: ['SOA', 'SALT', 'DUST', 'POM', 'BC', 'SO4']

#-----------



# Plot Specific formatting
##########################

# AOD 4-Panel plots vs MERRA and MODIS
#-------------------------------------
aod_diags:
plot_params:
range_min: -0.4
range_max: 0.4
nlevel: 17
colormap: "bwr"

plot_params_relerr:
range_max: 100
range_min: -100
nlevel: 21
colormap: "PuOr_r"

#-----------

#End of File
48 changes: 24 additions & 24 deletions lib/adf_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,6 @@ def __init__(self, config_file, debug=False):
'assets_dir': assets_dir,
'table_pages_dir': table_pages_dir,
'css_files_dir': css_files_dir}



#End for
#--------------------------------

Expand All @@ -186,8 +183,6 @@ def __init__(self, config_file, debug=False):
'css_files_dir': css_files_dir}
#End if



#########

# Create property needed to return "create_html" logical to user:
Expand Down Expand Up @@ -352,10 +347,13 @@ def create_website(self):
self.end_diag_fail(emsg)
#End except

#Make a jinja function that mimics python list object. This will allow for
# the use of 'list' in the html rendering.
#Make jinja functions that mimics python functions.
# - This will allow for the use of 'list' in the html rendering.
def jinja_list(seas_list):
return list(seas_list)
# - This will allow for the use of 'enumerate' in the html rendering.
def jinja_enumerate(arg):
return enumerate(arg)

#Notify user that script has started:
print("\n Generating Diagnostics webpages...")
Expand Down Expand Up @@ -619,6 +617,7 @@ def jinja_list(seas_list):

#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, but ignore certain keys
Expand All @@ -629,6 +628,7 @@ def jinja_list(seas_list):
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 @@ -648,18 +648,19 @@ def jinja_list(seas_list):
#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]}
"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]}

tmpl = jinenv.get_template('template.html') #Set template
rndr = tmpl.render(rend_kwarg_dict) #The template rendered

Expand All @@ -674,10 +675,9 @@ def jinja_list(seas_list):
#Construct individual plot type mean_diag html files
mean_tmpl = jinenv.get_template('template_mean_diag.html')

#Remove keys from main dictionary for this html page
templ_rend_kwarg_dict = {k: rend_kwarg_dict[k] for k in rend_kwarg_dict.keys() - {'imgs', 'var_title', 'season_title'}}
templ_rend_kwarg_dict["list"] = jinja_list
mean_rndr = mean_tmpl.render(templ_rend_kwarg_dict)
rend_kwarg_dict["enumerate"] = jinja_enumerate
rend_kwarg_dict["list"] = jinja_list
mean_rndr = mean_tmpl.render(rend_kwarg_dict)

#Write mean diagnostic plots HTML file:
with open(mean_ptype_file,'w', encoding='utf-8') as ofil:
Expand Down Expand Up @@ -780,4 +780,4 @@ def jinja_list(seas_list):
print(" ...Webpages have been generated successfully.")
#++++++++++++++++++++
#End Class definition
#++++++++++++++++++++
#++++++++++++++++++++
10 changes: 5 additions & 5 deletions lib/website_templates/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ <h2 style="display:inline; color:black;"> Baseline Case: </h2><h2 style="display
{% if non_seasons[category][var_name] == False %}
{% for season in seasons %}
{% if season in ptype_seas.keys() %}
<div class="grid-item">
<a href="../html_img/{{ ptype_seas[season] }}">{{ season }}</a>
</div><!--grid-item-->
<div class="grid-item">
<a href="../html_img/{{ ptype_seas[season] }}">{{ season }}</a>
</div><!--grid-item-->
{% else %}
<div class="grid-item-blocked">
<a-blocked>{{ season }}</a-blocked>
Expand All @@ -70,7 +70,7 @@ <h2 style="display:inline; color:black;"> Baseline Case: </h2><h2 style="display
<div class="grid-item">
<a href="../html_img/{{ ptype_seas[season] }}">{{ season }}</a>
</div><!--grid-item-->
{% endfor %}<!-- ptype_seas.keys() -->
{% endfor %}<!-- ptype_seas.keys() -->
{% endif %}<!-- non_season -->
{% endif %}<!-- var_name == var_title -->
{% endfor %}<!-- var_seas.items() -->
Expand All @@ -87,4 +87,4 @@ <h2 style="display:inline; color:black;"> Baseline Case: </h2><h2 style="display
</div> <!-- end main div -->

</body>
</html>
</html>
14 changes: 7 additions & 7 deletions lib/website_templates/template_mean_diag.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ <h1>{{ plottype_title }} Plots</h1>
<h3 class="block">{{ category }}</h3>
<div class="grid-container" style="column-gap: 5px; row-gap: 5px; padding:2px">
{% for var_name, ptype_seas in var_seas.items() %}
{% if non_seasons[category][var_name] == False %}
{% for season in ptype_seas.keys() %}
{% if season=="ANN"%}
<div class="grid-item-diag">
<a href="../html_img/plot_page_{{ var_name }}_ANN_{{ plottype_title }}_Mean.html"> {{var_name}} </a><br>
</div><!--grid-item2-->
{% endif %}
{% if non_seasons[category][var_name] == False %}<!-- Check if these have traditional seasons, ANN, DJF, etc. -->
{% 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>
</div><!--grid-item2-->
{% endif %}
{% endfor %}<!-- ptype_seas.keys() -->

{% else %}
Expand Down
Loading

0 comments on commit 02ebd3d

Please sign in to comment.