Open Erin-Morrison opened 4 months ago
This is weird and not well documented -- I guess because we're using that website image and not the 'real' data product. Anyway:
x <- terra::rast("MOD17A3H_Y_NPP_2023-01-01_rgb_720x360.TIFF")
y <- terra::extract(x, 1:(360*720))
hist(y$`MOD17A3H_Y_NPP_2023-01-01_rgb_720x360`)
It looks like they're using value 255 in this image as NA
, so deal with that first:
x_clamp <- clamp(x, lower = 1, upper = 254, values = FALSE)
y <- terra::extract(x_clamp, 1:(360*720))
hist(y$`MOD17A3H_Y_NPP_2023-01-01_rgb_720x360`)
That looks better!
Now, the color scale on the webpage we got this from says that NPP has a minimum of 50 and maximum of 2000.
npp_correct <- scales::rescale(y$`MOD17A3H_Y_NPP_2023-01-01_rgb_720x360`, to = c(50, 2000))
So @Erin-Morrison you will want to
terra::clamp
as above to remove the 255 valuesterra::extract
to get the data for the points you wantscales::rescale
(or do by formula) to rescale data~ SEE NOTE BELOW to the 50-2000 gC/m2/yr rangeThe rescale function doesn't work properly as uses the maximum of the extracted data points as the 2000 value. This means it gives different NPP values for individual points depending on the rest of the data set. Instead once the 255 values are removed this formula should scale it correctly x*(1950/254) + 50 (x=the 0-254 NPP value for each data point).
Thanks for catching my mistake @Erin-Morrison ! 👍
The MODIS data points are slightly off but seem to be correct proportional to each other. For right now I am using them in the models but this should be fixed.