mapchete.formats.base module

Main base classes for input and output formats.

When writing a new driver, please inherit from these classes and implement the respective interfaces.

class mapchete.formats.base.InputData(input_params, input_key=None, **kwargs)

Bases: object

Template class handling geographic input data.

Parameters
input_paramsdictionary

driver specific parameters

Attributes
pixelbufferinteger

buffer around output tiles

pyramidtilematrix.TilePyramid

output TilePyramid

crsrasterio.crs.CRS

object describing the process coordinate reference system

METADATA = {'data_type': None, 'driver_name': None, 'mode': 'r'}
add_preprocessing_task(func, fargs=None, fkwargs=None, key=None, geometry=None, bounds=None)

Add longer running preprocessing function to be called right before processing.

Applied correctly this will speed up process initialization and if multiple tasks are required they run in parallel as they are being passed on the Executor.

bbox(out_crs=None)

Return data bounding box.

Parameters
out_crsrasterio.crs.CRS

rasterio CRS object (default: CRS of process pyramid)

Returns
bounding boxgeometry

Shapely geometry object

cleanup()

Optional cleanup function called when Mapchete exits.

exists()

Check if data or file even exists.

Returns
file existsbool
get_preprocessing_task_result(task_key)

Get result of preprocessing task.

open(tile, **kwargs)

Return InputTile object.

Parameters
tileTile
Returns
input tileInputTile

tile view of input data

preprocessing_task_finished(task_key)

Return whether preprocessing task already ran.

set_preprocessing_task_result(task_key, result)

Set result of preprocessing task.

class mapchete.formats.base.InputTile(tile, **kwargs)

Bases: object

Target Tile representation of input data.

Parameters
tileTile
kwargskeyword arguments

driver specific parameters

input_key = None
is_empty()

Check if there is data within this tile.

Returns
is emptybool
preprocessing_tasks_results = {}
read(**kwargs)

Read reprojected & resampled input data.

Returns
dataarray or list

NumPy array for raster data or feature list for vector data

set_preprocessing_task_result(task_key=None, result=None)

Adds a preprocessing task result.

class mapchete.formats.base.OutputDataBaseFunctions(output_params, readonly=False, **kwargs)

Bases: object

extract_subset(input_data_tiles=None, out_tile=None)

Extract subset from multiple tiles. input_data_tiles : list of (Tile, process data) tuples out_tile : Tile Returns ——- NumPy array or list of features.

get_path(tile)

Determine target file path.

Parameters
tileBufferedTile

must be member of output TilePyramid

Returns
pathstring
is_valid_with_config(config)

Check if output format is valid with other process parameters.

Parameters
configdictionary

output configuration parameters

Returns
is_validbool
prepare(**kwargs)
property stac_asset_type

Asset MIME type.

property stac_item_id

Return STAC item ID according to configuration.

Defaults to path basename.

property stac_item_metadata

Custom STAC metadata.

property stac_path

Return path to STAC JSON file.

write_in_parent_process = False
class mapchete.formats.base.OutputDataReader(output_params, readonly=False, **kwargs)

Bases: OutputDataBaseFunctions

empty(process_tile)

Return empty data.

Parameters
process_tileBufferedTile

must be member of process TilePyramid

Returns
empty dataarray or list

empty array with correct data type for raster data or empty list for vector data

for_web(data)

Convert data to web output (raster only).

Parameters
dataarray
Returns
web dataarray
open(tile, process)

Open process output as input for other process.

Parameters
tileTile
processMapcheteProcess
read(output_tile)

Read existing process output.

Parameters
output_tileBufferedTile

must be member of output TilePyramid

Returns
process outputarray or list
class mapchete.formats.base.OutputDataWriter(output_params, readonly=False, **kwargs)

Bases: OutputDataReader

Template class handling process output data.

Parameters
output_paramsdictionary

output parameters from Mapchete file

Attributes
pixelbufferinteger

buffer around output tiles

pyramidtilematrix.TilePyramid

output TilePyramid

crsrasterio.crs.CRS

object describing the process coordinate reference system

METADATA = {'data_type': None, 'driver_name': None, 'mode': 'w'}
close(exc_type=None, exc_value=None, exc_traceback=None)

Gets called if process is closed.

output_cleaned(process_data)

Return verified and cleaned output.

Parameters
process_dataraw process output
Returns
NumPy array or list of features.
output_is_valid(process_data)

Check whether process output is allowed with output driver.

Parameters
process_dataraw process output
Returns
True or False
prepare_path(tile)

Create directory and subdirectory if necessary.

Parameters
tileBufferedTile

must be member of output TilePyramid

streamline_output(process_data)
use_stac = False
write(process_tile, data)

Write data from one or more process tiles.

Parameters
process_tileBufferedTile

must be member of process TilePyramid

class mapchete.formats.base.SingleFileOutputReader(output_params, readonly=False)

Bases: OutputDataReader

tiles_exist(process_tile=None, output_tile=None)

Check whether output tiles of a tile (either process or output) exists.

Parameters
process_tileBufferedTile

must be member of process TilePyramid

output_tileBufferedTile

must be member of output TilePyramid

Returns
existsbool
class mapchete.formats.base.SingleFileOutputWriter(output_params, readonly=False)

Bases: OutputDataWriter, SingleFileOutputReader

class mapchete.formats.base.TileDirectoryOutputReader(output_params, readonly=False)

Bases: OutputDataReader

tiles_exist(process_tile=None, output_tile=None)

Check whether output tiles of a tile (either process or output) exists.

Parameters
process_tileBufferedTile

must be member of process TilePyramid

output_tileBufferedTile

must be member of output TilePyramid

Returns
existsbool
class mapchete.formats.base.TileDirectoryOutputWriter(output_params, readonly=False)

Bases: OutputDataWriter, TileDirectoryOutputReader

mapchete.formats.base.is_feature_list(data)
mapchete.formats.base.is_numpy_or_masked_array(data)
mapchete.formats.base.is_numpy_or_masked_array_with_tags(data)