Loading data from the datacube

This notebook will briefly discuss how to load data from the datacube.

Requirements:

You need to run the following commands from the command line prior to launching jupyter notebook from the same terminal so that the required libraries and paths are set.

module use /g/data/v10/public/modules/modulefiles

module load dea

Importing the datacube module

To start with, we’ll import the datacube module and load an instance of the datacube and call our application name load-data-example.

[1]:
import datacube
dc = datacube.Datacube(app='load-data-example')

Loading data

Loading data from the datacube uses the load function.

The function takes several arguments:

  • product; A specifc product to load

  • x; Defines the spatial region in the x dimension

  • y; Defines the spatial region in the y dimension

  • time; Defines the temporal extent.

We’ll load the Landsat 5-TM, Nadir Bi-directional reflectance ristribution function Adjusted Reflectance, for the spatial region covering:

  • 149.25 -> 149.5 degrees longitude

  • -36.25 -> -36.5 degrees latitude

and a temporal extent covering:

  • 2008-01-01 -> 2009-01-01

[2]:
data = dc.load(product='ls5_nbar_albers',
               x=(149.25, 149.5), y=(-36.25, -36.5),
               time=('2008-01-01', '2009-01-01'))
[3]:
data
[3]:
<xarray.Dataset>
Dimensions:  (time: 8, x: 1041, y: 1221)
Coordinates:
  * time     (time) datetime64[ns] 2008-01-15T23:41:48.500000 ...
  * y        (y) float64 -4.066e+06 -4.066e+06 -4.066e+06 -4.066e+06 ...
  * x        (x) float64 1.543e+06 1.543e+06 1.543e+06 1.543e+06 1.543e+06 ...
Data variables:
    blue     (time, y, x) int16 3326 3326 3326 3326 3326 3326 3326 3326 3326 ...
    green    (time, y, x) int16 6061 5882 5942 5853 5942 5972 6150 7088 7493 ...
    red      (time, y, x) int16 5943 5792 5767 5717 5868 5792 6194 6370 6370 ...
    nir      (time, y, x) int16 6678 6434 6504 6364 6504 6434 6749 7932 8866 ...
    swir1    (time, y, x) int16 3155 2939 3179 3035 3323 3418 3825 4926 6002 ...
    swir2    (time, y, x) int16 1784 1618 1884 1718 1884 1984 2350 3182 4113 ...
Attributes:
    crs:      EPSG:3577

Load data via a products native co-ordinate system

By default, the x and y arguments accept queries in a geographical co-ordinate system WGS84, identified by the EPSG code 4326, which is the same as within Google Earth.

The user can also query via the native co-ordinate system that the product is stored in, and supply the crs argument.

[4]:
data = dc.load(product='ls5_nbar_albers',
               x=(1543137.5, 1569137.5), y=(-4065537.5, -4096037.5), crs='EPSG:3577',
               time=('2008-01-01', '2009-01-01'))
[5]:
data
[5]:
<xarray.Dataset>
Dimensions:  (time: 8, x: 1041, y: 1221)
Coordinates:
  * time     (time) datetime64[ns] 2008-01-15T23:41:48.500000 ...
  * y        (y) float64 -4.066e+06 -4.066e+06 -4.066e+06 -4.066e+06 ...
  * x        (x) float64 1.543e+06 1.543e+06 1.543e+06 1.543e+06 1.543e+06 ...
Data variables:
    blue     (time, y, x) int16 3326 3326 3326 3326 3326 3326 3326 3326 3326 ...
    green    (time, y, x) int16 6061 5882 5942 5853 5942 5972 6150 7088 7493 ...
    red      (time, y, x) int16 5943 5792 5767 5717 5868 5792 6194 6370 6370 ...
    nir      (time, y, x) int16 6678 6434 6504 6364 6504 6434 6749 7932 8866 ...
    swir1    (time, y, x) int16 3155 2939 3179 3035 3323 3418 3825 4926 6002 ...
    swir2    (time, y, x) int16 1784 1618 1884 1718 1884 1984 2350 3182 4113 ...
Attributes:
    crs:      EPSG:3577

Load specific measurements of a given product

Some products have several measurements such as Landsat 5-TM, which for the ls5_nbar_albers product contains the following spectral measurements:

  • blue

  • green

  • red

  • nir

  • swir1

  • swir2

In this next example we’ll only load the red and nir measurements.

[6]:
data = dc.load(product='ls5_nbar_albers',
               x=(149.25, 149.5), y=(-36.25, -36.5),
               time=('2008-01-01', '2009-01-01'),
               measurements=['red', 'nir'])
[7]:
data
[7]:
<xarray.Dataset>
Dimensions:  (time: 8, x: 1041, y: 1221)
Coordinates:
  * time     (time) datetime64[ns] 2008-01-15T23:41:48.500000 ...
  * y        (y) float64 -4.066e+06 -4.066e+06 -4.066e+06 -4.066e+06 ...
  * x        (x) float64 1.543e+06 1.543e+06 1.543e+06 1.543e+06 1.543e+06 ...
Data variables:
    red      (time, y, x) int16 5943 5792 5767 5717 5868 5792 6194 6370 6370 ...
    nir      (time, y, x) int16 6678 6434 6504 6364 6504 6434 6749 7932 8866 ...
Attributes:
    crs:      EPSG:3577

More information on the load function see the API docs: load()