“InaSAFE is delivered to you with a number of pre-defined hazards. In this lesson we look at how you go about adding new hazard definitions.”
A large part of InaSAFE functionality is driven by a simple metadata system that defines the available hazard, exposure and other conceptual behaviours. This system is referred to as 'definitions' and is implemented through a collection of simple python files containing dictionaries (tree-like data structures). In this lesson, we will walk through the steps needed to create a new hazard type, and contribute it back to InaSAFE.
Note that although this lesson requires some basic editing of Python source code, it is not necessary to be a skilled software developer in order to add a new hazard to InaSAFE.
In this exercise, we are going to use chemical spills as an example of a new type of hazard we would like to add to InaSAFE. We are going to be changing the source code of InaSAFE but do not be afraid of breaking anything - if it all goes wrong you can simply re-install InaSAFE from the plugin manager. Any changes made to source files should be made using a text editor such as Notepad++ or Sublime Edit.
Goal: To add a new hazard type for chemical spills to InaSAFE
~
refers to your home directory.hazard_generic
in the hazard file and copy the entire block (look for the closing }
which ends the block).hazard_generic
block effectively giving you two identical blocks.hazard_all
block at the bottom of hazard.py
as per the All hazards block specification below.hazard_classification.py
.generic_hazard_classes
and make a copy of it.hazard.py
again and changing your 'classifications': [generic_hazard_classes, chemical_spill_hazard_classes],
Name | Expectation |
---|---|
Working directory |
|
Hazard definitions |
|
Hazard block |
replace hazard_chemical_spill with hazard_chemical_spill |
Hazard block |
replace 'key' value from hazard_generic to hazard_chemical_spill |
Hazard block |
replace 'name' value from 'Generic Hazard' to 'Chemical Spill' |
Hazard block |
replace 'description' value with 'Example chemical spill hazard' |
All hazards block |
Insert a new item 'hazard_chemical_spill' into the list |
Hazard definitions |
Add |
Hazard classification block |
replace all references to 'generic_hazard_classes' with 'chemical_spill_hazard_classes'. |
Hazard classification block |
set the 'name' value to 'Chemical spill classes' |
Hazard classification block |
set the 'description' value to 'A chemical spill example classification' |
Hazard classification block |
set the 'citations' value to 'This example classification is not cited'. |
Hazard classification block |
change key 'high' to key: 'evacuation_zone'. |
Hazard classification block: |
change name 'high' to key 'Evacuation zone'. |
Hazard classification block |
change key 'medium' to key: 'danger_zone'. |
Hazard classification block |
change name 'medium' to key: 'Danger zone'. |
Hazard classification block |
change key 'low' to key: 'use_caution_zone'. |
Hazard classification block |
change name 'high' to key: 'Use caution zone'. |
Types block |
add a new line : chemical_spill_hazard_classes, |
Input layers |
Chemical spill, wards, worldpop_25 |
Analysis question |
In the event of Chemical spill, how many People will be affected? Summarise the results by Wards. |
In the process we followed in the exercise above, we followed simple process of extending the InaSAFE definitions. There are many more tweaks you can make to customise your hazard definition. For example, you can define specific actions for the action list in the report, you can define additional classifications (and they do not need to be limited to 3 classes). When compiling a hazard classification, you should pay special attention to displacement rates and affected properties of each class since they determine the logic that determines how many people will be affected or displaced when the analysis runs.
If you plan to do more serious modifications to the InaSAFE definitions, you make want to consider using a proper Python code editor rather than a simple text editor. Doing that will make it easier to follow the logic of haw hazards are defined.
In the same way that custom hazards can be defined, custom exposures can also be defined - though in our experience this is a less common requirement.
Be careful about updating your InaSAFE plugin if you have made local changes - it will overwrite your work.
We encourage you to contribute any new hazard definitions you create back to the InaSAFE project. If you do this they will automatically be available to any user who installs InaSAFE . It will also ensure that you can upgrade your copy easily and still use your contributed definitions. You will only see your hazard in English only until it is translated - translations will be managed once the code has been contributed to the main InaSAFE project.
The simplest way to share our changes is by making a ticket on GitHub and attaching your changed files.
InaSAFE can be modified easily by editing a few python metadata files:
It is possible to use this approach to also add new exposure types to InaSAFE:
Download the sample data for the lesson.