pythonruntime-errornandatetime-formatpvlib

How do I solve this NaN error by this function?


Input:

#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

Output:

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

Output:

/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'] is temperature data, df['W_s'] is windspeed data


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

Question: I don't understand that if I simply run the function I only get NaN values, might it have something to with the timestamp. I believe this also results in the RunTimeWarning when I want to plot the function.


Solution

  • This is not really a pvlib issue, more a pandas issue. The problem is that your input time series objects are not on a consistent index: the irradiance input has a pandas.DatetimeIndex while the temperature and wind speed inputs have pandas.RangeIndex (see the index printed out from your df). Math operations on Series are done by aligning index elements and substituting NaN where things don't line up. For example see how only the shared index elements correspond to non-NaN values here:

    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
    

    If you examine the index of your cell_temperature_mono_fixed, you'll see it has both timestamps (from the irradiance input) and integers (from the other two), so it's taking the union of the indexes but only filling in values for the intersection (which is empty in this case).

    So to fix your problem, you should make sure all the inputs are on a consistent index. The easiest way to do that is probably at the dataframe level, i.e. df = df.set_index('date_time').