splitvar/splitvar.py
def resamplebytime(ds, var, freq, timedim='time', function=np.mean, copyattrs=True):
    """
    Given an xarray dataset, split into periods of time defined by freq
    Major variable is var, others are dependent variables which will be
    inspected for appropriate reduction methods
    """

    # applied = (funcs[i](v) for i, v in enumerate(resampler._iter_grouped()))
    all = []
    for  v in ds:
        # Inspect variables to determine most appropriate function
        timetype = get_time_type(ds[v])
        if timetype == 'delta':
            func = sum_timedelta
        elif timetype == 'datetime':
            func = find_bounds 
        else:
            func = function

        print(v,func)
        # resampler = ds[v].resample({timedim: freq})
        applied = []
        for dsg in ds[v].resample({timedim: freq}).reduce(func,dim=timedim):
            print(dsg)
            applied.append(dsg)
        all.append(xarray.concat(applied, dim=timedim))

    combined = xarray.merge(all)

    if copyattrs:
        for v in list(combined.data_vars) + list(combined.coords):
            combined[v].attrs.update(ds[v].attrs)
            combined[v].encoding.update(ds[v].encoding)

    return combined

    Given an xarray dataset, split into periods of time defined by freq
    Major variable is var, others are dependent variables which will be
    inspected for appropriate reduction methods
    
Given an xarray dataset, split into periods of time defined by freq
Major variable is var, others are dependent variables which will be
inspected for appropriate reduction methods
Given an xarray dataset split into periods of time defined by freq Major variable is var others are dependent variables which will be inspected for appropriate reduction methods
def resamplebytime(ds, var, freq, timedim='time', function=np.mean, copyattrs=True):
    all = []
    for  v in ds:
        timetype = get_time_type(ds[v])
        if timetype == 'delta':
            func = sum_timedelta
        elif timetype == 'datetime':
            func = find_bounds 
        else:
            func = function
        print(v,func)
        applied = []
        for dsg in ds[v].resample({timedim: freq}).reduce(func,dim=timedim):
            print(dsg)
            applied.append(dsg)
        all.append(xarray.concat(applied, dim=timedim))
    combined = xarray.merge(all)
    if copyattrs:
        for v in list(combined.data_vars) + list(combined.coords):
            combined[v].attrs.update(ds[v].attrs)
            combined[v].encoding.update(ds[v].encoding)
    return combined
def resamplebytime ( ds , var , freq , timedim = 'time' , function = np . mean , copyattrs = True ) : all = [ ] for v in ds : timetype = get_time_type ( ds [ v ] ) if timetype == 'delta' : func = sum_timedelta elif timetype == 'datetime' : func = find_bounds else : func = function print ( v , func ) applied = [ ] for dsg in ds [ v ] . resample ( { timedim : freq } ) . reduce ( func , dim = timedim ) : print ( dsg ) applied . append ( dsg ) all . append ( xarray . concat ( applied , dim = timedim ) ) combined = xarray . merge ( all ) if copyattrs : for v in list ( combined . data_vars ) + list ( combined . coords ) : combined [ v ] . attrs . update ( ds [ v ] . attrs ) combined [ v ] . encoding . update ( ds [ v ] . encoding ) return combined
Given an xarray dataset, split into periods of time defined by freq
Major variable is var, others are dependent variables which will be
inspected for appropriate reduction methods
Given an xarray dataset split into periods of time defined by freq Major variable is var others are dependent variables which will be inspected for appropriate reduction methods
"""
    Given an xarray dataset, split into periods of time defined by freq
    Major variable is var, others are dependent variables which will be
    inspected for appropriate reduction methods
    """ # applied = (funcs[i](v) for i, v in enumerate(resampler._iter_grouped())) # Inspect variables to determine most appropriate function # resampler = ds[v].resample({timedim: freq})
ds
var
freq
timedim
function
copyattrs