AttributeError: 'PVSystem' object has no attribute 'racking_model'

94 views
Skip to first unread message

Tycho Melles

unread,
Sep 14, 2023, 4:01:04 PM9/14/23
to pvlib-python

Hi everyone,

While using pvlib/feedinlib for my Master thesis, I am running into an error that I cannot seem to figure out, which is the following:

AttributeError: 'PVSystem' object has no attribute 'racking_model'

I have added my full code at the bottom of this post (mostly copied from several examples). After reading the pvlib documentation, I believe 'racking_model' should be one of the attributes/parameters of PVSystem and should even have a default value. I tried everything I can think of and even took a look at the source code, which where the issue seems to 'occur', but did not get any further.

What I have figured out is that the code is working fine up until the point where the irradiation in the considered coordinate is plotted. The problem seems to be in the part where the feedin is calculated (without this not errors occur).

Does anyone know where this error might be coming from? Any help would be greatly appreciated!


from feedinlib import era5
import cdsapi
import matplotlib.pyplot as plt
import pvlib
from feedinlib import Photovoltaic
from feedinlib import get_power_plant_data
from shapely.geometry import Point
from pvlib import pvsystem


# get modules
module_df = get_power_plant_data(dataset='SandiaMod')
# print the first four modules
module_df.iloc[:, 1:5]

# get inverter data
inverter_df = get_power_plant_data(dataset='cecinverter')
# print the first four inverters
inverter_df.iloc[:, 1:5]

system_data = {
    'module_name': 'Advent_Solar_Ventura_210___2008_',  # module name as in database
    'inverter_name': 'ABB__MICRO_0_25_I_OUTD_US_208__208V_',  # inverter name as in database
    'azimuth': 180,
    'tilt': 30,
    'albedo': 0.2,
    }
pv_system = Photovoltaic(**system_data) #pvsystem.PVSystem(surface_tilt=30,surface_azimuth=90)


latitude = 52.4
longitude = 13.5
#location = Point(longitude,latitude)

# set start and end date (end date will be included
# in the time period for which data is downloaded)
start_date, end_date = '2015-01-01', '2015-02-01'
# set variable set to download
variable = 'pvlib'

era5_netcdf_filename = 'ERA5_weather_data.nc'

area = [longitude, latitude] #location of production

pvlib_df = era5.weather_df_from_era5(
    era5_netcdf_filename='ERA5_weather_data.nc',
    lib='pvlib', area=area)

#matplotlib inline
pvlib_df.loc[:, ['dhi', 'ghi']].plot(title='Irradiance')
plt.xlabel('Time')
plt.ylabel('Irradiance in $W/m^2$');


feedin = pv_system.feedin(
    weather=pvlib_df,
    location=(latitude, longitude))


#matplotlib inline
feedin.plot(title='PV feed-in')
plt.xlabel('Time')
plt.ylabel('Power in W');

cwh...@sandia.gov

unread,
Sep 14, 2023, 4:31:52 PM9/14/23
to pvlib-python
To get past the error, I _think_ you can add 'racking_model': 'open_rack' to system_data.

This looks like a bit of a disconnect between pvlib's PVSystem documentation and the behavior when 'racking_model' is omitted.

Cliff

Tycho Melles

unread,
Sep 14, 2023, 5:07:24 PM9/14/23
to pvlib-python
Hi Cliff,

Thank you for your quick response! Unfortunately, I had already tried that and it did not work for me. 

Just to be sure, I have tried the code with the adjustment you mentioned again and I added it below, but it keeps giving me the same error.

from feedinlib import era5
import cdsapi
import matplotlib.pyplot as plt
import pvlib
from feedinlib import Photovoltaic
from feedinlib import get_power_plant_data
from shapely.geometry import Point
from pvlib import pvsystem


# get modules
module_df = get_power_plant_data(dataset='SandiaMod')
# print the first four modules
module_df.iloc[:, 1:5]

