Skip to content

Instantly share code, notes, and snippets.

@davidbrochart
Last active April 25, 2019 10:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidbrochart/0aab58d607fe62ab46dd67dad8e19783 to your computer and use it in GitHub Desktop.
Save davidbrochart/0aab58d607fe62ab46dd67dad8e19783 to your computer and use it in GitHub Desktop.
import os
import zarr
def empty_zarr(name, variable=None):
'''Empty the Zarr archive of its data (but not its metadata).
Arguments:
- name: the name of the archive.
- variable: the name of the variable to empty (if None, empty all
variables)
'''
for dname in [f for f in os.listdir(name) if not f.startswith('.')]:
if variable is not None and dname == variable:
for fname in [f for f in os.listdir(f'{name}/{dname}')
if not f.startswith('.')]:
os.remove(f'{name}/{dname}/{fname}')
def append_zarr(src_name, dst_name):
'''Append a Zarr archive to another one.
Arguments:
- src_name: the name of the archive to append.
- dst_name: the name of the archive to be appended to.
'''
zarr_src = zarr.open(src_name, mode='r')
zarr_dst = zarr.open(dst_name, mode='a')
for key in [k for k in zarr_src.array_keys() if k not in ['lat', 'lon']]:
zarr_dst[key].append(zarr_src[key])
empty_zarr('trmm_3b42rt', 'time')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment