def window_roll(ts, w, tdim): 
    """Return all values falling in -w/+w window from each day-of-year
    and build new timeseries.

    Parameters
    ----------
    ts: xarray DataArray
        Temperature timeseries array
    w: int
        Half width of window
    tdim: str
        Name of time dimension

    Returns
    -------
    twindow: xarray DataArray
        Stacked array timeseries with new 'z' dimension representing
        a window of width 2*w+1
    """
    
    width = 2*w+1
    dtime = {tdim: width}
    trolled = ts.rolling(**dtime, center=True).construct('wdim')
    troll = trolled.stack(z=('wdim', tdim))
    twindow = troll.dropna(dim='z')
    return twindow