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 = {} for channel in channels: f[channel] = open('%s.ch%s.traces'%(filename,channel),'wb') params_pattern = '=IBdddd' # (num_samples, sample_bytes, v_off, v_scale, h_off, h_scale, [samples]) ... 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 traces = wave_array.reshape(sequence_count, wave_array.size//sequence_count) out = f[channel] for n in xrange(0,sequence_count): out.write(struct.pack(params_pattern,num_samples,wave_desc['dtype'].itemsize,wave_desc['vertical_offset'], wave_desc['vertical_gain'], -wave_desc['horiz_offset'], wave_desc['horiz_interval'])) traces[n].tofile(out) except (socket.error) as e: print '\n' + str(e) scope.clear() continue i += sequence_count except KeyboardInterrupt: print '\rUser interrupted fetch early' except Exception as e: print "\rUnexpected error:", e finally: print '\r', for channel in channels: f[channel].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
def fetch(filename, nevents, nsequence, trigchannel, triglevel, voltdiv): ''' 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 print trigchannel, triglevel commands = {} if (trigchannel != 999): commands['TRIG_SELECT'] = 'TRSE EDGE,SR,C' + str( trigchannel) + ',HT,OFF' if (triglevel != 999): commands['C2:TRIG_LEVEL'] = 'C2:TRLV ' + str(triglevel) + ' V' commands['C3:TRIG_LEVEL'] = 'C3:TRLV ' + str(triglevel) + ' V' commands['C4:TRIG_LEVEL'] = 'C4:TRLV ' + str(triglevel) + ' V' if (voltdiv != 999): commands['C2:VOLT_DIV'] = 'C2:VDIV ' + str(voltdiv) + ' V' commands['C3:VOLT_DIV'] = 'C3:VDIV ' + str(voltdiv) + ' V' commands['C4:VOLT_DIV'] = 'C4:VDIV ' + str(voltdiv) + ' V' scope.set_settings(commands) newsettings = scope.get_settings() # print newsettings 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 = {} timef = {} # output file with trigger times for channel in channels: f[channel] = open('%s.ch%s.traces' % (filename, channel), 'wb') timef[channel] = open('%s.ch%s.traces.times' % (filename, channel), 'wb') params_pattern = '=IBdddd' # (num_samples, sample_bytes, v_off, v_scale, h_off, h_scale, [samples]) ... try: i = 0 while i < nevents: print '\rfetching event: %i' % i, sys.stdout.flush() try: scope.trigger() print channels for channel in channels: # print channel wave_desc, wave_array, trig_time_array, trigger_time, acq_duration = scope.get_waveform( channel) num_samples = wave_desc[ 'wave_array_count'] // sequence_count traces = wave_array.reshape( sequence_count, wave_array.size // sequence_count) out = f[channel] outtime = timef[channel] # print num_samples,sequence_count # print trigger_time # print acq_duration outtime.write(str(trigger_time) + ' ') outtime.write(str(acq_duration) + '\n') #New way of writing files # waveform=LeCroyWaveformChannel(wave_desc,wave_array,trig_time_array) # waveform.to_file(out) # waveform.from_file(out) for n in xrange(0, sequence_count): # print "Here",n tempsturct = struct.pack(params_pattern, num_samples, wave_desc['dtype'].itemsize, wave_desc['vertical_offset'], wave_desc['vertical_gain'], -wave_desc['horiz_offset'], wave_desc['horiz_interval']) out.write(tempsturct) traces[n].tofile(out) except (socket.error) as e: print '\n' + str(e) scope.clear() continue i += sequence_count except KeyboardInterrupt: print '\rUser interrupted fetch early' except Exception as e: print "\rUnexpected error:", e finally: print '\r', for channel in channels: print "Closing", channel f[channel].close() timef[channel].close() scope.clear() return i
from lecroy import LeCroyScope scope = LeCroyScope(host="131.225.138.156") nsequence = 10 scope.clear() scope.set_sequence_mode(nsequence) settings = scope.get_settings() for a, b in settings.items(): print(a, ":", b) if b'ON' in settings['SEQUENCE']: sequence_count = int(settings['SEQUENCE'].split(b',')[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) scope.trigger() desc, array = scope.get_waveform(2) # wf = desc['vertical_gain']*array - desc['vertical_offset'] print("---------- Descritption of waveform ---------") for a, b in desc.items(): print(a, ":", b) plt.plot(array) plt.show()
def crunch(filename, nevents, nsequence, ped_start, ped_end, win_start, win_end, load): ''' Fetch and crunch 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 = {} for channel in channels: f[channel] = open('%s.ch%s.crunch'%(filename,channel),'wb') 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 traces = wave_array.reshape(sequence_count, wave_array.size//sequence_count) offset = wave_desc['vertical_offset'] gain = wave_desc['vertical_gain'] tinc = wave_desc['horiz_interval'] out = f[channel] for n in xrange(0,sequence_count): ped = traces[n,ped_start:ped_end]*gain-offset win = traces[n,win_start:win_end]*gain-offset values = numpy.asarray([ (ped_end-ped_start+1.0)*tinc, numpy.sum(ped)*tinc/load, numpy.amin(ped), numpy.amax(ped), numpy.std(ped), (win_end-win_start+1.0)*tinc, numpy.sum(win)*tinc/load, numpy.amin(win), numpy.amax(win), numpy.std(win) ],dtype=numpy.float64) values.tofile(out) except (socket.error) as e: print '\n' + str(e) scope.clear() continue i += sequence_count except KeyboardInterrupt: print '\rUser interrupted fetch early' except Exception as e: print "\rUnexpected error:", e finally: print '\r', for channel in channels: f[channel].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