3

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?

2 Answers 2

5

If 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
2
  • The last line 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
  • 2
    You can use time.lower and time.upper.
    – Alex Leith
    Jul 27, 2021 at 0:15
3

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.