0

I have recently downloaded the Anaconda Distribution 2.0.4 along with the PVLIB 0.81 for utilization with Spyder 4.2.5. I tried to run the procedural code example from Intro Tutorial (https://pvlib-python.readthedocs.io/en/stable/introtutorial.html#), but at the line where pvlib.inverter.sandia() is called, I get the error:

AttributeError: module 'pvlib' has no attribute 'inverter'

I utilized the dir command and the mentioned attribute is missing. Tried installation of PVLIB by two ways:

conda install -c pvlib pvlib

conda create -n pvlib -c conda-forge pvlib-python; conda activate pvlib

Yet the error remains. Could it be that the attribute was removed from the latest version of PVLIB? In that case, what would the alternative structure be, for the current version of PVLIB?


import matplotlib.pyplot as plt

naive_times = pd.date_range(start='2015', end='2016', freq='1h')



coordinates = [(30, -110, 'Tucson', 700, 'Etc/GMT+7'),
               (35, -105, 'Albuquerque', 1500, 'Etc/GMT+7'),
               (40, -120, 'San Francisco', 10, 'Etc/GMT+8'),
               (50, 10, 'Berlin', 34, 'Etc/GMT-1')]


import pvlib


sandia_modules = pvlib.pvsystem.retrieve_sam('SandiaMod')

sapm_inverters = pvlib.pvsystem.retrieve_sam('cecinverter')

module = sandia_modules['Canadian_Solar_CS5P_220M___2009_']

inverter = sapm_inverters['ABB__MICRO_0_25_I_OUTD_US_208__208V_']

temperature_model_parameters = pvlib.temperature.TEMPERATURE_MODEL_PARAMETERS['sapm']['open_rack_glass_glass']


temp_air = 20

wind_speed = 0

system = {'module': module, 'inverter': inverter,
          'surface_azimuth': 180}


energies = {}

for latitude, longitude, name, altitude, timezone in coordinates:
    times = naive_times.tz_localize(timezone)
    system['surface_tilt'] = latitude
    solpos = pvlib.solarposition.get_solarposition(times, latitude, longitude)
    dni_extra = pvlib.irradiance.get_extra_radiation(times)
    airmass = pvlib.atmosphere.get_relative_airmass(solpos['apparent_zenith'])
    pressure = pvlib.atmosphere.alt2pres(altitude)
    am_abs = pvlib.atmosphere.get_absolute_airmass(airmass, pressure)
    tl = pvlib.clearsky.lookup_linke_turbidity(times, latitude, longitude)
    cs = pvlib.clearsky.ineichen(solpos['apparent_zenith'], am_abs, tl,
                                 dni_extra=dni_extra, altitude=altitude)
    aoi = pvlib.irradiance.aoi(system['surface_tilt'], system['surface_azimuth'],
                               solpos['apparent_zenith'], solpos['azimuth'])
    total_irrad = pvlib.irradiance.get_total_irradiance(system['surface_tilt'],
                                                        system['surface_azimuth'],
                                                        solpos['apparent_zenith'],
                                                        solpos['azimuth'],
                                                        cs['dni'], cs['ghi'], cs['dhi'],
                                                        dni_extra=dni_extra,
                                                        model='haydavies')
    tcell = pvlib.temperature.sapm_cell(total_irrad['poa_global'],
                                        temp_air, wind_speed,
                                        **temperature_model_parameters)
    effective_irradiance = pvlib.pvsystem.sapm_effective_irradiance(
        total_irrad['poa_direct'], total_irrad['poa_diffuse'],
        am_abs, aoi, module)
    dc = pvlib.pvsystem.sapm(effective_irradiance, tcell, module)
    ac = pvlib.inverter.sandia(dc['v_mp'], dc['p_mp'], inverter)
    annual_energy = ac.sum()
    energies[name] = annual_energy


energies = pd.Series(energies)


print(energies.round(0))






energies.plot(kind='bar', rot=0)


plt.ylabel('Yearly energy yield (W hr)')
  • 1
    The code runs for me. You could check `pvlib.__version__` and also post more detail from the error message and your debugging. – adr Aug 04 '21 at 11:29
  • Checked `pvlib.__version__` and it actually showed version 0.7.2 for PVLIB. Uninstalled it and used `pip install pvlib[optional]`, and now the code is working. Thanks for the help, I'm transitioning from MATLAB to Python and you helped me very much. – Arthur Dias Aug 04 '21 at 14:36

1 Answers1

0

Could it be that the attribute was removed from the latest version of PVLIB?

No, the inverter module is still a part of pvlib as you can see in the pvlib.inverter.sandia() documentation and the source code for pvlib/inverter.py on GitHub

The code snippet you pasted above is working in this Colaboratory notebook. I'm sorry, I can only guess what might be the problem. What I find sometimes helps is to start with a fresh, clean new virtual or conda environment, install pvlib and Jupyter, and then try to execute this code snippet from a new Jupyter notebook. If you still have the issue, upload the Jupyter notebook to a GitHub Gist and paste a link to it here.

Mark Mikofski
  • 19,398
  • 2
  • 57
  • 90