def set_gcmt(self, filename, bffer=75.): """ :parameter cmt_cat: Name of a file in the .ndk format """ print('setting gcmt') parser = ParseNDKtoGCMT(filename) cmt_cat = parser.read_file() loc = cmt_cat.data['longitude'] lac = cmt_cat.data['latitude'] minlo, maxlo, minla, maxla, qual = self.csec.get_mm() if qual == 0: idxs = self.csec.get_grd_nodes_within_buffer(loc, lac, bffer, minlo, maxlo, minla, maxla) if qual == 1: idxs = self.csec.get_grd_nodes_within_buffer_idl(loc, lac, bffer, minlo, maxlo, minla, maxla) if idxs is not None: cmt_cat.select_catalogue_events(idxs) self.gcmt = cmt_cat
def setUp(self): # Parse catalogue fname = os.path.join(self.BASE_DATA_PATH, "test_gcmt_catalogue_01.txt") # Parse GCMT file prs = ParseNDKtoGCMT(fname) self.cat = prs.read_file()
def setUp(self): """ Read a sample catalogue containing 2 events after instantiating the CsvCatalogueParser object. """ filename = os.path.join(self.BASE_DATA_PATH, 'test_gcmt_catalogue.txt') parser = ParseNDKtoGCMT(filename) parser_cent = ParseNDKtoGCMT(filename) self.cat = parser.read_file() self.cat_cent = parser_cent.read_file(use_centroid='True')
def test_without_specifying_years(self): """ Tests that when the catalogue is parsed without specifying the start and end year that the start and end year come from the minimum and maximum in the catalogue """ filename = os.path.join(self.BASE_DATA_PATH, 'test_gcmt_catalogue.txt') parser = ParseNDKtoGCMT(filename) self.cat = parser.read_file() self.assertAlmostEqual(self.cat.start_year, np.min(self.cat.data['year'])) self.assertAlmostEqual(self.cat.end_year, np.max(self.cat.data['year']))
def test_read_centroid_from_ndk_string(self): import datetime from openquake.hmtk.seismicity.gcmt_catalogue import GCMTHypocentre tmps = """CENTROID: 1.060.0 10.47 0.03 127.42 0.03 15.0 0.0 BDY O-00000000000000""" prs = ParseNDKtoGCMT('pippo') hypo = GCMTHypocentre() hypo.date = datetime.date(2000, 1, 2) hypo.time = datetime.time(1, 2, 3) prs._read_centroid_from_ndk_string(tmps, hypo)
def test_locations(self): """ test locations """ fname = os.path.join(self.BASE_DATA_PATH, 'test_gcmt_catalogue_01.txt') prs = ParseNDKtoGCMT(fname) cat = prs.read_file(use_centroid=False) self.assertAlmostEqual(cat.data['longitude'][0], 111.72) self.assertAlmostEqual(cat.data['latitude'][0], -10.80) self.assertAlmostEqual(cat.data['longitude'][1], -113.12) self.assertAlmostEqual(cat.data['latitude'][1], 28.74) cat = prs.read_file(use_centroid=True) self.assertAlmostEqual(cat.data['longitude'][0], 112.44) self.assertAlmostEqual(cat.data['latitude'][0], -10.60) self.assertAlmostEqual(cat.data['longitude'][1], -113.12) self.assertAlmostEqual(cat.data['latitude'][1], 28.81)
def get_catalogue(catalogue_filename, force_csv=False): """ """ ext = Path(catalogue_filename).suffix path, name = os.path.split(catalogue_filename) cat_pickle_filename = os.path.join(path, Path(name).stem+'.pkl') if (ext == '.csv' or ext == '.hmtk') or (force_csv): parser = CsvCatalogueParser(catalogue_filename) catalogue = parser.read_file() pickle.dump(catalogue, open(cat_pickle_filename, 'wb')) elif ext == '.pkl' or ext == '.p': catalogue = pickle.load(open(catalogue_filename, 'rb')) elif ext == '.ndk': parser = ParseNDKtoGCMT(catalogue_filename) catalogue = parser.read_file() pickle.dump(catalogue, open(cat_pickle_filename, 'wb')) else: raise ValueError('File with an unkown extension') return catalogue
def get_dataframe(fname): print(fname) parser = ParseNDKtoGCMT(fname) cat_gcmt = parser.read_file() df = pd.DataFrame({k: cat_gcmt.data[k] for k in cat_gcmt.data.keys()}) return df