Ejemplo n.º 1
0
def test_projectgather_get_indices_site3_data1(
    mock_project_site, mock_spec_reader_metadata_only
):
    """Test project gathering of data"""
    # get required data
    site = MockSite("site3")
    meas_name = "data1"
    metadata = get_evals_metadata(site.name, meas_name)
    selection = get_selection()
    # now test gatherer._get_indices
    gatherer = gather.ProjectGather()
    # site 3, data1, level 0
    eval_wins = selection.get_eval_wins(0, 0)
    level_metadata = metadata.levels_metadata[0]
    spectra_indices, combined_indices = gatherer._get_indices(
        eval_wins, site, meas_name, level_metadata
    )
    expected_spectra = [0, 1, 2, 3, 4, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21]
    expected_combined = np.arange(15)
    np.testing.assert_array_equal(spectra_indices, np.array(expected_spectra))
    np.testing.assert_array_equal(combined_indices, expected_combined)
    # site 3, data1, level 1
    eval_wins = selection.get_eval_wins(1, 0)
    level_metadata = metadata.levels_metadata[1]
    spectra_indices, combined_indices = gatherer._get_indices(
        eval_wins, site, meas_name, level_metadata
    )
    np.testing.assert_array_equal(spectra_indices, np.array([0, 7, 8, 9, 10]))
    np.testing.assert_array_equal(combined_indices, np.array([0, 1, 2, 3, 4]))
Ejemplo n.º 2
0
def test_projectgather_get_indices_site2_run2(
    mock_project_site, mock_spec_reader_metadata_only
):
    """Test project gathering of data"""
    # get required data
    site = MockSite("site2")
    meas_name = "run2"
    metadata = get_evals_metadata(site.name, meas_name)
    selection = get_selection()
    # now test gatherer._get_indices
    gatherer = gather.ProjectGather()
    # site 2, run1, level 0
    eval_wins = selection.get_eval_wins(0, 0)
    level_metadata = metadata.levels_metadata[0]
    spectra_indices, combined_indices = gatherer._get_indices(
        eval_wins, site, meas_name, level_metadata
    )
    expected_spectra = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    expeceted_combined = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
    np.testing.assert_array_equal(spectra_indices, np.array(expected_spectra))
    np.testing.assert_array_equal(combined_indices, np.array(expeceted_combined))
    # site 2, run1, level 1
    eval_wins = selection.get_eval_wins(1, 0)
    level_metadata = metadata.levels_metadata[1]
    spectra_indices, combined_indices = gatherer._get_indices(
        eval_wins, site, meas_name, level_metadata
    )
    np.testing.assert_array_equal(spectra_indices, np.array([1, 2, 3, 4]))
    np.testing.assert_array_equal(combined_indices, np.array([1, 2, 3, 4]))
Ejemplo n.º 3
0
def test_projectgather_get_indices_site1_meas1(
    mock_project_site, mock_spec_reader_metadata_only
):
    """Test project gathering of data"""
    # get required data
    site = MockSite("site1")
    meas_name = "meas1"
    metadata = get_evals_metadata(site.name, meas_name)
    selection = get_selection()
    # now test gatherer._get_indices
    gatherer = gather.ProjectGather()
    # site 1, meas1, level 0
    eval_wins = selection.get_eval_wins(0, 0)
    level_metadata = metadata.levels_metadata[0]
    spectra_indices, combined_indices = gatherer._get_indices(
        eval_wins, site, meas_name, level_metadata
    )
    np.testing.assert_array_equal(spectra_indices, np.array([0, 1, 2, 3, 4]))
    np.testing.assert_array_equal(combined_indices, np.array([0, 1, 2, 3, 4]))
    # site 1, meas1, level 1
    eval_wins = selection.get_eval_wins(1, 0)
    level_metadata = metadata.levels_metadata[1]
    spectra_indices, combined_indices = gatherer._get_indices(
        eval_wins, site, meas_name, level_metadata
    )
    np.testing.assert_array_equal(spectra_indices, np.array([1]))
    np.testing.assert_array_equal(combined_indices, np.array([0]))
