Esempio n. 1
0
def fitimageslice(img,res_x,res_y,xslice,yslice,avg_e_func=None,h5file=None,plot=False):
	# ======================================
	# Extract start and end values
	# (NOT necessarily indices!)
	# ======================================
	x_start = xslice[0]
	x_end   = xslice[1]
	y_start = yslice[0]
	y_end   = yslice[1]

	# ======================================
	# Round to pixel edges.  Pixel edges in
	# px units are at 0.5, 1.5, 2.5, etc.
	# ======================================
	y_low = _np.round(y_start-0.5) + 0.5
	y_high = _np.round(y_end-0.5) + 0.5

	# ======================================
	# Take a strip between edges
	# ======================================
	y_px = _mt.linspacestep(1,img.shape[0])
	y_bool = _np.logical_and(y_low<y_px,y_px<y_high)
	strip = img[y_bool,x_start:x_end]

	# ======================================
	# Sum over the strip to get an average 
	# ======================================
	histdata = _np.sum(strip,0)
	xbins = len(histdata)
	x = _np.linspace(1,xbins,xbins)*res_x
	
	# ======================================
	# Fit with a Gaussian to find spot size
	# ======================================
	# plotbool=True
	# plotbool = False
	# varbool  = False
	varbool  = True
	gaussout=_gaussfit(x,histdata,sigma_y=_np.ones(xbins),
			plot=plot,
			variance_bool=varbool,
			verbose=False,
			background_bool=True,
			p0=[16000,0.003,1e-6,0]
			)

	# if plot:
	#         _plt.show()

	if avg_e_func != None:
		# ======================================
		# Get average energy of strip
		# ======================================
		# Sum to get relative counts of pixels
		relcounts=_np.sum(strip,1) / _np.float(_np.sum(strip))
		# Integrate each pixel strip
		Eavg=0
		for i,val in enumerate(_mt.linspacestep(y_low,y_high-1)):
			Eavg=Eavg + avg_e_func(val,val+1,h5file,res_y)*relcounts[i]
		return Eavg,gaussout
	else:
		return gaussout
Esempio n. 2
0
def findpinch(img,xbounds=None,ybounds=None,step=1,verbose=False):
	# ======================================
	# Translate to clearer variables
	# ======================================
	if xbounds is None:
		xstart=0
		xstop=img.shape[0]
	else:
		xstart = xbounds[0]
		xstop  = xbounds[1]

	if ybounds is None:
		ystart=0
		ystop=img.shape[1]
	else:
		ystart = ybounds[0]
		ystop  = ybounds[1]

	xrange = slice(xstart,xstop)
	yrange = slice(ystart,ystop)

	img=img[yrange,xrange]
	if verbose:
		fig=_mt.figure('To process')
		ax=fig.add_subplot(111)
		ax.imshow(img)
		_plt.show()
	
	# ======================================
	# Check number of points and
	# initialize arrays
	# ======================================
	num_pts   = (ystop-ystart)/step
	sigs      = _np.zeros(num_pts)
	variance  = _np.zeros(num_pts)
	stddev    = _np.zeros(num_pts)
	varerr    = _np.zeros(num_pts)
	chisq_red = _np.zeros(num_pts)
	
	# ======================================
	# Fit individual slices
	# ======================================
	for i,val in enumerate(_mt.linspacestep(0,ystop-ystart-step,step)):
		# Take a strip of the image
		strip = img[slice(val,val+step),:]
		
		# Sum over the strip to get an average of sorts
		histdata = _np.sum(strip,0)
		xbins = len(histdata)
		x = _np.linspace(1,xbins,xbins)
		
		# Fit with a Gaussian to find spot size
		# plotbool=True
		plotbool = False
		varbool  = False
		popt,pcov,chisq_red[i] = _mt.gaussfit(
				x,
				histdata,
				sigma_y=_np.ones(xbins),
				plot=plotbool,
				variance_bool=varbool,
				background_bool=True,
				verbose=False)
	
		variance[i] = popt[2]
	
	# ======================================
	# Fit 2nd-deg poly to results
	# ======================================
	yvar=_np.shape(_mt.linspacestep(ystart,ystop,step))[0]-1
	yvar=_mt.linspacestep(1,yvar)
	
	out=_np.polyfit(yvar,variance,2)

	if verbose:
		# pass
		_plt.figure()
		pvar = ystart + yvar*step
		_plt.plot(pvar,variance,'.-',pvar,_np.polyval(out,yvar),'-')
		_plt.show()

	# ======================================
	# Report minimum in steps and pixels
	# ======================================
	fitmin=-out[1]/(2*out[0])
	pxmin = fitmin*step+ystart

	print 'Minimum at {} step, {}px'.format(fitmin,pxmin)

	return pxmin
