示例#1
0
def window_wrapper(obsd_station_group, synt_station_group, config_dict=None,
                   obsd_tag=None, synt_tag=None,
                   event=None, figure_mode=False, figure_dir=None,
                   _verbose=False):
    """
    Wrapper for asdf I/O
    """
    # Make sure everything thats required is there.
    if not hasattr(synt_station_group, "StationXML"):
        print("Missing StationXML from synt_staiton_group")
        return
    if not hasattr(obsd_station_group, obsd_tag):
        print("Missing tag '%s' from obsd_station_group" % obsd_tag)
        return
    if not hasattr(synt_station_group, synt_tag):
        print("Missing tag '%s' from synt_station_group" % synt_tag)
        return

    inv = synt_station_group.StationXML
    observed = getattr(obsd_station_group, obsd_tag)
    synthetic = getattr(synt_station_group, synt_tag)

    return window_on_stream(observed, synthetic, config_dict,
                            station=inv, event=event,
                            figure_mode=figure_mode, figure_dir=figure_dir,
                            _verbose=_verbose)
示例#2
0
文件: window.py 项目: wjlei1990/pypaw
def window_wrapper(obsd_station_group, synt_station_group, config_dict=None,
                   obsd_tag=None, synt_tag=None, user_modules=None,
                   event=None, figure_mode=False, figure_dir=None,
                   _verbose=False):
    """
    Wrapper for asdf I/O
    """
    # Make sure everything thats required is there.
    if not hasattr(synt_station_group, "StationXML"):
        print("Missing StationXML from synt_staiton_group")
        return
    if not hasattr(obsd_station_group, obsd_tag):
        print("Missing tag '%s' from obsd_station_group" % obsd_tag)
        return
    if not hasattr(synt_station_group, synt_tag):
        print("Missing tag '%s' from synt_station_group" % synt_tag)
        return

    inv = synt_station_group.StationXML
    observed = getattr(obsd_station_group, obsd_tag)
    synthetic = getattr(synt_station_group, synt_tag)

    return window_on_stream(
        observed, synthetic, config_dict, station=inv,
        event=event, user_modules=user_modules,
        figure_mode=figure_mode, figure_dir=figure_dir,
        _verbose=_verbose)
示例#3
0
def test_window_on_stream_user_levels():
    obs_tr = read(obsfile)
    syn_tr = read(synfile)

    config_file = os.path.join(DATA_DIR, "window", "27_60.BHZ.config.yaml")
    config = wio.load_window_config_yaml(config_file)
    config_dict = {"Z": config, "R": config, "T": config}

    config_file = os.path.join(DATA_DIR, "window", "27_60.BHZ.config.yaml")
    config = wio.load_window_config_yaml(config_file)

    cat = readEvents(quakeml)
    inv = read_inventory(staxml)

    _mod = "pytomo3d.window.tests.user_module_example"
    user_modules = {"BHZ": _mod, "BHR": _mod, "BHT": _mod}

    windows = win.window_on_stream(obs_tr,
                                   syn_tr,
                                   config_dict,
                                   station=inv,
                                   event=cat,
                                   user_modules=user_modules,
                                   _verbose=False,
                                   figure_mode=False)

    assert len(windows) == 3
    nwins = dict((_w, len(windows[_w])) for _w in windows)
    assert nwins == {"IU.KBL..BHR": 5, "IU.KBL..BHZ": 2, "IU.KBL..BHT": 4}
示例#4
0
def test_window_on_stream_user_levels():
    obs_tr = read(obsfile)
    syn_tr = read(synfile)

    config_file = os.path.join(DATA_DIR, "window", "27_60.BHZ.config.yaml")
    config = wio.load_window_config_yaml(config_file)
    config_dict = {"Z": config, "R": config, "T": config}

    config_file = os.path.join(DATA_DIR, "window", "27_60.BHZ.config.yaml")
    config = wio.load_window_config_yaml(config_file)

    cat = readEvents(quakeml)
    inv = read_inventory(staxml)

    _mod = "pytomo3d.window.tests.user_module_example"
    user_modules = {"BHZ": _mod, "BHR": _mod, "BHT": _mod}

    windows = win.window_on_stream(obs_tr, syn_tr, config_dict, station=inv,
                                   event=cat, user_modules=user_modules,
                                   _verbose=False,
                                   figure_mode=False)

    assert len(windows) == 3
    nwins = dict((_w, len(windows[_w])) for _w in windows)
    assert nwins == {"IU.KBL..BHR": 5, "IU.KBL..BHZ": 2, "IU.KBL..BHT": 4}
