示例#1
0
def get_qr_intensity( qr, data,vert_rect,mask=None, show_roi=True ):
    
    V_K_label_array = roi.rectangles(vert_rect, data.shape)  #(y,x, hight, wdith)
    if mask is not None:V_K_label_array =V_K_label_array * mask
    if show_roi:
        data_ = data*V_K_label_array 
        fig, ax = plt.subplots()
        im = plt.imshow(data_,origin='lower',norm= LogNorm( vmin=.1, vmax=1e0 ) )
        fig.colorbar(im)
        plt.show()    
        
    fig, ax = plt.subplots()
    for i, vr in enumerate( vert_rect):
        print (i, vr)
        V_K_label_array_i = roi.rectangles((vr,), data.shape)  #(y,x, hight, wdith)  
        if mask is not None:V_K_label_array_i =V_K_label_array_i * mask
        roi_pixel_num = np.sum( V_K_label_array_i, axis=0)
        qr_ = qr  *V_K_label_array_i
        data_ = data*V_K_label_array_i  
    
        qr_ave = np.sum( qr_, axis=0)/roi_pixel_num
        data_ave = np.sum( data_, axis=0)/roi_pixel_num  
 
        ax.plot( qr_ave, data_ave,  '--o', label= 'interest_roi_%i'%i)
    ax.set_xlabel( r'$q_r$', fontsize=15)
    ax.set_yscale('log')
    ax.set_xscale('log')
    ax.legend() 
示例#2
0
def test_rectangles():
    shape = (15, 26)
    roi_data = np.array(([2, 2, 6, 3], [6, 7, 8, 5], [8, 18, 5, 10]),
                        dtype=np.int64)

    all_roi_inds = roi.rectangles(roi_data, shape)

    roi_inds, pixel_list = corr.extract_label_indices(all_roi_inds)

    ty = np.zeros(shape).ravel()
    ty[pixel_list] = roi_inds
    num_pixels_m = (np.bincount(ty.astype(int)))[1:]

    re_mesh = ty.reshape(*shape)
    for i, (col_coor, row_coor, col_val, row_val) in enumerate(roi_data, 0):
        ind_co = np.column_stack(np.where(re_mesh == i + 1))

        left, right = np.max([col_coor, 0]), np.min([col_coor + col_val,
                                                     shape[0]])
        top, bottom = np.max([row_coor, 0]), np.min([row_coor + row_val,
                                                     shape[1]])
        assert_almost_equal(left, ind_co[0][0])
        assert_almost_equal(right-1, ind_co[-1][0])
        assert_almost_equal(top, ind_co[0][1])
        assert_almost_equal(bottom-1, ind_co[-1][-1])
def test_correlation():
    num_levels = 4
    num_bufs = 8  # must be even
    num_qs = 2  # number of interested roi's (rings)
    img_dim = (50, 50)  # detector size

    roi_data = np.array(([10, 20, 12, 14], [40, 10, 9, 10]), dtype=np.int64)

    indices = roi.rectangles(roi_data, img_dim)

    img_stack = np.random.randint(1, 5, size=(500,) + img_dim)

    g2, lag_steps = corr.multi_tau_auto_corr(num_levels, num_bufs, indices, img_stack)

    assert_array_almost_equal(
        lag_steps, np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56])
    )

    assert_array_almost_equal(g2[1:, 0], 1.00, decimal=2)
    assert_array_almost_equal(g2[1:, 1], 1.00, decimal=2)
示例#4
0
def get_qr_intensity_series( qr, data,vert_rect, mask=None,show_roi=True ):
    
    V_K_label_array = roi.rectangles(vert_rect, data.shape)  #(y,x, hight, wdith)
    if mask is not None:V_K_label_array =V_K_label_array * mask
    qr_ = qr  *V_K_label_array
    data_ = data*V_K_label_array 
    if False:
        fig, ax = plt.subplots()
        im = plt.imshow(data_,origin='lower',norm= LogNorm( vmin=.1, vmax=1e0 ) )
        fig.colorbar(im)
        plt.show()
    
    data_ave = np.average( data_, axis=0)
    qr_ave = np.average( qr_, axis=0)
    
    if show_roi:
        fig, ax = plt.subplots()
        im = plt.imshow(data_,origin='lower',norm= LogNorm( vmin=.1, vmax=1e0 ) )
        fig.colorbar(im)
        plt.show()
示例#5
0
def test_static_test_sets():
    img_stack1 = np.random.randint(0, 60, size=(50, ) + (50, 50))

    label_array = np.zeros((25, 25))

    # different shapes for the images and labels
    assert_raises(ValueError,
                  lambda: roi.mean_intensity(img_stack1, label_array))
    images1 = []
    for i in range(10):
        int_array = np.tril(i*np.ones(50))
        int_array[int_array == 0] = i*100
        images1.append(int_array)

    images2 = []
    for i in range(20):
        int_array = np.triu(i*np.ones(50))
        int_array[int_array == 0] = i*100
        images2.append(int_array)

    samples = np.array((np.asarray(images1), np.asarray(images2)))

    roi_data = np.array(([2, 30, 12, 15], [40, 20, 15, 10]), dtype=np.int64)

    label_array = roi.rectangles(roi_data, shape=(50, 50))

    # test mean_intensity function
    average_intensity, index = roi.mean_intensity(np.asarray(images1),
                                                  label_array)
    # test mean_intensity_sets function
    average_int_sets, index_list = roi.mean_intensity_sets(samples,
                                                           label_array)

    assert_array_equal((list(average_int_sets)[0][:, 0]),
                       [float(x) for x in range(0, 1000, 100)])
    assert_array_equal((list(average_int_sets)[1][:, 0]),
                       [float(x) for x in range(0, 20, 1)])

    assert_array_equal((list(average_int_sets)[0][:, 1]),
                       [float(x) for x in range(0, 10, 1)])
    assert_array_equal((list(average_int_sets)[1][:, 1]),
                       [float(x) for x in range(0, 2000, 100)])

    # test combine_mean_intensity function
    combine_mean_int = roi.combine_mean_intensity(average_int_sets,
                                                  index_list)

    roi_data2 = np.array(([2, 30, 12, 15], [40, 20, 15, 10],
                          [20, 2, 4, 5]), dtype=np.int64)

    label_array2 = roi.rectangles(roi_data2, shape=(50, 50))

    average_int2, index2 = roi.mean_intensity(np.asarray(images1),
                                              label_array2)
    index_list2 = [index_list, index2]

    average_int_sets.append(average_int2)

    # raise ValueError when there is different labels in different image sets
    #  when trying to combine the values
    assert_raises(ValueError,
                  lambda: roi.combine_mean_intensity(average_int_sets,
                                                     index_list2))