Esempio n. 1
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
Esempio n. 2
0
    def test_get_decimal_time(self):
        # Tests the decimal time function. The function itself is tested in
        # tests.seismicity.utils so only minimal testing is undertaken here to
        # ensure coverage
        time_dict = {
            'year': np.array([1990, 2000]),
            'month': np.array([3, 9]),
            'day': np.ones(2, dtype=int),
            'hour': np.ones(2, dtype=int),
            'minute': np.ones(2, dtype=int),
            'second': np.ones(2, dtype=float)
        }
        expected_dec_time = decimal_time(time_dict['year'], time_dict['month'],
                                         time_dict['day'], time_dict['hour'],
                                         time_dict['minute'],
                                         time_dict['second'])

        cat = Catalogue()
        for key in ['year', 'month', 'day', 'hour', 'minute', 'second']:
            cat.data[key] = np.copy(time_dict[key])
        np.testing.assert_array_almost_equal(expected_dec_time,
                                             cat.get_decimal_time())
Esempio n. 3
0
    def test_get_decimal_time(self):
        # Tests the decimal time function. The function itself is tested in
        # tests.seismicity.utils so only minimal testing is undertaken here to
        # ensure coverage
        time_dict = {'year': np.array([1990, 2000]),
                     'month': np.array([3, 9]),
                     'day': np.ones(2, dtype=int),
                     'hour': np.ones(2, dtype=int),
                     'minute': np.ones(2, dtype=int),
                     'second': np.ones(2, dtype=float)}
        expected_dec_time = decimal_time(time_dict['year'],
                                         time_dict['month'],
                                         time_dict['day'],
                                         time_dict['hour'],
                                         time_dict['minute'],
                                         time_dict['second'])

        cat = Catalogue()
        for key in ['year', 'month', 'day', 'hour', 'minute', 'second']:
            cat.data[key] = np.copy(time_dict[key])
        np.testing.assert_array_almost_equal(expected_dec_time,
                                             cat.get_decimal_time())