Ejemplo n.º 1
0
        def imagegallery(event):
            global file
            values = e.get().split(" ")
            x0 = int(values[0])
            y0 = int(values[1])
            x1 = int(values[2])
            y1 = int(values[3])
            x = 0
            y = 0
            indexx = x1

            for x in range(x1 - x0 + 1):
                indexy = y1
                for y in range(y1 - y0 + 1):
                    s = PixelatedSTEM(
                        hs.signals.Signal2D(file.inav[indexy, indexx]))
                    st = s.template_match_disk(disk_r=6,
                                               lazy_result=True,
                                               show_progressbar=False)
                    peak_array = st.find_peaks(lazy_result=False,
                                               show_progressbar=False)
                    s.add_peak_array_as_markers(peak_array)
                    #plt.plot(s)
                    s.plot()
                    ax = s._plot.signal_plot.ax
                    ax.set_xlabel("pixel(" + str(indexx) + "_" + str(indexy) +
                                  ")")
                    #plt.title("pixel(" + str(indexx) + "_" + str(indexy) + ")")
                    #plt.show()
                    indexy -= 1
                    y += 1
                indexx -= 1
                x += 1
            plt.show()
            """
 def mousecoords(event):
     global methodOfAnalysis
     s = PixelatedSTEM(file.inav[0, 0])
     length = len(array(s))
     pointxy = (-1, -1)
     while pointxy is (-1, -1):
         pointxy = (int(event.x * length / 400), int(event.y * length / 400)
                    )  # get the mouse position from event
     l['text'] = l['text'] + str(pointxy[0]) + " " + str(pointxy[1]) + "\n"
     r.update()
     c2.unbind('<Button-1>')
     c2.bind('<Button-1>', lambda event: mousecoords1(event, pointxy))
Ejemplo n.º 3
0
def multiprocessing_func(values):
    global distances
    s = PixelatedSTEM(file.inav[values[0], values[1]])
    imarray = array(s)
    s = s.rotate_diffraction(0, show_progressbar=False)
    ############################################################################################################################
    st = s.template_match_disk(disk_r=5,
                               lazy_result=False,
                               show_progressbar=False)
    peak_array = st.find_peaks(lazy_result=False, show_progressbar=False)
    peak_array_com = s.peak_position_refinement_com(peak_array,
                                                    lazy_result=False,
                                                    show_progressbar=False)
    s_rem = s.subtract_diffraction_background(lazy_result=False,
                                              show_progressbar=False)
    peak_array_rem_com = s_rem.peak_position_refinement_com(
        peak_array_com, lazy_result=False, show_progressbar=False)
    ############################################################################################################################
    center = findCenter(imarray, peak_array_rem_com)

    # finds the specific spot and adding that distance to the array
    posDistance = 0
    closestPoint = center

    for (x, y) in ndenumerate(peak_array_rem_com):
        minimum = 999999
        for (a, b) in y:
            dis = distance(values[2], values[3], b, a)
            if dis < minimum:
                minimum = dis
                closestPoint = (b, a)
    posDistance = distance(closestPoint[0], closestPoint[1], center[0],
                           center[1])
    distances[values[1]][values[0]] = round(posDistance, 2)
 def Mousecoords(event):
     global methodOfAnalysis
     s = PixelatedSTEM(file.inav[100, 100])
     length = len(array(s))
     pointxy = (int(event.x * length / 400), int(event.y * length / 400)
                )  # get the mouse position from event
     l['text'] = l['text'] + str(pointxy[0]) + " " + str(
         pointxy[1]) + "\n"
     l['text'] = l['text'] + "Starting analysis...\n"
     r.update()
     analysis(pointxy, values, methodOfAnalysis)
     remove("temp.png")
     c2.unbind('<Button-1>')
     r.destroy()
     label1['text'] = label1['text'] + "Analysis complete.\n"
Ejemplo n.º 5
0
def multiprocessing_func(values):
    global singleValues, distances
    s = PixelatedSTEM(file.inav[values[0], values[1]])
    imarray = array(s)

    sigma_est = mean(estimate_sigma(imarray, ))
    # patch_size for 580 - 1, patch_size for 144 = 3
    #nlm = denoise_nl_means(imarray, h=1.15 * sigma_est, fast_mode=True, patch_size=3, patch_distance=6, )
    gaussian = gaussian_filter(imarray, 1.15 * sigma_est)
    #wien = wiener(imarray, 5, 3)

    original = gaussian  # Change this to whatever filter you want to use
    s = PixelatedSTEM(original)

    ############################################################################################################################
    st = s.template_match_ring(r_inner=1,
                               r_outer=6,
                               lazy_result=True,
                               show_progressbar=False)
    peak_array = st.find_peaks(lazy_result=False, show_progressbar=False)
    peak_array_com = s.peak_position_refinement_com(peak_array,
                                                    lazy_result=False,
                                                    show_progressbar=False)
    s_rem = s.subtract_diffraction_background(lazy_result=False,
                                              show_progressbar=False)
    peak_array_rem_com = s_rem.peak_position_refinement_com(
        peak_array_com, lazy_result=False, show_progressbar=False)
    ############################################################################################################################
    center = findCenter(imarray, peak_array_rem_com)

    # finds the specific spot and adding that distance to the array
    posDistance = 0
    closestPoint = center
    idx = 0
    for (x, y) in ndenumerate(peak_array_rem_com):
        minimum = 999999
        for (a, b) in y:
            if (2 < b < 142 and 2 < a < 142):
                di = distance(center[0], center[1], b, a)
                distances[values[1]][values[0]][idx] = round(di, 3)
                idx += 1
            dis = distance(values[2], values[3], b, a)
            if dis < minimum:
                minimum = dis
                closestPoint = (b, a)
    posDistance = distance(closestPoint[0], closestPoint[1], center[0],
                           center[1])
    singleValues[values[1]][values[0]] = round(posDistance, 2)
 def mousecoords1(event, pointxy):
     global methodOfAnalysis
     pointxy1 = None
     s = PixelatedSTEM(file.inav[0, 0])
     length = len(array(s))
     while pointxy1 is None:
         pointxy1 = (int(event.x * length / 400),
                     int(event.y * length / 400)
                     )  # get the mouse position from event
         print("pointxy1", pointxy1, "\n", "pointxy", pointxy)
     l['text'] = l['text'] + str(pointxy1[0]) + " " + str(
         pointxy1[1]) + "\n"
     l['text'] = l['text'] + "Starting analysis...\n"
     analysis(pointxy, pointxy1, values, methodOfAnalysis)
     r.update()
     remove("temp.png")
     c2.unbind('<Button-1>')
     r.destroy()
     label1['text'] = label1['text'] + "Analysis complete.\n"
Ejemplo n.º 7
0
        def imagegallery(event):
            global file
            values = e.get().split(" ")
            x0 = int(values[0])
            y0 = int(values[1])
            x1 = int(values[2])
            y1 = int(values[3])
            x = 0
            y = 0
            indexx = x1

            for x in range(x1 - x0 + 1):
                indexy = y1
                for y in range(y1 - y0 + 1):
                    s = PixelatedSTEM(
                        hs.signals.Signal2D(file.inav[indexx, indexy]))
                    st = s.template_match_ring(r_inner=1,
                                               r_outer=6,
                                               lazy_result=True,
                                               show_progressbar=False)
                    peak_array = st.find_peaks(method='dog',
                                               min_sigma=0.8,
                                               max_sigma=15,
                                               sigma_ratio=1.9,
                                               threshold=0.42,
                                               overlap=0.5,
                                               lazy_result=False,
                                               show_progressbar=True)
                    s.add_peak_array_as_markers(peak_array)
                    #plt.plot(s)
                    s.plot()
                    ax = s._plot.signal_plot.ax
                    ax.set_xlabel("pixel(" + str(indexx) + "_" + str(indexy) +
                                  ")")
                    #plt.title("pixel(" + str(indexx) + "_" + str(indexy) + ")")
                    #plt.show()
                    indexy -= 1
                    y += 1
                indexx -= 1
                x += 1
            plt.show()
            """
