コード例 #1
0
# -*- coding: utf-8 -*-
"""
Code example of a minimal digit span task.
Authors: Dominique Makowski
Copyright: The Neuropsydia Development Team
Site: https://github.com/neuropsychology/Neuropsydia.py
"""
import neuropsydia as n  # Load neuropsydia
import numpy as np  # For generation of random sequence


n.start()  # Initialize neuropsydia
n.instructions("Listen to the experimenter.")  # Display instructions

# Initialize values
number_of_fails = 0  # Initial number of errors
span = 2  # Initial span

while number_of_fails < 3:  # Do it while the number of errors is smaller than 3
    sequence = np.random.randint(10, size=span)  # Generate sequence of size span with ints ranging from 0 to 9
    good_answer = ""  # Initiate an empty good_answer

    for digit in sequence:  # For every digit in the sequence...
        good_answer = good_answer + str(digit)  # Add the current stimulus to the good answer
        n.newpage("grey")  # Load a grey background
        n.time.wait(250)  # Display an empty screen for 250 ms
        n.newpage("grey")  # Load a grey background
        n.write(digit, size=3)  # Load the stimulus
        n.refresh()  # Display the stimulus on screen
        n.time.wait(1000)  # Wait 1000 ms
コード例 #2
0
# -*- coding: utf-8 -*-
"""
Code example of a minimal go/no-go task.
Authors: Dominique Makowski
Copyright: The Neuropsydia Development Team
Site: https://github.com/neuropsychology/Neuropsydia.py
"""
import neuropsydia as n  # Load neuropsydia
import random  # Import the random module
import pandas as pd  # To manipulate and save the data
import numpy as np  # To do some maths

n.start()  # Start neuropsydia
n.instructions("Goal: Hit SPACE whenever a GREEN circle appears. \nWhen it is RED, don't press anything.")  # Display instructions and break line with \n
n.newpage("grey")  # Fill the screen
n.countdown()  # Display countdown

# Initialize the data storage with a dictionary containing empty lists
data = {"Trial": [],
        "Stimulus": [],
        "ISI":[],
        "RT":[],
        "Response":[]}

for trial in range(5):  # Iterate over the number of trials
    stimulus = random.choice(["green", "red"])  # Select a stimulus type
    ISI = random.randrange(start=500, stop=2000, step=500)  # Select the inter-stimuli interval (ISI)

    n.newpage("grey")  # Fill the screen
    n.write("+")  # Fixation cross
    n.refresh()  # Diplay it on screen
コード例 #3
0
n.start()  # Start neuropsydia

# Initialize data storage
data = {"Stimulus": [],
        "Stimulus_Color": [],
        "Answer": [],
        "RT": [],
        "Condition": [],
        "Correct": []}

#==============================================================================
# Part 1: Denomination
#==============================================================================

n.instructions("Press LEFT when RED, DOWN when GREEN and RIGHT when BLUE.")

n_trials = 10
for trial in range(n_trials):
    n.newpage("grey")  # Neutral grey background
    n.write("+")  # Fixation cross
    n.refresh()  # Display it
    n.time.wait(250)  # Wait 250 ms

    stim_color = np.random.choice(["raw_red", "raw_green", "raw_blue"])  # Choose a color
    stim = "XXXX"
    n.newpage("grey")  # Neutral grey background
    n.write(stim, style="bold", color=stim_color, size=3)  # Load the stimulus
    n.refresh()  # Display it
    answer, RT = n.response()  # Record response and response time
コード例 #4
0
# Initialize data storage
data = {
    "Stimulus": [],
    "Stimulus_Color": [],
    "Answer": [],
    "RT": [],
    "Condition": [],
    "Correct": []
}

#==============================================================================
# Part 1: Denomination
#==============================================================================

n.instructions("Press LEFT when RED, DOWN when GREEN and RIGHT when BLUE.")

n_trials = 10
for trial in range(n_trials):
    n.newpage("grey")  # Neutral grey background
    n.write("+")  # Fixation cross
    n.refresh()  # Display it
    n.time.wait(250)  # Wait 250 ms

    stim_color = np.random.choice(["raw_red", "raw_green",
                                   "raw_blue"])  # Choose a color
    stim = "XXXX"
    n.newpage("grey")  # Neutral grey background
    n.write(stim, style="bold", color=stim_color, size=3)  # Load the stimulus
    n.refresh()  # Display it
    answer, RT = n.response()  # Record response and response time
コード例 #5
0
# -*- coding: utf-8 -*-
"""
Code example of a minimal go/no-go task.
Authors: Dominique Makowski
Copyright: The Neuropsydia Development Team
Site: https://github.com/neuropsychology/Neuropsydia.py
"""
import neuropsydia as n  # Load neuropsydia
import random  # Import the random module
import pandas as pd  # To manipulate and save data
import numpy as np  # To do some maths

n.start()  # Start neuropsydia
n.instructions("Goal: Hit SPACE whenever a GREEN circle appears. \nIf RED, don't press anything!")  # Display instructions and break line with \n
n.newpage("grey")  # Fill the screen
n.countdown()  # Display countdown

# Initialize the data storage with a dictionary containing empty lists
data = {"Trial": [],
        "Stimulus": [],
        "ISI":[],
        "RT":[],
        "Response":[]}

n_trials = 10  # Number of trials
for trial in range(n_trials):  # Iterate over the number of trials
    stimulus = random.choice(["green", "green", "green", "red"])  # Select a stimulus type
    ISI = random.randrange(start=250, stop=1250, step=250)  # Select the inter-stimuli interval (ISI)

    n.newpage("grey")  # Fill the screen
    n.write("+")  # Fixation cross
コード例 #6
0
# Identification
if testmode is True:
    participant = "test"
