Commit 3a03d676 authored by CEVAER's avatar CEVAER
Browse files

set Nans to radii if not enough data

parent 455e20bb
......@@ -19,13 +19,20 @@ def research_contour(mask, lon, lat):
return lon_lwind, lat_lwind
def radius_for_wind(wind_mean, wind_knots, idx_max):
def radius_for_wind(polar_ds, wind_mean, wind_knots, idx_max):
wind_ms = wind_knots * 0.514444
wind_masked = np.ma.asarray(wind_mean.values)
wind_masked[:idx_max] = np.ma.masked
idx = np.nanargmin(np.abs(wind_masked - wind_ms))
count_total = polar_ds.isel(rad=idx).wind_speed.count(dim="theta")
wind_nan_count = np.sum(np.where(np.isnan(polar_ds.isel(rad=idx).wind_speed.values), 1, 0))
percent_invalid = wind_nan_count / count_total * 100
if percent_invalid > 75:
return np.nan, np.nan
return wind_mean.isel(rad=idx).item(), wind_mean.isel(rad=idx)["rad"].item()
......@@ -93,7 +100,7 @@ def save_netcdf(sat_file, path, center_status, percent_outside, percent_inside_i
})
# Compute and add radii to xarray dataset
quadrants = {"all": slice(0, 360), "NE": slice(0,90), "SE": slice(90, 180), "SW": slice(180, 270), "NW": slice(270, 360)}
quadrants = {"all": slice(0, 360), "NE": slice(0, 90), "SE": slice(90, 180), "SW": slice(180, 270), "NW": slice(270, 360)}
for quad, sl in quadrants.items():
polar_quad = ds_polar_north.sel(theta=sl)
wind_mean = polar_quad.wind_speed.mean(dim="theta")
......@@ -107,7 +114,7 @@ def save_netcdf(sat_file, path, center_status, percent_outside, percent_inside_i
radii = []
radii_nmi = []
for w in wind_vals:
wind_r, radius_w = radius_for_wind(wind_mean, w, idx_max)
wind_r, radius_w = radius_for_wind(ds_polar_north, wind_mean, w, idx_max)
radii.append(radius_w)
radii_nmi.append(radius_w * 0.000539957)
......
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