safe.impact_functions.impact_function_metadata module

InaSAFE Disaster risk assessment tool developed by AusAid - Impact Function Metadata

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.impact_function_metadata.ImpactFunctionMetadata[source]

Bases: object

Abstract metadata class for an impact function.

New in version 2.1.

There will be a concrete implementation of this interface which is specific to a single IF class. So anything returned (e.g. data_types) will only be relevant to the category/subcategories of the concrete implementation’s IF.

Example usage:

foo = IF()
meta = IF.metadata

bar = meta.allowed_subcategories('exposure')
bar
> [structure]

Note

We already know that for an IF only hazard and exposure categories are allowed, so there is no explicit method for that (we could change that later).

classmethod allowed_data_types(subcategory)[source]

Get the list of allowed data types for a subcategory.

Example usage:

foo = IF()
meta = IF.metadata
ubar = meta.allowed_data_types('structure')
ubar
> ['polygon']

In the above example it does not show ‘numeric’ as the request is specific to the structure subcategory for that IF (using the IF declaration at the top of this file as the basis for IF())

Passing a subcategory is required otherwise the context of the data_type(s) would be ambiguous (i.e. whether they can be used as exposure or hazards).

Parameters:subcategory (str) – Required subcategory which will be used to subset the allowed data_types.
Returns:A list of one or more strings is returned.
Return type:list
classmethod allowed_subcategories(category=None)[source]

Get the list of allowed subcategories for a given category.

Parameters:category (str) – Optional category which will be used to subset the allowed subcategories. If omitted, all supported subcategories will be returned (for both hazard and exposure). Default is None.
Returns:A list of strings is returned.
Return type:list
static as_dict()[source]

Return metadata as a dictionary.

This is a static method. You can use it to get the metadata in dictionary format for an impact function. Each concrete implementation of the metadata base class should implement this. Nothing else needs to be overridden from the base class unless you want to modify the default behaviour.

Returns:A dictionary representing all the metadata for the concrete impact function.
Return type:dict
classmethod available_exposure_constraints(exposure_key)[source]

Get exposure constraints for exposure_key.

Parameters:exposure_key (str) – The exposure key
Returns:List of tuple of layer_mode and layer_geometry
Return type:list
classmethod available_exposure_layer_mode(exposure_key, exposure_geometry_key)[source]

Get exposure layer mode for exposure_key.

Parameters:
  • exposure_key (str) – The exposure key
  • exposure_geometry_key (str) – The exposure geometry key
Returns:

A layer mode

Return type:

dict

classmethod available_exposures()[source]

get_available_exposure

Returns:List of available exposure
Return type:list
classmethod available_hazard_constraints(hazard_key, hazard_category_key)[source]

Get hazard constraints for hazard_key and hazard_category_key

Parameters:
  • hazard_key (str) – The hazard key
  • hazard_category_key (str) – The hazard category key
Returns:

List of tuple of layer_mode and layer_geometry

Return type:

list

classmethod available_hazard_layer_mode(hazard_key, hazard_geometry_key, hazard_category_key)[source]

Return all available layer_mode.

Parameters:
  • hazard_key (str) – The hazard key
  • hazard_geometry_key (str) – The hazard geometry key
  • hazard_category_key (str) – The hazard category key
Returns:

A layer mode

Return type:

dict, None

classmethod available_hazards(hazard_category_key)[source]

Get available hazards from hazard_category_key

Parameters:hazard_category_key (str) – The hazard category key
Returns:List of available hazards
Return type:list
classmethod continuous_hazards_units_for_layer(hazard_key, layer_geometry_key, layer_mode_key, hazard_category_key)[source]

Get continuous hazard units. :param hazard_key: The hazard key :type hazard_key: str

Parameters:
  • layer_geometry_key (str) – The layer geometry key
  • layer_mode_key (str) – The layer mode key
  • hazard_category_key (str) – The hazard category key
Returns:

List of continuous hazard unit

Return type:

list

classmethod exposure_additional_keywords(layer_mode_key=None, layer_geometry_key=None, exposure_key=None)[source]

Return additional_keywords for exposure.

Parameters:
  • layer_mode_key (str) – The layer mode key
  • layer_geometry_key (str) – The layer geometry key
  • exposure_key (str) – The hazard key
Returns:

List of additional keywords

Return type:

list

classmethod exposure_class_fields(layer_mode_key=None, layer_geometry_key=None, exposure_key=None)[source]

Return list of exposure class field.

Parameters:
  • layer_mode_key (str) – The layer mode key
  • layer_geometry_key (str) – The layer geometry key
  • exposure_key (str) – The exposure key
Returns:

List of exposure class field.

Return type:

list

classmethod exposure_units_for_layer(exposure_key, layer_geometry_key, layer_mode_key)[source]

Get exposure units.

Parameters:
  • exposure_key (str) – The exposure key
  • layer_geometry_key (str) – The geometry key
  • layer_mode_key (str) – The layer mode key
