afwizard package
afwizard.apps module
- class afwizard.apps.ObjectProxy
Bases:
ObjectProxy
- class afwizard.apps.PipelineWidgetState(pipeline, rasterization, visualization, classification, image)
Bases:
tupleCreate new instance of PipelineWidgetState(pipeline, rasterization, visualization, classification, image)
- classification
Alias for field number 3
- image
Alias for field number 4
- pipeline
Alias for field number 0
- rasterization
Alias for field number 1
- visualization
Alias for field number 2
- afwizard.apps.apply_restriction(dataset, segmentation=None, segmentation_overlay=None)
The Jupyter UI to create a segmentation object from scratch.
The use of this UI will soon be described in detail.
- afwizard.apps.as_pdal(dataset)
Transform a dataset or digital surface model into a PDAL dataset
- afwizard.apps.assign_pipeline(dataset, segmentation, pipelines)
Load a segmentation object with one or more multipolygons and a list of pipelines. Each multipolygon can be assigned to one pipeline.
- Parameters:
segmentation – This segmentation object needs to have one multipolygon for every type of ground class (dense forrest, steep hill, etc..).
pipelines – All pipelines that one wants to link with the given segmentations.
- Type:
- Type:
list of afwizard.filter.Pipeline
- Returns:
A segmentation object with added pipeline information
- Return type:
- afwizard.apps.cached_pipeline_application(dataset, pipeline, **config)
Call filter pipelinex execution in a cached way
- afwizard.apps.classification_widget(datasets, selected=None)
Create a widget to select classification values
The shown classification values are taken from the datasets themselves and the total amount of points for each class is shown in the widget. The widget then allows to select an arbitrary number of classes. By default, all classes are selected, unless ground points are present in the datasets in which case only these are selected.
- Parameters:
datasets (list) – A list of datasets.
selected (list) – An optional list of pre-selected indices.
- afwizard.apps.create_variability(batchdata, samples_for_continuous=5, non_persist_only=True)
Create combinatorical product of specified variants
- Parameters:
batchdata (list) – The variability data provided by the filter data model.
samples_for_continuous (int) – The number of samples to use when resolving ranges of floating point values (defaults to 5)
non_persist_only (bool) – Whether or not the creation of variability is restricted to entries with persist=False. The persist field is used to distinguish batch processing from end user configuration.
- afwizard.apps.execute_interactive(dataset, pipeline)
Interactively apply a filter pipeline to a given dataset in Jupyter
This allows you to interactively explore the effects of end user configuration values specified by the filtering pipeline.
- Parameters:
dataset (afwizard.DataSet) – The dataset to work on
pipeline – The pipeline to execute.
- Returns:
The pipeline with the end user configuration baked in
- Return type:
- afwizard.apps.expand_variability_string(varlist, type_='string', samples_for_continuous=5)
Split a string into variants allowing comma separation and ranges with a colon
- Parameters:
varlist (str) – The input string to expand
type (str) – The type of the variables to return. Maybe string, integer or number.
samples_for_continuous (int) – The number of samples to use when resolving ranges of floating point values (defaults to 5)
- afwizard.apps.hourglass_icon(button)
Context manager to temporarily show an hourglass icon on a button
- Parameters:
button (ipywidgets.Button) – The button
- afwizard.apps.pipeline_tuning(datasets=[], pipeline=None)
The Jupyter UI to create a filtering pipeline from scratch.
The use of this UI is described in detail in the notebook on creating filter pipelines.
- Parameters:
datasets (list) – One or more instances of Lidar datasets to work on
pipeline (afwizard.filter.Pipeline) – A pipeline to use as a starting point. If omitted, a new pipeline object will be created.
- Returns:
Returns the created pipeline object
- Return type:
- afwizard.apps.return_proxy(creator, widgets)
A transparent proxy that can be returned from Jupyter UIs
The created proxy object solves the general problem of needing to non-blockingly return from functions that display UI controls as a side effect. The returned object is updated whenever the widget state changes so that the return object would change. The proxy uses the
wraptlibrary to be as transparent as possible, allowing users to immediately work with the created object.- Parameters:
creator – A callable that accepts no parameters and creates the object that should be returned. This is called whenever the widget state changes.
widgets – A list of widgets whose changes should trigger a recreation of the proxy object.
- afwizard.apps.select_best_pipeline(dataset=None, pipelines=None)
Select the best pipeline for a given dataset.
The use of this UI is described in detail in the notebook on selecting filter pipelines.
- Parameters:
dataset (afwizard.DataSet) – The dataset to use for visualization of ground point filtering results
pipelines (list) – The tentative list of pipelines to try. May e.g. have been selected using the select_pipelines_from_library tool.
- Returns:
The selected pipeline with end user configuration baked in
- Return type:
- afwizard.apps.select_pipeline_from_library(multiple=False)
The Jupyter UI to select filtering pipelines from libraries.
The use of this UI is described in detail in the notebook on filtering libraries.
- Parameters:
multiple (bool) – Whether or not it should be possible to select multiple filter pipelines.
- Returns:
Returns the selected pipeline object(s)
- Return type:
- afwizard.apps.select_pipelines_from_library()
The Jupyter UI to select filtering pipelines from libraries.
The use of this UI is described in detail in the notebook on filtering libraries.
- Returns:
Returns the selected pipeline object(s)
- Return type:
- afwizard.apps.setup_overlay_control(dataset, with_map=False, inlude_draw_controle=True)
This function creates the rasterization control widged for the restrict, assign_pipeline and show_ineractive widgets
- afwizard.apps.show_interactive(dataset, filtering_callback=None, update_classification=False)
The interactive UI to visualize a dataset
- Parameters:
dataset (afwizard.DataSet) – The Lidar dataset to visualize
filtering_callback – A callback that is called to transform the dataset before visualization. This may be used to hook in additional functionality like the execution of a filtering pipeline
update_classification (bool) – Whether or not the classification values shown in the UI need to be updated for each preview. Boils down to the question of whether
filtering_callbackpotentially changes the classification of the dataset.
- afwizard.apps.trivial_tab_titles(tab, template='#{i}')
Adds trivial titles to a tab
- Parameters:
tab (ipywidgets.Tab) – The tab widget to change the titles
template – A format string to use to generated the title. May use the variable i to reference the tab index.
afwizard.asprs module
- afwizard.asprs.asprs(vals)
Map a number of values to ASPRS classification codes
- Parameters:
vals – An arbitrary number of values that somehow describe an ASPRS code. Can be integers which will used directy, can be strings which will be split at commas and then turned into integers
- Returns:
A sorted tuple of integers with ASPRS codes:
- Return type:
tuple
- afwizard.asprs.asprs_class_code(name)
Map ASPRS classification name to code
- afwizard.asprs.asprs_class_name(code)
Map ASPRS classification code to name
afwizard.dataset module
- class afwizard.dataset.DataSet(filename=None, spatial_reference=None)
Bases:
objectThe main class that represents a Lidar data set.
The DataSet class performs lazy loading - instantiating an object of this type does not trigger memory intense operations until you do something with the dataset that requires such operation.
- Parameters:
filename (str) – Filename to load the dataset from. The dataset is expected to be in LAS/LAZ 1.2-1.4 format. If an absolute filename is given, the dataset is loaded from that location. Relative paths are interpreted (in this order) with respect to the directory set with
set_data_directory(), the current working directory, XDG data directories (Unix only) and the Python package installation directory.spatial_reference (str) – A spatial reference as WKT or EPSG code. This will override the reference system found in the metadata and is required if no reference system is present in the metadata of the LAS/LAZ file. If this parameter is not provided, this information is extracted from the metadata.
- classmethod convert(dataset)
Convert this dataset to an instance of DataSet
This is used internally to convert datasets between different representations.
- Returns:
A dataset with transformed datapoints.
- Return type:
- rasterize(resolution=0.5, classification=None)
Create a digital terrain model from the dataset
It is important to note that for archaeologic applications, the mesh is not a traditional DEM/DTM (Digitial Elevation/Terrain Model), but rather a DFM (Digital Feature Model) which consists of ground and all potentially relevant structures like buildings etc. but always excludes vegetation.
- Parameters:
resolution (float) – The mesh resolution in meters. Adapt this depending on the scale of the features you are looking for and the point density of your Lidar data.
classification (tuple) – The classification values to include into the written mesh file.
- restrict(segmentation=None, segmentation_overlay=None)
Restrict the data set to a spatial subset
This is of vital importance when working with large Lidar datasets in AFwizard. The interactive exploration process for filtering pipelines requires a reasonably sized subset to allow fast previews.
- Parameters:
segmentation – A segmentation object that provides the geometric information for the cropping. If omitted, an interactive selection tool is shown in Jupyter.
segmentation_overlay – A segmentation object that will be overlayed on the map for easier use of the restrict app.
- Type:
- Type:
- save(filename, overwrite=False)
Store the dataset as a new LAS/LAZ file
This method writes the Lidar dataset represented by this data structure to an LAS/LAZ file. This includes the classification values which may have been overriden by a filter pipeline.
- Parameters:
filename (str) – Where to store the new LAS/LAZ file. You can either specify an absolute path or a relative path. Relative paths are interpreted w.r.t. the current working directory.
overwrite (bool) – If this parameter is false and the specified filename does already exist, an error is thrown. This is done in order to prevent accidental corruption of valueable data files.
- Returns:
A dataset object wrapping the written file
- Return type:
- show(visualization_type='hillshade', **kwargs)
Visualize the dataset in JupyterLab
Several visualization options can be chosen via the visualization_type parameter. Some of the arguments given below are only available for specific visualization types. To explore the visualization capabilities, you can also use the interactive user interface with
show_interactive().- Parameters:
visualization_type (str) – Which visualization to use. Current implemented values are
hillshadefor a greyscale 2D map,slopemapfor a 2D map color-coded by the slope andblended_hillshade_slopewhich allows to blend the former two into each other.classification (tuple) – Which classification values to include into the visualization. By default, all classes are considered. The best interface to provide this information is using
afwizard.asprs.resolution (float) – The spatial resolution in meters.
azimuth (float) – The angle in the xy plane where the sun is from [0, 360] (
hillshadeandblended_hillshade_slopeonly)angle_altitude – The angle altitude of the sun from [0, 90] (
hillshadeandblended_hillshade_slopeonly)alg (str) – The hillshade algorithm to use. Can be one of
HornandZevenbergenThorne. (hillshadeandblended_hillshade_slopeonly)blending_factor (float) – The blending ratio used between hillshade and slope map from [0, 1]. (
blended_hillshade_slopeonly)
- show_interactive()
Visualize the dataset with interactive visualization controls in Jupyter
- class afwizard.dataset.DigitalSurfaceModel(dataset=None, **rasterization_options)
Bases:
objectRepresentation of a rasterized DEM/DTM/DSM/DFM
Constructs a raster model from a dataset. This is typically used implicitly or through
rasterize().- show(visualization_type='hillshade', **kwargs)
- afwizard.dataset.remove_classification(dataset)
Remove the classification values from a Lidar dataset
Instead, all points will be classified as 1 (unclassified). This is useful to drop an automatic preclassification in order to create an archaelogically relevant classification from scratch.
- Parameters:
dataset (afwizard.Dataset) – The dataset to remove the classification from
- Returns:
A transformed dataset with unclassified points
- Return type:
- afwizard.dataset.reproject_dataset(dataset, out_srs, in_srs=None)
Standalone function to reproject a given dataset with the option of forcing an input reference system
- Parameters:
out_srs (str) – The desired output format in WKT.
in_srs (str) – The input format in WKT from which to convert. The default is the dataset’s current reference system.
- Returns:
A reprojected dataset
- Return type:
afwizard.execute module
- afwizard.execute.apply_adaptive_pipeline(dataset=None, segmentation=None, pipelines=None, output_dir='output', resolution=0.5, compress=False, suffix='filtered')
Python API to apply a fully configured adaptive pipeline
This function implements the large scale application of a spatially adaptive filter pipeline to a potentially huge dataset. This can either be used from Python or through AFwizard’s command line interface.
- Parameters:
datasets (list) – One or more datasets of type ~afwizard.dataset.DataSet.
segmentation (afwizard.segmentation.Segmentation) – The segmentation that provides the geometric information about the spatial segmentation of the dataset and what filter pipelines to apply in which segments.
output_dir (str) – The output directory to place the generated output in. Defaults to a subdirectory ‘output’ within the current working directory/
resolution (float) – The resolution in meters to use when generating GeoTiff files.
compress (bool) – Whether to write LAZ files instead of LAS>
suffix (str) – A suffix to use for files after applying filtering
afwizard.filter module
- class afwizard.filter.Filter(_variability=[], **config)
Bases:
objectThe base class for a filter in AFwizard
A filter can either be constructed from a configuration or be deserialized from a file using the
load_filter()function.- Parameters:
config (dict) – The dictionary of configuration values that conforms to the schema defined by the schema property.
- as_pipeline()
Convert to a filter pipeline with one stage
- property config
The configuration dictionary for this filter
- Type:
pyrsistent.PMap
- copy(**kwargs)
Create a copy of this filter with updated configuration parameters
- Parameters:
kwargs (dict) – A number of key/value pairs that should be changed on the newly created instance of this filter.
- classmethod enabled()
Whether the backend is currently usable
This allows disabling e.g. proprietary backends whenever the necessary proprietary code is not available.
- execute(dataset, **variability_data)
Apply the filter to a given data set
This method needs to be implemented by all filter backends. It is expected to return a new data set instance that contains the filter result and have no side effects on the input data set.
- Parameters:
dataset (afwizard.DataSet) – The data set to apply the filter to.
variability_data – Configuration values for the variation points of this filter.
- Returns:
A modified data set instance with the filter applied.
- execute_interactive(dataset)
Apply the filter in an interactive setting
Using this methods allows you to explore the finetuning capabilities of the filter (if it provides any).
- Parameters:
dataset (afwizard.DataSet) – The data set to apply the filter to.
- Returns:
A filter pipeline copy with the fine tuning configuration baked in.
- classmethod form_schema()
Define the part of the configuration schema that should be exposed to the user
Backend’s inheriting from the
Filterinterface class can use that to implicitly handle some parameters. These would still be part of the schema, but they are automatically added in theexecute()part.
- classmethod schema()
Define the configuration schema for this filter
- Returns:
A nested dictionary data structure that contains the JSON schema for the configuration of this filter. The schema should conform to the Draft 7 JSON Schema standard (https://json-schema.org/).
- Return type:
pyrsistent.PMap
- used_backends()
Return the identifiers of the backends used in this filter
- property variability
Access the filter’s end user configuration variability
- property variability_schema
Create a schema for the variability of this filter
- widget_form()
Create a widget form for this filter
- Returns:
The widget form
- Return type:
- exception afwizard.filter.FilterError
Bases:
AFwizardError
- class afwizard.filter.Pipeline(_variability=[], **kwargs)
Bases:
PipelineMixin,FilterA filter pipeline consisting of several steps
- Parameters:
filters (list) – The filter steps in this pipeline. Each filter is expected to be an instance of
Filter.
- execute(dataset, **variability_data)
Apply the filter to a given data set
This method needs to be implemented by all filter backends. It is expected to return a new data set instance that contains the filter result and have no side effects on the input data set.
- Parameters:
dataset (afwizard.DataSet) – The data set to apply the filter to.
variability_data – Configuration values for the variation points of this filter.
- Returns:
A modified data set instance with the filter applied.
- class afwizard.filter.PipelineMixin(_variability=[], **kwargs)
Bases:
objectA filter pipeline consisting of several steps
- Parameters:
filters (list) – The filter steps in this pipeline. Each filter is expected to be an instance of
Filter.
- as_pipeline()
- property author
The author of this profile
- property description
A description of the usage scenarios for this profile.
- property example_data_url
A link to a data set that this profile excels at filtering.
- classmethod form_schema()
- property keywords
The keywords that describe this filter pipeline
- classmethod schema()
- property title
A telling display name for the filter pipeline
- used_backends()
- afwizard.filter.deserialize_filter(data)
Deserialize a filter.
This relies on
_deserialize()to do the object deserialization, but reads the type information to select the correct filter class to construct.
- afwizard.filter.load_filter(filename)
Load a filter from a file
This function restores filters that were previously saved to disk using the
save_filter()function.- Parameters:
filename (str) – The filename to load the filter from. Relative paths are interpreted w.r.t. the current working directory.
- afwizard.filter.modify_filter_config(config, moddata, variation)
Modify a filter configuration according to variability data
- afwizard.filter.save_filter(filter_, filename)
Save a filter to a file
Filters saved to disk with this function can be reconstructed with the
load_filter()method.- Parameters:
filter (Filter) – The filter object to write to disk
filename – The filename where to write the filter. Relative paths are interpreted w.r.t. the current working directory.
- afwizard.filter.serialize_filter(filter_)
Serialize a given filter.
This relies on
_serialize()to do the object serialization, but adds information about the correct filter type.
- afwizard.filter.update_data(data, modifier)
Update a pyrsistent data structure according to a given modifier
afwizard.lastools module
- class afwizard.lastools.LASToolsFilter(_variability=[], **config)
Bases:
FilterThe base class for a filter in AFwizard
A filter can either be constructed from a configuration or be deserialized from a file using the
load_filter()function.- Parameters:
config (dict) – The dictionary of configuration values that conforms to the schema defined by the schema property.
- classmethod enabled()
Whether the backend is currently usable
This allows disabling e.g. proprietary backends whenever the necessary proprietary code is not available.
- execute(dataset, **variability_data)
Apply the filter to a given data set
This method needs to be implemented by all filter backends. It is expected to return a new data set instance that contains the filter result and have no side effects on the input data set.
- Parameters:
dataset (afwizard.DataSet) – The data set to apply the filter to.
variability_data – Configuration values for the variation points of this filter.
- Returns:
A modified data set instance with the filter applied.
- classmethod schema()
Define the configuration schema for this filter
- Returns:
A nested dictionary data structure that contains the JSON schema for the configuration of this filter. The schema should conform to the Draft 7 JSON Schema standard (https://json-schema.org/).
- Return type:
pyrsistent.PMap
- afwizard.lastools.get_lastools_directory()
Find the LASTools directory specified by the user
- afwizard.lastools.lasground_executable(base=None)
The full path to the lasground executable
- afwizard.lastools.lastools_is_present()
Whether LASTools is present on the system
- afwizard.lastools.set_lastools_directory(dir)
Set custom LASTools installation directory
Use this function at the beginning of your code to point AFwizard to a custom LASTools installation directory. Alternatively, you can use the environment variable
LASTOOLS_DIRto do so.- Parameters:
dir (str) – The LASTools installation directory to use
afwizard.library module
- class afwizard.library.FilterLibrary(name=None, path='', recursive=False)
Bases:
object- property filter_paths
- property filters
- afwizard.library.add_filter_library(path=None, package=None, recursive=False, name=None)
Add a custom filter library to this session
Adaptivefiltering keeps a list of filter libraries that it browses for filter pipeline definitions. This function adds a new directory to that list. You can use this to organize filter files on your hard disk.
- Parameters:
path (str) – The filesystem path where the filter library is located. The filter library is a directory containing a number of filter files and potentially a library.json file containing metadata.
package (str) – Alternatively, you can specify a Python package that is installed on the system and that contains the relevant JSON files. This is used for afwizards library of community-contributed filter pipelines.
recursive (bool) – Whether the file system should be traversed recursively from the given directory to find filter pipeline definitions.
name (str) – A display name to override the name provided by library metadata
- afwizard.library.get_current_filter_library()
Get the user-defined ‘current’ filter library
That filter library is used preferrably for saving filters. It can be set with :ref:~afwizard.set_current_filter_library.
- afwizard.library.get_filter_libraries()
Get a list of all filter libraries currently registered
- afwizard.library.library_keywords(libs=None)
Return a list of keywords used across one or more libraries
- Parameters:
libs – One or more filter libraries
- afwizard.library.locate_filter(filename)
Find a filter with a given filename across all filter libraries
- Parameters:
filename (str) – The filename of the filter without any directories.
- afwizard.library.locate_filter_by_hash(hash)
Locate a filter across the filter libraries given a metadata hash
- Parameters:
hash (str) – The hash that we are looking for.
- afwizard.library.metadata_hash(pipeline)
Calculate a hash value for the filter pipeline metadata
- afwizard.library.reset_filter_libraries()
Reset registered filter libraries to the default ones
The default libraries are the current working directory and the library of community-contributed filter pipelines provided by
afwizard.
- afwizard.library.set_current_filter_library(path, create_dirs=False, name='My filter library')
Set a library path that will be used to store filters in
- Parameters:
path (str) – The path to store filters in. Might be an absolute path or a relative path that will be interpreted with respect to the current working directory.
create_dirs (bool) – Whether afwizard should create this directory (and potentially some parent directories) for you
name (str) – The display name of the library (e.g. in the selection UI)
afwizard.opals module
- class afwizard.opals.OPALSDataManagerObject(filename=None, spatial_reference=None)
Bases:
DataSetThe main class that represents a Lidar data set.
The DataSet class performs lazy loading - instantiating an object of this type does not trigger memory intense operations until you do something with the dataset that requires such operation.
- Parameters:
filename (str) – Filename to load the dataset from. The dataset is expected to be in LAS/LAZ 1.2-1.4 format. If an absolute filename is given, the dataset is loaded from that location. Relative paths are interpreted (in this order) with respect to the directory set with
set_data_directory(), the current working directory, XDG data directories (Unix only) and the Python package installation directory.spatial_reference (str) – A spatial reference as WKT or EPSG code. This will override the reference system found in the metadata and is required if no reference system is present in the metadata of the LAS/LAZ file. If this parameter is not provided, this information is extracted from the metadata.
- classmethod convert(dataset)
Convert this dataset to an instance of DataSet
This is used internally to convert datasets between different representations.
- Returns:
A dataset with transformed datapoints.
- Return type:
- save(filename, compress=False, overwrite=False)
Store the dataset as a new LAS/LAZ file
This method writes the Lidar dataset represented by this data structure to an LAS/LAZ file. This includes the classification values which may have been overriden by a filter pipeline.
- Parameters:
filename (str) – Where to store the new LAS/LAZ file. You can either specify an absolute path or a relative path. Relative paths are interpreted w.r.t. the current working directory.
overwrite (bool) – If this parameter is false and the specified filename does already exist, an error is thrown. This is done in order to prevent accidental corruption of valueable data files.
- Returns:
A dataset object wrapping the written file
- Return type:
- class afwizard.opals.OPALSFilter(_variability=[], **config)
Bases:
FilterThe base class for a filter in AFwizard
A filter can either be constructed from a configuration or be deserialized from a file using the
load_filter()function.- Parameters:
config (dict) – The dictionary of configuration values that conforms to the schema defined by the schema property.
- classmethod enabled()
Whether the backend is currently usable
This allows disabling e.g. proprietary backends whenever the necessary proprietary code is not available.
- execute(dataset, **variability_data)
Execution of an OPALS module
This interfaces with OPALS using its CLI.
- classmethod form_schema()
Define the part of the configuration schema that should be exposed to the user
Backend’s inheriting from the
Filterinterface class can use that to implicitly handle some parameters. These would still be part of the schema, but they are automatically added in theexecute()part.
- classmethod schema()
Define the configuration schema for this filter
- Returns:
A nested dictionary data structure that contains the JSON schema for the configuration of this filter. The schema should conform to the Draft 7 JSON Schema standard (https://json-schema.org/).
- Return type:
pyrsistent.PMap
- afwizard.opals.execute_opals_module(dataset=None, config=None)
Implement execution logic for OPALS modules
- afwizard.opals.get_opals_directory()
Find the OPALS directory specified by the user
- afwizard.opals.get_opals_module_executable(module, base=None)
Find an OPALS executable by inspecting the OPALS installation
- Parameters:
module – The name of the OPALS module that we want to use. Note that this name is case-sensitive and should match the module name from the OPALS documentation.
- afwizard.opals.opals_is_present()
Whether OPALS is present on the system
- afwizard.opals.parse_opals_version(dir)
- afwizard.opals.set_opals_directory(dir)
Set custom OPALS installation directory
Use this function at the beginning of your code to point AFwizard to a custom OPALS installation directory. Alternatively, you can use the environment variable
OPALS_DIRto do so.- Parameters:
dir (str) – The OPALS installation directory to use
afwizard.paths module
- afwizard.paths.check_file_extension(filename, possible_values, default_value)
- afwizard.paths.download_test_file(filename)
Ensure the existence of a dataset file by downloading it
- afwizard.paths.get_temporary_filename(extension='')
Create a filename for a temporary file
Note, the file is not generated, but only a random filename is generated and it is ensured, that its directory is correctly created.
- Parameters:
extension (str) – A file extension that should be appended to the generated filename.
- afwizard.paths.get_temporary_workspace()
Return a temporary directory that persists across the session
This should be used as the working directory of any filter workflows or other operations that might produce spurious file outputs.
- afwizard.paths.load_schema(schema)
Load a schema JSON file by inspecting the Python package installation
- Parameters:
schema (str) – The relative path of the schema in the schema directory.
- Returns:
The schema dictionary
- afwizard.paths.locate_file(filename)
Locate a file on the filesystem
This function abstracts the resolution of paths given by the user. It should be used whenever data is loaded from user-provided locations. The priority list for path resolution is the following:
If the given path is absolute, it is used as is.
If a path was set with
set_data_directorycheck whether the given relative path exists with respect to that directoryCheck whether the given relative path exists with respect to the current working directory
Check whether the given relative path exists with respect to the specified XDG data directory (e.g. through the environment variable
XDG_DATA_DIR) - Linux/MacOS only.Check whether the given relative path exists with respect to the package installation directory. This can be used to write examples that use package-provided data.
- Parameters:
filename (str) – The (relative) filename to resolve
- Raises:
FileNotFoundError – Thrown if all resolution methods fail.
- Returns:
The resolved, absolute filename
- afwizard.paths.set_data_directory(directory, create_dir=False)
Set a custom root directory to locate data files
- Parameters:
directory (str) – The name of the custom data directory.
create_dir – Whether AFwizard should create the directory if it does not already exist.
- afwizard.paths.within_temporary_workspace()
A context manager that changes the current working directory to a temporary workspace
afwizard.pdal module
- class afwizard.pdal.PDALFilter(_variability=[], **config)
Bases:
FilterThe base class for a filter in AFwizard
A filter can either be constructed from a configuration or be deserialized from a file using the
load_filter()function.- Parameters:
config (dict) – The dictionary of configuration values that conforms to the schema defined by the schema property.
- as_pipeline()
Convert to a filter pipeline with one stage
- execute(dataset, **variability_data)
Apply the filter to a given data set
This method needs to be implemented by all filter backends. It is expected to return a new data set instance that contains the filter result and have no side effects on the input data set.
- Parameters:
dataset (afwizard.DataSet) – The data set to apply the filter to.
variability_data – Configuration values for the variation points of this filter.
- Returns:
A modified data set instance with the filter applied.
- classmethod form_schema()
Define the part of the configuration schema that should be exposed to the user
Backend’s inheriting from the
Filterinterface class can use that to implicitly handle some parameters. These would still be part of the schema, but they are automatically added in theexecute()part.
- classmethod schema()
Define the configuration schema for this filter
- Returns:
A nested dictionary data structure that contains the JSON schema for the configuration of this filter. The schema should conform to the Draft 7 JSON Schema standard (https://json-schema.org/).
- Return type:
pyrsistent.PMap
- class afwizard.pdal.PDALInMemoryDataSet(pipeline=None, spatial_reference=None)
Bases:
DataSetAn in-memory implementation of a Lidar data set that can used with PDAL
- Parameters:
pipeline – The numpy representation of the data set. This argument is used by e.g. filters that already have the dataset in memory.
- classmethod convert(dataset)
Covert a dataset to a PDALInMemoryDataSet instance.
This might involve file system based operations.
Warning: if no srs was specified and no comp_spatialreference entry is found in the metadata this function will exit with a Warning.
- Parameters:
dataset – The data set instance to convert.
- property data
- save(filename, overwrite=False)
Store the dataset as a new LAS/LAZ file
This method writes the Lidar dataset represented by this data structure to an LAS/LAZ file. This includes the classification values which may have been overriden by a filter pipeline.
- Parameters:
filename (str) – Where to store the new LAS/LAZ file. You can either specify an absolute path or a relative path. Relative paths are interpreted w.r.t. the current working directory.
overwrite (bool) – If this parameter is false and the specified filename does already exist, an error is thrown. This is done in order to prevent accidental corruption of valueable data files.
- Returns:
A dataset object wrapping the written file
- Return type:
- class afwizard.pdal.PDALPipeline(_variability=[], **kwargs)
Bases:
PipelineMixin,PDALFilterA filter pipeline consisting of several steps
- Parameters:
filters (list) – The filter steps in this pipeline. Each filter is expected to be an instance of
Filter.
- execute(dataset, **variability_data)
Apply the filter to a given data set
This method needs to be implemented by all filter backends. It is expected to return a new data set instance that contains the filter result and have no side effects on the input data set.
- Parameters:
dataset (afwizard.DataSet) – The data set to apply the filter to.
variability_data – Configuration values for the variation points of this filter.
- Returns:
A modified data set instance with the filter applied.
- afwizard.pdal.execute_pdal_pipeline(dataset=None, config=None)
Execute a PDAL pipeline
afwizard.segmentation module
- class afwizard.segmentation.Map(dataset=None, segmentation=None, in_srs=None, inlude_draw_controle=True)
Bases:
objectManage the interactive map use to create segmentations
It can be initilized with a dataset from which it will detect the boundaries and show them on the map. Or it can be initilized with a segmentation which will also be visualized on the map. There can be multiple polygons in the Segmentation and all will drawn. The depending on the segmentation it might be necessary to first swap the coordinates of the segmentation to fit with the ipyleaflet map in_srs can be used to override the current srs.
- Parameters:
dataset (Dataset) – The dataset from which the map should be displayed.
segmentation (Segmentation) – A premade segmentation can can be loaded and shown on a map without the need to load a dataset.
in_srs (str) – manually override the srs of the dataset or segmentation, necessary if none are specified in the object.
- load_geojson(segmentation, name='')
Imports a segmentation objectas an actual layer.
- Parameters:
segmentation (Segmentation) – A segmentation object which is to be loaded.
- load_hexbin_boundary(dataset=None, segmentation=None)
takes the dataset returns the boundary Segmentation. If a segmentation is given, this will convert it into a boundary segmentation.
- load_overlay(vis, title)
Takes a visualisation and loads it into the map.
- load_segmentation(segmentation, override=False)
Imports a segmentation object into the draw control data
- Parameters:
segmentation (Segmentation) – A segmentation object which is to be loaded.
- return_segmentation()
Exports the current polygon list as a Segmentation object
- Returns:
- param segmentation:
All current polygons in one segmentation object
- type segmentation:
Segmentation
- setup_controls()
Modifies the polygon draw control to only include polygons, delete and clear all. Also initilizes the zoom slider, and layer control
- setup_map(boundary_segmentation)
Takes the boundary coordinates of the given dataset through the pdal hexbin filter and returns them as a segmentation. From the segmentation it calculates the center point as well as the edge points to implement the starting location of the map. The edge points are used to draw the boundary square of the given dataset.
- show()
- class afwizard.segmentation.Segmentation(*args, spatial_reference=None, **kwargs)
Bases:
FeatureCollectionInitialises a FeatureCollection object from the :param features: List of features to constitute the FeatureCollection. :type features: list :return: FeatureCollection object :rtype: FeatureCollection
- classmethod load(filename=None, spatial_reference=None)
Load segmentation from a filename
- Parameters:
filename (str) – The filename to load from. Relative paths are interpreted w.r.t. the current working directory.
- save(filename)
Save the segmentation to disk
- Parameters:
filename (str) – The filename to save the segmentation to. Relative paths are interpreted w.r.t. the current working directory.
- show()
Create a new InteractiveMap with bounds from the segmentation.
- afwizard.segmentation.convert_segmentation(segmentation, srs_out, srs_in=None)
- This transforms the segmentation into a new spatial reference system.
For this program all segmentations should be in EPSG:4326. :param segmentation:
The segmentation that should be transformed
- type:
afwizard.segmentation.Segmentation
- param srs_in:
Current spatial reference system of the segmentation. Must be either EPSG or wkt.
- type:
str
- param srs_out:
Desired spatial reference system. Must be either EPSG or wkt. Default: None
- type:
str
- return:
Transformed segmentation.
- rtype:
afwizard.segmentation.Segmentation
- afwizard.segmentation.get_min_max_values(segmentation)
- afwizard.segmentation.load_segmentation(filename, spatial_reference=None)
Load a GeoJSON segmentation from a file
- Parameters:
filename (str) – The filename to load the GeoJSON file from.
spatial_reference – The WKT or EPSG code of the segmentation file.
- afwizard.segmentation.merge_classes(segmentation, keyword=None)
If multiple polygons share the same class attribute they will be combined in one multipolygon feature. Warning, if members of the same class have different metadata it will not be preserved.
- afwizard.segmentation.split_segmentation_classes(segmentation)
If multiple polygons share the same class attribute they will be split into different segmentations. These will be structed in a nested dictionary. Warning, if members of the same class have different metadata it will not be preserved.
- afwizard.segmentation.swap_coordinates(segmentation)
Takes a segmentation and swaps the lon and lat coordinates.
afwizard.utils module
- exception afwizard.utils.AFwizardError
Bases:
Exception
- afwizard.utils.as_number_type(type_, value)
Transform a string to a number according to given type information
- afwizard.utils.check_spatial_reference(crs)
Validate and normalize a given CRS string
We accept either WKT or an EPSG code string of the form
EPSG:xxxx{x}.
- afwizard.utils.is_iterable(object)
Whether the object is an iterable (excluding a string)
- afwizard.utils.stringify_parameters(value)
Stringify a value, making sequence space delimited
afwizard.versioning module
- afwizard.versioning.remove_opals_nightly(config)
Update function (0, 0) -> (0, 1)
The OPALS Nightly backend was a temporary solution to allow usage of the TerrainFilter module. Starting with OPALS v2.5 it is part of main OPALS. We do require that version.
- afwizard.versioning.upgrade_filter(data)
Upgrades a given filter configuration to the current data model version
- afwizard.versioning.upgrade_function(major, minor)
A decorator to use to mark an upgrade function.
Upgrade functions are expected to take a JSON configuration as their only argument and return a modified JSON.
- Parameters:
major – The major version to upgrade from
minor – The minor version to upgrade from
afwizard.visualization module
- afwizard.visualization.blended_hillshade_slope(dataset, blending_factor=0.5, **hillshade_options)
Implemented blended hillshade/slopemap visualization
- afwizard.visualization.gdal_image(dataset, **options)
Create a GDAL visualization of a raster dataset
- afwizard.visualization.gdal_visualization(dataset, **options)
Implement visualization using the GDAL DEM tool
- afwizard.visualization.img_as_widget(img)
Create an image widget from a PIL.Image
- afwizard.visualization.visualization_dispatcher(dataset, visualization_type=None, **options)
Dispatch to visualization implementations based on the visualization_type parameter
afwizard.widgets module
- class afwizard.widgets.BatchDataWidgetForm(*args, nobatch_keys=[], **kwargs)
Bases:
WidgetFormWithLabelsA widget form that wraps additional batch controls around widgets
The additional controls affect all scalar fields (strings, integers, numbers).
- property batchdata
- construct_element(getter=lambda : ..., setter=lambda _: ..., resetter=lambda : ..., widgets=[], subelements=[], batchdata_getter=lambda : ..., batchdata_setter=lambda _: ..., register_observer=lambda h, n, t: ...)
- class afwizard.widgets.BatchDataWidgetFormElement(getter, setter, resetter, widgets, subelements, batchdata_getter, batchdata_setter, register_observer)
Bases:
tupleCreate new instance of BatchDataWidgetFormElement(getter, setter, resetter, widgets, subelements, batchdata_getter, batchdata_setter, register_observer)
- batchdata_getter
Alias for field number 5
- batchdata_setter
Alias for field number 6
- getter
Alias for field number 0
- register_observer
Alias for field number 7
- resetter
Alias for field number 2
- setter
Alias for field number 1
- subelements
Alias for field number 4
- widgets
Alias for field number 3
- class afwizard.widgets.WidgetFormWithLabels(*args, **kwargs)
Bases:
FormA widget form that creates a label selection widget for arrays of strings
All other functionality is inherited from
ipywidgets_jsonschema.Form.