简体   繁体   中英

Get Max Values of a Datetime Dependent Range

I hope you all are fine.

I got a function (Y axis) that gets values according to a datetime pandas array (X axis) as shown below.

有效辐照度 PVLIB-Python

I need to get all the maximum values . Those n maximum values depends on the number of days that are between a start and end pd.timestamp. Then, I also need to save those values in an array ; something like this:

max_values = [
    (A_value_1, B_value_1),
    (A_value_2, B_value_1),
        ...,
    (A_value_n, A_value_n)]

Note: The B_value_# is the same that I am asking for but with another function (A_values: Irradiance and B_values: Cell temperature, just a contextualization for the PVLIB-Python community.

For those who are familiar with PVLIB-Python , I am trying to get the IV curve by using the pvsystem.calcparams_desoto function (this is because I am using a CEC module and it doesn't have the parameters required by the SAPM function. Part of this code is snipped below:

    IL, I0, Rs, Rsh, nNsVth = pvsystem.calcparams_desoto(
    effective_irrad_calc,
    pvtemps['temp_cell'],
    module['alpha_sc'],
    module['a_ref'],
    module['I_L_ref'],
    module['I_o_ref'],
    module['R_sh_ref'],
    module['R_s'],
    EgRef=1.121,
    dEgdT=-0.0002677
)

curve_info = pvsystem.singlediode(
    photocurrent=IL,
    saturation_current=I0,
    resistance_series=Rs,
    resistance_shunt=Rsh,
    nNsVth=nNsVth,
    ivcurve_pnts=100,
    method='lambertw'
)

# plot the calculated curves:
plt.figure()
for i, case in conditions.iterrows():
    label = (
        "$G_{eff}$ " + f"{case['Geff']} $W/m^2$\n"
        "$T_{cell}$ " + f"{case['Tcell']} $C$"
    )
    plt.plot(curve_info['v'][i], curve_info['i'][i], label=label)
    v_mp = curve_info['v_mp'][i]
    i_mp = curve_info['i_mp'][i]
    # mark the MPP
    plt.plot([v_mp], [i_mp], ls='', marker='o', c='k')

plt.legend(loc=(1.0, 0))
plt.xlabel('Module voltage [V]')
plt.ylabel('Module current [A]')
plt.title(parameters['Name'])
plt.show()
plt.gcf().set_tight_layout(True)

Note: This code snipped was taken at: https://github.com/pvlib/pvlib-python/blob/master/docs/examples/plot_singlediode.py

Thanks in advance. :)

First just making a small example:

df = pd.DataFrame(index=pd.date_range('2020-01-01', freq='1h', periods=24*5))
df['irradiance'] = np.clip(np.cos(np.linspace(np.pi, 2*np.pi*5+np.pi, 24*5)), 
                           a_min=0, a_max=None)

Then using pandas' resample function with a daily frequency and the max function, would give you the daily value for the peak:

max_value = df['irradiance'].resample('1d').max()

Similarly, the location of the max value can be found:

max_location = df['irradiance'].resample('1d').apply(lambda s: s.idxmax())

Now knowing the location/index of the max value you can apply this to another column of your DataFrame.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM