-
-
Save davidbrochart/0aab58d607fe62ab46dd67dad8e19783 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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