Beispiel #1
0
def test_adjusted_expected_tile_some_nans_and_square_tiling():
    print("Running tile some nans la_exp test + square tiling")
    # first, generate that locally-adjusted expected:
    nnans = 1
    band_idx = int(band / b)
    res_df = pd.DataFrame([])
    for tilei, tilej in square_matrix_tiling(start,
                                             stop,
                                             tile_size=40,
                                             edge=w,
                                             square=False):
        # define origin:
        origin = (tilei[0], tilej[0])
        # RAW observed matrix slice:
        observed = mock_M_raw[slice(*tilei), slice(*tilej)]
        # trying new expected function:
        expected = tile_of_expected(start, tilei, tilej, get_mock_exp)
        # for diagonal chuynking/tiling tilei==tilej:
        ice_weight_i = mock_v_ice[slice(*tilei)]
        ice_weight_j = mock_v_ice[slice(*tilej)]
        # that's the main working function from loopify:
        res = get_adjusted_expected_tile_some_nans(
            origin=origin,
            observed=observed,
            expected=expected,
            bal_weight=(ice_weight_i, ice_weight_j),
            kernels={
                "donut": kernel,
                "footprint": np.ones_like(kernel)
            },
            # nan_threshold=1,
            verbose=False)
        is_inside_band = (res["row"] > (res["col"] - band_idx))
        # new style, selecting good guys:
        does_comply_nans = (res["la_exp." + "footprint" + ".nnans"] < nnans)
        # so, select inside band and nNaNs compliant results and append:
        res_df = res_df.append(res[is_inside_band & does_comply_nans],
                               ignore_index=True)

    # drop dups (from overlaping tiles), sort and reset index:
    res_df = res_df \
                .drop_duplicates() \
                .sort_values(by=['row','col']) \
                .reset_index(drop=True)

    # prepare mock_data for comparison:
    # apparently sorting is needed in this case:
    mock_res_sorted = mock_res.sort_values(by=['row', 'col']).reset_index(
        drop=True)

    # ACTUAL TESTS:
    # integer part of DataFrame must equals exactly:
    assert (res_df[['row', 'col']].equals(mock_res_sorted[['row', 'col']]))
    # compare floating point part separately:
    assert (np.isclose(res_df["la_exp." + "donut" + ".value"],
                       mock_res_sorted['la_expected'],
                       equal_nan=True).all())
Beispiel #2
0
def test_tile_exp_diag_rectangle():
    # ####################
    # requested tile is on the diag
    # rectangular tile!
    # ####################
    i0, i1 = 50, 100
    j0, j1 = 50, 80
    #
    E_tile_ref = mock_E_ice[i0:i1, j0:j1]
    # now, let's try to reconstruct it
    # from diag-indexed vector using
    expected = tile_of_expected(start, (i0, i1), (j0, j1), get_mock_exp)
    ##########################
    assert np.isclose(E_tile_ref, expected, equal_nan=True).all()
Beispiel #3
0
def test_tile_exp_lower():
    # ####################
    # requested tile is in the lower
    # triangle of the matrix region
    # ####################
    i0, i1 = 150, 200
    j0, j1 = 5, 100
    #
    E_tile_ref = mock_E_ice[i0:i1, j0:j1]
    # now, let's try to reconstruct it
    # from diag-indexed vector using
    expected = tile_of_expected(start, (i0, i1), (j0, j1), get_mock_exp)
    ##########################
    assert np.isclose(E_tile_ref, expected, equal_nan=True).all()