Skip to content

Commit 02e11c9

Browse files
authored
Merge pull request #9 from E3SM-Project/issue-601-viewers
Add Viewer support
2 parents 72b4343 + c747ba4 commit 02e11c9

File tree

15 files changed

+1690
-808
lines changed

15 files changed

+1690
-808
lines changed

MANIFEST.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
recursive-include zppy_interfaces *.csv
2+
recursive-include zppy_interfaces *.html

conda/dev.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@ dependencies:
1111
- setuptools >= 60
1212
# Base
1313
# =================
14+
- beautifulsoup4
15+
- lxml
1416
- matplotlib-base >=3.8.2,<3.10
1517
- mpas_tools >=0.21.0
1618
- netcdf4
1719
- numpy >=2.0,<3.0
20+
- output_viewer=1.3.3
1821
- xarray >=2023.02.0
1922
- xcdat >=0.7.3,<1.0
2023
# Testing

tests/integration/global_time_series/cases_global_time_series.py

100644100755
Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,38 @@
88
WEB_DIR = "/lcrc/group/e3sm/public_html/diagnostic_output/ac.forsyth2/zi-test-webdir/"
99
RESULTS_DIR_PREFIX = "global_time_series_1985-1995_results"
1010

11+
plots_lnd_metric_average = "FSH,RH2M,LAISHA,LAISUN,QINTR,QOVER,QRUNOFF,QSOIL,QVEGE,QVEGT,SOILWATER_10CM,TSA,H2OSNO,"
12+
plots_lnd_metric_total = (
13+
"TOTLITC,CWDC,SOIL1C,SOIL2C,SOIL3C,SOIL4C,WOOD_HARVESTC,TOTVEGC,NBP,GPP,AR,HR"
14+
)
15+
plots_lnd_all = plots_lnd_metric_average + plots_lnd_metric_total
16+
17+
parameters_viewers: Parameters = Parameters(
18+
{
19+
"use_ocn": "False",
20+
"input": "/lcrc/group/e3sm2/ac.wlin/E3SMv3/v3.LR.historical_0051",
21+
"input_subdir": "archive/ocn/hist",
22+
"moc_file": "None",
23+
"case_dir": CASE_DIR,
24+
"experiment_name": "v3.LR.historical_0051",
25+
"figstr": "v3.LR.historical_0051",
26+
"color": "Blue",
27+
"ts_num_years": "5",
28+
"plots_original": "None",
29+
"plots_atm": "TREFHT",
30+
"plots_ice": "None",
31+
"plots_lnd": plots_lnd_all,
32+
"plots_ocn": "None",
33+
"nrows": "1",
34+
"ncols": "1",
35+
"results_dir": f"{RESULTS_DIR_PREFIX}_viewers",
36+
"regions": "glb,n,s",
37+
"make_viewer": "True",
38+
"start_yr": "1985",
39+
"end_yr": "1995",
40+
}
41+
)
42+
1143
parameters_custom: Parameters = Parameters(
1244
{
1345
"use_ocn": "False",
@@ -20,14 +52,15 @@
2052
"color": "Blue",
2153
"ts_num_years": "5",
2254
"plots_original": "None",
23-
"plots_atm": "TREFHT,AODDUST",
55+
"plots_atm": "TREFHT",
2456
"plots_ice": "None",
25-
"plots_lnd": "FSH,RH2M,LAISHA,LAISUN,QINTR,QOVER,QRUNOFF,QSOIL,QVEGE,QVEGT,SOILWATER_10CM,TSA,H2OSNO,TOTLITC,CWDC,SOIL1C,SOIL2C,SOIL3C,SOIL4C,WOOD_HARVESTC,TOTVEGC,NBP,GPP,AR,HR",
57+
"plots_lnd": plots_lnd_all,
2658
"plots_ocn": "None",
2759
"nrows": "4",
2860
"ncols": "2",
2961
"results_dir": f"{RESULTS_DIR_PREFIX}_custom",
3062
"regions": "glb,n,s",
63+
"make_viewer": "False",
3164
"start_yr": "1985",
3265
"end_yr": "1995",
3366
}
@@ -54,6 +87,7 @@
5487
"ncols": "2",
5588
"results_dir": f"{RESULTS_DIR_PREFIX}_original_8_no_ocn",
5689
"regions": "glb,n,s",
90+
"make_viewer": "False",
5791
"start_yr": "1985",
5892
"end_yr": "1995",
5993
}
@@ -79,6 +113,7 @@
79113
"ncols": "2",
80114
"results_dir": f"{RESULTS_DIR_PREFIX}_original_8",
81115
"regions": "glb,n,s",
116+
"make_viewer": "False",
82117
"start_yr": "1985",
83118
"end_yr": "1995",
84119
}
@@ -98,12 +133,13 @@
98133
"plots_original": "net_toa_flux_restom,global_surface_air_temperature,toa_radiation,net_atm_energy_imbalance,change_ohc,max_moc,change_sea_level,net_atm_water_imbalance",
99134
"plots_atm": "None",
100135
"plots_ice": "None",
101-
"plots_lnd": "FSH,RH2M,LAISHA,LAISUN,QINTR,QOVER,QRUNOFF,QSOIL,QVEGE,QVEGT,SOILWATER_10CM,TSA,H2OSNO,TOTLITC,CWDC,SOIL1C,SOIL2C,SOIL3C,SOIL4C,WOOD_HARVESTC,TOTVEGC,NBP,GPP,AR,HR",
136+
"plots_lnd": plots_lnd_all,
102137
"plots_ocn": "None",
103138
"nrows": "4",
104139
"ncols": "2",
105140
"results_dir": f"{RESULTS_DIR_PREFIX}_comprehensive_v3",
106141
"regions": "glb,n,s",
142+
"make_viewer": "False",
107143
"start_yr": "1985",
108144
"end_yr": "1995",
109145
}
@@ -135,6 +171,7 @@ def generate_results(parameters: Parameters):
135171