Esempio n. 3
0
def analyze_matlab(
        data     = None  ,
        camname  = None  ,
        oimg     = None  ,
        rect     = None  ,
        fitpts   = None  ,
        roiaxes  = None  ,
        plotaxes = None  ,
        verbose  = False ,
        uid      = None
        ):

    plt.close()
    # ======================================
    # Log inputs
    # ======================================
    frame = inspect.currentframe()
    args, temp, temp, values = inspect.getargvalues(frame)
    
    logger.log(level=1, msg='Input values:')
    for i, arg in enumerate(args):
        # pdb.set_trace()
        logger.log(level=1, msg='Arg name: {}, arg value: {}'.format(arg, values[arg]))

    logger.log(level=1, msg='Rectangle: x0: {}, y0: {}, x1: {}, y1: {}, width: {}, height: {}'.format(
        rect.x0           ,
        rect.y0           ,
        rect.x1           ,
        rect.y1           ,
        rect.get_width()  ,
        rect.get_height()
        )
        )
    
    # ======================================
    # Load and transfer matlab variables
    # ======================================
    # if (f is None):
    #         infile     = 'forpython.mat'
    #         f          = h5.File(infile);
    f = data.file

    if data is None:
        data       = f['data']

    if camname is None:
        camname = f['camname']
        camname = mt.derefstr(camname)

    # if imgnum is None:
    #         imgnum = f['imgnum'][0, 0]

    imgstr = data['raw']['images'][str(camname)]
    res    = imgstr['RESOLUTION'][0, 0]
    res    = res*1.0e-6

    # ======================================
    # Quadrupole set point
    # ======================================
    raw_rf     = data['raw']
    scalars_rf = raw_rf['scalars']
    setQS_str  = scalars_rf['step_value']
    setQS_dat  = E200.E200_api_getdat(setQS_str, uid).dat[0]
    setQS = mt.hardcode.setQS(setQS_dat)
    logger.info('setQS_dat is: {}'.format(setQS_dat))
    # logger.debug('setQS_dat type is: {}'.format(type(setQS_dat)))
    
    # ======================================
    # Bend magnet strength
    # ======================================
    B5D36     = data['raw']['scalars']['LI20_LGPS_3330_BDES']['dat']
    B5D36     = mt.derefdataset(B5D36, f)
    B5D36_en  = B5D36[0]
    # new_en    = (B5D36_en-4.3)
    gamma     = (B5D36_en/0.5109989)*1e3
    # new_gamma = (new_en/0.5109989)*1e3
    
    # ======================================
    # Translate into script params
    # ======================================
    n_rows    = 5
    if rect is None:
        xstart = 275
        xstop  = 325
        ystart = 1870
        ystop  = 1900
    else:
        xstart = rect.y0
        xstop  = rect.y1
        ystart = rect.x0
        ystop  = rect.x1

        xstart = np.round(xstart)
        xstop  = np.round(xstop)
        ystart = np.round(ystart)
        ystop  = np.round(ystop)
    
    # ======================================
    # Get image
    # ======================================
    # if oimg is None:
    #         oimg = E200.E200_load_images(imgstr, f)
    #         oimg = oimg.image[imgnum-1, :, :]
    # oimg=np.fliplr(oimg)

    img = oimg[xstart:xstop, ystart:ystop]

    # if roiaxes is not None:
    #     imgplot = roiaxes.imshow(img, interpolation='none', origin='lower', aspect='auto')
    
    # ======================================
    # Create a histogram of std dev
    # ======================================
    hist_vec  = mt.linspacestep(ystart, ystop, n_rows)
    n_groups  = np.size(hist_vec)
    # hist_data = np.zeros([n_groups, 2])
    x_pix     = np.round(mt.linspacestep(xstart, xstop-1, 1))
    x_meter   = (x_pix-np.mean(x_pix)) * res
    if camname == 'ELANEX':
        logger.log(level=logging.INFO, msg='Lanex is tipped at 45 degrees: dividing x axis by sqrt(2)')
        x_meter = x_meter/np.sqrt(2)
    # x_sq      = x_meter**2
    
    num_pts      = n_groups
    variance     = np.zeros(num_pts)
    gaussresults = np.empty(num_pts, object)
    stddev       = np.zeros(num_pts)
    varerr       = np.zeros(num_pts)
    chisq_red    = np.zeros(num_pts)
    y            = np.array([])

    for i in mt.linspacestep(0, n_groups-1):
        sum_x = np.sum(img[:, i*n_rows:(i+1)*n_rows], 1)
        y = np.append(y, ystart+n_rows*i+(n_rows-1.)/2.)
        # popt, pcov, chisq_red[i] = mt.gaussfit(x_meter, sum_x, sigma_y=np.sqrt(sum_x), plot=False, variance_bool=True, verbose=False, background_bool=True)
        gaussresults[i] = mt.gaussfit(x_meter, sum_x, sigma_y=np.sqrt(sum_x), plot=False, variance_bool=True, verbose=False, background_bool=True)
        variance[i]         = gaussresults[i].popt[2]
        # varerr[i]           = pcov[2, 2]
        # stddev[i]           = np.sqrt(pcov[2, 2])

    # ======================================
    # Remove nan from arrays
    # ======================================
    nan_ind   = np.logical_not(np.isnan(variance))
    variance  = variance[nan_ind]
    stddev    = stddev[nan_ind]
    varerr    = varerr[nan_ind]
    chisq_red = chisq_red[nan_ind]
    y         = y[nan_ind]
    
    # ======================================
    # Get energy axis
    # ======================================
    if camname == 'ELANEX':
        ymotor = data['raw']['scalars']['XPS_LI20_DWFA_M5']['dat']
        ymotor = mt.derefdataset(ymotor, f)
        ymotor = ymotor[0]*1e-3
        # print 'Ymotor is {}'.format(ymotor)
        logger.log(level=loggerlevel, msg='First: Original ymotor is: {}'.format(ymotor))
    
        ymotor = setQS.elanex_y_motor()*1e-3

        logger.log(level=loggerlevel, msg='First: Reconstructed ymotor is: {ymotor}'.format(ymotor=ymotor))
    else:
        ymotor = None

    # eaxis     = E200.eaxis(camname=camname, y=y, res=res, E0=20.35, etay=0, etapy=0, ymotor=ymotor)

    EnAxis = E200.Energy_Axis(camname=camname, hdf5_data=data, uid=uid)

    #  eaxis = E200.eaxis(y=y, camname=camname, res=res, E0=20.35, etay=0, etapy=0, ymotor=ymotor)
    #  eaxis = E200.eaxis(y=y, uid=uid, camname=camname, hdf5_data=data)
    eaxis = EnAxis.energy(ypx=y)

    yimg     = mt.linspacestep(1, img.shape[1])
    #  imgeaxis = E200.eaxis(camname=camname, y=yimg, res=res, E0=20.35, etay=0, etapy=0, ymotor=ymotor)
    #  imgeaxis = E200.eaxis(y=yimg, uid=uid, camname=camname, hdf5_data=data)
    imgeaxis = EnAxis.energy(ypx=yimg)

    yoimg     = mt.linspacestep(1, oimg.shape[1])
    #  oimgeaxis = E200.eaxis(camname=camname, y=yoimg, res=res, E0=20.35, etay=0, etapy=0, ymotor=ymotor)
    #  oimgeaxis = E200.eaxis(y=yoimg, uid=uid, camname=camname, hdf5_data=data)
    oimgeaxis = EnAxis.energy(ypx=yoimg)
    
    # ======================================
    # Default Twiss and beam params
    # ======================================
    emitx  = 0.001363/gamma
    # betax  = 1
    # alphax = 0
    # gammax = (1+np.power(alphax, 2))/betax
    twiss    = sltr.BeamParams(
        beta  = 0.5,
        alpha = 0,
        emit  = emitx
        )

    # ======================================
    # Quadrupole values
    # ======================================
    QS1_K1 = setQS.QS1.K1
    QS2_K1 = setQS.QS2.K1

    logger.log(level=loggerlevel, msg='QS1_K1 is: {}'.format(QS1_K1))
    logger.log(level=loggerlevel, msg='QS2_K1 is: {}'.format(QS2_K1))

    # ======================================
    # Create beamlines
    # ======================================
    # beamline=bt.beamlines.IP_to_cherfar(twiss_x=twiss, twiss_y=twiss, gamma=gamma)
    if camname == 'ELANEX':
        beamline = bt.beamlines.IP_to_lanex(
            beam_x = twiss, beam_y=twiss,
            QS1_K1 = QS1_K1,
            QS2_K1 = QS2_K1
            )
        #  from PyQt4.QtCore import pyqtRemoveInputHook
        #  pyqtRemoveInputHook()
        #  pdb.set_trace()
    else:
        beamline = bt.beamlines.IP_to_cherfar(
            beam_x=twiss, beam_y=twiss,
            QS1_K1 = QS1_K1,
            QS2_K1 = QS2_K1
            )

    beamline_array = np.array([])
    for i, value in enumerate(eaxis):
        # beamline.gamma = value/5.109989e-4
        beamline.gamma = sltr.GeV2gamma(value)
        beamline_array = np.append(beamline_array, copy.deepcopy(beamline))
    
    # ======================================
    # Fudge error
    # ======================================
    chisq_factor = 1e-28
    # used_error   = stddev*np.sqrt(chisq_factor)
    used_error   = variance*np.sqrt(chisq_factor)

    # ======================================
    # Fit beamline scan
    # ======================================
    scanresults = bt.fitBeamlineScan(beamline_array,
            variance,
            # emitx,
            error=used_error,
            verbose=True,
            plot=False,
            eaxis=eaxis
            )
    
    # ======================================
    # Plot results
    # ======================================
    mpl.rcParams.update({'font.size': 12})

    if plotaxes is not None:
        bt.plotfit(eaxis,
                variance,
                scanresults.fitresults.beta,
                scanresults.fitresults.X_unweighted,
                top='Emittance/Twiss Fit to Witness Butterfly',
                # top='Emittance and Beam Parameter Fit\nto Ionization-Injected Witness Bunch',
                figlabel='Butterfly Fit',
                bottom='Energy [GeV]',
                axes = plotaxes,
                error=used_error
                )
        plt.show()

    out = AnalysisResults(
        gaussfits = gaussresults,
        scanfit   = scanresults ,
        img       = img         ,
        yimg      = yimg        ,
        imgeaxis  = imgeaxis    ,
        oimg      = oimg        ,
        yoimg     = yoimg       ,
        oimgeaxis = oimgeaxis   ,
        eaxis     = eaxis       ,
        variance  = variance    ,
        xstart    = xstart      ,
        xstop     = xstop       ,
        ystart    = ystart      ,
        ystop     = ystop       ,
        res       = res         ,
        x_meter   = x_meter
        )
    
    return out
