safe.utilities.analysis module

InaSAFE Disaster risk assessment tool by AusAid -ImpactCalculator.

The module provides a high level interface for running full SAFE analysis.

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.utilities.analysis.Analysis[source]

Bases: object

Class for running full analysis.

aggregation_layer[source]

Property for aggregation layer.

Returns:Aggregation Layer of the analysis.
Return type:QgsMapLayer
analysis_error(exception, message)[source]

A helper to spawn an error and halt processing.

An exception will be logged, busy status removed and a message displayed.

Parameters:
  • message (ErrorMessage, Message) – an ErrorMessage to display
  • exception (Exception) – An exception that was raised
exposure_layer[source]

Property for exposure layer.

Returns:Exposure Layer of the analysis.
Return type:QgsMapLayer
generate_insufficient_overlap_message(e, exposure_geoextent, exposure_layer, hazard_geoextent, hazard_layer, viewport_geoextent)[source]

Generate insufficient overlap message.

Parameters:
  • e – An exception.
  • exposure_geoextent – Extent of the exposure layer.
  • exposure_layer – Exposure layer.
  • hazard_geoextent – Extent of the hazard layer.
  • hazard_layer – Hazard layer instance.
  • viewport_geoextent – Viewport extents.
Returns:

An InaSAFE message object.

get_clip_parameters()[source]

Calculate the best extents to use for the assessment.

Returns:A tuple consisting of:
  • extra_exposure_keywords: dict - any additional keywords that
    should be written to the exposure layer. For example if rescaling is required for a raster, the original resolution can be added to the keywords file.
  • adjusted_geo_extent: list - [xmin, ymin, xmax, ymax] - the best
    extent that can be used given the input datasets and the current viewport extents.
  • cell_size: float - the cell size that is the best of the
    hazard and exposure rasters.
  • exposure_layer: QgsMapLayer - layer representing exposure.
  • geo_extent: list - [xmin, ymin, xmax, ymax] - the unadjusted
    intersection of the two input layers extents and the viewport.
  • hazard_layer: QgsMapLayer - layer representing hazard.
Return type:dict, QgsRectangle, float, QgsMapLayer, QgsRectangle, QgsMapLayer
Raises:InsufficientOverlapError
static get_layer_title(layer, layer_keyword)[source]

Return layer’s title from keywords or layer name if not found.

Parameters:
  • layer (QgsMapLayer) – A valid QgsMapLayer
  • layer_keyword (dict) – A keyword for the layer
Returns:

Layer’s title

Return type:

str

get_optimal_extent(hazard_geo_extent, exposure_geo_extent, viewport_geo_extent=None)[source]

A helper function to determine what the optimal extent is.

Optimal extent should be considered as the intersection between the three inputs. The inasafe library will perform various checks to ensure that the extent is tenable, includes data from both etc.

This is a thin wrapper around safe.storage.utilities.bbox_intersection

Typically the result of this function will be used to clip input layers to a common extent before processing.

Parameters:
  • hazard_geo_extent (list) – An array representing the hazard layer extents in the form [xmin, ymin, xmax, ymax]. It is assumed that the coordinates are in EPSG:4326 although currently no checks are made to enforce this.
  • exposure_geo_extent (list) – An array representing the exposure layer extents in the form [xmin, ymin, xmax, ymax]. It is assumed that the coordinates are in EPSG:4326 although currently no checks are made to enforce this.
  • viewport_geo_extent

    (optional) An array representing the viewport extents in the form [xmin, ymin, xmax, ymax]. It is assumed that the coordinates are in EPSG:4326 although currently no checks are made to enforce this.

    ..note:: We do minimal checking as the inasafe library takes care of it for us.

Returns:

An array containing an extent in the form [xmin, ymin, xmax, ymax] e.g.:: [100.03, -1.14, 100.81, -0.73]

Return type:

list

Raises:

Any exceptions raised by the InaSAFE library will be propagated.

hazard_layer[source]

Property for hazard layer.

Returns:Hazard Layer of the analysis.
Return type:QgsMapLayer
impact_layer[source]

Obtain impact layer from the runner.

optimal_clip()[source]

A helper function to perform an optimal clip of the input data. Optimal extent should be considered as the intersection between the three inputs. The InaSAFE library will perform various checks to ensure that the extent is tenable, includes data from both etc.

The result of this function will be two layers which are clipped and re-sampled if needed, and in the EPSG:4326 geographic coordinate reference system.

Returns:The clipped hazard and exposure layers.
Return type:(QgsMapLayer, QgsMapLayer)
run_aggregator()[source]

Run all post processing steps.

run_analysis()[source]

It’s similar with run function in previous dock.py

run_post_processor()[source]

Carry out any postprocessing required for this impact layer.

send_analysis_done_signal()[source]

Send an analysis done signal to the listeners.

send_busy_signal()[source]

Send an busy signal to the listeners.

send_dynamic_message(message)[source]

Send a dynamic message to the listeners.

Dynamic messages represents a progres. Usually it will be appended to the previous messages.

Parameters:message (Message) – An instance of our rich message class.
send_error_message(error_message)[source]

Send an error message to the listeners.

Error messages represents and error. It usually replace the previous message since an error has been happened.

Parameters:error_message (ErrorMessage) – An instance of our rich error message class.
send_not_busy_signal()[source]

Send an busy signal to the listeners.

send_static_message(message)[source]

Send a static message to the listeners.

Static messages represents a whole new message. Usually it will replace the previous message.

Parameters:message (Message) – An instance of our rich message class.
setup_aggregator()[source]

Create an aggregator for this analysis run.

setup_analysis()[source]

Setup analysis so that it will be ready for running.

setup_impact_function()[source]

Setup impact function.

tr(string)[source]

We implement this since we do not inherit QObject.

Parameters:string (str) – String for translation.
Returns:Translated version of string.
Return type:str