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
?
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 communityI 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
?
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 (see above update)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.
You can see this working in the load_ard
source code:
predicate
func: https://github.com/GeoscienceAustralia/dea-notebooks/blob/develop/Tools/dea_tools/datahandling.py#L328-L329dc.load
: https://github.com/GeoscienceAustralia/dea-notebooks/blob/develop/Tools/dea_tools/datahandling.py#L342Here'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)