def within_bbox(self, srcs): """ :param srcs: a list of source objects :returns: the site IDs within the enlarged bounding box of the sources """ if self.sitecol is None: # for test_case_1_ruptures return [0] lons = [] lats = [] for src in srcs: try: box = self.integration_distance.get_affected_box(src) except BBoxError as exc: logging.error(exc) continue lons.append(box[0]) lats.append(box[1]) lons.append(box[2]) lats.append(box[3]) if cross_idl(*(list(self.sitecol.lons) + lons)): lons = numpy.array(lons) % 360 else: lons = numpy.array(lons) bbox = (lons.min(), min(lats), lons.max(), max(lats)) if bbox[2] - bbox[0] > 180: raise BBoxError( 'The bounding box of the sources is larger than half ' 'the globe: %d degrees' % (bbox[2] - bbox[0])) return self.sitecol.within_bbox(bbox)
def _check_csm(csm, oqparam, h5): # checks csm.gsim_lt.check_imts(oqparam.imtls) srcs = csm.get_sources() if not srcs: raise RuntimeError('All sources were discarded!?') if os.environ.get('OQ_CHECK_INPUT'): source.check_complex_faults(srcs) # build a smart SourceFilter try: sitecol = get_site_collection(oqparam, h5) # already stored except Exception: # missing sites.csv in test_case_1_ruptures sitecol = None csm.sitecol = sitecol if sitecol is None: return srcfilter = SourceFilter(sitecol, oqparam.maximum_distance) logging.info('Checking the sources bounding box') lons = [] lats = [] for src in srcs: try: box = srcfilter.get_enlarged_box(src) except BBoxError as exc: logging.error(exc) continue lons.append(box[0]) lats.append(box[1]) lons.append(box[2]) lats.append(box[3]) if cross_idl(*(list(sitecol.lons) + lons)): lons = numpy.array(lons) % 360 else: lons = numpy.array(lons) bbox = (lons.min(), min(lats), lons.max(), max(lats)) if bbox[2] - bbox[0] > 180: raise BBoxError( 'The bounding box of the sources is larger than half ' 'the globe: %d degrees' % (bbox[2] - bbox[0])) sids = sitecol.within_bbox(bbox) if len(sids) == 0: raise RuntimeError('All sources were discarded!?')