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 get_data(self): directory = self.get_dir() shots = self.setup_dict['shots'] if type(shots) == type([]): shots = ",".join(shots) keys = " ".join([self.setup_dict['X'], self.setup_dict['Y']]) self.data, self.errmsg, self.raw_data = qrange.qrange(directory, shots, keys) 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' self.raw_data = s + self.raw_data self.sdata = None if self.setup_dict['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)
def plotCam( KEY, axplot ): A1dat = statdat.statdat(sigNoRes, K(args.XKEY), K(KEY)) A1res = statdat.statdat(sigRes, K(args.XKEY), K(KEY)) A1tof = statdat.statdat(bgdat, K(args.XKEY), K(KEY)) A1datU = unumpy.uarray(( A1dat[:,1].tolist(), A1dat[:,3].tolist() )) try: A1resU = unumpy.uarray(( A1res[:,1].tolist(), A1res[:,3].tolist() )) plotres = True except: A1resU = unumpy.uarray(( [1.], [1.] )) plotres = False A1tofU = unumpy.uarray(( A1tof[:,1].tolist(), A1tof[:,3].tolist() )) A1datU = A1datU[ np.argsort( A1dat[:,0] )] try: A1resU = A1resU[ np.argsort( A1res[:,0] )] plotres = plotres and True except: A1resU = A1resU plotres = False A1tofU = A1tofU[ np.argsort( A1tof[:,0] )] axplot.errorbar( A1dat[:,0][np.argsort(A1dat[:,0])], unumpy.nominal_values(A1datU/A1tofU),\ yerr = unumpy.std_devs(A1datU/A1tofU), \ capsize=0., elinewidth = 2.75*msscale ,\ fmt='.', ecolor='green', mec='green', \ mew=2.75*msscale, ms=11.0*msscale,\ marker='o', mfc='limegreen', \ label="signal/base") if plotres and args.singleres: tw = axplot.twinx() tw.errorbar( A1dat[:,0][np.argsort(A1dat[:,0])], unumpy.nominal_values(A1datU/A1resU),\ yerr = unumpy.std_devs(A1datU/A1resU), \ capsize=0., elinewidth = 2.75*msscale ,\ fmt='.', ecolor='red', mec='red', \ mew=2.75*msscale, ms=11.0*msscale,\ marker='o', mfc='pink', \ label="signal/base") axplot.grid() axplot.set_xlabel(args.XKEY) axplot.set_ylabel(KEY)
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 plotkey( ax, gk, key, dat, base, marker="o", ms=5.0, mec="def", mfc="def", labelstr="def", save=False, raw=True, raw_offset=0 ): if mec == "def": mec = gdat[gk]["ec"] if mfc == "def": mfc = gdat[gk]["fc"] if labelstr == "def": labelstr = gdat[gk]["label"] if raw: ax.plot( fx(dat[:, K("DIMPLELATTICE:knob05")]) + raw_offset, dat[:, K(key)], ".", marker="o", mec=mec, ms=3, mew=1.0, color="gray", alpha=0.5, ) datS = statdat.statdat(dat, K("DIMPLELATTICE:knob05"), K(key)) alldat.append(datS) ax.errorbar( fx(datS[:, 0]), datS[:, 1] / base, yerr=datS[:, 3] / base, capsize=0.0, elinewidth=1.0, fmt=".", ecolor=mec, mec=mec, mew=1.0, marker=marker, mfc=mfc, ms=ms, label=labelstr, ) if save: fname = key.replace(":", "_") + "_" + labelstr[-3:] + ".rawdat" X = np.transpose(np.vstack((fx(datS[:, 0]), datS[:, 1] / base, datS[:, 3] / base))) np.savetxt(fname, X, fmt="%10.2f", delimiter="\t", newline="\n")
########## MAKE THE BIG PLOT AT THE BOTTOM ###### scale = (cols ** 0.5) / 3.0 msscale = (cols ** 0.5) / 3.5 if verbose: print "rows = ", rows print "cols = ", cols print "mainplotrows = ", mainplotrows if args.ratio == True: ax = plt.subplot(gs[Yplots : Yplots + mainplotrows, : (cols + 1) / 2]) else: ax = plt.subplot(gs[Yplots : Yplots + mainplotrows, :]) if args.ratio == True: ax2 = plt.subplot(gs[Yplots : Yplots + mainplotrows, (cols + 1) / 2 :]) xdat = statdat.statdat(sgdat, K(args.XKEY), K(SIGNALKEY)) xdatNoRes = statdat.statdat(sigNoRes, K(args.XKEY), K(SIGNALKEY)) xdatRes = statdat.statdat(sigRes, K(args.XKEY), K(SIGNALKEY)) bxdat = statdat.statdat(bgdat, K(args.XKEY), K(SIGNALKEY)) ax.errorbar( xdatNoRes[:, 0], xdatNoRes[:, 1], yerr=xdatNoRes[:, 3], capsize=0.0, elinewidth=2.75 * msscale, fmt=".", ecolor="blue", mec="blue", mew=2.75 * msscale, ms=11.0 * msscale,
base = 0.656 base_err = 0.068 base1 = base ax1.axvspan( 37.9/5.9-0.5, 37.9/5.9+0.5, facecolor='lightblue', alpha=0.6, linewidth=0) ax1.axvspan( -37.9/5.9-0.5, -37.9/5.9+0.5, facecolor='lightblue', alpha=0.6, linewidth=0) ax1.axhspan( (base-base_err)/base1, (base+base_err)/base1, facecolor='gray', alpha=0.6, linewidth=0) for k in sorted(detdat.keys()): dat = detdat[k]['data'][:,(0,3,4)] # Remove baslines from the data dat = dat[ dat[:,2] == -1. ] dat = statdat.statdat( dat, 0, 1 ) ax1.errorbar( (dat[:,0]+131.)/5.9, dat[:,1]/base1, yerr=dat[:,3]/base1,\ capsize=0., elinewidth=1.,\ fmt='.', ecolor=detdat[k]['ec'], mec=detdat[k]['ec'],\ mew=1.0, marker='o', mfc=detdat[k]['fc'],\ #label=detdat[k]['label']) label='$7E_{r}$\n$a_{s}=190a_{0}$') #ax1.errorbar( dat[:,0], dat[:,1]/zero, yerr=dat[:,3]/zero, fmt='.', ecolor=edgecolor, mec=edgecolor, mew=1.0, marker='o', mfc=fillcolor) ax1.grid() ax1.set_xlabel('Detuning ($\Gamma$)') ax1.set_ylabel('Bragg / Diffuse',ha='center',labelpad=20) ax1.set_xlim(-15.,15.) #ax1.xaxis.set_major_locator( matplotlib.ticker.MultipleLocator(0.1) ) #ax1.set_ylim(0.92, 1.48)
ax1.plot( d[:,0], d[:,1], 'o', color = colors[i], markersize=msize, markeredgewidth=0.3, label=Hleg) ax1.plot( d[:,0], d[:,2], 'x', color = colors[i], markersize=msize, markeredgewidth=1.0, label=Vleg ) ax1.plot( HfitX, HfitY, linestyle = '-', color = colors[i]) ax1.plot( VfitX, VfitY, linestyle = '-', color = colors[i]) Hlegb = "%s\nX Position of Waist" %dat Vlegb = "Y Position of Waist" camPixSize = 4.65 msizeb= 8 if i == 0: HposRefStat = statdat.statdat( d[:,[0,6]] , 0, 1) HposRef = HposRefStat[:,1] * camPixSize VposRefStat = statdat.statdat( d[:,[0,7]] , 0, 1) VposRef = VposRefStat[:,1] * camPixSize print HposRef print VposRef if i > 0: HposStat = statdat.statdat( d[:,[0,6]] , 0, 1) Hpos = HposStat[:,1] * camPixSize VposStat = statdat.statdat( d[:,[0,7]] , 0, 1) Vpos = VposStat[:,1] * camPixSize ax1b.plot( HposStat[:,0], Hpos - HposRef, '->', alpha=0.3,color = colors[i], markersize=msizeb, markeredgewidth=0.3, label=Hlegb) ax1b.plot( HposStat[:,0], Vpos - VposRef, '-<', alpha=0.3,color = colors[i], markersize=msizeb, markeredgewidth=1.0, label=Vlegb)
rangestr = args.range.replace(':','to') rangestr = rangestr.replace(',','_') shots = qrange.parse_range(args.range) data = [] for s in shots: report = ConfigObj( 'report'+s+'.INI') line = [ qrange.evalstr( report, args.XKEY ) ] for Y in args.YKEYS: line.append( qrange.evalstr( report, Y) ) data.append(line) dat = np.array(data) #print dat out = statdat.statdat( dat, 0, 1)[:,0] header = '#\n# Column index\n# 0 %s\n' % args.XKEY for i,Y in enumerate(args.YKEYS): header = header + '# %d %s\n' % ( 3*i+1, Y ) header = header + '# %d %s\n' % ( 3*i+2, 'standard deviation' ) header = header + '# %d %s\n' % ( 3*i+3, 'standard error of the mean' ) header = header + '# %d %s\n' % ( 3*i+4, 'pk-pk' ) try: out = np.c_[ out, statdat.statdat( dat, 0, i+1 )[:,1:] ] except: continue print header, format = '%8.3f'
def plotkey_relerr( ax, gdict, K, fx, xkey, ykey, dat, base, **kwargs): try: defmarker = gdict['marker'] except: defmarker = 'o' marker = kwargs.get( 'marker', defmarker) ms = kwargs.get( 'ms', 5. ) mew = kwargs.get( 'mew', 1.0 ) mec = kwargs.get( 'mec', gdict['ec']) mfc = kwargs.get( 'mfc', gdict['fc']) save = kwargs.get( 'save', False ) exceptions = kwargs.get( 'exceptions', False) raw = kwargs.get( 'raw', True ) raw_offset = kwargs.get( 'raw_offset', 0.) labelstr = kwargs.get( 'labelstr', gdict['label'] ) xkey0 = xkey ykey0 = ykey xkey = K(xkey) ykey = K(ykey) try: datS = statdat.statdat( dat, xkey, ykey ) Ystderr = datS[:,3]/base Ystddev = datS[:,2]/base X = datS[:,0] Y = datS[:,1]/base def meanY( x ): try: index = np.where( X == x )[0][0] assert isinstance( index, int ) return Y[index] except: print "Error finding mean value of Y at X = ", x raise if raw: datY = dat[:,ykey]/base datX = dat[:,xkey] datYnormed = np.array([ datY[i] / meanY( datX[i] ) \ for i in range(len(datX)) ] ) rawcolor = kwargs.pop('rawcolor', 'gray') ax.plot( fx(datX)+raw_offset, datYnormed, '.',\ marker='.', ms=4.5,\ color=rawcolor, alpha=0.5) ax.plot( fx(X), 100.*2.*Ystderr/Y, '.',\ mec=mec, mew=mew, marker=marker, mfc=mfc, ms=ms,\ label=labelstr) #ax.plot( fx(X), 100.*Ystddev/Y, '.',\ # mec=mec, mew=mew, marker=marker, mfc=mfc, ms=ms,\ # label=labelstr) if save: fname = xkey0.replace(':','_') + '_' + labelstr[-3:] + 'RELERR.rawdat' X = np.transpose(np.vstack( ( fx(datS[:,0]), datS[:,1]/base, datS[:,3]/base ))) np.savetxt( fname, X, fmt='%10.2f', delimiter='\t', newline='\n') return fx(datS[:,0]), unumpy.uarray(( datS[:,1]/base, datS[:,3]/base )) except: print "Exception occured in plotkey %s vs %s"% (ykey0,xkey0) if exceptions: raise return None
def plotkey( ax, gdict, K, fx, xkey, ykey, dat, base, **kwargs): try: defmarker = gdict['marker'] except: defmarker = 'o' marker = kwargs.get( 'marker', defmarker) ms = kwargs.get( 'ms', 5. ) mew = kwargs.get( 'mew', 1.0 ) mec = kwargs.get( 'mec', gdict['ec']) mfc = kwargs.get( 'mfc', gdict['fc']) ew = kwargs.get( 'ew', 1.0 ) ecap = kwargs.get( 'ecap', 0. ) save = kwargs.get( 'save', False ) exceptions = kwargs.get( 'exceptions', False) raw = kwargs.get( 'raw', True ) raw_offset = kwargs.get( 'raw_offset', 0.) labelstr = kwargs.get( 'labelstr', gdict['label'] ) xkey0 = xkey ykey0 = ykey xkey = K(xkey) ykey = K(ykey) if kwargs.get('use_stddev', False): error_index = 2 # standard deviation else: error_index = 3 # standard error discard = kwargs.pop('discard',None) if discard is not None: if 'y>' in discard.keys(): dat = dat[ dat[:,ykey] < discard['y>'] ] if 'y<' in discard.keys(): dat = dat[ dat[:,ykey] > discard['y<'] ] try: both_offset = kwargs.get('both_offset', 0.) yf = kwargs.get( 'yf', None) if yf is not None: ydict = kwargs.get('yf_kwargs', {} ) yf_usex = kwargs.get('yf_usex', False) if yf_usex is True: ydict['x'] = fx(xc) if raw: rawcolor = kwargs.pop('rawcolor', 'gray') rawalpha = kwargs.pop('rawalpha', 0.5) rawms = kwargs.pop('rawalpha', 4.5) xraw = fx(dat[:, xkey] ) + raw_offset + both_offset yraw = dat[:,ykey]/base if yf is not None: yraw = yf( yraw, **ydict ) ax.plot( xraw, yraw , '.', marker='.', ms=rawms,\ color=rawcolor, alpha=rawalpha) datS = statdat.statdat( dat, xkey, ykey, **kwargs) xplot = fx(datS[:,0]) yplot = datS[:,1]/base yploterr = datS[:,error_index]/base if yf is not None: yunc = unumpy.uarray(( yplot, yploterr )) yunc = yf( yunc, **ydict ) yplot = unumpy.nominal_values( yunc ) yploterr = unumpy.std_devs( yunc ) ax.errorbar( xplot+both_offset, yplot, yerr=yploterr,\ capsize=ecap, elinewidth=ew,\ fmt='.', ecolor=mec, mec=mec,\ mew=mew, marker=marker, mfc=mfc, ms=ms,\ label=labelstr) guide = kwargs.get( 'guide', False) if guide: guide_color = kwargs.get('guide_color', mec) f = interp1d( xplot, yplot, kind='linear') xnew = np.linspace( xplot.min(), xplot.max(), 120) ax.plot( xnew, f(xnew), color=guide_color, zorder = 1.1 ) if save: fname = xkey0.replace(':','_') + '_' + labelstr[-3:] + '.rawdat' X = np.transpose(np.vstack( ( xplot, yplot, yploterr ))) np.savetxt( fname, X, fmt='%10.2f', delimiter='\t', newline='\n') if kwargs.get('return_raw', False): return xraw, yraw return xplot, unumpy.uarray(( yplot, yploterr )) except: print "Exception occured in plotkey %s vs %s"% (ykey0,xkey0) if exceptions: raise
def plotCam( KEY, axplot ): A1dat = statdat.statdat(sigNoRes, K(args.XKEY), K(KEY)) A1res = statdat.statdat(sigRes, K(args.XKEY), K(KEY)) A1tof = statdat.statdat(bgdat, K(args.XKEY), K(KEY)) A1datU = unumpy.uarray(( A1dat[:,1].tolist(), A1dat[:,3].tolist() )) try: A1resU = unumpy.uarray(( A1res[:,1].tolist(), A1res[:,3].tolist() )) plotres = True except: A1resU = unumpy.uarray(( [1.], [1.] )) plotres = False try: A1tofU = unumpy.uarray(( A1tof[:,1].tolist(), A1tof[:,3].tolist() )) plottof = True except: A1tofU = np.ones_like(A1datU) plottof = False A1datU = A1datU[ np.argsort( A1dat[:,0] )] try: A1resU = A1resU[ np.argsort( A1res[:,0] )] plotres = plotres and True except: A1resU = A1resU plotres = False if plottof == True: A1tofU = A1tofU[ np.argsort( A1tof[:,0] )] xvals = A1dat[:,0][np.argsort(A1dat[:,0])] yunc = A1datU/A1tofU yvals = unumpy.nominal_values(yunc) yerrvals = unumpy.std_devs(yunc) axplot.errorbar( xvals, yvals, yerr=yerrvals,\ capsize=0., elinewidth = 2.75*msscale ,\ fmt='.', ecolor='green', mec='green', \ mew=2.75*msscale, ms=11.0*msscale,\ marker='o', mfc='limegreen', \ label="signal/base") if plotres and args.singleres: tw = axplot.twinx() tw.errorbar( A1dat[:,0][np.argsort(A1dat[:,0])], unumpy.nominal_values(A1datU/A1resU),\ yerr = unumpy.std_devs(A1datU/A1resU), \ capsize=0., elinewidth = 2.75*msscale ,\ fmt='.', ecolor='red', mec='red', \ mew=2.75*msscale, ms=11.0*msscale,\ marker='o', mfc='pink', \ label="signal/base") axplot.grid() axplot.set_xlabel(args.XKEY) if 'ANDOR1' in KEY: axplot.set_ylabel("A1/A1_tof") print "A1/A1tof:\n\t", print_uarray(yunc) elif 'ANDOR2' in KEY: axplot.set_ylabel("A2/A2_tof") print "A2/A2tof:\n\t", print_uarray(yunc) else: axplot.set_ylabel(KEY)