eobox.raster.cube

class eobox.raster.cube.EOCube(df_layers, chunksize=32, wdir=None)[source]

Bases: eobox.raster.cube.EOCubeAbstract

apply_and_write(fun, dst_paths, **kwargs)[source]
create_vrt_from_chunks(dst_path)[source]
get_chunk(ji)[source]

Get a EOCubeChunk

class eobox.raster.cube.EOCubeAbstract(df_layers, chunksize=32, wdir=None)[source]

Bases: object

property chunksize
property df_layers
get_chunk_path_from_layer_path(path_layer, ji, mkdir=True)[source]
get_df_ilocs(band, date)[source]

Get positions of rows matching specific band(s) and date(s).

The method supports three typical queries:

  • one band and one date (both given as strings)

  • one band and of several dates (band given as strings, date as list of strings)

  • several band and of one date (date given as strings, band as list of strings)

Parameters
  • band (str or list) – Band(s) for which to derive the iloc index.

  • date (str or list) – Date(s) for which to derive the iloc index.

Returns

Integer (if band and date are str) or list of iloc indices.

Return type

int or list

property n_chunks
property wdir
class eobox.raster.cube.EOCubeChunk(ji, df_layers, chunksize=32, wdir=None)[source]

Bases: eobox.raster.cube.EOCubeAbstract

property chunksize
convert_data_to_dataframe()[source]
convert_data_to_ndarray()[source]

Converts the data from dataframe to ndarray format. Assumption: df-columns are ndarray-layers (3rd dim.)

property data
static from_eocube(eocube, ji)[source]

Create a EOCubeChunk object from an EOCube object.

property ji
plot_raster(idx_layer, robust=False, vmin=None, vmax=None, spatial_bounds=False, figsize=None, ax=None)[source]
plot_raster_rgb(idx_layers, robust=False, vmin=None, vmax=None, spatial_bounds=False, figsize=None, ax=None)[source]
read_data()[source]
static robust_data_range(arr, robust=False, vmin=None, vmax=None)[source]

Get a robust data range, i.e. 2nd and 98th percentile for vmin, vmax parameters.

property spatial_bounds
write_dataframe(result, dst_paths, nodata=None, compress='lzw')[source]

Write results (dataframe) to disc.

write_ndarray(result, dst_paths, nodata=None, compress='lzw')[source]

Write results (ndarray) to disc.

class eobox.raster.cube.EOCubeSceneCollection(df_layers, chunksize, variables, qa, qa_valid, wdir=None)[source]

Bases: eobox.raster.cube.EOCubeSceneCollectionAbstract, eobox.raster.cube.EOCube

Handling scene collections, i.e. a set of scenes each with the same layers.

The class enables to perform chunkwise processing over a set of scenes having the same variables / bands. Therefore the df_layers dataframe requires information to be stored in the following columns:

  • sceneid (unique identifier of the scene),

  • date (the aquisition date of the scene as datetime type),

  • band (the layers / bands that exist for all scenes),

  • uname (unique identifier for all layers, i.e. scene + variable/qu-layer),

  • path (the path where the raster for that layer is located).

Parameters
  • df_layers (dataframe) – A dataframe, see description above.

  • chunksize (int) – Size of the spatial window used as processing unit.

  • variables (list of str) – Those values in df_layers['band'] that are treated as variables.

  • qa (str) – The value in df_layers['band'] which is treated as quality assessment layer.

  • qa_valid (list of int) – The values in the qualitiy assessment layer that identify pixels to be considered as valid in the variable rasters., by default None

  • wdir (str, optional) – Working directory

Raises

ValueError – [description]

apply_and_write_by_variable(fun, dst_paths, dtypes, compress, nodata, **kwargs)[source]
create_statistical_metrics(percentiles, iqr, diffs, dst_pattern, dtypes, compress='lzw', nodata=None, num_workers=1)[source]
create_virtual_time_series(idx_virtual, dst_pattern, dtypes, compress='lzw', nodata=None, num_workers=1)[source]
get_chunk(ji)[source]

Get a EOCubeSceneCollectionChunk

class eobox.raster.cube.EOCubeSceneCollectionAbstract(df_layers, chunksize, variables, qa, qa_valid, wdir=None)[source]

Bases: eobox.raster.cube.EOCubeAbstract

Handling scene collections, i.e. a set of scenes each with the same layers.

