Skip to content

Commit

Permalink
Removed area_types
Browse files Browse the repository at this point in the history
  • Loading branch information
micheles committed Oct 18, 2024
1 parent f96468c commit 806a8f5
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions openquake/risklib/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,10 @@ class CostCalculator(object):
The same "formula" applies to retrofitting cost.
"""
def __init__(self, cost_types, area_types, units, tagi={'taxonomy': 0}):
if set(cost_types) != set(area_types):
raise ValueError('cost_types has keys %s, area_types has keys %s'
% (sorted(cost_types), sorted(area_types)))
def __init__(self, cost_types, units, tagi={'taxonomy': 0}):
for ct in cost_types.values():
assert ct in ('aggregated', 'per_asset', 'per_area'), ct
for at in area_types.values():
assert at in ('aggregated', 'per_asset'), at
self.cost_types = cost_types
self.area_types = area_types
self.units = units
self.tagi = tagi

Expand Down Expand Up @@ -142,7 +136,7 @@ def __call__(self, loss_type, assetcol):
if cost_type == "per_asset":
return cost * number
if cost_type == "per_area":
area_type = self.area_types[loss_type]
area_type = self.cost_types['area']
if area_type == "aggregated":
return cost * area
elif area_type == "per_asset":
Expand Down Expand Up @@ -657,11 +651,10 @@ def _get_exposure(fname, stop=None):
cost_types.sort(key=operator.itemgetter(0))
cost_types = numpy.array(cost_types, cost_type_dt)
cc = CostCalculator(
{}, {}, {}, {name: i for i, name in enumerate(tagnames)})
{}, {}, {name: i for i, name in enumerate(tagnames)})
for ct in cost_types:
name = ct['name'] # structural, nonstructural, ...
cc.cost_types[name] = ct['type'] # aggregated, per_asset, per_area
cc.area_types[name] = get_area_type(cost_types)
cc.units[name] = ct['unit']
exp = Exposure(occupancy_periods, [], cc, TagCollection(tagnames), pairs)
assets_text = xml.assets.text.strip()
Expand Down Expand Up @@ -883,12 +876,9 @@ class Exposure(object):
def __toh5__(self):
cc = self.cost_calculator
loss_types = sorted(cc.cost_types)
dt = numpy.dtype([('cost_type', hdf5.vstr),
('area_type', hdf5.vstr),
('unit', hdf5.vstr)])
dt = numpy.dtype([('cost_type', hdf5.vstr), ('unit', hdf5.vstr)])
array = numpy.zeros(len(loss_types), dt)
array['cost_type'] = [cc.cost_types[lt] for lt in loss_types]
array['area_type'] = [cc.area_types[lt] for lt in loss_types]
array['unit'] = [cc.units[lt] for lt in loss_types]
attrs = dict(
loss_types=hdf5.array_of_vstr(loss_types),
Expand All @@ -900,7 +890,6 @@ def __fromh5__(self, array, attrs):
vars(self).update(attrs)
cc = self.cost_calculator = object.__new__(CostCalculator)
cc.cost_types = dict(zip(self.loss_types, decode(array['cost_type'])))
cc.area_types = dict(zip(self.loss_types, decode(array['area_type'])))
cc.units = dict(zip(self.loss_types, decode(array['unit'])))

@staticmethod
Expand Down

0 comments on commit 806a8f5

Please sign in to comment.