def plot_histogram(hist, zmin=None, zmax=None):
    ba.plot_histogram(hist,
                      xlabel=r'$\varphi_f ^{\circ}$',
                      ylabel=r'$\alpha_f ^{\circ}$',
                      zlabel="",
                      zmin=zmin,
                      zmax=zmax)
def plot(result):
    """
    Runs different plotting functions one by one
    to demonstrate trivial data presentation tasks.
    """

    fig = plt.figure(figsize=(12.80, 10.24))

    plt.subplot(2, 2, 1)
    ba.plot_histogram(result)
    plt.title("Intensity as colormap")

    plt.subplot(2, 2, 2)
    plot_cropped_map(result)
    plt.title("Cropping")

    plt.subplot(2, 2, 3)
    plot_relative_difference(result)
    plt.title("Relative difference")

    plt.subplot(2, 2, 4)
    plot_slices(result)
    plt.title("Various slicing of 2D into 1D")

    save_to_file(result)

    plt.subplots_adjust(left=0.07,
                        right=0.97,
                        top=0.9,
                        bottom=0.1,
                        hspace=0.25)
    plt.show()
def plot_relative_difference(hist):
    """
    Creates noisy histogram made of original histogram,
    then creates and plots a relative difference histogram: (noisy-hist)/hist
    """
    noisy = get_noisy_image(hist)
    diff = noisy.relativeDifferenceHistogram(hist)
    ba.plot_histogram(diff, zmin=1e-03, zmax=10)
 def plot_real_data(data):
     """
     Plot experimental data as colormap with horizontal/vertical lines
     representing slices on top.
     """
     plt.subplots_adjust(wspace=0.2, hspace=0.2)
     ba.plot_histogram(data, title="Experimental data")
     # line representing vertical slice
     plt.plot([phi_slice_value, phi_slice_value],
              [data.getYmin(), data.getYmax()],
              color='gray', linestyle='-', linewidth=1)
     # line representing horizontal slice
     plt.plot([data.getXmin(), data.getXmax()],
              [alpha_slice_value, alpha_slice_value],
              color='gray', linestyle='-', linewidth=1)
Exemplo n.º 5
0
def plot_peaks(hist):
    peaks = ba.FindPeaks(hist, 3, "nomarkov", 1e-03)
    xpeaks = [peak[0] for peak in peaks]
    ypeaks = [peak[1] for peak in peaks]
    print(peaks)
    # print("xpeaks:", xpeaks)
    # print("ypeaks:", ypeaks)
    print("xpeaks=[", ', '.join('{:4.2f}'.format(k) for k in xpeaks), "]")
    print("ypeaks=[", ', '.join('{:4.2f}'.format(k) for k in ypeaks), "]")
    ba.plot_histogram(hist, cmap="jet", zmin=1e+02, zmax=1e+07)
    plt.plot(xpeaks,
             ypeaks,
             linestyle='None',
             marker='x',
             color='white',
             markersize=10)
 def plot_real_data(self, data, nplot):
     plt.subplot(2, 2, nplot)
     plt.subplots_adjust(wspace=0.2, hspace=0.2)
     ba.plot_histogram(data, title="Experimental data")
     # line representing vertical slice
     plt.plot([phi_slice_value, phi_slice_value],
              [data.getYmin(), data.getYmax()],
              color='gray',
              linestyle='-',
              linewidth=1)
     # line representing horizontal slice
     plt.plot([data.getXmin(), data.getXmax()],
              [alpha_slice_value, alpha_slice_value],
              color='gray',
              linestyle='-',
              linewidth=1)
Exemplo n.º 7
0
def convert(filename):
    img = fabio.open(filename)
    print(img.header)

    data = img.data.astype("float64")

    nx, ny = 1024, 1024
    hist = ba.Histogram2D(nx, 0.0, nx * PIX_SIZE * 1000., ny, 0.0,
                          ny * PIX_SIZE * 1000.)
    hist.setContent(data)

    plt.figure()
    plt.imshow(img.data, norm=colors.LogNorm(100, 1e+07))

    plt.figure()
    ba.plot_histogram(hist)
    #hist.save("004_230_P144_im_full.int.gz")

    plt.show()
