Skip to content

Commit

Permalink
add cascading hazards
Browse files Browse the repository at this point in the history
  • Loading branch information
dvalters authored Jun 28, 2024
1 parent c9f1aaa commit 6c9a15f
Showing 1 changed file with 126 additions and 0 deletions.
126 changes: 126 additions & 0 deletions notebooks/Cascading_hazards.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 8,
"id": "f103681d",
"metadata": {},
"outputs": [],
"source": [
"# Cascading hazards experiment\n",
"\n",
"\n",
"class Hazard():\n",
" \n",
" def __init__(self, wf=0.0):\n",
" self.weighting_factor = wf\n",
" \n",
" def set_weighting_factor(self, wt):\n",
" self.weighting_factor = wt\n",
"\n",
"\n",
"class EarthquakeHazard(Hazard):\n",
" pass\n",
" \n",
"class LandslideHazard(Hazard):\n",
" pass\n",
"\n",
"class FloodHazard(Hazard):\n",
" pass\n",
"\n",
"\n",
"class CascadingHazard(Hazard):\n",
" def __init__(self, hazard1, hazard2):\n",
" self.hazard1 = hazard1 #v1\n",
" self.hazard2 = hazard2 #v2\n",
" #self.hazard3 = 0.2\n",
" \n",
" self.cascaded_haz_name = \"Unset\"\n",
" \n",
" self.weighting_factor = self.combine_hazard()\n",
" \n",
" \n",
" \n",
" # For 2 hazards, use v1 + (1 - v1) *v2 (or use full formula, but set v3=0)\n",
" \n",
" # For 3 hazards, v1 + (1 - v1)*v2 + (1 - v1 - (1 - v1)*v2)*v3\n",
" \n",
" def combine_hazard(self):\n",
" cwf = self.hazard1.weighting_factor + (1 - self.hazard1.weighting_factor) * \\\n",
" self.hazard2.weighting_factor + (1 - self.hazard1.weighting_factor - (1 - self.hazard1.weighting_factor) * \\\n",
" self.hazard2.weighting_factor) * 0.0 #v3\n",
" \n",
" return cwf\n",
"\n",
"\n",
"eq = EarthquakeHazard(wf=1)\n",
"\n",
"flood = FloodHazard(wf=0)\n",
"\n",
"eq_flood_casc = CascadingHazard(eq, flood)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "8f797167",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1\n",
"0\n"
]
},
{
"data": {
"text/plain": [
"1.0"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"\n",
"print(eq.weighting_factor)\n",
"print(flood.weighting_factor)\n",
"\n",
"eq_flood_casc.weighting_factor\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8e9f9e23",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.12"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

0 comments on commit 6c9a15f

Please sign in to comment.