Skip to content

Commit

Permalink
Fix loader for damages_rlzs, getting damage states and reading values…
Browse files Browse the repository at this point in the history
… as loss_type-dmg_state
  • Loading branch information
ptormene committed Nov 25, 2024
1 parent 965071b commit 07126fb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
19 changes: 8 additions & 11 deletions svir/dialogs/load_damages_rlzs_as_layer_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from svir.dialogs.load_output_as_layer_dialog import LoadOutputAsLayerDialog
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 +77,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 @@ -122,6 +123,7 @@ def on_rlz_or_stat_changed(self):
def populate_out_dep_widgets(self):
self.populate_rlz_or_stat_cbx()
self.populate_loss_type_cbx(self.loss_types)
self.populate_dmg_state_cbx()
self.show_num_sites()

def populate_taxonomy_cbx(self, taxonomies):
Expand All @@ -130,11 +132,6 @@ def populate_taxonomy_cbx(self, taxonomies):
self.taxonomy_cbx.addItems(taxonomies)
self.taxonomy_cbx.setEnabled(True)

def on_loss_type_changed(self):
loss_type = self.loss_type_cbx.currentText()
self.dmg_states = self.dataset[loss_type].dtype.names
self.populate_dmg_state_cbx()

def populate_dmg_state_cbx(self):
self.dmg_state_cbx.clear()
self.dmg_state_cbx.setEnabled(True)
Expand Down Expand Up @@ -258,7 +255,7 @@ def group_by_site(self, npz, rlz_or_stat, loss_type, dmg_state,
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[f'{loss_type}-{dmg_state}']
dmg_by_site[rec['lon'], rec['lat']] += value
data = numpy.zeros(
len(dmg_by_site),
Expand Down
5 changes: 5 additions & 0 deletions svir/utilities/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1179,6 +1179,11 @@ def get_loss_types(session, hostname, calc_id, message_bar):
return 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(
drive_engine_dlg, output_type, layer, user_params=None,
disagg_params=None):
Expand Down

0 comments on commit 07126fb

Please sign in to comment.