diff --git a/docs/examples/asset_level_impacts.ipynb b/docs/examples/asset_level_impacts.ipynb index 54ce0c4a..cad273d2 100644 --- a/docs/examples/asset_level_impacts.ipynb +++ b/docs/examples/asset_level_impacts.ipynb @@ -174,19 +174,34 @@ "\n", "fig1 = make_subplots(rows=1, cols=2)\n", "fig1.add_trace(\n", - " go.Scatter(x=exceedance_histo[\"exceed_probabilities\"], y=exceedance_histo[\"values\"], name=\"baseline wind\"),\n", + " go.Scatter(\n", + " x=exceedance_histo[\"exceed_probabilities\"],\n", + " y=exceedance_histo[\"values\"],\n", + " name=\"baseline wind\",\n", + " ),\n", " row=1,\n", " col=1,\n", ")\n", "fig1.add_trace(\n", - " go.Scatter(x=exceedance_ssp585[\"exceed_probabilities\"], y=exceedance_ssp585[\"values\"], name=\"wind SSP585\"),\n", + " go.Scatter(\n", + " x=exceedance_ssp585[\"exceed_probabilities\"],\n", + " y=exceedance_ssp585[\"values\"],\n", + " name=\"wind SSP585\",\n", + " ),\n", " row=1,\n", " col=1,\n", ")\n", "fig1.update_xaxes(\n", - " title=\"Annual exceedance probability\", title_font={\"size\": 14}, row=1, col=1, type=\"log\", autorange=\"reversed\"\n", + " title=\"Annual exceedance probability\",\n", + " title_font={\"size\": 14},\n", + " row=1,\n", + " col=1,\n", + " type=\"log\",\n", + " autorange=\"reversed\",\n", ")\n", - "fig1.update_yaxes(title=\"Damage as fraction of insurable value\", title_font={\"size\": 14}, row=1, col=1)" + "fig1.update_yaxes(\n", + " title=\"Damage as fraction of insurable value\", title_font={\"size\": 14}, row=1, col=1\n", + ")" ] }, { @@ -231,7 +246,9 @@ "asset_measures_dict = {}\n", "for i in asset_measures:\n", " key = i[\"key\"]\n", - " asset_measures_dict[Key(key[\"hazard_type\"], key[\"measure_id\"], key[\"scenario_id\"], key[\"year\"])] = i\n", + " asset_measures_dict[\n", + " Key(key[\"hazard_type\"], key[\"measure_id\"], key[\"scenario_id\"], key[\"year\"])\n", + " ] = i\n", "\n", "wind_impact_scores = asset_measures_dict[Key(\"Wind\", \"measure_set_0\", \"ssp585\", \"2050\")]\n", "\n", @@ -282,7 +299,11 @@ } ], "source": [ - "pp.pprint(response[\"risk_measures\"][\"score_based_measure_set_defn\"][\"score_definitions\"][\"measure_1\"])" + "pp.pprint(\n", + " response[\"risk_measures\"][\"score_based_measure_set_defn\"][\"score_definitions\"][\n", + " \"measure_1\"\n", + " ]\n", + ")" ] }, { diff --git a/docs/examples/hazard_indicators.ipynb b/docs/examples/hazard_indicators.ipynb index 0d283774..dd1e839d 100644 --- a/docs/examples/hazard_indicators.ipynb +++ b/docs/examples/hazard_indicators.ipynb @@ -67,8 +67,30 @@ "request = {\n", " \"items\": [\n", " {\n", - " \"longitudes\": [69.4787, 68.71, 20.1047, 19.8936, 19.6359, 0.5407, 6.9366, 6.935, 13.7319, 13.7319],\n", - " \"latitudes\": [34.556, 35.9416, 39.9116, 41.6796, 42.0137, 35.7835, 36.8789, 36.88, -12.4706, -12.4706],\n", + " \"longitudes\": [\n", + " 69.4787,\n", + " 68.71,\n", + " 20.1047,\n", + " 19.8936,\n", + " 19.6359,\n", + " 0.5407,\n", + " 6.9366,\n", + " 6.935,\n", + " 13.7319,\n", + " 13.7319,\n", + " ],\n", + " \"latitudes\": [\n", + " 34.556,\n", + " 35.9416,\n", + " 39.9116,\n", + " 41.6796,\n", + " 42.0137,\n", + " 35.7835,\n", + " 36.8789,\n", + " 36.88,\n", + " -12.4706,\n", + " -12.4706,\n", + " ],\n", " \"request_item_id\": \"my_flood_request\",\n", " \"hazard_type\": \"RiverineInundation\",\n", " \"indicator_id\": \"flood_depth\",\n", @@ -76,8 +98,30 @@ " \"year\": 1980,\n", " },\n", " {\n", - " \"longitudes\": [69.4787, 68.71, 20.1047, 19.8936, 19.6359, 0.5407, 6.9366, 6.935, 13.7319, 13.7319],\n", - " \"latitudes\": [34.556, 35.9416, 39.9116, 41.6796, 42.0137, 35.7835, 36.8789, 36.88, -12.4706, -12.4706],\n", + " \"longitudes\": [\n", + " 69.4787,\n", + " 68.71,\n", + " 20.1047,\n", + " 19.8936,\n", + " 19.6359,\n", + " 0.5407,\n", + " 6.9366,\n", + " 6.935,\n", + " 13.7319,\n", + " 13.7319,\n", + " ],\n", + " \"latitudes\": [\n", + " 34.556,\n", + " 35.9416,\n", + " 39.9116,\n", + " 41.6796,\n", + " 42.0137,\n", + " 35.7835,\n", + " 36.8789,\n", + " 36.88,\n", + " -12.4706,\n", + " -12.4706,\n", + " ],\n", " \"request_item_id\": \"my_flood_request\",\n", " \"hazard_type\": \"RiverineInundation\",\n", " \"indicator_id\": \"flood_depth\",\n", @@ -172,14 +216,44 @@ ], "source": [ "fig1 = make_subplots(rows=1, cols=2)\n", - "fig1.add_scatter(x=flood_results_baseline[0][\"index_values\"], y=flood_results_baseline[0][\"intensities\"], name=\"baseline flood\", row=1, col=1)\n", - "fig1.add_scatter(x=flood_results_rcp585[0][\"index_values\"], y=flood_results_rcp585[0][\"intensities\"], name=\"flood RCP 8.5 2050\", row=1, col=1)\n", - "fig1.update_xaxes(title=\"Return period (years)\", title_font={\"size\": 14}, row=1, col=1, type=\"log\")\n", + "fig1.add_scatter(\n", + " x=flood_results_baseline[0][\"index_values\"],\n", + " y=flood_results_baseline[0][\"intensities\"],\n", + " name=\"baseline flood\",\n", + " row=1,\n", + " col=1,\n", + ")\n", + "fig1.add_scatter(\n", + " x=flood_results_rcp585[0][\"index_values\"],\n", + " y=flood_results_rcp585[0][\"intensities\"],\n", + " name=\"flood RCP 8.5 2050\",\n", + " row=1,\n", + " col=1,\n", + ")\n", + "fig1.update_xaxes(\n", + " title=\"Return period (years)\", title_font={\"size\": 14}, row=1, col=1, type=\"log\"\n", + ")\n", "fig1.update_yaxes(title=\"Flood depth (m)\", title_font={\"size\": 14}, row=1, col=1)\n", - "fig1.add_scatter(x=wind_results_baseline[0][\"index_values\"], y=wind_results_baseline[0][\"intensities\"], name=\"baseline wind\", row=1, col=2)\n", - "fig1.add_scatter(x=wind_results_ssp585[0][\"index_values\"], y=wind_results_ssp585[0][\"intensities\"], name=\"wind SSP585 2050\", row=1, col=2)\n", - "fig1.update_xaxes(title=\"Return period (years)\", title_font={\"size\": 14}, row=1, col=2, type=\"log\")\n", - "fig1.update_yaxes(title=\"Max (1 minute) wind speed (m/s)\", title_font={\"size\": 14}, row=1, col=2)" + "fig1.add_scatter(\n", + " x=wind_results_baseline[0][\"index_values\"],\n", + " y=wind_results_baseline[0][\"intensities\"],\n", + " name=\"baseline wind\",\n", + " row=1,\n", + " col=2,\n", + ")\n", + "fig1.add_scatter(\n", + " x=wind_results_ssp585[0][\"index_values\"],\n", + " y=wind_results_ssp585[0][\"intensities\"],\n", + " name=\"wind SSP585 2050\",\n", + " row=1,\n", + " col=2,\n", + ")\n", + "fig1.update_xaxes(\n", + " title=\"Return period (years)\", title_font={\"size\": 14}, row=1, col=2, type=\"log\"\n", + ")\n", + "fig1.update_yaxes(\n", + " title=\"Max (1 minute) wind speed (m/s)\", title_font={\"size\": 14}, row=1, col=2\n", + ")" ] }, { @@ -312,11 +386,15 @@ "hazard_types = set(r[\"hazard_type\"] for r in hazard_resources)\n", "print(f\"Hazards: {hazard_types}\")\n", "wind_resources = [r for r in hazard_resources if r[\"hazard_type\"] == \"Wind\"]\n", - "print(f\"{len(hazard_resources)} hazard resources in the inventory, of which {len(wind_resources)} are Wind resources.\")\n", + "print(\n", + " f\"{len(hazard_resources)} hazard resources in the inventory, of which {len(wind_resources)} are Wind resources.\"\n", + ")\n", "iris_model_resource = next(r for r in wind_resources if \"iris\" in r[\"path\"])\n", "# pp.pprint(iris_model_resource[0])\n", "path = iris_model_resource[\"path\"]\n", - "print(f\"The resource 'path' is a unique identifier. For the IRIS Wind resource, for example, this is: '{path}'.\")\n", + "print(\n", + " f\"The resource 'path' is a unique identifier. For the IRIS Wind resource, for example, this is: '{path}'.\"\n", + ")\n", "print(\n", " \"Where resources are multi-dimensional arrays (as opposed to an external API), this is also the path of the array.\"\n", ")\n", @@ -479,11 +557,16 @@ } ], "source": [ - "#from typing import List\n", + "# from typing import List\n", "import pandas as pd\n", - "import json\n", "\n", - "rcp_display_names = {\"rcp2p6\": \"RCP 2.6\", \"rcp4p5\": \"RCP 4.5\" ,\"rcp6p0\": \"RCP 6.0\", \"rcp8p5\": \"RCP 8.5\", }\n", + "rcp_display_names = {\n", + " \"rcp2p6\": \"RCP 2.6\",\n", + " \"rcp4p5\": \"RCP 4.5\",\n", + " \"rcp6p0\": \"RCP 6.0\",\n", + " \"rcp8p5\": \"RCP 8.5\",\n", + "}\n", + "\n", "\n", "def scenario_code(id: str):\n", " if id.startswith(\"ssp\"):\n", @@ -493,19 +576,31 @@ " else:\n", " return id\n", "\n", + "\n", "def format_scenario(scenarios):\n", - " return \", \".join(f\"{scenario_code(scen['id'])} ({', '.join(str(y) for y in scen['years'])})\" for scen in scenarios)\n", + " return \", \".join(\n", + " f\"{scenario_code(scen['id'])} ({', '.join(str(y) for y in scen['years'])})\"\n", + " for scen in scenarios\n", + " )\n", + "\n", "\n", "resource_df = pd.json_normalize(hazard_resources)\n", - "resource_df = resource_df.filter([\"hazard_type\", \"indicator_id\", \"display_name\", \"path\", \"scenarios\"])\n", - "resource_df = resource_df.sort_values(by=[\"hazard_type\", \"indicator_id\", \"display_name\"])\n", + "resource_df = resource_df.filter(\n", + " [\"hazard_type\", \"indicator_id\", \"display_name\", \"path\", \"scenarios\"]\n", + ")\n", + "resource_df = resource_df.sort_values(\n", + " by=[\"hazard_type\", \"indicator_id\", \"display_name\"]\n", + ")\n", "resource_df.scenarios = resource_df.scenarios.apply(lambda s: format_scenario(s))\n", - "resource_df = resource_df.rename(columns={\"hazard_type\": \"Hazard type\",\n", - " \"indicator_id\": \"Indicator ID\",\n", - " \"display_name\": \"Display name\",\n", - " \"path\": \"Path (ID)\",\n", - " \"scenarios\": \"Scenarios\",\n", - " })\n", + "resource_df = resource_df.rename(\n", + " columns={\n", + " \"hazard_type\": \"Hazard type\",\n", + " \"indicator_id\": \"Indicator ID\",\n", + " \"display_name\": \"Display name\",\n", + " \"path\": \"Path (ID)\",\n", + " \"scenarios\": \"Scenarios\",\n", + " }\n", + ")\n", "\n", "md = resource_df.to_markdown(index=False)\n", "display(Markdown(md))" diff --git a/docs/user-guide/vulnerability_config.ipynb b/docs/user-guide/vulnerability_config.ipynb index 5694f3a6..26a2cb71 100644 --- a/docs/user-guide/vulnerability_config.ipynb +++ b/docs/user-guide/vulnerability_config.ipynb @@ -96,14 +96,16 @@ "outputs": [], "source": [ "# pip install nbformat pandas plotly requests\n", - "from dotenv import load_dotenv\n", "from io import StringIO\n", "import plotly.graph_objs as go\n", "import plotly.io\n", "from plotly.subplots import make_subplots\n", "\n", "plotly.io.renderers.default = \"notebook\"\n", - "from physrisk.vulnerability_models.config_based_model import config_items_from_csv, config_items_to_df" + "from physrisk.vulnerability_models.config_based_model import (\n", + " config_items_from_csv,\n", + " config_items_to_df,\n", + ")" ] }, { @@ -354,8 +356,17 @@ } ], "source": [ - "c1 = next(c for c in config_items if c.asset_class == \"RealEstateAsset\" and c.indicator_id==\"flood_depth\")\n", - "c2 = next(c for c in config_items if c.asset_class == \"ManufacturingAsset\" and c.indicator_id==\"days_tas/above/{temp_c}c\")\n", + "c1 = next(\n", + " c\n", + " for c in config_items\n", + " if c.asset_class == \"RealEstateAsset\" and c.indicator_id == \"flood_depth\"\n", + ")\n", + "c2 = next(\n", + " c\n", + " for c in config_items\n", + " if c.asset_class == \"ManufacturingAsset\"\n", + " and c.indicator_id == \"days_tas/above/{temp_c}c\"\n", + ")\n", "\n", "fig1 = make_subplots(rows=1, cols=2)\n", "fig1.add_trace(\n", @@ -368,14 +379,14 @@ " row=1,\n", " col=2,\n", ")\n", - "fig1.update_xaxes(\n", - " title=\"Flood depth (m)\", title_font={\"size\": 14}, row=1, col=1\n", - ")\n", - "fig1.update_xaxes(\n", - " title=\"Threshold (°C)\", title_font={\"size\": 14}, row=1, col=2\n", + "fig1.update_xaxes(title=\"Flood depth (m)\", title_font={\"size\": 14}, row=1, col=1)\n", + "fig1.update_xaxes(title=\"Threshold (°C)\", title_font={\"size\": 14}, row=1, col=2)\n", + "fig1.update_yaxes(\n", + " title=\"Damage as fraction of insurable value\", title_font={\"size\": 14}, row=1, col=1\n", ")\n", - "fig1.update_yaxes(title=\"Damage as fraction of insurable value\", title_font={\"size\": 14}, row=1, col=1)\n", - "fig1.update_yaxes(title=\"Fractional loss of production\", title_font={\"size\": 14}, row=1, col=2)" + "fig1.update_yaxes(\n", + " title=\"Fractional loss of production\", title_font={\"size\": 14}, row=1, col=2\n", + ")" ] } ], diff --git a/docs/user-guide/vulnerability_uncertainty.ipynb b/docs/user-guide/vulnerability_uncertainty.ipynb index f0c370e9..d4032ff5 100644 --- a/docs/user-guide/vulnerability_uncertainty.ipynb +++ b/docs/user-guide/vulnerability_uncertainty.ipynb @@ -44,12 +44,16 @@ "outputs": [], "source": [ "import numpy as np\n", - "from physrisk.vulnerability_models.cdf_based_vuln_function import CDFBasedVulnerabilityFunction\n", + "from physrisk.vulnerability_models.cdf_based_vuln_function import (\n", + " CDFBasedVulnerabilityFunction,\n", + ")\n", "\n", "hazard_indicator = np.array([0.0, 0.5, 1.0, 1.5, 2.0, 3.0, 4.0, 5.0, 6.0])\n", "impact_mean = np.array([0.0, 0.327, 0.494, 0.617, 0.721, 0.870, 0.931, 0.984, 1.0])\n", "impact_stddev = np.array([0.0, 0.12, 0.11, 0.10, 0.10, 0.08, 0.06, 0.02, 0.0])\n", - "vuln = CDFBasedVulnerabilityFunction(hazard_indicator, impact_mean, impact_stddev, kind=\"beta\")" + "vuln = CDFBasedVulnerabilityFunction(\n", + " hazard_indicator, impact_mean, impact_stddev, kind=\"beta\"\n", + ")" ] }, { @@ -105,15 +109,15 @@ 0, 2.589729209353675e-15, 1.1388817155030774e-8, - 0.000006192609493088892, + 6.192609493088892e-6, 0.0020552039513187523, 0.03810194292480483, - 0.20327066722238754, + 0.2032706672223875, 0.5216722166990232, 0.826150316425863, 0.9701775741685098, - 0.9985694197249159, - 0.9999964163769891, + 0.998569419724916, + 0.9999964163769892, 1 ], "y": [ @@ -139,7 +143,7 @@ 0, 1.1983317834278896e-24, 4.365110767870189e-15, - 4.9514458791817323e-11, + 4.951445879181732e-11, 4.366394111604668e-7, 0.00006910488350583003, 0.002012379117477847, @@ -173,11 +177,11 @@ 0, 7.310747150580936e-32, 6.6439418293208274e-21, - 3.4640891275731557e-16, + 3.464089127573155e-16, 1.788931187616554e-11, 1.0124236905159774e-8, 9.01014868562263e-7, - 0.000029034784402930698, + 0.000029034784402930695, 0.000490667328779204, 0.005288534347003648, 0.04070133545319811, @@ -246,10 +250,10 @@ 0.3595751532243283, 0.6279544738630115, 0.8351301543564849, - 0.9512515123455035, - 0.9926146111771639, + 0.9512515123455036, + 0.992614611177164, 0.9996697253240848, - 0.9999992004970235, + 0.9999992004970236, 1 ], "y": [ @@ -1114,10 +1118,12 @@ "\n", "fig = go.Figure()\n", "for i in [0, 2, 4, 6, 8]:\n", - " fig.add_scatter(x=vuln.cdf[i, :], y=vuln.impact, name=f\"Flood depth {hazard_indicator[i]}m\")\n", + " fig.add_scatter(\n", + " x=vuln.cdf[i, :], y=vuln.impact, name=f\"Flood depth {hazard_indicator[i]}m\"\n", + " )\n", "# also interpolate for a depth of 0.6m and display\n", "interp = vuln.interpolate_cdfs(np.array([0.6]))\n", - "fig.add_scatter(x=interp[0, :], y=vuln.impact, name=f\"Interpolated depth 0.6m\")\n", + "fig.add_scatter(x=interp[0, :], y=vuln.impact, name=\"Interpolated depth 0.6m\")\n", "fig.update_xaxes(title=\"Cumulative probability\", title_font={\"size\": 14})\n", "fig.update_yaxes(title=\"Fractional damage\", title_font={\"size\": 14})\n", "fig.show()" @@ -1156,13 +1162,13 @@ 0.09999999999999998, 0.09999999999999998, 0.09999999999999998, - 0.10000000000000009, + 0.10000000000000007, 0.09999999999999998, 0.09999999999999998 ], "x": [ 0.005, - 0.030000000000000002, + 0.03, 0.07500000000000001, 0.15000000000000002, 0.25, @@ -1177,7 +1183,7 @@ "y": [ 2.589729209353675e-15, 1.1388814565301566e-8, - 0.000006181220675933861, + 6.181220675933861e-6, 0.0020490113418256636, 0.03604673897348608, 0.16516872429758273, @@ -1186,7 +1192,7 @@ 0.1440272577426468, 0.02839184555640606, 0.0014269966520732424, - 0.0000035836230108943212 + 3.5836230108943212e-6 ] }, { @@ -1203,13 +1209,13 @@ 0.09999999999999998, 0.09999999999999998, 0.09999999999999998, - 0.10000000000000009, + 0.10000000000000007, 0.09999999999999998, 0.09999999999999998 ], "x": [ 0.005, - 0.030000000000000002, + 0.03, 0.07500000000000001, 0.15000000000000002, 0.25, @@ -1224,14 +1230,14 @@ "y": [ 1.1983317834278896e-24, 4.365110766671857e-15, - 4.951009368104945e-11, - 4.3658989670167496e-7, + 4.9510093681049445e-11, + 4.36589896701675e-7, 0.00006866824409466957, 0.0019432742339720167, - 0.020007629353486982, + 0.020007629353486985, 0.10001550879815133, 0.26977238844177365, - 0.37859113221602275, + 0.3785911322160227, 0.21142484225191327, 0.018176119821174175 ] @@ -1250,13 +1256,13 @@ 0.09999999999999998, 0.09999999999999998, 0.09999999999999998, - 0.10000000000000009, + 0.10000000000000007, 0.09999999999999998, 0.09999999999999998 ], "x": [ 0.005, - 0.030000000000000002, + 0.03, 0.07500000000000001, 0.15000000000000002, 0.25, @@ -1271,11 +1277,11 @@ "y": [ 7.310747150580936e-32, 6.64394182924772e-21, - 3.4640226881548626e-16, + 3.464022688154862e-16, 1.7888965467252782e-11, 1.0106347593283607e-8, 8.908906316571032e-7, - 0.000028133769534368434, + 0.00002813376953436843, 0.00046163254437627335, 0.0047978670182244445, 0.035412801106194464, @@ -2130,8 +2136,13 @@ "impact_bin_width = vuln.impact[1:] - vuln.impact[0:-1]\n", "for i in [2, 4, 6]:\n", " probs = vuln.cdf[i, 1:] - vuln.cdf[i, 0:-1]\n", - " fig.add_bar(x=impact_bin_centres, y=probs, width=impact_bin_width, name=f\"Flood depth {hazard_indicator[i]}m\", \n", - " opacity=0.7)\n", + " fig.add_bar(\n", + " x=impact_bin_centres,\n", + " y=probs,\n", + " width=impact_bin_width,\n", + " name=f\"Flood depth {hazard_indicator[i]}m\",\n", + " opacity=0.7,\n", + " )\n", "fig.update_xaxes(title=\"Fractional damage\", title_font={\"size\": 14})\n", "fig.update_yaxes(title=\"Probability\", title_font={\"size\": 14})\n", "fig.show()" diff --git a/docs/vulnerability_functions/inundation_jrc/onboard.ipynb b/docs/vulnerability_functions/inundation_jrc/onboard.ipynb index 4ec78a8f..627fdb55 100644 --- a/docs/vulnerability_functions/inundation_jrc/onboard.ipynb +++ b/docs/vulnerability_functions/inundation_jrc/onboard.ipynb @@ -54,7 +54,11 @@ " # whether zero depth is considered really zero or a flood event with smallest depth\n", " zero_as_minimum = True if location == \"North America\" else False\n", " # for North America, the 0 depth damage is for flooding of any depth. We consider that a 1 cm inundation.\n", - " depth = np.concatenate([[0, 0.01], flood_depth[1:]]) if zero_as_minimum else flood_depth\n", + " depth = (\n", + " np.concatenate([[0, 0.01], flood_depth[1:]])\n", + " if zero_as_minimum\n", + " else flood_depth\n", + " )\n", "\n", " mean = type_df[location + \"_Mean\"].to_numpy()\n", " std = type_df[location + \"_Std\"].to_numpy()\n", diff --git a/docs/vulnerability_functions/multi_hazard_wri_power_generating_assets/onboard.ipynb b/docs/vulnerability_functions/multi_hazard_wri_power_generating_assets/onboard.ipynb index d691bdcc..aa777440 100644 --- a/docs/vulnerability_functions/multi_hazard_wri_power_generating_assets/onboard.ipynb +++ b/docs/vulnerability_functions/multi_hazard_wri_power_generating_assets/onboard.ipynb @@ -22,7 +22,8 @@ "metadata": {}, "outputs": [], "source": [ - "import json, pandas\n", + "import json\n", + "import pandas\n", "\n", "data = {\"items\": []}\n", "\n", @@ -53,15 +54,23 @@ " \"event_type\": hazard_type.replace(\" \", \"\"),\n", " \"location\": \"Global\",\n", " \"intensity\": list(item[\"Threshold\"].values),\n", - " \"intensity_units\": item[\"Threshold Unit\"].values[0].replace(\" \", \"\"),\n", - " \"impact_type\": item[\"Vulnerability Type\"].values[0].replace(\" \", \"\"),\n", - " \"impact_units\": item[\"Vulnerability Unit\"].values[0].replace(\" \", \"\"),\n", + " \"intensity_units\": item[\"Threshold Unit\"]\n", + " .values[0]\n", + " .replace(\" \", \"\"),\n", + " \"impact_type\": item[\"Vulnerability Type\"]\n", + " .values[0]\n", + " .replace(\" \", \"\"),\n", + " \"impact_units\": item[\"Vulnerability Unit\"]\n", + " .values[0]\n", + " .replace(\" \", \"\"),\n", " \"impact_mean\": list(item[\"Vulnerability\"].values),\n", " \"impact_std\": [],\n", " }\n", " )\n", "\n", - "with open(\"WRI thermal power plant physical climate vulnerability factors.json\", \"w\") as f:\n", + "with open(\n", + " \"WRI thermal power plant physical climate vulnerability factors.json\", \"w\"\n", + ") as f:\n", " vulnerability_json = json.dumps(data, sort_keys=True, indent=4)\n", " f.write(vulnerability_json)" ] diff --git a/methodology/plots/interp_pixel_is_area.ipynb b/methodology/plots/interp_pixel_is_area.ipynb index 84ab1702..f075b194 100644 --- a/methodology/plots/interp_pixel_is_area.ipynb +++ b/methodology/plots/interp_pixel_is_area.ipynb @@ -6,9 +6,9 @@ "metadata": {}, "outputs": [], "source": [ - "import os, sys\n", + "import os\n", + "import sys\n", "from affine import Affine\n", - "import matplotlib.pyplot as plt\n", "import s3fs\n", "import hazard.utilities.zarr_utilities as zarr_utilities\n", "from hazard.sources.osc_zarr import OscZarr\n", @@ -17,7 +17,11 @@ "\n", "os.environ[\"CREDENTIAL_DOTENV_DIR\"] = os.path.dirname(os.getcwd())\n", "zarr_utilities.set_credential_env_variables()\n", - "s3 = s3fs.S3FileSystem(anon=False, key=os.environ[\"OSC_S3_ACCESS_KEY\"], secret=os.environ[\"OSC_S3_SECRET_KEY\"])" + "s3 = s3fs.S3FileSystem(\n", + " anon=False,\n", + " key=os.environ[\"OSC_S3_ACCESS_KEY\"],\n", + " secret=os.environ[\"OSC_S3_SECRET_KEY\"],\n", + ")" ] }, { @@ -28,7 +32,9 @@ "source": [ "longitude = 2.293\n", "latitude = 48.855\n", - "transform = Affine(0.008333333333333333, 0.0, -180.0, 0.0, -0.008333333333333333, 90.0, 0.0, 0.0, 1.0)" + "transform = Affine(\n", + " 0.008333333333333333, 0.0, -180.0, 0.0, -0.008333333333333333, 90.0, 0.0, 0.0, 1.0\n", + ")" ] }, { @@ -72,7 +78,8 @@ "source": [ "delta = 0.02\n", "plt1 = da.sel(\n", - " latitude=slice(latitude + delta, latitude - delta), longitude=slice(longitude - delta, longitude + delta)\n", + " latitude=slice(latitude + delta, latitude - delta),\n", + " longitude=slice(longitude - delta, longitude + delta),\n", ")[8, :, :].plot.pcolormesh(cmap=\"Blues\", cbar_kwargs={\"label\": \"flood depth (m)\"})" ] }, @@ -97,10 +104,17 @@ "# the point falls in pixel 21875, 4937\n", "\n", "plt1.axes.set_title(\"\")\n", - "surrounding_points = [[21874.5, 4936.5], [21874.5, 4937.5], [21875.5, 4936.5], [21875.5, 4937.5]]\n", + "surrounding_points = [\n", + " [21874.5, 4936.5],\n", + " [21874.5, 4937.5],\n", + " [21875.5, 4936.5],\n", + " [21875.5, 4937.5],\n", + "]\n", "for point in surrounding_points:\n", " pointt = transform * point\n", - " plt1.axes.plot([pointt[0], longitude], [pointt[1], latitude], \"--\", color=\"grey\", zorder=1)\n", + " plt1.axes.plot(\n", + " [pointt[0], longitude], [pointt[1], latitude], \"--\", color=\"grey\", zorder=1\n", + " )\n", " plt1.axes.scatter([pointt[0]], [pointt[1]], c=\"black\", marker=\"o\", zorder=2)\n", "plt1.axes.scatter([longitude], [latitude], c=\"black\", marker=\"x\", zorder=2)\n", "plt1.axes.figure"