|
1
|
|
|
# -*- coding: utf-8 -*- |
|
2
|
|
|
# vim:fileencoding=utf-8 |
|
3
|
|
|
# |
|
4
|
|
|
# Copyright (c) 2020 Stefan Bender |
|
5
|
|
|
# |
|
6
|
|
|
# This module is part of pyspaceweather. |
|
7
|
|
|
# pyspaceweather is free software: you can redistribute it or modify |
|
8
|
|
|
# it under the terms of the GNU General Public License as published |
|
9
|
|
|
# by the Free Software Foundation, version 2. |
|
10
|
|
|
# See accompanying COPYING.GPLv2 file or http://www.gnu.org/licenses/gpl-2.0.html. |
|
11
|
|
|
"""Space weather index read tests |
|
12
|
|
|
""" |
|
13
|
|
|
import numpy as np |
|
14
|
|
|
import pandas as pd |
|
15
|
|
|
|
|
16
|
|
|
from spaceweather import ap_kp_3h, sw_daily |
|
17
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
def test_update(): |
|
20
|
|
|
import os |
|
21
|
|
|
from pkg_resources import resource_filename |
|
22
|
|
|
from spaceweather.core import check_for_update, _get_last_update, SW_FILE |
|
23
|
|
|
swpath = resource_filename("spaceweather", os.path.join("data", SW_FILE)) |
|
24
|
|
|
fdate = _get_last_update(swpath) |
|
25
|
|
|
now = pd.Timestamp.utcnow() |
|
26
|
|
|
assert (now - fdate > pd.Timedelta("1d")) == check_for_update(swpath, max_age="1d") |
|
27
|
|
|
|
|
28
|
|
|
|
|
29
|
|
|
def test_daily(): |
|
30
|
|
|
df = sw_daily() |
|
31
|
|
|
np.testing.assert_allclose( |
|
32
|
|
|
df.loc["2000-01-01"].values, |
|
33
|
|
|
np.array([ |
|
34
|
|
|
2.000e+03, 1.000e+00, 1.000e+00, 2.272e+03, 7.000e+00, 5.300e+00, 4.700e+00, |
|
35
|
|
|
4.000e+00, 3.300e+00, 4.300e+00, 3.000e+00, 4.300e+00, 3.700e+00, 3.270e+01, |
|
36
|
|
|
5.600e+01, 3.900e+01, 2.700e+01, 1.800e+01, 3.200e+01, 1.500e+01, 3.200e+01, |
|
37
|
|
|
2.200e+01, 3.000e+01, 1.300e+00, 6.000e+00, 4.800e+01, 1.256e+02, 0.000e+00, |
|
38
|
|
|
1.605e+02, 1.750e+02, 1.299e+02, 1.656e+02, 1.790e+02, |
|
39
|
|
|
]), |
|
40
|
|
|
rtol=1e-12, |
|
41
|
|
|
) |
|
42
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
def test_3hourly_ap(): |
|
45
|
|
|
df = ap_kp_3h() |
|
46
|
|
|
np.testing.assert_allclose( |
|
47
|
|
|
df.loc[pd.date_range("2000-01-01 01:30", "2000-01-01 23:30", freq='3h')].Ap.values, |
|
48
|
|
|
np.array([56, 39, 27, 18, 32, 15, 32, 22]), |
|
49
|
|
|
rtol=1e-12, |
|
50
|
|
|
) |
|
51
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
def test_3hourly_kp(): |
|
54
|
|
|
df = ap_kp_3h() |
|
55
|
|
|
np.testing.assert_allclose( |
|
56
|
|
|
df.loc[pd.date_range("2000-01-01 01:30", "2000-01-01 23:30", freq='3h')].Kp.values, |
|
57
|
|
|
np.array([5.3, 4.7, 4.0, 3.3, 4.3, 3.0, 4.3, 3.7]), |
|
58
|
|
|
rtol=1e-12, |
|
59
|
|
|
) |
|
60
|
|
|
|