Skip to content

Commit

Permalink
add viwer
Browse files Browse the repository at this point in the history
  • Loading branch information
chengzhuzhang committed Nov 21, 2023
1 parent 58d0b5a commit f40d46a
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 10 deletions.
18 changes: 11 additions & 7 deletions auxiliary_tools/tropical_subseasonal_diags/tropical_subseasonal_driver.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from matplotlib.colors import ListedColormap, BoundaryNorm

from tropical_subseasonal_plot import plot
from tropical_subseasonal_viewer import create_viewer
from zwf import zwf_functions as wf

logger = custom_logger(__name__)
Expand Down Expand Up @@ -167,12 +168,14 @@ def calculate_spectrum(path, variable):
)

for variable in parameter.variables:
#test = calculate_spectrum(parameter.test_data_path, variable)
#test.to_netcdf("data/full_spec_test.nc")
#ref = calculate_spectrum(parameter.ref_data_path, variable)
#ref.to_netcdf("data/full_spec_ref.nc")
test = xr.open_dataset("/Users/zhang40/Documents/repos/e3sm_diags/auxiliary_tools/tropical_subseasonal_diags/data/full_spec_ref.nc").load()
ref = xr.open_dataset("/Users/zhang40/Documents/repos/e3sm_diags/auxiliary_tools/tropical_subseasonal_diags/data/full_spec_ref.nc").load()
test = calculate_spectrum(parameter.test_data_path, variable)
test.to_netcdf("data/full_spec_test.nc")
ref = calculate_spectrum(parameter.ref_data_path, variable)
ref.to_netcdf("data/full_spec_ref.nc")
# Below uses intermediate saved files for development
#test = xr.open_dataset("/Users/zhang40/Documents/repos/e3sm_diags/auxiliary_tools/tropical_subseasonal_diags/data/full_spec_ref.nc").load()
#ref = xr.open_dataset("/Users/zhang40/Documents/repos/e3sm_diags/auxiliary_tools/tropical_subseasonal_diags/data/full_spec_ref.nc").load()
parameter.var_id = variable

for diff_name in ["raw_sym", "raw_asy", "norm_sym", "norm_asy", "background"]:
diff = test[f"spec_{diff_name}"]-ref[f"spec_{diff_name}"]
Expand All @@ -182,5 +185,6 @@ def calculate_spectrum(path, variable):
plot(parameter, test[f"spec_{diff_name}"], ref[f"spec_{diff_name}"], diff)



display_name, url = create_viewer('.', parameter)
print("Viewer Created: ", url)

6 changes: 3 additions & 3 deletions auxiliary_tools/tropical_subseasonal_diags/tropical_subseasonal_plot.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def _save_plot(fig: plt.figure, parameter: CoreParameter):
# #get_output_dir(parameter.current_set, parameter),
# parameter.output_file + "." + f,
#)
fnm = f'{parameter.spec_type}.png'
fnm = f'{parameter.var_id}_{parameter.spec_type}_15N-15N.png'
plt.savefig(fnm)
logger.info(f"Plot saved in: {fnm}")

Expand Down Expand Up @@ -165,8 +165,8 @@ def _wave_frequency_plot(
do_zoom: Boolean
"""
#TODO link var_id
#varName = parameter.var_id
varName = 'PRECT'
varName = parameter.var_id
#varName = 'PRECT'
PlotDesc = {}
PlotDesc['spec_raw_sym'] = {"long_name_desc": f"{varName}: log-base10 of lightly smoothed spectral power of component symmetric about equator", "ref_fig_num": "Figure 1"} # Figure number from Wheeler and Kiladis (1999)
PlotDesc['spec_raw_asy'] = {"long_name_desc": f"{varName}: log-base10 of lightly smoothed spectral power of component antisymmetric about equator", "ref_fig_num": "Figure 1"}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import os
from typing import Dict, List

from cdp.cdp_viewer import OutputViewer

from e3sm_diags.logger import custom_logger


logger = custom_logger(__name__)


def create_viewer(root_dir, parameters):
"""
Given a set of parameters for the enso_diags set,
create a single webpage.
Return the title and url for this page.
"""
viewer = OutputViewer(path=root_dir)

# The name that's displayed on the viewer.
display_name = "Tropical Subseasonal Variability Diagnostics"
set_name = "tropical_subseasonal_diags"
# The title of the colums on the webpage.
# Appears in the second and third columns of the bolded rows.
cols = ["Description", "Plot"]
viewer.add_page(display_name, short_name=set_name, columns=cols)
for plot_type in ["Wavenumber Frequency", "Lag correlation"]:
# Appears in the first column of the bolded rows.
viewer.add_group(plot_type.capitalize())

for var in parameters.variables:
# Appears in the first column of the non-bolded rows.
# This should use param.case_id to match the output_dir determined by
# get_output_dir in e3sm_diags/plot/cartopy/enso_diags_plot.py.
# Otherwise, the plot image and the plot HTML file will have URLs
# differing in the final directory name.
for spec_type in ["norm_sym", "norm_asy", "raw_sym", "raw_asy", "background"]:
viewer.add_row(f'{var} {spec_type} ref_name')
# Adding the description for this var to the current row.
# This was obtained and stored in the driver for this plotset.
# Appears in the second column of the non-bolded rows.
#viewer.add_col(param.viewer_descr[var])
viewer.add_col(f'Long description for var')
# Link to an html version of the plot png file.
# Appears in the third column of the non-bolded rows.
image_relative_path = f'{var}_{spec_type}_15N-15N.png'
viewer.add_col(
image_relative_path,
is_file=True,
title="Plot",
#other_files=formatted_files,
#meta=create_metadata(param),
)

url = viewer.generate_page()

return display_name, url

0 comments on commit f40d46a

Please sign in to comment.