Sim

class pydynamind.Sim

Pythonic wrapper of the DynaMind Simulation class.

Links two modules using their port names. If modules have only one port also link_modules() can be used.

Parameters:
  • m_source (Module) – source module
  • outport_name (str) – name of the outport
  • m_sink (Module) – sink module
  • inport_name (str) – inport name
add_module(class_name, parameter={}, connect_module=None, parent_group=None, filters={}, module_name='')

Add a new model or group to the simulation the python way.

Parameters:
  • class_name (str) – class name of module. See documentation for available modules
  • parameter (dict) –

    module parameter as dict. {'parameter name': parameter_value}. Following parameter are supported

    • boolean: Boolean
    • int: Integer
    • float: Float and Doubles
    • str: String value
    • vector: String list ['val1', 'val2', '...']
    • dict: String map as dict {'key': 'value'}
  • connect_module (Module) – upstream module that the new module is connected to
  • parent_group (Module) – parent group if the newly created module. If not set the module is added to the root group.
  • filters (dict) – set module filter { 'view_name' : {'attribute': 'attribute filter' ,  'spatial': 'view name'} }
  • module_name (str) – alternative module name. This is useful to later find the module in the simulation
Returns:

created module. If the creation fails, it returns None.

Return type:

Module

clear()

Removes all modules, groups and links from the simulation

execute(dynamind_model, epsg_code, parameter_set)

Execute a dynamind model. The dynamind model is added to the simulation and parameters are set before the simulation is executed

Parameters:
  • dynamind_model (str) – dynamind model as string. See serialise()
  • epsg_code (int) – EPSG code
  • parameter_set (dict) – set of modules parameters for the definition of the dict please see set_modules_parameter()

Returns all links in simulation as vector

Returns:vector of links
Return type:[Link]
get_module(module_id)

Finds and returns a module in simulation. The module_id can be get from map_of_loaded_modules().

Parameters:module_id (str) – unique id of the module
Returns:module
Return type:Module
get_module_by_name(name)

Returns module by name, be careful names are not unique! If the module can not be found an exception will be raised.

Parameters:name (str) – name of the module
Returns:module
Return type:Module
is_busy()

Check if currently a simulation is running

Returns:True if busy, False if not
Return type:Boolean
keep_system_cache(keep_cache)

If the system cache (the simulation database) should not be deleted after the simulation has been executed set the parameter to True

Parameters:keep_cache (boolean) – True or False to keep the system cache

Helper to make linking modules less tedious. Just works if the to connecting modules have just one in and outport (This is the case for most module). Otherwise throws exception

Parameters:
  • m_source (dynamind.Module) – Module
  • m_sink (dynamind.Module) – Module
load_simulation(filename)

Loads DynaMind simulation

Parameters:filename (str) – Name of the .dyn file to load
map_of_loaded_modules()

Returns a map of the modules in the simulation.

Returns:{'module_id' : 'module name',...}
Return type:dict
register_modules(path)

Registers Python or C++ DynaMind modules for the simulation.

Parameters:path (str) – path to module
remove_module(module_name)

Removes a module from the simulation

Parameters:module_name (str) – module name
reset()

Resets the data stream of the simulation.

run()

Runs simulation

serialise()

Serialise simulation

Returns:Returns simulation as xml string
Return type:str
set_epsg_code(epsg_code)

Sets EPGS code of simulation

Parameters:epsg_code – EPSG code as integer
set_module_parameter(module_description=())
Deprecated:0.7

Set model parameter, this method will be removed. Please use set_modules_parameter()

Type:tuple
Parameters:module_description – the module description is a tuple with (module name, parameter list)

the parameter list is a dict that may contain following key word:

  • parameter: {'parameter name': parameter_value,...}
  • filter: { 'view_name' : {'attribute': 'attribute filter' :  spatial: 'view name'} }
set_modules_parameter(model_parameter_dict={})

Sets parameters and filters for a whole bunch of modules stored in a dict. See set_module_parameter() for how to define a module parameter set.

Parameters:model_parameter_dict – dict of modules including module parameter {'module name': module description, ...}
set_working_dir(directory)

Sets working directory, the location where the cahe database is created

Parameters:directory (str) – directory name
write_simulation_file(filename)

Writes simulation to file

Parameters:filename (str) – name of the file

Module

class pydynamind.Module

The DynaMind module class

createParameter(name, DN_type, description='')

Creates a new module parameter. This method is used to add new parameter to the module. This module should only be used in the Constructor of the module. The parameter can be access in the module using self.parameter_name = value. To do this, createParameter() may be called before the parameter is accessed.

Parameters:
  • name (str) – parameter name
  • DN_type (DataTypes) –

    DynaMind attribute. Following attributes are supported:

    • pydynamind.BOOL : Boolean
    • pydynamind.INT : Integer
    • pydynamind.DOUBLE : Float
    • pydynamind.STRING : String
    • pydynamind.FILENAME : File name
  • description (str) – add parameter description
