Ejemplo n.º 1
0
def test_plt_waterfall_savefig():
    power, times = read_data(
        rf_file=f"{test_data}/rf_tools/rf_data/S06XX/2019-10-01/S06XX_2019-10-01-14:30.txt"
    )
    plt = plt_waterfall(power, times, "S06XX-test")
    plt.savefig(f"{test_data}/rf_tools/plt_waterfall_test.png")
    test_file_path = Path(f"{test_data}/rf_tools/plt_waterfall_test.png")
    assert test_file_path.is_file() is True
    if test_file_path.is_file():
        test_file_path.unlink()
Ejemplo n.º 2
0
def savgol_interp(
    ref,
    tile,
    savgol_window_1=None,
    savgol_window_2=None,
    polyorder=None,
    interp_type=None,
    interp_freq=None,
):
    """Interpolate a power array followed by savgol smoothing.

    Interpolate to a given frequency,
    making the dimensions of the power arrays
    from reference and tile antennas equal,
    enabling comparisons between corresponding
    data points. Two level of savgol filter applied,
    first to capture deep nulls + small structure,
    and second level to smooth over noise.

    .. code-block:: python

        from embers.rf_tools.align_data import savgol_interp

         sg_interp_tuple = savgol_interp(
                            "~/embers-data/rf0XX.txt",
                            "~/embers-data/S06XX",
                            savgol_window_1=11,
                            savgol_window_2=15,
                            polyorder=2,
                            interp_type="cubic",
                            interp_freq=1)

        (ref_ali, tile_ali, time_array,
            ref_power, tile_power, ref_time, tile_time) = sg_interp_tuple

    :param ref: path to reference data file :class:`~str`
    :param tile: path to tile data file :class:`~str`
    :param savgol_window_1:  window size of savgol filer, must be odd :class:`~int`
    :param savgol_window_2:  window size of savgol filer, must be odd :class:`~int`
    :param polyorder: polynomial order to fit to savgol_window :class:`~int`
    :param interp_type: type of interpolation. Ex: 'cubic', 'linear' :class:`~str`
    :param interp_freq: freqency to which power array is interpolated in Hertz :class:`~int`

    :returns:
        A :class:`~tuple` (ref_ali, tile_ali, time_array, ref_power, tile_power, ref_time, tile_time)

        - ref_ali - aligned reference power array
        - tile_ali - aligned tile power array
        - time_array - corresponding to power arrays
        - ref_power - raw reference power array
        - tile_power - raw tile power array
        - ref_time - raw reference time array
        - tile_time - raw tile time array

    """

    # Read time and power arrays from data files
    ref_power, ref_time = read_data(ref)
    tile_power, tile_time = read_data(tile)

    # Round up/down to nearest integer of time
    start_time = math.ceil(max(ref_time[0], tile_time[0]))
    stop_time = math.floor(min(ref_time[-1], tile_time[-1]))

    # Array of times at which to evaluate the interpolated data
    time_array = np.arange(start_time, stop_time, (1 / interp_freq))

    # Mathematical interpolation functions
    f = interpolate.interp1d(ref_time, ref_power, axis=0, kind=interp_type)
    g = interpolate.interp1d(tile_time, tile_power, axis=0, kind=interp_type)

    # New power array, evaluated at the desired frequency
    ref_ali = f(time_array)
    tile_ali = g(time_array)

    # Savgol level 1. Capture nulls / small scale structure
    ref_ali = savgol_filter(ref_ali, savgol_window_1, polyorder, axis=0)
    tile_ali = savgol_filter(tile_ali, savgol_window_1, polyorder, axis=0)

    # Savgol level 2. Smooth noise
    ref_ali = savgol_filter(ref_ali, savgol_window_2, polyorder, axis=0)
    tile_ali = savgol_filter(tile_ali, savgol_window_2, polyorder, axis=0)

    return (ref_ali, tile_ali, time_array, ref_power, tile_power, ref_time,
            tile_time)
Ejemplo n.º 3
0
def test_read_data_time_arrow():
    _, times = read_data(
        rf_file=f"{test_data}/rf_tools/rf_data/S06XX/2019-10-01/S06XX_2019-10-01-14:30.txt"
    )
    assert times[0] <= times[-1]
Ejemplo n.º 4
0
def test_read_data_return_type():
    _, times = read_data(
        rf_file=f"{test_data}/rf_tools/rf_data/S06XX/2019-10-01/S06XX_2019-10-01-14:30.txt"
    )
    assert type(times).__name__ == "ndarray"
Ejemplo n.º 5
0
def test_read_data_power_times_shape():
    power, times = read_data(
        rf_file=f"{test_data}/rf_tools/rf_data/S06XX/2019-10-01/S06XX_2019-10-01-14:30.txt"
    )
    assert list(times.shape)[0] == list(power.shape)[0]
Ejemplo n.º 6
0
def test_read_data_power_shape():
    power, _ = read_data(
        rf_file=f"{test_data}/rf_tools/rf_data/S06XX/2019-10-01/S06XX_2019-10-01-14:30.txt"
    )
    assert power.shape == (16655, 112)
Ejemplo n.º 7
0
def test_plt_waterfall():
    power, times = read_data(
        rf_file=f"{test_data}/rf_tools/rf_data/S06XX/2019-10-01/S06XX_2019-10-01-14:30.txt"
    )
    plt = plt_waterfall(power, times, "S06XX-test")
    assert type(plt).__name__ == "module"