如何通过此函数解决此 NaN 错误?

How do I solve this NaN error by this function?

输入:

#Fixed-mono-cell temperature
parameters = pvlib.temperature.TEMPERATURE_MODEL_PARAMETERS['sapm']['open_rack_glass_glass'] #to extract specfic parameter 
cell_temperature_mono_fixed = pvlib.temperature.sapm_cell(effective_irrad_mono_fixed,
                                               df['T_a'],
                                               df['W_s'],
                                               **parameters)

cell_temperature_mono_fixed

输出:

2005-01-01 01:00:00   NaN
2005-01-01 02:00:00   NaN
2005-01-01 03:00:00   NaN
2005-01-01 04:00:00   NaN
2005-01-01 05:00:00   NaN
                       ..
8755                  NaN
8756                  NaN
8757                  NaN
8758                  NaN
8759                  NaN
Length: 17520, dtype: float64

cell_temperature_mono_fixed.plot

输出:

/Users/charlielinck/opt/anaconda3/lib/python3.9/site-packages/pandas/core/indexes/base.py:4024: RuntimeWarning: '

Extra data information:

df: dataframe

date_time   Sun_Az  Sun_alt GHI DHI DNI T_a W_s
0   2005-01-01 01:00:00 17.9    90.0    0.0 0.0 0.0 15.5    13.3
1   2005-01-01 02:00:00 54.8    90.0    0.0 0.0 0.0 17.0    14.5
2   2005-01-01 03:00:00 73.7    90.0    0.0 0.0 0.0 16.7    14.0
3   2005-01-01 04:00:00 85.7    90.0    0.0 0.0 0.0 16.7    14.2
4   2005-01-01 05:00:00 94.9    90.0    0.0 0.0 0.0 16.7    14.1
5   2005-01-01 06:00:00 103.5   90.0    0.0 0.0 0.0 16.6    14.3
6   2005-01-01 07:00:00 111.6   90.0    0.0 0.0 0.0 16.5    13.8
7   2005-01-01 08:00:00 120.5   89.6    1.0 1.0 0.0 16.6    16.0
8   2005-01-01 09:00:00 130.5   79.9    27.0    27.0    0.0 16.8    16.5
9   2005-01-01 10:00:00 141.8   71.7    55.0    55.0    0.0 16.9    16.9
10  2005-01-01 11:00:00 154.9   65.5    83.0    83.0    0.0 17.0    17.2
11  2005-01-01 12:00:00 169.8   61.9    114.0   114.0   0.0 17.4    17.9
12  2005-01-01 13:00:00 185.2   61.4    110.0   110.0   0.0 17.5    18.0
13  2005-01-01 14:00:00 200.4   64.0    94.0    94.0    0.0 17.5    17.8
14  2005-01-01 15:00:00 214.3   69.5    70.0    70.0    0.0 17.5    17.6
15  2005-01-01 16:00:00 226.3   77.2    38.0    38.0    0.0 17.2    17.0
16  2005-01-01 17:00:00 236.5   86.4    4.0 4.0 0.0 16.7    16.3
17  2005-01-01 18:00:00 245.5   90.0    0.0 0.0 0.0 16.0    14.5
18  2005-01-01 19:00:00 254.2   90.0    0.0 0.0 0.0 14.9    13.0
19  2005-01-01 20:00:00 262.3   90.0    0.0 0.0 0.0 16.0    14.1
20  2005-01-01 21:00:00 271.3   90.0    0.0 0.0 0.0 15.1    13.3
21  2005-01-01 22:00:00 282.1   90.0    0.0 0.0 0.0 15.5    13.2
22  2005-01-01 23:00:00 298.1   90.0    0.0 0.0 0.0 15.6    13.0
23  2005-01-02 00:00:00 327.5   90.0    0.0 0.0 0.0 15.8    13.1

df['T_a']为温度数据, df['W_s']为风速数据


effective_irrad_mono_fixed.head(24)

date_time 2005-01-01 01:00:00 0.000000 2005-01-01 02:00:00 0.000000 2005-01-01 03:00:00 0.000000 2005-01-01 04:00:00 0.000000 2005-01-01 05:00:00 0.000000 2005-01-01 06:00:00 0.000000 2005-01-01 07:00:00 0.000000 2005-01-01 08:00:00 0.936690 2005-01-01 09:00:00 25.168996 2005-01-01 10:00:00 51.165091 2005-01-01 11:00:00 77.354266 2005-01-01 12:00:00 108.002486 2005-01-01 13:00:00 103.809820 2005-01-01 14:00:00 88.138705 2005-01-01 15:00:00 65.051870 2005-01-01 16:00:00 35.390518 2005-01-01 17:00:00 3.742581 2005-01-01 18:00:00 0.000000 2005-01-01 19:00:00 0.000000 2005-01-01 20:00:00 0.000000 2005-01-01 21:00:00 0.000000 2005-01-01 22:00:00 0.000000 2005-01-01 23:00:00 0.000000 2005-01-02 00:00:00 0.000000

问题:我不明白如果我简单地运行我只得到NaN值的函数,它可能与时间戳有关。 我相信当我想绘制函数时,这也会导致 RunTimeWarning。

这不是真正的 pvlib 问题,更多的是 pandas 问题。问题是您的输入时间序列对象不在一致的索引上:辐照度输入具有 pandas.DatetimeIndex 而温度和风速输入具有 pandas.RangeIndex(请参阅从 [=13 打印出的索引=]). Series 上的数学运算是通过对齐索引元素并在不对齐的地方替换 NaN 来完成的。例如,在此处查看共享索引元素如何对应于 non-NaN 值:

In [46]: a = pd.Series([1, 2, 3], index=[1, 2, 3])
    ...: b = pd.Series([2, 3, 4], index=[2, 3, 4])
    ...: a*b
Out[46]: 
1    NaN
2    4.0
3    9.0
4    NaN
dtype: float64

如果您检查 cell_temperature_mono_fixed 的索引,您会看到它同时具有时间戳(来自辐照度输入)和整数(来自其他两个),因此它采用索引的并集但是仅填写交集的值(在本例中为空)。

因此,要解决您的问题,您应该确保所有输入都在一致的索引上。最简单的方法可能是在数据帧级别,即 df = df.set_index('date_time').