# 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
                                size=5,
                                mode='constant',
                                cval=-9999999999999)
    flat_index = np.array(flat_index, dtype=np.int)
    delta_row, delta_col = np.unravel_index(flat_index, (5, 5))
    delta_row = delta_row - 2
    delta_col = delta_col - 2
    new_row = row + delta_row
    new_col = col + delta_col
    new_row_matched = np.array([new_row[matched['row'][idx], matched['col'][idx]]
                                for idx in range(matched['row'].shape[0])])
    new_col_matched = np.array([new_col[matched['row'][idx], matched['col'][idx]]
                                for idx in range(matched['row'].shape[0])])
    return new_row_matched, new_col_matched


class test_prototyping_utils(unittest.TestCase):

    def setUp(self):

        self.t11 = np.array([[1, 43, 3, 4, 5, 6, 7, 8, 9, 35],
                             [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
                             [1, 2, 3, 4, 25, 6, 7, 8, 9, 10],
                             [1, 2, 3, 4, 5, 6, 7, 8, 9, 101],
                             [11, 2, 3, 4, 5, 6, 7, 8, 9, 101]])

        self.matched = {'row': np.array([0, 0, 1, 1, 2, 2, 3, 3, 4, 4]),
                        'col': np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])}

    def test_warmest(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

                                size=5,
                                mode='constant',
                                cval=-9999999999999)
    flat_index = np.array(flat_index, dtype=np.int)
    delta_row, delta_col = np.unravel_index(flat_index, (5, 5))
    delta_row = delta_row - 2
    delta_col = delta_col - 2
    new_row = row + delta_row
    new_col = col + delta_col
    new_row_matched = np.array([new_row[matched['row'][idx], matched['col'][idx]]
                                for idx in range(matched['row'].shape[0])])
    new_col_matched = np.array([new_col[matched['row'][idx], matched['col'][idx]]
                                for idx in range(matched['row'].shape[0])])
    return new_row_matched, new_col_matched


class test_prototyping_utils(unittest.TestCase):

    def setUp(self):

        self.t11 = np.array([[1, 43, 3, 4, 5, 6, 7, 8, 9, 35],
                             [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
                             [1, 2, 3, 4, 25, 6, 7, 8, 9, 10],
                             [1, 2, 3, 4, 5, 6, 7, 8, 9, 101],
                             [11, 2, 3, 4, 5, 6, 7, 8, 9, 101]])

        self.matched = {'row': np.array([0, 0, 1, 1, 2, 2, 3, 3, 4, 4]),
                        'col': np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])}

    def test_warmest(self):

        retv = get_warmest_or_coldest_index(self.t11, self.matched)