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

add at_reg_id_event #642

Merged
merged 22 commits into from
Mar 1, 2023
Merged
Changes from 1 commit
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
24 changes: 22 additions & 2 deletions climada/engine/impact.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def __init__(self,
crs=DEF_CRS,
eai_exp=None,
at_event=None,
at_reg_id_event=None,
tot_value=0,
aai_agg=0,
unit='',
Expand Down Expand Up @@ -129,6 +130,8 @@ def __init__(self,
expected impact for each exposure within a period of 1/frequency_unit
at_event : np.array, optional
impact for each hazard event
at_reg_id_event : np.array, optional
impact for each hazard event at each exposure region id
tot_value : float, optional
total exposure value affected
aai_agg : float, optional
Expand All @@ -150,6 +153,7 @@ def __init__(self,
self.crs = crs
self.eai_exp = np.array([], float) if eai_exp is None else eai_exp
self.at_event = np.array([], float) if at_event is None else at_event
self.at_reg_id_event = np.array([], float) if at_reg_id_event is None else at_reg_id_event
aleeciu marked this conversation as resolved.
Show resolved Hide resolved
self.frequency = np.array([],float) if frequency is None else frequency
self.frequency_unit = frequency_unit
self.tot_value = tot_value
Expand Down Expand Up @@ -191,8 +195,6 @@ def __init__(self,
else:
self.imp_mat = sparse.csr_matrix(np.empty((0, 0)))



def calc(self, exposures, impact_funcs, hazard, save_mat=False, assign_centroids=True):
"""This function is deprecated, use ``ImpactCalc.impact`` instead.
"""
Expand Down Expand Up @@ -390,6 +392,24 @@ def impact_per_year(self, all_years=True, year_range=None):
year_set[year] = sum(self.at_event[orig_year == year])
return year_set

def impact_per_exp_reg(self, exposures):
aleeciu marked this conversation as resolved.
Show resolved Hide resolved
"""Aggregate impact matrix at the regional level, based on the
regions specified in the exposure.

Parameters
----------
exposures : climada.entity.Exposures
exposure used to compute imp_mat
Returns
-------
np.matrix
"""
aleeciu marked this conversation as resolved.
Show resolved Hide resolved
self.at_reg_id_event = np.hstack([
self.imp_mat[:, np.where(exposures.gdf.region_id == reg_id)[0]].sum(1)
aleeciu marked this conversation as resolved.
Show resolved Hide resolved
for reg_id in exposures.gdf.region_id.unique()
])
return self.at_reg_id_event

def calc_impact_year_set(self,all_years=True, year_range=None):
"""This function is deprecated, use Impact.impact_per_year instead."""
LOGGER.warning("The use of Impact.calc_impact_year_set is deprecated."
Expand Down