ContextLab / attention-memory-task

An experiment used to explore interactions between covert attention and recognition memory
Other
9 stars 5 forks source link

Check behavioral labeling #77

Closed KirstensGitHub closed 4 years ago

KirstensGitHub commented 5 years ago

Check the compilation and labeling of all behavioral data

KirstensGitHub commented 5 years ago

WHAT WE'RE CHECKING:

These tests check to make sure that the behavioral data is compiled correctly, and that when the memory images are assigned an attention level from viewing, the attention levels are assigned accurately.

INITIAL CHECKS (complete):

This involved reviewing the two functions used to compile and organize / label the data.

EXP 1: Screen Shot 2019-08-26 at 6 41 21 PM

EXP 2: Screen Shot 2019-08-26 at 6 38 33 PM

SUMMARY OF CHANGES (complete):

FINAL CHECKS (in progress):

KirstensGitHub commented 5 years ago

BEHAVIORAL DATA ANALYSIS FUNCTIONS

Functions to Aggregate Subject Data and Verify Correct Stimuli were Presented

def sum_pd(subdir): ''' input: subject directory (string) output: full experiment info (dataframe) '''

# list all files in the subject's directory that contain pres or mem run data
files = [ x for x in os.listdir(subdir) if 'pres' in x or 'mem' in x ]

# read in the data from each of these files
df_list = [ pd.read_csv(subdir+'/'+x) for x in files ]

# concatenate into a single dataframe
df = pd.concat(df_list, ignore_index=True)

return(df)

def add_level(df): ''' input: subject dataframe output: subject dataframe w/ Attention Level string for each Memory trial row '''

for each run

for x in df.Run.unique():

    # select the data only from that run
    mask = df['Run']==x

    # pass the data for that run through run_level to add attention levels to memory images
    df[mask] = run_level(df[mask])

return(df)

def run_level(df): ''' input: df containing pres and mem from single run output: df with string in 'Attention Level' column in each Memory trial row '''

# loop over the trials in this run
for index,row in df[df['Trial Type']=='Memory'].iterrows():

    # obtain the image presented in the memory run
    mem_image = row['Memory Image']

    # obtain the category of the image from its filename
    # (SUN database images -- places -- contain the string 'sun')
    if 'sun' in mem_image:
        mem_image_category = 'Place'
    else:
        mem_image_category = 'Face'

    # add the image category to the memory trial row
    df['Category'][index] = mem_image_category

    # look in the columns for previously presented composites
    for composite in ['Cued Composite', 'Uncued Composite']:

        # if one of the previously seen composites contains the memory image file name (minus the last 4 chars: '.jpg')
        if df[df[composite].str.contains(mem_image[:-4], na=False)].shape[0]!=0:

            # pull the cued category from that row/presentation trial
            cued_cat = df[df[composite].str.contains(mem_image[:-4], na=False)]['Cued Category'].item()

            # if the image category matches the cued category for the presentation trial
            if mem_image_category == cued_cat:

                # AND the image was presented on the Cued Side
                if composite == 'Cued Composite':
                    # label "Full" attention
                    attention = "Full"

                # AND it was presented on the Uncued Side
                elif composite == 'Uncued Composite':
                    # label "Category" attention
                    attention = "Category"

            # else, if the image category does NOT match the cued category for the trial
            else:
                # AND it was presented in the Cued location
                if composite == 'Cued Composite':
                    # labbel "Cued" attention
                    attention = "Side"

                # AND the image was presented in the Uncued location
                elif composite == 'Uncued Composite':
                    # label "None" attention
                    attention = "None"

            # add the attention level to the memory trial row
            df['Attention Level'][index] = attention

mem_mask = df['Trial Type']=='Memory'
df.loc[mem_mask,'Attention Level'] = df.loc[mem_mask,'Attention Level'].fillna('Novel')

return(df)