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

Handle NaN in sea ice clims #1096

Merged
merged 8 commits into from
Jun 4, 2024
Merged
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
45 changes: 22 additions & 23 deletions pcmdi_metrics/sea_ice/sea_ice_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,14 @@
end_year = meyear

real_clim = {
"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},
"arctic": {"model_mean": {}},
"ca": {"model_mean": {}},
"na": {"model_mean": {}},
"np": {"model_mean": {}},
"antarctic": {"model_mean": {}},
"sp": {"model_mean": {}},
"sa": {"model_mean": {}},
"io": {"model_mean": {}},
}
real_mean = {
"arctic": {"model_mean": 0},
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -365,29 +373,20 @@
# 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)
print("--------------------------------------------")
for rgn in real_clim:
print(rgn)
# Get model mean
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_clim[rgn][r][var].data for r in list_of_runs]
real_clim[rgn]["model_mean"][var] = np.nanmean(
np.array(datalist), axis=0
)
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
Expand Down
Loading