Search code examples
pythonpandastimestampdatetimeindexpvlib

pvlib - bifacial.pvfactors_timeseries() ValueError: Buffer has wrong number of dimensions (expected 1, got 2)


I'm working with pvlib/pvfactors bifacial.pvfactors_timeseries and I'm having some issues with the timestamps. I use a DatetimeIndex as it can be seen:

times = pd.date_range('2021-01-01', '2021-01-02', closed='left', freq='1min',
                  tz=None)
rear_rad=bifacial.pvfactors_timeseries(
solar_azimuth=235.7,
solar_zenith=75.6,
surface_azimuth=270.0, #cte
surface_tilt=-72.8, #tracker
axis_azimuth=180.0, #cte
timestamps=times,
dni=29.0,
dhi=275.0,
gcr=0.2,
pvrow_height=2.0,
pvrow_width=2.0,
albedo=0.2, #variable mensual
n_pvrows=3,
index_observed_pvrow=1,
rho_front_pvrow=0.03, #reflectividad
rho_back_pvrow=0.05, #refletividad
horizon_band_angle=15.0)

I always end up having this Error:

ValueError: Buffer has wrong number of dimensions (expected 1, got 2)

The full traceback of the error is:

File "****", line 18, in rear_rad=bifacial.pvfactors_timeseries(

File "C:\Users\tomas.rodriguez\Anaconda3\lib\site-packages\pvlib\bifacial.py", line 141, in pvfactors_timeseries report = run_timeseries_engine(

File "C:\Users\tomas.rodriguez\Anaconda3\lib\site-packages\pvfactors\run.py", line 106, in run_timeseries_engine eng.fit(timestamps, dni, dhi, solar_zenith, solar_azimuth, surface_tilt,

File "C:\Users\tomas.rodriguez\Anaconda3\lib\site-packages\pvfactors\engine.py", line 161, in fit self.irradiance.fit(timestamps, DNI, DHI, solar_zenith, solar_azimuth,

File "C:\Users\tomas.rodriguez\Anaconda3\lib\site-packages\pvfactors\irradiance\models.py", line 527, in fit self._calculate_luminance_poa_components(

File "C:\Users\tomas.rodriguez\Anaconda3\lib\site-packages\pvfactors\irradiance\models.py", line 993, in _calculate_luminance_poa_components df_inputs = perez_diffuse_luminance(

File "C:\Users\tomas.rodriguez\Anaconda3\lib\site-packages\pvfactors\irradiance\utils.py", line 63, in perez_diffuse_luminance dni_et = irradiance.get_extra_radiation(df_inputs.index.dayofyear)

File "C:\Users\tomas.rodriguez\Anaconda3\lib\site-packages\pandas\core\indexes\extension.py", line 81, in fget result = getattr(self._data, name)

File "C:\Users\tomas.rodriguez\Anaconda3\lib\site-packages\pandas\core\arrays\datetimes.py", line 139, in f result = fields.get_date_field(values, field)

File "pandas_libs\tslibs\fields.pyx", line 305, in pandas._libs.tslibs.fields.get_date_field

ValueError: Buffer has wrong number of dimensions (expected 1, got 2)


Solution

  • The problem is that some of the parameters to pvfactors_timeseries need to be arrays, Series, etc, not scalars like you are using. This usability issue has already been noticed should be fixed in the next pvlib release (0.9.1, not yet released); see https://github.com/pvlib/pvlib-python/issues/1332

    This modified version of your code runs without error:

    rear_rad = bifacial.pvfactors_timeseries(
        solar_azimuth=pd.Series(235.7, times),
        solar_zenith=pd.Series(75.6, times),
        surface_azimuth=pd.Series(270.0, times), #cte
        surface_tilt=pd.Series(-72.8, times), #tracker
        axis_azimuth=180.0, #cte
        timestamps=times,
        dni=pd.Series(29.0, times),
        dhi=pd.Series(275.0, times),
        gcr=0.2,
        pvrow_height=2.0,
        pvrow_width=2.0,
        albedo=0.2, #variable mensual
        n_pvrows=3,
        index_observed_pvrow=1,
        rho_front_pvrow=0.03, #reflectividad
        rho_back_pvrow=0.05, #refletividad
        horizon_band_angle=15.0,
     )
    

    One other thing: pvlib expects surface_tilt to be non-negative, and I'm not sure what the function will return for a negative surface_tilt. Note that, in the pvlib convention, a tracker rotation can be positive or negative to indicate whether it is a tilt to the east or west, but surface_tilt is always positive (or zero) and the east/west direction is represented by surface_azimuth.

    P.S. it is good practice, when things aren't working like you expect, it is good practice to mention the package version you have installed (see print(pvlib.__version__) or pip show pvlib). Sometimes things change between versions and the answer depends on what version you are using.