def knet_test(): # M 5.8 - 134km E of Iwaki, Japan # 2019-03-10 17:10:52 (UTC)36.852°N 142.368°E14.7 km depth utime = datetime(2019, 3, 10, 17, 10, 52) eqlat = 36.852 eqlon = 142.368 eqdepth = 14.7 eqmag = 5.8 rawdir = os.path.join(os.path.expanduser('~'), 'tmp', 'knet') streams = fetch_data(utime, eqlat, eqlon, eqdepth, eqmag, rawdir=rawdir) assert len(streams) == 139
def fdsn(): # 2014-08-24 10:20:44 eid = 'nc72282711' utime = datetime(2014, 8, 24, 10, 20, 44) eqlat = 38.215 eqlon = -122.312 eqdepth = 11.1 eqmag = 6.0 rawdir = os.path.join(os.path.expanduser('~'), 'tmp', eid, 'raw') stream_collection = fetch_data(utime, eqlat, eqlon, eqdepth, eqmag, rawdir=rawdir) assert len(stream_collection) == 15
def download(event, event_dir, config): """Download waveform data. 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. """ # Make raw directory rawdir = get_rawdir(event_dir) tcollection, terrors = fetch_data( event.time.datetime, event.latitude, event.longitude, event.depth_km, event.magnitude, config=config, rawdir=rawdir, stream_collection=False, ) # download an event.json file in each event directory, # in case user is simply downloading for now create_event_file(event, event_dir) download_rupture_file(event.id, 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)
def download(event, event_dir, config, directory): """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/`. Returns: tuple: - StreamWorkspace: Contains the event and raw streams. - str: Name of workspace HDF file. - StreamCollection: Raw data StationStreams. """ # 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) else: # Make raw directory in_event_dir = os.path.join(directory, event.id) in_raw_dir = get_rawdir(in_event_dir) streams, bad, terrors = directory_to_streams(in_raw_dir) tcollection = StreamCollection(streams, **config['duplicate']) create_event_file(event, event_dir) # 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) # Create the workspace file and put the unprocessed waveforms in it workname = os.path.join(event_dir, 'workspace.hdf') # Remove any existing workspace file if os.path.isfile(workname): os.remove(workname) workspace = StreamWorkspace(workname) workspace.addEvent(event) with warnings.catch_warnings(): warnings.simplefilter("ignore", category=H5pyDeprecationWarning) workspace.addStreams(event, tcollection, label='unprocessed') return (workspace, workname, tcollection)