def gr2inc_mmax(mfd, mmaxs, weights, model_weight=1.): """Function to convert a GR distribution to incremental MFD and collapse Mmax logic tree branches :params model_weight: weight of total model, i.e. multiply all rates by this weight """ mfd_type = type(mfd).__name__ # print mfd_type if mfd_type != 'TruncatedGRMFD': msg = 'Input MFD should be of type TruncatedGRMFD, found type %s' % mfd_type raise TypeError(msg) # Ensure we get rates for all mmax values mfd.max_mag = max(mmaxs) mag_bins, rates = zip(*mfd.get_annual_occurrence_rates()) mag_bins = np.array(mag_bins) rates = np.array(rates) # print 'mag_bins' # print 'rates' new_rates = np.zeros(len(mag_bins)) for mmax, weight in zip(mmaxs, weights): idx = np.where(np.isclose(mag_bins, (mmax - 0.05), rtol=1e-2))[0][-1] + 1 new_rates[:idx] += rates[:idx] * weight new_rates = new_rates * model_weight new_mfd = EvenlyDiscretizedMFD(mfd.min_mag, mfd.bin_width, list(new_rates)) return new_mfd
def to_evenly_discretized_mfd(self): """ Returns the activity rate as an instance of the :class: openquake.hazardlib.mfd.evenly_discretized.EvenlyDiscretizedMFD """ return EvenlyDiscretizedMFD(self.mmin + self.bin_width / 2., self.bin_width, self.occurrence_rate.tolist())
def generate_fault_source_model(self): ''' Creates a resulting `openquake.hmtk` fault source set. :returns: source_model - list of instances of either the :class: `openquake.hmtk.sources.simple_fault_source.mtkSimpleFaultSource` or :class: `openquake.hmtk.sources.complex_fault_source.mtkComplexFaultSource` model_weight - Corresponding weights for each source model ''' source_model = [] model_weight = [] for iloc in range(0, self.get_number_mfd_models()): model_mfd = EvenlyDiscretizedMFD( self.mfd[0][iloc].min_mag, self.mfd[0][iloc].bin_width, self.mfd[0][iloc].occur_rates.tolist()) if isinstance(self.geometry, ComplexFaultGeometry): # Complex fault class source = mtkComplexFaultSource( self.id, self.name, self.trt, self.geometry.surface, self.mfd[2][iloc], self.rupt_aspect_ratio, model_mfd, self.rake) source.fault_edges = self.geometry.trace else: # Simple Fault source source = mtkSimpleFaultSource( self.id, self.name, self.trt, self.geometry.surface, self.geometry.dip, self.geometry.upper_depth, self.geometry.lower_depth, self.mfd[2][iloc], self.rupt_aspect_ratio, model_mfd, self.rake) source.fault_trace = self.geometry.trace source_model.append(source) model_weight.append(self.mfd[1][iloc]) return source_model, model_weight
def _make_source(self): points = [Point(lon, lat, depth) for lon, lat, depth in zip(self.CORNER_LONS, self.CORNER_LATS, self.CORNER_DEPTHS)] source = CharacteristicFaultSource( source_id=self.SOURCE_ID, name=self.NAME, tectonic_region_type=self.TRT, mfd=EvenlyDiscretizedMFD(self.MIN_MAG, self.BIN_WIDTH, self.RATES), temporal_occurrence_model=self.TOM, surface=PlanarSurface(self.STRIKE, self.DIP, points[0], points[1], points[3], points[2]), rake=self.RAKE ) assert_pickleable(source) return source
from openquake.hazardlib.geo.nodalplane import NodalPlane from openquake.hazardlib.geo.point import Point from openquake.hazardlib.geo.polygon import Polygon from openquake.hazardlib.geo.line import Line from openquake.hazardlib.scalerel.point import PointMSR from openquake.hazardlib.scalerel.peer import PeerMSR from openquake.hazardlib.tom import PoissonTOM from openquake.hazardlib.geo.surface.simple_fault import SimpleFaultSurface from openquake.hmtk.comparison.rate_grids import RateGrid, RatePolygon SOURCE_MODEL_FILE = os.path.join(os.path.dirname(__file__), "rate_grid_test_model.xml") POINT_SOURCE = PointSource("PNT000", "Point 000", "Active Shallow Crust", EvenlyDiscretizedMFD(5.0, 0.1, [1.0]), 1.0, PointMSR(), 1.0, PoissonTOM(1.0), 0.0, 20.0, Point(15.05, 15.05), PMF([(1.0, NodalPlane(0.0, 90.0, 0.0))]), PMF([(1.0, 5.0)])) BORDER_POINT_SOURCE = PointSource("PNT000", "Point 000", "Active Shallow Crust", EvenlyDiscretizedMFD(5.0, 0.1, [1.0]), 1.0, PointMSR(),
from openquake.hazardlib.pmf import PMF from openquake.hazardlib.geo.nodalplane import NodalPlane from openquake.hazardlib.geo.point import Point from openquake.hazardlib.geo.polygon import Polygon from openquake.hazardlib.geo.line import Line from openquake.hazardlib.scalerel.point import PointMSR from openquake.hazardlib.scalerel.peer import PeerMSR from openquake.hazardlib.tom import PoissonTOM from openquake.hazardlib.geo.surface.simple_fault import SimpleFaultSurface from openquake.hmtk.comparison.rate_grids import RateGrid, RatePolygon SOURCE_MODEL_FILE = os.path.join(os.path.dirname(__file__), "rate_grid_test_model.xml") POINT_SOURCE = PointSource("PNT000", "Point 000", "Active Shallow Crust", EvenlyDiscretizedMFD(5.0, 0.1, [1.0]), 1.0, PointMSR(), 1.0, PoissonTOM(1.0), 0.0, 20.0, Point(15.05, 15.05), PMF([(1.0, NodalPlane(0.0, 90.0, 0.0))]), PMF([(1.0, 5.0)])) BORDER_POINT_SOURCE = PointSource("PNT000", "Point 000", "Active Shallow Crust", EvenlyDiscretizedMFD(5.0, 0.1, [1.0]), 1.0, PointMSR(), 1.0, PoissonTOM(1.0), 0.0, 20.0, Point(15.0, 15.0), PMF([(1.0, NodalPlane(0.0, 90.0, 0.0))]), PMF([(1.0, 5.0)])) OUTSIDE_POINT_SOURCE = PointSource("PNT000", "Point 000", "Active Shallow Crust",