diff --git a/docs/notebooks/1_hazard_indicators.ipynb b/docs/notebooks/1_hazard_indicators.ipynb index 7f287ed3..2c591b5c 100644 --- a/docs/notebooks/1_hazard_indicators.ipynb +++ b/docs/notebooks/1_hazard_indicators.ipynb @@ -66,8 +66,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", @@ -75,8 +97,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", @@ -202,36 +246,50 @@ "fig1 = make_subplots(rows=1, cols=2)\n", "fig1.add_trace(\n", " go.Scatter(\n", - " x=flood_results_baseline[0][\"index_values\"], y=flood_results_baseline[0][\"intensities\"], name=\"baseline flood\"\n", + " x=flood_results_baseline[0][\"index_values\"],\n", + " y=flood_results_baseline[0][\"intensities\"],\n", + " name=\"baseline flood\",\n", " ),\n", " row=1,\n", " col=1,\n", ")\n", "fig1.add_trace(\n", " go.Scatter(\n", - " x=flood_results_rcp585[0][\"index_values\"], y=flood_results_rcp585[0][\"intensities\"], name=\"flood RCP 8.5 2050\"\n", + " x=flood_results_rcp585[0][\"index_values\"],\n", + " y=flood_results_rcp585[0][\"intensities\"],\n", + " name=\"flood RCP 8.5 2050\",\n", " ),\n", " row=1,\n", " col=1,\n", ")\n", - "fig1.update_xaxes(title=\"Return period (years)\", title_font={\"size\": 14}, row=1, col=1, type=\"log\")\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_trace(\n", " go.Scatter(\n", - " x=wind_results_baseline[0][\"index_values\"], y=wind_results_baseline[0][\"intensities\"], name=\"baseline wind\"\n", + " x=wind_results_baseline[0][\"index_values\"],\n", + " y=wind_results_baseline[0][\"intensities\"],\n", + " name=\"baseline wind\",\n", " ),\n", " row=1,\n", " col=2,\n", ")\n", "fig1.add_trace(\n", " go.Scatter(\n", - " x=wind_results_ssp585[0][\"index_values\"], y=wind_results_ssp585[0][\"intensities\"], name=\"wind SSP585 2050\"\n", + " x=wind_results_ssp585[0][\"index_values\"],\n", + " y=wind_results_ssp585[0][\"intensities\"],\n", + " name=\"wind SSP585 2050\",\n", " ),\n", " row=1,\n", " col=2,\n", ")\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.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", + ")" ] }, { @@ -353,11 +411,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", diff --git a/docs/notebooks/2_asset_level_impacts.ipynb b/docs/notebooks/2_asset_level_impacts.ipynb index d95b0ae8..dbe63a28 100644 --- a/docs/notebooks/2_asset_level_impacts.ipynb +++ b/docs/notebooks/2_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/methodology/plots/interp_pixel_is_area.ipynb b/methodology/plots/interp_pixel_is_area.ipynb index 84ab1702..32219339 100644 --- a/methodology/plots/interp_pixel_is_area.ipynb +++ b/methodology/plots/interp_pixel_is_area.ipynb @@ -6,7 +6,8 @@ "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", @@ -17,7 +18,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 +33,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 +79,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 +105,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" diff --git a/notebooks/vulnerability_onboarding/EU JRC global flood depth-damage functions/onboard.ipynb b/notebooks/vulnerability_onboarding/EU JRC global flood depth-damage functions/onboard.ipynb index 4ec78a8f..627fdb55 100644 --- a/notebooks/vulnerability_onboarding/EU JRC global flood depth-damage functions/onboard.ipynb +++ b/notebooks/vulnerability_onboarding/EU JRC global flood depth-damage functions/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/notebooks/vulnerability_onboarding/WRI thermal power plant physical climate vulnerability factors/onboard.ipynb b/notebooks/vulnerability_onboarding/WRI thermal power plant physical climate vulnerability factors/onboard.ipynb index d691bdcc..aa777440 100644 --- a/notebooks/vulnerability_onboarding/WRI thermal power plant physical climate vulnerability factors/onboard.ipynb +++ b/notebooks/vulnerability_onboarding/WRI thermal power plant physical climate vulnerability factors/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)" ]