Passed
Push — master ( c8cb9a...05ebe9 )
by Stefan
04:22
created

test_dataset   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 68
dl 0
loc 91
rs 10
c 0
b 0
f 0

3 Functions

Rating   Name   Duplication   Size   Complexity  
A test_dataset() 0 23 1
A test_nd_raise() 0 11 2
A test_lst() 0 43 1
1
# -*- coding: utf-8 -*-
2
# vim:fileencoding=utf-8
3
import datetime as dt
4
import numpy as np
5
import pytest
6
7
from nrlmsise00.dataset import msise_4d
8
9
10
@pytest.mark.parametrize(
11
	"ap, lon, lst", [
12
		(None, -70., None),
13
		(4., -70., 16.),
14
		([5., 6.], -70., [6., 18.]),
15
		(None, [-70, 0., 70.], [5., 7., 12.]),
16
		(None, [-70, 0., 70.], [[5., 17.], [6., 18.], [7., 19.]]),
17
		(None, [-70, 0., 70.], [[5., 6., 7.], [17., 18., 19.]]),
18
	]
19
)
20
def test_dataset(ap, lon, lst):
21
	# checks that broadcasting works as intended
22
	ds = msise_4d(
23
		[dt.datetime(2009, 6, 21, 8, 3, 20), dt.datetime(2009, 12, 21, 16, 3, 20)],
24
		[400, 200, 100],  # alt
25
		[60, 30, 0, -30, -60],  # g_lat
26
		lon,    # g_long
27
		150,    # f107A
28
		150,    # f107
29
		ap=ap,  # ap
30
		lst=lst,
31
	)
32
	assert ds
33
34
35
@pytest.mark.parametrize(
36
	"lon, lst, lst_expected", [
37
		(
38
			0,
39
			None,
40
			np.array([8., 16.]).reshape(2, 1),
41
		),
42
		(
43
			[30, 150],
44
			None,
45
			np.array([[10., 18.], [18., 26.]]).reshape(2, 2),
46
		),
47
		(
48
			[30, 120, 150],
49
			None,
50
			np.array([[10., 16., 18.], [18., 24., 26.]]),
51
		),
52
		(
53
			[30, 120, 150],
54
			[10., 16.],  # same shape as "time"
55
			np.array([[10., 10., 10.], [16., 16., 16.]]),
56
		),
57
		(
58
			[30, 120, 150],
59
			[10., 16., 18.],  # same shape as "lon"
60
			np.array([[10., 16., 18.], [10., 16., 18.]]),
61
		),
62
	]
63
)
64
def test_lst(lon, lst, lst_expected):
65
	# checks that local time works as intended
66
	ds = msise_4d(
67
		[dt.datetime(2009, 6, 21, 8), dt.datetime(2009, 12, 21, 16)],
68
		[400, 200, 100],  # alt
69
		[60, 30, 0, -30, -60],  # g_lat
70
		lon,    # g_long
71
		150,    # f107A
72
		150,    # f107
73
		4,      # ap
74
		lst=lst,
75
	)
76
	assert ds
77
	np.testing.assert_allclose(ds.lst.values, lst_expected)
78
79
80
def test_nd_raise():
81
	with pytest.raises(ValueError, match=r"Only scalars and up to 1-D .*"):
82
		msise_4d(
83
			dt.datetime(2009, 6, 21, 8),
84
			# 2-d should fail
85
			[[200]],  # alt
86
			60,   # g_lat
87
			-70,  # g_long
88
			150,  # f107A
89
			150,  # f107
90
			4,    # ap
91
		)
92