def get_data(self): directory = self.get_dir() shots = self.dic['shots'] shots.replace(' ', '') #remove all the spaces # keys = " ".join([self.dic['X'], self.dic['Y']]) # self.data, errmsg, raw_data = qrange.qrange(directory, shots, keys) keys = [self.dic['X'], self.dic['Y']] # print 'Before qrange.' self.data, errmsg, raw_data = qrange.qrange_eval(directory, shots, keys) # print 'After qrange.' s = '' for i in range(self.data.shape[1]): col = self.data[:,i] s00 = numpy.mean(col) s01 = stats.sem(col) s02 = numpy.std(col) s03 = numpy.max(col) - numpy.min(col) s = s + "Mean = %10.6f\n" % s00 s = s + "Std. deviation = %10.6f\n" % s02 s = s + "Std. Error of the mean = %10.6f\n" % s01 s = s + "Pk-Pk = %10.6f\n" % s03 s = s+ '\n' raw_data = s + raw_data self.dic['data_str'] = raw_data self.sdata = None if self.dic['X'] == "SEQ:shot": s = [ numpy.mean(self.data[:,1]), numpy.std(self.data[:,1]), stats.sem(self.data[:,1]),numpy.max(self.data[:,1]) - numpy.min(self.data[:,1]) ] a = [] for val in s: a.append( [val for i in range(self.data[:,1].size)]) self.sdata = numpy.c_[self.data[:,0], numpy.transpose(numpy.array(a))] else: self.sdata = statdat.statdat(self.data, 0, 1) return
def getdata_(self): """ Executes qrange to extract data from reports. """ #data, errmsg, rawdat = qrange.qrange(self.datadir, self.range, self.X + " " + self.Y) data, errmsg, rawdat = qrange.qrange_eval(self.datadir, self.range, [self.X , self.Y]) msg=None if data.shape == (0,): msg = "Data set yields no valid points:\n\n RANGE = %s\n X = %s\n Y = %s\n" % (self.range, self.X, self.Y) print msg return data, msg, False self.raw_data = rawdat colnames = rawdat.split('\n')[0] colnames = colnames[1:].split('\t')[1:] #Get basic statistics for all columns in data s = '' for i in range(data.shape[1]): col = data[:,i] s00 = numpy.mean( col ) #mean s02 = numpy.std( col ) #standard deviation s03 = numpy.max( col ) - numpy.min( col ) # peak to peak value s01 = stats.sem( col ) #standard error of the mean #s = s + colnames[i] + ':\n' s = s + "Mean = %10.6f\n" % s00 s = s + "Std. deviation = %10.6f\n" % s02 s = s + "Std. error of the mean = %10.6f\n" % s01 s = s + "Pk-Pk = %10.6f\n" % s03 s = s + '\n' self.stat = s #Get data that is reduced statistically. This means that if there is more #than 1 point for a given value of X,then the average and error will be used #The results of this operation are stored in a list called sdata: # # sdata = (mean, standard deviation, pk-pk, standard error of the mean) sdata=None if self.X == "SEQ:shot" and self.ST: s = [ numpy.mean( data[:,1] ), \ numpy.std( data[:,1]), \ stats.sem( data[:,1]), \ numpy.max( data[:,1]) - numpy.min(data[:,1]) \ ] a = [] for val in s: a.append( [ val for i in range( data[:,1].size ) ] ) sdata = numpy.c_[ data[:,0], numpy.transpose(numpy.array(a)) ] elif self.ST: import statdat sdata = statdat.statdat( data, 0, 1) return data, sdata, msg, True
def data_fetch( datakeys, gdat, **kwargs ): save = kwargs.get('save', False) fmt = kwargs.get('fmt', '%9.4g') print "Fetching data..." for k in gdat.keys(): try: gdat[k]['data'] = np.loadtxt(k+'.dat') print "Loaded %s succesfully." % k except: data, errmsg, rawdat = qrange.qrange_eval( gdat[k]['dir'], gdat[k]['shots'], datakeys) if save: np.savetxt(k+'.dat', data, fmt=fmt) gdat[k]['data'] = data print "Done." K = lambda key: datakeys.index(key) return gdat, K
if __name__ == '__main__': parser = argparse.ArgumentParser(__file__) parser.add_argument('--range', action = "store", \ help="range of shots to be used.") parser.add_argument('--onlyCD', action= "store_true", \ help="do only column density plot.") parser.add_argument('--onlyAZ', action= "store_true", \ help="do only azimuthal average plot.") parser.add_argument('--onlyAZAB', action= "store_true", \ help="do only azimuthal average and abel transform plot.") args = parser.parse_args() datakeys = ['SEQ:shot'] data, errmsg, rawdat = qrange.qrange_eval( os.getcwd() , args.range, datakeys) print data print type(data) if not hasattr( data, '__iter__'): #if not isinstance( data, list): data = [ data ] shots = [ int(i) for i in data ] print shots # As an example run this in 140103 # with --range 2959,2983,3016,3049 output = args.range output = output.replace('-','m') output = output.replace(':','-')
cdir = os.getcwd() BraggKeys = [SIGNALKEY, ANDOR1KEY, ANDOR2KEY, "DIMPLELATTICE:imgdet", "SEQ:shot", "DIMPLELATTICE:force_lcr3"] AllKeys = BraggKeys + [args.XKEY, args.BGKEY] print "\nObtaining data from : ", AllKeys def K(key): try: index = AllKeys.index(key) return index except Exception as e: print e exit() data, errmsg, rawdat = qrange.qrange_eval(cdir, args.range, AllKeys) # Deal with the backgrounds if args.BGKEY == "DIMPLELATTICE:force_lcr3": # This defines the value of the BGKEY that is used for background bgdval = 0.0 # This defines the value of the BGKEY that is used for signal sigval = 0.0 elif args.BGKEY == "DIMPLELATTICE:signal": bgdval = 0.0 sigval = 1.0 elif args.BGKEY == "DIMPLELATTICE:tof": bgdval = args.tofval sigval = 0.0 # Remove everything that has DL:force_lcr3 == 0 cond1 = data[:, K("DIMPLELATTICE:force_lcr3")] != 0
"DIMPLELATTICE:image", ] def K(key): return datakeys.index(key) print "Fetching data..." for k in gdat.keys(): try: gdat[k]["data"] = np.loadtxt(k + ".dat") print "Loaded %s succesfully." % k except: print k data, errmsg, rawdat = qrange.qrange_eval(gdat[k]["dir"], gdat[k]["shots"], datakeys) np.savetxt(k + ".data", data) gdat[k]["data"] = data print "Done." # Get figure started from matplotlib import rc rc("font", **{"family": "serif"}) figure = plt.figure(figsize=(12.0, 7.5)) gs = matplotlib.gridspec.GridSpec(2, 3, wspace=0.4, hspace=0.24, top=0.90, left=0.1, right=0.97, bottom=0.1) figure.suptitle(r"U/t CURVE (We use the shorthand $X_{t}\equiv\frac{X}{X_{\mathrm{TOF}}}$)") ax1 = plt.subplot(gs[0, 0]) axA1 = plt.subplot(gs[0, 1])
'label':'7$E_{r}$ July 29',\ 'dir':'/lab/data/app3/2013/1307/130729/',\ 'shots':'3243:3258,3259:3357,-3325,3364:3379',\ 'ec':'blue','fc':'lightblue',\ } datakeys = ['DIMPLELATTICE:imgdet', 'ANDOR1EIGEN:signal' , 'ANDOR2EIGEN:signal', 'HHHEIGEN:andor2norm', 'DIMPLELATTICE:force_lcr3' ] print "Fetching data..." for k in detdat.keys(): try: detdat[k]['data'] = np.loadtxt(k+'.dat') print "Loaded %s succesfully." % k except: print k data, errmsg, rawdat = qrange.qrange_eval( detdat[k]['dir'], detdat[k]['shots'], datakeys) np.savetxt(k+'.dat', data) detdat[k]['data'] = data print "Done." # Get figure started from matplotlib import rc rc('font',**{'family':'serif'}) figure = plt.figure(figsize=(4.,3.)) gs = matplotlib.gridspec.GridSpec( 1,1) figure.suptitle('') ax1 = plt.subplot( gs[0,0] )
help="range of shots to be used.") parser.add_argument('--output', action="store", \ help="optional path of png to save figure") args = parser.parse_args() rangestr = args.range.replace(':','to') rangestr = rangestr.replace(',','_') beams = ["GR1","GR2","GR3","IR1","IR2","IR3"] data = {} for beam in beams: keys = ["SEQ:shot"] for k in ["_Cx","_Cy","_Wx","_Wy"]: keys.append("LATTICEWEBCAM:"+beam+k) data[beam] = qrange.qrange_eval("./",args.range,keys)[0] ZOOM = 1 pairs = [("GR1","IR1"),("GR2","IR2"),("GR3","IR3")] fig = plt.figure(figsize=(16,12)) fig2 = plt.figure(figsize=(16,12)) gs = matplotlib.gridspec.GridSpec(3,3,wspace =0.5, hspace =0.6,top=0.9,left = 0.07,right=0.93,bottom=0.1) gs2 = matplotlib.gridspec.GridSpec(2,3,wspace =0.5, hspace =0.5,top=0.9,left = 0.07,right=0.93,bottom=0.1) for GR,IR in pairs: if GR == "GR1": #ax = fig2.add_subplot(231) #ax2 = fig2.add_subplot(234)