Exemple #1
0
def test_zero_crossings():
    datapath = os.path.join("data", "testdata", "zero_crossings")
    datadir = pkg_resources.resource_filename("gmprocess", datapath)
    sc = StreamCollection.from_directory(datadir)
    sc.describe()

    conf = get_config()

    update = {
        "processing": [
            {"detrend": {"detrending_method": "demean"}},
            {"check_zero_crossings": {"min_crossings": 1}},
        ]
    }
    update_dict(conf, update)

    edict = {
        "id": "ak20419010",
        "time": UTCDateTime("2018-11-30T17:29:29"),
        "lat": 61.346,
        "lon": -149.955,
        "depth": 46.7,
        "magnitude": 7.1,
    }
    event = get_event_object(edict)
    test = process_streams(sc, event, conf)
    for st in test:
        for tr in st:
            assert tr.hasParameter("ZeroCrossingRate")
    np.testing.assert_allclose(
        test[0][0].getParameter("ZeroCrossingRate")["crossing_rate"],
        0.008888888888888889,
        atol=1e-5,
    )
Exemple #2
0
def test_nnet():

    conf = get_config()

    update = {
        "processing": [
            {
                "detrend": {
                    "detrending_method": "demean"
                }
            },
            {
                "detrend": {
                    "detrending_method": "linear"
                }
            },
            {
                "compute_snr": {
                    "bandwidth": 20.0,
                    "check": {
                        "max_freq": 5.0,
                        "min_freq": 0.2,
                        "threshold": 3.0
                    },
                }
            },
            {
                "NNet_QA": {
                    "acceptance_threshold": 0.5,
                    "model_name": "CantWell"
                }
            },
        ]
    }
    update_dict(conf, update)

    data_files, origin = read_data_dir("geonet", "us1000778i", "*.V1A")
    streams = []
    for f in data_files:
        streams += read_data(f)

    sc = StreamCollection(streams)
    test = process_streams(sc, origin, conf)
    tstream = test.select(station="HSES")[0]
    nnet_dict = tstream.getStreamParam("nnet_qa")
    np.testing.assert_allclose(nnet_dict["score_HQ"],
                               0.99321798811740059,
                               rtol=1e-3)
Exemple #3
0
def test_nnet():

    conf = get_config()

    update = {
        'processing': [{
            'detrend': {
                'detrending_method': 'demean'
            }
        }, {
            'detrend': {
                'detrending_method': 'linear'
            }
        }, {
            'compute_snr': {
                'bandwidth': 20.0,
                'check': {
                    'max_freq': 5.0,
                    'min_freq': 0.2,
                    'threshold': 3.0
                }
            }
        }, {
            'NNet_QA': {
                'acceptance_threshold': 0.5,
                'model_name': 'CantWell'
            }
        }]
    }
    update_dict(conf, update)

    data_files, origin = read_data_dir('geonet', 'us1000778i', '*.V1A')
    streams = []
    for f in data_files:
        streams += read_data(f)

    sc = StreamCollection(streams)
    test = process_streams(sc, origin, conf)
    tstream = test.select(station='HSES')[0]
    nnet_dict = tstream.getStreamParam('nnet_qa')
    np.testing.assert_allclose(nnet_dict['score_HQ'],
                               0.99321798811740059,
                               rtol=1e-3)
def test_zero_crossings():
    datapath = os.path.join('data', 'testdata', 'zero_crossings')
    datadir = pkg_resources.resource_filename('gmprocess', datapath)
    sc = StreamCollection.from_directory(datadir)
    sc.describe()

    conf = get_config()

    update = {
        'processing': [{
            'detrend': {
                'detrending_method': 'demean'
            }
        }, {
            'check_zero_crossings': {
                'min_crossings': 1
            }
        }]
    }
    update_dict(conf, update)

    edict = {
        'id': 'ak20419010',
        'time': UTCDateTime('2018-11-30T17:29:29'),
        'lat': 61.346,
        'lon': -149.955,
        'depth': 46.7,
        'magnitude': 7.1
    }
    event = get_event_object(edict)
    test = process_streams(sc, event, conf)
    for st in test:
        for tr in st:
            assert tr.hasParameter('ZeroCrossingRate')
    np.testing.assert_allclose(
        test[0][0].getParameter('ZeroCrossingRate')['crossing_rate'],
        0.008888888888888889,
        atol=1e-5)
