Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Viewer support #9

Merged
merged 11 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
recursive-include zppy_interfaces *.csv
recursive-include zppy_interfaces *.html
3 changes: 3 additions & 0 deletions conda/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ dependencies:
- setuptools >= 60
# Base
# =================
- beautifulsoup4
- lxml
- matplotlib-base >=3.8.2,<3.10
- mpas_tools >=0.21.0
- netcdf4
- numpy >=2.0,<3.0
- output_viewer=1.3.3
- xarray >=2023.02.0
- xcdat >=0.7.3,<1.0
# Testing
Expand Down
43 changes: 40 additions & 3 deletions tests/integration/global_time_series/cases_global_time_series.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,38 @@
WEB_DIR = "/lcrc/group/e3sm/public_html/diagnostic_output/ac.forsyth2/zi-test-webdir/"
RESULTS_DIR_PREFIX = "global_time_series_1985-1995_results"

plots_lnd_metric_average = "FSH,RH2M,LAISHA,LAISUN,QINTR,QOVER,QRUNOFF,QSOIL,QVEGE,QVEGT,SOILWATER_10CM,TSA,H2OSNO,"
plots_lnd_metric_total = (
"TOTLITC,CWDC,SOIL1C,SOIL2C,SOIL3C,SOIL4C,WOOD_HARVESTC,TOTVEGC,NBP,GPP,AR,HR"
)
plots_lnd_all = plots_lnd_metric_average + plots_lnd_metric_total

parameters_viewers: Parameters = Parameters(
{
"use_ocn": "False",
"input": "/lcrc/group/e3sm2/ac.wlin/E3SMv3/v3.LR.historical_0051",
"input_subdir": "archive/ocn/hist",
"moc_file": "None",
"case_dir": CASE_DIR,
"experiment_name": "v3.LR.historical_0051",
"figstr": "v3.LR.historical_0051",
"color": "Blue",
"ts_num_years": "5",
"plots_original": "None",
"plots_atm": "TREFHT",
"plots_ice": "None",
"plots_lnd": plots_lnd_all,
"plots_ocn": "None",
"nrows": "1",
"ncols": "1",
"results_dir": f"{RESULTS_DIR_PREFIX}_viewers",
"regions": "glb,n,s",
"make_viewer": "True",
"start_yr": "1985",
"end_yr": "1995",
}
)

parameters_custom: Parameters = Parameters(
{
"use_ocn": "False",
Expand All @@ -20,14 +52,15 @@
"color": "Blue",
"ts_num_years": "5",
"plots_original": "None",
"plots_atm": "TREFHT,AODDUST",
"plots_atm": "TREFHT",
"plots_ice": "None",
"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",
"plots_lnd": plots_lnd_all,
"plots_ocn": "None",
"nrows": "4",
"ncols": "2",
"results_dir": f"{RESULTS_DIR_PREFIX}_custom",
"regions": "glb,n,s",
"make_viewer": "False",
"start_yr": "1985",
"end_yr": "1995",
}
Expand All @@ -54,6 +87,7 @@
"ncols": "2",
"results_dir": f"{RESULTS_DIR_PREFIX}_original_8_no_ocn",
"regions": "glb,n,s",
"make_viewer": "False",
"start_yr": "1985",
"end_yr": "1995",
}
Expand All @@ -79,6 +113,7 @@
"ncols": "2",
"results_dir": f"{RESULTS_DIR_PREFIX}_original_8",
"regions": "glb,n,s",
"make_viewer": "False",
"start_yr": "1985",
"end_yr": "1995",
}
Expand All @@ -98,12 +133,13 @@
"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",
"plots_atm": "None",
"plots_ice": "None",
"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",
"plots_lnd": plots_lnd_all,
"plots_ocn": "None",
"nrows": "4",
"ncols": "2",
"results_dir": f"{RESULTS_DIR_PREFIX}_comprehensive_v3",
"regions": "glb,n,s",
"make_viewer": "False",
"start_yr": "1985",
"end_yr": "1995",
}
Expand Down Expand Up @@ -135,6 +171,7 @@ def generate_results(parameters: Parameters):


def run_all_cases():
generate_results(parameters_viewers)
generate_results(parameters_custom)
generate_results(parameters_original_8_no_ocn)
generate_results(parameters_original_8)
Expand Down
46 changes: 43 additions & 3 deletions tests/unit/global_time_series/test_global_time_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
import pytest

from zppy_interfaces.global_time_series.coupled_global import (
Metric,
Variable,
construct_generic_variables,
get_data_dir,
get_exps,
get_vars_original,
get_ylim,
land_csv_row_to_var,
)
from zppy_interfaces.global_time_series.coupled_global_plotting import get_ylim
from zppy_interfaces.global_time_series.coupled_global_utils import Metric, Variable
from zppy_interfaces.global_time_series.coupled_global_viewer import (
VariableGroup,
get_variable_groups,
)
from zppy_interfaces.global_time_series.utils import (
Parameters,
Expand Down Expand Up @@ -81,6 +85,7 @@ def test_Parameters_and_related_functions():
"ncols": "1",
"results_dir": "results",
"regions": "glb,n,s",
"make_viewer": "True",
"start_yr": "1985",
"end_yr": "1989",
}
Expand Down Expand Up @@ -238,11 +243,46 @@ def test_get_vars_original():
assert get_var_names(get_vars_original(["invalid_plot"])) == []


def test_land_csv_row_to_var():
# Test with first row of land csv, whitespace stripped
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(
","
)
v: Variable = land_csv_row_to_var(csv_row)
assert v.variable_name == "BCDEP"
assert v.metric == Metric.AVERAGE
assert v.scale_factor == 1.0
assert v.original_units == "kg/m^2/s"
assert v.final_units == "kg/m^2/s"
assert v.group == "Aerosol Flux"
assert v.long_name == "total black carbon deposition (dry+wet) from atmosphere"


def test_construct_generic_variables():
vars: List[str] = ["a", "b", "c"]
assert get_var_names(construct_generic_variables(vars)) == vars


def test_VariableGroup():
var_str_list: List[str] = ["a", "b", "c"]
vars: List[Variable] = construct_generic_variables(var_str_list)
g: VariableGroup = VariableGroup("MyGroup", vars)
assert g.group_name == "MyGroup"
assert get_var_names(g.variables) == var_str_list


def test_get_variable_groups():
a: Variable = Variable(variable_name="a", group="GroupA")
b: Variable = Variable(variable_name="b", group="GroupA")
x: Variable = Variable(variable_name="x", group="GroupX")
y: Variable = Variable(variable_name="y", group="GroupX")

def get_group_names(groups: List[VariableGroup]) -> List[str]:
return list(map(lambda g: g.group_name, groups))

assert get_group_names(get_variable_groups([a, b, x, y])) == ["GroupA", "GroupX"]


def test_get_ylim():
# Min is equal, max is equal
assert get_ylim([-1, 1], [-1, 1]) == [-1, 1]
Expand Down
1 change: 1 addition & 0 deletions zppy_interfaces/global_time_series/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def _get_args() -> Parameters:
parser.add_argument("--ncols", type=str, help="Number of columns in pdf")
parser.add_argument("--results_dir", type=str, help="Results directory")
parser.add_argument("--regions", type=str, help="Regions")
parser.add_argument("--make_viewer", type=str, help="Make viewer")

# For both
parser.add_argument("--start_yr", type=str, help="Start year")
Expand Down
Loading
Loading