datacube.api.utils module¶
-
datacube.api.utils.empty_array(shape, dtype=<type 'numpy.int16'>, fill=-999)[source]¶ Return an empty (i.e. filled with the no data value) array of the given shape and data type
Parameters: - shape – shape of the array
- dtype – data type of the array (defaults to int32)
- fill – no data value (defaults to -999)
Returns: array
-
class
datacube.api.utils.DatasetBandMetaData(no_data_value, data_type)[source]¶ -
no_data_value= None¶
-
data_type= None¶
-
-
class
datacube.api.utils.DatasetMetaData(shape, transform, projection, bands)[source]¶ -
shape= None¶
-
transform= None¶
-
projection= None¶
-
bands= None¶
-
pixel_size_x= None¶
-
pixel_size_y= None¶
-
ul= None¶
-
lr= None¶
-
-
datacube.api.utils.get_dataset_data(dataset, bands=None, x=0, y=0, x_size=None, y_size=None)[source]¶
-
datacube.api.utils.read_dataset_data(dataset, bands=None, x=0, y=0, x_size=None, y_size=None)[source]¶ Return one or more bands from a dataset
Parameters: - dataset – The dataset from which to read the band
- bands – A list of bands to read from the dataset
- x –
- y –
- x_size –
- y_size –
Returns: dictionary of band/data as numpy array
-
datacube.api.utils.get_dataset_data_masked(dataset, bands=None, x=0, y=0, x_size=None, y_size=None, ndv=-999, mask=None)[source]¶ Return one or more bands from the dataset with pixel quality applied
Return type: dict[numpy.array]
-
datacube.api.utils.get_dataset_data_with_pq(dataset, dataset_pqa, bands=None, x=0, y=0, x_size=None, y_size=None, masks_pqa=[<PqaMask.PQ_MASK_CLEAR: 16383>], ndv=-999)[source]¶ Return one or more bands from the dataset with pixel quality applied
Return type: dict[numpy.array]
-
datacube.api.utils.get_mask_pqa(pqa, pqa_masks=[<PqaMask.PQ_MASK_CLEAR: 16383>], x=0, y=0, x_size=None, y_size=None, mask=None)[source]¶ Return a pixel quality mask
Parameters: - pqa – Pixel Quality dataset
- pqa_masks – which PQ flags to use
- mask – an optional existing mask to update
Returns: the mask
-
datacube.api.utils.get_mask_wofs(wofs, wofs_masks=[<WofsMask.WET: 128>], x=0, y=0, x_size=None, y_size=None, mask=None)[source]¶ Return a WOFS mask
Parameters: - wofs – WOFS dataset
- wofs_masks – which WOFS values to mask
- mask – an optional existing mask to update
Returns: the mask
-
datacube.api.utils.get_mask_vector_for_cell(x, y, vector_file, vector_layer, vector_feature, width=4000, height=4000, pixel_size_x=0.00025, pixel_size_y=-0.00025)[source]¶ Return a mask for the given cell based on the specified feature in the vector file
Parameters: - x (int) – X cell index
- y (int) – X cell
- vector_file (str) – Vector file containing the mask polygon
- vector_layer (str) – Layer name within the vector file
- vector_feature (int) – Feature id (index starts at 0) within the layer
- width (int) – Width of the mask
- height (int) – Height of the mask
- pixel_size_x (float) – X pixel size
- pixel_size_y (float) – Y pixel size
Returns: The mask
Return type: numpy.ma.MaskedArray.mask (array of boolean)
-
datacube.api.utils.get_dataset_data_stack(tiles, dataset_type, band_name, x=0, y=0, x_size=None, y_size=None, ndv=None, mask_pqa_apply=False, mask_pqa_mask=None)[source]¶
-
datacube.api.utils.raster_create(path, data, transform, projection, no_data_value, data_type, options=['INTERLEAVE=PIXEL'], width=None, height=None, dataset_metadata=None, band_ids=None)[source]¶
-
datacube.api.utils.raster_create_geotiff(path, data, transform, projection, no_data_value, data_type, options=['INTERLEAVE=PIXEL'], width=None, height=None, dataset_metadata=None, band_ids=None)[source]¶ Create a raster from a list of numpy arrays
Parameters: - path – path to the output raster
- data – list of numpy arrays
- transform – geo transform
- projection – projection
- no_data_value – no data value
- data_type – data type
- options – raster creation options
-
datacube.api.utils.raster_create_envi(path, data, transform, projection, no_data_value, data_type, options=['INTERLEAVE=BSQ'], width=None, height=None, dataset_metadata=None, band_ids=None)[source]¶ Create a raster from a list of numpy arrays
Parameters: - path – path to the output raster
- data – list of numpy arrays
- transform – geo transform
- projection – projection
- no_data_value – no data value
- data_type – data type
- options – raster creation options
-
datacube.api.utils.calculate_ndvi(red, nir, input_ndv=-999, output_ndv=-999)[source]¶ Calculate the Normalised Difference Vegetation Index (NDVI) from a Landsat dataset
NDVI is defined as (NIR - RED) / (NIR + RED)
-
datacube.api.utils.calculate_evi(red, blue, nir, l=1, c1=6, c2=7.5, input_ndv=-999, output_ndv=-999)[source]¶ Calculate the Enhanced Vegetation Index (EVI) from a Landsat dataset first applying Pixel Quality indicators
EVI is defined as 2.5 * (NIR - RED) / (NIR + C1 * RED - C2 * BLUE + L)
Defaults to the standard MODIS EVI of L=1 C1=6 C2=7.5
-
datacube.api.utils.calculate_nbr(nir, swir, input_ndv=-999, output_ndv=-999)[source]¶ Calculate the Normalised Burn Ratio (NBR) from a Landsat dataset
NBR is defined as (NIR - SWIR 2) / (NIR + SWIR 2)
-
datacube.api.utils.calculate_tassel_cap_index(bands, coefficients, input_ndv=-999, output_ndv=nan)[source]¶ Parameters: - bands –
- coefficients –
- input_ndv –
- output_ndv –
Returns:
-
datacube.api.utils.latlon_to_xy(lat, lon, transform)[source]¶ Convert lat/lon to x/y for raster NOTE: No projection done - assumes raster has native lat/lon projection
Parameters: - lat – latitude
- lon – longitude
- transform – GDAL GeoTransform
Returns: x, y pair
-
datacube.api.utils.latlon_to_cell(lat, lon)[source]¶ Return the cell that contains the given lat/lon pair
- NOTE: x of cell represents min (contained) lon value but y of cell represents max (not contained) lat value
- that is, 120/-20 contains lon values 120->120.99999 but lat values -19->-19.99999 that is, that is, 120/-20 does NOT contain lat value of -20
Parameters: - lat – latitude
- lon – longitude
Returns: cell as x, y pair
-
datacube.api.utils.get_dataset_filename(dataset, output_format=<OutputFormat.GEOTIFF: 'GTiff'>, mask_pqa_apply=False, mask_wofs_apply=False, mask_vector_apply=False)[source]¶
-
datacube.api.utils.get_dataset_band_stack_filename(dataset, band, output_format=<OutputFormat.GEOTIFF: 'GTiff'>, mask_pqa_apply=False, mask_wofs_apply=False, mask_vector_apply=False)[source]¶
-
datacube.api.utils.extract_feature_geometry_wkb(vector_file, vector_layer=0, vector_feature=0, epsg=4326)[source]¶
-
datacube.api.utils.calculate_stack_statistic_count(stack, ndv=-999, dtype=<type 'numpy.int16'>)[source]¶
-
datacube.api.utils.calculate_stack_statistic_count_observed(stack, ndv=-999, dtype=<type 'numpy.int16'>)[source]¶
-
datacube.api.utils.calculate_stack_statistic_min(stack, ndv=-999, dtype=<type 'numpy.int16'>)[source]¶
-
datacube.api.utils.calculate_stack_statistic_max(stack, ndv=-999, dtype=<type 'numpy.int16'>)[source]¶
-
datacube.api.utils.calculate_stack_statistic_mean(stack, ndv=-999, dtype=<type 'numpy.int16'>)[source]¶
-
datacube.api.utils.calculate_stack_statistic_percentile(stack, percentile, interpolation=<PercentileInterpolation.NEAREST: 'nearest'>, ndv=-999, dtype=<type 'numpy.int16'>)[source]¶