python - 将参数传递给使用 pvmismatch : Why is this not working? 的此函数

标签 python python-3.x pvlib

我正在使用一个名为 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 (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

最佳答案

感谢您使用PVmismatch 。如@carcigenicate ,在their comment中说,您收到 TypeError: 'int' object is not iterable 的原因是因为 setSuns()cells 的预期参数是 < em>列出,如 API 中所述: enter image description here

我认为您正在尝试设置模块中 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]

关于python - 将参数传递给使用 pvmismatch : Why is this not working? 的此函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64216311/

相关文章:

python - 根据列名称替换 pandas 数据框中的值

python - 从另一个线程扭曲触发事件

Python 音频编辑

python - Pandas 以最小的差距绘制时间序列

python - 使用请求从谷歌距离矩阵 api 获取响应时出现连接错误

python-3.x - 如何为python模块为 'tox'运行 'py.test'命令?

Python argparse 可选破折号整数参数

python - 属性错误: 'DataFrame' object has no attribute 'dtype'

python - 使用 PVLIB 模拟具有遮阳损失的系统