Skip to content

Commit 36f4735

Browse files
authored
Merge pull request #941 from CLIMADA-project/feature/remove-attribute-style-access-tutorials
Remove attribute-style accesses to (Geo)DataFrames columns and xarray Datasets variables and attributes within tutorials
2 parents 40d2779 + ec944e0 commit 36f4735

7 files changed

+25
-25
lines changed

doc/tutorial/climada_engine_Forecast.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,8 @@
255255
"\n",
256256
"### generate exposure\n",
257257
"# find out which hazard coord to consider\n",
258-
"CHE_borders = u_plot._get_borders(np.stack([exposure.gdf.latitude.values,\n",
259-
" exposure.gdf.longitude.values],\n",
258+
"CHE_borders = u_plot._get_borders(np.stack([exposure.gdf['latitude'].values,\n",
259+
" exposure.gdf['longitude'].values],\n",
260260
" axis=1)\n",
261261
" )\n",
262262
"centroid_selection = np.logical_and(np.logical_and(hazard.centroids.lat >= CHE_borders[2],\n",
@@ -390,4 +390,4 @@
390390
},
391391
"nbformat": 4,
392392
"nbformat_minor": 4
393-
}
393+
}

doc/tutorial/climada_engine_Impact.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
"| event_id |list(int)| id (>0) of each hazard event (Hazard.event_id)|\n",
6969
"| event_name |(list(str))| name of each event (Hazard.event_name)|\n",
7070
"| date |np.array| date of events (Hazard.date)|\n",
71-
"| coord_exp |np.array| exposures coordinates [lat, lon] (in degrees) (Exposure.gdf.latidues, Exposure.gdf.longitude)|\n",
71+
"| coord_exp |np.array| exposures coordinates [lat, lon] (in degrees) (Exposure.gdf['latitudes'], Exposure.gdf['longitude'])|\n",
7272
"| frequency |np.array| frequency of events (Hazard.frequency)|\n",
7373
"| frequency_unit |str| unit of event frequency, by default '1/year', i.e., annual (Hazard.frequency_unit)|\n",
7474
"| unit |str| value unit used (Exposure.value_unit)|\n",
@@ -1468,7 +1468,7 @@
14681468
"\n",
14691469
"# Set Hazard in Exposures points\n",
14701470
"# set centroids from exposures coordinates\n",
1471-
"centr_pnt = Centroids.from_lat_lon(exp_pnt.gdf.latitude.values, exp_pnt.gdf.longitude.values, exp_pnt.crs)\n",
1471+
"centr_pnt = Centroids.from_lat_lon(exp_pnt.gdf['latitude'].values, exp_pnt.gdf['longitude'].values, exp_pnt.crs)\n",
14721472
"# compute Hazard in that centroids\n",
14731473
"tr_pnt = TCTracks.from_ibtracs_netcdf(storm_id='2007314N10093')\n",
14741474
"tc_pnt = TropCyclone.from_tracks(tr_pnt, centroids=centr_pnt)\n",
@@ -1492,7 +1492,7 @@
14921492
"# Compute Impact\n",
14931493
"imp_pnt = ImpactCalc(exp_pnt, impf_pnt, tc_pnt).impact()\n",
14941494
"# nearest neighbor of exposures to centroids gives identity\n",
1495-
"print('Nearest neighbor hazard.centroids indexes for each exposure:', exp_pnt.gdf.centr_TC.values)\n",
1495+
"print('Nearest neighbor hazard.centroids indexes for each exposure:', exp_pnt.gdf['centr_TC'].values)\n",
14961496
"imp_pnt.plot_scatter_eai_exposure(ignore_zero=False, buffer=0.05);"
14971497
]
14981498
},
@@ -1716,7 +1716,7 @@
17161716
"# Compute impact\n",
17171717
"imp_ras = ImpactCalc(exp_ras, impf_ras, haz_ras).impact(save_mat=False)\n",
17181718
"# nearest neighbor of exposures to centroids is not identity because litpop does not contain data outside the country polygon\n",
1719-
"print('\\n Nearest neighbor hazard.centroids indexes for each exposure:', exp_ras.gdf.centr_FL.values)\n",
1719+
"print('\\n Nearest neighbor hazard.centroids indexes for each exposure:', exp_ras.gdf['centr_FL'].values)\n",
17201720
"imp_ras.plot_raster_eai_exposure();"
17211721
]
17221722
},
@@ -1967,7 +1967,7 @@
19671967
"\n",
19681968
"# compute sequence of hazards using TropCyclone video_intensity method\n",
19691969
"exp_sea = add_sea(exp_video, (100, 5))\n",
1970-
"centr_video = Centroids.from_lat_lon(exp_sea.gdf.latitude.values, exp_sea.gdf.longitude.values)\n",
1970+
"centr_video = Centroids.from_lat_lon(exp_sea.gdf['latitude'].values, exp_sea.gdf['longitude'].values)\n",
19711971
"centr_video.check()\n",
19721972
"\n",
19731973
"track_name = '2017242N16333'\n",

