def calculate_trace(container, twin, fargs):
    """
    Calculate trace and peaks/troughs of filtered time series

    Parameters
    ----------
    container : dict
        TimeSeries objects
    twin : tuple
        Time window. Time series are cropped to time window before extracting maxima.
    fargs : tuple
        Filter arguments. Time series are filtered before extracting maxima.

    Returns
    -------
    dict
        Filtered and windowed time series and peaks/throughs
    """
    container_out = dict()

    for name, ts in container.items():
        t, x = ts.get(twin=twin, filterargs=fargs)
        xmin, tmin = ts.minima(twin=twin, filterargs=fargs, rettime=True)
        xmax, tmax = ts.maxima(twin=twin, filterargs=fargs, rettime=True)

        container_out[name] = dict(t=t, x=x, tmin=tmin, xmin=xmin,
                                   tmax=tmax, xmax=xmax)

    return container_out