예제 #1
0
def test(file_name, threshold):
    #读取测试文件地址
    path = r'C:\Users\Tyler\Documents\Tencent Files\383746778\FileRecv\new_version\10-binary_file'
    #读取统计结果各小时矩阵
    label_path = r'C:\Users\Tyler\Documents\Tencent Files\383746778\FileRecv\new_version\result'
    f = open(os.path.join(path, file_name),'r')
    s = f.read()
    paraDict,matrix = cleanUpPic.resolveRadar(s)
    xsize = paraDict['xsize']
    ysize = paraDict['ysize']
    img_origin = np.reshape(matrix, (ysize, xsize))
    hour =  file_name[-4:-2]
    
    
    label_data = np.loadtxt(os.path.join(label_path,'final_matrix_'+hour))
    img_bool = np.zeros((ysize, xsize))
    for i in xrange(ysize):
        for j in xrange(xsize):
            dzb = img_origin[i][j]
            if dzb!=-1:
                label_test_data = np.reshape(label_data[dzb], (421,561))
                if float(label_test_data[i][j]) < threshold:
                    img_bool[i][j] = 1
    
    final_image = img_origin * img_bool
    plt.subplot(2,1,1)
    plt.imshow(img_origin)
    plt.subplot(2,1,2)
    plt.imshow(final_image)
    plt.show()
예제 #2
0
def statistics_history_distribution():
    #读取历史数据的地址
    path = r'C:\Users\Tyler\Documents\Tencent Files\383746778\FileRecv\new_version\10-binary_file\test'
    #保存结果的地址
    save_path = r'C:\Users\Tyler\Documents\Tencent Files\383746778\FileRecv\new_version\result'
    y_size = 421
    x_size = 561
    total_matrix = np.zeros((24,16,421,561), dtype= np.int)
        
    #各小时数据和统计
    count = np.zeros(24)
    file_list=os.listdir(path)
    for file_item in file_list:
        f = open(os.path.join(path, file_item),'r')
        s = f.read()
        paraDict,matrix = cleanUpPic.resolveRadar(s)
        xsize = paraDict['xsize']
        ysize = paraDict['ysize']
        img_origin = np.reshape(matrix, (ysize, xsize))
        hour =  int(file_item[-4:-2])
        count[hour] +=1
        for i in xrange(16):
            total_matrix[hour][i] += (img_origin ==i)*1 
    
    #每个小时的矩阵转成2维发送
    for i in xrange(24):
        final_matrix = total_matrix[i]*(1.0/count[i])
        final_2d_matrix = np.reshape(final_matrix, (16, ysize*xsize))
        np.savetxt(os.path.join(save_path,"final_matrix_"+str(i)), final_2d_matrix, fmt = '%1.7f')
    #total总和矩阵转成二维发送
    total_2d_matrix = np.reshape(total_matrix, (24*16, ysize*xsize))
    np.savetxt(os.path.join(save_path,"total_matrix"),total_2d_matrix, fmt = '%d')
    return total_matrix
예제 #3
0
    #list all of the documents
    list_doc = []
    for item in os.listdir(savePath):
        list_doc.append(item)

    list_doc.sort()
    count = 0
    
    #print list_doc
    for item in list_doc:
        #read the image
        f=open(os.path.join(savePath,item),'r')
        s= f.read()
       
        #resolve it read the whole image
        paraDict,matrix=cleanUpPic.resolveRadar(s)
        xsize=paraDict['xsize']
        ysize=paraDict['ysize']
        matrix=np.reshape(matrix,(ysize,xsize))   
        
        print xsize, ysize        
        normal_matrix.append(matrix)
        times_list.append(Time_Trans(paraDict['timeStr']))
        
        #prepic cleanup the noise of the image
        pic=cleanUpPic.PrePic()
        pic.Load_Pic_Matrix(matrix)
        pic.calc_from_DB()
        bool_matrix.append(pic.pic_bool)
        all_matrix.append(pic.pic_radar)