def fetch(filename, nevents, nsequence): ''' Fetch and save waveform traces from the oscilloscope. ''' scope = LeCroyScope(config.ip, timeout=config.timeout) scope.clear() scope.set_sequence_mode(nsequence) channels = scope.get_channels() # print(channels) settings = scope.get_settings() # print(settings) if b'ON' in settings['SEQUENCE']: sequence_count = int(settings['SEQUENCE'].split(',')[1]) else: sequence_count = 1 if nsequence != sequence_count: print('Could not configure sequence mode properly') if sequence_count != 1: print('Using sequence mode with %i traces per aquisition' % sequence_count) current_dim = {} for channel in channels: wave_desc = scope.get_wavedesc(channel) current_dim[channel] = wave_desc['wave_array_count'] // sequence_count try: i = 0 while i < nevents: print('\rfetching event: %i' % i) sys.stdout.flush() try: scope.trigger() for channel in channels: wave_desc, wave_array = scope.get_waveform(channel) print("wave_array = ", wave_array) num_samples = wave_desc[ 'wave_array_count'] // sequence_count if current_dim[channel] < num_samples: current_dim[channel] = num_samples traces = wave_array.reshape( sequence_count, wave_array.size // sequence_count) #necessary because h5py does not like indexing and this is the fastest (and man is it slow) way scratch = numpy.zeros((current_dim[channel], ), dtype=wave_array.dtype) except (socket.error, struct.error) as e: print('\n' + str(e)) scope.clear() continue i += sequence_count except KeyboardInterrupt: print('\rUser interrupted fetch early') finally: print('\r') scope.clear() return i
def fetch(filename, nevents, nsequence): ''' Fetch and save waveform traces from the oscilloscope. ''' scope = LeCroyScope(config.ip, timeout=config.timeout) scope.clear() scope.set_sequence_mode(nsequence) channels = scope.get_channels() settings = scope.get_settings() if 'ON' in settings['SEQUENCE']: sequence_count = int(settings['SEQUENCE'].split(',')[1]) else: sequence_count = 1 if nsequence != sequence_count: print 'Could not configure sequence mode properly' if sequence_count != 1: print 'Using sequence mode with %i traces per aquisition' % sequence_count f = h5py.File(filename, 'w') for command, setting in settings.items(): f.attrs[command] = setting current_dim = {} for channel in channels: wave_desc = scope.get_wavedesc(channel) current_dim[channel] = wave_desc['wave_array_count'] // sequence_count f.create_dataset("c%i_samples" % channel, (nevents, current_dim[channel]), dtype=wave_desc['dtype'], compression='gzip', maxshape=(nevents, None)) for key, value in wave_desc.items(): try: f["c%i_samples" % channel].attrs[key] = value except ValueError: pass f.create_dataset("c%i_vert_offset" % channel, (nevents, ), dtype='f8') f.create_dataset("c%i_vert_scale" % channel, (nevents, ), dtype='f8') f.create_dataset("c%i_horiz_offset" % channel, (nevents, ), dtype='f8') f.create_dataset("c%i_horiz_scale" % channel, (nevents, ), dtype='f8') f.create_dataset("c%i_num_samples" % channel, (nevents, ), dtype='f8') try: i = 0 while i < nevents: print '\rfetching event: %i' % i, sys.stdout.flush() try: scope.trigger() for channel in channels: wave_desc, wave_array = scope.get_waveform(channel) num_samples = wave_desc[ 'wave_array_count'] // sequence_count if current_dim[channel] < num_samples: current_dim[channel] = num_samples f['c%i_samples' % channel].resize( current_dim[channel], 1) traces = wave_array.reshape( sequence_count, wave_array.size // sequence_count) #necessary because h5py does not like indexing and this is the fastest (and man is it slow) way scratch = numpy.zeros((current_dim[channel], ), dtype=wave_array.dtype) for n in xrange(0, sequence_count): scratch[0:num_samples] = traces[ n] #'fast' copy to right size f['c%i_samples' % channel][i + n] = scratch #'fast' add to dataset f['c%i_num_samples' % channel][i + n] = num_samples f['c%i_vert_offset' % channel][i + n] = wave_desc['vertical_offset'] f['c%i_vert_scale' % channel][i + n] = wave_desc['vertical_gain'] f['c%i_horiz_offset' % channel][i + n] = -wave_desc['horiz_offset'] f['c%i_horiz_scale' % channel][i + n] = wave_desc['horiz_interval'] except (socket.error, struct.error) as e: print '\n' + str(e) scope.clear() continue i += sequence_count except KeyboardInterrupt: print '\rUser interrupted fetch early' finally: print '\r', f.close() scope.clear() return i
def fetch(filename, nevents, nsequence): ''' Fetch and save waveform traces from the oscilloscope. ''' scope = LeCroyScope(config.ip, timeout=config.timeout) scope.clear() scope.set_sequence_mode(nsequence) channels = scope.get_channels() settings = scope.get_settings() if 'ON' in settings['SEQUENCE']: sequence_count = int(settings['SEQUENCE'].split(',')[1]) else: sequence_count = 1 if nsequence != sequence_count: print 'Could not configure sequence mode properly' if sequence_count != 1: print 'Using sequence mode with %i traces per aquisition' % sequence_count f = h5py.File(filename, 'w') for command, setting in settings.items(): f.attrs[command] = setting current_dim = {} for channel in channels: wave_desc = scope.get_wavedesc(channel) current_dim[channel] = wave_desc['wave_array_count']//sequence_count f.create_dataset("c%i_samples"%channel, (nevents,current_dim[channel]), dtype=wave_desc['dtype'], compression='gzip', maxshape=(nevents,None)) for key, value in wave_desc.items(): try: f["c%i_samples"%channel].attrs[key] = value except ValueError: pass f.create_dataset("c%i_vert_offset"%channel, (nevents,), dtype='f8') f.create_dataset("c%i_vert_scale"%channel, (nevents,), dtype='f8') f.create_dataset("c%i_horiz_offset"%channel, (nevents,), dtype='f8') f.create_dataset("c%i_horiz_scale"%channel, (nevents,), dtype='f8') f.create_dataset("c%i_num_samples"%channel, (nevents,), dtype='f8') try: i = 0 while i < nevents: print '\rfetching event: %i' % i, sys.stdout.flush() try: scope.trigger() for channel in channels: wave_desc,wave_array = scope.get_waveform(channel) num_samples = wave_desc['wave_array_count']//sequence_count if current_dim[channel] < num_samples: current_dim[channel] = num_samples f['c%i_samples'%channel].resize(current_dim[channel],1) traces = wave_array.reshape(sequence_count, wave_array.size//sequence_count) #necessary because h5py does not like indexing and this is the fastest (and man is it slow) way scratch = numpy.zeros((current_dim[channel],),dtype=wave_array.dtype) for n in xrange(0,sequence_count): scratch[0:num_samples] = traces[n] #'fast' copy to right size f['c%i_samples'%channel][i+n] = scratch #'fast' add to dataset f['c%i_num_samples'%channel][i+n] = num_samples f['c%i_vert_offset'%channel][i+n] = wave_desc['vertical_offset'] f['c%i_vert_scale'%channel][i+n] = wave_desc['vertical_gain'] f['c%i_horiz_offset'%channel][i+n] = -wave_desc['horiz_offset'] f['c%i_horiz_scale'%channel][i+n] = wave_desc['horiz_interval'] except (socket.error, struct.error) as e: print '\n' + str(e) scope.clear() continue i += sequence_count except KeyboardInterrupt: print '\rUser interrupted fetch early' finally: print '\r', f.close() scope.clear() return i