def pre_run(self): S = self.settings # create arrays self.x_array = np.linspace(S['x0'], S['x1'], S['n_steps']) self.y_array = np.linspace(S['y0'], S['y1'], S['n_steps']) if S['retrace']: self.x_array = np.concatenate([self.x_array, self.x_array[::-1]]) self.y_array = np.concatenate([self.y_array, self.y_array[::-1]]) self.N = len(self.x_array) self.stage = self.app.hardware['attocube_xy_stage'] # data file self.h5file = h5_io.h5_base_file(self.app, measurement=self) H = self.h5measure = h5_io.h5_create_measurement_group( measurement=self, h5group=self.h5file, group_name=self.name) # Create acquisition arrays if S['collect_apd']: self.apd_counter = self.app.hardware.apd_counter self.apd_countrates = H.create_dataset( 'apd_countrates', self.N, dtype=float) # 'apd_countrate' if S['collect_spectrum']: self.spectra = H.create_dataset('spectra', (self.N, ccd_Nx), dtype=float) # 'apd_countrate' if S['collect_lifetime']: self.picoharp = self.app.hardware.picoharp self.time_traces = H.create_dataset( 'time_traces', (self.N, self.picoharp.settings['histogram_channels']), dtype=int)
def initH5CellCounter(self): """ Initialization operations for the h5 file. """ t0 = time.time() f = self.app.settings['data_fname_format'].format( app=self.app, measurement=self, timestamp=datetime.fromtimestamp(t0), sample=self.app.settings["sample"] + "_cell_counter", ext='h5') fname = os.path.join(self.app.settings['save_dir'], f) self.h5file_counter = h5_io.h5_base_file(app=self.app, measurement=self, fname=fname) self.h5_group = h5_io.h5_create_measurement_group( measurement=self, h5group=self.h5file_counter) self.h5_mean = self.h5_group.create_dataset(name='t0/c0/mean', shape=(self.N_frames, 1, 1), dtype="int16", chunks=(1, 1, 1)) self.h5_dt = self.h5_group.create_dataset(name='t0/c0/dt', shape=(self.N_frames, 1, 1), dtype="float", chunks=(1, 1, 1)) self.h5_t1 = self.h5_group.create_dataset(name='t0/c0/t1', shape=(self.N_frames, 1, 1), dtype="float", chunks=(1, 1, 1))
def run(self): self.display_update_period = 1 #seconds if self.save_data.val: self.full_optimize_history = [] self.full_optimize_history_time = [] self.t0 = time.time() while not self.interrupt_measurement_called: self.optimize_ii += 1 self.optimize_ii %= self.OPTIMIZE_HISTORY_LEN self.optimize_history_A[ self.optimize_ii] = self.ctrl.settings['T_A'] self.optimize_history_B[ self.optimize_ii] = self.ctrl.settings['T_B'] time.sleep(self.display_update_period) if self.settings['save_data']: try: self.h5_file = h5_io.h5_base_file(self.app, measurement=self) self.h5_file.attrs['time_id'] = self.t0 H = self.h5_meas_group = h5_io.h5_create_measurement_group( self, self.h5_file) #create h5 data arrays H['power_optimze_history'] = self.full_optimize_history H['optimze_history_time'] = self.full_optimize_history_time finally: self.h5_file.close()
def initH5_temp2(self): """ Initialization operations for the h5 file. """ t0 = time.time() f = self.app.settings['data_fname_format'].format( app=self.app, measurement=self, timestamp=datetime.fromtimestamp(t0), sample=self.app.settings["sample"], ext='h5') fname = os.path.join(self.app.settings['save_dir'], f) self.h5file = h5_io.h5_base_file(app=self.app, measurement=self, fname = fname) self.h5_group = h5_io.h5_create_measurement_group(measurement=self, h5group=self.h5file) img_size=self.image.shape length=self.camera.hamamatsu.number_image_buffers self.image_h5 = self.h5_group.create_dataset( name = 't0/c0/image', shape = ( length, img_size[0], img_size[1]), dtype = self.image.dtype, chunks = (1, self.eff_subarrayv, self.eff_subarrayh) ) """ THESE NAMES MUST BE CHANGED """ self.image_h5.dims[0].label = "z" self.image_h5.dims[1].label = "y" self.image_h5.dims[2].label = "x" #self.image_h5.attrs['element_size_um'] = [self.settings['zsampling'], self.settings['ysampling'], self.settings['xsampling']] self.image_h5.attrs['element_size_um'] = [1,1,1]
def run(self): self.display_update_period = 0.02 #seconds #self.apd_counter_hc = self.gui.apd_counter_hc #self.apd_count_rate = self.apd_counter_hc.apd_count_rate #self.pm_hc = self.gui.thorlabs_powermeter_hc #self.pm_analog_readout_hc = self.gui.thorlabs_powermeter_analog_readout_hc if self.save_data.val: self.full_optimize_history = [] self.full_optimize_history_time = [] self.t0 = time.time() while not self.interrupt_measurement_called: self.optimize_ii += 1 self.optimize_ii %= self.OPTIMIZE_HISTORY_LEN self.oo_spec.interrupt_measurement_called = self.interrupt_measurement_called self.oo_spec.settings['continuous'] = False self.oo_spec.settings['save_h5'] = False # if ~self.oo_spec.activation.val: # self.oo_spec.activation.update_value(True) #self.oo_spec.run() self.start_nested_measure_and_wait(self.oo_spec) spec = self.oo_spec.hw.spectrum.copy() if self.oo_spec.settings['baseline_subtract']: new_value = (spec - self.oo_spec.settings['baseline_val']).sum() else: new_value = self.pow_reading.update_value(spec.sum()) if isnan(new_value): print('spec sum nan', self.optimize_ii) self.pow_reading.update_value( self.optimize_history[self.optimize_ii - 1]) else: print('spec sum', self.optimize_ii, new_value) self.pow_reading.update_value(new_value) self.optimize_history[self.optimize_ii] = self.pow_reading.val time.sleep(self.settings['update_period']) #time.sleep(0.02) if self.settings['save_data']: try: self.h5_file = h5_io.h5_base_file(self.app, measurement=self) self.h5_file.attrs['time_id'] = self.t0 H = self.h5_meas_group = h5_io.h5_create_measurement_group( self, self.h5_file) #create h5 data arrays H['power_optimze_history'] = self.full_optimize_history H['optimze_history_time'] = self.full_optimize_history_time finally: self.h5_file.close()
def save_h5(self): # h5 data file setup self.t0 = time.time() self.h5_file = h5_io.h5_base_file(self.app, measurement=self) self.h5_filename = self.h5_file.filename self.h5_file.attrs['time_id'] = self.t0 H = self.h5_meas_group = h5_io.h5_create_measurement_group(self, self.h5_file) H['V'] = np.array(self.Varray) H['I'] = np.array(self.Iarray) self.h5_file.close()
def initH5(self): """ Initialization operations for the h5 file """ self.create_saving_directory() # file name creation timestamp = time.strftime("%y%m%d_%H%M%S", time.localtime()) sample = self.app.settings['sample'] #sample_name = f'{timestamp}_{self.name}_{sample}.h5' if sample == '': sample_name = '_'.join([timestamp, self.name]) else: sample_name = '_'.join([timestamp, self.name, sample]) fname = os.path.join(self.app.settings['save_dir'], sample_name + '.h5') # file creation self.h5file = h5_io.h5_base_file(app=self.app, measurement=self, fname=fname) self.h5_group = h5_io.h5_create_measurement_group(measurement=self, h5group=self.h5file) img_size = self.im.image[ 0].shape # both image[0] and image[1] are valid, since they have the same shape number_of_channels = len(self.channels) # take as third dimension of the file the total number of images collected in the buffer if self.camera.hamamatsu.last_frame_number < self.camera.hamamatsu.number_image_buffers: length = int((self.camera.hamamatsu.last_frame_number + 1) / number_of_channels) else: length = self.camera.hamamatsu.number_image_buffers / number_of_channels # dataset creation for ch_index in self.channels: name = f't0/c{ch_index}/image' self.image_h5[ch_index] = self.h5_group.create_dataset( name=name, shape=(length, img_size[0], img_size[1]), dtype=self.im.image[0].dtype, chunks=(1, img_size[0], img_size[1])) self.image_h5[ch_index].attrs['element_size_um'] = [ self.settings['zsampling'], self.settings['ysampling'], self.settings['xsampling'] ] self.image_h5[ch_index].attrs['acq_time'] = timestamp self.image_h5[ch_index].attrs['flowrate'] = self.settings[ 'flowrate']
def run(self): cam_hw = self.app.hardware.ascom_camera print(self.name, 'interrupted', self.interrupt_measurement_called) while not self.interrupt_measurement_called: # Blocking version #self.img = cam_hw.acq_single_exposure() # non blocking version cam_hw.ac.StartExposure(cam_hw.settings['exp_time']) t0 = time.time() while not cam_hw.ac.is_image_ready(): if self.interrupt_measurement_called: break time.sleep(0.05) self.settings['progress'] = 100.0 * ( time.time() - t0) / cam_hw.settings['exp_time'] self.img = cam_hw.ac.read_image_data() if not self.settings['continuous']: # save image try: t0 = time.time() fname = os.path.join(self.app.settings['save_dir'], "%i_%s" % (t0, self.name)) print(self.name, 'asdf', self.img.dtype, fname) if self.settings['save_ini']: self.app.settings_save_ini(fname + ".ini") if self.settings['save_png']: scipy.misc.imsave(fname + ".png", self.img) if self.settings['save_tif']: #im = PIL.Image.fromarray(self.img.T) #im.save("%i_%s.tif" % (t0, self.name), compression=6) tif_imsave(fname + ".tif", self.img.T.astype(np.uint16), compress=0) if self.settings['save_h5']: with h5_io.h5_base_file(self.app, fname=fname + ".h5") as H: M = h5_io.h5_create_measurement_group( measurement=self, h5group=H) M.create_dataset('img', data=self.img, compression='gzip') except Exception as e: print('Error saving files!', e) raise e finally: break # end the while loop for non-continuous scans else: pass
def run(self): # Set up Hardware self.andor_ccd.settings['acq_mode'] = 'single' self.andor_ccd.settings['trigger_mode'] = 'internal' self.andor_ccd.set_readout() ccd_hw = self.app.hardware['andor_ccd'] ccd_dev = ccd_hw.ccd_dev width_px = ccd_dev.Nx_ro height_px = ccd_dev.Ny_ro try: # create data file and array self.h5_file = h5_io.h5_base_file(app=self.app, measurement=self) self.h5m = h5_io.h5_create_measurement_group(measurement=self, h5group=self.h5_file) self.sweep_wls = self.settings.ranges['sweep_wls'].array self.h5m['sweep_wls'] = self.sweep_wls self.spectra = np.zeros((len(self.sweep_wls), width_px), dtype=float) self.spectra_h5 = self.h5m.create_dataset( 'spectra', shape=(len(self.sweep_wls), width_px), dtype=float) for ii, center_wl in enumerate(self.sweep_wls): if self.interrupt_measurement_called: break # move spectrometer to center wavelength self.spec.settings['center_wl'] = center_wl ccd_dev.start_acquisition() stat = ccd_hw.settings.ccd_status.read_from_hardware() while stat == 'ACQUIRING': if self.interrupt_measurement_called: break time.sleep(0.01) stat = ccd_hw.settings.ccd_status.read_from_hardware() if stat == 'IDLE': self.ccd_img = ccd_dev.get_acquired_data() self.spectrum = np.average(self.ccd_img, axis=0) self.spectra[ii, :] = self.spectrum self.spectra_h5[ii, :] = self.spectrum finally: print(self.name, 'done') self.h5_file.close()
def run(self): cam = self.spec_hw.cam print("rois|-->", cam.read_rois()) cam.commit_parameters() while not self.interrupt_measurement_called: self.t0 = time.time() dat = cam.acquire(readout_count=1, readout_timeout=-1) self.roi_data = cam.reshape_frame_data(dat) #print "roi_data shapes", [d.shape for d in self.roi_data] self.spec = spec = np.average(self.roi_data[0], axis=0) px_index = np.arange(self.spec.shape[-1]) self.hbin = self.spec_hw.settings['roi_x_bin'] if 'acton_spectrometer' in self.app.hardware: self.wls = self.app.hardware['acton_spectrometer'].get_wl_calibration(px_index, self.hbin) else: self.wls = self.hbin*px_index + 0.5*(self.hbin-1) self.pixels = self.hbin*px_index + 0.5*(self.hbin-1) self.raw_pixels = px_index self.wave_numbers = 1.0e7/self.wls self.raman_shifts = 1.0e7/self.laser_wl.val - 1.0e7/self.wls self.wls_mean = self.wls.mean() if not self.continuous.val: break if self.settings['save_h5']: self.h5_file = h5_io.h5_base_file(self.app, measurement=self ) self.h5_file.attrs['time_id'] = self.t0 H = self.h5_meas_group = h5_io.h5_create_measurement_group(self, self.h5_file) H['spectrum'] = spec H['wavelength'] = self.wls H['wave_numbers'] = self.wave_numbers H['raman_shifts'] = self.raman_shifts print('saved file') self.h5_file.close()
def save_data(self): t = time.localtime(time.time()) t_string = "{:02d}{:02d}{:02d}_{:02d}{:02d}{:02d}".format( int(str(t[0])[:-2]), t[1], t[2], t[3], t[4], t[5]) fname = os.path.join(self.app.settings['save_dir'], "%s_%s" % (t_string, self.name)) with h5_io.h5_base_file(self.app, fname=fname + ".h5") as H: print("Saving " + fname + ".h5") M = h5_io.h5_create_measurement_group(measurement=self, h5group=H) M.create_dataset('spectrum', data=self.spectrum, compression='gzip') M.create_dataset('wavelengths', data=self.wavelengths, compression='gzip')
def run(self): self.ph_hw = self.app.hardware['picoharp'] self.ph = self.ph_hw.picoharp if self.settings['use_calc_hist_chans']: self.ph_hw.settings[ 'histogram_channels'] = self.ph_hw.calc_num_hist_chans() self.sleep_time = min((max(0.1 * self.ph.Tacq * 1e-3, 0.010), 0.100)) self.t0 = time.time() while not self.interrupt_measurement_called: self.ph.start_histogram() if self.ph.Tacq < 101: time.sleep(self.ph.Tacq * 1e-3 + 5e-3) else: while not self.ph.check_done_scanning(): self.set_progress(100 * (time.time() - self.t0) / self.ph_hw.settings['Tacq']) if self.interrupt_measurement_called: break self.ph.read_histogram_data() self.ph_hw.settings.count_rate0.read_from_hardware() self.ph_hw.settings.count_rate1.read_from_hardware() time.sleep(self.sleep_time) self.ph_hw.settings.count_rate0.read_from_hardware() self.ph_hw.settings.count_rate1.read_from_hardware() self.ph.stop_histogram() self.ph.read_histogram_data() if not self.settings['continuous']: break self.data_slice = slice(0, self.ph_hw.settings['histogram_channels']) histogram_data = self.ph.histogram_data[self.data_slice] time_array = self.ph.time_array[self.data_slice] elapsed_meas_time = self.ph.read_elapsed_meas_time() if self.settings['save_h5']: self.h5_file = h5_io.h5_base_file(self.app, measurement=self) self.h5_file.attrs['time_id'] = self.t0 H = self.h5_meas_group = h5_io.h5_create_measurement_group( self, self.h5_file) H['time_histogram'] = histogram_data H['time_array'] = time_array H['elapsed_meas_time'] = elapsed_meas_time self.h5_file.close()
def init_roi_h5(self): """ Initialization operations for the h5 file """ self.create_saving_directory() # file name creation timestamp = time.strftime("%y%m%d_%H%M%S", time.localtime()) sample = self.app.settings['sample'] #sample_name = f'{timestamp}_{self.name}_{sample}_ROI.h5' sample_name = '_'.join([timestamp, self.name, sample, 'ROI.h5']) fname = os.path.join(self.app.settings['save_dir'], sample_name) # file creation self.h5_roi_file = h5_io.h5_base_file(app=self.app, measurement=self, fname = fname) self.h5_roi_group = h5_io.h5_create_measurement_group(measurement=self, h5group=self.h5_roi_file)
def snap_h5(self): # from ScopeFoundry import h5_io #self.app.hardware['asi_stage'].correct_backlash(0.02) self.h5_file = h5_io.h5_base_file(app=self.app, measurement=self) H = self.h5_meas_group = h5_io.h5_create_measurement_group( self, self.h5_file) im = self.get_rgb_image() im = np.flip(im.swapaxes(0, 1), 0) H['image'] = im self.h5_file.close() print('saved file successfully', im.sum()) return im
def _run(self): self.initial_scan_setup_plotting = True #Hardware self.keithley_hc = self.gui.keithley_sourcemeter_hc K1 = self.keithley = self.keithley_hc.keithley # h5 data file setup self.t0 = time.time() self.h5_file = h5_io.h5_base_file(self.gui, "%i_%s.h5" % (self.t0, self.name)) self.h5_file.attrs['time_id'] = self.t0 H = self.h5_meas_group = self.h5_file.create_group(self.name) h5_io.h5_save_measurement_settings(self, H) h5_io.h5_save_hardware_lq(self.gui, H) K1.resetA() K1.setAutoranges_A() K1.switchV_A_on() I, V = K1.measureIV_A(self.source_voltage_steps.val, Vmin=self.source_voltage_min.val, Vmax=self.source_voltage_max.val, KeithleyADCIntTime=1, delay=0) K1.switchV_A_off() print I print V self.Iarray = I self.Varray = V #save some data save_dict = {'I': self.Iarray, 'V': self.Varray} self.fname = "%i_photocurrent_iv.npz" % time.time() np.savez_compressed(self.fname, **save_dict) print "photocurrent_iv Saved", self.fname #create h5 data arrays H['I'] = self.Iarray H['V'] = self.Varray self.h5_file.close()
def run(self): self.display_ready = False self.hw = hw = self.app.hardware['hydraharp'] Tacq = hw.settings['Tacq'] if self.settings['auto_HistogramBins']: self.hw.update_HistogramBins() self.sleep_time = min((max(0.1*Tacq, 0.010), 0.100)) self.t0 = time.time() while not self.interrupt_measurement_called: hw.start_histogram() if Tacq < 0.1: time.sleep(Tacq+5e-3) else: while not hw.check_done_scanning(): self.set_progress( 100*(time.time() - self.t0)/Tacq ) if self.interrupt_measurement_called: break self.hist_data = hw.read_histogram_data(clear_after=False) time.sleep(self.sleep_time) hw.stop_histogram() self.hist_data = hw.read_histogram_data(clear_after=True) if not self.settings['continuous']: break elapsed_meas_time = hw.settings.ElapsedMeasTime.read_from_hardware() if self.settings['save_h5']: self.h5_file = h5_io.h5_base_file(self.app, measurement=self ) self.h5_file.attrs['time_id'] = self.t0 H = self.h5_meas_group = h5_io.h5_create_measurement_group(self, self.h5_file) H['time_histogram'] = self.hist_data[self.hw.hist_slice] H['time_array'] = self.hw.time_array[self.hw.hist_slice[-1]] H['elapsed_meas_time'] = elapsed_meas_time self.h5_file.close()
def save_image(self): print('thor_cam_capture save_image') S = self.settings t0 = time.time() fname = os.path.join(self.app.settings['save_dir'], "%i_%s" % (t0, self.name)) if S['save_ini']: self.app.settings_save_ini(fname + ".ini") if S['save_png']: self.imview.export(fname + ".png") if S['save_tif']: self.imview.export(fname + ".tif") if S['save_h5']: with h5_io.h5_base_file(app=self.app, measurement=self) as H: M = h5_io.h5_create_measurement_group(measurement=self, h5group=H) M.create_dataset('img', data=self.img, compression='gzip')
def run(self): self.t0 = time.time() #Hardware self.keithley_hw = self.app.hardware['keithley_sourcemeter'] KS = self.keithley_hw.settings self.keithley = self.keithley_hw.keithley KS['output_a_on'] = True time.sleep(0.5) #measure IV self.V_sources = self.voltage_range.sweep_array self.I_array = np.zeros_like(self.V_sources, float) self.V_array = np.zeros_like(self.V_sources, float) for i, Vs in enumerate(self.V_sources): self.ii = i self.set_progress(i / len(self.V_sources) * 100) KS['source_V_a'] = Vs time.sleep(KS['delay_time_a']) self.keithley_hw.settings.I_a.read_from_hardware() self.keithley_hw.settings.V_a.read_from_hardware() self.I_array[i] = KS["I_a"] self.V_array[i] = KS["V_a"] self.collect_Vs(i, Vs, KS["I_a"], KS["V_a"]) KS['output_a_on'] = False if self.settings['save_h5']: self.h5_file = h5_io.h5_base_file(self.app, measurement=self) self.h5_filename = self.h5_file.filename self.h5_file.attrs['time_id'] = self.t0 H = self.h5_meas_group = h5_io.h5_create_measurement_group( self, self.h5_file) H['V_sourced'] = self.V_sources H['V'] = np.array(self.V_array) H['I'] = np.array(self.I_array) self.save_collected() self.h5_file.close()
def run(self): self.display_update_period = 0.02 #seconds #self.apd_counter_hc = self.gui.apd_counter_hc #self.apd_count_rate = self.apd_counter_hc.apd_count_rate #self.pm_hc = self.gui.thorlabs_powermeter_hc #self.pm_analog_readout_hc = self.gui.thorlabs_powermeter_analog_readout_hc if self.save_data.val: self.full_optimize_history = [] self.full_optimize_history_time = [] self.t0 = time.time() while not self.interrupt_measurement_called: self.optimize_ii += 1 self.optimize_ii %= self.OPTIMIZE_HISTORY_LEN pow_reading = self.powermeter.settings.power.read_from_hardware() #pow_reading = self.powermeter.power_meter.measure_power() self.optimize_history[self.optimize_ii] = pow_reading #self.pm_analog_readout_hc.voltage.read_from_hardware() if self.save_data.val: self.full_optimize_history.append(pow_reading) self.full_optimize_history_time.append(time.time() - self.t0) time.sleep(self.settings['update_period']) #time.sleep(0.02) if self.settings['save_data']: try: self.h5_file = h5_io.h5_base_file(self.app, measurement=self) self.h5_file.attrs['time_id'] = self.t0 H = self.h5_meas_group = h5_io.h5_create_measurement_group( self, self.h5_file) #create h5 data arrays H['power_optimze_history'] = self.full_optimize_history H['optimze_history_time'] = self.full_optimize_history_time finally: self.h5_file.close()
def initH5(self): """ Initialization operations for the h5 file. """ self.h5file = h5_io.h5_base_file(app=self.app, measurement=self) self.h5_group = h5_io.h5_create_measurement_group(measurement=self, h5group=self.h5file) img_size = self.image.shape length = self.camera.pixelink.number_frames self.image_h5 = self.h5_group.create_dataset( name='t0/c0/image', shape=(self.camera.pixelink.number_frames, self.eff_img_height, self.eff_img_width), dtype=self.image.dtype) self.image_h5.dims[0].label = "z" self.image_h5.dims[1].label = "y" self.image_h5.dims[2].label = "x" self.image_h5.attrs['element_size_um'] = [1, 1, 1]
def initH5(self): """ Initialization operations for the h5 file. """ self.create_saving_directory() # file name creation timestamp = time.strftime("%y%m%d_%H%M%S", time.localtime()) sample = self.app.settings['sample'] #sample_name = f'{timestamp}_{self.name}_{sample}.h5' if sample == '': sample_name = '_'.join([timestamp, self.name]) else: sample_name = '_'.join([timestamp, self.name, sample]) fname = os.path.join(self.app.settings['save_dir'], sample_name + '.h5') # file creation self.h5file = h5_io.h5_base_file(app=self.app, measurement=self, fname=fname) self.h5_group = h5_io.h5_create_measurement_group(measurement=self, h5group=self.h5file) img_size = self.image.shape length = self.camera.hamamatsu.number_image_buffers self.image_h5 = self.h5_group.create_dataset( name='t0/c0/image', shape=(length, img_size[0], img_size[1]), dtype=self.image.dtype, chunks=(1, self.eff_subarrayv, self.eff_subarrayh)) self.image_h5.dims[0].label = "z" self.image_h5.dims[1].label = "y" self.image_h5.dims[2].label = "x" #self.image_h5.attrs['element_size_um'] = [self.settings['zsampling'], self.settings['ysampling'], self.settings['xsampling']] self.image_h5.attrs['element_size_um'] = [ 1, 1, 1 ] # required for compatibility with imageJ
def initH5(self): """ Initialization operations for the h5 file. """ self.h5file = h5_io.h5_base_file(app=self.app, measurement=self) self.h5_group = h5_io.h5_create_measurement_group(measurement=self, h5group=self.h5file) img_size=self.image.shape length=self.camera.hamamatsu.number_image_buffers self.image_h5 = self.h5_group.create_dataset( name = 't0/c0/image', shape = ( length, img_size[0], img_size[1]), dtype = self.image.dtype, chunks = (1, self.eff_subarrayv, self.eff_subarrayh) ) """ THESE NAMES MUST BE CHANGED """ self.image_h5.dims[0].label = "z" self.image_h5.dims[1].label = "y" self.image_h5.dims[2].label = "x" #self.image_h5.attrs['element_size_um'] = [self.settings['zsampling'], self.settings['ysampling'], self.settings['xsampling']] self.image_h5.attrs['element_size_um'] = [1,1,1]
def create_h5_file(self): self.create_saving_directory() # file name creation timestamp = time.strftime("%y%m%d_%H%M%S", time.localtime()) sample = self.app.settings['sample'] #sample_name = f'{timestamp}_{self.name}_{sample}.h5' if sample == '': sample_name = '_'.join([timestamp, self.name]) else: sample_name = '_'.join([timestamp, self.name, sample]) fname = os.path.join(self.app.settings['save_dir'], sample_name + '.h5') self.h5file = h5_io.h5_base_file(app=self.app, measurement=self, fname = fname) self.h5_group = h5_io.h5_create_measurement_group(measurement=self, h5group=self.h5file) img_size = self.img.shape dtype=self.img.dtype length = self.image_gen.frame_num.val self.image_h5 = self.h5_group.create_dataset(name = 't0/c0/image', shape = [length, img_size[0], img_size[1]], dtype = dtype) self.image_h5.attrs['element_size_um'] = [self.settings['zsampling'],self.settings['ysampling'],self.settings['xsampling']]
def run(self): self.t0 = time.time() self.spec_readout.settings['continuous'] = False self.spectra = [] self.center_wls = [] #center wls read from spectrometer for center_wl in self.center_wl_range.array: self.spec_center_wl.update_value(center_wl) time.sleep(1) self.start_nested_measure_and_wait(self.spec_readout, polling_time=0.1, start_time=0.1) self.spectra.append(self.spec_readout.spec) self.center_wls.append(self.spec_center_wl.val) self.h5_file = h5_io.h5_base_file(self.app, measurement=self) self.h5_file.attrs['time_id'] = self.t0 H = self.h5_meas_group = h5_io.h5_create_measurement_group( self, self.h5_file) H['spectra'] = np.array(self.spectra) H['center_wls'] = np.array(self.center_wls) self.h5_file.close()
def run(self): if len(self.used_hws) == 0: self.status = {'title':'Select a Collection Option and press Start', 'color':'r'} return else: ETA = datetime.timedelta(seconds=int(self.total_acquisition_time) ) self.status = {'title':'Power scan total acquisition time in h:mm:ss {}'.format(str(ETA)), 'color':'g'} self.move_to_min_pos() # loop through power wheel positions and measure active components. for ii in range(self.Np): self.ii = ii self.settings['progress'] = 100.*ii/self.Np if self.interrupt_measurement_called: break for hw, Tacq_lq, acq_times_array in self.Tacq_arrays: print("power scan {} of {}, {} acq_times {}".format(ii + 1, self.Np, hw, acq_times_array[ii])) Tacq_lq.update_value(acq_times_array[ii]) print("moving power wheel to " + str(self.power_wheel_hw.settings['position']) ) self.power_wheel_hw.settings['position'] = self.power_wheel_position[ii] time.sleep(0.25) # collect power meter value self.pm_powers[ii]=self.collect_pm_power_data() # read detectors if self.settings['collect_apd_counter']: time.sleep(self.apd_counter_hw.settings['int_time']) self.apd_count_rates[ii] = \ self.apd_counter_hw.settings.count_rate.read_from_hardware() if self.settings['collect_picoharp']: ph = self.ph_hw.picoharp ph.start_histogram() while not ph.check_done_scanning(): if self.interrupt_measurement_called: break ph.read_histogram_data() time.sleep(0.1) ph.stop_histogram() ph.read_histogram_data() Nt = self.ph_hw.settings['histogram_channels'] self.picoharp_elapsed_time[ii] = ph.read_elapsed_meas_time() self.picoharp_histograms[ii,:] = ph.histogram_data[0:Nt] self.picoharp_time_array = ph.time_array[0:Nt] if self.settings['collect_hydraharp']: self.hydraharp_histograms[ii,:] = self.aquire_histogram(self.hh_hw) self.hydraharp_time_array = self.hh_hw.sliced_time_array self.hydraharp_elapsed_time[ii] = self.hh_hw.settings['ElapsedMeasTime'] if self.settings['collect_winspec_remote_client']: #self.spec_readout.run() self.spec_readout.settings['continuous'] = False self.spec_readout.settings['save_h5'] = False self.spec_readout.interrupt_measurement_called = False self.spec_readout.run() time.sleep(0.5) Tacq_lq = self.installed_hw['winspec_remote_client'] #time.sleep(Tacq_lq.val) spec = np.array(self.spec_readout.data) self.spectra.append(spec) self.integrated_spectra.append(spec.sum()) if self.settings['collect_andor_ccd']: self.andor_readout.settings['read_single'] = True self.start_nested_measure_and_wait(self.andor_readout) spec = self.andor_readout.get_spectrum() self.spectra.append(spec) self.integrated_spectra.append(spec.sum()) if self.settings['collect_ascom_img']: self.ascom_camera_capture.interrupt_measurement_called = False self.ascom_camera_capture.run() img = self.ascom_camera_capture.img.copy()/self.ascom_camera_capture.settings['exp_time'] self.ascom_img_stack.append(img) self.ascom_img_integrated.append(img.astype(float).sum()) # collect power meter value after measurement self.pm_powers_after[ii]=self.collect_pm_power_data() self.status = {'title':'Power scan finished', 'color':'y'} # write data to h5 file on disk self.t0 = time.time() self.h5_file = h5_io.h5_base_file(app=self.app,measurement=self) try: self.h5_file.attrs['time_id'] = self.t0 H = self.h5_meas_group = h5_io.h5_create_measurement_group(self, self.h5_file) if self.settings['collect_apd_counter']: H['apd_count_rates'] = self.apd_count_rates if self.settings['collect_picoharp']: H['picoharp_elapsed_time'] = self.picoharp_elapsed_time H['picoharp_histograms'] = self.picoharp_histograms H['picoharp_time_array'] = self.picoharp_time_array if self.settings['collect_hydraharp']: H['hydraharp_elapsed_time'] = self.hydraharp_elapsed_time H['hydraharp_histograms'] = self.hydraharp_histograms H['hydraharp_time_array'] = self.hydraharp_time_array if self.settings['collect_winspec_remote_client']: H['wls'] = self.spec_readout.wls H['spectra'] = np.squeeze(np.array(self.spectra)) H['integrated_spectra'] = np.array(self.integrated_spectra) if self.settings['collect_andor_ccd']: H['wls'] = self.andor_readout.wls H['spectra'] = np.squeeze(np.array(self.spectra)) H['integrated_spectra'] = np.array(self.integrated_spectra) if self.settings['collect_ascom_img']: H['ascom_img_stack'] = np.array(self.ascom_img_stack) H['ascom_img_integrated'] = np.array(self.ascom_img_integrated) H['pm_powers'] = self.pm_powers H['pm_powers_after'] = self.pm_powers_after H['power_wheel_position'] = self.power_wheel_position for hw, Tacq_lq, acq_times_array in self.Tacq_arrays: H[hw + '_acq_times_array'] = acq_times_array print('saving ' + hw + '_acq_times_array') finally: self.log.info("data saved " + self.h5_file.filename) self.h5_file.close()
def run(self): self.first_display = True self.do_callback_times = [] self.img= np.zeros((self.settings['image_size_x'],self.settings['image_size_y']), dtype=np.float) self.counts= np.zeros((self.settings['image_size_x'],self.settings['image_size_y']), dtype=np.float) try: self.setup_tasks() # Create h5 arrays self.h5_file = h5_io.h5_base_file(self.app, measurement=self) self.h5_filename = self.h5_file.filename self.h5_m = h5_io.h5_create_measurement_group(measurement=self, h5group=self.h5_file) self.ao_data_h5 = self.h5_m.create_dataset('ao_data', shape=(self.N_ao, self.ao_chan_count), maxshape=(None, self.ao_chan_count), dtype=float, chunks=(self.N_ao, self.ao_chan_count)) self.ai_data_h5 = self.h5_m.create_dataset('ai_data', shape=(self.N_ai, self.ai_chan_count), maxshape=(None, self.ai_chan_count), dtype=float, chunks=(self.N_ai, self.ai_chan_count)) self.i_processed = 0 #KDE interp (it overwrites the one created in setup()) Nx=self.settings['image_size_x'] Ny=self.settings['image_size_y'] Ax=self.settings['amplitude_x'] Ay=self.settings['amplitude_y'] self.kde_img = KDE_Image((Ny,Nx), self.settings['kde_sigma']) ### Start Output Tasks self.ao_task.StartTask() self.do_task.StartTask() block_i=0 t00=time.time() while not self.interrupt_measurement_called: #time.sleep(0.1) if len(self.ao_block_queue) > 0: # pop things off queue i_ao, ao_block = self.ao_block_queue.pop(0) assert ao_block.shape[0] == self.N_ao # store in h5 dataset if i_ao >= self.ao_data_h5.shape[0]: self.ao_data_h5.resize((i_ao+self.N_ao, self.ao_chan_count)) self.ao_data_h5[i_ao:i_ao+self.N_ao,:] = ao_block # process block if len(self.ai_block_queue) > 0: # pop things off queue i_ai, ai_block = self.ai_block_queue.pop(0) assert ai_block.shape[0] == self.N_ai # store in h5 dataset if i_ai >= self.ai_data_h5.shape[0]: self.ai_data_h5.resize((i_ai+self.N_ai, self.ai_chan_count)) self.ai_data_h5[i_ai:i_ai+self.N_ai,:] = ai_block # process block if self.ai_data_h5.shape[0] > self.i_processed: x = self.ao_data_h5[self.i_processed: self.i_processed + self.N_ao, 0] y = self.ao_data_h5[self.i_processed: self.i_processed + self.N_ao, 1] #we are choosing here analog input channel 0 as signal z = self.ai_data_h5[self.i_processed: self.i_processed + self.N_ai, 0] # print ("x",x) # print ("y",y) # print ("z",z) # # Quick interpolation x_img=np.uint32((Nx-1)/2*x/Ax+(Nx)/2) y_img=np.uint32((Ny-1)/2*y/Ay+(Ny)/2) # for ii in range(len(x)): # #self.img[x_img[ii],y_img[ii]]+=z[ii] # self.counts[x_img[ii],y_img[ii]]+=1 # cc=self.counts[x_img[ii],y_img[ii]] # old_z=self.img[x_img[ii],y_img[ii]] # new_z=(old_z*(cc-1)+z[ii])/cc # self.img[x_img[ii],y_img[ii]]=new_z # ### KDE x_img=(Nx-1)/2*x/Ax+(Nx)/2 y_img=(Ny-1)/2*y/Ay+(Ny)/2 x_img = np.clip(x_img, 4, Nx-4) y_img = np.clip(y_img, 4, Ny-4) t0=time.time() self.kde_img.add_datapoints(x_img, y_img,z) print('Elapsed time for adding chunk to image:', round(time.time()-t0,3)) self.i_processed += self.N_ao block_i+=1 #print('Acquired samples:' , block_i*self.N_ai) if (block_i*self.N_ai) > 2e6: print('While loop terminated') break print('Elapsed time for all in while loop:', round(time.time()-t00,3)) # Optional: store old blocks in a finite sized buffer finally: self.stop_tasks()
def saveMeasurements(self): if list_equal(self.imageRaw_store, self.imageRAW): self.show_text("Raw images are not saved: the same measurement.") else: timestamp = time.strftime("%y%m%d_%H%M%S", time.localtime()) sample = self.app.settings['sample'] if sample == '': sample_name = '_'.join([timestamp, self.name]) else: sample_name = '_'.join([timestamp, self.name, sample]) # create file path for both h5 and other types of files pathname = os.path.join(self.app.settings['save_dir'], sample_name) Path(pathname).mkdir(parents=True, exist_ok=True) self.pathname = pathname self.sample_name = sample_name # create h5 base file if the h5 file is not exist if self.ui.saveH5.isChecked(): # create h5 file for raw fname_raw = os.path.join(pathname, sample_name + '_Raw.h5') self.h5file_raw = h5_io.h5_base_file(app=self.app, measurement=self, fname=fname_raw) # save measure component settings h5_io.h5_create_measurement_group(measurement=self, h5group=self.h5file_raw) for ch_idx in range(2): gname = f'data/c{ch_idx}/raw' if np.sum(self.imageRAW[ch_idx] ) == 0: # remove the empty channel self.h5file_raw.create_dataset(gname, data=h5py.Empty("f")) self.show_text("[H5] Raw images are empty.") else: self.h5file_raw.create_dataset( gname, data=self.imageRAW[ch_idx]) self.show_text("[H5] Raw images are saved.") self.h5file_raw.close() if self.ui.saveTif.isChecked(): for ch_idx in range(2): fname_raw = os.path.join( pathname, sample_name + f'_Raw_Ch{ch_idx}.tif') if np.sum(self.imageRAW[ch_idx] ) != 0: # remove the empty channel tif.imwrite(fname_raw, np.single(self.imageRAW[ch_idx])) self.show_text("[Tif] Raw images are saved.") else: self.show_text("[Tif] Raw images are empty.") self.imageRaw_store = self.imageRAW # store the imageRAW for comparision if self.isCalibrated: if self.ui.saveH5.isChecked(): fname_pro = os.path.join( self.pathname, self.sample_name + f'_C{self.current_channel_display()}_Processed.h5') self.h5file_pro = h5_io.h5_base_file(app=self.app, measurement=self, fname=fname_pro) h5_io.h5_create_measurement_group(measurement=self, h5group=self.h5file_pro) name = f'data/sim' if np.sum(self.imageSIM) == 0: dset = self.h5file_pro.create_dataset(name, data=h5py.Empty("f")) self.show_text("[H5] SIM images are empty.") else: dset = self.h5file_pro.create_dataset(name, data=self.imageSIM) self.show_text("[H5] SIM images are saved.") dset.attrs['kx'] = self.kx_full dset.attrs['ky'] = self.ky_full if self.numSets != 0: for idx in range(self.numSets): roi_group_name = f'data/roi/{idx:03}' raw_set = self.h5file_pro.create_dataset( roi_group_name + '/raw', data=self.imageRaw_ROI[idx]) raw_set.attrs['cx'] = self.oSegment.selected_cx[idx] raw_set.attrs['cy'] = self.oSegment.selected_cy[idx] sim_set = self.h5file_pro.create_dataset( roi_group_name + '/sim', data=self.imageSIM_ROI[idx]) sim_set.attrs['kx'] = self.kx_roi[idx] sim_set.attrs['ky'] = self.ky_roi[idx] self.show_text("[H5] ROI images are saved.") self.h5file_pro.close() if self.ui.saveTif.isChecked(): fname_sim = os.path.join( self.pathname, self.sample_name + f'_C{self.current_channel_display()}_SIM' + '.tif') fname_ini = os.path.join( self.pathname, self.sample_name + f'_C{self.current_channel_display()}_Settings' + '.ini') if np.sum(self.imageSIM) != 0: tif.imwrite(fname_sim, np.single(self.imageSIM)) self.app.settings_save_ini(fname_ini, save_ro=False) self.show_text("[Tif] SIM images are saved.") else: self.show_text("[Tif] SIM images are empty.") if self.numSets != 0: for idx in range(self.numSets): fname_roi = os.path.join( self.pathname, self.sample_name + f'_Roi_C{self.current_channel_display()}_{idx:003}_SIM' + '.tif') tif.imwrite(fname_roi, np.single(self.imageSIM_ROI[idx])) self.show_text("[Tif] ROI images are saved.")
def _run(self): #hardware self.stage = self.gui.mcl_xyz_stage_hc self.nanodrive = self.stage.nanodrive # Data arrays self.h_array = np.arange(self.h0.val, self.h1.val, self.dh.val, dtype=float) self.v_array = np.arange(self.v0.val, self.v1.val, self.dv.val, dtype=float) self.Nh = len(self.h_array) self.Nv = len(self.v_array) self.range_extent = [ self.h0.val, self.h1.val, self.v0.val, self.v1.val ] self.corners = [ self.h_array[0], self.h_array[-1], self.v_array[0], self.v_array[-1] ] self.imshow_extent = [ self.h_array[0] - 0.5 * self.dh.val, self.h_array[-1] + 0.5 * self.dh.val, self.v_array[0] - 0.5 * self.dv.val, self.v_array[-1] + 0.5 * self.dv.val ] # h5 data file setup self.t0 = time.time() self.h5_file = h5_io.h5_base_file(self.gui, "%i_%s.h5" % (self.t0, self.name)) self.h5_file.attrs['time_id'] = self.t0 self.h5_meas_group = self.h5_file.create_group(self.name) #h5_io.h5_save_measurement(self, self.h5_meas_group) h5_io.h5_save_measurement_settings(self, self.h5_file['/']) self.h5_meas_group.create_dataset(name='h_array', data=self.h_array, compression='gzip', shuffle=True) self.h5_meas_group.create_dataset(name='v_array', data=self.v_array, compression='gzip', shuffle=True) self.h5_meas_group.attrs['Nv'] = self.Nv self.h5_meas_group.attrs['Nh'] = self.Nh self.h5_meas_group.attrs['range_extent'] = self.range_extent self.h5_meas_group.attrs['corners'] = self.corners self.h5_meas_group.attrs['imshow_extent'] = self.imshow_extent #scan specific setup self.pre_scan_setup() # TODO Stop other timers?! print "scanning" self.current_pixel_num = 0 self.t_scan_start = time.time() try: v_axis_id = self.stage.v_axis_id h_axis_id = self.stage.h_axis_id # move slowly to start position start_pos = [None, None, None] start_pos[v_axis_id - 1] = self.v_array[0] start_pos[h_axis_id - 1] = self.h_array[0] #print "scan.." print start_pos self.nanodrive.set_pos_slow(*start_pos) # Scan! line_time0 = time.time() for i_v in range(self.Nv): if self.interrupt_measurement_called: break self.v_pos = self.v_array[i_v] self.nanodrive.set_pos_ax(self.v_pos, v_axis_id) #self.read_stage_position() if i_v % 2: #odd lines h_line_indicies = range(self.Nh)[::-1] else: #even lines -- traverse in opposite direction h_line_indicies = range(self.Nh) for i_h in h_line_indicies: if self.interrupt_measurement_called: break self.h_pos = self.h_array[i_h] self.nanodrive.set_pos_ax(self.h_pos, h_axis_id) # collect data self.collect_pixel(i_h, i_v) self.current_pixel_num += 1 T_pixel = float(time.time() - line_time0) / self.Nh print "line time:", time.time() - line_time0 line_time0 = time.time() self.progress.update_value(self.current_pixel_num * 100. / (self.Nv * self.Nh)) total_px = self.Nv * self.Nh print "time per pixel:", T_pixel, '| estimated total time (h)', total_px * T_pixel / 3600, '| Nh, Nv:', self.Nh, self.Nv, Time_finish = time.localtime(total_px * T_pixel + self.t_scan_start) print '| scan finishes at: {:02d}:{:02d}'.format( Time_finish.tm_hour, Time_finish.tm_min) # read stage position every line self.stage.read_pos() #scanning done self.post_scan_cleanup() #except Exception as err: # self.interrupt() # raise err finally: #save data file save_dict = { 'h_array': self.h_array, 'v_array': self.v_array, 'Nv': self.Nv, 'Nh': self.Nh, 'range_extent': self.range_extent, 'corners': self.corners, 'imshow_extent': self.imshow_extent, } save_dict.update(self.scan_specific_savedict()) for lqname, lq in self.gui.logged_quantities.items(): save_dict[lqname] = lq.val for hc in self.gui.hardware_components.values(): for lqname, lq in hc.logged_quantities.items(): save_dict[hc.name + "_" + lqname] = lq.val for lqname, lq in self.logged_quantities.items(): save_dict[self.name + "_" + lqname] = lq.val self.fname = "%i_%s.npz" % (self.t0, self.name) np.savez_compressed(self.fname, **save_dict) print self.name, "saved:", self.fname #h5 file self.h5_file.close() if not self.interrupt_measurement_called: self.measurement_sucessfully_completed.emit() else: pass
def saveMeasurements(self): timestamp = time.strftime("%y%m%d_%H%M%S", time.localtime()) ch = self.current_channel_process() # selected channel if self.isCalibrated: if self.ui.saveH5.isChecked(): if list_equal(self.imageSIM_store, self.imageSIM): self.show_text("[NOT SAVED]\tSIM images are identical.") else: # create file name for the processed file fname_pro = os.path.join( self.filepath, self.filetitle + f'_{timestamp}_C{self.current_channel_process()}_Processed.h5' ) # create H5 file self.h5file_pro = h5_io.h5_base_file(app=self.app, measurement=self, fname=fname_pro) # create measurement group and save measurement settings h5_io.h5_create_measurement_group(measurement=self, h5group=self.h5file_pro) # name of the sim image group sim_name = f'data/sim' avg_name = f'data/avg' std_name = f'data/std' if np.sum(self.imageSIM) == 0: dset = self.h5file_pro.create_dataset( sim_name, data=h5py.Empty("f")) dset_1 = self.h5file_pro.create_dataset( avg_name, data=h5py.Empty("f")) dset_2 = self.h5file_pro.create_dataset( std_name, data=h5py.Empty("f")) # self.show_text("[UNSAVED] SIM images are empty.") else: dset = self.h5file_pro.create_dataset( sim_name, data=self.imageSIM) dset_1 = self.h5file_pro.create_dataset( avg_name, data=self.imageAVG) dset_2 = self.h5file_pro.create_dataset( std_name, data=self.imageSTD) self.show_text("[SAVED]\tSIM images to <H5>.") dset.attrs['kx'] = self.kx_full dset.attrs['ky'] = self.ky_full if self.numSets != 0: for idx in range(self.numSets): roi_group_name = f'data/roi/{idx:03}' raw_set = self.h5file_pro.create_dataset( roi_group_name + '/raw', data=self.imageRAW_ROI[idx]) raw_set.attrs['cx'] = self.oSegment.selected_cx[ idx] raw_set.attrs['cy'] = self.oSegment.selected_cy[ idx] sim_set = self.h5file_pro.create_dataset( roi_group_name + '/sim', data=self.imageSIM_ROI[idx]) sim_set.attrs['kx'] = self.kx_roi[idx] sim_set.attrs['ky'] = self.ky_roi[idx] avg_set = self.h5file_pro.create_dataset( roi_group_name + '/avg', data=self.imageAVG_ROI[idx]) std_set = self.h5file_pro.create_dataset( roi_group_name + '/std', data=self.imageSTD_ROI[idx]) self.show_text("[SAVED]\tROI images to <H5>.") self.h5file_pro.close() if self.ui.saveTif.isChecked(): fname_sim = os.path.join( self.filepath, self.filetitle + f'_{timestamp}_C{self.current_channel_process()}_SIM' + '.tif') fname_ini = os.path.join( self.filepath, self.filetitle + f'_{timestamp}_C{self.current_channel_process()}_Settings' + '.ini') fname_avg = os.path.join( self.filepath, self.filetitle + f'_{timestamp}_C{self.current_channel_process()}_AVG' + '.tif') fname_std = os.path.join( self.filepath, self.filetitle + f'_{timestamp}_C{self.current_channel_process()}_STD' + '.tif') self.app.settings_save_ini(fname_ini, save_ro=False) if np.sum(self.imageSIM) != 0: tif.imwrite(fname_sim, np.single(self.imageSIM)) tif.imwrite(fname_avg, np.single(self.imageAVG)) tif.imwrite(fname_std, np.single(self.imageSTD)) self.show_text("[SAVED]\tSIM images to <TIFF>.") # else: # self.show_text("[UNSAVED] SIM images are empty.") if self.numSets != 0: for idx in range(self.numSets): fname_roi_sim = os.path.join( self.filepath, self.filetitle + f'_{timestamp}_Roi_C{self.current_channel_process()}_{idx:003}_SIM' + '.tif') fname_roi_avg = os.path.join( self.filepath, self.filetitle + f'_{timestamp}_Roi_C{self.current_channel_process()}_{idx:003}_AVG' + '.tif') fname_roi_std = os.path.join( self.filepath, self.filetitle + f'_{timestamp}_Roi_C{self.current_channel_process()}_{idx:003}_STD' + '.tif') tif.imwrite(fname_roi_sim, np.single(self.imageSIM_ROI[idx])) tif.imwrite(fname_roi_avg, np.single(self.imageAVG_ROI[idx])) tif.imwrite(fname_roi_std, np.single(self.imageSTD_ROI[idx])) self.show_text("[SAVED]\tROI images to <TIFF>.")
def run(self): """ Runs when measurement is started. Runs in a separate thread from GUI. It should not update the graphical interface directly, and should only focus on data acquisition. """ self.buffer = np.zeros((60000,2)) self.track_cam._dev.set_buffer_count(500) # if enabled will create an HDF5 file with the plotted data # first we create an H5 file (by default autosaved to app.settings['save_dir'] # This stores all the hardware and app meta-data in the H5 file if self.settings.save_video.value(): save_dir = self.app.settings.save_dir.value() data_path = os.path.join(save_dir,self.app.settings.sample.value()) try: os.makedirs(data_path) except OSError: print('directory already exist, writing to existing directory') frame_rate = self.track_cam.settings.frame_rate.value() self.recorder.settings.path.update_value(data_path) self.recorder.create_file('track_mov',frame_rate) #save h5 file_name_index=0 file_name=os.path.join(self.recorder.settings.path.value(),'trail_'+str(file_name_index)+'.h5') while os.path.exists(file_name): file_name_index+=1 file_name=os.path.join(self.recorder.settings.path.value(),'trail_'+str(file_name_index)+'.h5') self.h5file = h5_io.h5_base_file(app=self.app, measurement=self,fname = file_name) # create a measurement H5 group (folder) within self.h5file # This stores all the measurement meta-data in this group self.h5_group = h5_io.h5_create_measurement_group(measurement=self, h5group=self.h5file) # create an h5 dataset to store the data self.buffer_h5 = self.h5_group.create_dataset(name = 'buffer', shape = self.buffer.shape, dtype = self.buffer.dtype) # self.recorder.create_file('wide_mov',frame_rate) self.track_disp_queue = queue.Queue(1000) # self.wide_disp_queue = queue.Queue(1000) self.motor_queue = queue.Queue(1000) self.comp_thread = SubMeasurementQThread(self.camera_action) self.motor_thread = SubMeasurementQThread(self.motor_action) self.interrupt_subthread.connect(self.comp_thread.interrupt) self.interrupt_subthread.connect(self.motor_thread.interrupt) self.pid = PIDController(p = self.settings.proportional.value(), i = self.settings.integral.value(), d = self.settings.derivative.value()) self.midpoint = (self.track_cam.settings.height.value()//self.settings.binning.value())//2 self.pix_size = self.settings.pixel_size.value() * self.settings.binning.value() try: self.track_i = 0 self.i = 0 # self.wide_i = 0 self.track_flag = False self.track_cam.start() # self.wide_cam.start() self.comp_thread.start() self.motor_thread.start() # Will run forever until interrupt is called. while not self.interrupt_measurement_called: #wait for 0.1ms time.sleep(0.5) if self.interrupt_measurement_called: # Listen for interrupt_measurement_called flag. # This is critical to do, if you don't the measurement will # never stop. # The interrupt button is a polite request to the # Measurement thread. We must periodically check for # an interrupt request self.interrupt_subthread.emit() break finally: self.track_cam.stop() # self.wide_cam.stop() if self.settings.save_video.value(): self.recorder.close() del self.motor_thread del self.comp_thread del self.motor_queue del self.track_disp_queue if self.settings.save_video.value(): self.recorder.close() self.h5file.close()