136172

137173
def run_all_cases():
174+
generate_results(parameters_viewers)
138175
generate_results(parameters_custom)
139176
generate_results(parameters_original_8_no_ocn)
140177
generate_results(parameters_original_8)

tests/unit/global_time_series/test_global_time_series.py

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@
33
import pytest
44

55
from zppy_interfaces.global_time_series.coupled_global import (
6-
Metric,
7-
Variable,
86
construct_generic_variables,
97
get_data_dir,
108
get_exps,
119
get_vars_original,
12-
get_ylim,
10+
land_csv_row_to_var,
11+
)
12+
from zppy_interfaces.global_time_series.coupled_global_plotting import get_ylim
13+
from zppy_interfaces.global_time_series.coupled_global_utils import Metric, Variable
14+
from zppy_interfaces.global_time_series.coupled_global_viewer import (
15+
VariableGroup,
16+
get_variable_groups,
1317
)
1418
from zppy_interfaces.global_time_series.utils import (
1519
Parameters,
@@ -81,6 +85,7 @@ def test_Parameters_and_related_functions():
8185
"ncols": "1",
8286
"results_dir": "results",
8387
"regions": "glb,n,s",
88+
"make_viewer": "True",
8489
"start_yr": "1985",
8590
"end_yr": "1989",
8691
}
@@ -238,11 +243,46 @@ def test_get_vars_original():
238243
assert get_var_names(get_vars_original(["invalid_plot"])) == []
239244

240245

246+
def test_land_csv_row_to_var():
247+
# Test with first row of land csv, whitespace stripped
248+
csv_row = "BCDEP,A,1.00000E+00,kg/m^2/s,kg/m^2/s,Aerosol Flux,total black carbon deposition (dry+wet) from atmosphere".split(
249+
","
250+
)
251+
v: Variable = land_csv_row_to_var(csv_row)
252+
assert v.variable_name == "BCDEP"
253+
assert v.metric == Metric.AVERAGE
254+
assert v.scale_factor == 1.0
255+
assert v.original_units == "kg/m^2/s"
256+
assert v.final_units == "kg/m^2/s"
257+
assert v.group == "Aerosol Flux"
258+
assert v.long_name == "total black carbon deposition (dry+wet) from atmosphere"
259+
260+
241261
def test_construct_generic_variables():
242262
vars: List[str] = ["a", "b", "c"]
243263
assert get_var_names(construct_generic_variables(vars)) == vars
244264

245265

266+
def test_VariableGroup():
267+
var_str_list: List[str] = ["a", "b", "c"]
268+
vars: List[Variable] = construct_generic_variables(var_str_list)
269+
g: VariableGroup = VariableGroup("MyGroup", vars)
270+
assert g.group_name == "MyGroup"
271+
assert get_var_names(g.variables) == var_str_list
272+
273+
274+
def test_get_variable_groups():
275+
a: Variable = Variable(variable_name="a", group="GroupA")
276+
b: Variable = Variable(variable_name="b", group="GroupA")
277+
x: Variable = Variable(variable_name="x", group="GroupX")
278+
y: Variable = Variable(variable_name="y", group="GroupX")
279+
280+
def get_group_names(groups: List[VariableGroup]) -> List[str]:
281+
return list(map(lambda g: g.group_name, groups))
282+
283+
assert get_group_names(get_variable_groups([a, b, x, y])) == ["GroupA", "GroupX"]
284+
285+
246286
def test_get_ylim():
247287
# Min is equal, max is equal
248288
assert get_ylim([-1, 1], [-1, 1]) == [-1, 1]

zppy_interfaces/global_time_series/__main__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ def _get_args() -> Parameters:
7676
parser.add_argument("--ncols", type=str, help="Number of columns in pdf")
7777
parser.add_argument("--results_dir", type=str, help="Results directory")
7878
parser.add_argument("--regions", type=str, help="Regions")
79+
parser.add_argument("--make_viewer", type=str, help="Make viewer")
7980

8081
# For both
8182
parser.add_argument("--start_yr", type=str, help="Start year")

0 commit comments

Comments
 (0)