示例#5
0
def test_window_on_stream():
    obs_tr = read(obsfile)
    syn_tr = read(synfile)

    config_file = os.path.join(DATA_DIR, "window", "27_60.BHZ.config.yaml")
    config = win.load_window_config_yaml(config_file)
    config_dict = {"Z": config, "R": config, "T": config}

    config_file = os.path.join(DATA_DIR, "window", "27_60.BHZ.config.yaml")
    config = win.load_window_config_yaml(config_file)

    cat = readEvents(quakeml)
    inv = read_inventory(staxml)

    windows = win.window_on_stream(obs_tr,
                                   syn_tr,
                                   config_dict,
                                   station=inv,
                                   event=cat,
                                   _verbose=False,
                                   figure_mode=False)
    assert len(windows) > 0
示例#6
0
def func_wrapper(obsd_station_group,
                 synt_station_group,
                 obsd_tag=None,
                 synt_tag=None,
                 event=None,
                 param=None,
                 _verbose=False,
                 figure_mode=False,
                 figure_dir=None):
    """
    combo function, including:
    1) observed data signal processing
    2) synthetic data signal processing
    3) window selection based on a pair of data
    4) adjoint source constructor
    """
    # Make sure everything thats required is there.
    _station_name = obsd_station_group._station_name
    if not hasattr(obsd_station_group, "StationXML"):
        raise ValueError("obsd station group '%s' missing 'StationXML'" %
                         _station_name)
    if not hasattr(synt_station_group, "StationXML"):
        raise ValueError("synt station group '%s' missing 'StationXML'" %
                         _station_name)
    if not hasattr(obsd_station_group, obsd_tag):
        raise ValueError("obsd station group '%s' missing '%s'" %
                         (_station_name, obsd_tag))
    if not hasattr(synt_station_group, synt_tag):
        raise ValueError("synt station group '%s' missing '%s'" %
                         (_station_name, synt_tag))

    param = copy.deepcopy(param)

    obsd_staxml = obsd_station_group.StationXML
    synt_staxml = synt_station_group.StationXML
    observed = getattr(obsd_station_group, obsd_tag)
    synthetic = getattr(synt_station_group, synt_tag)

    # keep a reference for construct adjoint source, which
    # should be same length and dt as raw synt
    _raw_synt_tr = synthetic[0].copy()

    obsd_param = param["proc_obsd_param"]
    new_obsd = process_stream(observed, inventory=obsd_staxml, **obsd_param)

    synt_param = param["proc_synt_param"]
    new_synt = process_stream(synthetic, inventory=synt_staxml, **synt_param)

    window_config = load_window_config(param["window_param"])
    windows = window_on_stream(new_obsd,
                               new_synt,
                               window_config,
                               station=synt_staxml,
                               event=event,
                               figure_mode=figure_mode,
                               figure_dir=figure_dir,
                               _verbose=_verbose)
    if len(windows) == 0:
        # No windows selected
        return

    windows = smart_transform_window(windows)

    adj_config, adj_src_type = load_adjoint_config(param["adjsrc_param"])
    adjsrcs = calculate_adjsrc_on_stream(new_obsd,
                                         new_synt,
                                         windows,
                                         adj_config,
                                         adj_src_type,
                                         figure_mode=figure_mode,
                                         figure_dir=figure_dir,
                                         adjoint_src_flag=True)

    chan_weight_dict = calculate_chan_weight(adjsrcs, windows)

    interp_starttime = _raw_synt_tr.stats.starttime
    interp_delta = _raw_synt_tr.stats.delta
    interp_npts = _raw_synt_tr.stats.npts
    pre_filt = obsd_param["pre_filt"]
    new_adjsrcs = process_adjoint(adjsrcs,
                                  interp_starttime,
                                  interp_delta,
                                  interp_npts,
                                  rotate_flag=True,
                                  inventory=synt_staxml,
                                  event=event,
                                  sum_over_comp_flag=True,
                                  weight_flag=True,
                                  weight_dict=chan_weight_dict,
                                  filter_flag=True,
                                  pre_filt=pre_filt)

    origin = event.preferred_origin() or event.origins[0]
    time_offset = interp_starttime - origin.time
    results = reshape_adj(new_adjsrcs, time_offset, synt_staxml)

    return results
