def setUp(self): cat1 = Catalogue() cat1.end_year = 2000 cat1.start_year = 1900 cat1.data['eventID'] = [1.0, 2.0, 3.0] cat1.data['magnitude'] = np.array([1.0, 2.0, 3.0]) cat2 = Catalogue() cat2.end_year = 1990 cat2.start_year = 1910 cat2.data['eventID'] = [1.0, 2.0, 3.0] cat2.data['magnitude'] = np.array([1.0, 2.0, 3.0]) self.cat1 = cat1 self.cat2 = cat2
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
def from_df(df, end_year=None): cat = Catalogue() for column in df: if (column in Catalogue.FLOAT_ATTRIBUTE_LIST or column in Catalogue.INT_ATTRIBUTE_LIST): cat.data[column] = df[column].to_numpy() else: cat.data[column] = df[column] cat.end_year = np.max(df.year) if end_year is None else end_year return cat
def from_df(df, end_year=None): """ :param df: A :class:`pd.DataFrame` instance with the catalogue """ cat = Catalogue() for column in df: if (column in Catalogue.FLOAT_ATTRIBUTE_LIST or column in Catalogue.INT_ATTRIBUTE_LIST): cat.data[column] = df[column].to_numpy() else: cat.data[column] = df[column] cat.end_year = np.max(df.year) if end_year is None else end_year return cat
def from_df(df, end_year=None): """ Converts a dataframe into a :class:`openquake.hmtk.seismicity.catalogue.Catalogue` instance :param df: The dataframe with the catalogue :returns: The catalogue instance """ cat = Catalogue() for column in df: if (column in Catalogue.FLOAT_ATTRIBUTE_LIST or column in Catalogue.INT_ATTRIBUTE_LIST): cat.data[column] = df[column].to_numpy() else: cat.data[column] = df[column] cat.end_year = np.max(df.year) if end_year is None else end_year return cat