forked from pvlib/pvlib-python
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_merra2.py
More file actions
70 lines (56 loc) · 2.27 KB
/
test_merra2.py
File metadata and controls
70 lines (56 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
"""
tests for pvlib/iotools/merra2.py
"""
import pandas as pd
import pytest
import pvlib
import os
from tests.conftest import RERUNS, RERUNS_DELAY, requires_earthdata_credentials
@pytest.fixture
def params():
earthdata_username = os.environ["EARTHDATA_USERNAME"]
earthdata_password = os.environ["EARTHDATA_PASSWORD"]
return {
'latitude': 40.01, 'longitude': -80.01,
'start': '2020-06-01 15:00', 'end': '2020-06-01 20:00',
'dataset': 'M2T1NXRAD.5.12.4', 'variables': ['ALBEDO', 'SWGDN'],
'username': earthdata_username, 'password': earthdata_password,
}
@pytest.fixture
def expected():
index = pd.date_range("2020-06-01 15:30", "2020-06-01 20:30", freq="h",
tz="UTC")
index.name = 'time'
albedo = [0.163931, 0.1609407, 0.1601474, 0.1612476, 0.164664, 0.1711341]
ghi = [ 930., 1002.75, 1020.25, 981.25, 886.5, 743.5]
df = pd.DataFrame({'albedo': albedo, 'ghi': ghi}, index=index)
return df
@pytest.fixture
def expected_meta():
return {
'dataset': 'M2T1NXRAD.5.12.4',
'station': 'GridPointRequestedAt[40.010N_80.010W]',
'latitude': 40.0,
'longitude': -80.0,
'units': {'ALBEDO': '1', 'SWGDN': 'W m-2'}
}
@requires_earthdata_credentials
@pytest.mark.remote_data
@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY)
def test_get_merra2(params, expected, expected_meta):
df, meta = pvlib.iotools.get_merra2(**params)
pd.testing.assert_frame_equal(df, expected, check_freq=False)
assert meta == expected_meta
@requires_earthdata_credentials
@pytest.mark.remote_data
@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY)
def test_get_merra2_map_variables(params, expected, expected_meta):
df, meta = pvlib.iotools.get_merra2(**params, map_variables=False)
expected = expected.rename(columns={'albedo': 'ALBEDO', 'ghi': 'SWGDN'})
pd.testing.assert_frame_equal(df, expected, check_freq=False)
assert meta == expected_meta
def test_get_merra2_error():
with pytest.raises(ValueError, match='must be in the same year'):
pvlib.iotools.get_merra2(40, -80, '2019-12-31', '2020-01-02',
username='anything', password='anything',
dataset='anything', variables=[])