marinebon / p2p

Pole to Pole website
https://marinebon.github.io/p2p
3 stars 1 forks source link

+ box w/ arithmetic mean to `get_timeseries()` #14

Closed 7yl4r closed 10 months ago

7yl4r commented 5 years ago

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 NAs, and so timeseries doesn't show up. Implementing an average that drops NAs should fix this.

bbest commented 5 years ago

There are two ways to get a value for the existing NAs:

  1. Get a box of values and take the mean, which is what it previously did for the map.

  2. Get the nearest non-landmasked pixel and extract the series of values for that. Preferred!

bbest commented 5 years ago

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))])
7yl4r commented 4 years ago

This code in nms4r could be used to extract a polygon from ERDDAP.