splitvar/utils.py
def rebase_dataset(ds, target_units=None, timevar='time', offset=None):
    """
    Rebase the time dimension variable in a dataset to a different start date.
    This is useful to overcome limitations in pandas datetime indices used in 
    xarray, and to place two datasets with different date indices onto a common
    date index
    """

    # The units are defined as the units used by timevar
    units = ds[timevar].attrs['units']
    calendar = ds[timevar].attrs['calendar']

    newds = ds.copy()

    # Cycle through all variables, setting a flag if they are a bounds variable
    flag_bounds(newds)

    for name in newds.variables:
        if is_bounds(newds[name]):
            # This is a bounds variable and has been flagged as such so ignore
            # as it will be processed by the variable for which it is the bounds
            continue
        if newds[name].attrs['units'] == units:
            newds[name] = rebase_variable(newds[name], calendar, target_units, offset=offset)
            if bounds in newds[name].attrs:
                # Must make the same adjustment to the bounds variable
                bvarname = newds[name].attrs[bounds]
                try:
                    newds[bvarname] = rebase_variable(newds[bvarname], calendar, target_units, src_units=units, offset=offset)
                except KeyError:
                    # Ignore if bounds_var missing
                    pass

    # Unset bounds flags
    unflag_bounds(newds)

    # newds = xr.decode_cf(newds, decode_coords=False, decode_times=True)

    return newds

    Rebase the time dimension variable in a dataset to a different start date.
    This is useful to overcome limitations in pandas datetime indices used in 
    xarray, and to place two datasets with different date indices onto a common
    date index
    
Rebase the time dimension variable in a dataset to a different start date.
This is useful to overcome limitations in pandas datetime indices used in
xarray, and to place two datasets with different date indices onto a common
date index
Rebase the time dimension variable in a dataset to a different start date . This is useful to overcome limitations in pandas datetime indices used in xarray and to place two datasets with different date indices onto a common date index
def rebase_dataset(ds, target_units=None, timevar='time', offset=None):
    units = ds[timevar].attrs['units']
    calendar = ds[timevar].attrs['calendar']
    newds = ds.copy()
    flag_bounds(newds)
    for name in newds.variables:
        if is_bounds(newds[name]):
            continue
        if newds[name].attrs['units'] == units:
            newds[name] = rebase_variable(newds[name], calendar, target_units, offset=offset)
            if bounds in newds[name].attrs:
                bvarname = newds[name].attrs[bounds]
                try:
                    newds[bvarname] = rebase_variable(newds[bvarname], calendar, target_units, src_units=units, offset=offset)
                except KeyError:
                    pass
    unflag_bounds(newds)
    return newds
def rebase_dataset ( ds , target_units = None , timevar = 'time' , offset = None ) : units = ds [ timevar ] . attrs [ 'units' ] calendar = ds [ timevar ] . attrs [ 'calendar' ] newds = ds . copy ( ) flag_bounds ( newds ) for name in newds . variables : if is_bounds ( newds [ name ] ) : continue if newds [ name ] . attrs [ 'units' ] == units : newds [ name ] = rebase_variable ( newds [ name ] , calendar , target_units , offset = offset ) if bounds in newds [ name ] . attrs : bvarname = newds [ name ] . attrs [ bounds ] try : newds [ bvarname ] = rebase_variable ( newds [ bvarname ] , calendar , target_units , src_units = units , offset = offset ) except KeyError : pass unflag_bounds ( newds ) return newds
Rebase the time dimension variable in a dataset to a different start date.
Rebase the time dimension variable in a dataset to a different start date .
"""
    Rebase the time dimension variable in a dataset to a different start date.
    This is useful to overcome limitations in pandas datetime indices used in 
    xarray, and to place two datasets with different date indices onto a common
    date index
    """ # The units are defined as the units used by timevar # Cycle through all variables, setting a flag if they are a bounds variable # This is a bounds variable and has been flagged as such so ignore # as it will be processed by the variable for which it is the bounds # Must make the same adjustment to the bounds variable # Ignore if bounds_var missing # Unset bounds flags # newds = xr.decode_cf(newds, decode_coords=False, decode_times=True)
ds
target_units
timevar
offset