Skip to content

Commit

Permalink
deprecate set_geomety_points
Browse files Browse the repository at this point in the history
  • Loading branch information
emanuel-schmid committed Sep 16, 2024
1 parent 5b3e071 commit 689a032
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 61 deletions.
1 change: 0 additions & 1 deletion doc/tutorial/1_main_climada.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,6 @@
"from climada.entity.exposures import LitPop\n",
"\n",
"exp_litpop = LitPop.from_countries('Puerto Rico', res_arcsec = 120) # We'll go lower resolution than default to keep it simple\n",
"exp_litpop.set_geometry_points() # Set geodataframe geometries from lat lon data\n",
"\n",
"exp_litpop.plot_hexbin(pop_name=True, linewidth=4, buffer=0.1);"
]
Expand Down
62 changes: 5 additions & 57 deletions doc/tutorial/climada_entity_Exposures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"| Optional columns | Data Type | Description |\n",
"| :-------------------- | :------------ | :------------------------------------------------------------------------------------- |\n",
"| `impf_*` | int | impact functions ids for hazard types.<br>important attribute, since it relates the exposures to the hazard by specifying the impf_act functions.<br>Ideally it should be set to the specific hazard (e.g. `impf_TC`) so that different hazards can be set<br>in the same Exposures (e.g. `impf_TC` and `impf_FL`).<br>If not provided, set to default `impf_` with ids 1 in check(). |\n",
"| `geometry` | Point | geometry of type Point<br>Main feature of geopandas DataFrame extension<br>Computed in method `set_geometry_points()` |\n",
"| `geometry` | Point | geometry of type Point<br>Main feature of geopandas DataFrame extension |\n",
"| `deductible` | float | deductible value for each exposure. <br>Used for insurance |\n",
"| `cover` | float | cover value for each exposure. <br>Used for insurance |\n",
"| `category_id` | int | category id (e.g. building code) for each exposure |\n",
Expand Down Expand Up @@ -198,11 +198,7 @@
"print('exp has the type:', str(type(exp)))\n",
"print('and contains a GeoDataFrame exp.gdf:', str(type(exp.gdf)))\n",
"\n",
"# set geometry attribute (shapely Points) from GeoDataFrame from latitude and longitude\n",
"exp.set_geometry_points()\n",
"print('\\n' + 'check method logs:')\n",
"\n",
"# always apply the check() method in the end. It puts metadata that has not been assigned,\n",
"# Apply the check() method in the end. It puts metadata that has not been assigned,\n",
"# and points out missing mandatory data\n",
"exp.check()"
]
Expand Down Expand Up @@ -1147,11 +1143,7 @@
"exp_templ = Exposures(exp_templ)\n",
"print('\\n' + 'exp_templ is now an Exposures:', str(type(exp_templ)))\n",
"\n",
"# set geometry attribute (shapely Points) from GeoDataFrame from latitude and longitude\n",
"print('\\n' + 'set_geometry logs:')\n",
"exp_templ.set_geometry_points()\n",
"# as always, run check method to include metadata and check for missing mandatory parameters\n",
"\n",
"# run check method to include metadata and check for missing mandatory parameters\n",
"print('\\n' + 'check exp_templ:')\n",
"exp_templ.check()"
]
Expand Down Expand Up @@ -1760,7 +1752,8 @@
"id": "5d078d09",
"metadata": {},
"source": [
"Finally, as with any Python object, use climada's save option to save it in pickle format. Note however, that pickle has a transient format and should be avoided when possible."
"Optionally use climada's save option to save it in pickle format. This allows fast to quickly restore the object in its current state and take up your work right were you left it the next time.\n",
"Note however, that pickle has a transient format and is not suitable for storing data persistently."
]
},
{
Expand All @@ -1774,51 +1767,6 @@
"# this generates a results folder in the current path and stores the output there\n",
"save('exp_templ.pkl.p', exp_templ) # creates results folder and stores there"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"## Dask - improving performance for big exposure\n",
"\n",
"Dask is used in some methods of CLIMADA and can be activated easily by proving the scheduler."
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" value latitude longitude impf_TC\n",
"0 0 15.0 20.000000 1\n",
"1 1 15.0 20.202020 1\n",
"2 2 15.0 20.404040 1\n",
"3 3 15.0 20.606061 1\n",
"4 4 15.0 20.808081 1\n",
"CPU times: user 243 ms, sys: 116 ms, total: 359 ms\n",
"Wall time: 2.52 s\n",
" value latitude longitude impf_TC geometry\n",
"0 0 15.0 20.000000 1 POINT (20.00000 15.00000)\n",
"1 1 15.0 20.202020 1 POINT (20.20202 15.00000)\n",
"2 2 15.0 20.404040 1 POINT (20.40404 15.00000)\n",
"3 3 15.0 20.606061 1 POINT (20.60606 15.00000)\n",
"4 4 15.0 20.808081 1 POINT (20.80808 15.00000)\n"
]
}
],
"source": [
"# set_geometry_points is expensive for big exposures\n",
"# for small amount of data, the execution time might be even greater when using dask\n",
"exp.gdf.drop(columns=['geometry'], inplace=True)\n",
"print(exp.gdf.head())\n",
"%time exp.set_geometry_points(scheduler='processes')\n",
"print(exp.gdf.head())"
]
}
],
"metadata": {
Expand Down
5 changes: 2 additions & 3 deletions doc/tutorial/climada_entity_LitPop.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -728,12 +728,11 @@
"# Initiate GDP-Entity for Switzerland, with and without admin1_calc:\n",
"\n",
"ent_adm0 = LitPop.from_countries('CHE', res_arcsec=120, fin_mode='gdp', admin1_calc=False)\n",
"ent_adm0.set_geometry_points()\n",
"ent_adm0.check()\n",
"\n",
"ent_adm1 = LitPop.from_countries('CHE', res_arcsec=120, fin_mode='gdp', admin1_calc=True)\n",
"\n",
"ent_adm0.check()\n",
"ent_adm1.check()\n",
"\n",
"print('Done.')"
]
},
Expand Down

0 comments on commit 689a032

Please sign in to comment.