-
Notifications
You must be signed in to change notification settings - Fork 1
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
Improve mapping interpolation with k>1 when NaN values are present #382
Comments
Could do locally derived value fixing with something along the lines of def clean(img: np.ndarray) -> np.ndarray:
nans = np.isnan(img)
cleaned = img.copy()
cleaned[nans] = np.nanmedian(img)
to_fix = nans & ~scipy.ndimage.uniform_filter(nans, size=3)
for i, j in np.argwhere(to_fix):
cleaned[i, j] = np.nanmean(img[max(i - 1, 0) : i + 2, max(j - 1, 0) : j + 2])
return cleaned |
Non-finite values are replaced with the average of neighbouring pixels before mapping, rather than 0. This should reduce artefacts when using spline interpolation. #382
From futher testing,
I think this probably therefore rules out Scipy's |
`scipy.interpolate.griddata` was very slow, and could produce unstable results, so it seems much more sensible to stick with `RectBivariateSpline` with the newer more sophisticated NaN replacement. #382 (comment)
Currently, we use
RectBivariateSpline
, so have to replace NaN pixels with some value before interpolating (currently just set to 0). Even though we later mask any projected NaN pixels (with_should_propagate_nan_to_map
), this can produce edge effects near NaN pixels when using e.g. cubic splines.It would make more sense therefore to either:
nanmean
of 3x3 footprint around each pixel. This would cost more performance, but provide better results for variable data.bisplrep
orgriddata
.The text was updated successfully, but these errors were encountered: