Exemplo n.º 1
0
def join_signals(master, pieces):
    print('* Creating %r from %s' % (master, pieces))
    master_dir = os.path.join(Const.signals_dir, master)
    if not os.path.exists(master_dir):
        os.makedirs(master_dir)
    master_signal = os.path.join(master_dir, Const.SIGNAL_FILE)

    if not os.path.exists(master_signal):

        data = []
        for piece in pieces:
            filename = os.path.join(Const.signals_dir, piece,
                                    Const.SIGNAL_FILE)
            y = log_load_from_hdf(filename)
            data.append(y)

        all_data = np.vstack(data)
        desc('first piece', data[0])
        desc('all_data', all_data)
        print('  all data: %s %s' % (all_data.shape, all_data.dtype))

        print('  creating %r' % master_signal)
        log_write_to_hdf(master_signal, all_data)

    gt = os.path.join(Const.signals_dir, pieces[0], Const.GT_FILE)
    gtm = os.path.join(Const.signals_dir, master, Const.GT_FILE)
    if os.path.exists(gt):
        if os.path.exists(gtm):
            os.unlink(gtm)
        print('  copying ground truth %r' % gtm)
        os.link(gt, gtm)
    else:
        msg = ('  (no ground truth %r found)' % gt)
        raise Exception(msg)
Exemplo n.º 2
0
def join_signals(master, pieces):
    print('* Creating %r from %s' % (master, pieces))
    master_dir = os.path.join(Const.signals_dir, master)
    if not os.path.exists(master_dir):
        os.makedirs(master_dir)
    master_signal = os.path.join(master_dir, Const.SIGNAL_FILE)

    if not os.path.exists(master_signal):

        data = []
        for piece in pieces:
            filename = os.path.join(Const.signals_dir, piece,
                                    Const.SIGNAL_FILE)
            y = log_load_from_hdf(filename)
            data.append(y)

        all_data = np.vstack(data)
        desc('first piece', data[0])
        desc('all_data', all_data)
        print('  all data: %s %s' % (all_data.shape, all_data.dtype))

        print('  creating %r' % master_signal)
        log_write_to_hdf(master_signal, all_data)


    gt = os.path.join(Const.signals_dir, pieces[0], Const.GT_FILE)
    gtm = os.path.join(Const.signals_dir, master, Const.GT_FILE)
    if os.path.exists(gt):
        if os.path.exists(gtm):
            os.unlink(gtm)
        print('  copying ground truth %r' % gtm)
        os.link(gt, gtm)
    else:
        msg = ('  (no ground truth %r found)' % gt)
        raise Exception(msg)
