示例#1
0
def _set_time_units_like(source_store: zarr.Group, target_store: zarr.Group):
    """Modify all time-like variables in source_store to use same units as
    corresponding variable in target_store. The provided source_store must be
    opened in a mode such that it can be modified (e.g. mode='r+')"""
    for variable, source_array in source_store.items():
        target_array = target_store[variable]
        if "units" in source_array.attrs and "since" in source_array.attrs[
                "units"]:
            _set_array_time_units_like(source_array, target_array)
示例#2
0
def _assert_chunks_match(source_group: zarr.Group, target_group: zarr.Group,
                         dim: str):
    """Ensure chunks for source and target groups are valid for appending.
    
    Specifically:
        1. all arrays in source_group have corresponding arrays in target_group.
        2. chunk size is same for each array in source and target group.
        3. dim length is a multiple of chunk size for target group.
        
    In addition, log a warning if dim length is not a multiple of chunk size for source
    group."""
    for key, source_array in source_group.items():
        if key not in target_group:
            raise KeyError(
                f"Cannot append {source_array} because there is no corresponding array "
                f"in {target_group}.")
        if dim != key and dim in source_array.attrs[XARRAY_DIM_NAMES_ATTR]:
            axis = source_array.attrs[XARRAY_DIM_NAMES_ATTR].index(dim)
            target_array = target_group[key]
            _assert_array_chunks_match(source_array, target_array, axis)