예제 #1
0
def test_get_external_nbrs_dict_for_watershed():

    nx = 3
    ny = 3
    heights = np.array([0, 1, 2, 1, 2, 3, 2, 3, 1])
    watersheds = [np.array([0, 1, 2, 3, 4, 6]), np.array([5, 7, 8])]
    watershed_nr = 0

    a = 1/math.sqrt(200)
    b = 2/math.sqrt(200)
    total_dict = {0: (np.array([1, 3, 4]), np.array([-0.1, -0.1, -a])),
                  1: (np.array([0, 2, 3, 4, 5]), np.array([0.1, -0.1, 0, -0.1, -b])),
                  2: (np.array([1, 4, 5]), np.array([0.1, 0, -0.1])),
                  3: (np.array([0, 1, 4, 6, 7]), np.array([0.1, 0, -0.1, -0.1, -b])),
                  4: (np.array([0, 1, 2, 3, 5, 6, 7, 8]), np.array([b, 0.1, 0, 0.1, -0.1, 0, -0.1, a])),
                  5: (np.array([1, 2, 4, 7, 8]), np.array([b, 0.1, 0.1, 0, 0.2])),
                  6: (np.array([3, 4, 7]), np.array([0.1, 0, -0.1])),
                  7: (np.array([3, 4, 5, 6, 8]), np.array([b, 0.1, 0, 0.1, 0.2])),
                  8: (np.array([4, 5, 7]), np.array([-a, -0.2, -0.2]))}
    result_external_dict = {1: (np.array([5]), np.array([-b])),
                            2: (np.array([5]), np.array([-0.1])),
                            3: (np.array([7]), np.array([-b])),
                            4: (np.array([5, 7, 8]), np.array([-0.1, -0.1, a])),
                            6: (np.array([7]), np.array([-0.1]))}

    external_dict = trap_analysis.get_external_nbrs_dict_for_watershed(watershed_nr, total_dict, watersheds, nx, ny)

    print external_dict

    are_equal = compare_methods.compare_two_dictionaries_where_values_are_tuples_with_two_arrays(
        external_dict, result_external_dict)

    assert are_equal
예제 #2
0
def test_get_neighbors_derivatives_dictionary():

    nx = 3
    ny = 3
    heights = np.array([9, 8, 7, 6, 5, 4, 3, 2, 1])
    b = 2/math.sqrt(200)
    d = 4/math.sqrt(200)

    result_neighbors_derivatives_dictionary = {0: (np.array([1, 3, 4]),
                                                   np.array([0.1, 0.3, d], dtype=float)),
                                               1: (np.array([0, 2, 3, 4, 5]),
                                                   np.array([-0.1, 0.1, b, 0.3, d], dtype=float)),
                                               2: (np.array([1, 4, 5]),
                                                   np.array([-0.1, b, 0.3], dtype=float)),
                                               3: (np.array([0, 1, 4, 6, 7]),
                                                   np.array([-0.3, -b, 0.1, 0.3, d], dtype=float)),
                                               4: (np.array([0, 1, 2, 3, 5, 6, 7, 8]),
                                                   np.array([-d, -0.3, -b, -0.1, 0.1, b, 0.3, d], dtype=float)),
                                               5: (np.array([1, 2, 4, 7, 8]),
                                                   np.array([-d, -0.3, -0.1, b, 0.3], dtype=float)),
                                               6: (np.array([3, 4, 7]),
                                                   np.array([-0.3, -b, 0.1], dtype=float)),
                                               7: (np.array([3, 4, 5, 6, 8]),
                                                   np.array([-d, -0.3, -b, -0.1, 0.1], dtype=float)),
                                               8: (np.array([4, 5, 7]),
                                                   np.array([-d, -0.3, -0.1], dtype=float))}

    neighbors_derivatives_dictionary = util.get_neighbors_derivatives_dictionary(heights, nx, ny)

    are_equal = compare_methods.compare_two_dictionaries_where_values_are_tuples_with_two_arrays(
        neighbors_derivatives_dictionary, result_neighbors_derivatives_dictionary)

    assert are_equal
예제 #3
0
def test_compare_two_dictionaries_where_values_are_tuples_with_two_arrays_three():
    # The values are in different orders

    d1 = {0: (np.array([1, 2, 3]), np.array([1, 2, 3])), 1: (np.array([4, 5, 6]), np.array([1, 2, 3]))}
    d2 = {0: (np.array([1, 2, 3]), np.array([1, 3, 2])), 1: (np.array([4, 5, 6]), np.array([1, 2, 3]))}

    are_equal = compare_methods.compare_two_dictionaries_where_values_are_tuples_with_two_arrays(d1, d2)

    assert are_equal is False
예제 #4
0
def test_compare_two_dictionaries_where_values_are_tuples_with_two_arrays_four():
    # The dictionaries are equal

    d1 = {0: (np.array([1, 2, 3]), np.array([1, 2, 3])), 1: (np.array([4, 5, 6]), np.array([1, 2, 3]))}
    d2 = {0: (np.array([1, 2, 3]), np.array([1, 2, 3])), 1: (np.array([4, 5, 6]), np.array([1, 2, 3]))}

    are_equal = compare_methods.compare_two_dictionaries_where_values_are_tuples_with_two_arrays(d1, d2)

    assert are_equal
예제 #5
0
def test_compare_two_dictionaries_where_values_are_tuples_with_two_arrays_two():
    # Dictionaries have different keys

    d1 = {0: (np.array([1, 2, 3]), np.array([1, 2, 3])), 1: (np.array([4, 5, 6]), np.array([1, 2, 3]))}
    d2 = {0: (np.array([1, 2, 3]), np.array([1, 2, 3])), 2: (np.array([4, 5, 6]), np.array([1, 2, 3]))}

    are_equal = compare_methods.compare_two_dictionaries_where_values_are_tuples_with_two_arrays(d1, d2)

    assert are_equal is False