def test_split():

	dm = DataMatrix(length=4)
	dm.a = 'a', 'a', 'b', 'b'
	dm.b = 0, 1, 2, 3
	g = ops.split(dm.a)
	val, dm = g.next()
	eq_(val, 'a')
	check_col(dm.a, ['a', 'a'])
	check_col(dm.b, [0, 1])
	val, dm = g.next()
	eq_(val, 'b')
	check_col(dm.a, ['b', 'b'])
	check_col(dm.b, [2, 3])
Ejemplo n.º 2
0
def test_split():

    dm = DataMatrix(length=4)
    dm.a = 'a', 'a', 'b', 'b'
    dm.b = 0, 1, 2, 3
    # Without values
    g = ops.split(dm.a)
    val, dm = next(g)
    assert val == 'a'
    check_col(dm.a, ['a', 'a'])
    check_col(dm.b, [0, 1])
    val, dm = next(g)
    assert val == 'b'
    check_col(dm.a, ['b', 'b'])
    check_col(dm.b, [2, 3])
    # With values
    dm = DataMatrix(length=4)
    dm.a = 'a', 'a', 'b', 'b'
    dm.b = 0, 1, 2, 3
    dma, dmb = ops.split(dm.a, 'a', 'b')
    check_col(dma.a, ['a', 'a'])
    check_col(dma.b, [0, 1])
    check_col(dmb.a, ['b', 'b'])
    check_col(dmb.b, [2, 3])
Ejemplo n.º 3
0
def roi_hist(dm, col):

    for roi, rdm in ops.split(dm.roi):
        sns.distplot(rdm[col],
                     label='{} (N={})'.format(roi, len(rdm)),
                     hist=True,
                     kde=False,
                     bins=50,
                     hist_kws={
                         "alpha": .8,
                         "color": COLORS[roi]
                     })
    plt.xlabel('t value')
    plt.ylabel('Density')
    plt.axvline(0, color='black', linestyle=':')
    plt.legend()
def process_video(run, start_frame=1):

    kernel = smoothing_kernel()
    cap = cv2.VideoCapture(SRC_VIDEO.format(run - 1))
    dm = DataMatrix()
    im_prev = None
    for frame in it.count(start=start_frame):
        ret, im = cap.read()
        if not ret or frame >= MAX_FRAME:
            print('Done!')
            break
        dm <<= process_frame(run, frame, luminance_map(im, kernel),
                             change_map(im, im_prev, kernel))
        im_prev = im
    for sub, sdm in ops.split(dm.sub):
        io.writetxt(sdm, DST.format(subject=sub, run=run))
Ejemplo n.º 5
0
dm = run()
print(dm)

# Here we set up the baseline to remove NaN values
dm.pupil = srs.endlock(dm.ptrace_rsvp) 

dm.pupil = srs.baseline(
    series= dm.pupil,
    baseline=dm.ptrace_rsvp,
    bl_start=0,
    bl_end=2,
    method='subtractive'
)

# Splitting datamatrix between the two type of stimuli
blueDM, redDM = ops.split(dm.target_object, "blue", "red")

# Plot for preprocessed trace
plt.figure()
plt.title('Preprocesed trace')
for tone, cdm in ops.split(redDM.tone_red):
    colour = "#FF3333" if tone == "bright" else "#8B0000"
    plot.trace(cdm.pupil, color=colour)
    
for tone, cdm in ops.split(blueDM.tone_blue):
    colour = "#00FFFF" if tone == "bright" else "#00008B"
    plot.trace(cdm.pupil, color=colour)

plt.tight_layout()
plt.savefig(path + "/preprocessed.png")
plt.clf()
def test_split():

    dm = DataMatrix(length=4)
    dm.a = 'a', 'a', 'b', 'b'
    dm.b = 0, 1, 2, 3
    # Without values
    g = ops.split(dm.a)
    val, dm = next(g)
    assert val == 'a'
    check_col(dm.a, ['a', 'a'])
    check_col(dm.b, [0, 1])
    val, dm = next(g)
    assert val == 'b'
    check_col(dm.a, ['b', 'b'])
    check_col(dm.b, [2, 3])
    # With values
    dm = DataMatrix(length=4)
    dm.a = 'a', 'a', 'b', 'b'
    dm.b = 0, 1, 2, 3
    dma, dmb = ops.split(dm.a, 'a', 'b')
    check_col(dma.a, ['a', 'a'])
    check_col(dma.b, [0, 1])
    check_col(dmb.a, ['b', 'b'])
    check_col(dmb.b, [2, 3])
    # With multiple columns
    dm = DataMatrix(length=8)
    dm.A = 0, 0, 1, 1, 0, 0, 1, 1
    dm.B = 'a', 'b', 'a', 'b', 'a', 'b', 'a', 'b'
    dm.C = 'x', 'x', 'x', 'x', 'y', 'y', 'y', 'y'
    g = ops.split(dm.A, dm.B)
    val1, val2, sdm = next(g)
    assert val1 == 0
    assert val2 == 'a'
    assert (len(sdm) == 2)
    val1, val2, sdm = next(g)
    assert val1 == 0
    assert val2 == 'b'
    assert (len(sdm) == 2)
    val1, val2, sdm = next(g)
    assert val1 == 1
    assert val2 == 'a'
    assert (len(sdm) == 2)
    val1, val2, sdm = next(g)
    assert val1 == 1
    assert val2 == 'b'
    assert (len(sdm) == 2)
    g = ops.split(dm.A, dm.B, dm.C)
    val1, val2, val3, sdm = next(g)
    assert val1 == 0
    assert val2 == 'a'
    assert val3 == 'x'
    assert (len(sdm) == 1)
    val1, val2, val3, sdm = next(g)
    assert val1 == 0
    assert val2 == 'a'
    assert val3 == 'y'
    assert (len(sdm) == 1)
    val1, val2, val3, sdm = next(g)
    assert val1 == 0
    assert val2 == 'b'
    assert val3 == 'x'
    assert (len(sdm) == 1)
    val1, val2, val3, sdm = next(g)
    assert val1 == 0
    assert val2 == 'b'
    assert val3 == 'y'
    assert (len(sdm) == 1)
    val1, val2, val3, sdm = next(g)
    assert val1 == 1
    assert val2 == 'a'
    assert val3 == 'x'
    assert (len(sdm) == 1)
    val1, val2, val3, sdm = next(g)
    assert val1 == 1
    assert val2 == 'a'
    assert val3 == 'y'
    assert (len(sdm) == 1)
    val1, val2, val3, sdm = next(g)
    assert val1 == 1
    assert val2 == 'b'
    assert val3 == 'x'
    assert (len(sdm) == 1)
    val1, val2, val3, sdm = next(g)
    assert val1 == 1
    assert val2 == 'b'
    assert val3 == 'y'
    assert (len(sdm) == 1)
