0

I am just getting started with the GEE Python API. I want to extract NDVI values from single pixels of a MODIS product. When I run this:

import ee
ee.Authenticate()
ee.Initialize()

t_start = ee.Date("2000-01-01")
t_end = ee.Date("2020-05-25")

AOI = ee.FeatureCollection("users/manuelpopp/xining")

MODIS = ee.ImageCollection("MODIS/006/MOD13Q1") \
    .filterDate(t_start, t_end).filterBounds(AOI)

MODIS_ndvi = MODIS.select("NDVI")

scenes = [scene.get("id") for scene in MODIS_ndvi.getInfo().get("features")]
scene = scenes[0]
img = ee.Image(scene)
p = ee.Geometry.Point(101.768548, 36.685077)
ndvit = img.reduceRegion(ee.Reducer.first(), p).get("NDVI").getInfo()

it will set ndvit to 865. However, NDVI should not be a value larger than 1.

What did I do wrong here? I suppose there is a simple explanation for this value?

Manuel Popp
  • 1,003
  • 1
  • 10
  • 33

1 Answers1

1

The official file specification states that the true values ("parameter") are obtained through the following equation:

parameter=(file data - add_offset)/scale_factor

where file data is the value in the file, and add_offset and scale_factor are defined as e.g.


DataField_1     1 km 16 days NDVI       INT16           Dimension_1
                                                        Dimension_2

        DataField_1 HDF Attributes:
        Attribute       Data Type       Number of Values        Value or Max. String Length

        long_name       STRING          17      1 km 16 days NDVI
        units           STRING          4       NDVI
        valid_range     INT16           2       -2000, 10000
        _FillValue      INT16           1       -3000
        scale_factor    FLOAT64         1       10000
        scale_factor_err FLOAT64        1       0.0
        add_offset      FLOAT64         1       0.0
        add_offset_err  FLOAT64         1       0.0
        calibrated_nt   INT32           1       5

The scale_factor value is also in this table (add_offset is rarely used).

These value conversions are done to save space on disk (enabling saving the data as 16-bit integer rather than 32 or 64 bit floating point).

Jesse Anderson
  • 4,507
  • 26
  • 36
  • Thanks. I didn't expect they'd do such a thing, but considering the amount of data they have to store, it probably matters what format your values are in... – Manuel Popp Jun 05 '21 at 12:18