I am working with MODIS NDVI daily imagery in Google Earth Engine using Python. I want to identify the Julian Date at which NDVI reaches 50% between the minimum and maximum yearly values, and then return a collection of images which contain the 50% NDVI value and the Julian date at which that value was crossed for each year.
I would like to mask a collection representing daily annual time series, by another collection of images that represent the yearly values.
I have successfully created a function that iterates over the image collection returns a collection of threshold NDVI values for each year. This relies on the ee.Image.expression and ee.Reducer.minMax commands. However, I am struggling to mask the original collection of images based on the reduced dataset.
collection = ee.ImageCollection('MODIS/MCD43A4_006_NDVI') \
.filter(ee.Filter.date('2002-01-01', '2019-06-30'))\
.select("NDVI")
def addDateBand(image):
doy = image.date().getRelative('day', 'year')
doyBand = ee.Image.constant(doy).uint16().rename('doy')
return image.addBands(doyBand)
collection_withdates = collection.map(addDateBand)
calc_exp = '(b("NDVI_min") + (((b("NDVI_max") - b("NDVI_min")) * 0.5)))'
def makeYearlyComposite(date):
date = ee.Date(date)
return (collection_withdates \
.filterDate(date, date.advance(1, 'year')) \
.reduce(ee.Reducer.minMax())\
.expression(calc_exp).rename('NDVI_50')) \
.set("system:index", date.format("YYYY"))
start = ee.Date('2002-01-01')
end = ee.Date('2019-06-30')
n_yrs = end.difference(start, 'year').subtract(1)
years = ee.List.sequence(0, n_yrs).map(lambda n : start.advance(n, 'year'))
calc_composite = ee.ImageCollection(years.map(makeYearlyComposite))
This returns a collection of images that represent the values that I want to use as a mask on the original collection on a year-by-year basis. I am able to do this for one year using the updateMask function, but not for the entire collection which requires masking iteratively by year.
I am trying to figure out how to either integrate the threshold and masking steps into to the same initial function, or do it in two steps, the first to create the collection of masks, and the second to apply them.
Thanks in advance.