Ejemplo n.º 1
0
def press_key(event):
    """
    Process key press events in the interactive plot

    :param event: button press event
    """
    global sumdata, max_colorbar, ax0, my_cmap, figure, rectangle, onselect, rectprops

    if event.key == "right":
        max_colorbar = max_colorbar + 1
    elif event.key == "left":
        max_colorbar = max_colorbar - 1
        max_colorbar = max(max_colorbar, 1)
    extents = rectangle.extents
    xmin0, xmax0 = ax0.get_xlim()
    ymin0, ymax0 = ax0.get_ylim()

    ax0.cla()
    ax0.imshow(
        np.log10(sumdata),
        vmin=0,
        vmax=max_colorbar,
        cmap=my_cmap,
        extent=[crop_roi[2], crop_roi[3], crop_roi[1], crop_roi[0]],
    )  # unbinned pixel coordinates
    # extent (left, right, bottom, top)
    ax0.set_title("detector plane (sum)")
    ax0.axis("scaled")
    ax0.set_xlim(xmin0, xmax0)
    ax0.set_ylim(ymin0, ymax0)
    plt.draw()
    rectangle = RectangleSelector(
        ax0,
        onselect,
        drawtype="box",
        useblit=False,
        button=[1],
        interactive=True,
        rectprops=rectprops,
    )  # don't use middle and right buttons
    rectangle.to_draw.set_visible(True)
    figure.canvas.draw()
    rectangle.extents = extents
Ejemplo n.º 2
0
if invert_yaxis:
    ax1.invert_yaxis()
ax0.axis("scaled")
ax1.axis("scaled")
ax0.set_title("sum of all images")
ax1.set_title("integrated intensity in the ROI")
motor_text = figure.text(0.40, 0.95, "", size=12)
plt.tight_layout()
plt.connect("key_press_event", press_key)
plt.connect("button_press_event", onclick)
rectangle = RectangleSelector(
    ax0,
    onselect,
    drawtype="box",
    useblit=False,
    button=[1],
    interactive=True,
    rectprops=rectprops,
)  # don't use middle and right buttons
rectangle.to_draw.set_visible(True)
figure.canvas.draw()
rectangle.extents = (
    sum_roi[2] * binning[1] + crop_roi[2],
    sum_roi[3] * binning[1] + crop_roi[2],
    sum_roi[0] * binning[0] + crop_roi[0],
    sum_roi[1] * binning[0] + crop_roi[0],
)
# in the unbinned full detector pixel coordinates, extents (xmin, xmax, ymin, ymax)
figure.set_facecolor(background_plot)
plt.show()
ax_colorbar = fig.add_axes([0.92, 0.25, 0.03, 0.5])
cb = mpl.colorbar.ColorbarBase(ax_colorbar, cmap=cm, orientation='vertical')

# The interactive box
RS = RectangleSelector(
    ax,
    line_select_callback,
    drawtype='box',
    useblit=False,
    button=[1],  # don't use middle button
    minspanx=5,
    minspany=5,
    spancoords='pixels',
    interactive=True,
    rectprops=dict(alpha=0.5, color='gray'))

ymaxvalues = means + errors
yminvalues = means - errors
xmin, xmax = ax.get_xbound()
ymin, ymax = np.min(yminvalues), np.max(ymaxvalues)

RS.to_draw.set_visible(True)
RS.extents = (xmin, xmax, ymin, ymax)

# Initial coloring
color_values = compare_bars_to_ranges(RS.extents, errors_max, errors_min)
color_bars_based_on_values(the_bars, color_values, palette)

plt.show()
Ejemplo n.º 4
0
def window_slide(image, put, ans_V):
    blackarr = np.zeros((104, 104), dtype=np.float32)

    stepSize = 104
    (w_width, w_height) = (104, 104)  # window size
    arrr = []
    #fig, ax = plt.subplots(4, 4)
    idxAX = 0
    ddict = {}
    NEWc = np.argwhere(ans_V > 0)
    #distances = np.sqrt((nonzero[:,0] - TARGET[0]) ** 2 + (nonzero[:,1] - TARGET[1]) ** 2)

    #print NEWc

    # CREATE 16 pad size = 104x104
    for ii, x in enumerate(range(0, image.shape[1], stepSize)):
        for iii, y in enumerate(range(0, image.shape[0], stepSize)):
            """
              if ans_V[ii, iii] == 1.0:# or ans_V[ii, iii] > ans_V[ii+1, iii+1]:
                   print ii, iii,'ANSWER', ans_V[ii, iii]
                   #Знаю координаты и знаю что в них ответ!!!
                   
              else:
                   pass
              """
            #for x in range(0, 4):
            #    for y in range(0, 4):
            idxAX += 1

            #print (x,x + w_width), (y, y + w_height)
            #window = image[x:x + w_width, y:y + w_height, :]
            #arrr.append(window)

            #
            #if ans_V[ii, iii] == 1:
            #print NEWc[idxAX-1]
            #        ax[ii, iii].imshow(blackarr)
            #        ax[ii, iii].set_gid(idxAX)
            #else:
            #        ax[ii, iii].imshow(window)
            #        ax[ii, iii].set_gid(idxAX)
            # FOR COORD's ...
            ddict[idxAX] = [(x, x + w_width), (y, y + w_height)]
    #print len(arrr)
    """
        new = fig.get_axes()
        # FROM RUCAPTCHA DATA
        for P in put:
              #print (int(P)-1)
              axexx = new[P-1]
              axexx.imshow(blackarr)
              #print  'SDSDSD', axexx.get_gid(), int(P)
        #fig.connect('button_press_event', onclick)
        """
    #plt.connect('button_press_event', onclick)
    #plt.show()
    #plt.close(fig)

    # NEW IMAGE AND COORD's rectangle
    #imgs(image)
    fig0, ax0 = plt.subplots()

    answ = T4_4.func_o(ans_V)
    #print answ

    dict_to = {}

    for u in answ.keys():
        if answ[u] != []:
            #print sorted(set(answ[u])) #answ[u]
            mi, mx = min(sorted(set(answ[u]))), max(sorted(set(answ[u])))
            #print mi, mx

            Mx = mx + 1  #max(put)
            Mi = mi + 1  #min(put)
            #c0 = ddict[Mi]#[0]
            #c00 = ddict[Mx]#[1]
            print "OUT", ddict[Mi], ddict[Mx], Mi, Mx

            c1 = ddict[Mi]  #[0]
            c2 = ddict[Mx]  #[1]
            if c1[0][0] == c2[0][1] or c1[1][0] == c2[1][1]:
                cc1, cc2 = min(c1), max(c2)
                x0 = not0(cc1[0])
                y0 = not0(cc1[1])
                x1 = not0(cc2[0])
                y1 = not0(cc2[1])

                print cc1[0], cc2[0]  #c1[0][0], c1[1][0], c2[0][1], c2[1][1]

            else:
                x0 = not0(c1[0][0])
                y0 = not0(c1[1][0])
                x1 = not0(c2[0][1])
                y1 = not0(c2[1][1])
                #if dict_to[u] is type(list()):
            #dict_to[u].append(list(x0,y0,x1,y1))
            #else:
            dict_to[u] = list([x0, y0, x1, y1])
            #   print u, x0,y0,x1,y1

            #Y
            image[x0:x1, y1 - 3:y1, :] = _COLOR  # первая !!
            image[x0:x1, y0 - 3:y0, :] = _COLOR
            #X
            image[x0 - 3:x0, y0:y1, :] = _COLOR  # первая !!
            image[x1 - 3:x1, y0:y1, :] = _COLOR

            #c1[0][1], c1[1][1], c2[0][1], c2[1][1]
    plt.imshow(image)
    RS = RectangleSelector(
        ax0,
        line_select_callback,
        drawtype='box',
        useblit=False,
        button=[1, 1],  # don't use middle button
        minspanx=5,
        minspany=5,
        spancoords='pixels',
        interactive=True)
    """
        RS1 = RectangleSelector(ax0, line_select_callback,
                                               drawtype='box', useblit=False,
                                               button=[1, 1],  # don't use middle button
                                               minspanx=5, minspany=5,
                                               spancoords='pixels',
                                               interactive=True)
        """

    RS.to_draw.set_visible(False)
    #RS1.to_draw.set_visible(True)

    RS.extents = (y0, y1, x0, x1)
    #RS1.extents = ((y0+20),(y1+20), x0-10,x1-10)

    fig0.canvas.draw()
    plt.show()
    #return arrr
    #print "@#@WE@#E@", dict_to#, image
    return dict_to, image
