def setUp(self): # simple logic tree with 3 realizations # ___/ b11 (w=.2) # _/ \ b12 (w=.2) # \____ b02 (w=.6) self.bs0 = bs0 = lt.BranchSet('abGRAbsolute') bs0.branches = [ lt.Branch('bs0', 'b01', .4, (4.6, 1.1)), lt.Branch('bs0', 'b02', .6, (4.4, 0.9)) ] self.bs1 = bs1 = lt.BranchSet('maxMagGRAbsolute') bs1.branches = [ lt.Branch('bs1', 'b11', .5, 7.0), lt.Branch('bs1', 'b12', .5, 7.6) ] bs0.branches[0].bset = bs1 # setup sitecol, srcfilter, gsims, imtls sitecol = site.SiteCollection( [site.Site(Point(0, 0), numpy.array([760.]))]) self.srcfilter = calc.filters.SourceFilter(sitecol, {'default': 200}) self.gsims = [valid.gsim('ToroEtAl2002')] self.imtls = DictArray({'PGA': valid.logscale(.01, 1, 5)}) self.sg = sourceconverter.SourceGroup(ps.tectonic_region_type, [ps])
def get_site_collection(oqparam, mesh=None): """ Returns a SiteCollection instance by looking at the points and the site model defined by the configuration parameters. :param oqparam: an :class:`openquake.commonlib.oqvalidation.OqParam` instance :param mesh: a mesh of hazardlib points; if None the mesh is determined by invoking get_mesh """ if mesh is None: mesh = get_mesh(oqparam) if mesh is None: return if oqparam.inputs.get('site_model'): sitecol = [] if getattr(mesh, 'from_site_model', False): for param in sorted(get_site_model(oqparam)): pt = geo.Point(param.lon, param.lat, param.depth) sitecol.append( site.Site(pt, param.vs30, param.measured, param.z1pt0, param.z2pt5, param.backarc)) return site.SiteCollection(sitecol) # read the parameters directly from their file site_model_params = geo.utils.GeographicObjects( get_site_model(oqparam)) for pt in mesh: # attach the closest site model params to each site param, dist = site_model_params.get_closest( pt.longitude, pt.latitude) if dist >= oqparam.max_site_model_distance: logging.warn('The site parameter associated to %s came from a ' 'distance of %d km!' % (pt, dist)) sitecol.append( site.Site(pt, param.vs30, param.measured, param.z1pt0, param.z2pt5, param.backarc)) if len(sitecol) == 1 and oqparam.hazard_maps: logging.warn('There is a single site, hazard_maps=true ' 'has little sense') return site.SiteCollection(sitecol) # else use the default site params return site.SiteCollection.from_points(mesh.lons, mesh.lats, mesh.depths, oqparam)
def setUpClass(cls): conv = s.SourceConverter( investigation_time=50., rupture_mesh_spacing=1, # km complex_fault_mesh_spacing=1, # km width_of_mfd_bin=1., # for Truncated GR MFDs area_source_discretization=1.) cls.source_collector = { sc.trt: sc for sc in nrml.to_python(MIXED_SRC_MODEL, conv)} cls.sitecol = site.SiteCollection(cls.SITES)
def setUpClass(cls): cls.converter = s.SourceConverter( investigation_time=50., rupture_mesh_spacing=1, # km complex_fault_mesh_spacing=1, # km width_of_mfd_bin=1., # for Truncated GR MFDs area_source_discretization=1.) cls.source_collector = dict((sc.trt, sc) for sc in parse_source_model( MIXED_SRC_MODEL, cls.converter, lambda src: None)) cls.sitecol = site.SiteCollection(cls.SITES)
def setUpClass(cls): cls.parser = SourceModelParser(s.SourceConverter( investigation_time=50., rupture_mesh_spacing=1, # km complex_fault_mesh_spacing=1, # km width_of_mfd_bin=1., # for Truncated GR MFDs area_source_discretization=1.)) cls.source_collector = { sc.trt: sc for sc in cls.parser.parse_trt_models(MIXED_SRC_MODEL)} cls.sitecol = site.SiteCollection(cls.SITES)
def read_site_col(site_model_file): """Directly read a site colection from nrml """ sitecol = [] for param in sorted(get_site_model(site_model_file)): pt = geo.Point(param.lon, param.lat, 0.) sitecol.append( site.Site(pt, param.vs30, param.measured, param.z1pt0, param.z2pt5, param.backarc)) return site.SiteCollection(sitecol)
def get_site_collection(oqparam, mesh=None, site_ids=None, site_model_params=None): """ Returns a SiteCollection instance by looking at the points and the site model defined by the configuration parameters. :param oqparam: an :class:`openquake.commonlib.oqvalidation.OqParam` instance :param mesh: a mesh of hazardlib points; if None the mesh is determined by invoking get_mesh :param site_ids: a list of integers to identify the points; if None, a range(1, len(points) + 1) is used :param site_model_params: object with a method .get_closest returning the closest site model parameters """ if mesh is None: mesh = get_mesh(oqparam) if mesh is None: return site_ids = site_ids or list(range(len(mesh))) if oqparam.inputs.get('site_model'): if site_model_params is None: # read the parameters directly from their file site_model_params = geo.geodetic.GeographicObjects( get_site_model(oqparam)) sitecol = [] for i, pt in zip(site_ids, mesh): # NB: the mesh, when read from the datastore, is a 32 bit array; # however, the underlying C library expects 64 bit floats, thus # we have to cast float(pt.longitude), float(pt.latitude); # we should change the geodetic speedups instead param, dist = site_model_params.\ get_closest(float(pt.longitude), float(pt.latitude)) if dist >= MAX_SITE_MODEL_DISTANCE: logging.warn('The site parameter associated to %s came from a ' 'distance of %d km!' % (pt, dist)) sitecol.append( site.Site(pt, param.vs30, param.measured, param.z1pt0, param.z2pt5, param.backarc, i)) return site.SiteCollection(sitecol) # else use the default site params return site.SiteCollection.from_points(mesh.lons, mesh.lats, site_ids, oqparam)
def get_site_collection(site_model_file, sites, site_model_params=None, filename=None): """ Returns a SiteCollection instance by looking at the points and the site model defined by the configuration parameters. :param site_model_file: path to the site_model nrml file :param sites: Locations of hazard points that :param site_model_params: object with a method .get_closest returning the closest site model parameters :param filename: path to output nrml file where new site model will be written, if this parameter is specified. """ if site_model_params is None: # read the parameters directly from their file site_model_params = geo.geodetic.GeographicObjects( get_site_model(site_model_file)) sitecol = [] for pt in sites: # NB: the mesh, when read from the datastore, is a 32 bit array; # however, the underlying C library expects 64 bit floats, thus # we have to cast float(pt.longitude), float(pt.latitude); # we should change the geodetic speedups instead param, dist = site_model_params.\ get_closest(float(pt.longitude), float(pt.latitude)) if dist >= MAX_SITE_MODEL_DISTANCE: #logging.warn('The site parameter associated to %s came from a ' # 'distance of %d km!' % (pt, dist)) print 'WARNING:The site parameter associated to %s came from a ' \ 'distance of %d km!' % (pt, dist) sitecol.append( site.Site(pt, param.vs30, param.measured, param.z1pt0, param.z2pt5, param.backarc)) if filename is not None: name = filename.split('/')[-1][:-4] site_nodes = list(map(obj_to_node, sitecol)) #sorted(sitecol))) #print site_nodes site_model = Node("siteModel", nodes=site_nodes) #site_model = site_nodes #print site_model with open(filename, 'wb') as f: nrml.write(site_model, f, '%s', xmlns=NAMESPACE) # nrml.write([site_model], f, '%s', xmlns = NAMESPACE) return site.SiteCollection(sitecol)
def get_site_collection(oqparam, mesh=None, site_ids=None, site_model_params=None): """ Returns a SiteCollection instance by looking at the points and the site model defined by the configuration parameters. :param oqparam: an :class:`openquake.commonlib.oqvalidation.OqParam` instance :param mesh: a mesh of hazardlib points; if None the mesh is determined by invoking get_mesh :param site_ids: a list of integers to identify the points; if None, a range(1, len(points) + 1) is used :param site_model_params: object with a method .get_closest returning the closest site model parameters """ if mesh is None: mesh = get_mesh(oqparam) site_ids = site_ids or list(range(len(mesh))) if oqparam.inputs.get('site_model'): if site_model_params is None: # read the parameters directly from their file site_model_params = geo.geodetic.GeographicObjects( get_site_model(oqparam)) sitecol = [] for i, pt in zip(site_ids, mesh): param = site_model_params.\ get_closest(pt.longitude, pt.latitude) sitecol.append( site.Site(pt, param.vs30, param.measured, param.z1pt0, param.z2pt5, param.backarc, i)) return site.SiteCollection(sitecol) # else use the default site params return site.SiteCollection.from_points(mesh.lons, mesh.lats, site_ids, oqparam)