Ejemplo n.º 4
0
def test_projectgather_run(mock_project_site, mock_spec_reader_metadata_only):
    """Test gathering data for all sites"""
    # get required data
    proj = get_test_project(TEST_PROJECT_PATH)
    tf = ImpedanceTensor()
    selection = get_selection()
    gathered_data = gather.ProjectGather().run(
        TEST_CONFIG_NAME,
        proj,
        selection,
        tf,
        out_name="site1",
        in_name="site2",
        cross_name="site3",
    )
    # output data
    assert gathered_data.out_data.metadata.site_name == "site1"
    assert gathered_data.out_data.metadata.chans == ["Ex", "Ey"]
    assert gathered_data.out_data.metadata.fs == 128
    assert gathered_data.out_data.metadata.n_evals == 4
    np.testing.assert_equal(gathered_data.out_data.data[0], SITE1_COMBINED_DATA[0])
    np.testing.assert_equal(gathered_data.out_data.data[1], SITE1_COMBINED_DATA[1])
    np.testing.assert_equal(gathered_data.out_data.data[2], SITE1_COMBINED_DATA[2])
    np.testing.assert_equal(gathered_data.out_data.data[3], SITE1_COMBINED_DATA[3])
    # input data
    assert gathered_data.in_data.metadata.site_name == "site2"
    assert gathered_data.in_data.metadata.chans == ["Hx", "Hy"]
    assert gathered_data.in_data.metadata.fs == 128
    assert gathered_data.in_data.metadata.n_evals == 4
    np.testing.assert_equal(gathered_data.in_data.data[0], SITE2_COMBINED_DATA[0])
    np.testing.assert_equal(gathered_data.in_data.data[1], SITE2_COMBINED_DATA[1])
    np.testing.assert_equal(gathered_data.in_data.data[2], SITE2_COMBINED_DATA[2])
    np.testing.assert_equal(gathered_data.in_data.data[3], SITE2_COMBINED_DATA[3])
    # cross data
    assert gathered_data.cross_data.metadata.site_name == "site3"
    assert gathered_data.cross_data.metadata.chans == ["Hx", "Hy"]
    assert gathered_data.cross_data.metadata.fs == 128
    assert gathered_data.cross_data.metadata.n_evals == 4
    np.testing.assert_equal(gathered_data.cross_data.data[0], SITE3_COMBINED_DATA[0])
    np.testing.assert_equal(gathered_data.cross_data.data[1], SITE3_COMBINED_DATA[1])
    np.testing.assert_equal(gathered_data.cross_data.data[2], SITE3_COMBINED_DATA[2])
    np.testing.assert_equal(gathered_data.cross_data.data[3], SITE3_COMBINED_DATA[3])
Ejemplo n.º 5
0
def test_projectgather_get_empty_data(
    mock_project_site, mock_spec_reader_metadata_only
):
    """Test creating empty data"""
    selection = get_selection()
    chans = ["Hx", "Hy"]
    n_chans = len(chans)
    # now test gatherer._get_empty_data
    gatherer = gather.ProjectGather()
    empty_data = gatherer._get_empty_data(selection, chans)
    assert len(empty_data) == 4
    assert sorted(list(empty_data.keys())) == [0, 1, 2, 3]
    # check size of arrays
    for eval_idx, data in empty_data.items():
        # two decimation levels
        level = eval_idx // 2
        eval_level_idx = eval_idx - level * 2
        n_wins = selection.get_n_wins(level, eval_level_idx)
        assert data.shape == (n_wins, n_chans)
        assert data.dtype == np.complex128
Ejemplo n.º 6
0
def test_projectgather_get_site_data_site3(
    mock_project_site, mock_spec_reader_metadata_only
):
    """Test combining data for site1"""
    # get required data
    proj = get_test_project(TEST_PROJECT_PATH)
    site_name = "site3"
    selection = get_selection()
    # now test gatherer._get_indices
    gatherer = gather.ProjectGather()
    combined_data = gatherer._get_site_data(
        TEST_CONFIG_NAME, proj, selection, site_name, ["Hx", "Hy"]
    )
    assert len(combined_data.data) == 4
    assert combined_data.metadata.chans == ["Hx", "Hy"]
    assert combined_data.metadata.n_evals == 4
    assert combined_data.metadata.measurements == ["data1"]
    np.testing.assert_equal(combined_data.data[0], SITE3_COMBINED_DATA[0])
    np.testing.assert_equal(combined_data.data[1], SITE3_COMBINED_DATA[1])
    np.testing.assert_equal(combined_data.data[2], SITE3_COMBINED_DATA[2])
    np.testing.assert_equal(combined_data.data[3], SITE3_COMBINED_DATA[3])