def test_lut(self):
        """Confirm LUTs are identical."""

        for example in examples:
            if not (e_path / example / "outputs/runs/example_run").is_dir():
                continue

            print(f"Testing contents of lookup tables from {example} run.")
            b_dir = b_path / example
            t_dir = e_path / example / "outputs" / "lut"

            b_lut = read_lut((sorted(b_dir.glob("*.LUT"))[0]))
            t_lut = read_lut((sorted(t_dir.glob("*.LUT"))[0]))

            print("\t1: Assert traveltime tables are identical...")
            b_tt = b_lut.serve_traveltimes(50)
            t_tt = t_lut.serve_traveltimes(50)
            self.assertTrue((b_tt == t_tt).all())

            print("\t2: Assert various LUT parameters are identical...")
            print("\t\t...'fraction_tt'...")
            self.assertEqual(b_lut.fraction_tt, t_lut.fraction_tt)
            print("\t\t...'phases'...")
            self.assertEqual(b_lut.phases, t_lut.phases)
            print("\t\t...'station_data'...")
            pd.testing.assert_frame_equal(b_lut.station_data,
                                          t_lut.station_data,
                                          check_exact=False)
            print("\t\t...'grid_proj'...")
            self.assertEqual(b_lut.grid_proj, t_lut.grid_proj)
            print("\t\t...'coord_proj'...")
            self.assertEqual(b_lut.coord_proj, t_lut.coord_proj)
            print("\t\t...'ll_corner'...")
            self.assertTrue(np.isclose(b_lut.ll_corner, t_lut.ll_corner).all())
            print("\t\t...'ur_corner'...")
            self.assertTrue(np.isclose(b_lut.ur_corner, t_lut.ur_corner).all())
            print("\t\t...'node_spacing'...")
            self.assertTrue(
                np.equal(b_lut.node_spacing, t_lut.node_spacing).all())
            print("\t\t...'node_count'...")
            self.assertTrue(np.equal(b_lut.node_count, t_lut.node_count).all())
            print("\t   ...passed!")
Example #2
0
def update_lut(old_lut_file, save_file):
    """
    Utility function to convert old-style LUTs to new-style LUTs.

    Parameters
    ----------
    old_lut_file : str
        Path to lookup table file to update.
    save_file : str, optional
        Output path for updated lookup table.

    """

    from quakemigrate.io import read_lut

    lut = read_lut(old_lut_file)

    try:
        traveltimes = {}
        for station, phases in lut.maps.items():
            for phase, ttimes in phases.items():
                phase_code = phase.split("_")[1]
                traveltimes.setdefault(station,
                                       {}).update({phase_code: ttimes})
        lut.traveltimes = traveltimes
        del lut.maps
    except AttributeError:
        pass
    lut.phases = ["P", "S"]
    lut.fraction_tt = 0.1
    try:
        lut.node_spacing = lut.cell_size
        lut.node_count = lut.cell_count
        del lut._cell_size, lut._cell_count
    except AttributeError:
        pass

    lut.save(save_file)
# --- Specify parameters for amplitude measurement ---
amp_params = AttribDict()
amp_params.signal_window = 5.0
amp_params.highpass_filter = True
amp_params.highpass_freq = 2.0

# --- Specify parameters for magnitude calculation ---
mag_params = AttribDict()
mag_params.A0 = "Greenfield2018_bardarbunga"
mag_params.amp_feature = "S_amp"

mags = LocalMag(amp_params=amp_params, mag_params=mag_params,
                plot_amplitudes=True)

# --- Load the LUT ---
lut = read_lut(lut_file=lut_file)

# --- Create new Onset ---
onset = STALTAOnset(position="centred", sampling_rate=50)
onset.phases = ["P", "S"]
onset.bandpass_filters = {
    "P": [2, 16, 2],
    "S": [2, 16, 2]}
onset.sta_lta_windows = {
    "P": [0.2, 1.0],
    "S": [0.2, 1.0]}

# --- Create new PhasePicker ---
picker = GaussianPicker(onset=onset)
picker.plot_picks = True