def test_get_psm3_tmy_errors( latitude, longitude, api_key, names, interval ): """Test get_psm3() for multiple erroneous input scenarios. These scenarios include: * Bad API key -> HTTP 403 forbidden because api_key is rejected * Bad latitude/longitude -> Coordinates were not found in the NSRDB. * Bad name -> Name is not one of the available options. * Bad interval, single year -> Intervals can only be 30 or 60 minutes. """ with pytest.raises(HTTPError) as excinfo: psm3.get_psm3(latitude, longitude, api_key, PVLIB_EMAIL, names=names, interval=interval) # ensure the HTTPError caught isn't due to overuse of the API key assert "OVER_RATE_LIMIT" not in str(excinfo.value)
def test_get_psm3_5min(nrel_api_key): """test get_psm3 for 5-minute data""" data, metadata = psm3.get_psm3(LATITUDE, LONGITUDE, nrel_api_key, PVLIB_EMAIL, names='2019', interval=5) assert len(data) == 525600/5 first_day = data.loc['2019-01-01'] expected = pd.read_csv(YEAR_TEST_DATA_5MIN) assert_psm3_equal(first_day, metadata, expected)
def test_get_psm3_tmy(nrel_api_key): """test get_psm3 with a TMY""" header, data = psm3.get_psm3(LATITUDE, LONGITUDE, nrel_api_key, PVLIB_EMAIL, names='tmy-2017') expected = pd.read_csv(TMY_TEST_DATA) assert_psm3_equal(header, data, expected)
def test_get_psm3_check_leap_day(nrel_api_key): _, data_2012 = psm3.get_psm3(LATITUDE, LONGITUDE, nrel_api_key, PVLIB_EMAIL, names="2012", interval=60, leap_day=True) assert len(data_2012) == (8760 + 24)
def test_get_psm3_singleyear(nrel_api_key): """test get_psm3 with a single year""" header, data = psm3.get_psm3(LATITUDE, LONGITUDE, nrel_api_key, PVLIB_EMAIL, names='2017', interval=30) expected = pd.read_csv(YEAR_TEST_DATA) assert_psm3_equal(header, data, expected)
def test_get_psm3_tmy(nrel_api_key): """test get_psm3 with a TMY""" data, metadata = psm3.get_psm3(LATITUDE, LONGITUDE, nrel_api_key, PVLIB_EMAIL, names='tmy-2017', map_variables=False) expected = pd.read_csv(TMY_TEST_DATA) assert_psm3_equal(data, metadata, expected)
def test_get_psm3_attribute_mapping(nrel_api_key): """Test that pvlib names can be passed in as attributes and get correctly reverse mapped to PSM3 names""" data, meta = psm3.get_psm3(LATITUDE, LONGITUDE, nrel_api_key, PVLIB_EMAIL, names=2019, interval=60, attributes=['ghi', 'wind_speed'], map_variables=True) assert 'ghi' in data.columns assert 'wind_speed' in data.columns assert 'latitude' in meta.keys() assert 'longitude' in meta.keys() assert 'altitude' in meta.keys()
def test_get_psm3(): """test get_psm3""" header, data = psm3.get_psm3(LATITUDE, LONGITUDE, DEMO_KEY, PVLIB_EMAIL) expected = pd.read_csv(TEST_DATA) # check datevec columns assert np.allclose(data.Year, expected.Year) assert np.allclose(data.Month, expected.Month) assert np.allclose(data.Day, expected.Day) assert np.allclose(data.Hour, expected.Hour) # XXX: unclear if NSRDB changes to timesteps are permanent or temporary # assert np.allclose(data.Minute, expected.Minute) # check data columns assert np.allclose(data.GHI, expected.GHI) assert np.allclose(data.DNI, expected.DNI) assert np.allclose(data.DHI, expected.DHI) assert np.allclose(data.Temperature, expected.Temperature) assert np.allclose(data.Pressure, expected.Pressure) assert np.allclose(data['Dew Point'], expected['Dew Point']) assert np.allclose(data['Surface Albedo'], expected['Surface Albedo']) assert np.allclose(data['Wind Speed'], expected['Wind Speed']) assert np.allclose(data['Wind Direction'], expected['Wind Direction']) # check header for hf in HEADER_FIELDS: assert hf in header # check timezone assert (data.index.tzinfo.zone == 'Etc/GMT%+d' % -header['Time Zone']) # check errors with pytest.raises(HTTPError): # HTTP 403 forbidden because api_key is rejected psm3.get_psm3(LATITUDE, LONGITUDE, api_key='BAD', email=PVLIB_EMAIL) with pytest.raises(HTTPError): # coordinates were not found in the NSRDB psm3.get_psm3(51, -5, DEMO_KEY, PVLIB_EMAIL) with pytest.raises(HTTPError): # names is not one of the available options psm3.get_psm3(LATITUDE, LONGITUDE, DEMO_KEY, PVLIB_EMAIL, names='bad') with pytest.raises(HTTPError): # intervals can only be 30 or 60 minutes psm3.get_psm3(LATITUDE, LONGITUDE, DEMO_KEY, PVLIB_EMAIL, interval=15)
def test_get_psm3_singleyear(): """test get_psm3 with a single year""" header, data = psm3.get_psm3(LATITUDE, LONGITUDE, DEMO_KEY, PVLIB_EMAIL, names='2017', interval=30) expected = pd.read_csv(YEAR_TEST_DATA) assert_psm3_equal(header, data, expected) # check leap day _, data_2012 = psm3.get_psm3(LATITUDE, LONGITUDE, DEMO_KEY, PVLIB_EMAIL, names='2012', interval=60, leap_day=True) assert len(data_2012) == (8760 + 24) # check errors with pytest.raises(HTTPError): # HTTP 403 forbidden because api_key is rejected psm3.get_psm3(LATITUDE, LONGITUDE, api_key='BAD', email=PVLIB_EMAIL, names='2017') with pytest.raises(HTTPError): # coordinates were not found in the NSRDB psm3.get_psm3(51, -5, DEMO_KEY, PVLIB_EMAIL, names='2017') with pytest.raises(HTTPError): # intervals can only be 30 or 60 minutes psm3.get_psm3(LATITUDE, LONGITUDE, DEMO_KEY, PVLIB_EMAIL, names='2017', interval=15)
def test_get_psm3_tmy(): """test get_psm3 with a TMY""" header, data = psm3.get_psm3(LATITUDE, LONGITUDE, DEMO_KEY, PVLIB_EMAIL, names='tmy-2017') expected = pd.read_csv(TMY_TEST_DATA) assert_psm3_equal(header, data, expected) # check errors with pytest.raises(HTTPError): # HTTP 403 forbidden because api_key is rejected psm3.get_psm3(LATITUDE, LONGITUDE, api_key='BAD', email=PVLIB_EMAIL) with pytest.raises(HTTPError): # coordinates were not found in the NSRDB psm3.get_psm3(51, -5, DEMO_KEY, PVLIB_EMAIL) with pytest.raises(HTTPError): # names is not one of the available options psm3.get_psm3(LATITUDE, LONGITUDE, DEMO_KEY, PVLIB_EMAIL, names='bad')