doc/tutorial/climada_engine_unsequa.ipynb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@
177177
"# Here x_exp is the input uncertainty parameter and exp_func the inputvar.func.\n",
178178
"def exp_func(x_exp, exp_base=exp_base):\n",
179179
" exp = exp_base.copy()\n",
180-
" exp.gdf.value *= x_exp\n",
180+
" exp.gdf['value'] *= x_exp\n",
181181
" return exp"
182182
]
183183
},
@@ -989,7 +989,7 @@
989989
"exp_base.assign_centroids(haz)\n",
990990
"def exp_base_func(x_exp, exp_base):\n",
991991
" exp = exp_base.copy()\n",
992-
" exp.gdf.value *= x_exp\n",
992+
" exp.gdf['value'] *= x_exp\n",
993993
" return exp\n",
994994
"from functools import partial\n",
995995
"exp_func = partial(exp_base_func, exp_base=exp_base)"
@@ -2462,7 +2462,7 @@
24622462
"exp_base.assign_centroids(haz)\n",
24632463
"def exp_base_func(x_exp, exp_base):\n",
24642464
" exp = exp_base.copy()\n",
2465-
" exp.gdf.value *= x_exp\n",
2465+
" exp.gdf['value'] *= x_exp\n",
24662466
" return exp\n",
24672467
"from functools import partial\n",
24682468
"exp_func = partial(exp_base_func, exp_base=exp_base)"
@@ -2797,7 +2797,7 @@
27972797
" from climada.util.constants import ENT_DEMO_TODAY\n",
27982798
" entity = Entity.from_excel(ENT_DEMO_TODAY)\n",
27992799
" entity.exposures.ref_year = 2018\n",
2800-
" entity.exposures.gdf.value *= x_ent\n",
2800+
" entity.exposures.gdf['value'] *= x_ent\n",
28012801
" return entity\n",
28022802
"\n",
28032803
"# Entity in the future has a +- 10% uncertainty in the cost of all the adapatation measures\n",
@@ -5267,7 +5267,7 @@
52675267
"\n",
52685268
"def exp_func(cnt, x_exp, exp_list=exp_list):\n",
52695269
" exp = exp_list[int(cnt)].copy()\n",
5270-
" exp.gdf.value *= x_exp\n",
5270+
" exp.gdf['value'] *= x_exp\n",
52715271
" return exp\n",
52725272
"\n",
52735273
"exp_distr = {\"x_exp\": sp.stats.uniform(0.9, 0.2),\n",
@@ -5519,15 +5519,15 @@
55195519
" global exp_base\n",
55205520
" if 'exp_base' in globals():\n",
55215521
" if isinstance(exp_base, Exposures):\n",
5522-
" if exp_base.gdf.filename != str(filename):\n",
5522+
" if exp_base.gdf['filename'] != str(filename):\n",
55235523
" exp_base = Exposures.from_hdf5(filename)\n",
5524-
" exp_base.gdf.filename = str(filename)\n",
5524+
" exp_base.gdf['filename'] = str(filename)\n",
55255525
" else:\n",
55265526
" exp_base = Exposures.from_hdf5(filename)\n",
5527-
" exp_base.gdf.filename = str(filename)\n",
5527+
" exp_base.gdf['filename'] = str(filename)\n",
55285528
"\n",
55295529
" exp = exp_base.copy()\n",
5530-
" exp.gdf.value *= x_exp\n",
5530+
" exp.gdf['value'] *= x_exp\n",
55315531
" return exp\n",
55325532
"\n",
55335533
"exp_distr = {\"x_exp\": sp.stats.uniform(0.9, 0.2),\n",
@@ -5727,4 +5727,4 @@
57275727
},
57285728
"nbformat": 4,
57295729
"nbformat_minor": 4
5730-
}
5730+
}