Esempio n. 4
0
def results2pdf(path, local=False, verbose=False, loglevel=logging.CRITICAL):
    # =====================================
    # Regex-out the dataset number, date
    # =====================================
    dataset_string  = re.search('E200_(\d+)', path).groups()[0]
    date_string_tmp = re.search('\d{8}', path).group()

    year  = np.int(date_string_tmp[0:4])
    month = np.int(date_string_tmp[4:6])
    day   = np.int(date_string_tmp[6:])

    date        = dt.date(year=year, month=month, day=day)
    date_string = date.strftime('%b %-d, %Y')

    # =====================================
    # Load data
    # =====================================
    data = E200.E200_load_data(path, local=local, readonly=True)
    
    processed_drill = data.wdrill.data.processed
    scalars_drill   = processed_drill.scalars
    vectors_drill   = processed_drill.vectors
    arrays_drill    = processed_drill.arrays
    
    scalars_rdrill = data.rdrill.data.raw.scalars
    
    # =====================================
    # Helper function
    # =====================================
    def get_str(drill):
        out_str = drill._hdf5
        return drill, out_str
    
    # =====================================
    # get uids, energy axes, images, etc
    # =====================================
    valid = scalars_drill.ss_ELANEX_valid
    uids = valid.UID[valid.dat is True]
    #  uids = uids[0:4]
    
    valid_drill, valid_str               = get_str(scalars_drill.ss_ELANEX_valid)
    valid                               = E200.E200_api_getdat(valid_str, uids)
    
    quadval_drill, quadval_str           = get_str(scalars_rdrill.step_value)
    quadval                             = E200.E200_api_getdat(quadval_str, uids)
    
    emit_n_drill, emit_n_str             = get_str(scalars_drill.ss_ELANEX_emit_n)
    emit_n                              = E200.E200_api_getdat(emit_n_str, uids)
    
    betastar_drill, betastar_str         = get_str(scalars_drill.ss_ELANEX_betastar)
    betastar                            = E200.E200_api_getdat(betastar_str, uids)
    
    sstar_drill, sstar_str               = get_str(scalars_drill.ss_ELANEX_sstar)
    sstar                               = E200.E200_api_getdat(sstar_str, uids)
    
    rect_drill, rect_str                 = get_str(vectors_drill.ss_ELANEX_rect)
    rects                               = E200.E200_api_getdat(rect_str, uids)
    
    eaxis_drill, eaxis_str               = get_str(vectors_drill.ss_ELANEX_energy_axis)
    eaxis                               = E200.E200_api_getdat(eaxis_str, uids)
    
    variance_drill, variance_str         = get_str(vectors_drill.ss_ELANEX_variance)
    variance                            = E200.E200_api_getdat(variance_str, uids)
    
    beta_drill, beta_str                 = get_str(vectors_drill.ss_ELANEX_LLS_beta)
    beta                                = E200.E200_api_getdat(beta_str, uids)
    
    y_error_drill, y_error_str           = get_str(vectors_drill.ss_ELANEX_LLS_y_error)
    y_error                             = E200.E200_api_getdat(y_error_str, uids)
    
    X_unweighted_drill, X_unweighted_str = get_str(arrays_drill.ss_ELANEX_LLS_X_unweighted)
    X_unweighted                        = E200.E200_api_getdat(X_unweighted_str, uids)
    
    selected_img_drill, selected_img_str = get_str(arrays_drill.ss_ELANEX_selected_img)
    selected_img                        = E200.E200_api_getdat(selected_img_str, uids)
    
    oimg_eaxis_drill, oimg_eaxis_str     = get_str(vectors_drill.ss_ELANEX_oimg_eaxis)
    oimg_eaxis                          = E200.E200_api_getdat(oimg_eaxis_str, uids)
    
    elanex_drill, elanex_str             = get_str(data.rdrill.data.raw.images.ELANEX)
    images                              = E200.E200_load_images(elanex_str, uids)
    
    E224_Probe_drill, E224_Probe_str     = get_str(data.rdrill.data.raw.images.E224_Probe)
    
    # =====================================
    # Determine laser on shots
    # =====================================
    laseron = laser_on_off(E224_Probe_str, uids)
    
    # =====================================
    # Determine number of shots, pages
    # =====================================
    num_shots      = len(valid)
    slots_per_page = 5
    pages          = np.int(np.ceil(num_shots/np.float(slots_per_page)))
    
    # =====================================
    # Create filename, pdf, main title
    # =====================================
    now      = dt.datetime.now()
    filename = '{}_processed_{}-{:02d}-{:02d}_{:02d}{:02d}.pdf'.format(dataset_string, now.year, now.month, now.day, now.hour, now.minute)
    pdf      = PdfPages(filename)
    main_title = 'Single Shot Emittance Analysis, Dataset {dataset}, {datestring}, Page {{}}/{totalpgs}'.format(
        dataset    = dataset_string,
        datestring = date_string,
        totalpgs   = pages+1
        )
    layout_rect = [0, 0, 1, 0.95]

    # =====================================
    # Create overview
    # =====================================

    worksheet(data, pdf, main_title)
    
    # =====================================
    # Basic formatting options
    # =====================================
    linewidth = 1
    fontsize  = 7
    
    # =====================================
    # Create pages with slots_per_page
    # number of analysis/page
    # =====================================
    for i in range(pages):
        gs = gridspec.GridSpec(5, 3)
        fig = plt.figure(figsize=(8.5, 11))
        fig.suptitle(main_title.format(i+2))
    
        # =====================================
        # Add analysis to each slot
        # =====================================
        for j in range(slots_per_page):
            indx = i*slots_per_page+j
            print(indx)
            # =====================================
            # Only add if there are shots left
            # =====================================
            if indx < num_shots:
                # =====================================
                # Plot Energy
                # =====================================
                img_to_plot = np.fliplr(np.rot90(images.images[indx]))
                uid = images.UID[indx]
    
                ax     = fig.add_subplot(gs[j, 0])
                e_axis = oimg_eaxis.dat[indx]
                e_axis = np.flipud(e_axis)
    
                # =====================================
                # Get energy, pixel ranges
                # =====================================
                # x_min = 1
                x_max = img_to_plot.shape[0]
                # x_range = x_max-x_min
    
                # y_min = e_axis[-1]
                # y_max = e_axis[0]
                # y_max = img_to_plot.shape[1]
                # y_range = y_max-y_min
    
                # aspect = x_range/y_range * img_to_plot.shape[1]/img_to_plot.shape[0]
                # aspect = np.power(np.float64(img_to_plot.shape[1])/np.float64(img_to_plot.shape[0]), 2)
                
                # extent = (x_min, x_max, y_min, y_max)
    
                # =====================================
                # Show image
                # =====================================
                #  ax.imshow(img_to_plot, extent=extent, aspect=aspect, origin='lower')
                #  ax.imshow(img_to_plot, aspect=aspect, origin='lower')
                #  img = mpl.image.NonUniformImage(ax)
                #  img.set_data(e_axis, mt.linspacestep(1, x_max), img_to_plot)
                pixels      = selected_img.dat[indx].flatten()
                hist, edges = np.histogram(pixels, bins=50)
                new_edges   = edges[1:]
                max_count   = np.max(new_edges[hist > 50])
                img         = mt.NonUniformImage(e_axis, mt.linspacestep(1, x_max), img_to_plot, ax=ax)
                img.set_clim([0, max_count])
                mt.addlabel(axes            = ax, ylabel='Pixels', xlabel='Energy [GeV]')
                cb                          = fig.colorbar(img)
                ax.tick_params(labelsize    = fontsize)
                cb.ax.tick_params(labelsize = fontsize)
                ax.get_figure().tight_layout()
    
                # =====================================
                # Get rectangle info
                # =====================================
                thisrect = rects.dat[indx]
    
                # =====================================
                # Retool y to energy scale
                # =====================================
                # x = thisrect[0]
                # y = thisrect[1]
                # width = thisrect[2]
                # height=thisrect[3]
    
                myrect = mt.qt.Rectangle(*thisrect)
                y0 = myrect.x0
                y1 = myrect.x1
                temp = np.flipud(e_axis)
                e_y0 = temp[np.int(np.round(y0))]
                e_y1 = temp[np.int(np.round(y1))]
                e_width = e_y1-e_y0
                
                #  rect = mt.qt.Rectangle(x, e_y0, e_width, height, axes=ax, alpha=1, fill=False)
                rect = mt.qt.Rectangle(e_y0, y, e_width, height, axes=ax, alpha=1, fill=False)
                ax.add_patch(rect.get_rect())
    
                mt.graphics.less_labels(ax, y_fraction=1)
                mt.graphics.axesfontsize(ax, fontsize)
    
                # =====================================
                # Plot Fit
                # =====================================
                figlabel = 'Butterfly Fit'
                ax       = fig.add_subplot(gs[j, 1])
                ax0      = bt.plotfit(
                    eaxis.dat[indx],
                    variance.dat[indx],
                    beta.dat[indx],
                    X_unweighted.dat[indx],
                    top        = 'Emittance and Beam Parameter Fit',
                    figlabel   = figlabel,
                    bottom     = 'Energy [GeV]',
                    axes       = ax,
                    error      = y_error.dat[indx],
                    linewidth  = linewidth,
                    fontsize   = fontsize,
                    markersize = 2
                    )
                
                mt.graphics.less_labels(ax0, y_fraction=1)
                mt.graphics.axesfontsize(ax0, fontsize)
    
                ax0.get_figure().tight_layout()
    
                # =====================================
                # Add numbers
                # =====================================
                ax  = fig.add_subplot(gs[j, 2])
    
                # Calculate pinch energy
                size         = np.dot(X_unweighted.dat[indx], beta.dat[indx])
                argmin       = np.argmin(size)
                pinch_energy = eaxis.dat[indx][argmin]
    
                if laseron[indx]:
                    laser_status = 'On'
                else:
                    laser_status = 'Off'
    
                table_begin = r'''
    \begin{{tabular}}{{ll}}
    \toprule
    Date & {} \\
    UID & {:0.0f} \\
    Quad Offset [GeV] & {:0.3f} \\
    \midrule Pinch Energy [GeV] & {:0.3f} \\
    Norm Emit [mm-mrad] &  {:0.3f} \\
    Beta* [m] &  {:0.3f} \\
    S* [m] & {:0.3f} \\
    Laser & {} \\
    \bottomrule
    \end{{tabular}}'''
                table_begin = table_begin.format(
                    date_string,
                    uid,
                    quadval.dat[indx],
                    pinch_energy,
                    emit_n.dat[indx]*1e6,
                    betastar.dat[indx],
                    sstar.dat[indx],
                    laser_status
                    )
                table_begin = re.sub('\\n', ' ', table_begin)
    
                #  table_begin = r'''\begin{tabular}{ c | c | c | c } & col1 & col2 & col3 \\\hline row1 & 11 & 12 & 13 \\\hline row2 & 21 & 22 & 23 \\\hline  row3 & 31 & 32 & 33 \end{tabular}'''
                ax.text(-0.1, 0.25, table_begin, fontsize=fontsize)
                ax.set_frame_on(False)
                ax.get_xaxis().set_visible(False)
                ax.get_yaxis().set_visible(False)
                ax.get_figure().tight_layout()
                
        gs.tight_layout(fig, rect=layout_rect)
        pdf.savefig(fig)
        plt.close()
    
    pdf.close()

    command = 'open {}'.format(filename)
    subprocess.call(shlex.split(command))
