Risk Assessment API¶
Toolkit for hazard modeling, agent effects, and protection policy evaluation.
RiskToolkit¶
hera.riskassessment.riskToolkit.RiskToolkit
¶
Bases: abstractToolkit
Toolkit for agent-based risk assessment.
Manages hazardous agents (chemical, thermal, blast), their injury effect models, protection policies, and casualty estimation. Agents are stored as versioned data sources and can be loaded from JSON descriptors or from the database.
Source code in hera/riskassessment/riskToolkit.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
analysis
property
¶
Access the risk analysis layer.
Returns:
| Type | Description |
|---|---|
analysis
|
Object providing risk area calculation and LSM integration. |
ProtectionPolicy
property
¶
Access the ProtectionPolicy class for building protection action pipelines.
Returns:
| Type | Description |
|---|---|
type
|
The ProtectionPolicy class (not an instance). |
presentation
property
¶
Access the presentation layer for casualty visualizations.
Returns:
| Type | Description |
|---|---|
casualtiesPlot
|
|
__init__(projectName, filesDirectory=None, connectionName=None)
¶
Initialize the RiskToolkit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
projectName
|
str
|
The project name. |
required |
filesDirectory
|
str
|
Directory for file outputs. |
None
|
connectionName
|
str
|
The DB connection name. |
None
|
Source code in hera/riskassessment/riskToolkit.py
getAgent(nameOrDesc, version=None)
¶
Initialize the agents.
:param nameOrDesc: str or JSON. Can be either the name of the agent (str) or the descriptor
{
"name" : [the name of the agent],
"effectParameters" : {
TenBergeCoefficient and ect.
},
"effects": {
"effect name" : { effect data (+ injury levels) }
}
}
:param projectName: str The name of the project in the local DB that will be searched for the agent. :return:
Source code in hera/riskassessment/riskToolkit.py
listAgentsNames()
¶
Lists the agents that are currently loaded in the DB (both local and public).
:return: list A list of agent names.
Source code in hera/riskassessment/riskToolkit.py
loadAgent(name, agentDescription, version, saveMode=TOOLKIT_SAVEMODE_FILEANDDB)
¶
Adds the agent to the DB. Either to the public or to the local DB.
Equivalent to loadData
:param name: str Agent name :param agentDescription: dict The agent description
:return: None
Source code in hera/riskassessment/riskToolkit.py
loadData(fileNameOrData, saveMode=TOOLKIT_SAVEMODE_FILEANDDB, **kwargs)
¶
Abstract loading a data from file. Manages the parsing of the
datafile.
Equivalent to loadData
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fileNameOrData
|
|
required | |
parser
|
|
required |
Source code in hera/riskassessment/riskToolkit.py
Agent¶
hera.riskassessment.agents.Agents.Agent
¶
Represents a hazardous agent with its associated injury effect models.
An agent is initialized from a JSON descriptor that defines its name,
effect parameters (e.g. Ten Berge coefficient), and one or more injury
effects (e.g. inhalation, thermal). Each effect is accessible by name
via dictionary-style access (agent["inhalation"]).
Source code in hera/riskassessment/agents/Agents.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | |
effectNames
property
¶
List of effect names defined for this agent.
Returns:
| Type | Description |
|---|---|
list of str
|
|
physicalproperties
property
¶
Physical properties of the agent (molecular weight, density, vapor pressure, etc.).
Returns:
| Type | Description |
|---|---|
PhysicalPropeties
|
|
fullDescription
property
¶
The full JSON descriptor used to initialize this agent.
Returns:
| Type | Description |
|---|---|
dict
|
|
effectproperties
property
¶
The effect parameters dictionary (e.g. tenbergeCoefficient).
Returns:
| Type | Description |
|---|---|
dict
|
|
tenbergeCoefficient
property
writable
¶
The Ten Berge coefficient for dose-response calculations.
Returns:
| Type | Description |
|---|---|
float
|
|
name
property
¶
The name of the agent.
Returns:
| Type | Description |
|---|---|
str
|
|
__getitem__(name)
¶
Access an effect by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
|
required |
Returns:
| Type | Description |
|---|---|
Injury
|
The injury effect object. |
__init__(descriptor)
¶
Constructor of the Agent project.
Initializes an agent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
descriptor
|
|
required |
Source code in hera/riskassessment/agents/Agents.py
toJSON()
¶
Serialize the agent to a JSON-compatible dictionary.
Returns:
| Type | Description |
|---|---|
dict
|
|
Source code in hera/riskassessment/agents/Agents.py
ProtectionPolicy¶
hera.riskassessment.protectionpolicy.ProtectionPolicy.ProtectionPolicy
¶
Bases: object
Calculates the expected concentration of the defined protection policy. The policy should include: - indoor time. - masking. - evacuation.
So a policy is a list of actions that take place: each action modifies the concentration field and is defined by a begining and end. The end can be infite (=None), like in evacuation.
The object should support chaining of actions:
ProtectionPolicy.indoor(alpha=0.2,begin=0,end=10).masking(factor=1000,begin=0,end=1000).compute(C,concentrationField="C") .masking(distribution="beta",mean=1000,sigma=10,begin=0,end=1000,bins=100).compute(C,concentrationField="C")
This will create attributes with the details of the execution pipeline. in each attribute we will have: actionID (sequential number) => { "params" : { paramname => value } "outputfields" : ["field"] }
outputfields is used for the subsequent protection (if there is multiple output).
Currently, only a single indoor time is defined (without exit time)
In the future, we should calculate the concentrations field for each action imposed on the concentrations of the previous one (i.e add a field).
Source code in hera/riskassessment/protectionpolicy/ProtectionPolicy.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | |
params
property
¶
dict The parameters associated with this protection policy.
finalname
property
¶
str The name of the final concentration field in the dataset after all protection actions have been applied.
xname
property
¶
str The name of the x-coordinate dimension in the dataset.
yname
property
¶
str The name of the y-coordinate dimension in the dataset.
datetimename
property
¶
str The name of the datetime dimension in the dataset.
data
property
¶
xarray.Dataset or None
The concentration dataset produced after calling compute.
None before computation.
hdfkey
property
¶
Combined HDF key for all actions in this policy.
Returns:
| Type | Description |
|---|---|
str
|
|
__init__(actionList=[], x='x', y='y', datetime='datetime')
¶
A basic action list.
[ { name: "indoor|masking|evacuation", params: { action params } } ]
Source code in hera/riskassessment/protectionpolicy/ProtectionPolicy.py
addActions(jsonStrOrFile)
¶
add actions from a file.
The actions are under the "actions" key.
Source code in hera/riskassessment/protectionpolicy/ProtectionPolicy.py
addAction(name, params)
¶
Adds json with the params
indoor(**kwargs)
¶
Adds an indoor protection to the list of actions.
Must supply alpha or turnover. If indoor is restricted by time, then must supply (begin,end) or (enter,stay).
:params: kwargs:
- alpha (1/[time]) - room alpha = 1/[turn over rate].
- turnover ([time]) - room turn over rate.
- begin - the time in which the population enters indoor
- end - the time in which the population leaves indoor.
- enter - timedelta str after the begining of the simulation that the population enters indoor
- stay - timedelta str for staying indoor.
Source code in hera/riskassessment/protectionpolicy/ProtectionPolicy.py
masks(**kwargs)
¶
Adds a masking protection.
:params: kwargs:
- protectionFactor - The protectionFactor of the masks.
- begin - the time in which the population enters indoor.
- end - the time in which the population leaves indoor.
- enter - timedelta str after the begining of the simulation that the population enters indoor.
- stay - timedelta str for staying indoor.
Source code in hera/riskassessment/protectionpolicy/ProtectionPolicy.py
compute(data, C='C')
¶
Executes the pipeline.