forked from pvlib/pvlib-python
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_tmy.py
More file actions
114 lines (94 loc) · 4.39 KB
/
test_tmy.py
File metadata and controls
114 lines (94 loc) · 4.39 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import numpy as np
import pandas as pd
from pvlib.iotools import tmy
from tests.conftest import TESTS_DATA_DIR, PVLIB_DATA_DIR
import pytest
# test the API works
from pvlib.iotools import read_tmy3
TMY2_TESTFILE = PVLIB_DATA_DIR / '12839.tm2'
# TMY3 format (two files below) represents midnight as 24:00
TMY3_TESTFILE = PVLIB_DATA_DIR / '703165TY.csv'
TMY3_FEB_LEAPYEAR = PVLIB_DATA_DIR / '723170TYA.CSV'
# The SolarAnywhere TMY3 format (file below) represents midnight as 00:00
TMY3_SOLARANYWHERE = TESTS_DATA_DIR / 'Burlington, United States SolarAnywhere Time Series 2021 Lat_44_465 Lon_-73_205 TMY3 format.csv' # noqa: E501
def test_read_tmy3():
tmy.read_tmy3(TMY3_TESTFILE, map_variables=False)
def test_read_tmy3_norecolumn():
data, _ = tmy.read_tmy3(TMY3_TESTFILE, map_variables=False)
assert 'GHI source' in data.columns
def test_read_tmy3_map_variables():
data, meta = tmy.read_tmy3(TMY3_TESTFILE, map_variables=True)
assert 'ghi' in data.columns
assert 'dni' in data.columns
assert 'dhi' in data.columns
assert 'pressure' in data.columns
assert 'wind_direction' in data.columns
assert 'wind_speed' in data.columns
assert 'temp_air' in data.columns
assert 'temp_dew' in data.columns
assert 'relative_humidity' in data.columns
assert 'albedo' in data.columns
assert 'ghi_extra' in data.columns
assert 'dni_extra' in data.columns
assert 'precipitable_water' in data.columns
def test_read_tmy3_coerce_year():
coerce_year = 1987
data, _ = tmy.read_tmy3(TMY3_TESTFILE, coerce_year=coerce_year,
map_variables=False)
assert (data.index[:-1].year == 1987).all()
assert data.index[-1].year == 1988
def test_read_tmy3_no_coerce_year():
coerce_year = None
data, _ = tmy.read_tmy3(TMY3_TESTFILE, coerce_year=coerce_year,
map_variables=False)
assert 1997 and 1999 in data.index.year
assert data.index[-2] == pd.Timestamp('1998-12-31 23:00:00-09:00')
assert data.index[-1] == pd.Timestamp('1999-01-01 00:00:00-09:00')
def test_read_tmy2():
tmy.read_tmy2(TMY2_TESTFILE)
def test_gh865_read_tmy3_feb_leapyear_hr24():
"""correctly parse the 24th hour if the tmy3 file has a leap year in feb"""
data, meta = read_tmy3(TMY3_FEB_LEAPYEAR, map_variables=False)
# just to be safe, make sure this _IS_ the Greensboro file
greensboro = {
'USAF': 723170,
'Name': '"GREENSBORO PIEDMONT TRIAD INT"',
'State': 'NC',
'TZ': -5.0,
'latitude': 36.1,
'longitude': -79.95,
'altitude': 273.0}
assert meta == greensboro
# February for Greensboro is 1996, a leap year, so check to make sure there
# aren't any rows in the output that contain Feb 29th
assert data.index[1414] == pd.Timestamp('1996-02-28 23:00:00-0500')
assert data.index[1415] == pd.Timestamp('1996-03-01 00:00:00-0500')
# now check if it parses correctly when we try to coerce the year
data, _ = read_tmy3(TMY3_FEB_LEAPYEAR, coerce_year=1990,
map_variables=False)
# if get's here w/o an error, then gh865 is fixed, but let's check anyway
assert all(data.index[:-1].year == 1990)
assert data.index[-1].year == 1991
# let's do a quick sanity check, are the indices monotonically increasing?
assert all(np.diff(data.index.view(np.int64)) == 3600000000000)
# according to the TMY3 manual, each record corresponds to the previous
# hour so check that the 1st hour is 1AM and the last hour is midnite
assert data.index[0].hour == 1
assert data.index[-1].hour == 0
@pytest.fixture
def solaranywhere_index():
return pd.date_range('2021-01-01 01:00:00-05:00', periods=8760, freq='1h')
def test_solaranywhere_tmy3(solaranywhere_index):
# The SolarAnywhere TMY3 format specifies midnight as 00:00 whereas the
# NREL TMY3 format utilizes 24:00. The SolarAnywhere file is therefore
# included to test files with 00:00 timestamps are parsed correctly
data, meta = tmy.read_tmy3(TMY3_SOLARANYWHERE, encoding='iso-8859-1',
map_variables=False)
pd.testing.assert_index_equal(data.index, solaranywhere_index)
assert meta['USAF'] == 0
assert meta['Name'] == 'Burlington United States'
assert meta['State'] == 'NA'
assert meta['TZ'] == -5.0
assert meta['latitude'] == 44.465
assert meta['longitude'] == -73.205
assert meta['altitude'] == 41.0