Esempio n. 5
0
f.close()

figpath = '/Users/joelfrederico/AAC2014'

valid_bool = pjar.valid

analysis_arr = pjar.fitresults[valid_bool]

num_results = analysis_arr.shape[0]
emit_n      = np.zeros(num_results)
emit        = np.zeros(num_results)
beta        = np.zeros(num_results)
alpha       = np.zeros(num_results)
betastar    = np.zeros(num_results)
sstar       = np.zeros(num_results)
result      = mt.linspacestep(1, num_results)
for i, arr in enumerate(analysis_arr):
    emit_n[i]   = arr.scanfit.fitresults.emitn
    emit[i]     = arr.scanfit.fitresults.emit
    beta[i]     = arr.scanfit.fitresults.twiss.beta
    alpha[i]    = arr.scanfit.fitresults.twiss.alpha
    betastar[i] = arr.scanfit.fitresults.twiss.betastar
    sstar[i]    = arr.scanfit.fitresults.twiss.sstar

linewidth = 2

# =====================================
# Plot Emittance
# =====================================
y = emit_n*1e6
Esempio n. 6
0
mt.graphics.less_labels(ax0, y_fraction=1)
mt.graphics.axesfontsize(ax0, fontsize)
ax0.get_figure().tight_layout()

mt.graphics.savefig(filename=figlabel, path=figpath)

