def LoadData(self, data_item_number, filename): """LoadData(self, data_item_number, filename) --> none Loads the data from filename into the data_item_number. """ try: datafile = Data(str(filename), debug=True) # does all the hard work here except Exception as e: ShowWarningDialog( self.parent, "Could not load the file: " + filename + " \nPlease check the format.\n\n Stoner.Data" + " gave the following error:\n" + str(e), ) else: # For the freak case of only one data point try: if datafile.setas.cols["axes"] == 0: self.x_col = datafile.find_col(self.x_col) self.y_col = datafile.find_col(self.y_col) self.e_col = datafile.find_col(self.e_col) datafile.etsas(x=self.x_col, y=self.y_col, e=self.e_col) else: self.x_col = datafile.setas.cols["xcol"] self.y_col = datafile.setas.cols["ycol"][0] if len(datafile.setas.cols["yerr"]) > 0: self.e_col = datafile.setas.cols["yerr"][0] else: datafile.add_column(np.ones(len(datafile))) datafile.setas[-1] = "e" except Exception as e: ShowWarningDialog( self.parent, "The data file does not contain" + "all the columns specified in the opions\n" + e.message, ) # Okay now we have showed a dialog lets bail out ... return # The data is set by the default Template.__init__ function, neat hu # Know the loaded data goes into *_raw so that they are not # changed by the transforms datafile.y = np.where(datafile.y == 0.0, 1e-8, datafile.y) self.data[data_item_number].x_raw = datafile.x self.data[data_item_number].y_raw = datafile.y self.data[data_item_number].error_raw = datafile.e # Run the commands on the data - this also sets the x,y, error memebers # of that data item. self.data[data_item_number].run_command() # Send an update that new data has been loaded self.SendUpdateDataEvent()
def collate(grp,trail,**kargs): """Gather all the data up again.""" grp.sort() final=Data() final.add_column(grp[0].column('Energy'),'Energy') for g in grp: final.add_column(g.column('Asym'),g.title) if "group_key" in kargs: final[kargs["group_key"]]=grp.key final["path"]=trail if "save" in kargs and kargs["save"]: final.save(kargs["filename"]) return final
def collate(grp, trail, **kargs): """Gather all the data up again.""" grp.sort() final = Data() final.add_column(grp[0].column("Energy"), "Energy") for g in grp: final.add_column(g.column("Asym"), g.title) if "group_key" in kargs: final[kargs["group_key"]] = grp.key final["path"] = trail if "save" in kargs and kargs["save"]: final.save(kargs["filename"]) return final
def LoadData(self, data_item_number, filename): """LoadData(self, data_item_number, filename) --> none Loads the data from filename into the data_item_number. """ try: datafile=Data(str(filename),debug=True) # does all the hard work here except Exception as e: ShowWarningDialog(self.parent, 'Could not load the file: ' +\ filename + ' \nPlease check the format.\n\n Stoner.Data'\ + ' gave the following error:\n' + str(e)) else: # For the freak case of only one data point try: if datafile.setas.cols["axes"]==0: self.x_col=datafile.find_col(self.x_col) self.y_col=datafile.find_col(self.y_col) self.e_col=datafile.find_col(self.e_col) datafile.etsas(x=self.x_col,y=self.y_col,e=self.e_col) else: self.x_col=datafile.setas.cols["xcol"] self.y_col=datafile.setas.cols["ycol"][0] if len(datafile.setas.cols["yerr"])>0: self.e_col=datafile.setas.cols["yerr"][0] else: datafile.add_column(np.ones(len(datafile))) datafile.setas[-1]="e" except Exception as e: ShowWarningDialog(self.parent, 'The data file does not contain'\ + 'all the columns specified in the opions\n'+e.message) # Okay now we have showed a dialog lets bail out ... return # The data is set by the default Template.__init__ function, neat hu # Know the loaded data goes into *_raw so that they are not # changed by the transforms datafile.y=np.where(datafile.y==0.0,1E-8,datafile.y) self.data[data_item_number].x_raw = datafile.x self.data[data_item_number].y_raw = datafile.y self.data[data_item_number].error_raw = datafile.e # Run the commands on the data - this also sets the x,y, error memebers # of that data item. self.data[data_item_number].run_command() # Send an update that new data has been loaded self.SendUpdateDataEvent()
def norm_group(pos, _, **kargs): """Takes the drain current for each file in group and builds an analysis file and works out the mean drain""" if "signal" in kargs: signal = kargs["signal"] else: signal = "fluo" lfit = kargs["lfit"] rfit = kargs["rfit"] posfile = Data() posfile.metadata = pos[0].metadata posfile = posfile & pos[0].column(0) posfile.column_headers = ["Energy"] for f in pos: print(str(f["run"]) + str(f.find_col(signal))) posfile = posfile & f.column(signal) posfile.add_column(lambda r: np.mean(r[1:]), "mean drain") ec = posfile.find_col("Energy") md = posfile.find_col("mean drain") linearfit = scipy.poly1d( posfile.polyfit(ec, md, 1, lambda x, y: lfit[0] <= x <= lfit[1])) posfile.add_column(lambda r: r[md] - linearfit(r[ec]), "minus linear") highend = posfile.mean("minus", lambda r: rfit[0] <= r[ec] <= rfit[1]) ml = posfile.find_col("minus linear") posfile.add_column(lambda r: r[ml] / highend, "normalised") if "group_key" in kargs: posfile[kargs["group_key"]] = pos.key return posfile
def norm_group(pos,_,**kargs): """Takes the drain current for each file in group and builds an analysis file and works out the mean drain""" if "signal" in kargs: signal=kargs["signal"] else: signal="fluo" lfit=kargs["lfit"] rfit=kargs["rfit"] posfile=Data() posfile.metadata=pos[0].metadata posfile=posfile&pos[0].column(0) posfile.column_headers=['Energy'] for f in pos: print(str(f["run"])+str(f.find_col(signal))) posfile=posfile&f.column(signal) posfile.add_column(lambda r:np.mean(r[1:]),"mean drain") ec=posfile.find_col('Energy') md=posfile.find_col('mean drain') linearfit=scipy.poly1d(posfile.polyfit(ec,md,1,lambda x,y:lfit[0]<=x<=lfit[1])) posfile.add_column(lambda r:r[md]-linearfit(r[ec]),'minus linear') highend=posfile.mean('minus',lambda r:rfit[0]<=r[ec]<=rfit[1]) ml=posfile.find_col('minus linear') posfile.add_column(lambda r:r[ml]/highend,"normalised") if "group_key" in kargs: posfile[kargs["group_key"]]=pos.key return posfile
d.setas="xy" d.labels[d.find_col('Angle')]=r"Reflection Angle $\theta$" t.del_rows(0, lambda x,y: x<critical_edge) t.setas="xy" t.template.fig_width=7.0 t.template.fig_height=5.0 t.plot(fmt='go', plotter=pyplot.semilogy) main_fig=d.plot(figure=t.fig, plotter=pyplot.semilogy) d.show() #Now convert the angle to sin^2 t.apply(lambda x: np.sin(np.radians(x[0]/2.0))**2, 0,header=r"$sin^2\theta$") # Now create the m^2 order m=np.arange(len(t))+fringe_offset m=m**2 #And add it to t t.add_column(m, column_header='$m^2$') #Now we can it a straight line t.setas="x..y" fit=t.lmfit(Linear,result=True,replace=False,header="Fit") g=t["LinearModel:slope"] gerr=t["LinearModel:slope err"]/g g=np.sqrt(1.0/g) gerr/=2.0 l=float(d['Lambda']) th=l/(2*g) therr=th*(gerr) t.inset(loc="top right",width=0.5,height=0.4) t.plot_xy(r"Fit",r"$sin^2\theta$", 'b-',label="Fit") t.plot_xy(r"$m^2$",r"$sin^2\theta$", 'ro',label="Peak Position") t.xlabel="Fringe $m^2$"
d.setas = "xy" d.labels[d.find_col("Angle")] = r"Reflection Angle $\theta$" t.del_rows(0, lambda x, y: x < critical_edge) t.setas = "xy" t.template.fig_width = 7.0 t.template.fig_height = 5.0 t.plot(fmt="go", plotter=pyplot.semilogy) main_fig = d.plot(figure=t.fig, plotter=pyplot.semilogy) d.show() # Now convert the angle to sin^2 t.apply(lambda x: np.sin(np.radians(x[0] / 2.0)) ** 2, 0, header=r"$sin^2\theta$") # Now create the m^2 order m = np.arange(len(t)) + fringe_offset m = m ** 2 # And add it to t t.add_column(m, column_header="$m^2$") # Now we can it a straight line t.setas = "x..y" fit = t.lmfit(Linear, result=True, replace=False, header="Fit") g = t["LinearModel:slope"] gerr = t["LinearModel:slope err"] / g g = np.sqrt(1.0 / g) gerr /= 2.0 l = float(d["Lambda"]) th = l / (2 * g) therr = th * (gerr) t.inset(loc="top right", width=0.5, height=0.4) t.plot_xy(r"Fit", r"$sin^2\theta$", "b-", label="Fit") t.plot_xy(r"$m^2$", r"$sin^2\theta$", "ro", label="Peak Position") t.xlabel = "Fringe $m^2$"
t.del_rows(0, lambda x, y: x < critical_edge) t.setas = "xy" t.template.fig_width = 7.0 t.template.fig_height = 5.0 t.plot(fmt='go', plotter=pyplot.semilogy) main_fig = d.plot(figure=t.fig, plotter=pyplot.semilogy) d.show() #Now convert the angle to sin^2 t.apply(lambda x: np.sin(np.radians(x[0] / 2.0))**2, 0, header=r"$sin^2\theta$") # Now create the m^2 order m = np.arange(len(t)) + fringe_offset m = m**2 #And add it to t t.add_column(m, column_header='$m^2$') #Now we can it a straight line t.setas = "x..y" fit = t.lmfit(Linear, result=True, replace=False, header="Fit") g = t["LinearModel:slope"] gerr = t["LinearModel:slope err"] / g g = np.sqrt(1.0 / g) gerr /= 2.0 l = float(d['Lambda']) th = l / (2 * g) therr = th * (gerr) t.inset(loc="top right", width=0.5, height=0.4) t.plot_xy(r"Fit", r"$sin^2\theta$", 'b-', label="Fit") t.plot_xy(r"$m^2$", r"$sin^2\theta$", 'ro', label="Peak Position") t.xlabel = "Fringe $m^2$"
d.del_rows(0, lambda x, r: np.any(np.isnan(r))) popt, pcov = d.curve_fit(bg_wrapper, xcol=t_col, ycol=r_col, p0=p0, absolute_sigma=False) perr = np.sqrt(np.diag(pcov)) labels = [r"\theta_D", r"\rho_0", r"A"] units = ["K", r"\Omega m", r"\Omega m"] annotation = [ "${}$: {}\n".format(l, format_error(v, e, latex=True, mode="eng", units=u)) for l, v, e, u in zip(labels, popt, perr, units) ] annotation = "\n".join(annotation) popt = np.append(popt, 5) T = d.column(t_col) d.add_column(blochGrueneisen(T, *popt), header=r"Bloch") d.plot_xy( t_col, [r_col, "Bloch"], ["ro", "b-"], label=["Data", r"$Bloch-Gr\"ueisen Fit$"], ) d.xlabel = "Temperature (K)" d.ylabel = "Resistance ($\Omega$)" text(0.05, 0.65, annotation, transform=d.axes[0].transAxes)