I am trying to find all dates of a particular dataset in Open Data Cube.
The closest function I could find was dc.index.datasets.get_product_time_bounds
but that only provides the first and last date.
Is there any way to get all dates?
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.
Sign up to join this communityIf you only need the list of dates, you can use index.search_returning()
, which is much faster than a normal search as it doesn't need to pull the entire dataset back.
You give it the list of fields you want returned from the search, and it will return them as tuples:
for [time] in dc.index.datasets.search_returning(
['time'],
product='ls8_nbar_albers',
**other_search_params)
):
print(time)
# Time is actually a range
start_time, end_time = time.lower, time.upper
start_time, end_time = time
does not work and gives this error: TypeError: cannot unpack non-iterable DateTimeTZRange object
Jul 26, 2021 at 4:20
If what I'm hearing is that you'd like to know all the dates that a datacube product has datasets for, I don't think there's a built-in function.
The naive way to do it is to write something like:
import datacube
dc = datacube.Datacube()
datasets = dc.find_datasets(product="prod_name")
# Code to iterate through all datasets goes here
Note that this will load all datasets into memory, though. Better would be performing the query on the database. But unless someone else has a better idea, these two will work.