diff --git a/zppy_interfaces/global_time_series/coupled_global.py b/zppy_interfaces/global_time_series/coupled_global.py index b07bee8..ea0be12 100644 --- a/zppy_interfaces/global_time_series/coupled_global.py +++ b/zppy_interfaces/global_time_series/coupled_global.py @@ -165,7 +165,7 @@ def set_var( new_var_list: List[Variable] = [] if exp[exp_key] != "": try: - dataset_wrapper: DatasetWrapper = DatasetWrapper(exp[exp_key]) + dataset_wrapper: DatasetWrapper = DatasetWrapper(exp[exp_key], var_list) except Exception as e: logger.critical(e) logger.critical( @@ -253,16 +253,16 @@ def process_data( # Optionally read ohc if exp["ocean"] != "": - dataset_wrapper = DatasetWrapper(exp["ocean"]) - exp["annual"]["ohc"], _ = dataset_wrapper.globalAnnual(Variable("ohc")) + ohc_variable = Variable("ohc") + dataset_wrapper = DatasetWrapper(exp["ocean"], [ohc_variable]) + exp["annual"]["ohc"], _ = dataset_wrapper.globalAnnual(ohc_variable) # anomalies with respect to first year exp["annual"]["ohc"][:] = exp["annual"]["ohc"][:] - exp["annual"]["ohc"][0] if exp["vol"] != "": - dataset_wrapper = DatasetWrapper(exp["vol"]) - exp["annual"]["volume"], _ = dataset_wrapper.globalAnnual( - Variable("volume") - ) + vol_variable = Variable("volume") + dataset_wrapper = DatasetWrapper(exp["vol"], [vol_variable]) + exp["annual"]["volume"], _ = dataset_wrapper.globalAnnual(vol_variable) # annomalies with respect to first year exp["annual"]["volume"][:] = ( exp["annual"]["volume"][:] - exp["annual"]["volume"][0] diff --git a/zppy_interfaces/global_time_series/coupled_global_dataset_wrapper.py b/zppy_interfaces/global_time_series/coupled_global_dataset_wrapper.py index cd5e3dc..7af8a63 100644 --- a/zppy_interfaces/global_time_series/coupled_global_dataset_wrapper.py +++ b/zppy_interfaces/global_time_series/coupled_global_dataset_wrapper.py @@ -1,4 +1,4 @@ -from typing import Tuple +from typing import Any, List, Optional, Tuple import xarray import xcdat @@ -10,16 +10,20 @@ class DatasetWrapper(object): - def __init__(self, directory): + def __init__(self, directory: str, var_list: List[Variable]): self.directory: str = directory # `directory` will be of the form `{case_dir}/post//glb/ts/monthly/{ts_num_years_str}yr/` + file_path_list: List[str] = [] + for var in var_list: + # `var` will be of the form `FSNS`, `FLNS`, etc. + file_path_list.append(f"{directory}{var.variable_name}*.nc") self.dataset: xarray.core.dataset.Dataset = xcdat.open_mfdataset( - f"{directory}*.nc", center_times=True + file_path_list, center_times=True ) - self.area_tuple = None + self.area_tuple: Optional[Tuple[Any, Any, Any]] = None def set_area_tuple(self): keys = list(self.dataset.keys())