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

CDAT Migration: Update mp_partition_driver.py to use Dataset from dataset_xr.py #883

Merged
merged 4 commits into from
Oct 31, 2024
Merged
Changes from 2 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
27 changes: 14 additions & 13 deletions e3sm_diags/driver/mp_partition_driver.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
"""
This analysis set for mixed-phase cloud partition/T5050 metrics is requested by
the E3SM Aerosol Working Group. The script is integrated in e3sm_diags by Jill
Zhang and Yuying Zhang, with contribution from Yunpeng Shan, Jiwen Fan,
Xue Zheng and Susannah Burrows.
"""
from __future__ import annotations

import glob
Expand All @@ -9,8 +15,8 @@
import xarray as xr
from scipy.stats import binned_statistic

import e3sm_diags
from e3sm_diags.driver import utils
from e3sm_diags import INSTALL_PATH
from e3sm_diags.driver.utils.dataset_xr import Dataset
from e3sm_diags.logger import custom_logger
from e3sm_diags.plot.cartopy.mp_partition_plot import plot

Expand All @@ -20,8 +26,6 @@

logger = custom_logger(__name__)

# This analysis set for mixed-phase cloud partition/T5050 metrics is requested by the E3SM Aerosol Working Group. The script is integrated in e3sm_diags by Jill Zhang and Yuying Zhang, with contribution from Yunpeng Shan, Jiwen Fan, Xue Zheng and Susannah Burrows.


def flatten_array(var):
var_1d = var.stack(stacked=[...]).values
Expand Down Expand Up @@ -69,7 +73,7 @@ def run_diag(parameter: MPpartitionParameter) -> MPpartitionParameter:
# Read reference data first

benchmark_data_path = os.path.join(
e3sm_diags.INSTALL_PATH,
INSTALL_PATH,
"control_runs",
"mixed-phase_partition_data_1985-2014.json",
)
Expand All @@ -80,7 +84,7 @@ def run_diag(parameter: MPpartitionParameter) -> MPpartitionParameter:
# parse file
metrics_dict = json.loads(lcf_file)

test_data = utils.dataset.Dataset(parameter, test=True)
test_data = Dataset(parameter, data_type="test")
# test = test_data.get_timeseries_variable("LANDFRAC")
# print(dir(test))
# landfrac = test_data.get_timeseries_variable("LANDFRAC")(cdutil.region.domain(latitude=(-70.0, -30, "ccb")))
Expand Down Expand Up @@ -112,17 +116,16 @@ def run_diag(parameter: MPpartitionParameter) -> MPpartitionParameter:
)
raise

parameter.test_name_yrs = utils.general.get_name_and_yrs(
parameter, test_data, season
)
parameter.test_name_yrs = test_data.get_name_yrs_attr(season) # type: ignore

metrics_dict["test"] = {}
metrics_dict["test"]["T"], metrics_dict["test"]["LCF"] = compute_lcf(
cice, cliq, temp, landfrac
)

if run_type == "model-vs-model":
ref_data = utils.dataset.Dataset(parameter, ref=True)
ref_data = Dataset(parameter, data_type="ref")

ref_data_path = parameter.reference_data_path
start_year = parameter.ref_start_yr
end_year = parameter.ref_end_yr
Expand Down Expand Up @@ -162,9 +165,7 @@ def run_diag(parameter: MPpartitionParameter) -> MPpartitionParameter:
# cliq = ref_data.get_timeseries_variable("CLDLIQ")(
# cdutil.region.domain(latitude=(-70.0, -30, "ccb"))
# )
parameter.ref_name_yrs = utils.general.get_name_and_yrs(
parameter, ref_data, season
)
parameter.ref_name_yrs = ref_data.get_name_yrs_attr(season) # type: ignore
metrics_dict["ref"] = {}
metrics_dict["ref"]["T"], metrics_dict["ref"]["LCF"] = compute_lcf(
cice, cliq, temp, landfrac
Expand Down
Loading