diff --git a/docs/sphinx/source/whatsnew/v0.6.2.rst b/docs/sphinx/source/whatsnew/v0.6.2.rst index de00f40816..995bfe377b 100644 --- a/docs/sphinx/source/whatsnew/v0.6.2.rst +++ b/docs/sphinx/source/whatsnew/v0.6.2.rst @@ -46,10 +46,15 @@ Bug fixes near horizon. (:issue:`656`) * Fixed numpy warnings in :py:func:`~pvlib.tracking.singleaxis` when comparing NaN values to limits. (:issue:`622`) +* Silenced divide by 0 irradiance warnings in + :py:func:`~pvlib.irradiance.klucher` and + :py:func:`~pvlib.pvsystem.calcparams_desoto`. (:issue:`698`) +* Fix :py:class:`~pvlib.forecast.NDFD` model by updating variables. Testing ~~~~~~~ +* Remove most expected warnings emitted by test suite. (:issue:`698`) Contributors diff --git a/pvlib/forecast.py b/pvlib/forecast.py index 729c72b4df..bc93e96da5 100644 --- a/pvlib/forecast.py +++ b/pvlib/forecast.py @@ -17,8 +17,8 @@ import warnings warnings.warn( - 'The forecast module algorithms and features are highly experimental. ' + - 'The API may change, the functionality may be consolidated into an io ' + + 'The forecast module algorithms and features are highly experimental. ' + 'The API may change, the functionality may be consolidated into an io ' 'module, or the module may be separated into its own package.') @@ -97,7 +97,7 @@ class ForecastModel(object): """ access_url_key = 'NetcdfSubset' - catalog_url = 'http://thredds.ucar.edu/thredds/catalog.xml' + catalog_url = 'https://thredds.ucar.edu/thredds/catalog.xml' base_tds_url = catalog_url.split('/thredds/')[0] data_format = 'netcdf' @@ -789,6 +789,9 @@ def __init__(self, set_type='best'): self.variables = { 'temp_air': 'Temperature_surface', 'wind_speed_gust': 'Wind_speed_gust_surface', + # 'temp_air': 'Temperature_height_above_ground', # GH 702 + # 'wind_speed_u': 'u-component_of_wind_height_above_ground', + # 'wind_speed_v': 'v-component_of_wind_height_above_ground', 'total_clouds': 'Total_cloud_cover_entire_atmosphere', 'low_clouds': 'Low_cloud_cover_UnknownLevelType-214', 'mid_clouds': 'Medium_cloud_cover_UnknownLevelType-224', @@ -830,6 +833,7 @@ def process_data(self, data, cloud_cover='total_clouds', **kwargs): data = super(HRRR_ESRL, self).process_data(data, **kwargs) data['temp_air'] = self.kelvin_to_celsius(data['temp_air']) data['wind_speed'] = self.gust_to_speed(data) + # data['wind_speed'] = self.uv_to_speed(data) # GH 702 irrads = self.cloud_cover_to_irradiance(data[cloud_cover], **kwargs) data = data.join(irrads, how='outer') return data[self.output_variables] @@ -1036,9 +1040,8 @@ def __init__(self, set_type='best'): model_type = 'Forecast Products and Analyses' model = 'National Weather Service CONUS Forecast Grids (CONDUIT)' self.variables = { - 'temp_air': 'Temperature_surface', - 'wind_speed': 'Wind_speed_surface', - 'wind_speed_gust': 'Wind_speed_gust_surface', + 'temp_air': 'Temperature_height_above_ground', + 'wind_speed': 'Wind_speed_height_above_ground', 'total_clouds': 'Total_cloud_cover_surface', } self.output_variables = [ 'temp_air', diff --git a/pvlib/irradiance.py b/pvlib/irradiance.py index f34ba4b523..f45c658660 100644 --- a/pvlib/irradiance.py +++ b/pvlib/irradiance.py @@ -750,7 +750,10 @@ def klucher(surface_tilt, surface_azimuth, dhi, ghi, solar_zenith, solar_zenith, solar_azimuth) cos_tt = np.maximum(cos_tt, 0) # GH 526 - F = 1 - ((dhi / ghi) ** 2) + # silence warning from 0 / 0 + with np.errstate(invalid='ignore'): + F = 1 - ((dhi / ghi) ** 2) + try: # fails with single point input F.fillna(0, inplace=True) diff --git a/pvlib/pvsystem.py b/pvlib/pvsystem.py index 82380622e1..ad7981f08e 100644 --- a/pvlib/pvsystem.py +++ b/pvlib/pvsystem.py @@ -1276,7 +1276,9 @@ def calcparams_desoto(effective_irradiance, temp_cell, # by applying reflection and soiling losses to broadband plane of array # irradiance and not applying a spectral loss modifier, i.e., # spectral_modifier = 1.0. - Rsh = R_sh_ref * (irrad_ref / effective_irradiance) + # use errstate to silence divide by warning + with np.errstate(divide='ignore'): + Rsh = R_sh_ref * (irrad_ref / effective_irradiance) Rs = R_s return IL, I0, Rs, Rsh, nNsVth diff --git a/pvlib/test/conftest.py b/pvlib/test/conftest.py index 852a38a028..e91adb8689 100644 --- a/pvlib/test/conftest.py +++ b/pvlib/test/conftest.py @@ -114,7 +114,7 @@ def has_numba(): try: import numba except ImportError: - return True + return False else: vers = numba.__version__.split('.') if int(vers[0] + vers[1]) < 17: diff --git a/pvlib/test/test_clearsky.py b/pvlib/test/test_clearsky.py index ec82587930..ee291345f9 100644 --- a/pvlib/test/test_clearsky.py +++ b/pvlib/test/test_clearsky.py @@ -8,7 +8,7 @@ import pytz import pytest -from numpy.testing import assert_almost_equal, assert_allclose +from numpy.testing import assert_allclose from pandas.util.testing import assert_frame_equal, assert_series_equal from pvlib.location import Location @@ -308,8 +308,9 @@ def test_simplified_solis_scalar_neg_elevation(): def test_simplified_solis_series_elevation(): - expected = pd.DataFrame(np.array([[959.335463, 1064.653145, 129.125602]]), - columns=['dni', 'ghi', 'dhi']) + expected = pd.DataFrame( + np.array([[959.335463, 1064.653145, 129.125602]]), + columns=['dni', 'ghi', 'dhi']) expected = expected[['ghi', 'dni', 'dhi']] out = clearsky.simplified_solis(pd.Series(80)) diff --git a/pvlib/test/test_forecast.py b/pvlib/test/test_forecast.py index 622e007a4c..2ff37c0ad6 100644 --- a/pvlib/test/test_forecast.py +++ b/pvlib/test/test_forecast.py @@ -13,7 +13,10 @@ if has_siphon: - from pvlib.forecast import GFS, HRRR_ESRL, HRRR, NAM, NDFD, RAP + with warnings.catch_warnings(): + # don't emit import warning + warnings.simplefilter("ignore") + from pvlib.forecast import GFS, HRRR_ESRL, HRRR, NAM, NDFD, RAP # setup times and location to be tested. Tucson, AZ _latitude = 32.2 @@ -27,7 +30,8 @@ HRRR_ESRL, marks=[ skip_windows, pytest.mark.xfail(reason="HRRR_ESRL is unreliable"), - pytest.mark.timeout(timeout=60)])] + pytest.mark.timeout(timeout=60), + pytest.mark.filterwarnings('ignore:.*experimental')])] _working_models = [] _variables = ['temp_air', 'wind_speed', 'total_clouds', 'low_clouds', 'mid_clouds', 'high_clouds', 'dni', 'dhi', 'ghi'] @@ -75,21 +79,21 @@ def test_process_data(model): def test_vert_level(): amodel = NAM() vert_level = 5000 - data = amodel.get_processed_data(_latitude, _longitude, _start, _end, - vert_level=vert_level) + amodel.get_processed_data(_latitude, _longitude, _start, _end, + vert_level=vert_level) + @requires_siphon def test_datetime(): amodel = NAM() start = datetime.now() end = start + timedelta(days=1) - data = amodel.get_processed_data(_latitude, _longitude , start, end) + amodel.get_processed_data(_latitude, _longitude, start, end) @requires_siphon def test_queryvariables(): amodel = GFS() - old_variables = amodel.variables new_variables = ['u-component_of_wind_height_above_ground'] data = amodel.get_data(_latitude, _longitude, _start, _end, query_variables=new_variables) diff --git a/pvlib/test/test_irradiance.py b/pvlib/test/test_irradiance.py index a2799371c6..19f1e9244f 100644 --- a/pvlib/test/test_irradiance.py +++ b/pvlib/test/test_irradiance.py @@ -1,5 +1,6 @@ import datetime from collections import OrderedDict +import warnings import numpy as np from numpy import array, nan @@ -107,18 +108,24 @@ def test_get_extra_radiation(input, expected, method): assert_allclose(out, expected, atol=1) -@requires_numba -def test_get_extra_radiation_nrel_numba(times): - result = irradiance.get_extra_radiation(times, method='nrel', how='numba', - numthreads=8) - assert_allclose(result, [1322.332316, 1322.296282, 1322.261205, 1322.227091]) - - def test_get_extra_radiation_epoch_year(): out = irradiance.get_extra_radiation(doy, method='nrel', epoch_year=2012) assert_allclose(out, 1382.4926804890767, atol=0.1) +@requires_numba +def test_get_extra_radiation_nrel_numba(times): + with warnings.catch_warnings(): + # don't warn on method reload or num threads + warnings.simplefilter("ignore") + result = irradiance.get_extra_radiation( + times, method='nrel', how='numba', numthreads=4) + # and reset to no-numba state + irradiance.get_extra_radiation(times, method='nrel') + assert_allclose(result, + [1322.332316, 1322.296282, 1322.261205, 1322.227091]) + + def test_get_extra_radiation_invalid(): with pytest.raises(ValueError): irradiance.get_extra_radiation(300, method='invalid') @@ -135,13 +142,15 @@ def test_grounddiffuse_simple_series(irrad_data): def test_grounddiffuse_albedo_0(irrad_data): - ground_irrad = irradiance.get_ground_diffuse(40, irrad_data['ghi'], albedo=0) + ground_irrad = irradiance.get_ground_diffuse( + 40, irrad_data['ghi'], albedo=0) assert 0 == ground_irrad.all() def test_grounddiffuse_albedo_invalid_surface(irrad_data): with pytest.raises(KeyError): - irradiance.get_ground_diffuse(40, irrad_data['ghi'], surface_type='invalid') + irradiance.get_ground_diffuse( + 40, irrad_data['ghi'], surface_type='invalid') def test_grounddiffuse_albedo_surface(irrad_data): @@ -193,26 +202,24 @@ def test_klucher_series(irrad_data, ephem_data): def test_haydavies(irrad_data, ephem_data, dni_et): - result = irradiance.haydavies(40, 180, irrad_data['dhi'], irrad_data['dni'], - dni_et, - ephem_data['apparent_zenith'], - ephem_data['azimuth']) + result = irradiance.haydavies( + 40, 180, irrad_data['dhi'], irrad_data['dni'], dni_et, + ephem_data['apparent_zenith'], ephem_data['azimuth']) # values from matlab 1.4 code assert_allclose(result, [0, 27.1775, 102.9949, 33.1909], atol=1e-4) def test_reindl(irrad_data, ephem_data, dni_et): - result = irradiance.reindl(40, 180, irrad_data['dhi'], irrad_data['dni'], - irrad_data['ghi'], dni_et, - ephem_data['apparent_zenith'], - ephem_data['azimuth']) + result = irradiance.reindl( + 40, 180, irrad_data['dhi'], irrad_data['dni'], irrad_data['ghi'], + dni_et, ephem_data['apparent_zenith'], ephem_data['azimuth']) # values from matlab 1.4 code assert_allclose(result, [np.nan, 27.9412, 104.1317, 34.1663], atol=1e-4) def test_king(irrad_data, ephem_data): result = irradiance.king(40, irrad_data['dhi'], irrad_data['ghi'], - ephem_data['apparent_zenith']) + ephem_data['apparent_zenith']) assert_allclose(result, [0, 44.629352, 115.182626, 79.719855], atol=1e-4) @@ -220,8 +227,8 @@ def test_perez(irrad_data, ephem_data, dni_et, relative_airmass): dni = irrad_data['dni'].copy() dni.iloc[2] = np.nan out = irradiance.perez(40, 180, irrad_data['dhi'], dni, - dni_et, ephem_data['apparent_zenith'], - ephem_data['azimuth'], relative_airmass) + dni_et, ephem_data['apparent_zenith'], + ephem_data['azimuth'], relative_airmass) expected = pd.Series(np.array( [ 0. , 31.46046871, np.nan, 45.45539877]), index=irrad_data.index) @@ -260,8 +267,9 @@ def test_perez_arrays(irrad_data, ephem_data, dni_et, relative_airmass): dni = irrad_data['dni'].copy() dni.iloc[2] = np.nan out = irradiance.perez(40, 180, irrad_data['dhi'].values, dni.values, - dni_et, ephem_data['apparent_zenith'].values, - ephem_data['azimuth'].values, relative_airmass.values) + dni_et, ephem_data['apparent_zenith'].values, + ephem_data['azimuth'].values, + relative_airmass.values) expected = np.array( [ 0. , 31.46046871, np.nan, 45.45539877]) assert_allclose(out, expected, atol=1e-2) @@ -289,8 +297,8 @@ def test_sky_diffuse_zenith_close_to_90(model): def test_liujordan(): - expected = pd.DataFrame(np. - array([[863.859736967, 653.123094076, 220.65905025]]), + expected = pd.DataFrame(np.array( + [[863.859736967, 653.123094076, 220.65905025]]), columns=['ghi', 'dni', 'dhi'], index=[0]) out = irradiance.liujordan( @@ -484,7 +492,7 @@ def test_dirint_nans(): def test_dirint_tdew(): - times = pd.DatetimeIndex(['2014-06-24T12-0700','2014-06-24T18-0700']) + times = pd.DatetimeIndex(['2014-06-24T12-0700', '2014-06-24T18-0700']) ghi = pd.Series([1038.62, 254.53], index=times) zenith = pd.Series([10.567, 72.469], index=times) pressure = 93193. @@ -495,7 +503,7 @@ def test_dirint_tdew(): def test_dirint_no_delta_kt(): - times = pd.DatetimeIndex(['2014-06-24T12-0700','2014-06-24T18-0700']) + times = pd.DatetimeIndex(['2014-06-24T12-0700', '2014-06-24T18-0700']) ghi = pd.Series([1038.62, 254.53], index=times) zenith = pd.Series([10.567, 72.469], index=times) pressure = 93193. @@ -507,16 +515,16 @@ def test_dirint_no_delta_kt(): def test_dirint_coeffs(): coeffs = irradiance._get_dirint_coeffs() - assert coeffs[0,0,0,0] == 0.385230 - assert coeffs[0,1,2,1] == 0.229970 - assert coeffs[3,2,6,3] == 1.032260 + assert coeffs[0, 0, 0, 0] == 0.385230 + assert coeffs[0, 1, 2, 1] == 0.229970 + assert coeffs[3, 2, 6, 3] == 1.032260 def test_dirint_min_cos_zenith_max_zenith(): # map out behavior under difficult conditions with various # limiting kwargs settings # times don't have any physical relevance - times = pd.DatetimeIndex(['2014-06-24T12-0700','2014-06-24T18-0700']) + times = pd.DatetimeIndex(['2014-06-24T12-0700', '2014-06-24T18-0700']) ghi = pd.Series([0, 1], index=times) solar_zenith = pd.Series([90, 89.99], index=times) @@ -727,7 +735,7 @@ def test_dirindex_min_cos_zenith_max_zenith(): # map out behavior under difficult conditions with various # limiting kwargs settings # times don't have any physical relevance - times = pd.DatetimeIndex(['2014-06-24T12-0700','2014-06-24T18-0700']) + times = pd.DatetimeIndex(['2014-06-24T12-0700', '2014-06-24T18-0700']) ghi = pd.Series([0, 1], index=times) ghi_clearsky = pd.Series([0, 1], index=times) dni_clearsky = pd.Series([0, 5], index=times) diff --git a/pvlib/test/test_location.py b/pvlib/test/test_location.py index 534bf9887f..7381322121 100644 --- a/pvlib/test/test_location.py +++ b/pvlib/test/test_location.py @@ -19,15 +19,14 @@ from pvlib.location import Location from pvlib.solarposition import declination_spencer71 from pvlib.solarposition import equation_of_time_spencer71 -from test_solarposition import expected_solpos, golden_mst -from test_solarposition import golden - +from test_solarposition import expected_solpos, golden, golden_mst from conftest import requires_ephem, requires_scipy def test_location_required(): Location(32.2, -111) + def test_location_all(): Location(32.2, -111, 'US/Arizona', 700, 'Tucson') @@ -71,7 +70,7 @@ def test_location_print_pytz(): ' longitude: -111', ' altitude: 700', ' tz: US/Arizona' -]) + ]) assert tus.__str__() == expected_str @@ -212,7 +211,7 @@ def test_get_clearsky_simplified_solis_aod_pw(times): def test_get_clearsky_valueerror(times): tus = Location(32.2, -111, 'US/Arizona', 700, 'Tucson') with pytest.raises(ValueError): - clearsky = tus.get_clearsky(times, model='invalid_model') + tus.get_clearsky(times, model='invalid_model') def test_from_tmy_3(): @@ -275,7 +274,7 @@ def test_get_airmass(times): def test_get_airmass_valueerror(times): tus = Location(32.2, -111, 'US/Arizona', 700, 'Tucson') with pytest.raises(ValueError): - clearsky = tus.get_airmass(times, model='invalid_model') + tus.get_airmass(times, model='invalid_model') def test_Location___repr__(): @@ -288,7 +287,7 @@ def test_Location___repr__(): ' longitude: -111', ' altitude: 700', ' tz: US/Arizona' -]) + ]) assert tus.__repr__() == expected @@ -315,4 +314,4 @@ def test_get_sun_rise_set_transit_valueerror(golden): times = pd.DatetimeIndex(['2015-01-01 07:00:00', '2015-01-01 23:00:00'], tz='MST') with pytest.raises(ValueError): - result = golden.get_sun_rise_set_transit(times, method='eyeball') + golden.get_sun_rise_set_transit(times, method='eyeball') diff --git a/pvlib/test/test_modelchain.py b/pvlib/test/test_modelchain.py index 26761ebbcf..c15acf8bf6 100644 --- a/pvlib/test/test_modelchain.py +++ b/pvlib/test/test_modelchain.py @@ -7,7 +7,6 @@ import numpy as np import pandas as pd -from numpy import nan from pvlib import modelchain, pvsystem from pvlib.modelchain import ModelChain @@ -16,7 +15,7 @@ from pvlib.location import Location from pvlib._deprecation import pvlibDeprecationWarning -from pandas.util.testing import assert_series_equal, assert_frame_equal +from pandas.util.testing import assert_series_equal import pytest from test_pvsystem import sam_data, pvsyst_module_params @@ -164,7 +163,7 @@ def test_run_model(system, location): def test_run_model_with_irradiance(system, location): mc = ModelChain(system, location) times = pd.date_range('20160101 1200-0700', periods=2, freq='6H') - irradiance = pd.DataFrame({'dni':900, 'ghi':600, 'dhi':150}, + irradiance = pd.DataFrame({'dni': 900, 'ghi': 600, 'dhi': 150}, index=times) ac = mc.run_model(times, weather=irradiance).ac @@ -176,7 +175,7 @@ def test_run_model_with_irradiance(system, location): def test_run_model_perez(system, location): mc = ModelChain(system, location, transposition_model='perez') times = pd.date_range('20160101 1200-0700', periods=2, freq='6H') - irradiance = pd.DataFrame({'dni':900, 'ghi':600, 'dhi':150}, + irradiance = pd.DataFrame({'dni': 900, 'ghi': 600, 'dhi': 150}, index=times) ac = mc.run_model(times, weather=irradiance).ac @@ -189,7 +188,7 @@ def test_run_model_gueymard_perez(system, location): mc = ModelChain(system, location, airmass_model='gueymard1993', transposition_model='perez') times = pd.date_range('20160101 1200-0700', periods=2, freq='6H') - irradiance = pd.DataFrame({'dni':900, 'ghi':600, 'dhi':150}, + irradiance = pd.DataFrame({'dni': 900, 'ghi': 600, 'dhi': 150}, index=times) ac = mc.run_model(times, weather=irradiance).ac @@ -433,24 +432,24 @@ def test_losses_models_no_loss(pvwatts_dc_pvwatts_ac_system, location, weather, def test_invalid_dc_model_params(system, cec_dc_snl_ac_system, - pvwatts_dc_pvwatts_ac_system, location): + pvwatts_dc_pvwatts_ac_system, location): kwargs = {'dc_model': 'sapm', 'ac_model': 'snlinverter', 'aoi_model': 'no_loss', 'spectral_model': 'no_loss', 'temp_model': 'sapm', 'losses_model': 'no_loss'} - system.module_parameters.pop('A0') # remove a parameter + system.module_parameters.pop('A0') # remove a parameter with pytest.raises(ValueError): - mc = ModelChain(system, location, **kwargs) + ModelChain(system, location, **kwargs) kwargs['dc_model'] = 'singlediode' - cec_dc_snl_ac_system.module_parameters.pop('a_ref') # remove a parameter + cec_dc_snl_ac_system.module_parameters.pop('a_ref') # remove a parameter with pytest.raises(ValueError): - mc = ModelChain(cec_dc_snl_ac_system, location, **kwargs) + ModelChain(cec_dc_snl_ac_system, location, **kwargs) kwargs['dc_model'] = 'pvwatts' kwargs['ac_model'] = 'pvwatts' pvwatts_dc_pvwatts_ac_system.module_parameters.pop('pdc0') with pytest.raises(ValueError): - mc = ModelChain(pvwatts_dc_pvwatts_ac_system, location, **kwargs) + ModelChain(pvwatts_dc_pvwatts_ac_system, location, **kwargs) @pytest.mark.parametrize('model', [ @@ -463,7 +462,7 @@ def test_invalid_models(model, system, location): 'temp_model': 'sapm', 'losses_model': 'no_loss'} kwargs[model] = 'invalid' with pytest.raises(ValueError): - mc = ModelChain(system, location, **kwargs) + ModelChain(system, location, **kwargs) def test_bad_get_orientation(): @@ -480,10 +479,10 @@ def test_deprecated_07(): 'alpha_sc': 1, 'I_L_ref': 1, 'R_s': 1} system = PVSystem(module_parameters=module_parameters) with pytest.warns(pvlibDeprecationWarning): - mc = ModelChain(system, location, - dc_model='singlediode', # this should fail after 0.7 - aoi_model='no_loss', spectral_model='no_loss', - ac_model='snlinverter') + ModelChain(system, location, + dc_model='singlediode', # this should fail after 0.7 + aoi_model='no_loss', spectral_model='no_loss', + ac_model='snlinverter') @requires_scipy @@ -496,7 +495,8 @@ def test_basic_chain_required(sam_data): modules = sam_data['sandiamod'] module_parameters = modules['Canadian_Solar_CS5P_220M___2009_'] inverters = sam_data['cecinverter'] - inverter_parameters = inverters['ABB__MICRO_0_25_I_OUTD_US_208_208V__CEC_2014_'] + inverter_parameters = inverters[ + 'ABB__MICRO_0_25_I_OUTD_US_208_208V__CEC_2014_'] with pytest.raises(ValueError): dc, ac = modelchain.basic_chain(times, latitude, longitude, module_parameters, inverter_parameters, @@ -509,13 +509,13 @@ def test_basic_chain_alt_az(sam_data): end='20160101 1800-0700', freq='6H') latitude = 32.2 longitude = -111 - altitude = 700 surface_tilt = 0 surface_azimuth = 0 modules = sam_data['sandiamod'] module_parameters = modules['Canadian_Solar_CS5P_220M___2009_'] inverters = sam_data['cecinverter'] - inverter_parameters = inverters['ABB__MICRO_0_25_I_OUTD_US_208_208V__CEC_2014_'] + inverter_parameters = inverters[ + 'ABB__MICRO_0_25_I_OUTD_US_208_208V__CEC_2014_'] dc, ac = modelchain.basic_chain(times, latitude, longitude, module_parameters, inverter_parameters, @@ -537,12 +537,12 @@ def test_basic_chain_strategy(sam_data): modules = sam_data['sandiamod'] module_parameters = modules['Canadian_Solar_CS5P_220M___2009_'] inverters = sam_data['cecinverter'] - inverter_parameters = inverters['ABB__MICRO_0_25_I_OUTD_US_208_208V__CEC_2014_'] + inverter_parameters = inverters[ + 'ABB__MICRO_0_25_I_OUTD_US_208_208V__CEC_2014_'] - dc, ac = modelchain.basic_chain(times, latitude, longitude, - module_parameters, inverter_parameters, - orientation_strategy='south_at_latitude_tilt', - altitude=altitude) + dc, ac = modelchain.basic_chain( + times, latitude, longitude, module_parameters, inverter_parameters, + orientation_strategy='south_at_latitude_tilt', altitude=altitude) expected = pd.Series(np.array([ 183.522449305, -2.00000000e-02]), index=times) @@ -561,7 +561,8 @@ def test_basic_chain_altitude_pressure(sam_data): modules = sam_data['sandiamod'] module_parameters = modules['Canadian_Solar_CS5P_220M___2009_'] inverters = sam_data['cecinverter'] - inverter_parameters = inverters['ABB__MICRO_0_25_I_OUTD_US_208_208V__CEC_2014_'] + inverter_parameters = inverters[ + 'ABB__MICRO_0_25_I_OUTD_US_208_208V__CEC_2014_'] dc, ac = modelchain.basic_chain(times, latitude, longitude, module_parameters, inverter_parameters, @@ -616,7 +617,8 @@ def test_complete_irradiance_clean_run(system, location): """The DataFrame should not change if all columns are passed""" mc = ModelChain(system, location) times = pd.date_range('2010-07-05 9:00:00', periods=2, freq='H') - i = pd.DataFrame({'dni': [2, 3], 'dhi': [4, 6], 'ghi': [9, 5]}, index=times) + i = pd.DataFrame( + {'dni': [2, 3], 'dhi': [4, 6], 'ghi': [9, 5]}, index=times) mc.complete_irradiance(times, weather=i) @@ -637,12 +639,14 @@ def test_complete_irradiance(system, location): 'ghi': [372.103976116, 497.087579068], 'dhi': [356.543700, 465.44400]}, index=times) - mc.complete_irradiance(times, weather=i[['ghi', 'dni']]) + with pytest.warns(UserWarning): + mc.complete_irradiance(times, weather=i[['ghi', 'dni']]) assert_series_equal(mc.weather['dhi'], pd.Series([356.543700, 465.44400], index=times, name='dhi')) - mc.complete_irradiance(times, weather=i[['dhi', 'dni']]) + with pytest.warns(UserWarning): + mc.complete_irradiance(times, weather=i[['dhi', 'dni']]) assert_series_equal(mc.weather['ghi'], pd.Series([372.103976116, 497.087579068], index=times, name='ghi')) diff --git a/pvlib/test/test_solarposition.py b/pvlib/test/test_solarposition.py index 656e0ca0ee..4a8c142dff 100644 --- a/pvlib/test/test_solarposition.py +++ b/pvlib/test/test_solarposition.py @@ -1,11 +1,11 @@ import calendar import datetime +import warnings import numpy as np import pandas as pd -from pandas.util.testing import (assert_frame_equal, assert_series_equal, - assert_index_equal) +from pandas.util.testing import assert_frame_equal, assert_series_equal from numpy.testing import assert_allclose import pytest @@ -18,10 +18,10 @@ # setup times and locations to be tested. -times = pd.date_range(start=datetime.datetime(2014,6,24), - end=datetime.datetime(2014,6,26), freq='15Min') +times = pd.date_range(start=datetime.datetime(2014, 6, 24), + end=datetime.datetime(2014, 6, 26), freq='15Min') -tus = Location(32.2, -111, 'US/Arizona', 700) # no DST issues possible +tus = Location(32.2, -111, 'US/Arizona', 700) # no DST issues possible times_localized = times.tz_localize(tus.tz) tol = 5 @@ -58,7 +58,7 @@ def expected_solpos_multi(): 'apparent_zenith': [50.111622, 50.478260], 'azimuth': [194.340241, 194.311132], 'apparent_elevation': [39.888378, 39.521740]}, - index=[['2003-10-17T12:30:30Z', '2003-10-18T12:30:30Z']]) + index=['2003-10-17T12:30:30Z', '2003-10-18T12:30:30Z']) @pytest.fixture() @@ -126,7 +126,7 @@ def test_deprecated_07(): @requires_spa_c def test_spa_c_physical(expected_solpos, golden_mst): - times = pd.date_range(datetime.datetime(2003,10,17,12,30,30), + times = pd.date_range(datetime.datetime(2003, 10, 17, 12, 30, 30), periods=1, freq='D', tz=golden_mst.tz) ephem_data = solarposition.spa_c(times, golden_mst.latitude, golden_mst.longitude, @@ -138,7 +138,7 @@ def test_spa_c_physical(expected_solpos, golden_mst): @requires_spa_c def test_spa_c_physical_dst(expected_solpos, golden): - times = pd.date_range(datetime.datetime(2003,10,17,13,30,30), + times = pd.date_range(datetime.datetime(2003, 10, 17, 13, 30, 30), periods=1, freq='D', tz=golden.tz) ephem_data = solarposition.spa_c(times, golden.latitude, golden.longitude, @@ -149,7 +149,7 @@ def test_spa_c_physical_dst(expected_solpos, golden): def test_spa_python_numpy_physical(expected_solpos, golden_mst): - times = pd.date_range(datetime.datetime(2003,10,17,12,30,30), + times = pd.date_range(datetime.datetime(2003, 10, 17, 12, 30, 30), periods=1, freq='D', tz=golden_mst.tz) ephem_data = solarposition.spa_python(times, golden_mst.latitude, golden_mst.longitude, @@ -162,7 +162,7 @@ def test_spa_python_numpy_physical(expected_solpos, golden_mst): def test_spa_python_numpy_physical_dst(expected_solpos, golden): - times = pd.date_range(datetime.datetime(2003,10,17,13,30,30), + times = pd.date_range(datetime.datetime(2003, 10, 17, 13, 30, 30), periods=1, freq='D', tz=golden.tz) ephem_data = solarposition.spa_python(times, golden.latitude, golden.longitude, @@ -174,33 +174,6 @@ def test_spa_python_numpy_physical_dst(expected_solpos, golden): assert_frame_equal(expected_solpos, ephem_data[expected_solpos.columns]) -@requires_numba -def test_spa_python_numba_physical(expected_solpos, golden_mst): - times = pd.date_range(datetime.datetime(2003,10,17,12,30,30), - periods=1, freq='D', tz=golden_mst.tz) - ephem_data = solarposition.spa_python(times, golden_mst.latitude, - golden_mst.longitude, - pressure=82000, - temperature=11, delta_t=67, - atmos_refract=0.5667, - how='numba', numthreads=1) - expected_solpos.index = times - assert_frame_equal(expected_solpos, ephem_data[expected_solpos.columns]) - - -@requires_numba -def test_spa_python_numba_physical_dst(expected_solpos, golden): - times = pd.date_range(datetime.datetime(2003,10,17,13,30,30), - periods=1, freq='D', tz=golden.tz) - ephem_data = solarposition.spa_python(times, golden.latitude, - golden.longitude, pressure=82000, - temperature=11, delta_t=67, - atmos_refract=0.5667, - how='numba', numthreads=1) - expected_solpos.index = times - assert_frame_equal(expected_solpos, ephem_data[expected_solpos.columns]) - - @needs_pandas_0_17 def test_sun_rise_set_transit_spa(expected_rise_set_spa, golden): # solution from NREL SAP web calculator @@ -268,18 +241,18 @@ def test_sun_rise_set_transit_ephem(expected_rise_set_ephem, golden): expected = pd.DataFrame(index=times, columns=['sunrise', 'sunset'], dtype='datetime64[ns]') - expected['sunrise'] = pd.Series(index=times, data= - [expected_rise_set_ephem.loc[datetime.datetime(2015, 1, 2), 'sunrise'], + expected['sunrise'] = pd.Series(index=times, data=[ + expected_rise_set_ephem.loc[datetime.datetime(2015, 1, 2), 'sunrise'], expected_rise_set_ephem.loc[datetime.datetime(2015, 1, 3), 'sunrise'], expected_rise_set_ephem.loc[datetime.datetime(2015, 1, 3), 'sunrise'], expected_rise_set_ephem.loc[datetime.datetime(2015, 1, 3), 'sunrise']]) - expected['sunset'] = pd.Series(index=times, data= - [expected_rise_set_ephem.loc[datetime.datetime(2015, 1, 2), 'sunset'], + expected['sunset'] = pd.Series(index=times, data=[ + expected_rise_set_ephem.loc[datetime.datetime(2015, 1, 2), 'sunset'], expected_rise_set_ephem.loc[datetime.datetime(2015, 1, 2), 'sunset'], expected_rise_set_ephem.loc[datetime.datetime(2015, 1, 2), 'sunset'], expected_rise_set_ephem.loc[datetime.datetime(2015, 1, 3), 'sunset']]) - expected['transit'] = pd.Series(index=times, data= - [expected_rise_set_ephem.loc[datetime.datetime(2015, 1, 2), 'transit'], + expected['transit'] = pd.Series(index=times, data=[ + expected_rise_set_ephem.loc[datetime.datetime(2015, 1, 2), 'transit'], expected_rise_set_ephem.loc[datetime.datetime(2015, 1, 2), 'transit'], expected_rise_set_ephem.loc[datetime.datetime(2015, 1, 3), 'transit'], expected_rise_set_ephem.loc[datetime.datetime(2015, 1, 3), 'transit']]) @@ -307,23 +280,24 @@ def test_sun_rise_set_transit_ephem(expected_rise_set_ephem, golden): expected = pd.DataFrame(index=times, columns=['sunrise', 'sunset'], dtype='datetime64[ns]') - expected['sunrise'] = pd.Series(index=times, data= - [expected_rise_set_ephem.loc[datetime.datetime(2015, 1, 1), 'sunrise'], + expected['sunrise'] = pd.Series(index=times, data=[ + expected_rise_set_ephem.loc[datetime.datetime(2015, 1, 1), 'sunrise'], expected_rise_set_ephem.loc[datetime.datetime(2015, 1, 2), 'sunrise'], expected_rise_set_ephem.loc[datetime.datetime(2015, 1, 2), 'sunrise'], expected_rise_set_ephem.loc[datetime.datetime(2015, 1, 3), 'sunrise']]) - expected['sunset'] = pd.Series(index=times, data= - [expected_rise_set_ephem.loc[datetime.datetime(2015, 1, 1), 'sunset'], + expected['sunset'] = pd.Series(index=times, data=[ + expected_rise_set_ephem.loc[datetime.datetime(2015, 1, 1), 'sunset'], expected_rise_set_ephem.loc[datetime.datetime(2015, 1, 1), 'sunset'], expected_rise_set_ephem.loc[datetime.datetime(2015, 1, 2), 'sunset'], expected_rise_set_ephem.loc[datetime.datetime(2015, 1, 2), 'sunset']]) - expected['transit'] = pd.Series(index=times, data= - [expected_rise_set_ephem.loc[datetime.datetime(2015, 1, 1), 'transit'], + expected['transit'] = pd.Series(index=times, data=[ + expected_rise_set_ephem.loc[datetime.datetime(2015, 1, 1), 'transit'], expected_rise_set_ephem.loc[datetime.datetime(2015, 1, 1), 'transit'], expected_rise_set_ephem.loc[datetime.datetime(2015, 1, 2), 'transit'], expected_rise_set_ephem.loc[datetime.datetime(2015, 1, 3), 'transit']]) - result = solarposition.sun_rise_set_transit_ephem(times, + result = solarposition.sun_rise_set_transit_ephem( + times, golden.latitude, golden.longitude, next_or_previous='previous', altitude=golden.altitude, pressure=0, temperature=11, horizon='-0:34') # round to nearest minute @@ -337,7 +311,8 @@ def test_sun_rise_set_transit_ephem(expected_rise_set_ephem, golden): expected = expected.tz_convert('UTC') # resuse result from previous for col, data in expected.iteritems(): expected[col] = data.dt.tz_convert('UTC') - result = solarposition.sun_rise_set_transit_ephem(times, + result = solarposition.sun_rise_set_transit_ephem( + times, golden.latitude, golden.longitude, next_or_previous='previous', altitude=golden.altitude, pressure=0, temperature=11, horizon='-0:34') # round to nearest minute @@ -367,9 +342,11 @@ def test_sun_rise_set_transit_ephem_horizon(golden): times = pd.DatetimeIndex([datetime.datetime(2016, 1, 3, 0, 0, 0) ]).tz_localize('MST') # center of sun disk - center = solarposition.sun_rise_set_transit_ephem(times, + center = solarposition.sun_rise_set_transit_ephem( + times, latitude=golden.latitude, longitude=golden.longitude) - edge = solarposition.sun_rise_set_transit_ephem(times, + edge = solarposition.sun_rise_set_transit_ephem( + times, latitude=golden.latitude, longitude=golden.longitude, horizon='-0:34') result_rounded = (edge['sunrise'] - center['sunrise']).dt.round('min') @@ -383,7 +360,7 @@ def test_sun_rise_set_transit_ephem_horizon(golden): @requires_ephem def test_pyephem_physical(expected_solpos, golden_mst): - times = pd.date_range(datetime.datetime(2003,10,17,12,30,30), + times = pd.date_range(datetime.datetime(2003, 10, 17, 12, 30, 30), periods=1, freq='D', tz=golden_mst.tz) ephem_data = solarposition.pyephem(times, golden_mst.latitude, golden_mst.longitude, pressure=82000, @@ -395,8 +372,8 @@ def test_pyephem_physical(expected_solpos, golden_mst): @requires_ephem def test_pyephem_physical_dst(expected_solpos, golden): - times = pd.date_range(datetime.datetime(2003,10,17,13,30,30), periods=1, - freq='D', tz=golden.tz) + times = pd.date_range(datetime.datetime(2003, 10, 17, 13, 30, 30), + periods=1, freq='D', tz=golden.tz) ephem_data = solarposition.pyephem(times, golden.latitude, golden.longitude, pressure=82000, temperature=11) @@ -411,7 +388,7 @@ def test_calc_time(): import math # validation from USNO solar position calculator online - epoch = datetime.datetime(1970,1,1) + epoch = datetime.datetime(1970, 1, 1) epoch_dt = pytz.utc.localize(epoch) loc = tus @@ -427,21 +404,21 @@ def test_calc_time(): actual_timestamp = (actual_time - epoch_dt).total_seconds() assert_allclose((alt.replace(second=0, microsecond=0) - - epoch_dt).total_seconds(), actual_timestamp) + epoch_dt).total_seconds(), actual_timestamp) assert_allclose((az.replace(second=0, microsecond=0) - - epoch_dt).total_seconds(), actual_timestamp) + epoch_dt).total_seconds(), actual_timestamp) @requires_ephem def test_earthsun_distance(): - times = pd.date_range(datetime.datetime(2003,10,17,13,30,30), + times = pd.date_range(datetime.datetime(2003, 10, 17, 13, 30, 30), periods=1, freq='D') distance = solarposition.pyephem_earthsun_distance(times).values[0] assert_allclose(1, distance, atol=0.1) def test_ephemeris_physical(expected_solpos, golden_mst): - times = pd.date_range(datetime.datetime(2003,10,17,12,30,30), + times = pd.date_range(datetime.datetime(2003, 10, 17, 12, 30, 30), periods=1, freq='D', tz=golden_mst.tz) ephem_data = solarposition.ephemeris(times, golden_mst.latitude, golden_mst.longitude, @@ -454,7 +431,7 @@ def test_ephemeris_physical(expected_solpos, golden_mst): def test_ephemeris_physical_dst(expected_solpos, golden): - times = pd.date_range(datetime.datetime(2003,10,17,13,30,30), + times = pd.date_range(datetime.datetime(2003, 10, 17, 13, 30, 30), periods=1, freq='D', tz=golden.tz) ephem_data = solarposition.ephemeris(times, golden.latitude, golden.longitude, pressure=82000, @@ -466,7 +443,7 @@ def test_ephemeris_physical_dst(expected_solpos, golden): def test_ephemeris_physical_no_tz(expected_solpos, golden_mst): - times = pd.date_range(datetime.datetime(2003,10,17,19,30,30), + times = pd.date_range(datetime.datetime(2003, 10, 17, 19, 30, 30), periods=1, freq='D') ephem_data = solarposition.ephemeris(times, golden_mst.latitude, golden_mst.longitude, @@ -479,27 +456,27 @@ def test_ephemeris_physical_no_tz(expected_solpos, golden_mst): def test_get_solarposition_error(golden): - times = pd.date_range(datetime.datetime(2003,10,17,13,30,30), + times = pd.date_range(datetime.datetime(2003, 10, 17, 13, 30, 30), periods=1, freq='D', tz=golden.tz) with pytest.raises(ValueError): - ephem_data = solarposition.get_solarposition(times, golden.latitude, - golden.longitude, - pressure=82000, - temperature=11, - method='error this') + solarposition.get_solarposition(times, golden.latitude, + golden.longitude, + pressure=82000, + temperature=11, + method='error this') @pytest.mark.parametrize("pressure, expected", [ (82000, _expected_solpos_df()), (90000, pd.DataFrame( - np.array([[ 39.88997, 50.11003, 194.34024, 39.87205, 14.64151, - 50.12795]]), + np.array([[39.88997, 50.11003, 194.34024, 39.87205, 14.64151, + 50.12795]]), columns=['apparent_elevation', 'apparent_zenith', 'azimuth', 'elevation', 'equation_of_time', 'zenith'], index=['2003-10-17T12:30:30Z'])) ]) def test_get_solarposition_pressure(pressure, expected, golden): - times = pd.date_range(datetime.datetime(2003,10,17,13,30,30), + times = pd.date_range(datetime.datetime(2003, 10, 17, 13, 30, 30), periods=1, freq='D', tz=golden.tz) ephem_data = solarposition.get_solarposition(times, golden.latitude, golden.longitude, @@ -515,14 +492,14 @@ def test_get_solarposition_pressure(pressure, expected, golden): @pytest.mark.parametrize("altitude, expected", [ (1830.14, _expected_solpos_df()), (2000, pd.DataFrame( - np.array([[ 39.88788, 50.11212, 194.34024, 39.87205, 14.64151, - 50.12795]]), + np.array([[39.88788, 50.11212, 194.34024, 39.87205, 14.64151, + 50.12795]]), columns=['apparent_elevation', 'apparent_zenith', 'azimuth', 'elevation', 'equation_of_time', 'zenith'], index=['2003-10-17T12:30:30Z'])) ]) def test_get_solarposition_altitude(altitude, expected, golden): - times = pd.date_range(datetime.datetime(2003,10,17,13,30,30), + times = pd.date_range(datetime.datetime(2003, 10, 17, 13, 30, 30), periods=1, freq='D', tz=golden.tz) ephem_data = solarposition.get_solarposition(times, golden.latitude, golden.longitude, @@ -537,23 +514,26 @@ def test_get_solarposition_altitude(altitude, expected, golden): @pytest.mark.parametrize("delta_t, method", [ (None, 'nrel_numpy'), - (67.0, 'nrel_numpy'), pytest.param( None, 'nrel_numba', marks=[pytest.mark.xfail( reason='spa.calculate_deltat not implemented for numba yet')]), - (67.0, 'nrel_numba') + (67.0, 'nrel_numba'), + (67.0, 'nrel_numpy'), ]) def test_get_solarposition_deltat(delta_t, method, expected_solpos_multi, golden): - times = pd.date_range(datetime.datetime(2003,10,17,13,30,30), + times = pd.date_range(datetime.datetime(2003, 10, 17, 13, 30, 30), periods=2, freq='D', tz=golden.tz) - ephem_data = solarposition.get_solarposition(times, golden.latitude, - golden.longitude, - pressure=82000, - delta_t=delta_t, - temperature=11, - method=method) + with warnings.catch_warnings(): + # don't warn on method reload or num threads + warnings.simplefilter("ignore") + ephem_data = solarposition.get_solarposition(times, golden.latitude, + golden.longitude, + pressure=82000, + delta_t=delta_t, + temperature=11, + method=method) this_expected = expected_solpos_multi this_expected.index = times this_expected = np.round(this_expected, 5) @@ -562,7 +542,7 @@ def test_get_solarposition_deltat(delta_t, method, expected_solpos_multi, def test_get_solarposition_no_kwargs(expected_solpos, golden): - times = pd.date_range(datetime.datetime(2003,10,17,13,30,30), + times = pd.date_range(datetime.datetime(2003, 10, 17, 13, 30, 30), periods=1, freq='D', tz=golden.tz) ephem_data = solarposition.get_solarposition(times, golden.latitude, golden.longitude) @@ -587,7 +567,7 @@ def test_get_solarposition_method_pyephem(expected_solpos, golden): def test_nrel_earthsun_distance(): times = pd.DatetimeIndex([datetime.datetime(2015, 1, 2), - datetime.datetime(2015, 8, 2),] + datetime.datetime(2015, 8, 2)] ).tz_localize('MST') result = solarposition.nrel_earthsun_distance(times, delta_t=64.0) expected = pd.Series(np.array([0.983289204601, 1.01486146446]), @@ -772,3 +752,57 @@ def test_sun_rise_set_transit_geometric(expected_rise_set_spa, golden_mst): atol=np.abs(expected_sunset_error).max()) assert np.allclose(test_transit, expected_transit, atol=np.abs(expected_transit_error).max()) + + +# put numba tests at end of file to minimize reloading + +@requires_numba +def test_spa_python_numba_physical(expected_solpos, golden_mst): + times = pd.date_range(datetime.datetime(2003, 10, 17, 12, 30, 30), + periods=1, freq='D', tz=golden_mst.tz) + with warnings.catch_warnings(): + # don't warn on method reload or num threads + # ensure that numpy is the most recently used method so that + # we can use the warns filter below + warnings.simplefilter("ignore") + ephem_data = solarposition.spa_python(times, golden_mst.latitude, + golden_mst.longitude, + pressure=82000, + temperature=11, delta_t=67, + atmos_refract=0.5667, + how='numpy', numthreads=1) + with pytest.warns(UserWarning): + ephem_data = solarposition.spa_python(times, golden_mst.latitude, + golden_mst.longitude, + pressure=82000, + temperature=11, delta_t=67, + atmos_refract=0.5667, + how='numba', numthreads=1) + expected_solpos.index = times + assert_frame_equal(expected_solpos, ephem_data[expected_solpos.columns]) + + +@requires_numba +def test_spa_python_numba_physical_dst(expected_solpos, golden): + times = pd.date_range(datetime.datetime(2003, 10, 17, 13, 30, 30), + periods=1, freq='D', tz=golden.tz) + + with warnings.catch_warnings(): + # don't warn on method reload or num threads + warnings.simplefilter("ignore") + ephem_data = solarposition.spa_python(times, golden.latitude, + golden.longitude, pressure=82000, + temperature=11, delta_t=67, + atmos_refract=0.5667, + how='numba', numthreads=1) + expected_solpos.index = times + assert_frame_equal(expected_solpos, ephem_data[expected_solpos.columns]) + + with pytest.warns(UserWarning): + # test that we get a warning when reloading to use numpy only + ephem_data = solarposition.spa_python(times, golden.latitude, + golden.longitude, + pressure=82000, + temperature=11, delta_t=67, + atmos_refract=0.5667, + how='numpy', numthreads=1) diff --git a/pvlib/test/test_spa.py b/pvlib/test/test_spa.py index 467ef77d74..196acd72cb 100644 --- a/pvlib/test/test_spa.py +++ b/pvlib/test/test_spa.py @@ -1,5 +1,6 @@ import os import datetime as dt +import warnings try: from importlib import reload @@ -16,8 +17,6 @@ import unittest import pytest -from pvlib.location import Location - try: from numba import __version__ as numba_version @@ -37,7 +36,7 @@ pressure = 820 temp = 11 delta_t = 67.0 -atmos_refract= 0.5667 +atmos_refract = 0.5667 JD = 2452930.312847 JC = 0.0379277986858 @@ -77,7 +76,7 @@ theta0 = 90 - e0 Gamma = 14.340241 Phi = 194.340241 -year = 1985 +year = 1985 month = 2 year_array = np.array([-499, 500, 1000, 1500, 1800, 1860, 1900, 1950, 1970, 1985, 1990, 2000, 2005, 2050, 2150]) @@ -93,7 +92,8 @@ mix_year_array = np.full((10), year) mix_month_array = np.full((10), month) mix_year_actual = np.full((10), dt_actual) -mix_month_actual = mix_year_actual +mix_month_actual = mix_year_actual + class SpaBase(object): """Test functions common to numpy and numba spa""" @@ -107,8 +107,9 @@ def test_julian_day_dt(self): second = dt.second microsecond = dt.microsecond assert_almost_equal(JD, - self.spa.julian_day_dt(year, month, day, hour, - minute, second, microsecond), 6) + self.spa.julian_day_dt( + year, month, day, hour, + minute, second, microsecond), 6) def test_julian_ephemeris_day(self): assert_almost_equal(JDE, self.spa.julian_ephemeris_day(JD, delta_t), 5) @@ -153,13 +154,12 @@ def test_moon_ascending_longitude(self): assert_almost_equal(X4, self.spa.moon_ascending_longitude(JCE), 6) def test_longitude_nutation(self): - assert_almost_equal(dPsi, self.spa.longitude_nutation(JCE, X0, X1, X2, - X3, X4), 6) + assert_almost_equal(dPsi, self.spa.longitude_nutation( + JCE, X0, X1, X2, X3, X4), 6) def test_obliquity_nutation(self): - assert_almost_equal(dEpsilon, self.spa.obliquity_nutation(JCE, X0, X1, - X2, X3, X4), - 6) + assert_almost_equal(dEpsilon, self.spa.obliquity_nutation( + JCE, X0, X1, X2, X3, X4), 6) def test_mean_ecliptic_obliquity(self): assert_almost_equal(epsilon0, self.spa.mean_ecliptic_obliquity(JME), 6) @@ -199,21 +199,20 @@ def test_equatorial_horizontal_parallax(self): def test_parallax_sun_right_ascension(self): u = self.spa.uterm(lat) x = self.spa.xterm(u, lat, elev) - y = self.spa.yterm(u, lat, elev) assert_almost_equal(dAlpha, self.spa.parallax_sun_right_ascension( x, xi, H, delta), 4) def test_topocentric_sun_right_ascension(self): assert_almost_equal(alpha_prime, - self.spa.topocentric_sun_right_ascension( - alpha, dAlpha), 5) + self.spa.topocentric_sun_right_ascension( + alpha, dAlpha), 5) def test_topocentric_sun_declination(self): u = self.spa.uterm(lat) x = self.spa.xterm(u, lat, elev) y = self.spa.yterm(u, lat, elev) assert_almost_equal(delta_prime, self.spa.topocentric_sun_declination( - delta, x, y, xi, dAlpha,H), 5) + delta, x, y, xi, dAlpha, H), 5) def test_topocentric_local_hour_angle(self): assert_almost_equal(H_prime, self.spa.topocentric_local_hour_angle( @@ -242,14 +241,18 @@ def test_topocentric_azimuth_angle(self): assert_almost_equal(Phi, self.spa.topocentric_azimuth_angle(Gamma), 5) def test_solar_position(self): - assert_almost_equal( - np.array([[theta, theta0, e, e0, Phi]]).T, self.spa.solar_position( + with warnings.catch_warnings(): + # don't warn on method reload or num threads + warnings.simplefilter("ignore") + spa_out_0 = self.spa.solar_position( unixtimes, lat, lon, elev, pressure, temp, delta_t, - atmos_refract)[:-1], 5) - assert_almost_equal( - np.array([[v, alpha, delta]]).T, self.spa.solar_position( + atmos_refract)[:-1] + spa_out_1 = self.spa.solar_position( unixtimes, lat, lon, elev, pressure, temp, delta_t, - atmos_refract, sst=True)[:3], 5) + atmos_refract, sst=True)[:3] + assert_almost_equal(np.array([[theta, theta0, e, e0, Phi]]).T, + spa_out_0, 5) + assert_almost_equal(np.array([[v, alpha, delta]]).T, spa_out_1, 5) def test_equation_of_time(self): eot = 14.64 @@ -261,13 +264,16 @@ def test_transit_sunrise_sunset(self): # tests at greenwich times = pd.DatetimeIndex([dt.datetime(1996, 7, 5, 0), dt.datetime(2004, 12, 4, 0)] - ).tz_localize('UTC').astype(np.int64)*1.0/10**9 + ).tz_localize( + 'UTC').astype(np.int64)*1.0/10**9 sunrise = pd.DatetimeIndex([dt.datetime(1996, 7, 5, 7, 8, 15), dt.datetime(2004, 12, 4, 4, 38, 57)] - ).tz_localize('UTC').astype(np.int64)*1.0/10**9 + ).tz_localize( + 'UTC').astype(np.int64)*1.0/10**9 sunset = pd.DatetimeIndex([dt.datetime(1996, 7, 5, 17, 1, 4), dt.datetime(2004, 12, 4, 19, 2, 2)] - ).tz_localize('UTC').astype(np.int64)*1.0/10**9 + ).tz_localize( + 'UTC').astype(np.int64)*1.0/10**9 times = np.array(times) sunrise = np.array(sunrise) sunset = np.array(sunset) @@ -275,13 +281,15 @@ def test_transit_sunrise_sunset(self): assert_almost_equal(sunrise/1e3, result[1]/1e3, 3) assert_almost_equal(sunset/1e3, result[2]/1e3, 3) - - times = pd.DatetimeIndex([dt.datetime(1994, 1, 2),] - ).tz_localize('UTC').astype(np.int64)*1.0/10**9 - sunset = pd.DatetimeIndex([dt.datetime(1994, 1, 2, 16, 59, 55),] - ).tz_localize('UTC').astype(np.int64)*1.0/10**9 - sunrise = pd.DatetimeIndex([dt.datetime(1994, 1, 2, 7, 8, 12),] - ).tz_localize('UTC').astype(np.int64)*1.0/10**9 + times = pd.DatetimeIndex([dt.datetime(1994, 1, 2), ] + ).tz_localize( + 'UTC').astype(np.int64)*1.0/10**9 + sunset = pd.DatetimeIndex([dt.datetime(1994, 1, 2, 16, 59, 55), ] + ).tz_localize( + 'UTC').astype(np.int64)*1.0/10**9 + sunrise = pd.DatetimeIndex([dt.datetime(1994, 1, 2, 7, 8, 12), ] + ).tz_localize( + 'UTC').astype(np.int64)*1.0/10**9 times = np.array(times) sunrise = np.array(sunrise) sunset = np.array(sunset) @@ -294,18 +302,21 @@ def test_transit_sunrise_sunset(self): times = pd.DatetimeIndex([dt.datetime(2015, 1, 2), dt.datetime(2015, 4, 2), dt.datetime(2015, 8, 2), - dt.datetime(2015, 12, 2),], - ).tz_localize('UTC').astype(np.int64)*1.0/10**9 + dt.datetime(2015, 12, 2)], + ).tz_localize( + 'UTC').astype(np.int64)*1.0/10**9 sunrise = pd.DatetimeIndex([dt.datetime(2015, 1, 2, 7, 19), dt.datetime(2015, 4, 2, 5, 43), dt.datetime(2015, 8, 2, 5, 1), - dt.datetime(2015, 12, 2, 7, 1),], - ).tz_localize('MST').astype(np.int64)*1.0/10**9 + dt.datetime(2015, 12, 2, 7, 1)], + ).tz_localize( + 'MST').astype(np.int64)*1.0/10**9 sunset = pd.DatetimeIndex([dt.datetime(2015, 1, 2, 16, 49), dt.datetime(2015, 4, 2, 18, 24), dt.datetime(2015, 8, 2, 19, 10), - dt.datetime(2015, 12, 2, 16, 38),], - ).tz_localize('MST').astype(np.int64)*1.0/10**9 + dt.datetime(2015, 12, 2, 16, 38)], + ).tz_localize( + 'MST').astype(np.int64)*1.0/10**9 times = np.array(times) sunrise = np.array(sunrise) sunset = np.array(sunset) @@ -317,30 +328,32 @@ def test_transit_sunrise_sunset(self): times = pd.DatetimeIndex([dt.datetime(2015, 1, 2), dt.datetime(2015, 4, 2), dt.datetime(2015, 8, 2), - dt.datetime(2015, 12, 2),], - ).tz_localize('UTC').astype(np.int64)*1.0/10**9 + dt.datetime(2015, 12, 2)], + ).tz_localize( + 'UTC').astype(np.int64)*1.0/10**9 sunrise = pd.DatetimeIndex([dt.datetime(2015, 1, 2, 7, 36), dt.datetime(2015, 4, 2, 5, 58), dt.datetime(2015, 8, 2, 5, 13), - dt.datetime(2015, 12, 2, 7, 17),], - ).tz_localize('Asia/Shanghai' - ).astype(np.int64)*1.0/10**9 + dt.datetime(2015, 12, 2, 7, 17)], + ).tz_localize('Asia/Shanghai').astype( + np.int64)*1.0/10**9 sunset = pd.DatetimeIndex([dt.datetime(2015, 1, 2, 17, 0), dt.datetime(2015, 4, 2, 18, 39), dt.datetime(2015, 8, 2, 19, 28), - dt.datetime(2015, 12, 2, 16, 50),], - ).tz_localize('Asia/Shanghai' - ).astype(np.int64)*1.0/10**9 + dt.datetime(2015, 12, 2, 16, 50)], + ).tz_localize('Asia/Shanghai').astype( + np.int64)*1.0/10**9 times = np.array(times) sunrise = np.array(sunrise) sunset = np.array(sunset) - result = self.spa.transit_sunrise_sunset(times, 39.917, 116.383, 64.0,1) + result = self.spa.transit_sunrise_sunset( + times, 39.917, 116.383, 64.0, 1) assert_almost_equal(sunrise/1e3, result[1]/1e3, 1) assert_almost_equal(sunset/1e3, result[2]/1e3, 1) def test_earthsun_distance(self): times = (pd.date_range('2003-10-17 12:30:30', periods=1, freq='D') - .tz_localize('MST')) + .tz_localize('MST')) unixtimes = times.tz_convert('UTC').astype(np.int64)*1.0/10**9 unixtimes = np.array(unixtimes) result = self.spa.earthsun_distance(unixtimes, 64.0, 1) @@ -359,6 +372,7 @@ def test_calculate_deltat(self): result_scalar = self.spa.calculate_deltat(year, month) assert_almost_equal(dt_actual, result_scalar) + class NumpySpaTest(unittest.TestCase, SpaBase): """Import spa without compiling to numba then run tests""" @classmethod @@ -410,14 +424,12 @@ def test_solar_position_multithreaded(self): nresult = np.array([result, result, result]).T times = np.array([unixtimes[0], unixtimes[0], unixtimes[0]]) assert_almost_equal( - nresult - , self.spa.solar_position( + nresult, self.spa.solar_position( times, lat, lon, elev, pressure, temp, delta_t, - atmos_refract, numthreads=8)[:-1], 5) + atmos_refract, numthreads=3)[:-1], 5) result = np.array([v, alpha, delta]) nresult = np.array([result, result, result]).T assert_almost_equal( - nresult - , self.spa.solar_position( + nresult, self.spa.solar_position( times, lat, lon, elev, pressure, temp, delta_t, - atmos_refract, numthreads=8, sst=True)[:3], 5) + atmos_refract, numthreads=3, sst=True)[:3], 5) diff --git a/pvlib/test/test_tracking.py b/pvlib/test/test_tracking.py index 872076eb9d..8ab8032831 100644 --- a/pvlib/test/test_tracking.py +++ b/pvlib/test/test_tracking.py @@ -397,8 +397,15 @@ def test_get_irradiance(): backtrack=True) times = pd.date_range(start='20160101 1200-0700', end='20160101 1800-0700', freq='6H') - location = Location(latitude=32, longitude=-111) - solar_position = location.get_solarposition(times) + # latitude=32, longitude=-111 + solar_position = pd.DataFrame(np.array( + [[55.36421554, 55.38851771, 34.63578446, 34.61148229, + 172.32003763, -3.44516534], + [96.50000401, 96.50000401, -6.50000401, -6.50000401, + 246.91581654, -3.56292888]]), + columns=['apparent_zenith', 'zenith', 'apparent_elevation', + 'elevation', 'azimuth', 'equation_of_time'], + index=times) irrads = pd.DataFrame({'dni': [900, 0], 'ghi': [600, 0], 'dhi': [100, 0]}, index=times) solar_zenith = solar_position['apparent_zenith']