# =====================================
# Plot Image
# =====================================
fig = plt.figure()
ax  = fig.add_subplot(1, 1, 1)
# xx = mt.linspaceborders(div*1e3)
# yy = mt.linspaceborders(energy)
yy = mt.linspaceborders(shot17.oimgeaxis)
xx = mt.linspaceborders(mt.linspacestep(1, shot17.oimg.shape[0]))
yy = yy[shot17.ystart:shot17.ystop]
xx = xx[shot17.xstart:shot17.xstop]*shot17.res*1e6/np.sqrt(2)
xx = xx-np.mean(xx)
vmax = 1600
p1   = ax.pcolormesh(xx, yy, shot17.img.transpose(), vmax=vmax, cmap=cm.RdBu_r)
# p1   = ax.contourf(xx, yy, shot17.img.transpose(), vmax=1500, cmap=cm.Blues)
cbar = fig.colorbar(p1)
p2   = ax.contour(xx, yy, shot17.img.transpose(), levels=np.linspace(0, vmax, 6), colors='Black', linewidths=linewidth)
ax.axhspan(ymin=yy[36*5], ymax=yy[37*5], color='Red', fill=False, linewidth=4)

ax.axis([xx.min(), xx.max(), yy.min(), yy.max()])

toplabel    = 'Ionization-Injected Witness Profile at Lanex'
windowlabel = 'Lanex'