def getStationList(self): """ Retrieve StationList object from container. Returns: StationList: StationList object. Raises: AttributeError: If stationlist object has not been set in the container. """ if 'stations' not in self.getStrings(): raise AttributeError('StationList object not set in container.') sql_string = self.getString('stations') stationlist = StationList.loadFromSQL(sql_string) return stationlist
def test_station2(): # # Test the wenchuan data # homedir = os.path.dirname(os.path.abspath(__file__)) event = 'wenchuan' datadir = os.path.abspath(os.path.join(homedir, 'station_data')) datadir = os.path.abspath(os.path.join(datadir, event, 'input')) inputfile = os.path.join(datadir, 'stationlist.xml') xmlfiles = [inputfile] stations = StationList.loadFromXML(xmlfiles, ":memory:") df1, _ = stations.getStationDictionary(instrumented=True) df2, _ = stations.getStationDictionary(instrumented=False) ppath = os.path.abspath(os.path.join(datadir, '..', 'database', 'test3.pickle')) if SAVE: ldf = [df1, df2] with open(ppath, 'wb') as f: pickle.dump(ldf, f, pickle.HIGHEST_PROTOCOL) else: with open(ppath, 'rb') as f: ldf = pickle.load(f) saved_df1 = ldf[0] saved_df2 = ldf[1] compare_dataframes(saved_df1, df1) compare_dataframes(saved_df2, df2) # # Dump the database to SQL and then restore it to a new # StationList object. Compare dataframes. # sql = stations.dumpToSQL() stations2 = StationList.loadFromSQL(sql) df1, _ = stations2.getStationDictionary(instrumented=True) df2, _ = stations2.getStationDictionary(instrumented=False) compare_dataframes(saved_df1, df1) compare_dataframes(saved_df2, df2)
def test_station2(): # # Test the wenchuan data # homedir = os.path.dirname(os.path.abspath(__file__)) event = 'wenchuan' datadir = os.path.abspath(os.path.join(homedir, 'station_data')) datadir = os.path.abspath(os.path.join(datadir, event, 'input')) inputfile = os.path.join(datadir, 'stationlist.xml') xmlfiles = [inputfile] stations = StationList.loadFromXML(xmlfiles, ":memory:") df1 = stations.getStationDictionary(instrumented=True) df2 = stations.getStationDictionary(instrumented=False) ppath = os.path.abspath(os.path.join(datadir, '..', 'database', 'test3.pickle')) if SAVE: ldf = [df1, df2] with open(ppath, 'wb') as f: pickle.dump(ldf, f, pickle.HIGHEST_PROTOCOL) else: with open(ppath, 'rb') as f: ldf = pickle.load(f) saved_df1 = ldf[0] saved_df2 = ldf[1] compare_dataframes(saved_df1, df1) compare_dataframes(saved_df2, df2) # # Dump the database to SQL and then restore it to a new # StationList object. Compare dataframes. # sql = stations.dumpToSQL() stations2 = StationList.loadFromSQL(sql) df1 = stations2.getStationDictionary(instrumented=True) df2 = stations2.getStationDictionary(instrumented=False) compare_dataframes(saved_df1, df1) compare_dataframes(saved_df2, df2)
def getStationList(self): """ Retrieve StationList object from container. Returns: StationList: StationList object. Raises: AttributeError: If stationlist object has not been set in the container. """ if 'stations' not in self.getStrings(): raise AttributeError('StationList object not set in container.') sql_string = self.getString('stations') stationlist = StationList.loadFromSQL(sql_string) return stationlist
def test_station2(): # # Test the wenchuan data # homedir = os.path.dirname(os.path.abspath(__file__)) event = 'wenchuan' datadir = os.path.abspath(os.path.join(homedir, 'station_data')) datadir = os.path.abspath(os.path.join(datadir, event, 'input')) inputfile = os.path.join(datadir, 'stationlist.xml') xmlfiles = [inputfile] stations = StationList.loadFromFiles(xmlfiles, ":memory:") df1, _ = stations.getStationDictionary(instrumented=True) # Check Keys pressent assert 'PGA' in _ assert 'PGV' in _ assert 'SA(0.3)' in _ assert 'SA(1.0)' in _ assert 'SA(3.0)' in _ assert 'PGV_sd' in df1 assert 'PGV' in df1 assert 'SA(0.3)' in df1 assert 'SA(1.0)' in df1 assert 'SA(3.0)' in df1 assert 'id' in df1 df2, _ = stations.getStationDictionary(instrumented=False) # Check Keys pressent assert 'MMI' in _ ppath = os.path.abspath( os.path.join(datadir, '..', 'database', 'test3.pickle')) if SAVE: ldf = [df1, df2] with open(ppath, 'wb') as f: pickle.dump(ldf, f, protocol=4) else: with open(ppath, 'rb') as f: ldf = pickle.load(f) saved_df1 = ldf[0] saved_df2 = ldf[1] compare_dataframes(saved_df1, df1) compare_dataframes(saved_df2, df2) # # Dump the database to SQL and then restore it to a new # StationList object. Compare dataframes. # sql = stations.dumpToSQL() stations2 = StationList.loadFromSQL(sql) df1, _ = stations2.getStationDictionary(instrumented=True) df2, _ = stations2.getStationDictionary(instrumented=False) compare_dataframes(saved_df1, df1) compare_dataframes(saved_df2, df2)