| 1 |
"""Tests for SatelliteInterpolator.""" |
| 2 |
|
| 3 |
import unittest |
| 4 |
import numpy as np |
| 5 |
|
| 6 |
from geotiepoints import SatelliteInterpolator |
| 7 |
|
| 8 |
TIES_EXP1 = np.array([[6384905.78040055, 6381081.08333225, 6371519.34066148, |
| 9 |
6328950.00792935, 6253610.69157758, 6145946.19489936, |
| 10 |
6124413.29556372], |
| 11 |
[6377591.95940176, 6370997., 6354509.6014956, |
| 12 |
6305151.62592155, 6223234.99818839, 6109277.14889072, |
| 13 |
6086485.57903118], |
| 14 |
[6359307.40690478, 6345786.79166939, 6311985.2535809, |
| 15 |
6245655.67090206, 6147295.76471541, 6017604.5338691, |
| 16 |
5991666.28769983], |
| 17 |
[6351993.58590599, 6335702.70833714, 6294975.51441502, |
| 18 |
6221857.28889426, 6116920.07132621, 5980935.48786045, |
| 19 |
5953738.5711673], |
| 20 |
[6338032.26190294, 6320348.4990906, 6276139.09205974, |
| 21 |
6199670.56624433, 6091551.90273768, 5952590.38414781, |
| 22 |
5924798.08042984], |
| 23 |
[6290665.5946295, 6270385.16249031, 6219684.08214232, |
| 24 |
6137100.75832981, 6023313.2794414, 5879194.72399075, |
| 25 |
5850371.01290062], |
| 26 |
[6172248.92644589, 6145476.82098957, 6078546.55734877, |
| 27 |
5980676.23854351, 5852716.72120069, 5695705.57359808, |
| 28 |
5664303.34407756], |
| 29 |
[6124882.25917245, 6095513.48438928, 6022091.54743135, |
| 30 |
5918106.430629, 5784478.09790441, 5622309.91344102, |
| 31 |
5589876.27654834]]) |
| 32 |
|
| 33 |
TIES_EXP2 = np.array([[6372937.31273379, 6370997., 6366146.21816553, |
| 34 |
6351605.98629588, 6327412.61244969, 6293626.50067273, |
| 35 |
6286869.27831734], |
| 36 |
[6353136.46335726, 6345786.79166939, 6327412.61244969, |
| 37 |
6299445.69529922, 6261968.60390423, 6215087.60607344, |
| 38 |
6205711.40650728]]) |
| 39 |
|
| 40 |
TIES_EXP3 = np.array([[6372937.31273379, 6370997., 6366146.21816553, |
| 41 |
6351605.98629588, 6327412.61244969, 6293626.50067273, |
| 42 |
6286869.27831734], |
| 43 |
[6353136.46335726, 6345786.79166939, 6327412.61244969, |
| 44 |
6299445.69529922, 6261968.60390423, 6215087.60607344, |
| 45 |
6205711.40650728]]) |
| 46 |
|
| 47 |
TIES_EXP4 = np.array([[6381081.08333225, 6381639.66045187, 6372470.10269454, |
| 48 |
6353590.21586788, 6325042.05851245], |
| 49 |
[6370997., 6366146.21816553, 6351605.98629588, |
| 50 |
6327412.61244969, 6293626.50067273], |
| 51 |
[6345786.79166939, 6327412.61244969, 6299445.69529922, |
| 52 |
6261968.60390423, 6215087.60607344], |
| 53 |
[6335702.70833714, 6311919.17016336, 6278581.57890056, |
| 54 |
6235791.00048604, 6183672.04823372]]) |
| 55 |
|
| 56 |
TIES_EXP5 = np.array([[6381081.08333225, 6371519.34066148, 6328950.00792935, |
| 57 |
6253610.69157758, 6145946.19489936], |
| 58 |
[6370997., 6354509.6014956, 6305151.62592155, |
| 59 |
6223234.99818839, 6109277.14889072], |
| 60 |
[6345786.79166939, 6311985.2535809, 6245655.67090206, |
| 61 |
6147295.76471541, 6017604.5338691], |
| 62 |
[6270385.16249031, 6219684.08214232, 6137100.75832981, |
| 63 |
6023313.2794414, 5879194.72399075], |
| 64 |
[6145476.82098957, 6078546.55734877, 5980676.23854351, |
| 65 |
5852716.72120069, 5695705.57359808], |
| 66 |
[6095513.48438928, 6022091.54743135, 5918106.430629, |
| 67 |
5784478.09790441, 5622309.91344102]]) |
| 68 |
|
| 69 |
TIES_EXP6 = np.array([[6381081.08333225, 6371519.34066148, 6328950.00792935, |
| 70 |
6253610.69157758, 6145946.19489936], |
| 71 |
[6370997., 6354509.6014956, 6305151.62592155, |
| 72 |
6223234.99818839, 6109277.14889072], |
| 73 |
[6345786.79166939, 6311985.2535809, 6245655.67090206, |
| 74 |
6147295.76471541, 6017604.5338691], |
| 75 |
[6335702.70833714, 6294975.51441502, 6221857.28889426, |
| 76 |
6116920.07132621, 5980935.48786045], |
| 77 |
[6320348.4990906, 6276139.09205974, 6199670.56624433, |
| 78 |
6091551.90273768, 5952590.38414781], |
| 79 |
[6270385.16249031, 6219684.08214232, 6137100.75832981, |
| 80 |
6023313.2794414, 5879194.72399075], |
| 81 |
[6145476.82098957, 6078546.55734877, 5980676.23854351, |
| 82 |
5852716.72120069, 5695705.57359808], |
| 83 |
[6095513.48438928, 6022091.54743135, 5918106.430629, |
| 84 |
5784478.09790441, 5622309.91344102]]) |
| 85 |
|
| 86 |
|
| 87 |
class TestSatelliteInterpolator(unittest.TestCase): |
| 88 |
|
| 89 |
"""Class for unit testing the ancillary interpolation functions |
| 90 |
""" |
| 91 |
|
| 92 |
def setUp(self): |
| 93 |
pass |
| 94 |
|
| 95 |
# def test_fillborders(self): |
| 96 |
# lons = np.arange(20).reshape((4, 5), order="F") |
| 97 |
# lats = np.arange(20).reshape((4, 5), order="C") |
| 98 |
# lines = np.array([2, 7, 12, 17]) |
| 99 |
# cols = np.array([2, 7, 12, 17, 22]) |
| 100 |
# hlines = np.arange(20) |
| 101 |
# hcols = np.arange(24) |
| 102 |
# satint = SatelliteInterpolator( |
| 103 |
# (lons, lats), (lines, cols), (hlines, hcols), chunk_size=10) |
| 104 |
# satint.fill_borders('x', 'y') |
| 105 |
# self.assertTrue(np.allclose(satint.tie_data[0], TIES_EXP1)) |
| 106 |
# self.assertTrue( |
| 107 |
# np.allclose(satint.row_indices, np.array([0, 2, 7, 9, 10, 12, 17, 19]))) |
| 108 |
# self.assertTrue( |
| 109 |
# np.allclose(satint.col_indices, np.array([0, 2, 7, 12, 17, 22, 23]))) |
| 110 |
|
| 111 |
def test_extrapolate_cols(self): |
| 112 |
lons = np.arange(10).reshape((2, 5), order="F") |
| 113 |
lats = np.arange(10).reshape((2, 5), order="C") |
| 114 |
lines = np.array([2, 7]) |
| 115 |
cols = np.array([2, 7, 12, 17, 22]) |
| 116 |
hlines = np.arange(10) |
| 117 |
hcols = np.arange(24) |
| 118 |
satint = SatelliteInterpolator( |
| 119 |
(lons, lats), (lines, cols), (hlines, hcols)) |
| 120 |
|
| 121 |
self.assertTrue(np.allclose(satint._extrapolate_cols(satint.tie_data[0]), |
| 122 |
TIES_EXP2)) |
| 123 |
|
| 124 |
def test_fill_col_borders(self): |
| 125 |
lons = np.arange(10).reshape((2, 5), order="F") |
| 126 |
lats = np.arange(10).reshape((2, 5), order="C") |
| 127 |
lines = np.array([2, 7]) |
| 128 |
cols = np.array([2, 7, 12, 17, 22]) |
| 129 |
hlines = np.arange(10) |
| 130 |
hcols = np.arange(24) |
| 131 |
satint = SatelliteInterpolator( |
| 132 |
(lons, lats), (lines, cols), (hlines, hcols)) |
| 133 |
satint._fill_col_borders() |
| 134 |
self.assertTrue(np.allclose(satint.tie_data[0], TIES_EXP3)) |
| 135 |
self.assertTrue(np.allclose(satint.col_indices, |
| 136 |
np.array([0, 2, 7, 12, 17, 22, 23]))) |
| 137 |
|
| 138 |
# def test_extrapolate_rows(self): |
| 139 |
# lons = np.arange(10).reshape((2, 5), order="F") |
| 140 |
# lats = np.arange(10).reshape((2, 5), order="C") |
| 141 |
# lines = np.array([2, 7]) |
| 142 |
# cols = np.array([2, 7, 12, 17, 22]) |
| 143 |
# hlines = np.arange(10) |
| 144 |
# hcols = np.arange(24) |
| 145 |
# satint = SatelliteInterpolator( |
| 146 |
# (lons, lats), (lines, cols), (hlines, hcols)) |
| 147 |
# self.assertTrue(np.allclose(satint._extrapolate_rows(satint.tie_data[0]), |
| 148 |
# TIES_EXP4) |
| 149 |
|
| 150 |
# def test_fill_row_borders(self): |
| 151 |
# lons = np.arange(20).reshape((4, 5), order="F") |
| 152 |
# lats = np.arange(20).reshape((4, 5), order="C") |
| 153 |
# lines = np.array([2, 7, 12, 17]) |
| 154 |
# cols = np.array([2, 7, 12, 17, 22]) |
| 155 |
# hlines = np.arange(20) |
| 156 |
# hcols = np.arange(24) |
| 157 |
# satint = SatelliteInterpolator( |
| 158 |
# (lons, lats), (lines, cols), (hlines, hcols)) |
| 159 |
# satint._fill_row_borders() |
| 160 |
# self.assertTrue(np.allclose(satint.tie_data[0], TIES_EXP5)) |
| 161 |
# self.assertTrue(np.allclose(satint.row_indices, |
| 162 |
# np.array([0, 2, 7, 12, 17, 19]))) |
| 163 |
# satint = SatelliteInterpolator((lons, lats), (lines, cols), |
| 164 |
# (hlines, hcols), chunk_size=10) |
| 165 |
# satint._fill_row_borders() |
| 166 |
# self.assertTrue(np.allclose(satint.tie_data[0], TIES_EXP6)) |
| 167 |
# self.assertTrue(np.allclose(satint.row_indices, |
| 168 |
# np.array([0, 2, 7, 9, 10, 12, 17, 19]))) |