def clearsky_index(ghi, clearsky_ghi, max_clearsky_index=<NUM_LIT>):
clearsky_index = ghi / clearsky_ghi<EOL>clearsky_index = np.where(~np.isfinite(clearsky_index), <NUM_LIT:0>,<EOL>clearsky_index)<EOL>input_is_nan = ~np.isfinite(ghi) | ~np.isfinite(clearsky_ghi)<EOL>clearsky_index = np.where(input_is_nan, np.nan, clearsky_index)<EOL>clearsky_index = np.maximum(clearsky_index, <NUM_LIT:0>)<EOL>clearsky_index = np.minimum(clearsky_index, max_clearsky_index)<EOL>if isinstance(ghi, pd.Series):<EOL><INDENT>clearsky_index = pd.Series(clearsky_index, index=ghi.index)<EOL><DEDENT>return clearsky_index<EOL>
Calculate the clearsky index.

The clearsky index is the ratio of global to clearsky global irradiance.
Negative and non-finite clearsky index values will be truncated to zero.

Parameters
----------
ghi : numeric
    Global horizontal irradiance in W/m^2.

clearsky_ghi : numeric
    Modeled clearsky GHI

max_clearsky_index : numeric, default 2.0
    Maximum value of the clearsky index. The default, 2.0, allows
    for over-irradiance events typically seen in sub-hourly data.

Returns
-------
clearsky_index : numeric
    Clearsky index