Skip to content

Add ic_get_dates() function #216

Closed
Closed
@ErikSeras

Description

  • geemap version: 0.8.4
  • Python version: 3.6.9
  • Operating System: Google Colab

Description

I would like geemap to have a function that allows getting dates from an ee.ImageCollection. I tried it this way.

What I Did

import ee
import geemap
from datetime import datetime

try:
    ee.Initialize()
except Exception as e:
    ee.Authenticate()
    ee.Initialize()

# Function
def ic_get_dates(imgcol):
    def iter_func(image, newlist):
        date = ee.Number.parse(image.date().format("YYYYMMddHHmmss"));
        newlist = ee.List(newlist);
        return ee.List(newlist.add(date).sort())
    date_ee = imgcol.iterate(iter_func, ee.List([]))

    date_list = list(ee.List(date_ee).reduce(ee.Reducer.frequencyHistogram()).getInfo().keys())

    def date_gee(date):
        return str(datetime.strptime(date, '%Y%m%d%H%M%S')).replace(" ", "T")

    return list(map(date_gee, date_list))

# IC
ic = ee.ImageCollection("NOAA/GOES/16/MCMIPF") \
    .filterDate("2020-08-18T17:00:00", "2020-08-18T18:00:00")

# Get dates
dates = ic_get_dates(ic)

print(dates)

# ['2020-08-18T17:00:20', '2020-08-18T17:10:20', '2020-08-18T17:20:20', '2020-08-18T17:30:20', '2020-08-18T17:40:20', '2020-08-18T17:50:20']

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions