def assoc_assets_sites(self, sitecol): """ :param sitecol: a sequence of sites :returns: a pair (filtered_sites, assets_by_site) The new site collection is different from the original one if some assets were discarded or if there were missing assets for some sites. """ maximum_distance = self.oqparam.asset_hazard_distance siteobjects = geodetic.GeographicObjects( Site(sid, lon, lat) for sid, lon, lat in zip(sitecol.sids, sitecol.lons, sitecol.lats)) assets_by_sid = general.AccumDict() for assets in self.assets_by_site: if len(assets): lon, lat = assets[0].location site, _ = siteobjects.get_closest(lon, lat, maximum_distance) if site: assets_by_sid += {site.sid: list(assets)} if not assets_by_sid: raise AssetSiteAssociationError( 'Could not associate any site to any assets within the ' 'maximum distance of %s km' % maximum_distance) mask = numpy.array([sid in assets_by_sid for sid in sitecol.sids]) assets_by_site = [assets_by_sid.get(sid, []) for sid in sitecol.sids] return sitecol.filter(mask), numpy.array(assets_by_site)
def setUp(self): p1 = Point(0.0, 0.1) p2 = Point(0.0, 0.2) p3 = Point(0.0, 0.3) self.points = geodetic.GeographicObjects([p1, p2, p3])