|
1
|
|
|
# -*- coding: utf-8 -*- |
|
2
|
|
|
from __future__ import division, absolute_import, unicode_literals |
|
3
|
|
|
|
|
4
|
|
|
import datetime as dt |
|
5
|
|
|
import numpy as np |
|
6
|
|
|
import pytest |
|
7
|
|
|
|
|
8
|
|
|
from aacgmv2 import utils |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
class TestUtilsAACGMV2: |
|
12
|
|
|
def setup(self): |
|
13
|
|
|
"""Runs before every method to create a clean testing setup""" |
|
14
|
|
|
self.dtime = dt.datetime(2015, 1, 1, 0, 0, 0) |
|
15
|
|
|
self.out = None |
|
16
|
|
|
|
|
17
|
|
|
def teardown(self): |
|
18
|
|
|
"""Runs after every method to clean up previous testing""" |
|
19
|
|
|
del self.dtime, self.out |
|
20
|
|
|
|
|
21
|
|
|
def test_subsol(self): |
|
22
|
|
|
"""Test the subsolar calculation""" |
|
23
|
|
|
self.out = utils.subsol(self.dtime.year, int(self.dtime.strftime("%j")), |
|
24
|
|
|
self.dtime.hour * 3600.0 |
|
25
|
|
|
+ self.dtime.minute * 60.0 + self.dtime.second) |
|
26
|
|
|
|
|
27
|
|
|
np.testing.assert_allclose(self.out, [-179.2004, -23.0431], rtol=1.0e-4) |
|
28
|
|
|
|
|
29
|
|
|
def test_igrf_dipole_axis(self): |
|
30
|
|
|
"""Test the IGRF dipole axis calculation""" |
|
31
|
|
|
self.out = utils.igrf_dipole_axis(self.dtime) |
|
32
|
|
|
|
|
33
|
|
|
np.testing.assert_allclose(self.out, [0.050281, -0.16057, 0.98574], |
|
34
|
|
|
rtol=1.0e-4) |
|
35
|
|
|
|
|
36
|
|
|
@pytest.mark.parametrize('gc_lat,gd_lat,mult', |
|
37
|
|
|
[(45.0, 45.1924, False), |
|
38
|
|
|
([45.0, -45.0], [45.1924, -45.1924], True), |
|
39
|
|
|
(np.array([45.0, -45.0]), |
|
40
|
|
|
np.array([45.1924, -45.1924]), True)]) |
|
41
|
|
|
def test_gc2gd_lat(self, gc_lat, gd_lat, mult): |
|
42
|
|
|
"""Test the geocentric to geodetic conversion""" |
|
43
|
|
|
self.out = utils.gc2gd_lat(gc_lat) |
|
44
|
|
|
|
|
45
|
|
|
if mult: |
|
46
|
|
|
np.testing.assert_allclose(self.out, gd_lat, rtol=1.0e-4) |
|
47
|
|
|
else: |
|
48
|
|
|
np.testing.assert_almost_equal(self.out, gd_lat, decimal=4) |
|
49
|
|
|
|