Passed
Pull Request — main (#81)
by Angeline
01:38
created

TestUtilsAACGMV2.test_subsol_raises_time_range()   A

Complexity

Conditions 2

Size

Total Lines 12
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 12
rs 10
c 0
b 0
f 0
cc 2
nop 2
1
import datetime as dt
2
import numpy as np
3
import pytest
4
5
from aacgmv2 import utils
6
7
8
class TestUtilsAACGMV2(object):
9
    """Unit tests for the utility functions."""
10
11
    def setup_method(self):
12
        """Set up every method to create a clean testing setup."""
13
        self.rtol = 1.0e-4
14
        self.out = None
15
16
    def teardown_method(self):
17
        """Run after every method to clean up previous testing."""
18
        del self.rtol, self.out
19
20
    @pytest.mark.parametrize('year,ref', [(1880, [-179.1494, -23.0801]),
21
                                          (2015, [-179.2004, -23.0431])])
22
    def test_subsol(self, year, ref):
23
        """Test the subsolar calculation.
24
25
        Parameters
26
        ----------
27
        year : int
28
            Input year
29
        ref : list
30
            Expected output
31
32
        """
33
        self.out = utils.subsol(year, 1, 0.0)
34
        np.testing.assert_allclose(self.out, ref, rtol=self.rtol)
35
36
    @pytest.mark.parametrize('year', [(1500), (2110)])
37
    def test_subsol_raises_time_range(self, year):
38
        """Test the routine failure for out-of-range dates.
39
40
        Parameters
41
        ----------
42
        year : int
43
            Input year
44
45
        """
46
        with pytest.raises(ValueError, match="subsol valid between 1601-2100"):
47
            self.out = utils.subsol(year, 1, 0.0)
48
49
    @pytest.mark.parametrize('year,ref',
50
                             [(1500, [0.141408, -0.48357, 0.86381]),
51
                              (2015, [0.050281, -0.16057, 0.98574]),
52
                              (2110, [0.027069, -0.08006, 0.99642])])
53
    def test_igrf_dipole_axis(self, year, ref):
54
        """Test the IGRF dipole axis calculation.
55
56
        Parameters
57
        ----------
58
        year : int
59
            Input year
60
        ref : list
61
            Expected output
62
63
        """
64
        self.out = utils.igrf_dipole_axis(dt.datetime(year, 1, 1))
65
66
        np.testing.assert_allclose(self.out, ref, rtol=self.rtol)
67
68
    @pytest.mark.parametrize('gc_lat,gd_lat,mult',
69
                             [(45.0, 45.1924, False),
70
                              ([45.0, -45.0], [45.1924, -45.1924], True),
71
                              (np.array([45.0, -45.0]),
72
                               np.array([45.1924, -45.1924]), True)])
73
    def test_gc2gd_lat(self, gc_lat, gd_lat, mult):
74
        """Test the geocentric to geodetic conversion.
75
76
        Parameters
77
        ----------
78
        gc_lat : float, list, array
79
            Geocentric latitude
80
        gd_lat : float, list, array
81
            Geodetic latitude
82
        mult : bool
83
            Specify whether or not the input/output is a float
84
85
        """
86
        self.out = utils.gc2gd_lat(gc_lat)
87
88
        if mult:
89
            np.testing.assert_allclose(self.out, gd_lat, rtol=self.rtol)
90
        else:
91
            np.testing.assert_almost_equal(self.out, gd_lat, decimal=4)
92