def intensity(values):
    s = PixelatedSTEM(file.inav[values[0], values[1]])
    imarray = array(s)
    singleValues[values[1]][values[0]] = imarray[values[3]][values[2]]
def startAnalysis(values=None):
    global file, currFunc
    methodOfAnalysis = ""

    def assignMethod(method):
        global methodOfAnalysis
        methodOfAnalysis = method

    def mousecoords(event):
        global methodOfAnalysis
        s = PixelatedSTEM(file.inav[0, 0])
        length = len(array(s))
        pointxy = (-1, -1)
        while pointxy is (-1, -1):
            pointxy = (int(event.x * length / 400), int(event.y * length / 400)
                       )  # get the mouse position from event
        l['text'] = l['text'] + str(pointxy[0]) + " " + str(pointxy[1]) + "\n"
        r.update()
        c2.unbind('<Button-1>')
        c2.bind('<Button-1>', lambda event: mousecoords1(event, pointxy))

    def mousecoords1(event, pointxy):
        global methodOfAnalysis
        pointxy1 = None
        s = PixelatedSTEM(file.inav[0, 0])
        length = len(array(s))
        while pointxy1 is None:
            pointxy1 = (int(event.x * length / 400),
                        int(event.y * length / 400)
                        )  # get the mouse position from event
            print("pointxy1", pointxy1, "\n", "pointxy", pointxy)
        l['text'] = l['text'] + str(pointxy1[0]) + " " + str(
            pointxy1[1]) + "\n"
        l['text'] = l['text'] + "Starting analysis...\n"
        analysis(pointxy, pointxy1, values, methodOfAnalysis)
        r.update()
        remove("temp.png")
        c2.unbind('<Button-1>')
        r.destroy()
        label1['text'] = label1['text'] + "Analysis complete.\n"

    s = PixelatedSTEM(file.inav[0, 0])
    s.save("temp.png")
    img = Image.open("temp.png")
    img = img.resize((400, 400), Image.ANTIALIAS)
    img.save('temp.png')

    r = tk.Toplevel(root)

    c = tk.Canvas(r, height=720, width=1080)
    c.pack()
    f = tk.Frame(r, bg='#333333')
    f.place(relwidth=1, relheight=1)
    l = tk.Message(f,
                   bg='#999999',
                   font=('Calibri', 15),
                   anchor='nw',
                   justify='left',
                   highlightthickness=0,
                   bd=0,
                   width=1000)
    l.place(relx=0.05, rely=0.7, relwidth=0.9, relheight=0.2)
    b1 = tk.Button(f,
                   text='Intensity Mapping',
                   bg='#620000',
                   font=('Calibri', 15),
                   highlightthickness=0,
                   bd=0,
                   activebackground='#800000',
                   activeforeground='#ffffff',
                   command=lambda: assignMethod("intensity"),
                   pady=0.02,
                   fg='#ffffff')
    b1.place(relx=0.2, rely=0.6, relwidth=0.2, relheight=0.05)
    b2 = tk.Button(f,
                   text='Strain Mapping',
                   bg='#620000',
                   font=('Calibri', 15),
                   highlightthickness=0,
                   bd=0,
                   activebackground='#800000',
                   activeforeground='#ffffff',
                   command=lambda: assignMethod("strain"),
                   pady=0.02,
                   fg='#ffffff')
    b2.place(relx=0.6, rely=0.6, relwidth=0.2, relheight=0.05)
    c2 = tk.Canvas(r, width=400, height=400)
    c2.place(relx=0.3)
    img = ImageTk.PhotoImage(Image.open("temp.png"))
    c2.create_image(0, 0, anchor='nw', image=img)
    c2.bind('<Button-1>', mousecoords)
    l['text'] = l[
        'text'] + "Please click on the method of analysis and then the point you would like to analyze from the diffraction pattern above.\n"
    r.mainloop()
    if path.exists("temp.png"):
        remove("temp.png")
