1

I have a 32 year Landsat time series Open Data Cube query and I am interested in pulling out only two months per year of data (August and Feb).

Is there any way extracting data per month with the dc.load, or following the dc.load?

1
  • Hi, and welcome to GIS Stackexchange. It will increase the likelihood of getting a (useful) answer to share what you've tried already, and what portal/platform you are running the time series query on. Finally it might be obvious, but clarifying what 'dc load' might turn out to be helpful context for those answering.
    – RoperMaps
    Jun 22, 2021 at 7:57

1 Answer 1

3

August 2021 update: As of version v1.84, open-data-cube itself now supports passing directly filtering data before loading it by passing a predicate/filter function to datacube.load()'s new dataset_predicate parameter. For example, to load satellite data from February and August only:

import datacube

# Connect to datacube
dc = datacube.Datacube(app='Filtering_datasets')

# Create a predicate function for filtering satellite data.
# This returns True only if the dataset's month is Feb (2) or 
# August (8):
def filter_feb_aug(dataset):
    return dataset.time.begin.month in (2, 8)

# Load satellite data using predicate function to filter to specific months
ds = dc.load(product='ga_ls8c_ard_3', 
             lat=(-35.0, -35.1), 
             lon=(148.0, 148.1), 
             time='2018',
             measurements=['nbart_red'],
             dataset_predicate=filter_feb_aug,
             output_crs='EPSG:3577',
             resolution=(-30, 30),
             group_by='solar_day')

# Verify that only August or February satellite observations remain 
print(ds.time)


June 2021 answer: The predicate functionality in the load_ard function from dea-tools lets you do this! Essentially you can pass in a custom function and it will filter data prior to actually loading it - there's some examples here that show how to use load_ard to extract only data from a single month or season: https://docs.dea.ga.gov.au/notebooks/Frequently_used_code/Using_load_ard.html#Filtering-data-before-load-using-a-custom-function

If you want to do something similar with dc.load itself it's a little trickier: you'll need to identify the data you want to load with dc.find_datasets, then loop through the resulting list and keep only the individual datasets that match your criteria. The filtered list can then be loaded with dc.load using the datasets param. (see above update)

You can see this working in the load_ard source code:

  1. Where it identifies all the datasets to load for a given query: https://github.com/GeoscienceAustralia/dea-notebooks/blob/develop/Tools/dea_tools/datahandling.py#L308
  2. Where it filters that list based on the predicate func: https://github.com/GeoscienceAustralia/dea-notebooks/blob/develop/Tools/dea_tools/datahandling.py#L328-L329
  3. And finally, where that filtered list of datasets is given to dc.load: https://github.com/GeoscienceAustralia/dea-notebooks/blob/develop/Tools/dea_tools/datahandling.py#L342

Here's a simple code example that works on the Digital Earth Australia instance of the Open Data Cube:

import datacube
from dea_tools.datahandling import load_ard

# Connect to datacube
dc = datacube.Datacube(app='Filtering_datasets')


# Create a predicate function for filtering satellite data.
# This returns True only if the dataset's month is Feb (2) or 
# August (8):
def filter_feb_aug(dataset):
    return dataset.time.begin.month in (2, 8)


# Load satellite data using predicate function to filter to specific months
ds = load_ard(dc=dc,
              products=['ga_ls8c_ard_3'],
              lat=(-35.0, -35.1),
              lon=(148.0, 148.1),
              time='2018',
              measurements=['nbart_red'],
              predicate=filter_feb_aug,
              output_crs='EPSG:3577',
              resolution=(-30, 30),
              group_by='solar_day')

# Verify that only August or February satellite observations remain
print(ds.time)

Output of filtered data load

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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