11"""
2- test iotools for GOES4
2+ test iotools for PSM4
33"""
44
55import os
6- from pvlib .iotools import goes4
6+ from pvlib .iotools import psm4
77from ..conftest import DATA_DIR , RERUNS , RERUNS_DELAY , assert_index_equal
88import numpy as np
99import pandas as pd
1212from io import StringIO
1313import warnings
1414
15- TMY_TEST_DATA = DATA_DIR / 'test_goes4_tmy -2023.csv'
16- YEAR_TEST_DATA = DATA_DIR / 'test_goes4_2023 .csv'
17- YEAR_TEST_DATA_5MIN = DATA_DIR / 'test_goes4_2023_5min .csv'
18- MANUAL_TEST_DATA = DATA_DIR / 'test_read_goes4 .csv'
15+ TMY_TEST_DATA = DATA_DIR / 'test_psm4_tmy -2023.csv'
16+ YEAR_TEST_DATA = DATA_DIR / 'test_psm4_2023 .csv'
17+ YEAR_TEST_DATA_5MIN = DATA_DIR / 'test_psm4_2023_5min .csv'
18+ MANUAL_TEST_DATA = DATA_DIR / 'test_read_psm4 .csv'
1919LATITUDE , LONGITUDE = 40.5137 , - 108.5449
2020METADATA_FIELDS = [
2121 'Source' , 'Location ID' , 'City' , 'State' , 'Country' , 'Latitude' ,
@@ -46,8 +46,8 @@ def nrel_api_key():
4646 return demo_key
4747
4848
49- def assert_goes4_equal (data , metadata , expected ):
50- """check consistency of GOES4 data"""
49+ def assert_psm4_equal (data , metadata , expected ):
50+ """check consistency of PSM4 data"""
5151 # check datevec columns
5252 assert np .allclose (data .Year , expected .Year )
5353 assert np .allclose (data .Month , expected .Month )
@@ -73,46 +73,46 @@ def assert_goes4_equal(data, metadata, expected):
7373
7474@pytest .mark .remote_data
7575@pytest .mark .flaky (reruns = RERUNS , reruns_delay = RERUNS_DELAY )
76- def test_get_goes4_tmy (nrel_api_key ):
77- """test get_goes4 with a TMY"""
78- data , metadata = goes4 . get_goes4 (LATITUDE , LONGITUDE , nrel_api_key ,
79- PVLIB_EMAIL , names = 'tmy-2023' ,
80- leap_day = False , map_variables = False )
76+ def test_get_psm4_tmy (nrel_api_key ):
77+ """test get_psm4 with a TMY"""
78+ data , metadata = psm4 . get_psm4 (LATITUDE , LONGITUDE , nrel_api_key ,
79+ PVLIB_EMAIL , names = 'tmy-2023' ,
80+ leap_day = False , map_variables = False )
8181 expected = pd .read_csv (TMY_TEST_DATA )
82- assert_goes4_equal (data , metadata , expected )
82+ assert_psm4_equal (data , metadata , expected )
8383
8484
8585@pytest .mark .remote_data
8686@pytest .mark .flaky (reruns = RERUNS , reruns_delay = RERUNS_DELAY )
87- def test_get_goes4_singleyear (nrel_api_key ):
88- """test get_goes4 with a single year"""
89- data , metadata = goes4 . get_goes4 (LATITUDE , LONGITUDE , nrel_api_key ,
90- PVLIB_EMAIL , names = '2023' ,
91- leap_day = False , map_variables = False ,
92- interval = 30 )
87+ def test_get_psm4_singleyear (nrel_api_key ):
88+ """test get_psm4 with a single year"""
89+ data , metadata = psm4 . get_psm4 (LATITUDE , LONGITUDE , nrel_api_key ,
90+ PVLIB_EMAIL , names = '2023' ,
91+ leap_day = False , map_variables = False ,
92+ interval = 30 )
9393 expected = pd .read_csv (YEAR_TEST_DATA )
94- assert_goes4_equal (data , metadata , expected )
94+ assert_psm4_equal (data , metadata , expected )
9595
9696
9797@pytest .mark .remote_data
9898@pytest .mark .flaky (reruns = RERUNS , reruns_delay = RERUNS_DELAY )
99- def test_get_goes4_5min (nrel_api_key ):
100- """test get_goes4 for 5-minute data"""
101- data , metadata = goes4 . get_goes4 (LATITUDE , LONGITUDE , nrel_api_key ,
102- PVLIB_EMAIL , names = '2023' , interval = 5 ,
103- leap_day = False , map_variables = False )
99+ def test_get_psm4_5min (nrel_api_key ):
100+ """test get_psm4 for 5-minute data"""
101+ data , metadata = psm4 . get_psm4 (LATITUDE , LONGITUDE , nrel_api_key ,
102+ PVLIB_EMAIL , names = '2023' , interval = 5 ,
103+ leap_day = False , map_variables = False )
104104 assert len (data ) == 525600 / 5
105105 first_day = data .loc ['2023-01-01' ]
106106 expected = pd .read_csv (YEAR_TEST_DATA_5MIN )
107- assert_goes4_equal (first_day , metadata , expected )
107+ assert_psm4_equal (first_day , metadata , expected )
108108
109109
110110@pytest .mark .remote_data
111111@pytest .mark .flaky (reruns = RERUNS , reruns_delay = RERUNS_DELAY )
112- def test_get_goes4_check_leap_day (nrel_api_key ):
113- data_2012 , _ = goes4 . get_goes4 (LATITUDE , LONGITUDE , nrel_api_key ,
114- PVLIB_EMAIL , names = "2012" , interval = 60 ,
115- leap_day = True , map_variables = False )
112+ def test_get_psm4_check_leap_day (nrel_api_key ):
113+ data_2012 , _ = psm4 . get_psm4 (LATITUDE , LONGITUDE , nrel_api_key ,
114+ PVLIB_EMAIL , names = "2012" , interval = 60 ,
115+ leap_day = True , map_variables = False )
116116 assert len (data_2012 ) == (8760 + 24 )
117117
118118
@@ -124,10 +124,10 @@ def test_get_goes4_check_leap_day(nrel_api_key):
124124 ])
125125@pytest .mark .remote_data
126126@pytest .mark .flaky (reruns = RERUNS , reruns_delay = RERUNS_DELAY )
127- def test_get_goes4_tmy_errors (
127+ def test_get_psm4_tmy_errors (
128128 latitude , longitude , api_key , names , interval
129129):
130- """Test get_goes4 () for multiple erroneous input scenarios.
130+ """Test get_psm4 () for multiple erroneous input scenarios.
131131
132132 These scenarios include:
133133 * Bad API key -> HTTP 403 forbidden because api_key is rejected
@@ -136,39 +136,39 @@ def test_get_goes4_tmy_errors(
136136 * Bad interval, single year -> Intervals can only be 30 or 60 minutes.
137137 """
138138 with pytest .raises (HTTPError ) as excinfo :
139- goes4 . get_goes4 (latitude , longitude , api_key , PVLIB_EMAIL ,
140- names = names , interval = interval , leap_day = False ,
141- map_variables = False )
139+ psm4 . get_psm4 (latitude , longitude , api_key , PVLIB_EMAIL ,
140+ names = names , interval = interval , leap_day = False ,
141+ map_variables = False )
142142 # ensure the HTTPError caught isn't due to overuse of the API key
143143 assert "OVER_RATE_LIMIT" not in str (excinfo .value )
144144
145145
146146@pytest .fixture
147147def io_input (request ):
148- """file-like object for parse_goes4 """
148+ """file-like object for parse_psm4 """
149149 with MANUAL_TEST_DATA .open () as f :
150150 data = f .read ()
151151 obj = StringIO (data )
152152 return obj
153153
154154
155- def test_parse_goes4 (io_input ):
156- """test parse_goes4 """
157- data , metadata = goes4 . parse_goes4 (io_input , map_variables = False )
155+ def test_parse_psm4 (io_input ):
156+ """test parse_psm4 """
157+ data , metadata = psm4 . parse_psm4 (io_input , map_variables = False )
158158 expected = pd .read_csv (YEAR_TEST_DATA )
159- assert_goes4_equal (data , metadata , expected )
159+ assert_psm4_equal (data , metadata , expected )
160160
161161
162- def test_read_goes4 ():
163- """test read_goes4 """
164- data , metadata = goes4 . read_goes4 (MANUAL_TEST_DATA , map_variables = False )
162+ def test_read_psm4 ():
163+ """test read_psm4 """
164+ data , metadata = psm4 . read_psm4 (MANUAL_TEST_DATA , map_variables = False )
165165 expected = pd .read_csv (YEAR_TEST_DATA )
166- assert_goes4_equal (data , metadata , expected )
166+ assert_psm4_equal (data , metadata , expected )
167167
168168
169- def test_read_goes4_map_variables ():
170- """test read_goes4 map_variables=True"""
171- data , metadata = goes4 . read_goes4 (MANUAL_TEST_DATA , map_variables = True )
169+ def test_read_psm4_map_variables ():
170+ """test read_psm4 map_variables=True"""
171+ data , metadata = psm4 . read_psm4 (MANUAL_TEST_DATA , map_variables = True )
172172 columns_mapped = ['Year' , 'Month' , 'Day' , 'Hour' , 'Minute' , 'temp_air' ,
173173 'alpha' , 'aod' , 'asymmetry' , 'dhi_clear' , 'dni_clear' ,
174174 'ghi_clear' , 'Cloud Fill Flag' , 'Cloud Type' ,
@@ -181,13 +181,13 @@ def test_read_goes4_map_variables():
181181
182182@pytest .mark .remote_data
183183@pytest .mark .flaky (reruns = RERUNS , reruns_delay = RERUNS_DELAY )
184- def test_get_goes4_attribute_mapping (nrel_api_key ):
184+ def test_get_psm4_attribute_mapping (nrel_api_key ):
185185 """Test that pvlib names can be passed in as attributes and get correctly
186- reverse mapped to GOES4 names"""
187- data , meta = goes4 . get_goes4 (LATITUDE , LONGITUDE , nrel_api_key ,
188- PVLIB_EMAIL , names = 2019 , interval = 60 ,
189- attributes = ['ghi' , 'wind_speed' ],
190- leap_day = False , map_variables = True )
186+ reverse mapped to psm4 names"""
187+ data , meta = psm4 . get_psm4 (LATITUDE , LONGITUDE , nrel_api_key ,
188+ PVLIB_EMAIL , names = 2019 , interval = 60 ,
189+ attributes = ['ghi' , 'wind_speed' ],
190+ leap_day = False , map_variables = True )
191191 # Check that columns are in the correct order (GH1647)
192192 expected_columns = [
193193 'Year' , 'Month' , 'Day' , 'Hour' , 'Minute' , 'ghi' , 'wind_speed' ]
0 commit comments