# get inverter data
inverter_df = get_power_plant_data(dataset='cecinverter')
# print the first four inverters
inverter_df.iloc[:, 1:5]

system_data = {
    'module_name': 'Advent_Solar_Ventura_210___2008_',  # module name as in database
    'inverter_name': 'ABB__MICRO_0_25_I_OUTD_US_208__208V_',  # inverter name as in database
    'azimuth': 180,
    'tilt': 30,
    'albedo': 0.2,
    'racking_model': 'open_rack'
Op donderdag 14 september 2023 om 22:31:52 UTC+2 schreef cwh...@sandia.gov:

cwh...@sandia.gov

unread,
Sep 14, 2023, 5:31:28 PM9/14/23
to pvlib-python
What versions of pvlib and feedinlib are you using?

Tycho Melles

unread,
Sep 15, 2023, 3:27:42 AM9/15/23
to pvlib-python
Thank you again for your quick response!

For pvlib I am using version 0.10.1

For feedinlib I think I am using version 0.1.0rc4 (I'm not sure how to check that one but when I just try to reinstall feedinlib it tells me the following: "Requirement already satisfied: feedinlib in c:\users\tmell\appdata\roaming\python\python38\site-packages (0.1.0rc4)")

Lastly, I am using Python 3.7

Op donderdag 14 september 2023 om 23:31:28 UTC+2 schreef cwh...@sandia.gov:

cwh...@sandia.gov

unread,
Sep 15, 2023, 10:58:56 AM9/15/23
to pvlib-python
Those are the latest versions. 

When I run your code I get a different error, 

ImportError: cannot import name 'era5' from 'feedinlib'

Could be something amiss in my environment. Is feedinlib installed as a package, or is it being used from a working folder?

If you can post code that I can use to reproduce the 'racking_model' error, I can help debug.

Tycho Melles

unread,
Sep 15, 2023, 12:49:23 PM9/15/23
to pvlib-python
I think the error you are seeing might be caused by not having the latest version of feedinlib installed; when I for example install/use version 0.0.12 of feedinlib, I get that error as well. Maybe importing era5 data has only been implemented in the latest version(s)?

When I then install version 0.1.0rc4 of feedinlib again, the ImportError (that you are seeing as well) is gone and I get the AttributeError regarding the 'racking_model' again. Is it possible that your environment does not have the latest version of feedinlib installed? And if so, do you get the same error as me with the latest version of feedinlib?

I installed feedinlib (and pvlib) using 'pip install'. I believe that means it is installed as a package (but my technical knowledge of Python is lacking there a little bit).
Op vrijdag 15 september 2023 om 16:58:56 UTC+2 schreef cwh...@sandia.gov:

kevina...@gmail.com

unread,
Sep 15, 2023, 1:47:46 PM9/15/23
to pvlib-python

I think adding a key for "temperature_model_parameters" to the system_data dict is needed.  For example:

temp_params = pvlib.temperature.TEMPERATURE_MODEL_PARAMETERS['sapm']['open_rack_glass_polymer']


system_data = {
    'module_name': 'Advent_Solar_Ventura_210___2008_',  # module name as in database
    'inverter_name': 'ABB__MICRO_0_25_I_OUTD_US_208__208V_',  # inverter name as in database
    'azimuth': 180,
    'tilt': 30,
    'albedo': 0.2,
    'temperature_model_parameters': temp_params,
}

However, then you will run into an error "AttributeError: 'ModelChain' object has no attribute 'ac'".  To fix this I think feedinlib needs to update their code to be compatible with the latest version of pvlib.  Until then you can downgrade to pvlib 0.9.5 (pip install pvlib==0.9.5), which I think will get it working.

Tycho, perhaps you could make those suggestions (update documentation to use temperature_model_parameters; change to using ModelChain.results.ac instead of ModelChain.ac), to the feedinlib folks?

Kevin

Tycho Melles

unread,
Sep 16, 2023, 7:59:17 AM9/16/23
to pvlib-python
Hi Kevin,

Thank you very much for your help!

Adding the temperature_model_ parameters did indeed solve the racking_model error!

The model now however did not yet show the error you predicted. Instead, I got the following error:

"ValueError: Incomplete input data. Data needs to contain ['ghi', 'dni', 'dhi']. Detected data contains: ['wind_speed', 'temp_air', 'ghi', 'dhi']"

The data that is referred to is retrieved from ERA5 using feedinlib with the following code:

"
from feedinlib import era5


latitude = 52.4
longitude = 13.5

# set start and end date (end date will be included
# in the time period for which data is downloaded)
start_date, end_date = '2015-01-01', '2015-02-01'
# set variable set to download
variable = "pvlib"

target_file = 'ERA5_weather_data.nc'

# get pvlib data for specified location
ds = era5.get_era5_data_from_datespan_and_position(
    variable=variable,
    start_date=start_date, end_date=end_date,
    latitude=latitude, longitude=longitude,
    target_file=target_file)
"

This gives me the wind speed, air temperature, dhi and ghi, but not the dni, which is apparently needed as well (although in the feedinlib documentation they also seem to only have ghi and dhi). I was able to solve this error by adding the following to my code to estimate the dni:

"
.
.
.
pvlib_df = era5.weather_df_from_era5(
    era5_netcdf_filename='ERA5_weather_data.nc',
    lib='pvlib', area=area)

dni = pvlib.irradiance.dni(pvlib_df['ghi'],pvlib_df['dhi'], zenith=80, clearsky_dni=None, clearsky_tolerance=1.1, zenith_threshold_for_zero_dni=88.0, zenith_threshold_for_clearsky_limit=80.0)

pvlib_df['dni'] = dni


#matplotlib inline
pvlib_df.loc[:, ['dhi', 'ghi']].plot(title='Irradiance')
plt.xlabel('Time')
plt.ylabel('Irradiance in $W/m^2$');
"

I am however not sure if this is the easiest (or even correct) way to obtain the dni and I also wasn't sure what to do with the zenith angle, as this is also not retrieved from ERA5 at the moment. Do you know if it is possible to get the dni directly from ERA5 as well or atleast avoid having to calculate this seperately (in the feedinlib documentation they do not seem to do this, but for some reason it seems necessary now)?

After this, I got the error "AttributeError: 'ModelChain' object has no attribute 'ac'" as you predicted, which was indeed solved by installing pvlib version 0.9.5.

Then however I got another error: "NameError: name 'spectrum' is not defined". I can imagine this might be caused by the dni estimation I added. I tried to solve this by adding 'from pvlib import spectrum', which does not give me an additional error (so the import should be working), but for some reason does not solve the error.

Do you maybe have a suggestion how I could solve the missing dni data error in a better way (which I believe would also solve the other error)?

Op vrijdag 15 september 2023 om 19:47:46 UTC+2 schreef kevina...@gmail.com:

Tycho Melles

unread,
Sep 18, 2023, 8:40:36 AM9/18/23
to pvlib-python
Hi Kevin and Cliff,

I looked at it again today and for some reason, the error  "NameError: name 'spectrum' is not defined" disappeared. The code that I added at the bottom of this message is now running properly without any errors. To me, the results seem to make sense at first sight.

The determining of the DNI seems to be working correctly. The only thing I am still figuring out is what to input for the zenith angle in the irradiance function used to determine the DNI, but I think I have found a solution for that using the function 'pvlib.solarposition.get_solarposition' (I just have to figure out how to input the correct times, so it is not included yet in the code below).

Thank you both again for your help in starting my work with pvlib!

@Kevin I will try to see if I can contact the feedinlib people to make them aware of the issue I encountered.

Kind regards,
Tycho

from feedinlib import era5
import cdsapi
import matplotlib.pyplot as plt
import pvlib
from feedinlib import Photovoltaic
from feedinlib import get_power_plant_data
from shapely.geometry import Point
from pvlib import pvsystem
from pvlib import spectrum



# get modules
module_df = get_power_plant_data(dataset='SandiaMod')
# print the first four modules
module_df.iloc[:, 1:5]

# get inverter data
inverter_df = get_power_plant_data(dataset='cecinverter')
# print the first four inverters
inverter_df.iloc[:, 1:5]

temp_params = pvlib.temperature.TEMPERATURE_MODEL_PARAMETERS['sapm']['open_rack_glass_polymer']


system_data = {
    'module_name': 'Advent_Solar_Ventura_210___2008_',  # module name as in database
    'inverter_name': 'ABB__MICRO_0_25_I_OUTD_US_208__208V_',  # inverter name as in database
    'azimuth': 180,
    'tilt': 30,
    'albedo': 0.2,
    'temperature_model_parameters': temp_params,
}
pv_system = Photovoltaic(**system_data) #pvsystem.PVSystem(surface_tilt=30,surface_azimuth=90)

system = Photovoltaic(**system_data)

latitude = 13.5
longitude = 52.4

#location = Point(longitude,latitude)

# set start and end date (end date will be included
# in the time period for which data is downloaded)
start_date, end_date = '2015-01-01', '2015-02-01'
# set variable set to download
variable = 'feedinlib'


era5_netcdf_filename = 'ERA5_weather_data.nc'

area = [longitude, latitude] #location of production

pvlib_df = era5.weather_df_from_era5(
    era5_netcdf_filename='ERA5_weather_data.nc',
    lib='pvlib', area=area)

dni = pvlib.irradiance.dni(pvlib_df['ghi'],pvlib_df['dhi'], zenith=80, clearsky_dni=None, clearsky_tolerance=1.1, zenith_threshold_for_zero_dni=88.0, zenith_threshold_for_clearsky_limit=80.0)

pvlib_df['dni'] = dni

#matplotlib inline
plt.figure

pvlib_df.loc[:, ['dhi', 'ghi']].plot(title='Irradiance')
plt.xlabel('Time')
plt.ylabel('Irradiance in $W/m^2$');


feedin = system.feedin(

    weather=pvlib_df,
    location=(latitude, longitude))


#matplotlib inline
plt.figure()

feedin.plot(title='PV feed-in')
plt.xlabel('Time')
plt.ylabel('Power in W');

Op zaterdag 16 september 2023 om 13:59:17 UTC+2 schreef Tycho Melles:

kevina...@gmail.com

unread,
Sep 18, 2023, 8:58:16 AM9/18/23
to pvlib-python
Well done figuring out how to determine DNI from the other two irradiance variables.  For the zenith angle question, indeed using `pvlib.solarposition.get_solarposition()` is appropriate (assuming that the ERA5 data doesn't have solar position already).  For the times to pass in, I'd expect the `pvlib_df` dataframe to have a datetime index that would be suitable, so perhaps you can pass in `pvlib_df.index` for the times.  I'm not able to test that myself at the moment.  Check that the solar positions are aligned in time with the irradiance data (e.g. sunrise in the solar position is the same as sunrise in the irradiance).  If they are misaligned, then check that the timestamps are timezone-localized correctly (https://pvlib-python.readthedocs.io/en/stable/user_guide/timetimezones.html).

It's just speculation, but perhaps the "name error: spectrum is not defined" issue may have been due to using an interactive python session that didn't get restarted after installing the different version of pvlib.  Making changes to the python environment without restarting the python session is a good way to get strange issues that go away after you do start a new session.

Kevin

Tycho Melles

unread,
Sep 18, 2023, 2:22:35 PM9/18/23
to pvlib-python
Hi Kevin,

I was having some trouble extracting the dates from pvlib_df as the date is not really seen as a column of the dataframe, but 'pvlib_df.index' is exactly what I needed, thank you!

Tycho

Op maandag 18 september 2023 om 14:58:16 UTC+2 schreef kevina...@gmail.com:
Reply all
Reply to author
Forward
0 new messages