Closed 7yl4r closed 10 months ago
There are two ways to get a value for the existing NAs:
Get a box of values and take the mean, which is what it previously did for the map.
Get the nearest non-landmasked pixel and extract the series of values for that. Preferred!
I think this is the way to go:
r - If raster value NA search and extract the nearest non-NA pixel - Stack Overflow
# then take the raster value with lowest distance to point AND non-NA value in the raster
sampled = apply(X = xy, MARGIN = 1, FUN = function(xy) r@data@values[which.min(replace(distanceFromPoints(r, xy), is.na(r), NA))])
This code in nms4r could be used to extract a polygon from ERDDAP.
Doing an average of the nearest N pixels (or lat/lon range?) will reduce noise in the signal.
Additionally: some sites are slightly "inland" (according to the course data pixels from ERDDAP) (e.g. montemar. This causes the pixel returned by ERDDAP to be all
NA
s, and so timeseries doesn't show up. Implementing an average that dropsNA
s should fix this.