|
1
|
|
|
# -*- coding: utf-8 -*- |
|
2
|
|
|
# vim:fileencoding=utf-8 |
|
3
|
|
|
# |
|
4
|
|
|
# Copyright (c) 2018 Stefan Bender |
|
5
|
|
|
# |
|
6
|
|
|
# This module is part of sciapy. |
|
7
|
|
|
# sciapy 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 LICENSE file or http://www.gnu.org/licenses/gpl-2.0.html. |
|
11
|
|
|
"""SCIAMACHY regression module data loading tests |
|
12
|
|
|
""" |
|
13
|
|
|
from datetime import datetime |
|
14
|
|
|
from pkg_resources import resource_filename |
|
15
|
|
|
|
|
16
|
|
|
import numpy as np |
|
17
|
|
|
from pytest import mark, raises |
|
18
|
|
|
|
|
19
|
|
|
import sciapy.regress |
|
20
|
|
|
|
|
21
|
|
|
DZM_FILE = resource_filename(__name__, "sciaNO_20100203_v6.2.1_geogra30.nc") |
|
22
|
|
|
|
|
23
|
|
|
AEdata = [ |
|
24
|
|
|
(datetime(2000, 1, 1), "jyear", 1999.9986311, 507.208333), |
|
25
|
|
|
(datetime(2000, 1, 1), "jd", 2451544.5, 507.208333), |
|
26
|
|
|
(datetime(2000, 1, 1), "mjd", 51544.0, 507.208333), |
|
27
|
|
|
(datetime(2007, 7, 1), "jyear", 2007.4948665, 83.208333), |
|
28
|
|
|
(datetime(2007, 7, 1), "jd", 2454282.5, 83.208333), |
|
29
|
|
|
(datetime(2007, 7, 1), "mjd", 54282.0, 83.208333), |
|
30
|
|
|
] |
|
31
|
|
|
Lyadata = [ |
|
32
|
|
|
(datetime(2000, 1, 1), "jyear", 1999.9986311, 4.59), |
|
33
|
|
|
(datetime(2000, 1, 1), "jd", 2451544.5, 4.59), |
|
34
|
|
|
(datetime(2000, 1, 1), "mjd", 51544.0, 4.59), |
|
35
|
|
|
(datetime(2007, 7, 1), "jyear", 2007.4948665, 3.71), |
|
36
|
|
|
(datetime(2007, 7, 1), "jd", 2454282.5, 3.71), |
|
37
|
|
|
(datetime(2007, 7, 1), "mjd", 54282.0, 3.71), |
|
38
|
|
|
] |
|
39
|
|
|
|
|
40
|
|
|
|
|
41
|
|
|
def test_load_proxyAEfiles(): |
|
42
|
|
|
import pandas as pd |
|
43
|
|
|
AEfile = resource_filename("sciapy", |
|
44
|
|
|
"data/indices/AE_Kyoto_1980-2016_daily2_shift12h.dat") |
|
45
|
|
|
pAEt, pAEv = sciapy.regress.load_solar_gm_table(AEfile, |
|
46
|
|
|
cols=[0, 1], names=["time", "AE"], tfmt="jyear") |
|
47
|
|
|
pAEt2, pAEv2 = sciapy.regress.load_data.load_dailymeanAE() |
|
48
|
|
|
np.testing.assert_allclose(pAEt, pAEt2) |
|
49
|
|
|
pd.testing.assert_frame_equal(pAEv, pAEv2) |
|
50
|
|
|
|
|
51
|
|
|
|
|
52
|
|
|
def test_load_proxyLyafiles(): |
|
53
|
|
|
import pandas as pd |
|
54
|
|
|
Lyafile = resource_filename("sciapy", |
|
55
|
|
|
"data/indices/lisird_lya3_1980-2017.dat") |
|
56
|
|
|
pLyat, pLyav = sciapy.regress.load_solar_gm_table(Lyafile, |
|
57
|
|
|
cols=[0, 1], names=["time", "Lya"], tfmt="jyear") |
|
58
|
|
|
pLyat2, pLyav2 = sciapy.regress.load_data.load_dailymeanLya() |
|
59
|
|
|
np.testing.assert_allclose(pLyat, pLyat2) |
|
60
|
|
|
pd.testing.assert_frame_equal(pLyav, pLyav2) |
|
61
|
|
|
|
|
62
|
|
|
|
|
63
|
|
|
@mark.parametrize("date, tfmt, texp, vexp", AEdata) |
|
64
|
|
|
def test_load_proxyAEvalues(date, tfmt, texp, vexp): |
|
65
|
|
|
pAEt, pAEv = sciapy.regress.load_data.load_dailymeanAE(tfmt=tfmt) |
|
66
|
|
|
idx = list(pAEv.index.to_pydatetime()).index(date) |
|
67
|
|
|
np.testing.assert_allclose(pAEt[idx], texp) |
|
68
|
|
|
np.testing.assert_allclose(pAEv["AE"][idx], vexp) |
|
69
|
|
|
np.testing.assert_allclose(pAEv["AE"][date.strftime("%Y-%m-%d")], vexp) |
|
70
|
|
|
|
|
71
|
|
|
|
|
72
|
|
|
@mark.parametrize("date, tfmt, texp, vexp", Lyadata) |
|
73
|
|
|
def test_load_proxyLyavalues(date, tfmt, texp, vexp): |
|
74
|
|
|
pLyat, pLyav = sciapy.regress.load_data.load_dailymeanLya(tfmt=tfmt) |
|
75
|
|
|
idx = list(pLyav.index.to_pydatetime()).index(date) |
|
76
|
|
|
np.testing.assert_allclose(pLyat[idx], texp) |
|
77
|
|
|
np.testing.assert_allclose(pLyav["Lya"][idx], vexp) |
|
78
|
|
|
np.testing.assert_allclose(pLyav["Lya"][date.strftime("%Y-%m-%d")], vexp) |
|
79
|
|
|
|
|
80
|
|
|
|
|
81
|
|
|
def test_load_dzm_normal(): |
|
82
|
|
|
data = sciapy.regress.load_scia_dzm(DZM_FILE, 70., -75.) |
|
83
|
|
|
np.testing.assert_allclose(data[0], np.array([2010.09184335])) |
|
84
|
|
|
np.testing.assert_allclose(data[1], np.array([25992364.81988303])) |
|
85
|
|
|
np.testing.assert_allclose(data[2], np.array([2722294.10593951])) |
|
86
|
|
|
np.testing.assert_allclose(data[3], np.array([65.5642548])) |
|
87
|
|
|
|
|
88
|
|
|
|
|
89
|
|
|
def test_load_dzm_center(): |
|
90
|
|
|
data = sciapy.regress.load_scia_dzm(DZM_FILE, 70., -45., center=True) |
|
91
|
|
|
np.testing.assert_allclose(data[0], np.array([2010.09184335])) |
|
92
|
|
|
np.testing.assert_allclose(data[1], np.array([-9293324.84946741])) |
|
93
|
|
|
np.testing.assert_allclose(data[2], np.array([2337592.1464543])) |
|
94
|
|
|
np.testing.assert_allclose(data[3], np.array([46.02054338])) |
|
95
|
|
|
|
|
96
|
|
|
|
|
97
|
|
|
def test_load_dzm_spe(): |
|
98
|
|
|
data = sciapy.regress.load_scia_dzm(DZM_FILE, 70., 15., SPEs=True) |
|
99
|
|
|
np.testing.assert_allclose(data[0], np.array([2010.09184335])) |
|
100
|
|
|
np.testing.assert_allclose(data[1], np.array([10184144.7669378])) |
|
101
|
|
|
np.testing.assert_allclose(data[2], np.array([2633165.7502271])) |
|
102
|
|
|
np.testing.assert_allclose(data[3], np.array([45.41338086])) |
|
103
|
|
|
|
|
104
|
|
|
|
|
105
|
|
|
def test_load_dzm_summerSH(): |
|
106
|
|
|
data = sciapy.regress.load_scia_dzm(DZM_FILE, 70., 45., season="summerSH") |
|
107
|
|
|
np.testing.assert_allclose(data[0], np.array([2010.09184335])) |
|
108
|
|
|
np.testing.assert_allclose(data[1], np.array([24484783.29918655])) |
|
109
|
|
|
np.testing.assert_allclose(data[2], np.array([2814284.4588219])) |
|
110
|
|
|
np.testing.assert_allclose(data[3], np.array([65.04123748])) |
|
111
|
|
|
|
|
112
|
|
|
|
|
113
|
|
|
def test_load_dzm_summerNH(): |
|
114
|
|
|
with raises(IndexError): |
|
115
|
|
|
sciapy.regress.load_scia_dzm(DZM_FILE, 70., 75., season="summerNH") |
|
116
|
|
|
|