Commit 183297ef authored by CEVAER's avatar CEVAER
Browse files

Set NaNs to variable grids

parent 351c9782
......@@ -86,11 +86,24 @@ def to_polar(ds, lon_center, lat_center):
ds.lon.isel(x=-1, y=-1).item(), ds.lat.isel(x=-1, y=-1).item(),
ds.lon.isel(x=0, y=-1).item(), ds.lat.isel(x=0, y=-1).item())
# Build an array which takes negative values at location where wind_speed values are valid.
nan_mask_array = np.where(np.isnan(ds["wind_speed"]), 10, -50)
# Transform that array to polar
nan_mask_array_polar = cv2.linearPolar(nan_mask_array, (int(yloc), int(xloc)), max_radius,
cv2.INTER_NEAREST + cv2.WARP_FILL_OUTLIERS)
# Retrieve indices where valid data is located
valid_indices = np.where(nan_mask_array_polar < 0)
# Computing polar projection for all variables
vars_polar = {}
for var_name in ds.data_vars:
var_polar = cv2.linearPolar(ds[var_name].values, (int(yloc), int(xloc)), max_radius, cv2.INTER_NEAREST + cv2.WARP_FILL_OUTLIERS)
vars_polar[var_name] = (["theta", "rad"], var_polar)
var_polar = cv2.linearPolar(ds[var_name].values, (int(yloc), int(xloc)), max_radius,
cv2.INTER_NEAREST + cv2.WARP_FILL_OUTLIERS)
nan_ar = np.empty(var_polar.shape)
nan_ar[:] = np.nan
# Keeping only valid indices
nan_ar[valid_indices] = var_polar[valid_indices]
vars_polar[var_name] = (["theta", "rad"], nan_ar)
vars_polar["lon"] = (["theta", "rad"], lons_polar)
vars_polar["lat"] = (["theta", "rad"], lats_polar)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment