Exemplo n.º 1
0
def save_pickle(obj):
    pickle_dir = file_operation.data_output('pickle')
    if not os.path.exists(pickle_dir):
        print 'No reference pickle output directory, now creating one.'
        os.makedirs(pickle_dir)
    with open('ref.pickle', 'w') as f:  # Python 3: open(..., 'wb')
        pickle.dump(obj, f)
def save_csv(data_numeric, num_frame, filename):
    flat_data = []
    for i in range(1, len(data_numeric)):
        flat_data.append(cut_tail(data_numeric[i]) - load_ref())
    csv_dir = file_operation.data_output('csv')

    if not os.path.exists(csv_dir):
        print('No csv directory, now creating one.')
        os.makedirs(csv_dir)
    _, tail = os.path.split(filename)
    csv_name = csv_dir + tail[:-4] + '_' + 'difference_not_scale.csv'

    try:
        with open(csv_name, 'w') as f:
            # print f
            for i in range(len(data_numeric) - 1):
                f.write('frame#' + str(i) + '\n')
                array = np.transpose(np.flipud(flat_data[i])).reshape(23, 28)
                csv.writer(f).writerows(array)
        f.close()

    except IOError:
        print(
            'file still opening, in lock. Please close all the corresponding csv file'
        )
Exemplo n.º 3
0
def save_img(img, index, filename):
    # print 'saving img ' + str(index)
    img_dir = file_operation.data_output('img')
    if not os.path.exists(img_dir):
        print 'No contour img directory, now creating one.'
        os.makedirs(img_dir)
    _, tail = os.path.split(filename)
    # extract the .txt extend file name
    plt.imsave(img_dir + tail[:-4] + '_' + str(index) + '.jpg',
               img,
               cmap=plt.cm.GnBu)
Exemplo n.º 4
0
def write_angle(filename, slice_timestamp, index_list, angle_list):
    pair_dir = file_operation.data_output('pair')
    if not os.path.exists(pair_dir):
        print 'No timestamp angle pair directory, now creating one.'
        os.makedirs(pair_dir)
    _, tail = os.path.split(filename)
    # extract the .txt extend file name
    f = open(pair_dir + tail[:-4] + "_timestamp_angle_pair.csv", "w")
    w = csv.writer(f)
    #repitition_angle = []
    # for i in angle_list:
    #     repitition_angle.append( [str(i)] * 162 + ['write command']*2)

    # angle_list = list(itertools.chain.from_iterable(slice_timestamp))
    # print angle_list
    [identity, timestamp] = zip(*slice_timestamp)
    #print 'identity', identity
    #timestamp_angle = zip(identity, timestamp, frame_list)
    #print timestamp_angle
    timestamp_angle = zip(index_list, identity, timestamp, angle_list)
    # print timestamp_angle
    w.writerows(timestamp_angle)
    # print timestamp_angle
    f.close()