safe.impact_functions.base module

InaSAFE Disaster risk assessment tool developed by AusAid - Impact Function Base Class

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.base.ImpactFunction[source]

Bases: object

Abstract base class for all impact functions.

actual_extent[source]

Property for the actual extent for analysis.

Returns:A list in the form [xmin, ymin, xmax, ymax].
Return type:list
actual_extent_crs[source]

Property for the actual extent crs for analysis.

Returns:A number representing the EPSG code for the CRS. e.g. 4326
Return type:int
aggregation[source]

Property for the aggregation layer to be used for the analysis.

Returns:A map layer.
Return type:SafeLayer
callback[source]

Property for the callback used to relay processing progress.

Returns:A callback function. The callback function will have the following parameter requirements.

progress_callback(current, maximum, message=None)

Return type:function

See also

console_progress_callback

static console_progress_callback(current, maximum, message=None)[source]

Simple console based callback implementation for tests.

Parameters:
  • current (int) – Current progress.
  • maximum (int) – Maximum range (point at which task is complete.
  • message (str, QString) – Optional message to display in the progress bar
exposure[source]

Property for the exposure layer to be used for the analysis.

Returns:A map layer.
Return type:SafeLayer
classmethod function_category()[source]

Property for function category based on hazard categories.

Function category could be ‘single_event’ or/and ‘multiple_event’. Single event data type means that the data is captured by a single observation, while ‘multiple_event’ has been aggregated for some observations.

Returns:The hazard categories that this function supports.
Return type:list
classmethod function_type()[source]

Property for the type of impact function (‘old-style’ or ‘qgis2.0’).

QGIS2 impact functions are using the QGIS api and have more dependencies. Legacy IF’s use only numpy, gdal etc. and can be used in contexts where no QGIS is present.

hazard[source]

Property for the hazard layer to be used for the analysis.

Returns:A map layer.
Return type:SafeLayer
host_name[source]

Property for the host name that runs this.

Returns:The host name.
Return type:basestring
impact[source]

Property for the impact layer generated by the analysis.

Note

It is not guaranteed that all impact functions produce a spatial layer.

Returns:A map layer.
Return type:QgsMapLayer, QgsVectorLayer, QgsRasterLayer
classmethod instance()[source]

Make an instance of the impact function.

classmethod metadata()[source]

Get the metadata class of this impact function.

parameters[source]

Get the parameter.

prepare()[source]

Prepare this impact function for running the analysis.

This method should normally be called in your concrete class’s run method before it attempts to do any real processing. This method will do any needed house keeping such as:

  • checking that the exposure and hazard layers sufficiently

overlap (post 3.1) * clipping or subselecting features from both layers such that

only features / coverage within the actual analysis extent will be analysed (post 3.1)
  • raising errors if any untenable condition exists e.g. extent has no valid CRS. (post 3.1)

We suggest to overload this method in your concrete class implementation so that it includes any impact function specific checks too.

..note: For 3.1, we will still do those preprocessing in analysis
class. We will just need to check if the function_type is ‘qgis2.0’, it needs to have the extent set.

#

question[source]

Formulate the question for this impact function.

This method produces a natural language question for this impact function derived from the following three inputs:

  • descriptive name of the hazard layer e.g. ‘a flood like in

    January 2004’

  • descriptive name of the exposure layer e.g. ‘people’

  • question statement in the impact function metadata e.g.

    ‘will be affected’.

These inputs will be concatenated into a string e.g.:

“In the event of a flood like in January 2004, how many people will be affected.”
requested_extent[source]

Property for the extent of impact function analysis.

Returns:A list in the form [xmin, ymin, xmax, ymax].
Return type:list
requested_extent_crs[source]

Property for the extent CRS of impact function analysis.

Returns:A number representing the EPSG code for the CRS. e.g. 4326
Return type:int
requires_clipping[source]

Check to clip or not to clip layers.

If function type is a ‘qgis2.0’ impact function, then return False – clipping is unnecessary, else return True.

Returns:To clip or not to clip.
Return type:bool
style[source]

Property for the style for the impact layer.

This property is read only.

Returns:A dictionary containing the analysis style. Generally this should be an adjunct to the qml style applied to the impact layer so that other types of style (e.g. SLD) can be generated for the impact layer.
Return type:dict
tabulated_impact[source]

Property for the result (excluding GIS layer) of the analysis.

This property is read only.

Returns:A dictionary containing the analysis results. The format of the dictionary may vary between impact function but the following sections are expected:
  • title: A brief title for the results
  • headings: column headings for the results
  • totals: totals for all rows in the tabulation area
  • tabulation: detailed line items for the tabulation

The returned dictionary is probably best described with a simple example:

Example to follow here....
Return type:dict
target_field[source]

Property for the target_field of the impact layer.

Returns:The target field in the impact layer in case it’s a vector.
Return type:basestring
user[source]

Property for the user who runs this.

Returns:User who runs this
Return type:basestring
validate()[source]

Validate things needed before running the analysis.