0

I want to get date value from time series of earth engine collection. This is my code:

import ee

ee.Authenticate()
ee.Initialize()

collection = ee.ImageCollection('NASA/FLDAS/NOAH01/C/GL/M/V001')
taken = collection.filterDate('2019-01-01', '2019-12-31').sort('system:time_start', False)
poi = ee.Geometry.Point([112.621391, -7.983908])

def setProperty(image):
    dict = image.reduceRegion(ee.Reducer.mean(), poi)
    return image.set(dict)

reduce = collection.map(setProperty)

time = reduce.aggregate_array('system:time_start').getInfo()

print(time)

But I get this output:

[378691200000, 381369600000, 383788800000, ..., 1588291200000]

Question: How to get the real date like this?

2019-01-01 00:00:00
ricoen
  • 9
  • 5
  • Please include the necessary imports to provide a [Provide a Minimal, Reproducible Example (e.g. code, data, errors) as text](https://stackoverflow.com/help/minimal-reproducible-example) – Trenton McKinney Jul 07 '20 at 06:12

2 Answers2

1

Those values are timestamps in milliseconds. Try converting them to proper datetime via:

import datetime

time = [datetime.datetime.fromtimestamp(x/1000) for x in reduce.aggregate_array('system:time_start').getInfo()]

or to make it a little less long:

import datetime

time = reduce.aggregate_array('system:time_start').getInfo()

dt_time = [datetime.datetime.fromtimestamp(x // 1000) for x in time]
ewokx
  • 2,204
  • 3
  • 14
  • 27
-1

it does not show anything in my case despite I got no error in running the code. In my case I have:

dataset = ee.ImageCollection('COPERNICUS/S2').filterDate(first_date, end_date).filterBounds(roi).filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', cloud_percentage))\
                  .map(addNDVI)\
                  .map(addMoisture)\
                  .map(maskS2clouds)\
                  .sort('system:time_start')                 
def setProperty(image):
    dict = image.reduceRegion(ee.Reducer.mean(), roi)
    return image.set(dict)

reduce = dataset.map(setProperty)

time = reduce.aggregate_array('system:time_start').getInfo()

dt_time = [datetime.datetime.fromtimestamp(x // 1000) for x in time]
print(dt_time)

I have verified that I have 35 images for the selected time interval and region of interest. Any suggestion?