Exemplo n.º 3
0
def extract_signals(id_video, id_filter):
    filter_function = Const.filters[id_filter]['filter']
    ndim = Const.filters[id_filter]['ndim']
    assert ndim in [2, 3]

    mp4 = os.path.join(Const.data_dir, '%s.mp4' % id_video)
    should_exist(mp4)

    stem = find_stem(id_video)

    # TODO: use stem
    calibration = os.path.join(Const.data_dir,
                               Const.CALIBRATION_PATTERN % stem)
    if os.path.exists(calibration):
        S = get_groundtruth(calibration)
    else:
        print('No ground truth file %r found.' % calibration)
        S = None

    maskfile = os.path.join(Const.data_dir, Const.MASK_PATTERN % stem)
    if os.path.exists(maskfile):
        mask = get_mask(maskfile)
        mask_select = filter_function(mask)
    else:
        print('No mask file %r found.' % maskfile)
        mask = None

    print('Creating %s - %s ' % (id_video, id_filter))

    signal_name = '%s-%s' % (id_video, id_filter)
    signal_dir = os.path.join(Const.signals_dir, signal_name)
    if not os.path.exists(signal_dir):
        os.makedirs(signal_dir)

    # copy signal
    signal_file = os.path.join(signal_dir, Const.SIGNAL_FILE)

    if mask is None:
        # No mask, creting normal file
        extract_data(mp4, filter_name=id_filter, hdf=signal_file)
    else:
        # Write to temp file
        tmp_file = signal_file + '.without_mask'
        extract_data(mp4, filter_name=id_filter, hdf=tmp_file)
        y = log_load_from_hdf(tmp_file)
        desc('y', y)
        y0 = y[0]
        desc('y0', y0)
        desc('mask_select', mask_select)

        y0_sel = y0[mask_select]
        desc('y0_sel', y0_sel)
        print('Number selected: %s' % np.sum(mask_select))
        y_sel = y[..., mask_select]
        desc('y_sel', y_sel)

        log_write_to_hdf(signal_file, y_sel)

    should_exist(signal_file)

    if S is not None:
        if mask is None:
            desc('S', S)
            true_S = filter_S(S, filter_function, ndim)
            desc('true_S', true_S)
        else:
            true_S = filter_S_keep_dim(S, filter_function)
            desc('true_S', true_S)
            true_S = true_S[:, mask_select]
            desc('true_S (after mask)', true_S)

        write_arrays_to_pickle(os.path.join(signal_dir, Const.GT_FILE),
                               {'true_S': true_S})
    else:
        print('No ground truth found.')
Exemplo n.º 4
0
def extract_signals(id_video, id_filter):
    filter_function = Const.filters[id_filter]['filter']
    ndim = Const.filters[id_filter]['ndim']
    assert ndim in [2, 3]

    mp4 = os.path.join(Const.data_dir, '%s.mp4' % id_video)
    should_exist(mp4)

    stem = find_stem(id_video)

    # TODO: use stem
    calibration = os.path.join(Const.data_dir,
                               Const.CALIBRATION_PATTERN % stem)
    if os.path.exists(calibration):
        S = get_groundtruth(calibration)
    else:
        print('No ground truth file %r found.' % calibration)
        S = None

    maskfile = os.path.join(Const.data_dir, Const.MASK_PATTERN % stem)
    if os.path.exists(maskfile):
        mask = get_mask(maskfile)
        mask_select = filter_function(mask)
    else:
        print('No mask file %r found.' % maskfile)
        mask = None

    print('Creating %s - %s ' % (id_video, id_filter))

    signal_name = '%s-%s' % (id_video, id_filter)
    signal_dir = os.path.join(Const.signals_dir, signal_name)
    if not os.path.exists(signal_dir):
        os.makedirs(signal_dir)

    # copy signal
    signal_file = os.path.join(signal_dir, Const.SIGNAL_FILE)

    if mask is None:
        # No mask, creting normal file
        extract_data(mp4, filter_name=id_filter, hdf=signal_file)
    else:
        # Write to temp file
        tmp_file = signal_file + '.without_mask'
        extract_data(mp4, filter_name=id_filter, hdf=tmp_file)
        y = log_load_from_hdf(tmp_file)
        desc('y', y)
        y0 = y[0]
        desc('y0', y0)
        desc('mask_select', mask_select)

        y0_sel = y0[mask_select]
        desc('y0_sel', y0_sel)
        print('Number selected: %s' % np.sum(mask_select))
        y_sel = y[..., mask_select]
        desc('y_sel', y_sel)

        log_write_to_hdf(signal_file, y_sel)

    should_exist(signal_file)

    if S is not None:
        if mask is None:
            desc('S', S)
            true_S = filter_S(S, filter_function, ndim)
            desc('true_S', true_S)
        else:
            true_S = filter_S_keep_dim(S, filter_function)
            desc('true_S', true_S)
            true_S = true_S[:, mask_select]
            desc('true_S (after mask)', true_S)

        write_arrays_to_pickle(
                 os.path.join(signal_dir, Const.GT_FILE),
                 {'true_S': true_S}
        )
    else:
        print('No ground truth found.')