Skip to content

Commit b1a1aeb

Browse files
committed
save file and toss some timings
1 parent f8f930f commit b1a1aeb

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

activestorage/netcdf_to_zarr.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from activestorage.config import *
1010
from kerchunk.hdf import SingleHdf5ToZarr
1111

12+
import time
1213

1314
def gen_json(file_url, varname, outf, storage_type, storage_options):
1415
"""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):
3536
storage_options['default_cache_type'] = "none"
3637
fs = s3fs.S3FileSystem(**storage_options)
3738
fs2 = fsspec.filesystem('')
39+
tk1 = time.time()
3840
with fs.open(file_url, 'rb') as s3file:
3941
h5chunks = SingleHdf5ToZarr(s3file, file_url,
4042
inline_threshold=0)
43+
tk2 = time.time()
44+
print("Time to set up Kerchunk", tk2 - tk1)
4145
with fs2.open(outf, 'wb') as f:
4246
content = h5chunks.translate()
4347
f.write(ujson.dumps(content).encode())
48+
tk3 = time.time()
49+
print("Time to Translate and Dump Kerchunks to json file", tk3 - tk2)
4450
# not S3
4551
else:
4652
fs = fsspec.filesystem('')
@@ -98,7 +104,9 @@ def load_netcdf_zarr_generic(fileloc, varname, storage_type, storage_options, bu
98104
print(f"Storage type {storage_type}")
99105

100106
# 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:
102110
_, zarray, zattrs = gen_json(fileloc,
103111
varname,
104112
out_json.name,

0 commit comments

Comments
 (0)