diff --git a/pcmdi_metrics/sea_ice/sea_ice_driver.py b/pcmdi_metrics/sea_ice/sea_ice_driver.py index 4d190e4cd..741847964 100644 --- a/pcmdi_metrics/sea_ice/sea_ice_driver.py +++ b/pcmdi_metrics/sea_ice/sea_ice_driver.py @@ -228,14 +228,14 @@ end_year = meyear real_clim = { - "arctic": {"model_mean": {}}, - "ca": {"model_mean": {}}, - "na": {"model_mean": {}}, - "np": {"model_mean": {}}, - "antarctic": {"model_mean": {}}, - "sp": {"model_mean": {}}, - "sa": {"model_mean": {}}, - "io": {"model_mean": {}}, + "arctic": {"model_mean": None}, + "ca": {"model_mean": None}, + "na": {"model_mean": None}, + "np": {"model_mean": None}, + "antarctic": {"model_mean": None}, + "sp": {"model_mean": None}, + "sa": {"model_mean": None}, + "io": {"model_mean": None}, } real_mean = { "arctic": {"model_mean": 0}, @@ -309,7 +309,15 @@ "%(model_version)": model, "%(realization)": run, } - test_data_full_path = os.path.join(test_data_path, filename_template) + test_data_tmp = lib.replace_multi(test_data_path, tags) + if "*" in test_data_tmp: + # Get the most recent version for last wildcard + ind = test_data_tmp.split("/")[::-1].index("*") + tmp1 = "/".join(test_data_tmp.split("/")[0:-ind]) + globbed = glob.glob(tmp1) + globbed.sort() + test_data_tmp = globbed[-1] + test_data_full_path = os.path.join(test_data_tmp, filename_template) test_data_full_path = lib.replace_multi(test_data_full_path, tags) test_data_full_path = glob.glob(test_data_full_path) test_data_full_path.sort() @@ -365,7 +373,16 @@ # Running sum of all realizations for rgn in clims: real_clim[rgn][run] = clims[rgn] + if real_clim[rgn]["model_mean"] is None: + real_clim[rgn]["model_mean"] = clims[rgn] + else: + real_clim[rgn]["model_mean"][var] = ( + real_clim[rgn]["model_mean"][var] + clims[rgn][var] + ) real_mean[rgn][run] = means[rgn] + real_mean[rgn]["model_mean"] = ( + real_mean[rgn]["model_mean"] + means[rgn] + ) print("\n-------------------------------------------") print("Calculating model regional average metrics \nfor ", model) @@ -373,12 +390,12 @@ for rgn in real_clim: print(rgn) # Get model mean - datalist = [real_clim[rgn][r][var].data for r in list_of_runs] - real_clim[rgn]["model_mean"][var] = np.nanmean( - np.array(datalist), axis=0 + real_clim[rgn]["model_mean"][var] = real_clim[rgn]["model_mean"][ + var + ] / len(list_of_runs) + real_mean[rgn]["model_mean"] = real_mean[rgn]["model_mean"] / len( + list_of_runs ) - datalist = [real_mean[rgn][r] for r in list_of_runs] - real_mean[rgn]["model_mean"] = np.nanmean(np.array(datalist)) for run in real_clim[rgn]: # Set up metrics dictionary