Skip to content

Commit

Permalink
copt zattrs too
Browse files Browse the repository at this point in the history
  • Loading branch information
yoctoyotta1024 committed Jan 12, 2024
1 parent 8bdffb4 commit 525fc55
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions pySD/sdmout_src/ensembzarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,10 @@ def ensemble_data(func, datasets, var):

return func(data4ensemb)

def write_matchingarray_to_storage(arrayname, arr, refz):
def write_matchingarray_to_storage(arrayname, arr, refz, zattrs):
''' write array 'arr' to zarr storage under
'arrayname' using same metadata as refz '''
'arrayname' using same metadata as refz and
copying zattrs to .zattrs file '''

if arr.shape != refz.shape:
err = "arr and reference for metadata must have same shape"
Expand All @@ -112,6 +113,8 @@ def write_matchingarray_to_storage(arrayname, arr, refz):
order=refz.order)
z[:] = arr

os.system('cp '+zattrs+' '+arrayname+'/.zattrs')

def write_meanvars_to_ensembzarr(ensembdataset, vars4ensemb,
datasets, refset):
''' write mean over ensemble of datasets for
Expand All @@ -122,8 +125,11 @@ def write_meanvars_to_ensembzarr(ensembdataset, vars4ensemb,
meanname = ensembdataset+"/"+var
meanvar = ensemble_data(lambda x : np.mean(x, axis=0),
datasets, var)

zattrs = refset+"/"+var+"/.zattrs"
write_matchingarray_to_storage(meanname, meanvar,
zarr.open(refset)[var])
zarr.open(refset)[var],
zattrs)

def write_stdvars_to_ensembzarr(ensembdataset, vars4ensemb,
datasets, refset):
Expand All @@ -135,8 +141,11 @@ def write_stdvars_to_ensembzarr(ensembdataset, vars4ensemb,
stdname = ensembdataset+"/"+var+"_std"
stdvar = ensemble_data(lambda x : np.std(x, axis=0),
datasets, var)

zattrs = refset+"/"+var+"/.zattrs"
write_matchingarray_to_storage(stdname, stdvar,
zarr.open(refset)[var])
zarr.open(refset)[var],
zattrs)

def write_ensemb_zarr(ensembdataset, vars4ensemb, datasets):
''' create zarr storage called 'ensembdataset'
Expand Down

0 comments on commit 525fc55

Please sign in to comment.