首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >将参数传递给这个使用to失配的函数:为什么这不起作用?

将参数传递给这个使用to失配的函数:为什么这不起作用?
EN

Stack Overflow用户
提问于 2020-10-05 21:18:30
回答 2查看 85关注 0票数 2

我正在使用一个名为be错配的库,它测量不完全遮阳对太阳能电池的影响,我认为它很快就会与pvlib兼容。我不确定这是一个一般性的与python有关的问题,还是仅仅是与库有关的问题,但可能是前者。

我想要创建一个函数,它包含一个使用"setSuns“的”阴影“列表,以及要阴影的单元格的索引。我的代码如下:

代码语言:javascript
复制
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

后来,我尝试尝试如下所示的函数:

代码语言:javascript
复制
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:

代码语言:javascript
复制
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
EN

Stack Overflow用户

回答已采纳

发布于 2020-10-13 05:03:14

感谢您使用PVmismatch。正如@carcigenicate他们的评论中所说,您之所以获得TypeError: 'int' object is not iterable,是因为setSuns()中的cells的预期参数是一个列表,如API接口中所记录的那样:

我想你是想把3个细胞的辐照度和温度设定在一个模块里。如果正确的话,您可以在对setSuns的单个调用后对setTemps的单个调用中执行此操作。还要注意的是细胞温度为开尔文,而不是摄氏。还请注意,您可以通过调用IV曲线功率数组的NumPy max()函数Pcell[cell_idx]来获得最大的单元格温度。

代码语言:javascript
复制
>>> 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
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64216311

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档