Skip to content

Commit

Permalink
Merge pull request #715 from metno/griesie_fix_710
Browse files Browse the repository at this point in the history
make calulation of temporal correlation work with xarray 2022.6.0
  • Loading branch information
jgriesfeller authored Aug 19, 2022
2 parents 9846275 + 0fb90d8 commit cdb5e93
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions pyaerocom/aeroval/coldatatojson_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1075,13 +1075,15 @@ def _calc_temporal_corr(coldata):
return np.nan, np.nan
elif coldata.has_latlon_dims:
coldata = coldata.flatten_latlondim_station_name()
arr = coldata.data

# Use only sites that contain at least 3 valid data points (otherwise
# correlation will be 1).
obs_ok = arr[0].count(dim="time") > 2
arr[0] = arr[0].where(obs_ok, drop=True)
arr[1] = arr[1].where(obs_ok, drop=True)
if np.prod(arr.shape) == 0:
obs_ok = coldata.data[0].count(dim="time") > 2
arr = []
arr.append(coldata.data[0].where(obs_ok, drop=True))
arr.append(coldata.data[1].where(obs_ok, drop=True))

if np.prod(arr[0].shape) == 0 or np.prod(arr[1].shape) == 0:
return np.nan, np.nan
corr_time = xr.corr(arr[1], arr[0], dim="time")
with ignore_warnings(RuntimeWarning, "Mean of empty slice", "All-NaN slice encountered"):
Expand Down

0 comments on commit cdb5e93

Please sign in to comment.