API
Configuration
Configuration Classes
Classes
fct.config.Configuration.Configuration
Configuration singleton, which can be read from a .ini file.
Configuration defines:
- datasources
- tilesets
- datasets
- shared parameters: workdir, srid
Attributes
srid
property
readonly
Return SRID
touched
property
readonly
Return list of datasets which have been accessed or created during processing session
vertical_ref
property
readonly
Vertical reference system for elevations
workdir
property
readonly
Return working directory
Methods
auto(self)
Populate configuration from config.ini
defined in FCT_CONFIG
environment variable. Use .env if exists.
axes(self, name)
Returns all axes defined in named dataset
basename(self, name, **kwargs)
Return Dataset filename relative to workdir
configure(self, workspace, datasources, datasets, tilesets)
Populate configuration
dataset(self, name)
Return Dataset by name/key
datasource(self, name)
Return DataSource definition
default(self)
Populate configuration from default config.ini
filename(self, name, **kwargs)
Return Dataset filename instance
from_file(self, filename)
Populate configuration from .ini file
tileset(self, name='default')
Return Tileset definition
fct.config.Configuration.Dataset
Describes an output dataset
Attributes
ext
property
readonly
Return file extension
name
property
readonly
Return dataset's name
Methods
filename(self, **kwargs)
Return filename instance
subdir(self, **kwargs)
Return storage subdirectory
tilename(self, **kwargs)
Return tilename instance
fct.config.Configuration.DataSource
DataSource(name, filename, resolution)
Attributes
filename: None
property
readonly
itemgetter(item, ...) --> itemgetter object
Return a callable object that fetches the given item(s) from its operand. After f = itemgetter(2), the call f(r) returns r[2]. After g = itemgetter(2, 5, 3), the call g(r) returns (r[2], r[5], r[3])
name: None
property
readonly
itemgetter(item, ...) --> itemgetter object
Return a callable object that fetches the given item(s) from its operand. After f = itemgetter(2), the call f(r) returns r[2]. After g = itemgetter(2, 5, 3), the call g(r) returns (r[2], r[5], r[3])
resolution: None
property
readonly
itemgetter(item, ...) --> itemgetter object
Return a callable object that fetches the given item(s) from its operand. After f = itemgetter(2), the call f(r) returns r[2]. After g = itemgetter(2, 5, 3), the call g(r) returns (r[2], r[5], r[3])
Methods
__getnewargs__(self)
special
Return self as a plain tuple. Used by copy and pickle.
__new__(_cls, name, filename, resolution)
special
staticmethod
Create new instance of DataSource(name, filename, resolution)
__repr__(self)
special
Return a nicely formatted representation string
fct.config.Configuration.FileParser
Read configuration components form a .ini file
Methods
datasets(data)
staticmethod
Read YAML dataset definitions and return a dict of datasets
datasource(name, items)
staticmethod
Populate a DataSource object
load_dataset_yaml(configfile)
staticmethod
Read dataset definitions from datasets
directory or from `datasets.yml
parse(configfile)
staticmethod
Main parsing method
tileset(name, items)
staticmethod
Populate a Tileset object
fct.config.Configuration.Tileset
Describes a tileset from a shapefile index
Attributes
bounds
property
readonly
(minx, miny, maxx, maxy) bounds of this tileset
height
property
readonly
Height in pixels of one tile
name
property
readonly
Name of this tileset
tiledir
property
readonly
Tile storage relative to dataset path
tileindex
property
readonly
Index of tiles belonging to this tileset
width
property
readonly
Width in pixels of one tile
Methods
__len__(self)
special
Return number of tiles in tileindex
filename(self, dataset, **kwargs)
Return dataset main file with tileset qualifier
index(self, x, y)
Return tile coordinates of real world point (x, y)
tilename(self, dataset, row, col, **kwargs)
Return full-path filename instance for specific tile
tiles(self)
Generator of tiles
fct.config.Configuration.Workspace
Shared parameters and output dataset definitions
Attributes
srid
property
readonly
Return SRID
srs
property
readonly
Return SRS Identifier
workdir
property
readonly
Return working directory
Methods
copy(self)
Returns a deep copy of this object
set_srs(self, srs)
Set SRS
descriptors
Classes
fct.config.descriptors.DatasetParameter
A file-based dataset declared in datasets.yml
, either tiled or not
fct.config.descriptors.DatasetResolver
Resolves a DatasetParameter according to current configuration.
Attributes
name
property
readonly
Return dataset's key
none
property
readonly
Return True if this parameter should resolve to None
Methods
filename(self, mode='r', tileset='default', **kwargs)
Resolves to this datasource filename. If tileset
is None, returns a global dataset. Otherwise, returns the single-file dataset for the specified tileset, such as a VRT file for tiled datasets.
tilename(self, mode='r', tileset='default', **kwargs)
Resolves to a specific tilename based on kwargs
arguments
fct.config.descriptors.DatasourceParameter
A file-based datasource declared in config.ini
fct.config.descriptors.DatasourceResolver
Resolves a DatasourceParameter according to current configuration.
Attributes
name
property
readonly
Return datasource's key
none
property
readonly
Return True if this parameter should resolve to None
Methods
filename(self)
Resolves to this datasource filename
fct.config.descriptors.LiteralParameter
A simple valued (string or numeric) parameter
fct.config.descriptors.WorkflowContext
A context manager that manages workflow execution: - allows specific execution settings - records execution details.
Methods
after_operation(self, operation, *args, **kwargs)
After-execution hook
before_operation(self, operation, *args, **kwargs)
Before-execution hook
record_execution_time(self, operation, elapsed)
Record execution time for operation name
set_outputdir(self, outputdir)
Set output directory within workspace's working directory
set_tiledir(self, tiledir)
Set default tileset's tile directory
set_tileset(self, tileset)
Set current default tileset
set_workdir(self, workdir)
Set current workspace's working directory
Functions
fct.config.descriptors.pretty_time_delta(delta)
See https://gist.github.com/thatalextaylor/7408395
workflows.decorators
Decorators for building workflows
workflows.decorators.operation(fun)
Decorates a workflow operation
Source code in workflows/decorators.py
def operation(fun):
"""
Decorates a workflow operation
"""
@wraps(fun)
def decorated(ctx, *args, **kwargs):
ctx.before_operation(fun, *args, **kwargs)
fun(*args, **kwargs)
ctx.after_operation(fun, *args, **kwargs)
return decorated
workflows.decorators.parallel(tilefun)
Decorates tilefun
to process tiles in parallel using a Multiprocessing wrapper.
Source code in workflows/decorators.py
def parallel(tilefun):
"""
Decorates `tilefun` to process tiles in parallel
using a Multiprocessing wrapper.
"""
@wraps(tilefun)
def decorated(tileset, *args, processes=1, **kwargs):
"""
Multiprocessing wrapper
See https://stackoverflow.com/questions/8804830/python-multiprocessing-picklingerror-cant-pickle-type-function
"""
def arguments():
for tile in tileset.tiles():
yield [
tilefun,
tile.row,
tile.col,
*args,
kwargs
]
with Pool(processes=processes) as pool:
pooled = pool.imap_unordered(starcall, arguments())
with click.progressbar(pooled, length=len(tileset)) as iterator:
for _ in iterator:
# click.echo('\n\r')
pass
return decorated