def test_filter_windows_2(): sensor_config = {"flag": True, "sensor_types": ["STS-1", "STS1"]} measure_config = \ {"component": { "R": {"tshift_reference": 0, "tshift_acceptance_level": 0.1, "std_ratio": 3.0}, "T": {"tshift_reference": 0, "tshift_acceptance_level": 0.1, "std_ratio": 3.0}, "Z": {"tshift_reference": 0, "tshift_acceptance_level": 0.1, "std_ratio": 3.0}}, "flag": True} config = {"sensor": sensor_config, "measurement": measure_config} _wins, log = fw.filter_windows( windows, stations, measures, config, verbose=False) assert len(_wins) == 0 measure_config = \ {"component": { "R": {"tshift_reference": 0, "tshift_acceptance_level": 10.0, "std_ratio": 0.01}, "T": {"tshift_reference": 0, "tshift_acceptance_level": 10.0, "std_ratio": 0.01}, "Z": {"tshift_reference": 0, "tshift_acceptance_level": 10.0, "std_ratio": 0.01}}, "flag": True} config = {"sensor": sensor_config, "measurement": measure_config} _wins, log = fw.filter_windows( windows, stations, measures, config, verbose=False) assert len(_wins) == 0
def test_filter_windows(): sensor_config = {"flag": True, "sensor_types": ["STS-1", "STS1"]} measure_config = \ {"component": { "R": {"tshift_reference": 0, "tshift_acceptance_level": 6.0, "std_ratio": 3.0}, "T": {"tshift_reference": 0, "tshift_acceptance_level": 6.0, "std_ratio": 3.0}, "Z": {"tshift_reference": 0, "tshift_acceptance_level": 6.0, "std_ratio": 3.0}}, "flag": True} config = {"sensor": sensor_config, "measurement": measure_config} _wins, log = fw.filter_windows( windows, stations, measures, config, verbose=False) assert _wins["II.AAK"] == windows["II.AAK"] assert _wins["II.ABKT"]["II.ABKT..BHR"] == \ windows["II.ABKT"]["II.ABKT..BHR"] assert _wins["II.ABKT"]["II.ABKT..BHZ"] == \ windows["II.ABKT"]["II.ABKT..BHZ"] assert "II.ABKT..BHT" not in _wins["II.ABKT"] assert "IU.BCD" not in _wins["II.ABKT"] _true_log = \ {'sensor': { 'window_rejection_percentage': 50.0, 'nwindows_old': 18, 'channel_rejection_percentage': 37.5, 'nwindows_new': 9, 'nchannels_new': 5, 'nchannels_old': 8}, 'measurement': { 'window_rejection_percentage': 0.0, 'nwindows_old': 9, 'channel_rejection_percentage': 0.0, 'nwindows_new': 9, 'nchannels_new': 5, 'nchannels_old': 5}} assert log == _true_log
def test_filter_windows_2(): sensor_config = {"flag": True, "sensor_types": ["STS-1", "STS1"]} measure_config = \ {"component": { "R": {"tshift_reference": 0, "tshift_acceptance_level": 0.1, "dlna_reference": 0, "dlna_acceptance_level": 1.0, "std_ratio": 3.0}, "T": {"tshift_reference": 0, "tshift_acceptance_level": 0.1, "dlna_reference": 0, "dlna_acceptance_level": 1.0, "std_ratio": 3.0}, "Z": {"tshift_reference": 0, "tshift_acceptance_level": 0.1, "dlna_reference": 0, "dlna_acceptance_level": 1.0, "std_ratio": 3.0}}, "flag": True} config = {"sensor": sensor_config, "measurement": measure_config} _wins, _meas, log = fw.filter_windows(windows, stations, measures, config, verbose=False) assert len(_wins) == 0 assert len(_meas) == 0 measure_config = \ {"component": { "R": {"tshift_reference": 0, "tshift_acceptance_level": 10.0, "dlna_reference": 0, "dlna_acceptance_level": 1.0, "std_ratio": 0.01}, "T": {"tshift_reference": 0, "tshift_acceptance_level": 10.0, "dlna_reference": 0, "dlna_acceptance_level": 1.0, "std_ratio": 0.01}, "Z": {"tshift_reference": 0, "tshift_acceptance_level": 10.0, "dlna_reference": 0, "dlna_acceptance_level": 1.0, "std_ratio": 0.01}}, "flag": True} config = {"sensor": sensor_config, "measurement": measure_config} _wins, _meas, log = fw.filter_windows(windows, stations, measures, config, verbose=False) assert len(_wins) == 0 assert len(_meas) == 0
def test_filter_windows(): sensor_config = {"flag": True, "sensor_types": ["STS-1", "STS1"]} measure_config = \ {"component": { "R": {"tshift_reference": 0, "tshift_acceptance_level": 6.0, "dlna_reference": 0, "dlna_acceptance_level": 1.0, "std_ratio": 3.0}, "T": {"tshift_reference": 0, "tshift_acceptance_level": 6.0, "dlna_reference": 0, "dlna_acceptance_level": 1.0, "std_ratio": 3.0}, "Z": {"tshift_reference": 0, "tshift_acceptance_level": 6.0, "dlna_reference": 0, "dlna_acceptance_level": 1.0, "std_ratio": 3.0}}, "flag": True} config = {"sensor": sensor_config, "measurement": measure_config} _wins, _meas, log = fw.filter_windows( windows, stations, measures, config, verbose=False) assert _wins["II.AAK"] == windows["II.AAK"] assert _wins["II.ABKT"]["II.ABKT..BHR"] == \ windows["II.ABKT"]["II.ABKT..BHR"] assert "II.ABKT..BHZ" not in _wins["II.ABKT"] assert "II.ABKT..BHT" not in _wins["II.ABKT"] assert "IU.BCD" not in _wins["II.ABKT"] assert _meas["II.AAK"] == { "II.AAK..BHR": [{"dt": 1.0, "misfit_dt": 1.0, "dlna": 0.7, "misfit_dlna": 1.0}, {"dt": -1.0, "misfit_dt": 1.0, "dlna": -0.7, "misfit_dlna": 1.0}], "II.AAK..BHT": [{"dt": 1.5, "misfit_dt": 2.5, "dlna": 0.9, "misfit_dlna": 0.5}], "II.AAK..BHZ": [{"dt": 1.0, "misfit_dt": 1.0, "dlna": 0.6, "misfit_dlna": 1.0}, {"dt": 2.0, "misfit_dt": 4.0, "dlna": 0.4, "misfit_dlna": 0.6}, {"dt": -1.5, "misfit_dt": 3.00, "dlna": -0.5, "misfit_dlna": 1.0}]} assert _meas["II.ABKT"] == { "II.ABKT..BHR": [{"dt": 1.0, "misfit_dt": 1.5, "dlna": 0.6, "misfit_dlna": 0.5}]} assert_wins_and_meas_same_length(_wins, _meas) print(log) _true_log = \ {'sensor': { 'window_rejection_percentage': '50.00', 'nwindows_old': 18, 'channel_rejection_percentage': '37.50', 'nwindows_new': 9, 'nchannels_new': 5, 'nchannels_old': 8}, 'measurement': { 'window_rejection_percentage': '22.22', 'nwindows_old': 9, 'channel_rejection_percentage': '20.00', 'nwindows_new': 7, 'nchannels_new': 4, 'nchannels_old': 5}} assert log == _true_log
def run_window_filter(paths, params, verbose=False): check_path(paths) check_param(params) window_file = paths["window_file"] station_file = paths["station_file"] output_file = paths["output_file"] measurement_file = paths["measurement_file"] windows = load_json(window_file) # count the number of windows in the original window file nchans_old, nwins_old, nwins_comp_old = count_windows(windows) stations = load_json(station_file) measurements = load_json(measurement_file) # filter the window based on given sensor types windows_new, measures_new, log = filter_windows( windows, stations, measurements, params, verbose=verbose) nchans_new, nwins_new, nwins_comp_new = count_windows(windows_new) assert_windows_and_measurements_same_length(windows_new, measures_new) print("=" * 10 + " Summary " + "=" * 10) print("channels: %d --> %d" % (nchans_old, nchans_new)) print("windows: %d -- > %d" % (nwins_old, nwins_new)) print("Old component windows: %s" % (nwins_comp_old)) print("New component windows: %s" % (nwins_comp_new)) # dump the new windows file to replace the original one print("Filtered window files: %s" % output_file) dump_json(windows_new, output_file) new_measure_file = measurement_file + ".filter" print("Filtered measurement file: %s" % new_measure_file) dump_json(measures_new, new_measure_file) # dump the log file logfile = os.path.join(os.path.dirname(output_file), "filter.log") print("Log file located at: %s" % logfile) dump_json(log, logfile)