Returns:

List of exposure unit

Return type:

list

classmethod exposures_for_layer(layer_geometry_key)[source]

Get hazard categories form layer_geometry_key

Parameters:layer_geometry_key (str) – The geometry id
Returns:List of exposure
Return type:list
classmethod get_exposure_requirements()[source]

Get exposure layer requirements.

classmethod get_hazard_requirements()[source]

Get hazard layer requirements.

classmethod get_layer_requirements()[source]

Return layer requirements.

This is a static method. You can use it to get the layer requirements for the impact function.

Returns:A dict that contains layer requirements.
Return type:dict
classmethod get_name()[source]

Return IF name.

Returns:The IF name.
Return type:str
classmethod hazard_additional_keywords(layer_mode_key=None, layer_geometry_key=None, hazard_category_key=None, hazard_key=None)[source]

Return additional_keywords for hazard.

Parameters:
  • layer_mode_key (str) – The layer mode key
  • layer_geometry_key (str) – The layer geometry key
  • hazard_category_key (str) – The hazard category key
  • hazard_key (str) – The hazard key
Returns:

List of additional keywords

Return type:

list

classmethod hazard_categories_for_layer(layer_geometry_key, hazard_key=None)[source]

Get hazard categories form layer_geometry_key

Parameters:layer_geometry_key – The geometry id
Returns:List of hazard_categories
Return type:list
classmethod hazards_for_layer(hazard_geometry_key, hazard_category_key=None)[source]

Get hazard categories form layer_geometry_key

Parameters:
  • hazard_geometry_key (str) – The geometry id
  • hazard_category_key (str) – The hazard category
Returns:

List of hazard

Return type:

list

classmethod is_disabled()[source]

Determine if an impact function is disable.

Usually is used for checking whether an impact function is disabled or not. If there is no disabled keyword in the metadata, return False.

Returns:Return True if the metadata disabled value is True.
Return type:bool
classmethod is_function_for_constraint(hazard_key, exposure_key, hazard_geometry_key=None, exposure_geometry_key=None, hazard_mode_key=None, exposure_mode_key=None)[source]

Check if the constraints match with the function.

Parameters:
  • hazard_key (str) – The hazard key
  • exposure_key (str) – the exposure key
  • hazard_geometry_key (str) – The hazard geometry key
  • exposure_geometry_key (str) – The exposure geometry key
  • hazard_mode_key (str) – The hazard mode key
  • exposure_mode_key (str) – The exposure mode key
Returns:

True if match, else False

Return type:

bool

static is_subset(element, container)[source]

Check the membership of element from container.

It will check based on the type. Only valid for string and list.

Parameters:
  • element (list, str) – Element that will be searched for in container.
  • container (list, str) – Container that will be checked.
Returns:

boolean of the membership

Return type:

bool

classmethod is_valid()[source]

Check whether the metadata is valid or not.

TODO(IS): Add comment explaining how we validate IF Metadata.

Returns:True or False based on the validity of IF Metadata
Return type:bool
static json()[source]

JSON representation of the metadata for this impact function.

This is a static method. You can use it to get the raw json metadata for an impact function. Each concrete implementation of the metadata base class should implement this. Nothing else needs to be overridden from the base class unless you want to modify the default behaviour.

Returns:A json document representing all the metadata for the concrete impact function.
Return type:json
classmethod parameters()[source]

Return list of parameters.

This is a static method. You can use it to get the list of parameters for the impact function.

Returns:A list that contains all parameters.
Return type:list
classmethod purposes_for_layer(layer_geometry_key)[source]

Get purposes of a layer geometry id.

Parameters:layer_geometry_key (str) – The geometry id
Returns:List of purposes
Return type:list
classmethod raster_hazards_classifications_for_layer(hazard_key, layer_geometry_key, layer_mode_key, hazard_category_key)[source]

Get vector_hazards_classifications. :param hazard_key: The hazard key :type hazard_key: str

Parameters:
  • layer_geometry_key (str) – The layer geometry key
  • layer_mode_key (str) – The layer mode key
  • hazard_category_key (str) – The hazard category key
Returns:

List of continuous hazard unit

Return type:

list

static simplify_layer_constraint(layer_constraint)[source]

Simplify layer constraint to layer_type and data_type only.

Parameters:layer_constraint (dict) – Dictionary that represents layer_constraint
Returns:Simple version of layer_constraint
Return type:dict
classmethod valid_layer_keywords()[source]

Return a dictionary for valid layer keywords.

classmethod vector_hazards_classifications_for_layer(hazard_key, layer_geometry_key, layer_mode_key, hazard_category_key)[source]

Get vector_hazards_classifications. :param hazard_key: The hazard key :type hazard_key: str

Parameters:
  • layer_geometry_key (str) – The layer geometry key
  • layer_mode_key (str) – The layer mode key
  • hazard_category_key (str) – The hazard category key
Returns:

List of continuous hazard unit

Return type:

list