Exemple #1
0
    def test_select_catalogue_rrup(self):
        """
        Tests catalogue selection with Joyner-Boore distance
        """
        self.fault = mtkActiveFault('001',
                                    'A Fault',
                                    self.simple_fault, [(5., 0.5), (7., 0.5)],
                                    0.,
                                    None,
                                    msr_sigma=[(-1.5, 0.15), (0., 0.7),
                                               (1.5, 0.15)])

        cat1 = Catalogue()
        cat1.data = {
            "eventID": ["001", "002", "003", "004"],
            "longitude": np.array([30.1, 30.1, 30.5, 31.5]),
            "latitude": np.array([30.0, 30.25, 30.4, 30.5]),
            "depth": np.array([5.0, 250.0, 10.0, 10.0])
        }
        selector = CatalogueSelector(cat1)
        # Select within 50 km of the fault
        self.fault.select_catalogue(selector, 50.0, distance_metric="rupture")
        np.testing.assert_array_almost_equal(
            self.fault.catalogue.data["longitude"], np.array([30.1, 30.5]))
        np.testing.assert_array_almost_equal(
            self.fault.catalogue.data["latitude"], np.array([30.0, 30.4]))
        np.testing.assert_array_almost_equal(
            self.fault.catalogue.data["depth"], np.array([5.0, 10.0]))
Exemple #2
0
    def test_select_catalogue_rrup(self):
        """
        Tests catalogue selection with Joyner-Boore distance
        """
        self.fault = mtkActiveFault(
            '001',
            'A Fault',
            self.simple_fault,
            [(5., 0.5), (7., 0.5)],
            0.,
            None,
            msr_sigma=[(-1.5, 0.15), (0., 0.7), (1.5, 0.15)])

        cat1 = Catalogue()
        cat1.data = {"eventID": ["001", "002", "003", "004"],
                     "longitude": np.array([30.1, 30.1, 30.5, 31.5]),
                     "latitude": np.array([30.0, 30.25, 30.4, 30.5]),
                     "depth": np.array([5.0, 250.0, 10.0, 10.0])}
        selector = CatalogueSelector(cat1)
        # Select within 50 km of the fault
        self.fault.select_catalogue(selector, 50.0,
                                    distance_metric="rupture")
        np.testing.assert_array_almost_equal(
            self.fault.catalogue.data["longitude"],
            np.array([30.1, 30.5]))
        np.testing.assert_array_almost_equal(
            self.fault.catalogue.data["latitude"],
            np.array([30.0, 30.4]))
        np.testing.assert_array_almost_equal(
            self.fault.catalogue.data["depth"],
            np.array([5.0, 10.0]))
Exemple #3
0
def get_catalogue_from_ses(fname, duration):
    """
    Converts a set of ruptures into an instance of
    :class:`openquake.hmtk.seismicity.catalogue.Catalogue`.

    :param fname:
        Name of the .csv file
    :param float duration:
        Duration [in years] of the SES
    :returns:
        A :class:`openquake.hmtk.seismicity.catalogue.Catalogue` instance
    """
    # Read the set of ruptures
    ses = pd.read_csv(fname, sep='\t', skiprows=1)
    if len(ses.columns) < 2:
        ses = pd.read_csv(fname, sep=',', skiprows=1)
    # Create an empty catalogue
    cat = Catalogue()
    # Set catalogue data
    cnt = 0
    year = []
    eventids = []
    mags = []
    lons = []
    lats = []
    deps = []
    print(ses['rup_id'])
    print('Columns:', ses.columns)
    for i in range(len(ses)):
        nevents = ses['multiplicity'][i]
        for j in range(nevents):
            eventids.append(':d'.format(cnt))
            mags.append(ses['mag'].values[i])
            lons.append(ses['centroid_lon'].values[i])
            lats.append(ses['centroid_lat'].values[i])
            deps.append(ses['centroid_depth'].values[i])
            cnt += 1
            year.append(numpy.random.random_integers(1, duration, 1))

    data = {}
    year = numpy.array(year, dtype=int)
    data['year'] = year
    data['month'] = numpy.ones_like(year, dtype=int)
    data['day'] = numpy.ones_like(year, dtype=int)
    data['hour'] = numpy.zeros_like(year, dtype=int)
    data['minute'] = numpy.zeros_like(year, dtype=int)
    data['second'] = numpy.zeros_like(year)
    data['magnitude'] = numpy.array(mags)
    data['longitude'] = numpy.array(lons)
    data['latitude'] = numpy.array(lats)
    data['depth'] = numpy.array(deps)
    data['eventID'] = eventids
    cat.data = data
    cat.end_year = duration
    cat.start_year = 0
    cat.data['dtime'] = cat.get_decimal_time()
    return cat