Example #1
0
def uti_data_file_plot(_fname, _read_labels=1, _e=0, _x=0, _y=0, _graphs_joined=1):
    # data, mode, allrange = srw_ascii_load(fname)
    data, mode, allrange, arLabels, arUnits = _file_load(_fname, _read_labels)
    # print(allrange)
    m = _enum("T", "V", "H", "E", "HV", "EV", "EH", "EHV")
    if mode == m.T:
        fig = __mode_T(data, allrange, arLabels, arUnits, _e, _x, _y)
    elif mode == m.V:
        fig = __mode_V(data, allrange)
    elif mode == m.H:
        fig = __mode_H(data, allrange)
    elif mode == m.E:
        fig = __mode_E(data, allrange, arLabels, arUnits)
    elif mode == m.HV:
        fig = __mode_HV(data, allrange, arLabels, arUnits, _x, _y, _graphs_joined)
    # elif mode==m.EV:
    #  fig = __mode_EV(data,allrange)
    # elif mode==m.EH:
    #  fig = __mode_EH(data,allrange)
    elif mode == m.EHV:
        fig = __mode_EHV(data, allrange, arLabels, arUnits, _e, _x, _y, _graphs_joined)
    return uti_plot_matplotlib_aux.maybe_savefig(fig)
Example #2
0
def uti_plot2d(ar2d, x_range, y_range, labels=("Horizontal position [m]", "Vertical position [m]")):
    # fig = _pl.figure(figsize=(12,8))
    fig = _pl.figure()
    _plot_2D(ar2d, x_range, y_range, labels, fig)
    return uti_plot_matplotlib_aux.maybe_savefig(fig)
Example #3
0
def __mode_EHV(data, allrange, _ar_labels, _ar_units, _ec, _xc, _yc, _graphs_joined=1):
    # allrange, units = _rescale_range(allrange)
    allrange, units = _rescale_range(allrange, _ar_units, _ec, _xc, _yc)
    # e0, e1, ne, x0, x1, nx, y0, y1, ny = allrange
    e0, e1, ne, x0, x1, nx, y0, y1, ny, ec, xc, yc = allrange

    # e = np.linspace(e0, e1, ne)
    # x = np.linspace(x0, x1, nx)
    # y = np.linspace(y0, y1, ny)
    # ie = np.where(data.sum(axis=1)==data.sum(axis=1).max())[0][0]
    # ix = np.where(abs(x)==abs(x).min())[0][0]
    # iy = np.where(abs(y)==abs(y).min())[0][0]

    range_e = e0, e1, ne
    range_x = x0, x1, nx
    range_y = y0, y1, ny

    ie = 0
    if ne > 1:
        if ec > e1:
            ie = ne - 1
        elif ec > e0:
            eStep = (e1 - e0) / (ne - 1)
            if eStep > 0:
                ie = int(round((ec - e0) / eStep))
    ix = 0
    if nx > 1:
        if xc > x1:
            ix = nx - 1
        elif xc > x0:
            xStep = (x1 - x0) / (nx - 1)
            if xStep > 0:
                ix = int(round((xc - x0) / xStep))
    iy = 0
    if ny > 1:
        if yc > y1:
            iy = ny - 1
        elif yc > y0:
            yStep = (y1 - y0) / (ny - 1)
            if yStep > 0:
                iy = int(round((yc - y0) / yStep))

    # label2D = ("Horizontal Position, ["+units[1]+"]", "Vertical Position, ["+units[2]+"]")
    label2D = (_ar_labels[1] + " [" + units[1] + "]", _ar_labels[2] + " [" + units[2] + "]")

    # label1E = ("Energy, ["+units[0]+"]","Ph/s/0.1%BW/mm^2")
    label1E = (_ar_labels[0] + " [" + units[0] + "]", _ar_labels[3] + " [" + units[3] + "]")

    # label1H = ("Horizontal Position, ["+units[1]+"]","Ph/s/0.1%BW/mm^2")
    label1H = (_ar_labels[1] + " [" + units[1] + "]", _ar_labels[3] + " [" + units[3] + "]")

    # label1V = ("Vertical Position, ["+units[2]+"]","Ph/s/0.1%BW/mm^2")
    label1V = (_ar_labels[2] + " [" + units[2] + "]", _ar_labels[3] + " [" + units[3] + "]")

    arCutXY = array("d", [0] * nx * ny)
    perY = ne * nx
    i = 0
    for iiy in range(ny):
        perY_iiy = perY * iiy
        for iix in range(nx):
            arCutXY[i] = data[ie + ne * iix + perY_iiy]
            i += 1

    arCutE = array("d", [0] * ne)
    perX_ix = ne * ix
    perY_iy = perY * iy
    for iie in range(ne):
        arCutE[iie] = data[iie + perX_ix + perY_iy]

    arCutX = array("d", [0] * nx)
    for iix in range(nx):
        arCutX[iix] = data[ie + ne * iix + perY_iy]

    arCutY = array("d", [0] * ny)
    for iiy in range(ny):
        arCutY[iiy] = data[ie + perX_ix + perY * iiy]

    # fig = _pl.figure(figsize=(8,8))
    # _plot_2D(data[:,:,ie], range_x, range_y, label2D, fig, 221)
    # _plot_1D(data[ix,iy,:],range_e,label1E,fig,224)
    # _plot_1D(data[ie,:,iy],range_x,label1H,fig,222)
    # _plot_1D(data[:,ix,ie],range_y,label1V,fig,223)

    fig = None
    if _graphs_joined:
        fig = _pl.figure(figsize=(12, 5))
        _plot_2D(arCutXY, range_x, range_y, label2D, fig, 221)  # showing graphs in one figure
        _plot_1D(arCutE, range_e, label1E, fig, 222)
        _plot_1D(arCutX, range_x, label1X, fig, 223)
        _plot_1D(arCutY, range_y, label1Y, fig, 224)
    else:
        uti_plot2d(arCutXY, range_x, range_y, label2D)
        uti_plot1d(arCutE, range_e, label1E)
        uti_plot1d(arCutX, range_x, label1X)
        uti_plot1d(arCutY, range_y, label1Y)
    return uti_plot_matplotlib_aux.maybe_savefig(fig)
Example #4
0
def uti_plot1d(ar1d, x_range, labels=("energy [eV]", "ph/s/0.1%bw")):
    # fig = _pl.figure(figsize=(12,8))
    fig = _pl.figure()
    _plot_1D(ar1d, x_range, labels, fig)
    return uti_plot_matplotlib_aux.maybe_savefig(fig)