From 19880324ba207e866cd4c21745e1ed5a513115a6 Mon Sep 17 00:00:00 2001 From: philipstarkey Date: Thu, 25 Jun 2020 10:48:10 +1000 Subject: [PATCH] Fix h5py deprecation warnings Addresses labscript-suite/labscript-utils#47 for this module --- labscript_devices/AlazarTechBoard.py | 6 +++--- labscript_devices/FunctionRunner/labscript_devices.py | 2 +- labscript_devices/IMAQdxCamera/blacs_workers.py | 2 +- labscript_devices/LightCrafterDMD.py | 2 +- labscript_devices/NovaTechDDS9M.py | 2 +- labscript_devices/PhaseMatrixQuickSyn.py | 2 +- labscript_devices/TekScope/blacs_workers.py | 4 ++-- labscript_devices/ZaberStageController/blacs_workers.py | 2 +- labscript_devices/imaqdx_server.py | 2 +- 9 files changed, 12 insertions(+), 12 deletions(-) diff --git a/labscript_devices/AlazarTechBoard.py b/labscript_devices/AlazarTechBoard.py index d1cecc2a..e6061d07 100644 --- a/labscript_devices/AlazarTechBoard.py +++ b/labscript_devices/AlazarTechBoard.py @@ -316,7 +316,7 @@ def init(self): def transition_to_buffered(self, device_name, h5file, initial_values, fresh): self.h5file = h5file # We'll need this in transition_to_manual self.device_name = device_name - with h5py.File(h5file) as hdf5_file: + with h5py.File(h5file, 'r') as hdf5_file: print("\nUsing "+h5file) self.atsparam = atsparam = labscript_utils.properties.get( hdf5_file, device_name, 'device_properties') @@ -379,7 +379,7 @@ def transition_to_buffered(self, device_name, h5file, initial_values, fresh): # Store the actual acquisition rate back as an attribute. # Again, this should be done as an ACQUISITIONS table entry, but not today - with h5py.File(h5file) as hdf5_file: + with h5py.File(h5file, 'r+') as hdf5_file: hdf5_file['devices'][device_name].attrs.create( 'acquisition_rate', actual_acquisition_rate, dtype='int32') @@ -585,7 +585,7 @@ def transition_to_manual(self): # Waits on the acquisition thread, and manages the lock self.wait_acquisition_complete() # Write data to HDF5 file - with h5py.File(self.h5file) as hdf5_file: + with h5py.File(self.h5file, 'r+') as hdf5_file: grp = hdf5_file.create_group('/data/traces/'+self.device_name) if self.channels & ats.CHANNEL_A: dsetA = grp.create_dataset( diff --git a/labscript_devices/FunctionRunner/labscript_devices.py b/labscript_devices/FunctionRunner/labscript_devices.py index 1ea41fe2..5f5b04a7 100644 --- a/labscript_devices/FunctionRunner/labscript_devices.py +++ b/labscript_devices/FunctionRunner/labscript_devices.py @@ -50,7 +50,7 @@ def func(shot_context, t, ...): recommended place to do it is within the group 'data/', for example: - with h5py.File(self.h5_file) as f: + with h5py.File(self.h5_file, 'r+') as f: data_group = f['data'].create_group(self.device_name) # save datasets/attributes within this group diff --git a/labscript_devices/IMAQdxCamera/blacs_workers.py b/labscript_devices/IMAQdxCamera/blacs_workers.py index 0f57240f..07b3d492 100644 --- a/labscript_devices/IMAQdxCamera/blacs_workers.py +++ b/labscript_devices/IMAQdxCamera/blacs_workers.py @@ -429,7 +429,7 @@ def transition_to_manual(self): print(f"Saving {len(self.images)}/{len(self.exposures)} images.") - with h5py.File(self.h5_filepath) as f: + with h5py.File(self.h5_filepath, 'r+') as f: # Use orientation for image path, device_name if orientation unspecified if self.orientation is not None: image_path = 'images/' + self.orientation diff --git a/labscript_devices/LightCrafterDMD.py b/labscript_devices/LightCrafterDMD.py index c72832b7..e8e0ca59 100644 --- a/labscript_devices/LightCrafterDMD.py +++ b/labscript_devices/LightCrafterDMD.py @@ -317,7 +317,7 @@ def program_manual(self, values): return {} def transition_to_buffered(self, device_name, h5file, initial_values, fresh): - with h5py.File(h5file) as hdf5_file: + with h5py.File(h5file, 'r') as hdf5_file: group = hdf5_file['/devices/'+device_name] if 'IMAGE_TABLE' in group: table_data = group['IMAGE_TABLE'][:] diff --git a/labscript_devices/NovaTechDDS9M.py b/labscript_devices/NovaTechDDS9M.py index 7907421f..956bab07 100644 --- a/labscript_devices/NovaTechDDS9M.py +++ b/labscript_devices/NovaTechDDS9M.py @@ -457,7 +457,7 @@ def transition_to_buffered(self,device_name,h5file,initial_values,fresh): self.final_values = {} static_data = None table_data = None - with h5py.File(h5file) as hdf5_file: + with h5py.File(h5file, 'r') as hdf5_file: group = hdf5_file['/devices/'+device_name] # If there are values to set the unbuffered outputs to, set them now: if 'STATIC_DATA' in group: diff --git a/labscript_devices/PhaseMatrixQuickSyn.py b/labscript_devices/PhaseMatrixQuickSyn.py index ce01a071..503d9893 100644 --- a/labscript_devices/PhaseMatrixQuickSyn.py +++ b/labscript_devices/PhaseMatrixQuickSyn.py @@ -333,7 +333,7 @@ def transition_to_buffered(self,device_name,h5file,initial_values,fresh): self.initial_values = initial_values # Store the final values to for use during transition_to_static: self.final_values = {} - with h5py.File(h5file) as hdf5_file: + with h5py.File(h5file, 'r') as hdf5_file: group = hdf5_file['/devices/'+device_name] # If there are values to set the unbuffered outputs to, set them now: if 'STATIC_DATA' in group: diff --git a/labscript_devices/TekScope/blacs_workers.py b/labscript_devices/TekScope/blacs_workers.py index b14548e3..52cdc70c 100644 --- a/labscript_devices/TekScope/blacs_workers.py +++ b/labscript_devices/TekScope/blacs_workers.py @@ -17,7 +17,7 @@ def init(self): def transition_to_buffered(self, device_name, h5file, front_panel_values, refresh): self.h5file = h5file # We'll need this in transition_to_manual self.device_name = device_name - with h5py.File(h5file) as hdf5_file: + with h5py.File(h5file, 'r') as hdf5_file: print('\n' + h5file) self.scope_params = scope_params = labscript_utils.properties.get( hdf5_file, device_name, 'device_properties') @@ -53,7 +53,7 @@ def transition_to_manual(self): data[ch] = vals[ch] # Open the file after download so as not to hog the file lock - with h5py.File(self.h5file) as hdf_file: + with h5py.File(self.h5file, 'r+') as hdf_file: grp = hdf_file.create_group('/data/traces') print('Saving traces...') dset = grp.create_dataset(self.device_name, data=data) diff --git a/labscript_devices/ZaberStageController/blacs_workers.py b/labscript_devices/ZaberStageController/blacs_workers.py index 0eec9c74..1db73f2b 100644 --- a/labscript_devices/ZaberStageController/blacs_workers.py +++ b/labscript_devices/ZaberStageController/blacs_workers.py @@ -90,7 +90,7 @@ def program_manual(self, values): return self.check_remote_values() def transition_to_buffered(self, device_name, h5file, initial_values, fresh): - with h5py.File(h5file) as hdf5_file: + with h5py.File(h5file, 'r') as hdf5_file: group = hdf5_file['/devices/' + device_name] if 'static_values' in group: data = group['static_values'] diff --git a/labscript_devices/imaqdx_server.py b/labscript_devices/imaqdx_server.py index e8ace018..e81b5ba8 100644 --- a/labscript_devices/imaqdx_server.py +++ b/labscript_devices/imaqdx_server.py @@ -363,7 +363,7 @@ def transition_to_static(self, h5_filepath): # # Just save the first however many we were expecting: # self.imgs = self.imgs[:n_images] - with h5py.File(h5_filepath) as h5_file: + with h5py.File(h5_filepath, 'r+') as h5_file: # Use orientation for image path, camera_name if orientation unspecified if self.device_properties['orientation']: image_path = self.image_path + _ensure_str(self.device_properties['orientation'])