Exemplo n.º 8
0
def test_plot_utils():
    simulation = SimulationBuilder().build_simulation()
    # simulation.runSimulation()
    result = simulation.result()

    fig = plt.figure(figsize=(12.80, 10.24))
    plt.subplot(2, 2, 1)

    arr = np.zeros((5, 3))
    ba.plot_array(arr)

    plt.subplot(2, 2, 2)
    arr = np.array([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15]])
    ba.plot_array(arr)

    plt.subplot(2, 2, 3)
    ba.plot_colormap(result)

    plt.subplot(2, 2, 4)
    ba.plot_histogram(result.histogram2d())

    fig.tight_layout()
Exemplo n.º 9
0
def run_simulation():
    sample = get_sample()
    simulation = get_simulation()
    simulation.setSample(sample)
    simulation.runSimulation()

    h2 = simulation.result().histogram2d()
    for i in range(0, h2.getTotalNumberOfBins()):
        cont = h2.getBinContent(i)
        x = h2.getXaxisIndex(i)
        y = h2.getYaxisIndex(i)
        # if (x>=600 and x<=603 and y>=493 and y<=495):
        #     pass
        if (x>=593 and x <=606 and y>=0 and y<=617):
            cont = cont*0.01
        if cont == 0.0:
            cont = 1e-03
        h2.setBinContent(i, cont)

    ba.plot_histogram(h2)
    np.savetxt("experimental_data.txt", h2.array())
    plt.show()

    return simulation.result()
Exemplo n.º 10
0
    simulation.getOptions().setMonteCarloIntegration(True, 100)
    return simulation


def run_simulation():
    """
    Runs simulation and returns intensity map.
    """
    simulation = get_simulation()
    simulation.setSample(get_sample())
    simulation.setTerminalProgressMonitor()
    simulation.runSimulation()
    return simulation.result()


if __name__ == '__main__':
    result = run_simulation().histogram2d()
    ba.plot_histogram(result, cmap='jet', aspect='auto')

    peaks = ba.FindPeaks(result, 2, "nomarkov", 0.001)
    xpeaks = [peak[0] for peak in peaks]
    ypeaks = [peak[1] for peak in peaks]
    print(peaks)
    plt.plot(xpeaks,
             ypeaks,
             linestyle='None',
             marker='x',
             color='white',
             markersize=10)
    plt.show()
Exemplo n.º 11
0
                                     200, 0.0*deg, 0.6*deg)
    simulation.setBeamParameters(1.34*angstrom, 0.4*deg, 0.0*deg)
    simulation.setBeamIntensity(1e+08)
    simulation.getOptions().setMonteCarloIntegration(True, 100)
    return simulation


def run_simulation():
    """
    Runs simulation and returns intensity map.
    """
    simulation = get_simulation()
    simulation.setSample(get_sample())
    simulation.setTerminalProgressMonitor()
    simulation.runSimulation()
    return simulation.result()


if __name__ == '__main__':
    result = run_simulation().histogram2d()
    ba.plot_histogram(result)

    peaks = ba.FindPeaks(result, 2, "nomarkov", 0.001)
    xpeaks = [peak[0] for peak in peaks]
    ypeaks = [peak[1] for peak in peaks]
    print(peaks)
    plt.plot(xpeaks, ypeaks, linestyle='None', marker='x', color='white',
             markersize=10)
    plt.show()

def plot_histogram(hist, zmin=None, zmax=None):
    ba.plot_histogram(hist, xlabel=r'$\varphi_f ^{\circ}$',
                      ylabel=r'$\alpha_f ^{\circ}$',
                      zlabel="", zmin=zmin, zmax=zmax,
                      cmap='jet', aspect='auto')
def plot_cropped_map(hist):
    """
    Plot cropped version of intensity data
    """
    crop = hist.crop(-1.0 * deg, 0.5 * deg, 1.0 * deg, 1.0 * deg)
    ba.plot_histogram(crop)