forked from pvlib/pvlib-python
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_solargis.py
More file actions
73 lines (61 loc) · 2.57 KB
/
test_solargis.py
File metadata and controls
73 lines (61 loc) · 2.57 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
71
72
73
import pandas as pd
import pytest
import pvlib
import requests
from tests.conftest import (
RERUNS,
RERUNS_DELAY,
assert_frame_equal,
assert_index_equal,
)
@pytest.fixture
def hourly_index():
hourly_index = pd.date_range(start='2022-01-01 00:30+01:00', freq='60min',
periods=24, name='dateTime')
hourly_index.freq = None
return hourly_index
@pytest.fixture
def hourly_index_start_utc():
hourly_index_left_utc = pd.date_range(
start='2023-01-01 00:00+00:00', freq='30min', periods=24*2,
name='dateTime')
hourly_index_left_utc.freq = None
return hourly_index_left_utc
@pytest.fixture
def hourly_dataframe(hourly_index):
ghi = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 5.0, 73.0, 152.0, 141.0, 105.0,
62.0, 65.0, 62.0, 11.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
dni = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 30.0, 233.0, 301.0, 136.0, 32.0,
0.0, 3.0, 77.0, 5.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
return pd.DataFrame(data={'ghi': ghi, 'dni': dni}, index=hourly_index)
@pytest.mark.remote_data
@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY)
def test_get_solargis(hourly_dataframe):
data, meta = pvlib.iotools.get_solargis(
latitude=48.61259, longitude=20.827079,
start='2022-01-01', end='2022-01-01',
tz='GMT+01', variables=['GHI', 'DNI'],
time_resolution='HOURLY', api_key='demo')
assert_frame_equal(data, hourly_dataframe)
@pytest.mark.remote_data
@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY)
def test_get_solargis_utc_start_timestamp(hourly_index_start_utc):
data, meta = pvlib.iotools.get_solargis(
latitude=48.61259, longitude=20.827079,
start='2023-01-01', end='2023-01-01',
variables=['GTI'],
timestamp_type='start',
time_resolution='MIN_30',
map_variables=False, api_key='demo')
assert 'GTI' in data.columns # assert that variables aren't mapped
assert_index_equal(data.index, hourly_index_start_utc)
@pytest.mark.remote_data
@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY)
def test_get_solargis_http_error():
# Test if HTTPError is raised if date outside range is specified
match = r"request fromDate .* is before the available start date"
with pytest.raises(requests.HTTPError, match=match):
_, _ = pvlib.iotools.get_solargis(
latitude=48.61259, longitude=20.827079,
start='1920-01-01', end='1920-01-01', # date outside range
variables=['GHI', 'DNI'], time_resolution='HOURLY', api_key='demo')