【问题标题】:Passing arguments to this function which uses pvmismatch: Why is this not working?将参数传递给使用 pvmismatch 的函数:为什么这不起作用?
【发布时间】:2020-10-05 21:18:30
【问题描述】:

我正在使用一个名为 pvmismatch 的库,它可以测量不完美阴影对太阳能电池的影响,我认为它很快就会与 pvlib 兼容。我不确定这是一个与 python 相关的问题,还是与库相关的问题,但可能是前者。

我想创建一个函数,该函数接受使用“setSuns”的“阴影”列表以及要为哪些单元格着色的索引。我的代码如下:

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

我后来尝试了这个功能如下:

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

我得到的错误是“'int' 类型的对象不可迭代”。我在这里做错了什么?

感谢所有帮助。

下面是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

【问题讨论】:

  • 跟踪的确切错误是什么?
  • 另请注意,将列表作为默认参数 (shades_list = []) 通常是 bad idea
  • 谢谢@Carcigenicate。我已经添加了 TraceBack。真的,我别无选择,只能在这种情况下使用列表。
  • 您可以使用列表,但设置默认参数None,然后在函数内部分配列表,如果它是None。不幸的是,这个错误似乎是特定于库的,所以我帮不上什么忙。绝对修复默认参数。这在某个时候咬你(它在某个时候咬每个人)。有关我提到的修复的更好描述,请参阅链接。
  • 再次查看错误,cells= cells_list[i] 在对setSunssetTemps 的调用中应该是cells= cells_list。注意参数是“cells”(复数),而不是“cell”

标签: python python-3.x pvlib


【解决方案1】:

感谢您使用PVmismatch。正如@carcigenicate,在their comment 中所说,您得到TypeError: 'int' object is not iterable 的原因是因为setSuns()cells 的预期参数是API 中记录的列表

我认为您正在尝试为一个模块中的 3 个电池设置辐照度和温度。如果正确,您可以通过对setSuns 的一次调用然后对setTemps 的一次调用来执行此操作。另请注意cell temperatures are Kelvin,而不是摄氏度。另请注意,您可以通过调用 IV 曲线幂数组 Pcell[cell_idx] 上的 NumPy max() 函数来获取最大电池温度。

>>> 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]

【讨论】:

    【解决方案2】:

    权力列表是一个空数组。尝试将list_of_powers[i] = my_module_shaded.pvcells[i].Igen*max(my_module_shaded.pvcells[i].Vcell) 替换为list_of_powers.append(my_module_shaded.pvcells[i].Igen*max(my_module_shaded.pvcells[i].Vcell))

    【讨论】:

    • 这可能是真的,但这不会导致他们提到的错误。
    • 感谢您的建议,可惜这并不能解决问题。
    猜你喜欢
    • 2020-06-22
    • 2015-09-09
    • 2021-05-29
    • 2022-10-12
    • 1970-01-01
    • 1970-01-01
    • 2022-11-25
    • 1970-01-01
    • 2013-01-27
    相关资源
    最近更新 更多