Пример #1
0
def test_channel_pair(config_all):
    """Tests member functions of channel_pair."""
    import sys
    import os
    sys.path.append(os.path.abspath('delta'))
    from delta.data_models.channels_2d import channel_2d, channel_pair

    ch1 = channel_2d(13, 7, 24, 8, 'horizontal')
    ch2 = channel_2d(12, 7, 24, 8, 'horizontal')

    assert(channel_pair(ch1, ch2) == channel_pair(ch2, ch1))
Пример #2
0
def test_channel_2d(config_all):
    """Tests channel_2d object."""
    import sys
    import os
    sys.path.append(os.path.abspath('delta'))
    from delta.data_models.channels_2d import channel_2d

    ch_v = 6
    ch_h = 3
    ch = channel_2d(ch_v, ch_h, 24, 8, "horizontal")

    assert(ch.__str__() == f"({ch_v:03d}, {ch_h:03d})")
    assert(ch == channel_2d(ch_v, ch_h, 24, 8, "horizontal"))
    assert(ch.get_num() == (ch_v - 1) * 8 + ch_h)
    assert(ch.get_idx() == (ch_v - 1) * 8 + ch_h - 1)
Пример #3
0
def test_channel_range_v(config_all):
    """Tests channel_range object."""
    import sys
    import os
    sys.path.append(os.path.abspath('delta'))
    from delta.data_models.channels_2d import channel_2d, channel_range

    ch_start = channel_2d(2, 3, 6, 6, "vertical")
    ch_end = channel_2d(5, 5, 6, 6, "vertical")

    ch_rg = channel_range(ch_start, ch_end)
    assert(ch_rg.length() == 12)
    i = 0
    for _ in ch_rg:
        i += 1
    assert(i == ch_rg.length())
Пример #4
0
def test_ecei_channel_geom(stream_attrs_018431, stream_attrs_022289):
    """Verify calculated ECEI channel positions are the same as in fluctana."""
    import sys
    import os
    sys.path.append(os.path.abspath('delta'))
    import numpy as np
    # Import packages as delta.... so that we can run pytest as
    from delta.data_models.channels_2d import channel_2d
    from delta.data_models.kstar_ecei import get_geometry

    # Pick a random channel
    ch_h = np.random.randint(1, 9)
    ch_v = np.random.randint(1, 25)
    ch_2d = channel_2d(ch_v, ch_h, 24, 8, order="horizontal")

    for stream_attrs in [stream_attrs_018431, stream_attrs_022289]:
        K = kstarecei_mockup(ch_h, ch_v, stream_attrs["dev"],
                             stream_attrs["LoFreq"], stream_attrs["TFcurrent"],
                             stream_attrs["LensFocus"],
                             stream_attrs["LensZoom"], stream_attrs["Mode"])
        pos_true = K.channel_position()
        print("pos_true = ", pos_true)
        rpos_arr, zpos_arr, apos_arr = get_geometry(stream_attrs)
        print("Re-factored:", ch_2d.get_idx())
        print(
            f"rpos = {rpos_arr[ch_2d.get_idx()]}, zpos = {zpos_arr[ch_2d.get_idx()]}, apos = {apos_arr[ch_2d.get_idx()]}"
        )
        pos_delta = np.array([
            rpos_arr[ch_2d.get_idx()], zpos_arr[ch_2d.get_idx()],
            apos_arr[ch_2d.get_idx()]
        ])

        assert (np.linalg.norm(pos_true - pos_delta) < 1e-8)
Пример #5
0
def test_kernel_coherence(gen_sine_waves):
    """Test coherence."""
    import sys
    import os
    sys.path.append(os.path.abspath('delta'))
    import numpy as np
    from delta.analysis.kernels_spectral import kernel_coherence
    from delta.data_models.channels_2d import channel_2d, channel_pair

    ch1 = channel_2d(1, 1, 2, 1, "horizontal")
    ch2 = channel_2d(2, 1, 2, 1, "horizontal")
    ch_pair = channel_pair(ch1, ch2)

    fft_data = gen_sine_waves
    coherence = kernel_coherence(fft_data, [ch_pair], None)

    assert ((np.abs(coherence.mean()) - 1.0) < 1e-8)
Пример #6
0
def test_kernel_crosspower(gen_sine_waves):
    """Test crosspower."""
    import sys
    import os
    sys.path.append(os.path.abspath('delta'))
    from delta.analysis.kernels_spectral import kernel_crosspower
    from delta.data_models.channels_2d import channel_2d, channel_pair

    ch1 = channel_2d(1, 1, 2, 1, "horizontal")
    ch2 = channel_2d(2, 1, 2, 1, "horizontal")
    ch_pair = channel_pair(ch1, ch2)

    fft_data = gen_sine_waves
    crosspower = kernel_crosspower(fft_data, [ch_pair], {"win_factor": 1})

    assert (crosspower[0, 2] > crosspower.mean())
    assert (crosspower[0, 8] > crosspower.mean())
Пример #7
0
def test_kernel_crossphase(gen_sine_waves):
    """Test crosspower."""
    import sys
    import os
    sys.path.append(os.path.abspath('delta'))
    import numpy as np
    from delta.analysis.kernels_spectral import kernel_crossphase
    from delta.data_models.channels_2d import channel_2d, channel_pair

    ch1 = channel_2d(1, 1, 2, 1, "horizontal")
    ch2 = channel_2d(2, 1, 2, 1, "horizontal")
    ch_pair = channel_pair(ch1, ch2)

    fft_data = gen_sine_waves
    crossphase = kernel_crossphase(fft_data, [ch_pair], {"win_factor": 1})

    assert (np.abs(np.abs(crossphase[0, 2]) - 0.25) < 1e-7)
    assert (np.abs(np.abs(crossphase[0, 8]) - 0.5) < 1e-7)
Пример #8
0
def test_kernel_coherence(caplog, gen_sine_waves):
    """Test coherence."""
    import sys
    import os
    sys.path.append(os.path.abspath('delta'))
    import numpy as np
    from delta.analysis.kernels_spectral import kernel_coherence
    from delta.data_models.channels_2d import channel_2d, channel_pair

    import logging
    logger = logging.getLogger(__name__)
    caplog.set_level(logging.INFO)

    ch1 = channel_2d(1, 1, 2, 1, "horizontal")
    ch2 = channel_2d(2, 1, 2, 1, "horizontal")
    ch_pair = channel_pair(ch1, ch2)

    logger.info(f"{ch1.get_idx()} {ch2.get_idx()}")

    fft_data = gen_sine_waves
    coherence = kernel_coherence(fft_data, [ch_pair], None)

    assert ((np.abs(coherence.mean()) - 1.0) < 1e-8)