# Path: atrain_match/utils/pps_prototyping_util.py
# def get_warmest_or_coldest_index(t11, matched, warmest=True):
#     """Get index for coldedest pixel in 5x5 neighbourhood."""
#     FILL = 999999.9  # coldest
#     if warmest:
#         FILL = -99
# 
#     steps = [(i, j) for i in [-2, -1, 0, 1, 2] for j in [-2, -1, 0, 1, 2]]
#     t11_neighbour_i = np.zeros((25, matched['row'].shape[0]))
#     for i, (step_r, step_c) in enumerate(steps):
#         new_row_col = {'row': matched['row'] + step_r,
#                        'col': matched['col'] + step_c}
#         t11_neighbour_i[i, :] = get_data_from_array_fill_outside(t11,
#                                                                  new_row_col,
#                                                                  Fill=FILL)
#     if warmest:
#         neigbour_index = np.argmax(t11_neighbour_i, axis=0)
#     else:  # coldest
#         neigbour_index = np.argmin(t11_neighbour_i, axis=0)
#     new_row_matched = np.array(
#         [matched['row'][idx] + steps[neigbour_index[idx]][0]
#          for idx in range(matched['row'].shape[0])])
#     new_col_matched = np.array(
#         [matched['col'][idx] + steps[neigbour_index[idx]][1]
#          for idx in range(matched['row'].shape[0])])
#     new_row_col = {'row': new_row_matched, 'col': new_col_matched}
#     return new_row_col
# 
# Path: atrain_match/utils/match.py
# class MatchMapper(object):
#     def __init__(self, rows, cols, pixel_mask, time_diff=None,
#                  time_threshold=None):
#     def __call__(self, array):
#     def rows(self):
#     def cols(self):
#     def time_diff(self):
#     def time_diff(self, value):
#     def mask(self):
# def match_lonlat(source, target,
#                  radius_of_influence=0.7*RESOLUTION*1000.0,
#                  n_neighbours=1):


import numpy as np
import unittest
from atrain_match.utils.pps_prototyping_util import (get_warmest_or_coldest_index)
from atrain_match.utils import match
    from scipy.ndimage.filters import generic_filter
        from pyresample.geometry import SwathDefinition
        from pyresample.kd_tree import get_neighbour_info
        lat_t = np.array([89, 10, 15]).astype(np.float64)
        lon3 = np.array([[25, 10, 15], 
                         [10, 10, 15]]).astype(np.float64)
        lat3 = np.array([[10, 11, 16], 
                         [12, 10, 15]]).astype(np.float64)
        self.source = (lon, lat)
        self.source3 = (lon3, lat3)
        self.target = (lon_t, lat_t)
        self.RESOLUTION = 5

    def test_match_integers(self):
        lon = np.array([0, 10, 25])
        source_def  = SwathDefinition(*(lon, lon))
        target_def = SwathDefinition(*(lon, lon))
        valid_in, valid_out, indices_int, distances = get_neighbour_info(source_def, target_def, 1000, neighbours=1)
        lon = np.array([0, 10, 25]).astype(np.float64)
        source_def  = SwathDefinition(*(lon, lon))
        target_def = SwathDefinition(*(lon, lon))
        valid_in, valid_out, indices_float, distances = get_neighbour_info(source_def, target_def, 1000, neighbours=1)


    def test_match(self):
        mapper, _ = match.match_lonlat(self.source3, self.target,
                                       radius_of_influence=0.7 * 5 * 1000.0,
                                       n_neighbours=1)
  
        self.assertEqual(mapper.cols.data[0], -9)
        self.assertEqual(mapper.cols.data[2], 2)

    def test_match_nodata(self):

# Path: atrain_match/utils/pps_prototyping_util.py
# def get_warmest_or_coldest_index(t11, matched, warmest=True):
#     """Get index for coldedest pixel in 5x5 neighbourhood."""
#     FILL = 999999.9  # coldest
#     if warmest:
#         FILL = -99
# 
#     steps = [(i, j) for i in [-2, -1, 0, 1, 2] for j in [-2, -1, 0, 1, 2]]
#     t11_neighbour_i = np.zeros((25, matched['row'].shape[0]))
#     for i, (step_r, step_c) in enumerate(steps):
#         new_row_col = {'row': matched['row'] + step_r,
#                        'col': matched['col'] + step_c}
#         t11_neighbour_i[i, :] = get_data_from_array_fill_outside(t11,
#                                                                  new_row_col,
#                                                                  Fill=FILL)
#     if warmest:
#         neigbour_index = np.argmax(t11_neighbour_i, axis=0)
#     else:  # coldest
#         neigbour_index = np.argmin(t11_neighbour_i, axis=0)
#     new_row_matched = np.array(
#         [matched['row'][idx] + steps[neigbour_index[idx]][0]
#          for idx in range(matched['row'].shape[0])])
#     new_col_matched = np.array(
#         [matched['col'][idx] + steps[neigbour_index[idx]][1]
#          for idx in range(matched['row'].shape[0])])
#     new_row_col = {'row': new_row_matched, 'col': new_col_matched}
#     return new_row_col
# 
# Path: atrain_match/utils/match.py
# class MatchMapper(object):
#     def __init__(self, rows, cols, pixel_mask, time_diff=None,
#                  time_threshold=None):
#     def __call__(self, array):
#     def rows(self):
#     def cols(self):
#     def time_diff(self):
#     def time_diff(self, value):
#     def mask(self):
# def match_lonlat(source, target,
#                  radius_of_influence=0.7*RESOLUTION*1000.0,
#                  n_neighbours=1):


# Path: atrain_match/tests/test_utils.py
import numpy as np
import unittest
from atrain_match.utils.pps_prototyping_util import (get_warmest_or_coldest_index)
from atrain_match.utils import match
    from scipy.ndimage.filters import generic_filter
        from pyresample.geometry import SwathDefinition
        from pyresample.kd_tree import get_neighbour_info

        lat_t = np.array([89, 10, 15]).astype(np.float64)
        lon3 = np.array([[25, 10, 15], 
                         [10, 10, 15]]).astype(np.float64)
        lat3 = np.array([[10, 11, 16], 
                         [12, 10, 15]]).astype(np.float64)
        self.source = (lon, lat)
        self.source3 = (lon3, lat3)
        self.target = (lon_t, lat_t)
        self.RESOLUTION = 5

    def test_match_integers(self):
        lon = np.array([0, 10, 25])
        source_def  = SwathDefinition(*(lon, lon))
        target_def = SwathDefinition(*(lon, lon))
        valid_in, valid_out, indices_int, distances = get_neighbour_info(source_def, target_def, 1000, neighbours=1)
        lon = np.array([0, 10, 25]).astype(np.float64)
        source_def  = SwathDefinition(*(lon, lon))
        target_def = SwathDefinition(*(lon, lon))
        valid_in, valid_out, indices_float, distances = get_neighbour_info(source_def, target_def, 1000, neighbours=1)


    def test_match(self):
        mapper, _ = match.match_lonlat(self.source3, self.target,
                                       radius_of_influence=0.7 * 5 * 1000.0,
                                       n_neighbours=1)
  
        self.assertEqual(mapper.cols.data[0], -9)
        self.assertEqual(mapper.cols.data[2], 2)

    def test_match_nodata(self):

        mapper, _ = match.match_lonlat(self.source, self.target,