How to use the zarr.creation.empty function in zarr

To help you get started, we’ve selected a few zarr examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dcs4cop / xcube / xcube / util / dsgrow.py View on Github external
if var.dims[0] != 'time':
                    raise ValueError(f"Variable: {var_name} Dimension 'time' must be first dimension")
                time_var_names.append(var_name)
    if chunk_sizes:
        time_slice = chunk_dataset(time_slice, chunk_sizes, format_name='zarr')
    temp_dir = tempfile.TemporaryDirectory(suffix='time-slice-', prefix='.zarr')
    time_slice.to_zarr(temp_dir.name)
    slice_root_group = zarr.open(temp_dir.name, mode='r')
    slice_arrays = dict(slice_root_group.arrays())

    cube_root_group = zarr.open(store, mode='r+')
    for var_name, var_array in cube_root_group.arrays():
        if var_name in time_var_names:
            slice_array = slice_arrays[var_name]
            # Add one empty time step
            empty = zarr.creation.empty(slice_array.shape, dtype=var_array.dtype)
            var_array.append(empty, axis=0)
            # Shift contents
            var_array[insert_index + 1:, ...] = var_array[insert_index:-1, ...]
            # Insert slice
            var_array[insert_index, ...] = slice_array[0]

    unchunk_dataset(store, coords_only=True)