mapchete.config module

Configuration object required to rund a Mapchete process.

Before running a process, a MapcheteConfig object has to be initialized by either using a Mapchete file or a dictionary holding the process parameters. Upon creation, all parameters are validated and the InputData objects are created which are then exposed to the user process.

An invalid process configuration or an invalid process file cause an Exception when initializing the configuration.

class mapchete.config.MapcheteConfig(input_config, zoom=None, area=None, area_crs=None, bounds=None, bounds_crs=None, mode='continue', **kwargs)

Bases: object

Process configuration.

MapcheteConfig reads and parses a Mapchete configuration, verifies the parameters, creates the necessary metadata required and provides the configuration snapshot for every zoom level.

Parameters
input_configstring or dictionary

a Mapchete configuration file or a configuration dictionary

zoomlist or integer

zoom level or a pair of minimum and maximum zoom level the process is initialized with

boundstuple

left, bottom, right, top boundaries the process is initalized with

modestring
  • memory: Generate process output on demand without reading pre-existing data or writing new data.

  • readonly: Just read data without processing new data.

  • continue: (default) Don’t overwrite existing output.

  • overwrite: Overwrite existing output.

Attributes
modestring

process mode

processstring

absolute path to process file

config_dirstring

path to configuration directory

process_pyramidtilematrix.TilePyramid

TilePyramid used to process data

output_pyramidtilematrix.TilePyramid

TilePyramid used to write output data

inputdictionary

inputs for process

outputOutputData

driver specific output object

zoom_levelslist

process zoom levels

zoomlist or int

subset zoom levels provided in process configuration

boundstuple

override bounds or area provided in process configuration

bounds_crsstr or CRS

CRS of bounds (default: process CRS)

areageometry

override bounds or area provided in process configuration

area_crsstr or CRS

CRS of area (default: process CRS)

baselevelsdictionary

base zoomlevels, where data is processed; zoom levels not included are generated from baselevels

area_at_zoom(zoom=None)

Return process area for zoom level.

The current process area is an intersection of the defined process area from the configuration, the spatial subsets provided by extra arguments (e.g. bounds) and the union of all inputs.

Parameters
zoomint or None

if None, the union of all zoom level areas is returned

Returns
process areashapely geometry
at_zoom(zoom)

Deprecated.

baselevels()

Optional baselevels configuration.

baselevels:

min: <zoom> max: <zoom> lower: <resampling method> higher: <resampling method>

bounds_at_zoom(zoom=None)

Return process bounds for zoom level.

Parameters
zoominteger or list
Returns
process boundstuple

left, bottom, right, top

crs()

Deprecated.

effective_bounds()

Effective process bounds required to initialize inputs.

Process bounds sometimes have to be larger, because all intersecting process tiles have to be covered as well.

get_inputs_for_tile(tile)

Get and open all inputs for given tile.

get_process_func_params(zoom)

Return function kwargs.

init_zoom_levels()

Zoom levels this process is currently initialized with.

This gets triggered by using the zoom kwarg. If not set, it will be equal to self.zoom_levels.

input()

Input items used for process stored in a dictionary.

Keys are the hashes of the input parameters, values the respective InputData classes.

If process mode is readonly or if only overviews are about to be built, no inputs are required and thus not initialized due to performance reasons. However, process bounds which otherwise are dependant on input bounds, may change if not explicitly provided in process configuration.

input_at_zoom(key=None, zoom=None)
inputs()

Deprecated.

metatiling()

Deprecated.

output()

Output writer class of driver.

output_reader()

Output reader class of driver.

params_at_zoom(zoom)

Return configuration parameters snapshot for zoom as dictionary.

Parameters
zoomint

zoom level

Returns
configuration snapshotdictionary
zoom level dependent process configuration
pixelbuffer()

Deprecated.

preprocessing_task_finished(task_key)

Return True if task of given key has already been run.

preprocessing_tasks()

Get mapping of all preprocessing tasks.

preprocessing_tasks_count()

Return number of preprocessing tasks.

preprocessing_tasks_per_input()

Get all preprocessing tasks defined by the input drivers.

process_area(zoom=None)

Deprecated.

process_bounds(zoom=None)

Deprecated.

process_file()

Deprecated.

process_func()

Import process function and make syntax check.

set_preprocessing_task_result(task_key, result)

Append preprocessing task result to input.

zoom_levels()

Process zoom levels as defined in the configuration.

mapchete.config.bounds_from_opts(wkt_geometry=None, point=None, point_crs=None, zoom=None, bounds=None, bounds_crs=None, raw_conf=None)

Return process bounds depending on given inputs.

Parameters
wkt_geometrystring

WKT geometry used to generate bounds.

pointiterable

x and y coordinates of point whose corresponding process tile bounds shall be returned.

point_crsstr or CRS

CRS of point (default: process pyramid CRS)

zoomint

Mandatory zoom level if point is provided.

boundsiterable

Bounding coordinates to be used

bounds_crsstr or CRS

CRS of bounds (default: process pyramid CRS)

raw_confdict

Raw mapchete configuration as dictionary.

Returns
BufferedTilePyramid
mapchete.config.clip_bounds(bounds=None, clip=None)

Clip bounds by clip.

Parameters
boundsbounds to be clipped
clipclip bounds
Returns
Bounds(left, bottom, right, top)
mapchete.config.get_hash(x, length=16)

Return hash of x.

mapchete.config.get_process_func(process=None, config_dir=None, run_compile=False)

Import and return process function.

mapchete.config.get_zoom_levels(process_zoom_levels=None, init_zoom_levels=None)

Validate and return zoom levels.

mapchete.config.initialize_inputs(raw_inputs, config_dir=None, pyramid=None, delimiters=None, readonly=False)
mapchete.config.open_inputs(inputs, tile)
mapchete.config.raw_conf(mapchete_file)

Load a mapchete_file into a dictionary.

Parameters
mapchete_filestr

Path to a Mapchete file.

Returns
dictionary
mapchete.config.raw_conf_output_pyramid(raw_conf)

Load the process pyramid of a raw configuration.

Parameters
raw_confdict

Raw mapchete configuration as dictionary.

Returns
BufferedTilePyramid
mapchete.config.raw_conf_process_pyramid(raw_conf, reset_pixelbuffer=False)

Load the process pyramid of a raw configuration.

Parameters
raw_confdict

Raw mapchete configuration as dictionary.

Returns
BufferedTilePyramid
mapchete.config.snap_bounds(bounds=None, pyramid=None, zoom=None)

Snap bounds to tiles boundaries of specific zoom level.

Parameters
boundsbounds to be snapped
pyramidTilePyramid
zoomint
Returns
Bounds(left, bottom, right, top)