JGCRISummer2024 / Arctic_Fox

High Latitude Soil Respiration
1 stars 0 forks source link

MODIS #2

Open Erin-Morrison opened 4 months ago

Erin-Morrison commented 4 months ago

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.

bpbond commented 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`)

Rplot1

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`)

Rplot2

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

  1. Use terra::clamp as above to remove the 255 values
  2. Use terra::extract to get the data for the points you want
  3. ~Use scales::rescale (or do by formula) to rescale data~ SEE NOTE BELOW to the 50-2000 gC/m2/yr range
Erin-Morrison commented 4 months ago

The 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).

bpbond commented 4 months ago

Thanks for catching my mistake @Erin-Morrison ! 👍