diff --git a/docs/getting_started/asset_level_impacts.ipynb b/docs/getting_started/asset_level_impacts.ipynb index b29e3b02..e92fad23 100644 --- a/docs/getting_started/asset_level_impacts.ipynb +++ b/docs/getting_started/asset_level_impacts.ipynb @@ -181,10 +181,31 @@ "\n", "fig1 = make_subplots(rows=1, cols=1)\n", "\n", - "fig1.add_scatter(x=exceedance_histo[\"exceed_probabilities\"], y=exceedance_histo[\"values\"], name=\"baseline wind\", row=1, col=1)\n", - "fig1.add_scatter(x=exceedance_ssp585[\"exceed_probabilities\"], y=exceedance_ssp585[\"values\"], name=\"wind SSP585\", row=1, col=1)\n", - "fig1.update_xaxes(title=\"Annual exceedance probability\", title_font={\"size\": 14}, row=1, col=1, type=\"log\", autorange=\"reversed\")\n", - "fig1.update_yaxes(title=\"Damage as fraction of insurable value\", title_font={\"size\": 14}, row=1, col=1)\n" + "fig1.add_scatter(\n", + " x=exceedance_histo[\"exceed_probabilities\"],\n", + " y=exceedance_histo[\"values\"],\n", + " name=\"baseline wind\",\n", + " row=1,\n", + " col=1,\n", + ")\n", + "fig1.add_scatter(\n", + " x=exceedance_ssp585[\"exceed_probabilities\"],\n", + " y=exceedance_ssp585[\"values\"],\n", + " name=\"wind SSP585\",\n", + " row=1,\n", + " col=1,\n", + ")\n", + "fig1.update_xaxes(\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(\n", + " title=\"Damage as fraction of insurable value\", title_font={\"size\": 14}, row=1, col=1\n", + ")" ] }, { @@ -229,7 +250,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", @@ -280,7 +303,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/getting_started/hazard_indicators.ipynb b/docs/getting_started/hazard_indicators.ipynb index cc6ef42e..c535781e 100644 --- a/docs/getting_started/hazard_indicators.ipynb +++ b/docs/getting_started/hazard_indicators.ipynb @@ -70,8 +70,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", @@ -79,8 +101,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", @@ -204,14 +248,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)\n", + "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", + ")\n", "fig1.update_layout(legend=dict(orientation=\"h\", y=-0.15))\n", "fig1.update_layout(margin=dict(l=20, r=20, t=20, b=20))" ] diff --git a/docs/getting_started/hazard_inventory.ipynb b/docs/getting_started/hazard_inventory.ipynb index 6bfdca00..3891f578 100644 --- a/docs/getting_started/hazard_inventory.ipynb +++ b/docs/getting_started/hazard_inventory.ipynb @@ -123,18 +123,22 @@ "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", "print(\"The available climate scenarios and years for the IRIS resource are:\")\n", "pp.pprint(iris_model_resource[\"scenarios\"])\n", "print(\"The whole IRIS data resource, as an example:\")\n", - "pp.pprint(iris_model_resource)\n" + "pp.pprint(iris_model_resource)" ] }, { @@ -200,7 +204,13 @@ "metadata": {}, "outputs": [], "source": [ - "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", @@ -210,19 +220,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", "style = \"\"\"\n", "