def plot_single(contains='', ind=0, fit=False, plot_range=None, **kw): title = kw.pop('title', None) folder = toolbox.latest_data(contains) filename = toolbox.measurement_filename(folder, ext='dat') V, f, c, i, st = np.loadtxt(filename, unpack=True) fig = plt.figure() ax = plt.subplot(111) fltr = i == ind #(dd[:,2]<(y+0.05)) & (dd[:,2]>(j-0.05)) # xx = f[np.where(fltr)] zz = c[np.where(fltr)] ax.plot(xx, zz) if fit: X = np.arange(np.min(xx), np.max(xx), 0.005) fitfunc = fit_laserscan(xx, zz) ax.plot(X, fitfunc['fitfunc'](X)) if plot_range != None: ax.set_xlim(plot_range) ax.set_ylabel('Counts') ax.set_xlabel('Laser frequency [GHz]') if title != None: plt.title(title + ' ' + os.path.split(filename)[1]) else: plt.title(os.path.split(filename)[1])
def load_hdf5data(self): self.h5filepath = toolbox.measurement_filename(self.folder) self.f = h5py.File(self.h5filepath, 'r') self.name = self.f.keys()[0] self.g = self.f[self.name] self.measurementstring = os.path.split(self.folder)[1] self.timestamp = os.path.split(os.path.split(self.folder)[0])[1] \ + '/' + self.measurementstring[:6] self.measurementstring = self.measurementstring[7:] self.default_plot_title = self.timestamp+'\n'+self.measurementstring
def __init__(self, folder, **kw): sequence.SequenceAnalysis.__init__(self,folder, **kw) pq_folder=kw.pop('pq_folder', None) if pq_folder != None: if pq_folder =='bs_remote': h5filepath = 'X:' + self.g.attrs['bs_data_path'][12:] else: h5filepath = toolbox.measurement_filename(pq_folder) print 'h5filepath:',h5filepath h5mode=kw.get('hdf5_mode', 'r') self.pqf = h5py.File(h5filepath,h5mode) else: self.pqf=self.f
def get_temperature(older_than, newer_than): x = np.array([]) y = np.array([]) while toolbox.latest_data(contains='temp_monitor', older_than=older_than, newer_than=newer_than, raise_exc=False) != False: ## Find the data folder timestamp, folder = toolbox.latest_data(contains='temp_monitor', older_than=older_than, newer_than=newer_than, return_timestamp=True) ## convert timestamp to Epoch time (absolute time) Time_temp1 = datetime.datetime(int(timestamp[:4]), int(timestamp[4:6]), int(timestamp[6:8]), int(timestamp[8:10]), int(timestamp[10:12]), int(timestamp[12:14]), 0) Time_temp1 = datetime.datetime.timetuple(Time_temp1) Epoch_timestamp = calendar.timegm(Time_temp1) # in seconds ## get the data filename = toolbox.measurement_filename(folder, ext='dat') data = np.loadtxt(filename, skiprows=16) # convert time data to Epoch time time_data = data[:, 0] * 3600 + Epoch_timestamp temperature_data = (data[:, 1] - 100) / 0.385 # Filter out fluke measurements indices_flukes = [i for i, j in enumerate(temperature_data) if j < 10] time_data = np.delete(time_data, indices_flukes) temperature_data = np.delete(temperature_data, indices_flukes) x = np.concatenate( (x, time_data)) # Time after beginning of measurement [sec] y = np.concatenate((y, temperature_data)) older_than = str(int(timestamp) - 1) ## Ordering in time: sort_indices = np.argsort(x) x = np.array(x)[sort_indices] y = np.array(y)[sort_indices] print 'folder = ' + folder return x, y, folder
def load_hdf5data(self, **kw): self.h5filepath = toolbox.measurement_filename(self.folder) h5mode=kw.pop('hdf5_mode', 'r') self.f = h5py.File(self.h5filepath,h5mode) for k in self.f.keys(): if type(self.f[k])==h5py.Group: self.name = k # print k self.g = self.f[self.name] self.measurementstring = os.path.split(self.folder)[1] self.timestamp = os.path.split(os.path.split(self.folder)[0])[1] \ + '/' + self.measurementstring[:6] self.measurementstring = self.measurementstring[7:] self.default_plot_title = self.timestamp+'\n'+self.measurementstring
def load_hdf5data(self, **kw): self.h5filepath = toolbox.measurement_filename(self.folder) h5mode = kw.pop('hdf5_mode', 'r') self.f = h5py.File(self.h5filepath, h5mode) for k in self.f.keys(): if type(self.f[k]) == h5py.Group and k in os.path.split( self.h5filepath )[1]: # PH added this check because sometimes additional files added to hdf5 file (06/16) self.name = k self.g = self.f[self.name] break self.measurementstring = os.path.split(self.folder)[1] self.timestamp = os.path.split(os.path.split(self.folder)[0])[1] \ + '/' + self.measurementstring[:6] self.measurementstring = self.measurementstring[7:] self.default_plot_title = self.timestamp + '\n' + self.measurementstring
def __init__(self, folder, **kw): sequence.SequenceAnalysis.__init__(self, folder, **kw) pq_folder = kw.pop('pq_folder', None) pq_device = kw.pop('pq_device', '') self.pq_device = pq_device if pq_folder != None: if pq_folder == 'bs_remote': h5filepath = 'X:' + self.g.attrs['bs_data_path'][12:] else: h5filepath = toolbox.measurement_filename(pq_folder) print 'h5filepath:', h5filepath h5mode = kw.get('hdf5_mode', 'r') self.pqf = h5py.File(h5filepath, h5mode) else: self.pqf = self.f
def plot_freq_against_index(contains='', plot_range=None, interp_res=0.01, **kw): title = kw.pop('title', None) folder = toolbox.latest_data(contains) filename = toolbox.measurement_filename(folder, ext='dat') V, f, c, i, st = np.loadtxt(filename, unpack=True) Y = np.unique(i) if plot_range == None: X = np.arange(np.min(f), np.max(f), interp_res) else: X = np.arange(plot_range[0], plot_range[1], interp_res) Z = np.zeros((len(X), len(Y))) for j, y in enumerate(Y): fltr = i == y #(dd[:,2]<(y+0.05)) & (dd[:,2]>(j-0.05)) # xx = f[np.where(fltr)] zz = c[np.where(fltr)] interp_func = interp1d(xx, zz, bounds_error=False, fill_value=0.) Z[:, j] = np.nan_to_num(interp_func(X)) fig = plt.figure() ax = plt.subplot(111) ax.imshow(Z, aspect='auto', origin='lower', vmin=0, vmax=np.max(Z), extent=[min(Y), max(Y), X[0], X[-1]], cmap='binary') ax.set_xlabel('Scan nr') ax.set_ylabel('Laser frequency [GHz]') if title != None: plt.title(title + ' ' + os.path.split(filename)[1]) else: plt.title(os.path.split(filename)[1]) save_and_close_plot(folder, name='Laserscan_2d')
def fix_hdf5_file(contains='', **kw): folder = toolbox.latest_data(contains, **kw) h5filepath = toolbox.measurement_filename(folder) filename = os.path.split(folder)[1] h5mode = kw.pop('hdf5_mode', 'r+') f = h5py.File(h5filepath, h5mode) groups = 0 for k in f.keys(): if type(f[k]) == h5py.Group: groups += 1 group_name = k print k if groups != 1: print 'Ambiguous hdf5 group! Cannot automatically rename!' return f[filename] = f[k]
def load_grouped_pulses(contains="", filepath=""): filepath = filepath if filepath != "" else toolbox.measurement_filename( toolbox.latest_data(contains=contains)) print filepath with h5py.File(filepath, 'r') as hf: num_pulses = np.max( np.array(hf['pulse_sim/pulses'].keys()).astype(int)) overview_keys = [str(j) for j in (hf['pulse_sim/seq_overview'].keys())] overview_data = {} for key in overview_keys: overview_data[key] = np.array( hf.get('pulse_sim/seq_overview/' + key)) grouped_seq = [] for i in range(num_pulses): overview = {} for key in overview_keys: overview[key] = overview_data[key][i] pulses = np.array(hf.get('pulse_sim/pulses/' + str(i))) grouped_seq.append([overview, pulses]) return grouped_seq
def result(self, folder): data = toolbox.measurement_filename(directory = folder, ext = 'npz') result = np.load(data) return result
def spectral_diffusion(contains='', print_avg_counts=False, count_filter=None, plot_range=None, **kw): title = kw.pop('title', None) folder = toolbox.latest_data(contains) filename = toolbox.measurement_filename(folder, ext='dat') V, f, c, i, st = np.loadtxt(filename, unpack=True) Y = np.unique(i) centres = np.array([]) errors = np.array([]) diff = np.array([]) overlaps = np.array([]) avg_counts = 0. for j, y in enumerate(Y): fltr = i == y #(dd[:,2]<(y+0.05)) & (dd[:,2]>(j-0.05)) # xx = f[np.where(fltr)] zz = c[np.where(fltr)] fitfunc = fit_laserscan(xx, zz, do_print=False) if count_filter == None or np.sum(zz) > count_filter: centres = np.append(centres, fitfunc['params'][2]) errors = np.append(errors, fitfunc['params'][3]) if centres.size != 1: diff = np.append(diff, centres[-1] - centres[-2]) overlaps = np.append(overlaps, overlap(diff[-1], errors[-1])) avg_counts = (avg_counts * j + np.sum(zz)) / (j + 1) #print j,fitfunc['params'][3] ys = range(len(centres)) fig = plt.figure() ax = plt.subplot(111) ax.errorbar(ys, centres, yerr=errors) ax.set_ylabel('Centre') ax.set_xlabel('Scan ind') if print_avg_counts: print 'Avg counts ', avg_counts if plot_range != None: ax.set_ylim(plot_range) if title != None: plt.title(title + ' ' + os.path.split(filename)[1]) else: plt.title(os.path.split(filename)[1]) fig = plt.figure() ax = plt.subplot(111) ax.plot(ys[:-1], 1e3 * diff) ax.set_ylabel('Difference (MHz)') ax.set_xlabel('Scan ind') fig = plt.figure() ax = plt.subplot(111) ax.plot(ys[:-1], overlaps) ax.set_ylabel('Overlap with previous') ax.set_xlabel('Scan ind') print "Mean overlap ", np.mean(overlaps)
def plot_overlaid(contains='', show_indiv=False, fit=False, compensate_drift=False, plot_range=None, interp_res=0.005, **kw): title = kw.pop('title', None) folder = toolbox.latest_data(contains) filename = toolbox.measurement_filename(folder, ext='dat') V, f, c, i, st = np.loadtxt(filename, unpack=True) if not show_indiv: if plot_range == None: if compensate_drift: X = np.arange( np.min(f) - np.mean(f), np.max(f) - np.mean(f), interp_res) else: X = np.arange(np.min(f), np.max(f), interp_res) else: X = np.arange(plot_range[0], plot_range[1], interp_res) Z = np.zeros(len(X)) Y = np.unique(i) fig = plt.figure() ax = plt.subplot(111) for j, y in enumerate(Y): fltr = i == y #(dd[:,2]<(y+0.05)) & (dd[:,2]>(j-0.05)) # xx = f[np.where(fltr)] zz = c[np.where(fltr)] if compensate_drift: avg_pos = np.sum(xx * zz) / np.sum(zz) xx = xx - avg_pos if show_indiv: ax.plot(xx, zz) else: interp_func = interp1d(xx, zz, bounds_error=False, fill_value=0.) Z = Z + np.nan_to_num(interp_func(X)) if not show_indiv: ax.plot(X, Z) if fit: fitfunc = fit_laserscan(X, Z) ax.plot(X, fitfunc['fitfunc'](X)) if plot_range != None: ax.set_xlim(plot_range) ax.set_ylabel('Counts') ax.set_xlabel('Laser frequency [GHz]') if title != None: plt.title(title + ' ' + os.path.split(filename)[1]) else: plt.title(os.path.split(filename)[1])