Ejemplo n.º 1
0
def test_discover_ndv_list_three(arr_str2):
    candidates = discover_ndv(arr_str2, debug=False, verbose=True)
    mode_vals = mode(_convert_rgb(arr_str2)[1])
    candidate_original = [int((mode_vals[0])[0, i]) for i in range(3)]
    candidate_continuous, arr = _compute_continuous(
        _convert_rgb(arr_str2)[0], 1)
    candidate_list = \
        [i for i, j in zip(candidate_original,
                           candidate_continuous)
         if i == j]
    assert candidates == [1, 1, 1]
Ejemplo n.º 2
0
def test_discover_ndv_list_less_three(arr_str2):
    cons_arr = np.array(
        [
            [1, 1, 1],
            [1, 1, 1],
            [1, 2, 1],
            [1, 2, 1],
            [1, 2, 1],
            [1, 2, 1],
            [1, 1, 1],
            [1, 2, 1],
        ]
    )

    cons_arr2 = np.array(
        [
            [1, 1, 1],
            [1, 2, 1],
            [1, 1, 1],
            [1, 2, 1],
            [1, 1, 1],
            [1, 2, 1],
            [1, 1, 1],
            [1, 2, 1],
        ]
    )

    arr_str2[0] = cons_arr
    arr_str2[1:] = cons_arr2
    candidates = discover_ndv(arr_str2, debug=False, verbose=True)
    candidate_continuous, arr = _compute_continuous(_convert_rgb(arr_str2)[0], 1)
    assert candidates == "None"
Ejemplo n.º 3
0
def test_search_image_edge_ca2(test_fixtures):
    data_ca, data_ca2 = test_fixtures
    data_ca2_mod = _convert_rgb(data_ca2)[0]

    candidate_original = [255, 255, 255]
    candidate_continuous = [255, 255, 250]

    rgb_mod = np.copy(data_ca2_mod)
    top_row = rgb_mod[0, :, :]
    bottom_row = rgb_mod[-1, :, :]
    first_col = rgb_mod[:, 0, :]
    last_col = rgb_mod[:, -1, :]
    img_edge = np.concatenate((top_row, last_col, bottom_row, first_col), axis=0)
    arr = _compute_continuous(rgb_mod, 0)[-1]
    full = [
        len(np.transpose(np.where((img_edge == candidate).all(axis=1))))
        for candidate in (candidate_original, candidate_continuous)
    ]

    cont = [
        len(np.transpose(np.where((arr == candidate).all(axis=1))))
        for candidate in (candidate_original, candidate_continuous)
    ]

    assert img_edge.shape[0] == rgb_mod.shape[0] * 4
    assert full == [242, 0]
    assert cont == [7048, 0]
Ejemplo n.º 4
0
def test_discover_ndv_list_less_three2(arr_str2):
    cons_arr = np.array([[1, 1, 1], [1, 1, 1], [1, 2, 1], [1, 2, 1], [1, 2, 1],
                         [1, 2, 1], [1, 1, 1], [1, 2, 1]])

    cons_arr2 = np.array([[1, 1, 1], [1, 2, 1], [1, 1, 1], [1, 2, 1],
                          [1, 1, 1], [1, 2, 1], [1, 1, 1], [1, 2, 1]])

    arr_str2[0] = cons_arr
    arr_str2[1:] = cons_arr2
    candidates = discover_ndv(arr_str2, debug=False, verbose=False)
    mode_vals = mode(_convert_rgb(arr_str2)[1])
    candidate_original = [int((mode_vals[0])[0, i]) for i in range(3)]
    candidate_continuous, arr = _compute_continuous(
        _convert_rgb(arr_str2)[0], 1)
    candidate_list = \
        [i for i, j in zip(candidate_original,
                           candidate_continuous)
         if i == j]
    assert candidates == ''
Ejemplo n.º 5
0
def discover_ndv(rgb_orig, debug, verbose):
    """Returns nodata value by calculating mode of RGB array

    Parameters
    ----------
    rgb_orig: ndarray
              array of input pixels of shape (rows, cols, depth)
    debug: Boolean
           Enables matplotlib & printing of figures
    verbose: Boolean
             Prints extra information, like competing candidate values


    Returns
    -------
    list of nodata value candidates or empty string if none found

    """
    rgb_mod, rgb_mod_flat = _convert_rgb(rgb_orig)
    # Full image mode bincount
    mode_vals = mode(rgb_mod_flat)
    candidate_original = [int((mode_vals[0])[0, i]) for i in range(3)]

    # Find continuous values in RGB array
    candidate_continuous, arr = _compute_continuous(rgb_mod, 1)

    # If debug mode, print histograms & be verbose
    if debug:
        click.echo("Original image ndv candidate: %s" %
                   (str(candidate_original)))
        click.echo("Filtered image ndv candidate: %s" %
                   (str(candidate_continuous)))
        outplot = "/tmp/hist_plot.png"
        _debug_mode(rgb_mod_flat, arr, outplot)

    # Compare ndv candidates from full & squished image
    candidate_list = [
        i for i, j in zip(candidate_original, candidate_continuous) if i == j
    ]

    # If candidates from original & filtered images match exactly,
    # print value & exit
    if len(candidate_list) == 3:
        return candidate_list

    # If candidates do not match exactly, continue vetting process
    # by searching image edge for frequency of each candidate
    elif len(candidate_list) < 3:
        if verbose:
            click.echo("Competing ndv candidates...searching "
                       "image collar for value frequency. "
                       "Candidate list: %s" % str(candidate_list))

        count_img_edge_full, count_img_edge_continuous = _search_image_edge(
            rgb_mod, candidate_original, candidate_continuous)

        if verbose:
            for candidate in (candidate_original, candidate_continuous):
                click.echo("Candidate value: %s "
                           "Candidate count: %s "
                           "Continuous count: %s" % (
                               str(candidate),
                               str(count_img_edge_full),
                               str(count_img_edge_continuous),
                           ))

        output = _evaluate_count(count_img_edge_full,
                                 count_img_edge_continuous, verbose)

        return output

    else:
        raise ValueError("Invalid candidate list {!r}".format(candidate_list))
Ejemplo n.º 6
0
def test_discover_ndv_list_three(arr_str2):
    candidates = discover_ndv(arr_str2, debug=False, verbose=True)
    candidate_continuous, arr = _compute_continuous(_convert_rgb(arr_str2)[0], 1)
    assert candidates == [1, 1, 1]
Ejemplo n.º 7
0
def test_convert_rgb_dim_zero(rgb_orig):
    rgb_mod_flat = _convert_rgb(rgb_orig)
    assert np.array_equal(
        rgb_mod_flat[1],
        rgb_orig.reshape(rgb_orig.shape[0] * rgb_orig.shape[1], rgb_orig.shape[-1]),
    )
Ejemplo n.º 8
0
def test_convert_rgba(test_fixtures):
    a, _ = test_fixtures
    amod = _convert_rgb(a)[0]
    assert amod.shape == (167, 167, 3)