def sunset_sunrise(time, lat, lon):
    """
    Calculates the local sunrise/sunset of the glider location.

    The function uses the Astral package to calculate the sunrise and sunset
    times using the date, latitude and longitude. The times are returned
    rather than day or night indices, as it is more flexible for the quenching
    correction.


    Parameters
    ----------
    time: numpy.ndarray or pandas.Series
        The date & time array in a numpy.datetime64 format.
    lat: numpy.ndarray or pandas.Series
        The latitude of the glider position.
    lon: numpy.ndarray or pandas.Series
        The longitude of the glider position.

    Returns
    -------
    sunrise: numpy.ndarray
        An array of the sunrise times.
    sunset: numpy.ndarray
        An array of the sunset times.

    """
    from astral import Astral
    from pandas import DataFrame
    ast = Astral()
    df = DataFrame.from_dict(dict([('time', time), ('lat', lat), ('lon', lon)])
        )
    df = df.set_index(df.time.values.astype('datetime64[D]'))
    grp_avg = df.groupby(df.index).mean()
    date = grp_avg.index.to_pydatetime()
    grp_avg['sunrise'] = list(map(ast.sunrise_utc, date, df.lat, df.lon))
    grp_avg['sunset'] = list(map(ast.sunset_utc, date, df.lat, df.lon))
    df_reidx = grp_avg.reindex(df.index).astype('datetime64[ns]')
    sunrise, sunset = df_reidx[['sunrise', 'sunset']].values.T
    return sunrise, sunset
