diff --git a/svir/dialogs/load_gmf_data_as_layer_dialog.py b/svir/dialogs/load_gmf_data_as_layer_dialog.py index 1c0eb7af3..24745dbe4 100644 --- a/svir/dialogs/load_gmf_data_as_layer_dialog.py +++ b/svir/dialogs/load_gmf_data_as_layer_dialog.py @@ -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 @@ -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()) diff --git a/svir/metadata.txt b/svir/metadata.txt index 7e1e9f667..bfe8b3782 100644 --- a/svir/metadata.txt +++ b/svir/metadata.txt @@ -24,6 +24,7 @@ email=staff.it@globalquakemodel.org # 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 @@ -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. @@ -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