Skip to content

Commit

Permalink
Fix management of damage states
Browse files Browse the repository at this point in the history
  • Loading branch information
ptormene committed Oct 24, 2024
1 parent 25eeca9 commit 72a7ef2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
17 changes: 9 additions & 8 deletions svir/dialogs/load_damages_rlzs_as_layer_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from svir.utilities.utils import (WaitCursorManager,
log_msg,
get_loss_types,
get_attrs,
)
from svir.tasks.extract_npz_task import ExtractNpzTask

Expand Down Expand Up @@ -77,11 +78,12 @@ def finalize_init(self, extracted_npz):
self.npz_file = extracted_npz

# NOTE: still running this synchronously, because it's small stuff
with WaitCursorManager('Loading loss types...',
with WaitCursorManager('Loading loss types and damage_states...',
self.iface.messageBar()):
self.loss_types = get_loss_types(
self.session, self.hostname, self.calc_id,
self.iface.messageBar())
attrs = get_attrs(self.session, self.hostname, self.calc_id,
self.iface.messageBar())
self.loss_types = attrs['loss_types']
self.dmg_states = ['no_damage'] + attrs['limit_states']

self.populate_out_dep_widgets()

Expand Down Expand Up @@ -131,7 +133,7 @@ def populate_taxonomy_cbx(self, taxonomies):
self.taxonomy_cbx.setEnabled(True)

def on_loss_type_changed(self):
self.dmg_states = self.dataset.dtype.names
# self.dmg_states = self.dataset.dtype.names
self.populate_dmg_state_cbx()

def populate_dmg_state_cbx(self):
Expand Down Expand Up @@ -251,13 +253,12 @@ def read_npz_into_layer_aggr_by_site(self, field_types, **kwargs):
log_msg(msg, level='C', message_bar=self.iface.messageBar())
return self.layer

def group_by_site(self, npz, rlz_or_stat, loss_type, dmg_state,
taxonomy='All'):
def group_by_site(self, npz, rlz_or_stat, loss_type, dmg_state, taxonomy='All'):
F32 = numpy.float32
dmg_by_site = collections.defaultdict(float) # lon, lat -> dmg
for rec in npz[rlz_or_stat]:
if taxonomy == 'All' or taxonomy.encode('utf8') == rec['taxonomy']:
value = rec[loss_type][dmg_state]
value = rec[dmg_state]
dmg_by_site[rec['lon'], rec['lat']] += value
data = numpy.zeros(
len(dmg_by_site),
Expand Down
14 changes: 6 additions & 8 deletions svir/utilities/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1193,14 +1193,12 @@ def check_is_lockdown(hostname, session):


def get_loss_types(session, hostname, calc_id, message_bar):
composite_risk_model_attrs = extract_npz(
session, hostname, calc_id, 'composite_risk_model.attrs',
message_bar=message_bar)
# casting loss_types to string, otherwise numpy complains when creating
# array of zeros with data type as follows:
# [('lon', F32), ('lat', F32), (loss_type, F32)])
loss_types = composite_risk_model_attrs['loss_types']
return loss_types
return get_attrs(session, hostname, calc_id, message_bar)['loss_types']


def get_attrs(session, hostname, calc_id, message_bar):
return extract_npz(session, hostname, calc_id, 'composite_risk_model.attrs',
message_bar=message_bar)


def write_metadata_to_layer(
Expand Down

0 comments on commit 72a7ef2

Please sign in to comment.