diff --git a/h5py_write_speed.py b/h5py_write_speed.py index 89ab71c..735c2a8 100755 --- a/h5py_write_speed.py +++ b/h5py_write_speed.py @@ -16,7 +16,7 @@ xb = random(SIZE) > 0.5 # mean ~ 0.5 xbl = xb.tolist() -with tempfile.NamedTemporaryFile() as fn: +with tempfile.NamedTemporaryFile(suffix=".h5") as fn: with h5py.File(fn, "w") as h: tic = time() h["bool"] = xb @@ -29,4 +29,5 @@ # %% here's what nidaqmx gives us tic = time() h["listbool"] = xbl - print(f"{time()-tic:3e} sec. to write boolean from bool list") +# outside context manager to help ensure HDF5 file is finalized +print(f"{time()-tic:3e} sec. to write boolean from bool list") diff --git a/netcdf_write_speed.py b/netcdf_write_speed.py index a5d2c76..f519772 100755 --- a/netcdf_write_speed.py +++ b/netcdf_write_speed.py @@ -19,7 +19,6 @@ from numpy import packbits import xarray from time import time -import os SIZE = (3, 200000) # arbitrary size to test @@ -30,23 +29,20 @@ Xb = xarray.DataArray(xb, name="bool") -with tempfile.NamedTemporaryFile(suffix=".nc", delete=False) as f: +with tempfile.NamedTemporaryFile(suffix=".nc") as f: tic = time() Xb.to_netcdf(f.name, "w") -os.unlink(f.name) print(f"{time()-tic:.3f} sec. to write boolean from Numpy bool") -with tempfile.NamedTemporaryFile(suffix=".nc", delete=False) as f: +with tempfile.NamedTemporaryFile(suffix=".nc") as f: tic = time() xi = packbits(xbl, axis=0) # each column becomes uint8 BIG-ENDIAN Xi = xarray.DataArray(xi, name="uint8") Xi.to_netcdf(f.name, "w", engine="netcdf4") -os.unlink(f.name) print(f"{time()-tic:.3f} sec. to write uint8") # %% here's what nidaqmx gives us -with tempfile.NamedTemporaryFile(suffix=".nc", delete=False) as f: +with tempfile.NamedTemporaryFile(suffix=".nc") as f: tic = time() Xbl = xarray.DataArray(xbl, name="listbool") Xbl.to_netcdf(f.name, "w") -os.unlink(f.name) print(f"{time()-tic:.3f} sec. to write boolean from bool list")