1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
from __future__ import division, absolute_import, unicode_literals |
3
|
|
|
|
4
|
|
|
import datetime as dt |
5
|
|
|
from io import StringIO |
6
|
|
|
import logging |
7
|
|
|
import numpy as np |
8
|
|
|
import pytest |
9
|
|
|
from sys import version_info |
10
|
|
|
import warnings |
11
|
|
|
|
12
|
|
|
import aacgmv2 |
13
|
|
|
|
14
|
|
View Code Duplication |
class TestFutureDepWarning: |
|
|
|
|
15
|
|
|
def setup(self): |
16
|
|
|
# Initialize the routine to be tested |
17
|
|
|
self.test_routine = None |
18
|
|
|
self.test_args = [] |
19
|
|
|
self.test_kwargs = {} |
20
|
|
|
|
21
|
|
|
def teardown(self): |
22
|
|
|
del self.test_routine, self.test_args, self.test_kwargs |
23
|
|
|
|
24
|
|
|
def test_future_dep_warning(self): |
25
|
|
|
"""Test the implementation of FutureWarning for deprecated routines""" |
26
|
|
|
if self.test_routine is None: |
27
|
|
|
assert True |
28
|
|
|
else: |
29
|
|
|
with warnings.catch_warnings(record=True) as wout: |
30
|
|
|
# Cause all warnings to always be triggered. |
31
|
|
|
warnings.simplefilter("always") |
32
|
|
|
|
33
|
|
|
# Trigger a warning. |
34
|
|
|
self.test_routine(*self.test_args, **self.test_kwargs) |
35
|
|
|
|
36
|
|
|
# Verify some things |
37
|
|
|
assert len(wout) == 1 |
38
|
|
|
assert issubclass(wout[-1].category, FutureWarning) |
39
|
|
|
assert "Deprecated routine" in str(wout[-1].message) |
40
|
|
|
|
41
|
|
|
|
42
|
|
|
class TestDepAACGMV2Warning(TestFutureDepWarning): |
43
|
|
|
def setup(self): |
44
|
|
|
self.dtime = dt.datetime(2015, 1, 1, 0, 0, 0) |
45
|
|
|
self.test_routine = None |
46
|
|
|
self.test_args = [] |
47
|
|
|
self.test_kwargs = {} |
48
|
|
|
|
49
|
|
|
def teardown(self): |
50
|
|
|
del self.dtime, self.test_routine, self.test_args, self.test_kwargs |
51
|
|
|
|
52
|
|
|
def test_gc2gd_lat_warning(self): |
53
|
|
|
"""Test future deprecation warning for gc2gd_lat""" |
54
|
|
|
|
55
|
|
|
self.test_routine = aacgmv2.deprecated.gc2gd_lat |
56
|
|
|
self.test_args = [60.0] |
57
|
|
|
self.test_future_dep_warning() |
58
|
|
|
|
59
|
|
|
def test_igrf_dipole_axis_warning(self): |
60
|
|
|
"""Test future deprecation warning for igrf_dipole_axis""" |
61
|
|
|
|
62
|
|
|
self.test_routine = aacgmv2.deprecated.igrf_dipole_axis |
63
|
|
|
self.test_args = [self.dtime] |
64
|
|
|
self.test_future_dep_warning() |
65
|
|
|
|
66
|
|
|
class TestDepAACGMV2: |
67
|
|
|
def setup(self): |
68
|
|
|
"""Runs before every method to create a clean testing setup""" |
69
|
|
|
self.dtime = dt.datetime(2015, 1, 1, 0, 0, 0) |
70
|
|
|
self.lat = None |
71
|
|
|
self.lon = None |
72
|
|
|
|
73
|
|
|
def teardown(self): |
74
|
|
|
"""Runs after every method to clean up previous testing""" |
75
|
|
|
del self.dtime, self.lat, self.lon |
76
|
|
|
|
77
|
|
|
def test_subsol(self): |
78
|
|
|
"""Test the subsolar calculation""" |
79
|
|
|
doy = int(self.dtime.strftime("%j")) |
80
|
|
|
ut = self.dtime.hour * 3600.0 + self.dtime.minute * 60.0 + \ |
81
|
|
|
self.dtime.second |
82
|
|
|
with warnings.catch_warnings(): |
83
|
|
|
warnings.simplefilter("ignore") |
84
|
|
|
self.lon, self.lat = aacgmv2.deprecated.subsol(self.dtime.year, |
85
|
|
|
doy, ut) |
86
|
|
|
|
87
|
|
|
np.testing.assert_almost_equal(self.lon, -179.2004, decimal=4) |
88
|
|
|
np.testing.assert_almost_equal(self.lat, -23.0431, decimal=4) |
89
|
|
|
|
90
|
|
|
def test_gc2gd_lat(self): |
91
|
|
|
"""Test the geocentric to geodetic conversion""" |
92
|
|
|
with warnings.catch_warnings(): |
93
|
|
|
warnings.simplefilter("ignore") |
94
|
|
|
self.lat = aacgmv2.deprecated.gc2gd_lat(45.0) |
95
|
|
|
|
96
|
|
|
np.testing.assert_almost_equal(self.lat, 45.1924, decimal=4) |
97
|
|
|
|
98
|
|
|
def test_gc2gd_lat_list(self): |
99
|
|
|
"""Test the geocentric to geodetic conversion""" |
100
|
|
|
self.lat = [45.0, -45.0] |
101
|
|
|
with warnings.catch_warnings(): |
102
|
|
|
warnings.simplefilter("ignore") |
103
|
|
|
self.lat = aacgmv2.deprecated.gc2gd_lat(self.lat) |
104
|
|
|
|
105
|
|
|
np.testing.assert_allclose(self.lat, [45.1924, -45.1924], rtol=1.0e-4) |
106
|
|
|
|
107
|
|
|
def test_gc2gd_lat_arr(self): |
108
|
|
|
"""Test the geocentric to geodetic conversion""" |
109
|
|
|
self.lat = np.array([45.0, -45.0]) |
110
|
|
|
with warnings.catch_warnings(): |
111
|
|
|
warnings.simplefilter("ignore") |
112
|
|
|
self.lat = aacgmv2.deprecated.gc2gd_lat(self.lat) |
113
|
|
|
|
114
|
|
|
np.testing.assert_allclose(self.lat, [45.1924, -45.1924], rtol=1.0e-4) |
115
|
|
|
|
116
|
|
|
def test_igrf_dipole_axis(self): |
117
|
|
|
"""Test the IGRF dipole axis calculation""" |
118
|
|
|
with warnings.catch_warnings(): |
119
|
|
|
warnings.simplefilter("ignore") |
120
|
|
|
m = aacgmv2.deprecated.igrf_dipole_axis(self.dtime) |
121
|
|
|
|
122
|
|
|
np.testing.assert_allclose(m, [0.050281,-0.16057,0.98574], rtol=1.0e-4) |
123
|
|
|
|