The class enables to perform chunkwise processing over a set of scenes having the same variables / bands. Therefore the df_layers dataframe requires information to be stored in the following columns:

  • sceneid (unique identifier of the scene),

  • date (the aquisition date of the scene as datetime type),

  • band (the layers / bands that exist for all scenes),

  • uname (unique identifier for all layers, i.e. scene + variable/qu-layer),

  • path (the path where the raster for that layer is located).

Parameters
  • df_layers (dataframe) – A dataframe, see description above.

  • chunksize (int) – Size of the spatial window used as processing unit.

  • variables (list of str) – Those values in df_layers['band'] that are treated as variables.

  • qa (str) – The value in df_layers['band'] which is treated as quality assessment layer.

  • qa_valid (list of int) – The values in the qualitiy assessment layer that identify pixels to be considered as valid in the variable rasters., by default None

  • wdir (str, optional) – Working directory

Raises

ValueError – [description]

property qa
property qa_valid
property variables
class eobox.raster.cube.EOCubeSceneCollectionChunk(ji, df_layers, chunksize, variables, qa, qa_valid, wdir=None)[source]

Bases: eobox.raster.cube.EOCubeSceneCollectionAbstract, eobox.raster.cube.EOCubeChunk

Handling scene collections, i.e. a set of scenes each with the same layers.

The class enables to perform chunkwise processing over a set of scenes having the same variables / bands. Therefore the df_layers dataframe requires information to be stored in the following columns:

  • sceneid (unique identifier of the scene),

  • date (the aquisition date of the scene as datetime type),

  • band (the layers / bands that exist for all scenes),

  • uname (unique identifier for all layers, i.e. scene + variable/qu-layer),

  • path (the path where the raster for that layer is located).

Parameters
  • df_layers (dataframe) – A dataframe, see description above.

  • chunksize (int) – Size of the spatial window used as processing unit.

  • variables (list of str) – Those values in df_layers['band'] that are treated as variables.

  • qa (str) – The value in df_layers['band'] which is treated as quality assessment layer.

  • qa_valid (list of int) – The values in the qualitiy assessment layer that identify pixels to be considered as valid in the variable rasters., by default None

  • wdir (str, optional) – Working directory

Raises

ValueError – [description]

read_data_by_variable(mask=True)[source]

Reads and masks (if desired) the data and converts it in one dataframe per variable.

eobox.raster.cube.create_names_statistical_metrics(dst_pattern, percentiles=None, iqr=True, diffs=True, variables=None)[source]
eobox.raster.cube.create_names_virtual_time_series(dst_pattern, idx_virtual, variables=None)[source]
eobox.raster.cube.create_statistical_metrics(df_var, percentiles=None, iqr=True, diffs=True, colname_pattern=None, num_workers=1, rename2p=False, verbosity=0)[source]

Calculate statistial metrics from a dataframe with pd.DateTimeIndex and a instance (e.g. pixels) dimension.

Parameters
  • df_var ([type]) – [description]

  • percentiles ([type]) – [description]

  • iqr ([type]) – [description]

  • num_workers (int, optional) – [description], by default 1

  • rename2p (bool, optional) – Rename %-columns (e.g 90%) to p-columns (e.g. p90)

  • verbosity (int, optional) – [description], by default 0

Returns

[description]

Return type

[type]

eobox.raster.cube.create_virtual_time_series(df_var, idx_virtual, colname_pattern=None, num_workers=1, verbosity=0)[source]

Create a virtual time series from a dataframe with pd.DateTimeIndex and a instance (e.g. pixels) dimension.

Parameters
  • df_var ([type]) – [description]

  • idx_virtual ([type]) – [description]

  • colname_pattern (str) – Pattern for the column name, e.g. ‘ls2010_vts2w_{date}_ndvi’, where the data will be inserted from idx_virtual.

  • num_workers (int, optional) – [description], by default 1

  • verbosity (int, optional) – [description], by default 0

Returns

[description]

Return type

[type]

eobox.raster.cube.scoll_df_to_var_dfs(scoll_df, df_layers, qa=None, qa_valid=None, verbose=True)[source]

Convert a dataframe with variable and qa columns into a dictionary with masked variable dataframes.

Parameters
  • scoll_df ([pd.DataFrame]) – dataframe as returned by EOCubeSceneCollectionChunk(…).read_data().convert_data_to_dataframe()

  • df_layers ([pd.DataFrame]) – See EOCubeSceneCollectionAbstract.

  • qa ([str]) – See EOCubeSceneCollectionAbstract.

  • qa_valid ([list]) – See EOCubeSceneCollectionAbstract.

  • verbose ([bool]) –