Ejemplo n.º 10
0
def multiprocessing_func(values):
    global singleValues, distances
    s = PixelatedSTEM(file.inav[values[0], values[1]])

    original = array(s)
    ############################################################################################################################
    # # FILTERS

    # sigma_est = mean(estimate_sigma(original, ))
    # # patch_size for 580 - 1, patch_size for 144 = 3
    # nlm = denoise_nl_means(original, h=1.15*sigma_est, fast_mode=True, patch_size=3, patch_distance=6, )
    # gaussian = gaussian_filter(original, 1.15*sigma_est)
    # wien = wiener(original, 5, 3)

    # s = PixelatedSTEM(gaussian) # Change this to whatever filter you want to use
    ############################################################################################################################
    # # PIXSTEM

    # s = s.rotate_diffraction(0,show_progressbar=False)
    # st = s.template_match_disk(disk_r=5, lazy_result=False, show_progressbar=False)
    # peak_array = st.find_peaks(lazy_result=False, show_progressbar=False)
    # peak_array_com = s.peak_position_refinement_com(peak_array, lazy_result=False, show_progressbar=False)
    # s_rem = s.subtract_diffraction_background(lazy_result=False, show_progressbar=False)
    # peak_array_rem_com = s_rem.peak_position_refinement_com(peak_array_com, lazy_result=False, show_progressbar=False)
    ############################################################################################################################
    # MY METHOD

    # defines template and templates matches
    # spot for 580 - [265:320, 265:320]
    # spot for 144 - [65:80, 65:80]
    template = original[65:80, 65:80]
    result = match_template(original, template, pad_input=True)
    # only takes points greater than the threshold r-value
    tempList = []
    for i in range(len(result)):
        for j in range(len(result[i])):
            if (result[i][j] > 0.87):  # change correlation value
                tempList.append((i, j))
    # removes duplicate spots that are too close to each other
    i = 0
    l = []
    while i < len(tempList):
        j = 0
        temp = []
        point = tempList[i]
        while j < len(tempList):
            if distance(point[0], point[1], tempList[j][0],
                        tempList[j][1]) < 15:  # change minimum center distance
                temp.append(tempList[j])
                tempList.pop(j)
            else:
                j = j + 1
        max = 0
        pnt = temp[0]
        for j in range(len(temp)):
            if (result[pnt[0]][pnt[1]] < result[temp[j][0]][temp[j][1]]):
                max = result[temp[j][0]][temp[j][1]]
                pnt = temp[j]
        l.append(pnt)
    peak_array_rem_com = [[], l]
    ############################################################################################################################

    closestPoint = None
    closestPoint1 = None
    length = len(original)
    for (x, y) in ndenumerate(peak_array_rem_com):
        minimum = 999999
        minimum1 = 999999
        for (a, b) in y:
            dis = distance(values[2], values[3], b, a)
            dis1 = distance(values[4], values[5], b, a)
            if dis < minimum and dis < length / 10:
                minimum = dis
                closestPoint = (b, a)
            if dis1 < minimum1 and dis1 < length / 10:
                minimum1 = dis1
                closestPoint1 = (b, a)
    print(closestPoint, closestPoint1, values[4], values[5])
    posDistance = distance(closestPoint[0], closestPoint[1], closestPoint1[0],
                           closestPoint1[1])
    singleValues[values[1]][values[0]] = round(posDistance, 2)