test_regress_load_data.test_load_dzm_summerNH()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 6
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 0
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
from astropy.time import Time
17
import numpy as np
18
from pytest import mark, raises
19
try:
20
	import netCDF4
21
	NC_EXT = ".nc"
22
except ImportError:
23
	NC_EXT = ".nc3"
24
25
import sciapy.regress
26
27
DZM_FILE = resource_filename(__name__, "sciaNO_20100203_v6.2.1_geogra30" + NC_EXT)
28
29
AEdata = [
30
		("2000-01-01", "jyear", 1999.9986311, 507.208333),
31
		("2000-01-01", "jd", 2451544.5, 507.208333),
32
		("2000-01-01", "mjd", 51544.0, 507.208333),
33
		("2007-07-01", "jyear", 2007.4948665, 83.208333),
34
		("2007-07-01", "jd", 2454282.5, 83.208333),
35
		("2007-07-01", "mjd", 54282.0, 83.208333),
36
]
37
Lyadata = [
38
		("2000-01-01", "jyear", 1999.9986311, 4.59),
39
		("2000-01-01", "jd", 2451544.5, 4.59),
40
		("2000-01-01", "mjd", 51544.0, 4.59),
41
		("2007-07-01", "jyear", 2007.4948665, 3.74),
42
		("2007-07-01", "jd", 2454282.5, 3.74),
43
		("2007-07-01", "mjd", 54282.0, 3.74),
44
]
45
46
47
def test_load_proxyAEfiles():
48
	AEfile = resource_filename("sciapy",
49
			"data/indices/AE_Kyoto_1980-2018_daily2_shift12h.dat")
50
	pAEt, pAEv = sciapy.regress.load_solar_gm_table(AEfile,
51
			cols=[0, 1], names=["time", "AE"], tfmt="jyear")
52
	pAEt2, pAEv2 = sciapy.regress.load_data.load_dailymeanAE()
53
	np.testing.assert_allclose(pAEt, pAEt2)
54
55
56
def test_load_proxyLyafiles():
57
	Lyafile = resource_filename("sciapy",
58
			"data/indices/lisird_lya3_1980-2021.dat")
59
	pLyat, pLyav = sciapy.regress.load_solar_gm_table(Lyafile,
60
			cols=[0, 1], names=["time", "Lya"], tfmt="jyear")
61
	pLyat2, pLyav2 = sciapy.regress.load_data.load_dailymeanLya()
62
	np.testing.assert_allclose(pLyat, pLyat2)
63
64
65
@mark.parametrize("date, tfmt, texp, vexp", AEdata)
66
def test_load_proxyAEvalues(date, tfmt, texp, vexp):
67
	pAEt, pAEv = sciapy.regress.load_data.load_dailymeanAE(tfmt=tfmt)
68
	idx = list(Time(pAEt, format=tfmt).iso).index(date + " 00:00:00.000")
69
	np.testing.assert_allclose(pAEt[idx], texp)
70
	np.testing.assert_allclose(pAEv["AE"][idx], vexp)
71
72
73
@mark.parametrize("date, tfmt, texp, vexp", Lyadata)
74
def test_load_proxyLyavalues(date, tfmt, texp, vexp):
75
	pLyat, pLyav = sciapy.regress.load_data.load_dailymeanLya(tfmt=tfmt)
76
	idx = list(Time(pLyat, format=tfmt).iso).index(date + " 00:00:00.000")
77
	np.testing.assert_allclose(pLyat[idx], texp)
78
	np.testing.assert_allclose(pLyav["Lya"][idx], 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
	data = sciapy.regress.load_scia_dzm(DZM_FILE, 70., 75., season="summerNH")
115
	np.testing.assert_equal(data[0], np.array([]))
116
	np.testing.assert_equal(data[1], np.array([]))
117
	np.testing.assert_equal(data[2], np.array([]))
118
	np.testing.assert_equal(data[3], np.array([]))
119