def load(self,file,plot=True): """Load data from the file given in the path string.""" self.time = -1 base = 0.1 count = 0 uplim = 31 y = np.fromfile(file,np.int32,-1) x = np.arange(0,50001,1,dtype=np.float32) x = self.convertTime(x) # #f = ip.interp1d(x,y) #p0 = [10., 0.0001, 10000., 2.] #p1, cov = op.curve_fit(self.func, x, y, p0) #print(p1) #p1f = self.func(x, *p1) #Fit of neutron monitor #xs = range(200) #xs = np.arange(0,35,0.1) #ys = np.zeros(350,dtype=np.uint32) xs = np.arange(0,uplim,base) ys = np.zeros(uplim/base,dtype=np.uint32) for (i,j) in zip(x,y): if i > base: ys[int(10*base-1)]=count base += 0.1 count = 0 count += j base = 0.1 count = 0 uplim = 31 # ymean = np.mean(ys[250:300]) ynew = np.array([float(yo)-ymean*(uplim/base)/50001 for yo in y]) # ysnew = np.zeros(uplim/base,dtype=np.float32) for (i,j) in zip(x,ynew): if i > base: ysnew[int(10*base-1)]=count base += 0.1 count = 0 count += j # if plot: graph = GraphFrame(None,"Monitor") graph2 = GraphFrame(None,"Monitor Adjusted") # graph.plot(np.arange(0.0,20.0,0.1),f(xs)) # graph.plot(xs,ys) graph2.plot(xs,ysnew) # self.spec = np.expand_dims(np.expand_dims(y,axis=0),axis=0)
def load(self,file,wxon=True): """Load data from the file given in the path string.""" with open(file,"r") as infile: infile.readline() # drop first line line = infile.readline() #Find the time information m = re.search("lasted (\d+) milliseconds",line) if m: self.time = float(m.group(1)) else: raise InvalidFileError data = np.loadtxt(file,dtype=np.float32,skiprows=3) x = data[:,0] y = data[:,1] y += 1 x = self.convertTime(x) f = ip.interp1d(x,y) #Interpolation of neutron monitor xs = range(200) if(wxon): graph = GraphFrame(None,"Monitor") graph.plot(np.arange(0.0,20.0,0.1),f(xs)) self.spec = np.expand_dims(np.expand_dims(f(xs),axis=0),axis=0)
def onView(self,event): """Display a graph of the spectrum.""" x,y,e = self.calcSpec() graph = GraphFrame(self,"Spectrum") graph.plot(x,y,range=(self.vmin,self.vmax),yerr=e) self.Show(False)