def do_sweep(ri,center_freqs,offsets,nsamp, nchan_per_step=8,reads_per_step=2,callback = None, sweep_data=None, demod=True, loopback=False): if nchan_per_step > center_freqs.shape[0]: nchan_per_step = center_freqs.shape[0] if sweep_data is not None: swp = sweep_data else: swp = SweepData() for offset_index,offset in enumerate(offsets): ri.set_tone_freqs(center_freqs+offset,nsamp=nsamp) nchan = ri.fft_bins.shape[1] nstep = int(np.ceil(nchan/float(nchan_per_step))) toread = set(range(nchan)) for k in range(nstep): if len(toread) == 0: break if len(toread) < nchan_per_step: print "couldn't read last %d channels because number of channels is not a multiple of nchan_per_step" % len(toread) break if len(toread) > nchan_per_step: start = k stop = k + (nchan//nstep)*nstep selection = range(start,stop,nchan/nchan_per_step)[:nchan_per_step] toread = toread.difference(set(selection)) else: selection = list(toread) toread = set() selection.sort() ri.select_fft_bins(selection) ri._sync(loopback=loopback) time.sleep(0.2) epoch = time.time() try: dmod,addr = ri.get_data_katcp(reads_per_step,demod=demod) except Exception,e: print e continue chids = ri.fpga_fft_readout_indexes+1 tones = ri.tone_bins[0,ri.readout_selection] abort = False for m in range(len(chids)): #print "m:",m,"selection[m]",selection[m],tones[m]*ri.fs*1.0/nsamp,ri.readout_selection[m] sweep_index = ri.readout_selection[m]# np.abs(actual_freqs - ri.fs*tones[m]/nsamp).argmin() block = DataBlock(data = dmod[:,m], tone=tones[m], fftbin = chids[m], nsamp = nsamp, nfft = ri.nfft, wavenorm = ri.wavenorm, t0 = epoch, fs = ri.fs, sweep_index=sweep_index, heterodyne=ri.heterodyne, lo=ri.lo_frequency, hardware_delay_estimate=ri.hardware_delay_estimate) block.progress = (k+1)/float(nstep) swp.add_block(block) if callback: abort = callback(block) if abort: break
def coarse_sweep(ri,freqs=np.linspace(10,200,384),nsamp=2**15,nchan_per_step=4,reads_per_step=2, callback = None, sweep_id = 1, sweep_data = None): actual_freqs = ri.set_tone_freqs(freqs,nsamp=nsamp) if sweep_data is not None: data = sweep_data else: data = SweepData(sweep_id) ri.r.write_int('sync',0) ri.r.write_int('sync',1) ri.r.write_int('sync',0) time.sleep(1) nchan = ri.fft_bins.shape[1] nstep = int(np.ceil(nchan/float(nchan_per_step))) toread = set(range(nchan)) for k in range(nstep): if len(toread) == 0: break if len(toread) > nchan_per_step: start = k stop = k + (nchan//nstep)*nstep selection = range(start,stop,nchan/nchan_per_step)[:nchan_per_step] toread = toread.difference(set(selection)) else: selection = list(toread) toread = set() ri.select_fft_bins(selection) ri.r.write_int('sync',0) ri.r.write_int('sync',1) ri.r.write_int('sync',0) time.sleep(0.2) try: dmod,addr = ri.get_data(reads_per_step) except Exception,e: print e continue # dmod = dmod*ri.wavenorm chids = ri.fpga_fft_readout_indexes+1 tones = ri.tone_bins[0,ri.readout_selection] abort = False for m in range(len(chids)): sweep_index = selection[m] # np.abs(actual_freqs - ri.fs*tones[m]/nsamp).argmin() block = DataBlock(data = dmod[:,m], tone=tones[m], fftbin = chids[m], nsamp = nsamp, nfft = ri.nfft, wavenorm = ri.wavenorm, t0 = time.time(), fs = ri.fs, sweep_index=sweep_index) block.progress = (k+1)/float(nstep) data.add_block(block) if callback: abort = callback(block) if abort: break
def do_prepared_sweep(ri, nchan_per_step=8, reads_per_step=2, callback=None, sweep_data=None, banks=None, demod=True, loopback=False): if nchan_per_step > ri.fft_bins.shape[1]: nchan_per_step = ri.fft_bins.shape[1] if ri.fft_bins.shape[1] % nchan_per_step: print "Warning: number of channels is not a multiple of nchan_per_step. Not all channels will be read." if sweep_data is not None: swp = sweep_data else: swp = SweepData() nbanks = ri.tone_bins.shape[0] nsamp = ri.tone_nsamp if banks is None: banks = range(nbanks) for ibank, bank in enumerate(banks): ri.select_bank(bank) nchan = ri.fft_bins.shape[1] nstep = int(np.ceil(nchan / float(nchan_per_step))) toread = set(range(nchan)) for k in range(nstep): print("%.1f" % (100. * (ibank * nstep + k) / (nstep * len(banks)))), if len(toread) == 0: break if len(toread) < nchan_per_step: print "couldn't read last %d channels because number of channels is not a multiple of nchan_per_step" % len( toread) break if len(toread) > nchan_per_step: start = k stop = k + (nchan // nstep) * nstep selection = range(start, stop, nchan / nchan_per_step)[:nchan_per_step] toread = toread.difference(set(selection)) else: selection = list(toread) toread = set() selection.sort() ri.select_fft_bins(selection) ri._sync(loopback=loopback) time.sleep(0.2) epoch = time.time() try: dmod, addr = ri.get_data(reads_per_step, demod=demod) except Exception, e: print e continue # dmod = dmod*ri.wavenorm chids = ri.fpga_fft_readout_indexes + 1 tones = ri.tone_bins[bank, ri.readout_selection] abort = False for m in range(len(chids)): #print "m:",m,"selection[m]",selection[m],tones[m]*ri.fs*1.0/nsamp,ri.readout_selection[m] sweep_index = ri.readout_selection[ m] # np.abs(actual_freqs - ri.fs*tones[m]/nsamp).argmin() block = DataBlock( data=dmod[:, m], tone=tones[m], fftbin=chids[m], nsamp=nsamp, nfft=ri.nfft, wavenorm=ri.wavenorm, t0=epoch, fs=ri.fs, sweep_index=sweep_index, heterodyne=ri.heterodyne, lo=ri.lo_frequency, hardware_delay_estimate=ri.hardware_delay_estimate) block.progress = (k + 1) / float(nstep) swp.add_block(block) if callback: abort = callback(block) if abort: break
def coarse_sweep(ri, freqs=np.linspace(10, 200, 384), nsamp=2**15, nchan_per_step=4, reads_per_step=2, callback=None, sweep_id=1, sweep_data=None): actual_freqs = ri.set_tone_freqs(freqs, nsamp=nsamp) if sweep_data is not None: data = sweep_data else: data = SweepData(sweep_id) ri.r.write_int('sync', 0) ri.r.write_int('sync', 1) ri.r.write_int('sync', 0) time.sleep(1) nchan = ri.fft_bins.shape[1] nstep = int(np.ceil(nchan / float(nchan_per_step))) toread = set(range(nchan)) for k in range(nstep): if len(toread) == 0: break if len(toread) > nchan_per_step: start = k stop = k + (nchan // nstep) * nstep selection = range(start, stop, nchan / nchan_per_step)[:nchan_per_step] toread = toread.difference(set(selection)) else: selection = list(toread) toread = set() ri.select_fft_bins(selection) ri.r.write_int('sync', 0) ri.r.write_int('sync', 1) ri.r.write_int('sync', 0) time.sleep(0.2) try: dmod, addr = ri.get_data(reads_per_step) except Exception, e: print e continue # dmod = dmod*ri.wavenorm chids = ri.fpga_fft_readout_indexes + 1 tones = ri.tone_bins[0, ri.readout_selection] abort = False for m in range(len(chids)): sweep_index = selection[ m] # np.abs(actual_freqs - ri.fs*tones[m]/nsamp).argmin() block = DataBlock(data=dmod[:, m], tone=tones[m], fftbin=chids[m], nsamp=nsamp, nfft=ri.nfft, wavenorm=ri.wavenorm, t0=time.time(), fs=ri.fs, sweep_index=sweep_index) block.progress = (k + 1) / float(nstep) data.add_block(block) if callback: abort = callback(block) if abort: break