safe.impact_functions.registry module

InaSAFE Disaster risk assessment tool developed by AusAid and World Bank - Impact Function Registry.

Contact : ole.moller.nielsen@gmail.com

Note

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

class safe.impact_functions.registry.Registry[source]

Bases: object

A simple registry for keeping track of all impact functions.

We will use a singleton pattern to ensure that there is only one canonical registry. The registry can be used by impact functions to register themselves and their GUID’s.

To get the impact functions, please do not use directly from this Registry, but rather user ImpactFunctionManager.

classmethod clear()[source]

Remove all registered impact functions in the registry.

classmethod filter(hazard_metadata=None, exposure_metadata=None)[source]

Filter impact function given the hazard and exposure metadata.

Parameters:
  • hazard_metadata (dict) – Dictionary represent hazard keywords
  • exposure_metadata (dict) – Dictionary represent exposure keywords
Returns:

List of impact functions.

Return type:

list

static filter_by_exposure(impact_functions, exposure_keywords)[source]

Filter impact function by exposure_keywords.

Parameters:
  • impact_functions (list) – List of impact functions
  • exposure_keywords (dict) – Dictionary represent exposure keywords
Returns:

List of impact functions.

Return type:

list

static filter_by_hazard(impact_functions, hazard_keywords)[source]

Filter impact function by hazard_keywords.

Parameters:
  • impact_functions (list) – List of impact functions.
  • hazard_keywords (dict) – Dictionary represent hazard keywords.
Returns:

List of impact functions.

Return type:

list

classmethod filter_by_keyword_string(hazard_keywords=None, exposure_keywords=None)[source]

Get available impact functions from hazard and exposure keywords.

Disabled impact function will not be loaded.

Parameters:
  • hazard_keywords (dict) – The keywords of the hazard.
  • exposure_keywords (dict) – The keywords of the exposure.
classmethod filter_by_metadata(metadata_key, metadata_value)[source]

Return IF classes given its metadata key and value.

Parameters:
  • metadata_key (str) – The key of the metadata e.g ‘id’, ‘name’
  • metadata_value (str, dict) – The value of the metadata, e.g for the key ‘id’ the value is ‘FloodNativePolygonExperimentalFunction’
Returns:

impact function classes

Return type:

list

classmethod get_class(name)[source]

Return the class of an impact function given its class name.

Parameters:name (str) – The class name of the IF.
Returns:impact function class
Return type:safe.impact_functions.base.ImpactFunction
classmethod get_instance(name)[source]

Return an instance of impact function given its class name.

Parameters:name (str) – the name of IF class
Returns:impact function instance
Return type:safe.impact_functions.base.ImpactFunction.instance()
impact_functions[source]

Return all registered impact functions.

classmethod list()[source]

List of all registered impact functions by their name.

classmethod register(impact_function)[source]

Register an impact function to the Registry.

Impact Function that will be registered has to have a unique id that is not registered yet.

Parameters:impact_function (ImpactFunction.) – The impact function to register.