doc/tutorial/climada_entity_Exposures.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1639,7 +1639,7 @@
16391639
"# Example 3: plot_raster method\n",
16401640
"from climada.util.plot import add_cntry_names # use climada's plotting utilities\n",
16411641
"ax = exp.plot_raster(); # plot with same resolution as data\n",
1642-
"add_cntry_names(ax, [exp.gdf.longitude.min(), exp.gdf.longitude.max(), exp.gdf.latitude.min(), exp.gdf.latitude.max()])\n",
1642+
"add_cntry_names(ax, [exp.gdf['longitude'].min(), exp.gdf['longitude'].max(), exp.gdf['latitude'].min(), exp.gdf['latitude'].max()])\n",
16431643
"\n",
16441644
"# use keyword argument save_tiff='filepath.tiff' to save the corresponding raster in tiff format\n",
16451645
"# use keyword argument raster_res='desired number' to change resolution of the raster."

doc/tutorial/climada_entity_LitPop.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,9 @@
161161
" raise err\n",
162162
"exp.plot_scatter();\n",
163163
"\n",
164-
"# Note that `exp.gdf.region_id` is a number identifying each country:\n",
164+
"# Note that `exp.gdf['region_id']` is a number identifying each country:\n",
165165
"print('\\n Region IDs (`region_id`) in this exposure:')\n",
166-
"print(exp.gdf.region_id.unique())"
166+
"print(exp.gdf['region_id'].unique())"
167167
]
168168
},
169169
{

doc/tutorial/climada_hazard_TropCyclone.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1743,14 +1743,14 @@
17431743
"# 1. Which is the time frequency of the data?\n",
17441744
"# The values of a DataArray are numpy.arrays.\n",
17451745
"# The nummpy.ediff1d computes the different between elements in an array\n",
1746-
"diff_time_ns = np.ediff1d(tc_syn.time)\n",
1746+
"diff_time_ns = np.ediff1d(tc_syn[\"time\"])\n",
17471747
"diff_time_h = diff_time_ns.astype(int)/1000/1000/1000/60/60\n",
17481748
"print('Mean time frequency in hours:', diff_time_h.mean())\n",
17491749
"print('Std time frequency in hours:', diff_time_h.std())\n",
17501750
"print()\n",
17511751
"\n",
17521752
"# 2. Compute the maximum sustained wind for each day.\n",
1753-
"print('Daily max sustained wind:', tc_syn.max_sustained_wind.groupby('time.day').max())"
1753+
"print('Daily max sustained wind:', tc_syn[\"max_sustained_wind\"].groupby('time.day').max())"
17541754
]
17551755
},
17561756
{

doc/tutorial/climada_util_calibrate.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,7 +1039,7 @@
10391039
"from climada.util.constants import SYSTEM_DIR\n",
10401040
"\n",
10411041
"emdat = pd.read_csv(SYSTEM_DIR / \"tc_impf_cal_v01_EDR.csv\")\n",
1042-
"emdat_subset = emdat[(emdat.cal_region2 == \"NA1\") & (emdat.year >= 2010)]\n",
1042+
"emdat_subset = emdat[(emdat[\"cal_region2\"] == \"NA1\") & (emdat[\"year\"] >= 2010)]\n",
10431043
"emdat_subset"
10441044
]
10451045
},
@@ -1689,7 +1689,7 @@
16891689
"# tracks.plot()\n",
16901690
"\n",
16911691
"# # Calculate windfield for the tracks\n",
1692-
"# centroids = Centroids.from_lat_lon(exposure.gdf.latitude, exposure.gdf.longitude)\n",
1692+
"# centroids = Centroids.from_lat_lon(exposure.gdf['latitude'], exposure.gdf['longitude'])\n",
16931693
"# hazard = TropCyclone.from_tracks(tracks, centroids)"
16941694
]
16951695
},

0 commit comments

Comments
 (0)