def update_config(custom_cfg_file):
    """Merge custom config with default.

    Args:
        custom_cfg_file (str):
            Path to custom config.

    Returns:
        dict: Merged config dictionary.

    """
    config = get_config()

    if not os.path.isfile(custom_cfg_file):
        return config
    try:
        with open(custom_cfg_file, 'rt', encoding='utf-8') as f:
            custom_cfg = yaml.load(f, Loader=yaml.FullLoader)
            update_dict(config, custom_cfg)
    except yaml.parser.ParserError:
        return None

    return config
Exemple #6
0
def test_lowpass_max():
    datapath = os.path.join('data', 'testdata', 'lowpass_max')
    datadir = pkg_resources.resource_filename('gmprocess', datapath)
    sc = StreamCollection.from_directory(datadir)
    sc.describe()

    conf = get_config()
    update = {
        'processing': [
            {
                'detrend': {
                    'detrending_method': 'demean'
                }
            },
            {
                'remove_response': {
                    'f1': 0.001,
                    'f2': 0.005,
                    'f3': None,
                    'f4': None,
                    'output': 'ACC',
                    'water_level': 60
                }
            },
            #            {'detrend': {'detrending_method': 'linear'}},
            #            {'detrend': {'detrending_method': 'demean'}},
            {
                'get_corner_frequencies': {
                    'constant': {
                        'highpass': 0.08,
                        'lowpass': 20.0
                    },
                    'method': 'constant',
                    'snr': {
                        'same_horiz': True
                    }
                }
            },
            {
                'lowpass_max_frequency': {
                    'fn_fac': 0.9
                }
            }
        ]
    }
    update_dict(conf, update)
    update = {
        'windows': {
            'signal_end': {
                'method': 'model',
                'vmin': 1.0,
                'floor': 120,
                'model': 'AS16',
                'epsilon': 2.0
            },
            'window_checks': {
                'do_check': False,
                'min_noise_duration': 1.0,
                'min_signal_duration': 1.0
            }
        }
    }
    update_dict(conf, update)
    edict = {
        'id': 'ci38038071',
        'time': UTCDateTime('2018-08-30 02:35:36'),
        'lat': 34.136,
        'lon': -117.775,
        'depth': 5.5,
        'magnitude': 4.4
    }
    event = get_event_object(edict)
    test = process_streams(sc, event, conf)
    for st in test:
        for tr in st:
            freq_dict = tr.getParameter('corner_frequencies')
            np.testing.assert_allclose(freq_dict['lowpass'], 18.0)
Exemple #7
0
def test_lowpass_max():
    datapath = os.path.join("data", "testdata", "lowpass_max")
    datadir = pkg_resources.resource_filename("gmprocess", datapath)
    sc = StreamCollection.from_directory(datadir)
    sc.describe()

    conf = get_config()
    update = {
        "processing": [
            {
                "detrend": {
                    "detrending_method": "demean"
                }
            },
            {
                "remove_response": {
                    "f1": 0.001,
                    "f2": 0.005,
                    "f3": None,
                    "f4": None,
                    "water_level": 60,
                }
            },
            #            {'detrend': {'detrending_method': 'linear'}},
            #            {'detrend': {'detrending_method': 'demean'}},
            {
                "get_corner_frequencies": {
                    "constant": {
                        "highpass": 0.08,
                        "lowpass": 20.0
                    },
                    "method": "constant",
                    "snr": {
                        "same_horiz": True
                    },
                }
            },
            {
                "lowpass_max_frequency": {
                    "fn_fac": 0.9
                }
            },
        ]
    }
    update_dict(conf, update)
    update = {
        "windows": {
            "signal_end": {
                "method": "model",
                "vmin": 1.0,
                "floor": 120,
                "model": "AS16",
                "epsilon": 2.0,
            },
            "window_checks": {
                "do_check": False,
                "min_noise_duration": 1.0,
                "min_signal_duration": 1.0,
            },
        }
    }
    update_dict(conf, update)
    edict = {
        "id": "ci38038071",
        "time": UTCDateTime("2018-08-30 02:35:36"),
        "lat": 34.136,
        "lon": -117.775,
        "depth": 5.5,
        "magnitude": 4.4,
    }
    event = get_event_object(edict)
    test = process_streams(sc, event, conf)
    for st in test:
        for tr in st:
            freq_dict = tr.getParameter("corner_frequencies")
            np.testing.assert_allclose(freq_dict["lowpass"], 18.0)