2

I am using a library called pvmismatch which measures the impact of imperfect shading on solar cells, which I think will soon be compatible with pvlib. I am not sure if this is a question related to python in general or just the library, but probably the former.

I would like to create a function which takes in a list of "shadings" which uses "setSuns" and also the indices of which cells are to be shaded. My code is below:

def shade_into_powers(shades_list = [], temperatures_list = [], cells_list = []):
    length_of_lists = len(shades_list)
    list_of_powers = []
    for i in range(0, length_of_lists):
        my_module_shaded.setSuns(Ee = shades_list[i], cells = cells_list[i])
        my_module_shaded.setTemps(Tc=temperatures_list[i], cells= cells_list[i])
        list_of_powers[i] = my_module_shaded.pvcells[i].Igen*max(my_module_shaded.pvcells[i].Vcell)
    return list_of_powers

I later tried to try out this function as below:

shadez = [0.43, 0.43, 0.43]
tempez = [88, 81, 77]
cellz = [30, 31, 32]
powers_listed = shade_into_powers(shadez, tempez, cellz)

The error I get is "object of type 'int' is not iterable". What am I doing wrong here?

All help appreciated.

The below is the TraceBack:

Traceback (most recent call last):
  File "/home/abed/.config/JetBrains/PyCharmCE2020.2/scratches/scratch_2.py", line 176, in <module>
    powers_listed = shade_into_powers(shadez, tempez, cellz)
  File "/home/abed/.config/JetBrains/PyCharmCE2020.2/scratches/scratch_2.py", line 168, in shade_into_powers
    my_module_shaded.setSuns(Ee = shades_list[i], cells = cells_list[i])
  File "/home/abed/.local/lib/python3.7/site-packages/pvmismatch/pvmismatch_lib/pvmodule.py", line 323, in setSuns
    cells_to_update = [self.pvcells[i] for i in cells]
TypeError: 'int' object is not iterable

Abed
  • 183
  • 7
  • What is the exact error with trace? – Carcigenicate Oct 05 '20 at 21:20
  • 1
    Also note, having lists as default arguments (`shades_list = []`) is a usually [bad idea](https://stackoverflow.com/questions/1132941/least-astonishment-and-the-mutable-default-argument). – Carcigenicate Oct 05 '20 at 21:21
  • Thank you @Carcigenicate. I have added the TraceBack. I have no choice, really, but to use lists in this case. – Abed Oct 06 '20 at 00:11
  • You can use lists, but make the default argument `None`, then assign the list inside the function if it's `None`. And unfortunately that error appears to be library specific, so I can't help much. Definitely fix the default argument though. That *will* bite you at some point (it bites everyone at some point). See the link on a better description of the fix I mentioned. – Carcigenicate Oct 06 '20 at 00:14
  • 1
    From looking at the error again, `cells= cells_list[i]` in the calls to `setSuns` and `setTemps` should be `cells= cells_list`. Note the parameter is "cells" (plural), not "cell" – Carcigenicate Oct 06 '20 at 13:42

2 Answers2

2

Thank you for using PVmismatch. As @carcigenicate, says in their comment, the reason you are getting TypeError: 'int' object is not iterable is because the expected argument for cells in setSuns() is a list as documented in the API: enter image description here

I think you are trying to set the irradiance & temperature for 3 cells in a module. If correct, you can do this in a single call to setSuns followed by a single call to setTemps. Also note that cell temperatures are Kelvin, not Celsius. Also note you can get the max cell temperatures by calling the NumPy max() function on the array of IV-curve powers, Pcell[cell_idx].

>>> from pvmismatch import *

>>> shadez = [0.43, 0.43, 0.43]
>>> tempez = [88, 81, 77]
>>> cellz = [30, 31, 32]

>>> my_module_shaded = pvmodule.PVmodule()

>>> my_module_shaded.Pmod.max()  # module max power
321.2733629193704

# power of cells 30, 31, & 32, same for all cells in module
>>> [cellpower.max() for cellpower in my_module_shaded.Pcell[cellz]]
[3.3466338806725577, 3.3466338806725577, 3.3466338806725577]

>>> my_module_shaded.setSuns(Ee=shadez, cells=cellz)

>>> my_module_shaded.Pmod.max()  # module max power, after irradiance change
217.32753929640674

# NOTE: cell temperature is in Kelvin, not Celsius!
>>> tempez = [tc + 273.15 for tc in tempez]  # convert to Kelvin
>>> my_module_shaded.setTemps(Tc=tempez, cells=cellz)

>>> my_module_shaded.Pmod.max()  # module max power, after temperature change
215.93464636002747

# power of cells 30, 31, & 32, same for all cells in module
>>> [cellpower.max() for cellpower in my_module_shaded.Pcell[cellz]]
[1.0892289330819398, 1.1230533440517434, 1.1424662134689452]
Mark Mikofski
  • 19,398
  • 2
  • 57
  • 90
0

List of powers is an empty array. Try replacing list_of_powers[i] = my_module_shaded.pvcells[i].Igen*max(my_module_shaded.pvcells[i].Vcell) with list_of_powers.append(my_module_shaded.pvcells[i].Igen*max(my_module_shaded.pvcells[i].Vcell))

Nymoj
  • 24
  • 3