else:
    n.newpage((74,20,140))
    n.write("STAR CONTROL", y = 1.5, color = "white", size = 3)
    participant = n.ask("ID: ", x = -1, y = -3, color = "white", background = (74,20,140), size = 1.5)

# Create data folder
path = './data/' + participant + "/"
if os.path.exists(path) is False:
    os.mkdir(path)


# Instructions (can be activated to increase the pressure in the context of experiments with students)
n.instructions("This is a game designed to measure how fast your are, as speed has been shown to a reliable index of intellectual ability and mental agility.\n\nThe task is repetitive and long on purpose, as the ability of maintaining speed until the end is also an indicator of cognitive altertness and aptitude.\n\nHence, throughout the game, we would like you to try responding as fast as possible.", size=0.8, end_text="Press ENTER to start the game.")

# Part 1
# -----------------------------------------------------------------------------
start_time = datetime.datetime.now()
df_ProcessingSpeed = processing_speed(n_trials=n_trials["P1"], testmode = testmode, display_trigger = display_trigger)
save_data(df_ProcessingSpeed, start_time, participant, task = "Processing_Speed", path = path + participant + "_ProcessingSpeed")


# Part 2
# -----------------------------------------------------------------------------
start_time = datetime.datetime.now()
df_ResponseSelection = response_selection(n_trials=n_trials["P2"], testmode = testmode, display_trigger = display_trigger)
save_data(df_ResponseSelection, start_time, participant, task = "Response_Selection", path =path + participant + "_ResponseSelection")

コード例 #7
0
ファイル: DigitSpan.py プロジェクト: hndr91/Neuropsydia.py
# -*- coding: utf-8 -*-
"""
Code example of a minimal digit span task.
Authors: Dominique Makowski
Copyright: The Neuropsydia Development Team
Site: https://github.com/neuropsychology/Neuropsydia.py
"""
import neuropsydia as n  # Load neuropsydia
import numpy as np  # For generation of random sequence

n.start()  # Initialize neuropsydia
n.instructions("Listen to the experimenter.")  # Display instructions

# Initialize values
number_of_fails = 0  # Initial number of errors
span = 2  # Initial span

while number_of_fails < 3:
    sequence = np.random.randint(10, size=span)  # Generate sequence
    good_answer = ""  # Transform sequence of integers into string

    for digit in sequence:  # For every element in the sequence...
        good_answer = good_answer + str(
            digit)  # Add the current stimulus to sequence
        n.newpage("grey")
        n.time.wait(250)  # Display an empty screen for 250 ms
        n.newpage("grey")  # Load a grey background
        n.write(digit, size=3)  # Load the stimulus
        n.refresh()  # Render the stimulus on screen
        n.time.wait(1000)  # Wait 1000 ms
コード例 #8
0
ファイル: BDI.py プロジェクト: y1ngyang/Neuropsydia.py
             1: "I feel I have failed more than the average person.",
             2: "As I look back on my life, all I can see is a lot of failures.",
             3: "I feel I am a complete failure as a person."
             }
        # I cannot legally show the rest of the questions
        }



n.start()  # Initialize neuropsydia

participant_id = n.ask("Participant ID:", order=1)  # Get participant id
participant_gender = n.ask("Gender:", order=2)  # Get participant's gender
participant_age = n.ask("Age:", order=3)  # get participant's age

n.instructions("Please tell if you agree with each following proposition.")  # Instructions


data = {}  # Initialize empty data dict
for item in items:

    data[item] = {}  # For each item, initialize empty sub-dict

    for proposition_number in items[item]:

        question = items[item][proposition_number]  # Current proposition

        n.newpage()
        n.write("\n\n\n" + question, long_text=True)  # Display current proposition
        answer = n.choice([0, 1],
                          overwrite_choices_display=["No", "Yes"],
コード例 #9
0
ファイル: Flanker.py プロジェクト: y1ngyang/Neuropsydia.py
# -*- coding: utf-8 -*-
"""
Code example of a minimal flanker task.
Authors: Dominique Makowski
Copyright: The Neuropsydia Development Team
Site: https://github.com/neuropsychology/Neuropsydia.py
"""
import neuropsydia as n  # Load neuropsydia
import pandas as pd  # To manipulate and save data
import numpy as np  # To do some maths

n.start()  # Start neuropsydia
n.instructions(
    "Hit RIGHT or LEFT arrow according to the direction of the CENTRAL arrow."
)  # Display instructions

# Initialize cache
cache = {}
for possible_angle in [0, 90, 180]:
    cache = n.preload("arrow-left.png",
                      size=2,
                      rotate=possible_angle,
                      cache=cache)  # Preload images

# Initialize the data storage with a dictionary containing empty lists
data = {
    "Trial": [],
    "Trial_Type": [],
    "Stimulus_Orientation": [],
    "RT": [],
    "Response": []
コード例 #10
0
#Create empty lists to store the stimuli displayed and the rating of the ppts
stimuli = []
rating_arousal = []
rating_valence = []
fixation = []

# =============================================================================
# Start
# =============================================================================
n.start()

participant = n.ask("ID: ")

n.instructions(
    "In this task, you will be presented with different images and your task is to rate how intense your feeling is when you see the images."
)

fixation_cross(3000)

for i in range(60):  # Number of trials
    n.newpage("grey", auto_refresh=False)
    random_image = random.choice(
        [x for x in list_stimuli if os.path.isfile(os.path.join(path, x))])
    n.image("images/" + random_image, size=20, y=0)
    trigger.start()
    n.refresh()
    n.time.wait(3000)
    list_stimuli.remove(random_image)
    random_image = random_image.split(".")[0]
    stimuli.append(random_image)