9
9
from activestorage .config import *
10
10
from kerchunk .hdf import SingleHdf5ToZarr
11
11
12
+ import time
12
13
13
14
def gen_json (file_url , varname , outf , storage_type , storage_options ):
14
15
"""Generate a json file that contains the kerchunk-ed data for Zarr."""
@@ -35,12 +36,17 @@ def gen_json(file_url, varname, outf, storage_type, storage_options):
35
36
storage_options ['default_cache_type' ] = "none"
36
37
fs = s3fs .S3FileSystem (** storage_options )
37
38
fs2 = fsspec .filesystem ('' )
39
+ tk1 = time .time ()
38
40
with fs .open (file_url , 'rb' ) as s3file :
39
41
h5chunks = SingleHdf5ToZarr (s3file , file_url ,
40
42
inline_threshold = 0 )
43
+ tk2 = time .time ()
44
+ print ("Time to set up Kerchunk" , tk2 - tk1 )
41
45
with fs2 .open (outf , 'wb' ) as f :
42
46
content = h5chunks .translate ()
43
47
f .write (ujson .dumps (content ).encode ())
48
+ tk3 = time .time ()
49
+ print ("Time to Translate and Dump Kerchunks to json file" , tk3 - tk2 )
44
50
# not S3
45
51
else :
46
52
fs = fsspec .filesystem ('' )
@@ -98,7 +104,9 @@ def load_netcdf_zarr_generic(fileloc, varname, storage_type, storage_options, bu
98
104
print (f"Storage type { storage_type } " )
99
105
100
106
# Write the Zarr group JSON to a temporary file.
101
- with tempfile .NamedTemporaryFile () as out_json :
107
+ save_json = "test_file.json"
108
+ # with tempfile.NamedTemporaryFile() as out_json:
109
+ with open (save_json , "wb" ) as out_json :
102
110
_ , zarray , zattrs = gen_json (fileloc ,
103
111
varname ,
104
112
out_json .name ,
0 commit comments