Code Duplication    Length = 19-25 lines in 5 locations

aacgmv2/tests/test_py_aacgmv2.py 5 locations

@@ 231-255 (lines=25) @@
228
        np.testing.assert_allclose(self.lon_out, [81.16846959], rtol=1e-4)
229
        np.testing.assert_allclose(self.r_out, [1.04566346], rtol=1e-4)
230
231
    def test_convert_latlon_arr_arr(self):
232
        """Test array latlon conversion for array input"""
233
        (self.lat_out, self.lon_out,
234
         self.r_out) = aacgmv2.convert_latlon_arr(np.array([60, 61]),
235
                                                  np.array([0, 0]),
236
                                                  np.array([300, 300]),
237
                                                  self.dtime)
238
239
        if not isinstance(self.lat_out, np.ndarray):
240
            raise AssertionError()
241
        if not isinstance(self.lon_out, np.ndarray):
242
            raise AssertionError()
243
        if not isinstance(self.r_out, np.ndarray):
244
            raise AssertionError()
245
        if not (self.r_out.shape == self.lon_out.shape and
246
                self.lat_out.shape == self.r_out.shape and
247
                self.r_out.shape == (2,)):
248
            raise AssertionError()
249
250
        np.testing.assert_allclose(self.lat_out, [58.22577090, 59.31860933],
251
                                   rtol=1e-4)
252
        np.testing.assert_allclose(self.lon_out, [81.16846959, 81.61398933],
253
                                   rtol=1e-4)
254
        np.testing.assert_allclose(self.r_out, [1.04566346, 1.04561304],
255
                                   rtol=1e-4)
256
257
    def test_convert_latlon_arr_list_mix(self):
258
        """Test array latlon conversion for mixed types with list"""
@@ 280-302 (lines=23) @@
277
        np.testing.assert_allclose(self.r_out, [1.04566346, 1.04561304],
278
                                   rtol=1e-4)
279
280
    def test_convert_latlon_arr_arr_mix(self):
281
        """Test array latlon conversion for mixed type with an array"""
282
        (self.lat_out, self.lon_out,
283
        self.r_out) = aacgmv2.convert_latlon_arr(np.array([60, 61]), 0,
284
                                                 300, self.dtime)
285
286
        if not isinstance(self.lat_out, np.ndarray):
287
            raise AssertionError()
288
        if not isinstance(self.lon_out, np.ndarray):
289
            raise AssertionError()
290
        if not isinstance(self.r_out, np.ndarray):
291
            raise AssertionError()
292
        if not (self.r_out.shape == self.lon_out.shape and
293
                self.lat_out.shape == self.r_out.shape and
294
                self.r_out.shape == (2,)):
295
            raise AssertionError()
296
297
        np.testing.assert_allclose(self.lat_out, [58.22577090, 59.31860933],
298
                                   rtol=1e-4)
299
        np.testing.assert_allclose(self.lon_out, [81.16846959, 81.61398933],
300
                                   rtol=1e-4)
301
        np.testing.assert_allclose(self.r_out, [1.04566346, 1.04561304],
302
                                   rtol=1e-4)
303
304
    def test_convert_latlon_arr_mult_arr_mix(self):
305
        """Test array latlon conversion for mix type with multi-dim array"""
@@ 186-208 (lines=23) @@
183
        np.testing.assert_allclose(self.lon_out, [81.16846959], rtol=1e-4)
184
        np.testing.assert_allclose(self.r_out, [1.04566346], rtol=1e-4)
185
186
    def test_convert_latlon_arr_list(self):
187
        """Test array latlon conversion for list input"""
188
        (self.lat_out, self.lon_out,
189
         self.r_out) = aacgmv2.convert_latlon_arr([60, 61], [0, 0], [300, 300],
190
                                                  self.dtime)
191
192
        if not isinstance(self.lat_out, np.ndarray):
193
            raise AssertionError()
194
        if not isinstance(self.lon_out, np.ndarray):
195
            raise AssertionError()
196
        if not isinstance(self.r_out, np.ndarray):
197
            raise AssertionError()
198
        if not (self.r_out.shape == self.lon_out.shape and
199
                self.lat_out.shape == self.r_out.shape and
200
                self.r_out.shape == (2,)):
201
            raise AssertionError()
202
203
        np.testing.assert_allclose(self.lat_out, [58.22577090, 59.31860933],
204
                                   rtol=1e-4)
205
        np.testing.assert_allclose(self.lon_out, [81.16846959, 81.61398933],
206
                                   rtol=1e-4)
207
        np.testing.assert_allclose(self.r_out, [1.04566346, 1.04561304],
208
                                   rtol=1e-4)
209
210
    def test_convert_latlon_arr_arr_single(self):
211
        """Test array latlon conversion for array input of shape (1,)"""
@@ 210-229 (lines=20) @@
207
        np.testing.assert_allclose(self.r_out, [1.04566346, 1.04561304],
208
                                   rtol=1e-4)
209
210
    def test_convert_latlon_arr_arr_single(self):
211
        """Test array latlon conversion for array input of shape (1,)"""
212
        (self.lat_out, self.lon_out,
213
        self.r_out) = aacgmv2.convert_latlon_arr(np.array([60]), np.array([0]),
214
                                                 np.array([300]), self.dtime)
215
216
        if not isinstance(self.lat_out, np.ndarray):
217
            raise AssertionError()
218
        if not isinstance(self.lon_out, np.ndarray):
219
            raise AssertionError()
220
        if not isinstance(self.r_out, np.ndarray):
221
            raise AssertionError()
222
        if not (self.r_out.shape == self.lon_out.shape and
223
                self.lat_out.shape == self.r_out.shape and
224
                self.r_out.shape == (1,)):
225
            raise AssertionError()
226
227
        np.testing.assert_allclose(self.lat_out, [58.2257709], rtol=1e-4)
228
        np.testing.assert_allclose(self.lon_out, [81.16846959], rtol=1e-4)
229
        np.testing.assert_allclose(self.r_out, [1.04566346], rtol=1e-4)
230
231
    def test_convert_latlon_arr_arr(self):
232
        """Test array latlon conversion for array input"""
@@ 166-184 (lines=19) @@
163
        np.testing.assert_allclose(self.lon_out, [81.16846959], rtol=1e-4)
164
        np.testing.assert_allclose(self.r_out, [1.04566346], rtol=1e-4)
165
166
    def test_convert_latlon_arr_list_single(self):
167
        """Test array latlon conversion for list input of single values"""
168
        (self.lat_out, self.lon_out,
169
         self.r_out) = aacgmv2.convert_latlon_arr([60], [0], [300], self.dtime)
170
171
        if not isinstance(self.lat_out, np.ndarray):
172
            raise AssertionError()
173
        if not isinstance(self.lon_out, np.ndarray):
174
            raise AssertionError()
175
        if not isinstance(self.r_out, np.ndarray):
176
            raise AssertionError()
177
        if not (self.r_out.shape == self.lon_out.shape and
178
                self.lat_out.shape == self.r_out.shape and
179
                self.r_out.shape == (1,)):
180
            raise AssertionError()
181
182
        np.testing.assert_allclose(self.lat_out, [58.2257709], rtol=1e-4)
183
        np.testing.assert_allclose(self.lon_out, [81.16846959], rtol=1e-4)
184
        np.testing.assert_allclose(self.r_out, [1.04566346], rtol=1e-4)
185
186
    def test_convert_latlon_arr_list(self):
187
        """Test array latlon conversion for list input"""