Skip to content

Commit 5d11f75

Browse files
Merge branch 'develop' into feature/restructure_fitfuncs_exceedance
2 parents 19c482a + 9bb8856 commit 5d11f75

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1030
-989
lines changed

CHANGELOG.md

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Code freeze date: YYYY-MM-DD
1111
### Dependency Changes
1212

1313
### Added
14+
1415
- `climada.util.interpolation` module for inter- and extrapolation util functions used in local exceedance intensity and return period functions [#930](https://github.com/CLIMADA-project/climada_python/pull/930)
1516

1617
### Changed
@@ -56,6 +57,19 @@ Updated:
5657

5758
- GitHub actions workflow for CLIMADA Petals compatibility tests [#855](https://github.com/CLIMADA-project/climada_python/pull/855)
5859
- `climada.util.calibrate` module for calibrating impact functions [#692](https://github.com/CLIMADA-project/climada_python/pull/692)
60+
- Method `Hazard.check_matrices` for bringing the stored CSR matrices into "canonical format" [#893](https://github.com/CLIMADA-project/climada_python/pull/893)
61+
- Generic s-shaped impact function via `ImpactFunc.from_poly_s_shape` [#878](https://github.com/CLIMADA-project/climada_python/pull/878)
62+
- climada.hazard.centroids.centr.Centroids.get_area_pixel
63+
- climada.hazard.centroids.centr.Centroids.get_dist_coast
64+
- climada.hazard.centroids.centr.Centroids.get_elevation
65+
- climada.hazard.centroids.centr.Centroids.get_meta
66+
- climada.hazard.centroids.centr.Centroids.get_pixel_shapes
67+
- climada.hazard.centroids.centr.Centroids.to_crs
68+
- climada.hazard.centroids.centr.Centroids.to_default_crs
69+
- climada.hazard.centroids.centr.Centroids.write_csv
70+
- climada.hazard.centroids.centr.Centroids.write_excel
71+
- climada.hazard.local_return_period [#898](https://github.com/CLIMADA-project/climada_python/pull/898)
72+
- climada.util.plot.subplots_from_gdf [#898](https://github.com/CLIMADA-project/climada_python/pull/898)
5973

6074
### Changed
6175

@@ -80,22 +94,6 @@ CLIMADA tutorials. [#872](https://github.com/CLIMADA-project/climada_python/pull
8094
- Fix broken links in `CONTRIBUTING.md` [#900](https://github.com/CLIMADA-project/climada_python/pull/900)
8195
- When writing `TCTracks` to NetCDF, only apply compression to `float` or `int` data types. This fixes a downstream issue, see [climada_petals#135](https://github.com/CLIMADA-project/climada_petals/issues/135) [#911](https://github.com/CLIMADA-project/climada_python/pull/911)
8296

83-
### Added
84-
85-
- Method `Hazard.check_matrices` for bringing the stored CSR matrices into "canonical format" [#893](https://github.com/CLIMADA-project/climada_python/pull/893)
86-
- Generic s-shaped impact function via `ImpactFunc.from_poly_s_shape` [#878](https://github.com/CLIMADA-project/climada_python/pull/878)
87-
- climada.hazard.centroids.centr.Centroids.get_area_pixel
88-
- climada.hazard.centroids.centr.Centroids.get_dist_coast
89-
- climada.hazard.centroids.centr.Centroids.get_elevation
90-
- climada.hazard.centroids.centr.Centroids.get_meta
91-
- climada.hazard.centroids.centr.Centroids.get_pixel_shapes
92-
- climada.hazard.centroids.centr.Centroids.to_crs
93-
- climada.hazard.centroids.centr.Centroids.to_default_crs
94-
- climada.hazard.centroids.centr.Centroids.write_csv
95-
- climada.hazard.centroids.centr.Centroids.write_excel
96-
- climada.hazard.local_return_period [#898](https://github.com/CLIMADA-project/climada_python/pull/898)
97-
- climada.util.plot.subplots_from_gdf [#898](https://github.com/CLIMADA-project/climada_python/pull/898)
98-
9997
### Deprecated
10098

10199
- climada.hazard.centroids.centr.Centroids.from_lat_lon

climada/engine/forecast.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def __init__(
186186
if exposure_name is None:
187187
try:
188188
self.exposure_name = u_coord.country_to_iso(
189-
exposure.gdf.region_id.unique()[0], "name"
189+
exposure.gdf["region_id"].unique()[0], "name"
190190
)
191191
except (KeyError, AttributeError):
192192
self.exposure_name = "custom"

climada/engine/impact.py

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,8 @@ def from_eih(cls, exposures, hazard, at_event, eai_exp, aai_agg, imp_mat=None):
245245
date = hazard.date,
246246
frequency = hazard.frequency,
247247
frequency_unit = hazard.frequency_unit,
248-
coord_exp = np.stack([exposures.gdf.latitude.values,
249-
exposures.gdf.longitude.values],
248+
coord_exp = np.stack([exposures.gdf['latitude'].values,
249+
exposures.gdf['longitude'].values],
250250
axis=1),
251251
crs = exposures.crs,
252252
unit = exposures.value_unit,
@@ -1176,25 +1176,25 @@ def from_csv(cls, file_name):
11761176
# pylint: disable=no-member
11771177
LOGGER.info('Reading %s', file_name)
11781178
imp_df = pd.read_csv(file_name)
1179-
imp = cls(haz_type=imp_df.haz_type[0])
1180-
imp.unit = imp_df.unit[0]
1181-
imp.tot_value = imp_df.tot_value[0]
1182-
imp.aai_agg = imp_df.aai_agg[0]
1183-
imp.event_id = imp_df.event_id[~np.isnan(imp_df.event_id)].values
1179+
imp = cls(haz_type=imp_df['haz_type'][0])
1180+
imp.unit = imp_df['unit'][0]
1181+
imp.tot_value = imp_df['tot_value'][0]
1182+
imp.aai_agg = imp_df['aai_agg'][0]
1183+
imp.event_id = imp_df['event_id'][~np.isnan(imp_df['event_id'])].values
11841184
num_ev = imp.event_id.size
1185-
imp.event_name = imp_df.event_name[:num_ev].values.tolist()
1186-
imp.date = imp_df.event_date[:num_ev].values
1187-
imp.at_event = imp_df.at_event[:num_ev].values
1188-
imp.frequency = imp_df.event_frequency[:num_ev].values
1189-
imp.frequency_unit = imp_df.frequency_unit[0] if 'frequency_unit' in imp_df \
1185+
imp.event_name = imp_df['event_name'][:num_ev].values.tolist()
1186+
imp.date = imp_df['event_date'][:num_ev].values
1187+
imp.at_event = imp_df['at_event'][:num_ev].values
1188+
imp.frequency = imp_df['event_frequency'][:num_ev].values
1189+
imp.frequency_unit = imp_df['frequency_unit'][0] if 'frequency_unit' in imp_df \
11901190
else DEF_FREQ_UNIT
1191-
imp.eai_exp = imp_df.eai_exp[~np.isnan(imp_df.eai_exp)].values
1191+
imp.eai_exp = imp_df['eai_exp'][~np.isnan(imp_df['eai_exp'])].values
11921192
num_exp = imp.eai_exp.size
11931193
imp.coord_exp = np.zeros((num_exp, 2))
1194-
imp.coord_exp[:, 0] = imp_df.exp_lat[:num_exp]
1195-
imp.coord_exp[:, 1] = imp_df.exp_lon[:num_exp]
1194+
imp.coord_exp[:, 0] = imp_df['exp_lat'][:num_exp]
1195+
imp.coord_exp[:, 1] = imp_df['exp_lon'][:num_exp]
11961196
try:
1197-
imp.crs = u_coord.to_crs_user_input(imp_df.exp_crs.values[0])
1197+
imp.crs = u_coord.to_crs_user_input(imp_df['exp_crs'].values[0])
11981198
except AttributeError:
11991199
imp.crs = DEF_CRS
12001200

@@ -1224,23 +1224,23 @@ def from_excel(cls, file_name):
12241224
dfr = pd.read_excel(file_name)
12251225
imp = cls(haz_type=str(dfr['haz_type'][0]))
12261226

1227-
imp.unit = dfr.unit[0]
1228-
imp.tot_value = dfr.tot_value[0]
1229-
imp.aai_agg = dfr.aai_agg[0]
1227+
imp.unit = dfr['unit'][0]
1228+
imp.tot_value = dfr['tot_value'][0]
1229+
imp.aai_agg = dfr['aai_agg'][0]
12301230

1231-
imp.event_id = dfr.event_id[~np.isnan(dfr.event_id.values)].values
1232-
imp.event_name = dfr.event_name[:imp.event_id.size].values
1233-
imp.date = dfr.event_date[:imp.event_id.size].values
1234-
imp.frequency = dfr.event_frequency[:imp.event_id.size].values
1235-
imp.frequency_unit = dfr.frequency_unit[0] if 'frequency_unit' in dfr else DEF_FREQ_UNIT
1236-
imp.at_event = dfr.at_event[:imp.event_id.size].values
1231+
imp.event_id = dfr['event_id'][~np.isnan(dfr['event_id'].values)].values
1232+
imp.event_name = dfr['event_name'][:imp.event_id.size].values
1233+
imp.date = dfr['event_date'][:imp.event_id.size].values
1234+
imp.frequency = dfr['event_frequency'][:imp.event_id.size].values
1235+
imp.frequency_unit = dfr['frequency_unit'][0] if 'frequency_unit' in dfr else DEF_FREQ_UNIT
1236+
imp.at_event = dfr['at_event'][:imp.event_id.size].values
12371237

1238-
imp.eai_exp = dfr.eai_exp[~np.isnan(dfr.eai_exp.values)].values
1238+
imp.eai_exp = dfr['eai_exp'][~np.isnan(dfr['eai_exp'].values)].values
12391239
imp.coord_exp = np.zeros((imp.eai_exp.size, 2))
1240-
imp.coord_exp[:, 0] = dfr.exp_lat.values[:imp.eai_exp.size]
1241-
imp.coord_exp[:, 1] = dfr.exp_lon.values[:imp.eai_exp.size]
1240+
imp.coord_exp[:, 0] = dfr['exp_lat'].values[:imp.eai_exp.size]
1241+
imp.coord_exp[:, 1] = dfr['exp_lon'].values[:imp.eai_exp.size]
12421242
try:
1243-
imp.crs = u_coord.to_csr_user_input(dfr.exp_crs.values[0])
1243+
imp.crs = u_coord.to_csr_user_input(dfr['exp_crs'].values[0])
12441244
except AttributeError:
12451245
imp.crs = DEF_CRS
12461246

@@ -1419,14 +1419,14 @@ def video_direct_impact(exp, impf_set, haz_list, file_name='',
14191419
np.array([haz.intensity.max() for haz in haz_list]).max()]
14201420

14211421
if 'vmin' not in args_exp:
1422-
args_exp['vmin'] = exp.gdf.value.values.min()
1422+
args_exp['vmin'] = exp.gdf['value'].values.min()
14231423

14241424
if 'vmin' not in args_imp:
14251425
args_imp['vmin'] = np.array([imp.eai_exp.min() for imp in imp_list
14261426
if imp.eai_exp.size]).min()
14271427

14281428
if 'vmax' not in args_exp:
1429-
args_exp['vmax'] = exp.gdf.value.values.max()
1429+
args_exp['vmax'] = exp.gdf['value'].values.max()
14301430

14311431
if 'vmax' not in args_imp:
14321432
args_imp['vmax'] = np.array([imp.eai_exp.max() for imp in imp_list

climada/engine/impact_calc.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ def impact(self, save_mat=True, assign_centroids=True,
154154
exp_gdf.size, self.n_events)
155155
imp_mat_gen = self.imp_mat_gen(exp_gdf, impf_col)
156156

157-
insured = ('cover' in exp_gdf and exp_gdf.cover.max() >= 0) \
158-
or ('deductible' in exp_gdf and exp_gdf.deductible.max() > 0)
157+
insured = ('cover' in exp_gdf and exp_gdf['cover'].max() >= 0) \
158+
or ('deductible' in exp_gdf and exp_gdf['deductible'].max() > 0)
159159
if insured:
160160
LOGGER.info("cover and/or deductible columns detected,"
161161
" going to calculate insured impact")
@@ -253,8 +253,8 @@ def minimal_exp_gdf(self, impf_col, assign_centroids, ignore_cover, ignore_deduc
253253
" Run 'exposures.assign_centroids()' beforehand or set"
254254
" 'assign_centroids' to 'True'")
255255
mask = (
256-
(self.exposures.gdf.value.values == self.exposures.gdf.value.values) # value != NaN
257-
& (self.exposures.gdf.value.values != 0) # value != 0
256+
(self.exposures.gdf['value'].values == self.exposures.gdf['value'].values)# value != NaN
257+
& (self.exposures.gdf['value'].values != 0) # value != 0
258258
& (self.exposures.gdf[self.hazard.centr_exp_col].values >= 0) # centroid assigned
259259
)
260260

@@ -320,7 +320,7 @@ def _chunk_exp_idx(haz_size, idx_exp_impf):
320320
)
321321
idx_exp_impf = (exp_gdf[impf_col].values == impf_id).nonzero()[0]
322322
for exp_idx in _chunk_exp_idx(self.hazard.size, idx_exp_impf):
323-
exp_values = exp_gdf.value.values[exp_idx]
323+
exp_values = exp_gdf['value'].values[exp_idx]
324324
cent_idx = exp_gdf[self.hazard.centr_exp_col].values[exp_idx]
325325
yield (
326326
self.impact_matrix(exp_values, cent_idx, impf),
@@ -363,10 +363,10 @@ def insured_mat_gen(self, imp_mat_gen, exp_gdf, impf_col):
363363
haz_type=self.hazard.haz_type,
364364
fun_id=impf_id)
365365
if 'deductible' in exp_gdf:
366-
deductible = exp_gdf.deductible.values[exp_idx]
366+
deductible = exp_gdf['deductible'].values[exp_idx]
367367
mat = self.apply_deductible_to_mat(mat, deductible, self.hazard, cent_idx, impf)
368368
if 'cover' in exp_gdf:
369-
cover = exp_gdf.cover.values[exp_idx]
369+
cover = exp_gdf['cover'].values[exp_idx]
370370
mat = self.apply_cover_to_mat(mat, cover)
371371
yield (mat, exp_idx)
372372

0 commit comments

Comments
 (0)