示例#7
0
def func_wrapper(obsd_station_group, synt_station_group, obsd_tag=None,
                 synt_tag=None, event=None, param=None, _verbose=False,
                 figure_mode=False, figure_dir=None):
    """
    combo function, including:
    1) observed data signal processing
    2) synthetic data signal processing
    3) window selection based on a pair of data
    4) adjoint source constructor
    """
    # Make sure everything thats required is there.
    _station_name = obsd_station_group._station_name
    if not hasattr(obsd_station_group, "StationXML"):
        raise ValueError("obsd station group '%s' missing 'StationXML'"
                         % _station_name)
    if not hasattr(synt_station_group, "StationXML"):
        raise ValueError("synt station group '%s' missing 'StationXML'"
                         % _station_name)
    if not hasattr(obsd_station_group, obsd_tag):
        raise ValueError("obsd station group '%s' missing '%s'"
                         % (_station_name, obsd_tag))
    if not hasattr(synt_station_group, synt_tag):
        raise ValueError("synt station group '%s' missing '%s'"
                         % (_station_name, synt_tag))

    param = copy.deepcopy(param)

    obsd_staxml = obsd_station_group.StationXML
    synt_staxml = synt_station_group.StationXML
    observed = getattr(obsd_station_group, obsd_tag)
    synthetic = getattr(synt_station_group, synt_tag)

    # keep a reference for construct adjoint source, which
    # should be same length and dt as raw synt
    _raw_synt_tr = synthetic[0].copy()

    obsd_param = param["proc_obsd_param"]
    new_obsd = process_stream(observed, inventory=obsd_staxml, **obsd_param)

    synt_param = param["proc_synt_param"]
    new_synt = process_stream(synthetic, inventory=synt_staxml, **synt_param)

    window_config = load_window_config(param["window_param"])
    windows = window_on_stream(new_obsd, new_synt, window_config,
                               station=synt_staxml, event=event,
                               figure_mode=figure_mode, figure_dir=figure_dir,
                               _verbose=_verbose)
    if len(windows) == 0:
        # No windows selected
        return

    windows = smart_transform_window(windows)

    adj_config, adj_src_type = load_adjoint_config(param["adjsrc_param"])
    adjsrcs = calculate_adjsrc_on_stream(
        new_obsd, new_synt, windows, adj_config, adj_src_type,
        figure_mode=figure_mode, figure_dir=figure_dir,
        adjoint_src_flag=True)

    chan_weight_dict = calculate_chan_weight(adjsrcs, windows)

    interp_starttime = _raw_synt_tr.stats.starttime
    interp_delta = _raw_synt_tr.stats.delta
    interp_npts = _raw_synt_tr.stats.npts
    pre_filt = obsd_param["pre_filt"]
    new_adjsrcs = process_adjoint(
        adjsrcs, interp_starttime, interp_delta, interp_npts,
        rotate_flag=True, inventory=synt_staxml, event=event,
        sum_over_comp_flag=True, weight_flag=True,
        weight_dict=chan_weight_dict, filter_flag=True,
        pre_filt=pre_filt)

    origin = event.preferred_origin() or event.origins[0]
    time_offset = interp_starttime - origin.time
    results = reshape_adj(new_adjsrcs, time_offset, synt_staxml)

    return results