def compute(self, ruptures, rupture_seeds, rupture_ids, maximum_distance): """ Compute ground motion values radiated from `ruptures`. :param ruptures: an iterator over N :class:`openquake.hazardlib.source.rupture.Rupture` instances :param rupture_seeds: an interator over N integer values to be used to initialize the RNG :param rupture_ids: an iterator over N integer values. Each of them uniquely identifies the corresponding `rupture` :param float maximum_distance: the maximum distance threshold used to filter the sites to be considered for each rupture :returns: a tuple with two elements. The first one is a list of A numpy array. Each of them contains the ground motion values associated with an asset. The second element contains the list of A assets considered. """ all_gmvs = [] all_assets = [] site_gmv = collections.defaultdict(dict) performance_dict = collections.Counter() for rupture, rupture_seed, rupture_id in itertools.izip( ruptures, rupture_seeds, rupture_ids): gsim, tstddev = self.gsim(rupture) with LightMonitor(performance_dict, 'filtering sites'): sites_of_interest, mask = self.sites_of_interest( rupture, maximum_distance) if not sites_of_interest: continue with LightMonitor(performance_dict, 'generating epsilons'): (total, inter, intra) = self.epsilons(rupture_seed, mask, tstddev) with LightMonitor(performance_dict, 'compute ground motion fields'): gmf = ground_motion_field_with_residuals( rupture, sites_of_interest, self.imt, gsim, self.truncation_level, total_residual_epsilons=total, intra_residual_epsilons=intra, inter_residual_epsilons=inter) with LightMonitor(performance_dict, 'collecting gmvs'): for site, gmv in itertools.izip(sites_of_interest, gmf): site_gmv[site.id][rupture_id] = gmv logs.LOG.debug('Disaggregation of the time spent in the loop %s' % (performance_dict)) for site_id, assets in self.sites_assets: n_assets = len(assets) if site_id in site_gmv: gmvs = [site_gmv[site_id].get(r, 0) for r in rupture_ids] else: gmvs = numpy.zeros(len(rupture_ids)) del site_gmv[site_id] all_gmvs.extend([gmvs] * n_assets) all_assets.extend(assets) return all_assets, all_gmvs