getClassName()

Returns class name. However if called in Python it returns the name the for C++ module. To obtain the real class name please call get_class_name()

Parameters:description (str) – class name
getGDALDBName()

Gets GDAL database name of the current simulation used in this module

Returns:database name
Return type:string
getName()

Gets module name

Returns:Module name
Return type:str
getParameterAsString(module_name)

Gets module parameter as string

Parameters:module_name (str) – parameter name
Returns:parameter value as string
Return type:str
getParameterList()

Returns names of parameters in the module as list

Returns:paramter list
Return type:[str]
get_class_name()

Returns real class name

Returns:class name
Return type:str
get_group_counter()

Returns the parent’s group counter, or -1 if no group is set.

Returns:group counter
Return type:int
init()

This method should be overwritten if the module modifies the data stream definition in response to parameter input or the incoming data stream.

Outside the module, it calls the init method of the module. Usually the Simulation takes care of initialising modules.

registerViewContainers(view_containers)

Registers a list of view containers in the Module. This is used in the Constructor or in init() to register views to be used later in run()

Parameters:view_containers ([ ViewContainer ]) – List of view containers
run()

This method needs to be overwritten when developing a new module

setIsGDALModule(is_gdal_module)

Set to True to activate the GDAL API

Parameters:is_gdal_module (Boolean) – True for GDAL API
setName(name)

Sets module name

Parameters:name (str) – set module name

ViewContainer

class pydynamind.ViewContainer(*args)

Class to access the GIS data. The class utilises heavily the GDAL library. Internally the view container links to a GDAL layer and provides a simple wrapper to read, and create OGRFeatures. The Python/GDAL documentation can be found here

Parameters:
  • name (str) – view name
  • type (pydynamind.TYPE) –

    Defines component type. Following types are supported:

    • pydynamind.COMPONENT
    • pydynamind.NODE
    • pydynamind.EDGE
    • pydynamind.FACE
  • access_geometry

    Defines access to the geometry. Following types are supported:

    • pydynamind.READ
    • pydynamind.MODIFY
    • pydynamind.WRITE
addAttribute(name, attribute_type, access)

Add attribute access to the view container.

Parameters:
  • name (str) – attribute name
  • attribute_type (pydynamind.Attribute.TYPE) –

    Defines the attribute type. Following attributes are supported:

    • pydynamind.Attribute.INT
    • pydynamind.Attribute.DOUBLE
    • pydynamind.Attribute.STRING
    • pydynamind.Attribute.DOUBLEVECTOR
  • access (pydynamind.ACCESS) –

    Defines access to the attribute. Following types are supported:

    • pydynamind.READ
    • pydynamind.MODIFY
    • pydynamind.WRITE
create_feature()

Creates and inserts a new feature into the view. Features created with this function are managed by DynaMind and do not need to be destroyed.

Returns:feature
Return type:OGRFeature
create_index(attribute_name)

Creates a fresh index for an attribute. This speeds up the search within this index dramatically.

Parameters:attribute_name (str) – attribute name on which the index should be created
finalise()

Closes the ViewContainer writing the data to the database and freeing the memory. May be used before the end of the run method.

get_attribute_filter_sql_string(filter)

Returns set attribute filter as sql string (doesn’t include WHERE)

Parameters:name (str) – attribute filter
Returns:sql filter string
Return type:str
get_feature(fid)

Returns feature with id.

Parameters:fid (int) – feature id
Returns:feature
Return type:OGRFeature
get_linked_features(feature, link_id='')

Sets a filter to easy access linked features. May be used in combination with next() For example: for feature in self.view_container.get_linked_features(feature_from_other_view): :type feature: OGRFeature :param feature: OGRFeature linking to this view :return: this ViewContainer set to only return linked features :rtype: ViewContainer

get_ogr_ds()

Returns OGR data source. Only use if really really needed.

Returns:OGR data source
Return type:OGRDataSource
get_ogr_layer()

Returns the OGR layer. Only use if really really needed.

Returns:OGR Layer
Return type:OGRLayer
next()

Iterator to iterate over the features in the ViewContainer under consideration of the set filters. The method my not be directly called but enables easy access to iterate over features using the standard for loop. e.g. for feature in self.view_container:

Before iterating over the all features please call reset_reading().

Returns:next feature
Return type:OGRFeature
reset_reading()

Resets iterator

set_attribute_filter(attribute_filter)

Sets attribute filter. Before setting an attribute filter please call reset(). Filters can be set using OGR SQL a documentation can be found here To speed up the filtering please create an index first with create_index() The Attribute filter may be used in combination with next()

Parameters:attribute_filter (str) – Attribute filter using OGR SQL syntax
sync()

Synchronises the ViewContainer writing the data to the database and freeing the memory.