<commit_before># s2p (Satellite Stereo Pipeline) testing module
# Copyright (C) 2019, <NAME> (CMLA) <<EMAIL>>
# Copyright (C) 2019, <NAME> (CNES) <<EMAIL>>

import os
import numpy as np
import rpcm

import s2p
from s2p import sift
from s2p import config
from tests_utils import data_path


def test_image_keypoints():
    """
    """
    kpts = sift.image_keypoints(data_path('input_triplet/img_02.tif'), 100,
                                100, 200, 200)

    ref_kpts = np.loadtxt(data_path('expected_output/units/unit_image_keypoints.txt'))
    np.testing.assert_allclose(kpts[:, :2], ref_kpts[:, :2], atol=1e-3)


def assert_arrays_are_equal(a, b, rtol=0.01, atol=0.1, verbose=True):
    """
    Test if two numpy arrays are equal up to tolerance.
    """
    # check that the shapes are the same
    np.testing.assert_equal(a.shape, b.shape, verbose=verbose)

    # check that the arrays elements are the same
    np.testing.assert_allclose(a, b, rtol=rtol, atol=atol, verbose=verbose)


def test_matching():
    """
    """
    computed = sift.keypoints_match(np.loadtxt(data_path('units/sift1.txt')),
                                    np.loadtxt(data_path('units/sift2.txt')))
    expected = np.loadtxt(data_path('expected_output/units/unit_keypoints_match.txt'))
    assert_arrays_are_equal(computed, expected)


def test_matches_on_rpc_roi():
    """
    Test SIFT matching of two image ROIs.
    """
    img1 = data_path('input_triplet/img_01.tif')
    img2 = data_path('input_triplet/img_02.tif')
    rpc1 = rpcm.rpc_from_geotiff(img1)
    rpc2 = rpcm.rpc_from_geotiff(img2)
    computed = s2p.sift.matches_on_rpc_roi(img1, img2, rpc1, rpc2, 100, 100,
                                           200, 200)
    expected = np.loadtxt(data_path('expected_output/units/matches_on_rpc_roi.txt'))
    assert_arrays_are_equal(computed, expected)
<commit_msg>[refactor] add docstrings and remove unused stuff from sift_test.py<commit_after># s2p.sift testing module
# Copyright (C) 2019, <NAME> (CMLA) <<EMAIL>>
# Copyright (C) 2019, <NAME> (CNES) <<EMAIL>>

import numpy as np
import rpcm

from s2p import sift
from tests_utils import data_path


def test_image_keypoints():
    """
    Unit test for the function s2p.sift.image_keypoints.

    Right now it tests only the x, y coordinates of keypoints.
    """
    computed = sift.image_keypoints(data_path('input_triplet/img_02.tif'),
                                    100, 100, 200, 200)
    expected = np.loadtxt(data_path('expected_output/units/unit_image_keypoints.txt'))
    np.testing.assert_allclose(computed[:, :2], expected[:, :2], atol=1e-3)


def test_matching():
    """
    Unit test for the function s2p.sift.keypoints_match.
    """
    computed = sift.keypoints_match(np.loadtxt(data_path('units/sift1.txt')),
                                    np.loadtxt(data_path('units/sift2.txt')))
    expected = np.loadtxt(data_path('expected_output/units/unit_keypoints_match.txt'))
    np.testing.assert_allclose(computed, expected, rtol=0.01, atol=0.1,
                               verbose=True)


def test_matches_on_rpc_roi():
    """
    Unit test for the function sift.matches_on_rpc_roi.
    """
    img1 = data_path('input_triplet/img_01.tif')
    img2 = data_path('input_triplet/img_02.tif')
    rpc1 = rpcm.rpc_from_geotiff(img1)
    rpc2 = rpcm.rpc_from_geotiff(img2)
    computed = sift.matches_on_rpc_roi(img1, img2, rpc1, rpc2, 100, 100, 200, 200)
    expected = np.loadtxt(data_path('expected_output/units/matches_on_rpc_roi.txt'))
    np.testing.assert_allclose(computed, expected, rtol=0.01, atol=0.1,
                               verbose=True)

{'fraction_non_alphanumeric': 0.12190423775454046, 'fraction_numerical': 0.03632361034672537, 'mean_word_length': 3.2514619883040936, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '613230', 'n_tokens_mistral': 1408, 'n_tokens_neox': 1282, 'n_words': 254}