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

Change the loader for GMFs, to pick the rlz first, then the event id, then the IMT #876

Merged
merged 7 commits into from
Jan 10, 2025
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
50 changes: 35 additions & 15 deletions svir/dialogs/load_gmf_data_as_layer_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,33 +61,52 @@ def __init__(self, drive_engine_dlg, iface, viewer_dock, session, hostname,

self.extract_realizations()

log_msg('Extracting events. Watch progress in QGIS task bar',
level='I', message_bar=self.iface.messageBar())
self.extract_npz_task = ExtractNpzTask(
'Extract events', QgsTask.CanCancel, self.session,
self.hostname, self.calc_id, 'events', self.get_eid,
self.on_extract_error)
QgsApplication.taskManager().addTask(self.extract_npz_task)
with WaitCursorManager(
'Extracting events...', message_bar=self.iface.messageBar()):
events_npz = extract_npz(
self.session, self.hostname, self.calc_id, 'events',
message_bar=self.iface.messageBar(), params=None)

rlz_ids = np.unique(events_npz['array']['rlz_id'])

branch_paths = [f"{i}:{bp.decode('utf8')}"
for i, bp in enumerate(self.rlzs_npz['array']['branch_path'])
if i in rlz_ids]

if 'GEM_QGIS_TEST' in os.environ:
branch_path = branch_paths[0]
else:
branch_path, ok = QInputDialog.getItem(
self.drive_engine_dlg,
'Select a realization',
'Realization',
branch_paths,
0)
if not ok:
self.reject()
return

self.rlz_id = int(branch_path.split(':')[0])
self.set_eid(events_npz)

def get_closest_element(self, element, elements):
return elements[np.abs(elements - element).argmin()]

def get_eid(self, events_npz):
def set_eid(self, events_npz):
self.events_npz = events_npz
events = events_npz['array']
self.eid = -1 # assuming events start from 0
events = events[events['rlz_id'] == self.rlz_id]

if 'GEM_QGIS_TEST' in os.environ:
self.eid = self.get_closest_element(self.eid, events['id'])
self.eid = events['id'][0]
ok = True
elif 'scenario' in self.calculation_mode:
ids_str = ''
for gsim_idx, gsim in enumerate(self.gsims):
ids = events[events['rlz_id'] == gsim_idx]['id']
ids_str += '\n%s: %s' % (gsim, ids)
input_msg = "Events:%s" % ids_str
input_msg = f"Events: {events['id']}"
else:
input_msg = "Range (%s - %s)" % (events[0]['id'], events[-1]['id'])

if 'GEM_QGIS_TEST' not in os.environ:
self.eid = -1 # assuming events start from 0
while self.eid not in events['id']:
if self.eid == -1:
is_first_iteration = True
Expand All @@ -110,6 +129,7 @@ def get_eid(self, events_npz):
if not ok:
self.reject()
return

log_msg('Extracting ground motion fields.'
' Watch progress in QGIS task bar',
level='I', message_bar=self.iface.messageBar())
Expand Down
5 changes: 3 additions & 2 deletions svir/metadata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ [email protected]
# Uncomment the following line and add your changelog entries:
changelog=
3.22.0
* The loader for ground motion fields was modified, so the user selects the realization first, then the event id, then the IMT used for styling the layer
* Support for social vulnerability and recovery modeling was removed
* Added the possibility to display total aggregated loss curves
3.21.1
Expand Down Expand Up @@ -213,7 +214,7 @@ changelog=
* Geopackages containing polygons for the aggregation of points by zone can be pre-loaded, selecting the desired layers from the package
* An additional checkbox gives the possibility to automatically discard zones that contain no points
* Improved legends and classification criteria, depending on the unique values present in the field used for styling
* The menu action to aggregate loss by zone was re-added, pointing to the Processing Toolkit algorithm that we use now to perform the
* The menu action to aggregate loss by zone was re-added, pointing to the Processing Toolkit algorithm that we use now to perform the
same kind of analysis (i.e. "Join attributes by location (summary)"). The section of the user manual that was previously removed is
partially restored, and there is an explanation on how to use the Processing algorithm to obtain the same results that were obtained
by the plugin tool before.
Expand All @@ -233,7 +234,7 @@ changelog=
3.3.0
* Fixed loader for aggregated Average Asset Losses Statistics OQ-Engine output
* All calls to the OQ-Engine "extract" API are logged
* Fixed a bug that caused the log verbosity to be always set to "warning", instead of reading it correctly from user settings
* Fixed a bug that caused the log verbosity to be always set to "warning", instead of reading it correctly from user settings
3.2.12
* More stable connection with the OQ-Engine server, preventing issues while reading the console log of a calculation
3.2.11
Expand Down
Loading