def setUp(self): self.imts = ["PGA", "PGV"] self.periods = [0.05, 0.075, 0.1, 0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18, 0.19, 0.20, 0.22, 0.24, 0.26, 0.28, 0.30, 0.32, 0.34, 0.36, 0.38, 0.40, 0.42, 0.44, 0.46, 0.48, 0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 3.0, 4.001, 5.0, 7.5, 10.0] self.gsims = ["AbrahamsonEtAl2014", "AbrahamsonEtAl2014NSHMPLower", "AbrahamsonEtAl2014NSHMPMean", "AbrahamsonEtAl2014NSHMPUpper", "AbrahamsonEtAl2014RegCHN", "AbrahamsonEtAl2014RegJPN", "AbrahamsonEtAl2014RegTWN", "AkkarBommer2010SWISS01", "AkkarBommer2010SWISS04", "AkkarBommer2010SWISS08", "AkkarEtAl2013", "AkkarEtAlRepi2014"] # this set of parameters raised exceptions, as e.g. # AkkarBommer2010SWISS01's PGV eas empty vs30 = 760.0 self.params = {"magnitude": np.array([3, 4]), "distance": np.array([10, 11, 12]), "dip": 60, "aspect": 1.5, "rake": 0.0, "ztor": 0.0, "strike": 0.0, "msr": get_available_magnitude_scalerel()["WC1994"], "initial_point": Point(0, 0), "hypocentre_location": [0.5, 0.5], "vs30": vs30, "vs30_measured": True, "line_azimuth": 0.0, "backarc": False, "z1pt0": vs30_to_z1pt0_cy14(vs30), "z2pt5": vs30_to_z2pt5_cb14(vs30)}
def update_sites_context(self, record, context): '''Updates the attributes of `context` with the given `record` data. `context` is a :class:`openquake.hazardlib.contexts.SitesContext` object. In the typical implementation it has the attributes defined in `self.sites_context_attrs` all initialized to empty lists. Here you should append to those attributes the relative record value, e.g.: `context.vs30.append(record.vs30)` ''' context.vs30.append(record.site.vs30) context.lons.append(record.site.longitude) context.lats.append(record.site.latitude) if record.site.altitude: depth = record.site.altitude * -1.0E-3 else: depth = 0.0 context.depths.append(depth) if record.site.vs30_measured is not None: vs30_measured = record.site.vs30_measured else: vs30_measured = 0 context.vs30measured.append(vs30_measured) if record.site.z1pt0 is not None: z1pt0 = record.site.z1pt0 else: z1pt0 = vs30_to_z1pt0_cy14(record.site.vs30) context.z1pt0.append(z1pt0) if record.site.z2pt5 is not None: z2pt5 = record.site.z2pt5 else: z2pt5 = vs30_to_z2pt5_cb14(record.site.vs30) context.z2pt5.append(z2pt5) if getattr(record.site, "backarc", None) is not None: context.backarc.append(record.site.backarc)
def _get_sites_context_event(self, idx): """ Returns the site context for a particular event """ sctx = SitesContext() longs = [] lats = [] depths = [] vs30 = [] vs30_measured = [] z1pt0 = [] z2pt5 = [] backarc = [] azimuth = [] hanging_wall = [] for idx_j in idx: # Site parameters rup = self.records[idx_j] longs.append(rup.site.longitude) lats.append(rup.site.latitude) if rup.site.altitude: depths.append(rup.site.altitude * -1.0E-3) else: depths.append(0.0) vs30.append(rup.site.vs30) if rup.site.vs30_measured is not None: vs30_measured.append(rup.site.vs30_measured) else: vs30_measured.append(0) if rup.site.z1pt0 is not None: z1pt0.append(rup.site.z1pt0) else: z1pt0.append(vs30_to_z1pt0_cy14(rup.site.vs30)) if rup.site.z2pt5 is not None: z2pt5.append(rup.site.z2pt5) else: z2pt5.append(vs30_to_z2pt5_cb14(rup.site.vs30)) if ("backarc" in dir(rup.site)) and rup.site.backarc is not None: backarc.append(rup.site.backarc) setattr(sctx, 'vs30', np.array(vs30)) if len(longs) > 0: setattr(sctx, 'lons', np.array(longs)) if len(lats) > 0: setattr(sctx, 'lats', np.array(lats)) if len(depths) > 0: setattr(sctx, 'depths', np.array(depths)) if len(vs30_measured) > 0: setattr(sctx, 'vs30measured', np.array(vs30_measured)) if len(z1pt0) > 0: setattr(sctx, 'z1pt0', np.array(z1pt0)) if len(z2pt5) > 0: setattr(sctx, 'z2pt5', np.array(z2pt5)) if len(backarc) > 0: setattr(sctx, 'backarc', np.array(backarc)) return sctx
def _parse_site_data(self, metadata): """ Parses the site information """ network_code = metadata["network_code"].strip() station_code = metadata["station_code"].strip() site_id = "{:s}-{:s}".format(network_code, station_code) location_code = metadata["location_code"].strip() site_lon = valid.longitude(metadata["st_longitude"]) site_lat = valid.latitude(metadata["st_latitude"]) elevation = valid.vfloat(metadata["st_elevation"], "st_elevation") vs30 = valid.vfloat(metadata["vs30_m_sec"], "vs30_m_sec") vs30_topo = valid.vfloat(metadata["vs30_m_sec_WA"], "vs30_m_sec_WA") if vs30: vs30_measured = True elif vs30_topo: vs30 = vs30_topo vs30_measured = False else: vs30_measured = False st_nation_code = metadata["st_nation_code"].strip() if st_nation_code: st_country = COUNTRY_CODES[st_nation_code] else: st_country = None site = RecordSite(site_id, station_code, station_code, site_lon, site_lat, elevation, vs30, vs30_measured, network_code=network_code, country=st_country) site.slope = valid.vfloat(metadata["slope_deg"], "slope_deg") site.sensor_depth = valid.vfloat(metadata["sensor_depth_m"], "sensor_depth_m") site.instrument_type = metadata["instrument_code"].strip() if site.vs30: site.z1pt0 = vs30_to_z1pt0_cy14(vs30) site.z2pt5 = vs30_to_z2pt5_cb14(vs30) housing_code = metadata["housing_code"].strip() if housing_code and (housing_code in HOUSING): site.building_structure = HOUSING[housing_code] return site
def setUp(self): self.imts = ["PGA", "PGV"] self.periods = [ 0.05, 0.075, 0.1, 0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18, 0.19, 0.20, 0.22, 0.24, 0.26, 0.28, 0.30, 0.32, 0.34, 0.36, 0.38, 0.40, 0.42, 0.44, 0.46, 0.48, 0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 3.0, 4.001, 5.0, 7.5, 10.0 ] self.gsims = [ "AbrahamsonEtAl2014", # "AbrahamsonEtAl2014NSHMPLower", # "AbrahamsonEtAl2014NSHMPMean", # "AbrahamsonEtAl2014NSHMPUpper", "AbrahamsonEtAl2014RegCHN", "AbrahamsonEtAl2014RegJPN", "AbrahamsonEtAl2014RegTWN", "AkkarBommer2010SWISS01", "AkkarBommer2010SWISS04", "AkkarBommer2010SWISS08", "AkkarEtAl2013", "AkkarEtAlRepi2014" ] # this set of parameters raised exceptions, as e.g. # AkkarBommer2010SWISS01's PGV eas empty vs30 = 760.0 self.params = { "magnitude": np.array([3, 4]), "distance": np.array([10, 11, 12]), "dip": 60, "aspect": 1.5, "rake": 0.0, "ztor": 0.0, "strike": 0.0, "msr": get_available_magnitude_scalerel()["WC1994"], "initial_point": Point(0, 0), "hypocentre_location": [0.5, 0.5], "vs30": vs30, "vs30_measured": True, "line_azimuth": 0.0, "backarc": False, "z1pt0": vs30_to_z1pt0_cy14(vs30), "z2pt5": vs30_to_z2pt5_cb14(vs30) }
def _update_sites_context(self, ctx, records): """Called by self.update_context""" for attname in self.sites_context_attrs: setattr(ctx, attname, []) for record in records: ctx.vs30.append(record.site.vs30) ctx.lons.append(record.site.longitude) ctx.lats.append(record.site.latitude) if record.site.altitude: depth = record.site.altitude * -1.0E-3 else: depth = 0.0 ctx.depths.append(depth) if record.site.vs30_measured is not None: vs30_measured = record.site.vs30_measured else: vs30_measured = 0 ctx.vs30measured.append(vs30_measured) if record.site.z1pt0 is not None: z1pt0 = record.site.z1pt0 else: z1pt0 = vs30_to_z1pt0_cy14(record.site.vs30) ctx.z1pt0.append(z1pt0) if record.site.z2pt5 is not None: z2pt5 = record.site.z2pt5 else: z2pt5 = vs30_to_z2pt5_cb14(record.site.vs30) ctx.z2pt5.append(z2pt5) if getattr(record.site, "backarc", None) is not None: ctx.backarc.append(record.site.backarc) # finalize: for attname in self.sites_context_attrs: attval = getattr(ctx, attname) # remove attribute if its value is empty-like if attval is None or not len(attval): delattr(ctx, attname) elif attname in ('vs30measured', 'backarc'): setattr(ctx, attname, np.asarray(attval, dtype=bool)) else: # dtype=float forces Nones to be safely converted to nan setattr(ctx, attname, np.asarray(attval, dtype=float))