File tree 2 files changed +6
-9
lines changed 2 files changed +6
-9
lines changed Original file line number Diff line number Diff line change 16
16
xb = random (SIZE ) > 0.5 # mean ~ 0.5
17
17
xbl = xb .tolist ()
18
18
19
- with tempfile .NamedTemporaryFile () as fn :
19
+ with tempfile .NamedTemporaryFile (suffix = ".h5" ) as fn :
20
20
with h5py .File (fn , "w" ) as h :
21
21
tic = time ()
22
22
h ["bool" ] = xb
29
29
# %% here's what nidaqmx gives us
30
30
tic = time ()
31
31
h ["listbool" ] = xbl
32
- print (f"{ time ()- tic :3e} sec. to write boolean from bool list" )
32
+ # outside context manager to help ensure HDF5 file is finalized
33
+ print (f"{ time ()- tic :3e} sec. to write boolean from bool list" )
Original file line number Diff line number Diff line change 19
19
from numpy import packbits
20
20
import xarray
21
21
from time import time
22
- import os
23
22
24
23
25
24
SIZE = (3 , 200000 ) # arbitrary size to test
30
29
Xb = xarray .DataArray (xb , name = "bool" )
31
30
32
31
33
- with tempfile .NamedTemporaryFile (suffix = ".nc" , delete = False ) as f :
32
+ with tempfile .NamedTemporaryFile (suffix = ".nc" ) as f :
34
33
tic = time ()
35
34
Xb .to_netcdf (f .name , "w" )
36
- os .unlink (f .name )
37
35
print (f"{ time ()- tic :.3f} sec. to write boolean from Numpy bool" )
38
36
39
- with tempfile .NamedTemporaryFile (suffix = ".nc" , delete = False ) as f :
37
+ with tempfile .NamedTemporaryFile (suffix = ".nc" ) as f :
40
38
tic = time ()
41
39
xi = packbits (xbl , axis = 0 ) # each column becomes uint8 BIG-ENDIAN
42
40
Xi = xarray .DataArray (xi , name = "uint8" )
43
41
Xi .to_netcdf (f .name , "w" , engine = "netcdf4" )
44
- os .unlink (f .name )
45
42
print (f"{ time ()- tic :.3f} sec. to write uint8" )
46
43
# %% here's what nidaqmx gives us
47
- with tempfile .NamedTemporaryFile (suffix = ".nc" , delete = False ) as f :
44
+ with tempfile .NamedTemporaryFile (suffix = ".nc" ) as f :
48
45
tic = time ()
49
46
Xbl = xarray .DataArray (xbl , name = "listbool" )
50
47
Xbl .to_netcdf (f .name , "w" )
51
- os .unlink (f .name )
52
48
print (f"{ time ()- tic :.3f} sec. to write boolean from bool list" )
You can’t perform that action at this time.
0 commit comments