# Buggy code
def surface_based_cape_cin(pressure, temperature, dewpoint):
    r"""Calculate surface-based CAPE and CIN.

    Calculate the convective available potential energy (CAPE) and convective inhibition (CIN)
    of a given upper air profile for a surface-based parcel. CIN is integrated
    between the surface and LFC, CAPE is integrated between the LFC and EL (or top of
    sounding). Intersection points of the measured temperature profile and parcel profile are
    linearly interpolated.

    Parameters
    ----------
    pressure : `pint.Quantity`
        Atmospheric pressure profile. The first entry should be the starting
        (surface) observation.
    temperature : `pint.Quantity`
        Temperature profile
    dewpoint : `pint.Quantity`
        Dewpoint profile

    Returns
    -------
    `pint.Quantity`
        Surface based Convective Available Potential Energy (CAPE).
    `pint.Quantity`
        Surface based Convective INhibition (CIN).

    See Also
    --------
    cape_cin, parcel_profile

    """
    profile = parcel_profile(pressure, temperature[0], dewpoint[0])
    return cape_cin(pressure, temperature, dewpoint, profile)


# Traceback (IndexError)
Traceback (most recent call last):
File "cal_sounding_data.py", line 360, in <module>
newset_dic[k] = specStationSounding(k,dataset_dic)
File "cal_sounding_data.py", line 284, in specStationSounding
result_dic = soundingCalculation(num,p,t,td,ws,wd)
File "cal_sounding_data.py", line 170, in soundingCalculation
lfc_p, lfc_T = mpcalc.lfc(P,T,Td)
File "/anaconda2/envs/py3/lib/python3.6/site-packages/metpy/xarray.py", line 138, in wrapper
return func(*args, **kwargs)
File "/anaconda2/envs/py3/lib/python3.6/site-packages/metpy/units.py", line 290, in wrapper
return func(*args, **kwargs)
File "/anaconda2/envs/py3/lib/python3.6/site-packages/metpy/calc/thermo.py", line 378, in lfc
return x[0], y[0]
File "/anaconda2/envs/py3/lib/python3.6/site-packages/pint/quantity.py", line 1281, in __getitem__
value = self._magnitude[key]
IndexError: index 0 is out of bounds for axis 0 with size 0

# Fixed code
def surface_based_cape_cin(pressure, temperature, dewpoint):
    r"""Calculate surface-based CAPE and CIN.

    Calculate the convective available potential energy (CAPE) and convective inhibition (CIN)
    of a given upper air profile for a surface-based parcel. CIN is integrated
    between the surface and LFC, CAPE is integrated between the LFC and EL (or top of
    sounding). Intersection points of the measured temperature profile and parcel profile are
    linearly interpolated.

    Parameters
    ----------
    pressure : `pint.Quantity`
        Atmospheric pressure profile. The first entry should be the starting
        (surface) observation.
    temperature : `pint.Quantity`
        Temperature profile
    dewpoint : `pint.Quantity`
        Dewpoint profile

    Returns
    -------
    `pint.Quantity`
        Surface based Convective Available Potential Energy (CAPE).
    `pint.Quantity`
        Surface based Convective INhibition (CIN).

    See Also
    --------
    cape_cin, parcel_profile

    """
    p, t, td, profile = parcel_profile_with_lcl(pressure, temperature, dewpoint)
    return cape_cin(p, t, td, profile)