Ejemplo n.º 5
0
    0.70,
    0.70,
    "ROI max at line = "
    + "{:.0f}".format(
        data[index_peak, sum_roi[0] : sum_roi[1], sum_roi[2] : sum_roi[3]].max()
    ),
    size=10,
)
plt.tight_layout()
plt.connect("key_press_event", press_key)
plt.connect("button_press_event", onclick)
rectangle = RectangleSelector(
    ax0,
    onselect,
    drawtype="box",
    useblit=False,
    button=[1],
    interactive=True,
    rectprops=rectprops,
)  # don't use middle and right buttons
rectangle.to_draw.set_visible(True)
figure.canvas.draw()
rectangle.extents = (
    sum_roi[2],
    sum_roi[3],
    sum_roi[0],
    sum_roi[1],
)  # extents (xmin, xmax, ymin, ymax)
figure.set_facecolor(background_plot)
plt.show()
Ejemplo n.º 6
0
def window_slide(image, put, ans_V):
        blackarr = np.zeros((104, 104), dtype=np.float32)

        stepSize = 104
        (w_width, w_height) = (104, 104) # window size
        arrr = []
        idxAX = 0
        ddict = {}
        NEWc = np.argwhere(ans_V>0)

        # CREATE 16 pad size = 104x104
        for ii, x in enumerate(range(0, image.shape[1], stepSize)):
           for iii,y in enumerate(range(0, image.shape[0], stepSize)):
              idxAX += 1
              ddict[idxAX] = [(x,x + w_width), (y, y + w_height)]

        answ = T4_4.func_o(ans_V)


        dict_to = {}
 
        for u in answ.keys():
             if answ[u] != []:
                #print sorted(set(answ[u])) #answ[u]
                mi, mx = min(sorted(set(answ[u]))), max(sorted(set(answ[u])))
                #print mi, mx  

                Mx = mx+1 #max(put)
                Mi = mi+1 #min(put)
                #c0 = ddict[Mi]#[0]
                #c00 = ddict[Mx]#[1]
                print "OUT", ddict[Mi], ddict[Mx], Mi, Mx
                
                c1 = ddict[Mi]#[0]
                c2 = ddict[Mx]#[1]
                if c1[0][0] == c2[0][1] or c1[1][0] == c2[1][1]:
                      cc1, cc2 = min(c1), max(c2)
                      x0 = not0(cc1[0]) 
                      y0 = not0(cc1[1]) 
                      x1 = not0(cc2[0]) 
                      y1 = not0(cc2[1])
                      
                      print cc1[0], cc2[0]#c1[0][0], c1[1][0], c2[0][1], c2[1][1]
                      
                else:
                      x0 = not0(c1[0][0]) 
                      y0 = not0(c1[1][0]) 
                      x1 = not0(c2[0][1]) 
                      y1 = not0(c2[1][1])
                        #if dict_to[u] is type(list()): 
                #dict_to[u].append(list(x0,y0,x1,y1))
                #else:
                dict_to[u] = list([x0,y0,x1,y1])
                #   print u, x0,y0,x1,y1
                 
                #Y
                image[x0:x1, y1-3:y1, :] = _COLOR  # первая !!
                image[x0:x1, y0-3:y0, :] = _COLOR
                #X
                image[x0-3:x0, y0:y1, :] = _COLOR  # первая !!
                image[x1-3:x1, y0:y1, :] = _COLOR       
                
                #c1[0][1], c1[1][1], c2[0][1], c2[1][1]
        plt.imshow(image)
        RS = RectangleSelector(ax0, line_select_callback,
                                       drawtype='box', useblit=False,
                                       button=[1, 1],  # don't use middle button
                                       minspanx=5, minspany=5,
                                       spancoords='pixels',
                                       interactive=True)

        """
        RS1 = RectangleSelector(ax0, line_select_callback,
                                               drawtype='box', useblit=False,
                                               button=[1, 1],  # don't use middle button
                                               minspanx=5, minspany=5,
                                               spancoords='pixels',
                                               interactive=True)
        """

        RS.to_draw.set_visible(False)
        #RS1.to_draw.set_visible(True)
        
        RS.extents = (y0,y1, x0,x1)
        #RS1.extents = ((y0+20),(y1+20), x0-10,x1-10)

        fig0.canvas.draw()
        plt.show()
        #return arrr
        #print "@#@WE@#E@", dict_to#, image
        return dict_to, image