Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pre-commit.ci] pre-commit autoupdate #328

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: check-merge-conflict
- id: end-of-file-fixer
Expand All @@ -22,7 +22,7 @@ repos:
exclude: ^.*(\.(tsv)|Makefile)$

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.7
rev: v0.8.6
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix, --config=pyproject.toml]
Expand All @@ -38,7 +38,7 @@ repos:
then /bin/mkdir .mypy_cache; fi; exit 0'

- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v1.11.1"
rev: "v1.14.1"
hooks:
- id: mypy
verbose: true
Expand Down
39 changes: 33 additions & 6 deletions docs/getting_started/asset_level_impacts.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
")"
]
},
{
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
")"
]
},
{
Expand Down
96 changes: 85 additions & 11 deletions docs/getting_started/hazard_indicators.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,61 @@
"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",
" \"scenario\": \"historical\",\n",
" \"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",
Expand Down Expand Up @@ -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))"
]
Expand Down
48 changes: 35 additions & 13 deletions docs/getting_started/hazard_inventory.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
]
},
{
Expand Down Expand Up @@ -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",
Expand All @@ -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",
"<style scoped>\n",
Expand Down
6 changes: 4 additions & 2 deletions docs/user_guide/hazard_indicators/indicators.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,13 @@
"source": [
"import numpy as np\n",
"\n",
"print(f\"Numpy also has 'C' ordering by default\") \n",
"print(\"Numpy also has 'C' ordering by default\")\n",
"a = np.arange(24)\n",
"b = a.reshape([2, 3, 4])\n",
"print(b)\n",
"print(f\"Element [0, 2, 3] = {b[0, 2, 3]} is next to element [0, 2, 2] = {b[0, 2, 2]} in memory\") "
"print(\n",
" f\"Element [0, 2, 3] = {b[0, 2, 3]} is next to element [0, 2, 2] = {b[0, 2, 2]} in memory\"\n",
")"
]
},
{
Expand Down
30 changes: 22 additions & 8 deletions docs/user_guide/vulnerability/vulnerability_config.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,15 @@
"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_impact_curves import config_items_from_csv, config_items_to_df"
"from physrisk.vulnerability_models.config_based_impact_curves import (\n",
" config_items_from_csv,\n",
" config_items_to_df,\n",
")"
]
},
{
Expand Down Expand Up @@ -354,18 +355,31 @@
}
],
"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_scatter(x=c1.points_x, y=c1.points_y, name=\"Example damage curve\", row=1, col=1)\n",
"fig1.add_scatter(x=c2.points_x, y=c2.points_y, name=\"Example threshold curve\", row=1, col=2)\n",
"fig1.add_scatter(\n",
" x=c1.points_x, y=c1.points_y, name=\"Example damage curve\", row=1, col=1\n",
")\n",
"fig1.add_scatter(\n",
" x=c2.points_x, y=c2.points_y, name=\"Example threshold curve\", row=1, col=2\n",
")\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(title=\"Damage as fraction of insurable value\", row=1, col=1)\n",
"fig1.update_yaxes(title=\"Fractional loss of production\", row=1, col=2)\n",
"fig1.update_layout(legend=dict(orientation=\"h\", y=-0.15))\n",
"#fig1.update_layout(legend=dict(yanchor=\"top\", y=0.99, xanchor=\"left\", x=0.01))\n",
"# fig1.update_layout(legend=dict(yanchor=\"top\", y=0.99, xanchor=\"left\", x=0.01))\n",
"fig1.update_layout(margin=dict(l=20, r=20, t=20, b=20))"
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@
"metadata": {},
"outputs": [],
"source": [
"import plotly.graph_objs as go\n",
"import plotly.io\n",
"from plotly.subplots import make_subplots\n",
"from physrisk.vulnerability_models.configuration.config_builders import ConfigBuilderJRCFlood\n",
"from physrisk.vulnerability_models.configuration.config_builders import (\n",
" ConfigBuilderJRCFlood,\n",
")\n",
"\n",
"plotly.io.renderers.default = \"notebook\"\n",
"\n",
"builder = ConfigBuilderJRCFlood()\n",
Expand Down Expand Up @@ -105,9 +107,13 @@
"source": [
"fig1 = make_subplots(rows=1, cols=1)\n",
"for item in config_items:\n",
" fig1.add_scatter(x=item.points_x, y=item.points_y, row=1, col=1, name=item.asset_identifier)\n",
" fig1.add_scatter(\n",
" x=item.points_x, y=item.points_y, row=1, col=1, name=item.asset_identifier\n",
" )\n",
"fig1.update_xaxes(title=\"Flood depth (m)\", title_font={\"size\": 14}, row=1, col=1)\n",
"fig1.update_yaxes(title=\"Damage as fraction of TIV\", title_font={\"size\": 14}, row=1, col=1)\n",
"fig1.update_yaxes(\n",
" title=\"Damage as fraction of TIV\", title_font={\"size\": 14}, row=1, col=1\n",
")\n",
"fig1.update_layout(legend=dict(orientation=\"h\", y=-0.25))\n",
"fig1.update_layout(margin=dict(l=20, r=20, t=20, b=20))"
]
Expand Down
Loading
Loading