davemlz / eemont

A python package that extends Google Earth Engine.
https://eemont.readthedocs.io/
MIT License
417 stars 69 forks source link

getTimeSeriesByRegion returns repeated and empty dates in time series #79

Closed mariofomacajr closed 2 years ago

mariofomacajr commented 2 years ago

When I getTimeSeriesByRegion to Sentinel 2 NDVI its returns empty cand repeated cells in result it's as if there were many images in one day with a few seconds of difference

BUG_eemont.zip Captura de tela 2022-09-12 105922

davemlz commented 2 years ago

Hey Mario!

Now I see the problem: You're filtering the collection by all the points and then just requesting the time series of a single point. If you want to do it that way (point by point), you must go:

for i in range(len(data)):

    point = ee.Geometry.Point([data['lon'][i],data['lat'][i]]).buffer(20) 

    S2 = (ee.ImageCollection("COPERNICUS/S2_SR")
        .filterBounds(point)
        .filterDate("2021-08-01","2022-02-15")        
        .scaleAndOffset()
        .maskClouds(scaledImage=True) # Set this arg to True if scaling before masking
        .spectralIndices(['NDVI']))

    ts_S2 = S2.getTimeSeriesByRegion(geometry= point,
                            bands = ['NDVI'],
                            reducer = [ee.Reducer.mean()],
                            scale = 10,
                            naValue = -9999)

    ...

I'm sorry I didn't see the error before.

Also, if you're using maskClouds() after scaleAndOffset() you have to set maskClouds(scaledImage=True). A better option is to go:

S2 = (ee.ImageCollection("COPERNICUS/S2_SR")
      .filterBounds(point)
      .filterDate("2021-08-01","2022-02-15")        
      .preprocess()
      .spectralIndices(['NDVI']))

With preprocess() both maskClouds() and scaleAndOffset() are done automatically! :)

Cheers!

David

mariofomacajr commented 2 years ago

Thank you soo much!