|
5 | 5 | import os.path |
6 | 6 | import numpy as np |
7 | 7 | from coral.corner_reflector import * |
8 | | -from coral.dataio import readpar, readmli |
| 8 | +from coral.dataio import readpar, readmli, read_radar_coords, write_radar_coords |
9 | 9 |
|
10 | 10 | class TestCoral(unittest.TestCase): |
11 | 11 | @classmethod |
@@ -157,6 +157,59 @@ def test_loop(self): |
157 | 157 |
|
158 | 158 | # test the mean value of the average intensity image |
159 | 159 | self.assertEqual(round(np.mean(avgI), 6), -11.385613) # -11.385613198856245 |
| 160 | + |
| 161 | + |
| 162 | +class TestShift(unittest.TestCase): |
| 163 | + @classmethod |
| 164 | + def setUpClass(cls): |
| 165 | + cls.files = [] |
| 166 | + for file in glob.glob("data/*.mli"): |
| 167 | + cls.files.append(file) |
| 168 | + |
| 169 | + cls.files.sort() |
| 170 | + cls.sub_im = 51 |
| 171 | + cls.targ_win_sz = 5 |
| 172 | + cls.clt_win_sz = 9 |
| 173 | + cls.cr = [ 86, 111] # coordinates changed to check shift |
| 174 | + |
| 175 | + def test_loop(self): |
| 176 | + '''test the coordinate shift''' |
| 177 | + avgI, rcs, scr, Avg_clt, t, cr_new, cr_pos = loop(self.files, self.sub_im, self.cr, self.targ_win_sz, self.clt_win_sz) |
| 178 | + |
| 179 | + # test array containing values of shift to be applied to radar coordinates |
| 180 | + self.assertEqual(cr_pos[0], 52) |
| 181 | + self.assertEqual(cr_pos[1], 50) |
| 182 | + |
| 183 | + |
| 184 | +class TestCRfiles(unittest.TestCase): |
| 185 | + @classmethod |
| 186 | + def setUpClass(cls): |
| 187 | + cls.file_in1 = "data/site_az_rg.txt" |
| 188 | + cls.file_in2 = "data/site_lat_lon_hgt_date1_date2_az_rg.txt" |
| 189 | + cls.file_out1 = "data/site_az_rg_new.txt" |
| 190 | + cls.file_out2 = "data/site_lat_lon_hgt_date1_date2_az_rg_new.txt" |
| 191 | + cls.sites = {'SERF' : np.array([[-999, -999],[ 87, 110]])} |
| 192 | + cls.geom = "desc" |
| 193 | + |
| 194 | + def test_cr_file(self): |
| 195 | + '''test the calculation loop function''' |
| 196 | + # open reduced CR coordinate file |
| 197 | + site, az, rg = read_radar_coords(self.file_in1) |
| 198 | + self.assertEqual(int(rg[0]), 87) |
| 199 | + self.assertEqual(int(az[0]), 110) |
| 200 | + # write to new file |
| 201 | + write_radar_coords(self.file_in1, self.file_out1, self.sites, self.geom) |
| 202 | + assert os.path.exists(self.file_out1) == 1 |
| 203 | + os.remove(self.file_out1) |
| 204 | + |
| 205 | + # open full CR coordinate file |
| 206 | + site, az, rg = read_radar_coords(self.file_in2) |
| 207 | + self.assertEqual(int(rg[0]), 87) |
| 208 | + self.assertEqual(int(az[0]), 110) |
| 209 | + # write to new file |
| 210 | + write_radar_coords(self.file_in2, self.file_out2, self.sites, self.geom) |
| 211 | + assert os.path.exists(self.file_out2) == 1 |
| 212 | + os.remove(self.file_out2) |
160 | 213 |
|
161 | 214 |
|
162 | 215 | if __name__ == '__main__': |
|
0 commit comments