def test_process_streams(): # Loma Prieta test station (nc216859) data_files, origin = read_data_dir("geonet", "us1000778i", "*.V1A") streams = [] for f in data_files: streams += read_data(f) sc = StreamCollection(streams) sc.describe() config = update_config(os.path.join(datadir, "config_min_freq_0p2.yml")) test = process_streams(sc, origin, config=config) logging.info(f"Testing trace: {test[0][1]}") assert len(test) == 3 assert len(test[0]) == 3 assert len(test[1]) == 3 assert len(test[2]) == 3 # Apparently the traces end up in a different order on the Travis linux # container than on my local mac. So testing individual traces need to # not care about trace order. trace_maxes = np.sort( [np.max(np.abs(t.data)) for t in test.select(station="HSES")[0]]) np.testing.assert_allclose(trace_maxes, np.array([157.812449, 240.379521, 263.601519]), rtol=1e-5)
def test_process_streams(): # Loma Prieta test station (nc216859) data_files, origin = read_data_dir('geonet', 'us1000778i', '*.V1A') streams = [] for f in data_files: streams += read_data(f) sc = StreamCollection(streams) sc.describe() config = update_config(os.path.join(datadir, 'config_min_freq_0p2.yml')) test = process_streams(sc, origin, config=config) logging.info('Testing trace: %s' % test[0][1]) assert len(test) == 3 assert len(test[0]) == 3 assert len(test[1]) == 3 assert len(test[2]) == 3 # Apparently the traces end up in a different order on the Travis linux # container than on my local mac. So testing individual traces need to # not care about trace order. trace_maxes = np.sort( [np.max(np.abs(t.data)) for t in test.select(station='HSES')[0]]) np.testing.assert_allclose(trace_maxes, np.array( [157.81975508, 240.33718094, 263.67804256]), rtol=1e-5)
def test_check_instrument(): data_files, origin = read_data_dir("fdsn", "nc51194936", "*.mseed") streams = [] for f in data_files: streams += read_data(f) sc = StreamCollection(streams) sc.describe() config = update_config(os.path.join(datadir, "config_test_check_instr.yml")) test = process_streams(sc, origin, config=config) for sta, expected in [("CVS", True), ("GASB", True), ("SBT", False)]: st = test.select(station=sta)[0] logging.info(f"Testing stream: {st}") assert st.passed == expected
def test_check_instrument(): data_files, origin = read_data_dir('fdsn', 'nc51194936', '*.mseed') streams = [] for f in data_files: streams += read_data(f) sc = StreamCollection(streams) sc.describe() config = update_config(os.path.join(datadir, 'config_test_check_instr.yml')) test = process_streams(sc, origin, config=config) for sta, expected in [('CVS', True), ('GASB', True), ('SBT', False)]: st = test.select(station=sta)[0] logging.info('Testing stream: %s' % st) assert st.passed == expected
def download(event, event_dir, config, directory, create_workspace=True): """Download data or load data from local directory, turn into Streams. Args: event (ScalarEvent): Object containing basic event hypocenter, origin time, magnitude. event_dir (str): Path where raw directory should be created (if downloading). config (dict): Dictionary with gmprocess configuration information. directory (str): Path where data already exists. Must be organized in a 'raw' directory, within directories with names as the event ids. For example, if `directory` is 'proj_dir' and you have data for event id 'abc123' then the raw data to be read in should be located in `proj_dir/abc123/raw/`. create_workspace (bool): Create workspace file? Returns: tuple: - StreamWorkspace: Contains the event and raw streams. - str: Name of workspace HDF file. - StreamCollection: Raw data StationStreams. - str: Path to the rupture file. """ # Make raw directory rawdir = get_rawdir(event_dir) if directory is None: tcollection, terrors = fetch_data(event.time.datetime, event.latitude, event.longitude, event.depth_km, event.magnitude, config=config, rawdir=rawdir) # create an event.json file in each event directory, # in case user is simply downloading for now create_event_file(event, event_dir) rup_file = get_rupture_file(event_dir) else: # Make raw directory in_event_dir = os.path.join(directory, event.id) rup_file = get_rupture_file(in_event_dir) in_raw_dir = get_rawdir(in_event_dir) logging.debug('in_raw_dir: %s' % in_raw_dir) streams, bad, terrors = directory_to_streams(in_raw_dir) logging.debug('streams:') logging.debug(streams) tcollection = StreamCollection(streams, **config['duplicate']) create_event_file(event, event_dir) if len(tcollection): logging.debug('tcollection.describe():') logging.debug(tcollection.describe()) # Plot the raw waveforms with warnings.catch_warnings(): warnings.simplefilter("ignore", category=UserWarning) pngfiles = glob.glob(os.path.join(rawdir, '*.png')) if not len(pngfiles): plot_raw(rawdir, tcollection, event) if create_workspace: # Create the workspace file and put the unprocessed waveforms in it workname = os.path.join(event_dir, WORKSPACE_NAME) # Remove any existing workspace file if os.path.isfile(workname): os.remove(workname) workspace = StreamWorkspace(workname) workspace.addEvent(event) logging.debug('workspace.dataset.events:') logging.debug(workspace.dataset.events) workspace.addStreams(event, tcollection, label='unprocessed') logging.debug('workspace.dataset.waveforms.list():') logging.debug(workspace.dataset.waveforms.list()) else: workspace = None workname = None return (workspace, workname, tcollection, rup_file)