Skip to content
Merged
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
4 changes: 2 additions & 2 deletions climada/engine/calibration_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def calib_instance(
years_in_common = df_out.loc[
df_out["year"].isin(np.sort(list((iys.keys())))), "year"
]
for cnt_, year in years_in_common.iteritems():
for cnt_, year in years_in_common.items():
df_out.loc[df_out["year"] == year, "impact_CLIMADA"] = iys[year]

else: # impact per event
Expand Down Expand Up @@ -403,7 +403,7 @@ def calib_all(
if df_result is None:
df_result = copy.deepcopy(df_out)
else:
df_result = df_result.append(df_out, input)
df_result = pd.concat([df_result, df_out], ignore_index=True)

return df_result

Expand Down
11 changes: 6 additions & 5 deletions climada/engine/impact_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ def hit_country_per_hazard(intensity_path, names_path, reg_id_path, date_path):
all_hits.append(hits)

# create data frame for output
hit_countries = pd.DataFrame(columns=["hit_country", "Date_start", "ibtracsID"])
hit_countries = []
for track, _ in enumerate(names):
# Check if track has hit any country else go to the next track
if len(all_hits[track]) > 0:
Expand All @@ -419,16 +419,17 @@ def hit_country_per_hazard(intensity_path, names_path, reg_id_path, date_path):
# Hit country ISO
ctry_iso = u_coord.country_to_iso(all_hits[track][hit], "alpha3")
# create entry for each country a hazard has hit
hit_countries = hit_countries.append(
hit_countries.append(
{
"hit_country": ctry_iso,
"Date_start": date[track],
"ibtracsID": names[track],
},
ignore_index=True,
}
)
# retrun data frame with all hit countries per hazard
return hit_countries
return pd.DataFrame(
hit_countries, columns=["hit_country", "Date_start", "ibtracsID"]
)


def create_lookup(emdat_data, start, end, disaster_subtype="Tropical cyclone"):
Expand Down
5 changes: 3 additions & 2 deletions climada/entity/exposures/litpop/litpop.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,17 +632,18 @@ def from_shape_and_countries(
# works if shape is Polygon or MultiPolygon
gdf = exp.gdf.loc[exp.gdf.geometry.within(shape)]
elif isinstance(shape, (geopandas.GeoSeries, list)):
gdf = geopandas.GeoDataFrame(columns=exp.gdf.columns)
idx = np.array([False] * exp.gdf.shape[0], dtype=bool)
for shp in shape:
if isinstance(
shp, (shapely.geometry.MultiPolygon, shapely.geometry.Polygon)
):
gdf = gdf.append(exp.gdf.loc[exp.gdf.geometry.within(shp)])
idx |= exp.gdf.geometry.within(shp)
else:
raise NotImplementedError(
"Not implemented for list or GeoSeries containing "
f"objects of type {type(shp)} as `shape`"
)
gdf = exp.gdf.loc[idx]
else:
raise NotImplementedError(
"Not implemented for `shape` of type {type(shape)}"
Expand Down
4 changes: 3 additions & 1 deletion climada/test/test_litpop_integr.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def test_from_shape_and_countries_zurich_pass(self):
with from_shape_and_countries()"""

ent = lp.LitPop.from_shape_and_countries(
shape, "Switzerland", res_arcsec=30, reference_year=2016
[shape, shape], "Switzerland", res_arcsec=30, reference_year=2016
)
self.assertEqual(ent.value.min(), 0.0)
self.assertEqual(ent.region_id.min(), 756)
Expand All @@ -217,6 +217,8 @@ def test_from_shape_and_countries_zurich_pass(self):
],
8.529166666666658,
)
# must be the same as for shape=`shape` or shape=`[shape]`
self.assertEqual(ent.gdf.shape, (1050, 5))

def test_Liechtenstein_15_lit_pass(self):
"""Create Nightlights entity for Liechtenstein 2016:"""
Expand Down
Loading