예제 #1
0
def test_ifas_masked_std():
    """ This tests the standard deviation computation with masked 
    arrays."""

    # Creating the testing array of integers.
    test_array = test.base.create_prime_test_array(shape=(5,5))

    # Creating the mask for this array.
    column_indexes = [0,1,3,4]
    row_indexes = [1,4,2,3]
    mask_array = mask.mask_single_pixels(data_array=test_array,
                                         column_indexes=column_indexes,
                                         row_indexes=row_indexes)

    # Creating a masked array.
    masked_array = np_ma.array(test_array, mask=mask_array)

    # The std.
    std = core.math.ifas_masked_std(array=masked_array)

    # Test the population std against the expected value.
    CHECK_STRING = '29.08662486490562'
    CHECK_NUMBER = sy.Float(CHECK_STRING)

    # Checking the mean itself.
    assert_message = ("The check std value is: {check}  "
                      "The std value is: {std} "
                      "The array is: \n {array}"
                      .format(check=CHECK_NUMBER, std=std,
                              array=masked_array))
    assert math.isclose(std, CHECK_NUMBER), assert_message
    # All done.
    return None
예제 #2
0
def test_ifas_masked_median():
    """ This tests the median computation with masked arrays."""

    # Creating the testing array of integers.
    test_array = test.base.create_prime_test_array(shape=(5,5))

    # Creating the mask for this array.
    column_indexes = [0,1,3,4]
    row_indexes = [1,4,2,3]
    mask_array = mask.mask_single_pixels(data_array=test_array,
                                         column_indexes=column_indexes,
                                         row_indexes=row_indexes)

    # Creating a masked array.
    masked_array = np_ma.array(test_array, mask=mask_array)

    # The median.
    median = core.math.ifas_masked_median(array=masked_array)

    # Test the median against the expected value.
    CHECK_STRING = '37'
    CHECK_NUMBER = sy.Integer(CHECK_STRING)

    # Checking the mean itself.
    assert_message = ("The check median value is: {check}  "
                      "The median value is: {median} "
                      "The array is: \n {array}"
                      .format(check=CHECK_NUMBER, median=median,
                              array=masked_array))
    assert median == CHECK_NUMBER, assert_message
    # All done.
    return None
def test_mask_single_pixels():
    """ This tests the masking of single pixels."""

    # Creating the testing array.
    test_array = test.base.create_prime_test_array(shape=(10, 10))

    # Prescribed masking parameters
    # Every other column.
    column_indexes = [1, 2, 3, 4, 8, 7, 6, 5, 1, 1, 8, 8]
    row_indexes = [1, 2, 3, 4, 5, 6, 7, 8, 8, 6, 1, 3]
    # Create the mask.
    test_mask = mask.mask_single_pixels(data_array=test_array,
                                        column_indexes=column_indexes,
                                        row_indexes=row_indexes)
    # Create a masked array for both convince and testing.
    test_masked_array = np_ma.array(test_array, mask=test_mask, dtype=int)

    # A properly completed mask should have the same product value
    # as this number. This is how the mask is checked.
    CHECK_STRING = '192.684278256839293972761174821265114117452620'
    CHECK_LOGARITHM = sy.Float(CHECK_STRING)
    __, __, product_log10 = core.math.ifas_large_integer_array_product(
        integer_array=test_masked_array.compressed())

    # Finally, check. As we are dealing with large single power
    # prime composite numbers and long decimals, and the smallest
    # factor change of removing the 2 product still changes the
    # logarithm enough, checking if the logs are close is good
    # enough.
    assert_message = ("The check logarithm is: {check}  "
                      "The product logarithm is: {log} "
                      "The masked array is: \n {array}".format(
                          check=CHECK_LOGARITHM,
                          log=product_log10,
                          array=test_masked_array))
    assert math.isclose(product_log10, CHECK_LOGARITHM), assert_message
    # All done.
    return None