Ejemplo n.º 7
0
if args.parse:
    print("Parsing again! This will take some time...")
    run.clear()
else:
    if os.path.isdir(path + "/.memoize/"):
        print("Using existing parsed data (unless new files have been added).")
    else:
        print(
            "No existing directory with parsed data! Parsing files, this will take some time..."
        )

dm = run()
print(dm)
print(dm.column_names)

bwCondition, colourCondition = ops.split(dm.block_condition, 0, 1)


def ttest(var1, var2):
    '''Runs a t-test between two variables'''
    mean1 = np.mean(var1)
    mean2 = np.mean(var2)
    vari1 = np.var(var1)
    vari2 = np.var(var2)
    sd1 = np.sqrt(vari1)
    sd2 = np.sqrt(vari2)
    len1 = len(var1)
    len2 = len(var2)
    print("Performing T-Test with the following parameters:")
    print("Variable 1 - Mean: {0} SD: {1} N: {2} CV: {3}".format(
        mean1, sd1, len1, sd1 / mean1))
Ejemplo n.º 8
0
def splitFillers(dm):
    """
    Splits filler trials into:
    - 2 first fillers, one negative, one neutral
    - 2 last fillers, one negative, one neutral
    - remaining fillers, that should be mixed with the experimental trials
    
    Arguments:
    dm        --- DataMatrix containing filler objects
    
    Returns:
    dm_first    --- dm containing only 2 rows, corresponding to the first 2 fillers
    dm_last     --- dm containing only 2 rows, corresponding to the last 2 fillers
    dm_remaining    --- dm containing the remainder (if any) of the fillers
    
    NOTE the order
    """

    # Below is an awful piece of script to make sure the first and last two fillers
    # consist of one neg and one neu trial.
    # I just don't see a way to do this more elegantly

    # Shuffle the fillers:
    dm = ops.shuffle(dm)

    # Split the fillers on the basis of valence:
    (cat1, filler_dm_negative), (cat2,
                                 filler_dm_neutral) = ops.split(dm["Emotion"])

    # Select 2 fillers, one from each valence category, as first 2 fillers:
    identifier_filler1_neg = filler_dm_negative["Object"][0]
    identifier_filler1_neu = filler_dm_neutral["Object"][0]

    dm_filler1_neg = filler_dm_negative["Object"] == identifier_filler1_neg
    dm_filler1_neu = filler_dm_neutral["Object"] == identifier_filler1_neu

    # Merge the two first trial_dms
    dm_first = dm_filler1_neg << dm_filler1_neu
    # Shuffle
    dm_first = ops.shuffle(dm_first)
    # Add a column indicating the type of filler (for later debugging/cross
    # checking)
    dm_first["filler_type"] = "first"

    # Remove the already selected pairs from the dms
    # (i.e., select WITHOUT replacement):
    filler_dm_negative = filler_dm_negative[1:]
    filler_dm_neutral = filler_dm_neutral[1:]

    # Do the same thing for the last 2 fillers:
    # Select 2 fillers, one from each valence category, as first 2 fillers:
    identifier_filler2_neg = filler_dm_negative["Object"][0]
    identifier_filler2_neu = filler_dm_neutral["Object"][0]

    dm_filler2_neg = filler_dm_negative["Object"] == identifier_filler2_neg
    dm_filler2_neu = filler_dm_neutral["Object"] == identifier_filler2_neu
    # Merge:
    dm_last = dm_filler2_neg << dm_filler2_neu
    # And shuffle:
    dm_last = ops.shuffle(dm_last)
    # Add column with filler type
    dm_last["filler_type"] = "last"

    # Remove from the dms:
    filler_dm_negative = filler_dm_negative[1:]
    filler_dm_neutral = filler_dm_neutral[1:]

    # Merge the remaining filler dms:
    dm_remaining = filler_dm_negative << filler_dm_neutral
    # Shuffle:
    dm_remaining = ops.shuffle(dm_remaining)
    # Add column with filler type
    dm_remaining["filler_type"] = "middle"

    return dm_first, dm_last, dm_remaining