Tasks¶
Tasks in Ethopy define the experimental protocol by combining experiments, behaviors, and stimuli with specific parameters. They serve as configuration files that specify how an experiment should run.
Task Structure¶
A typical task file consists of three main parts:
- Session Parameters: Global settings for the experiment
- Stimulus/Behavior/Experiment Conditions: Parameters
- Experiment Configuration: Setup and execution of the experiment
Basic Structure¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
Using of Task Templates in Ethopy¶
Overview¶
The ethopy-create-task
command generates a Python template file for an Ethopy experiment. This template includes default parameters and placeholders that you need to customize for your specific experiment.
Generating a Template¶
To create a task template, run the following command in your terminal:
1 |
|
You will be prompted to enter the module paths and class names for the experiment, behavior, and stimuli components. The generated file will include all required parameters with placeholders (...
) that need to be filled.
Template Generation Process¶
The script follows these steps:
- Prompt for Module Paths and Class Names
- Enter the paths relative to
ethopy
for:- Experiment module (e.g.,
experiments.match_port
) - Behavior module (e.g.,
behaviors.multi_port
) - Stimulus module (e.g.,
stimuli.grating
)
- Experiment module (e.g.,
-
Enter corresponding class names for each module.
-
Validate Imports
- The script attempts to import the specified modules and classes.
-
If an import fails, an error message is displayed.
-
Extract Default Parameters
-
The script retrieves the parameters from the experiment, behavior, and stimulus classes.
-
Generate a Template File
-
A Python file is created with structured sections:
- Session Parameters: General experiment settings
- Experiment Setup: Instantiating the experiment
- Trial Conditions: Configuration for experiments, behaviors, and stimuli
- Condition Merging: Combining all conditions for trial generation
- Execution: Running the experiment
-
Save the File
- The template is saved with a default filename (
task_<stimulus>_<date>.py
) or a user-specified name.
Next Steps¶
After generating the template:
- Open the generated file in a text editor.
- Fill in missing parameters where indicated by
...
- Customize trial conditions to match your experiment's requirements.
- Run the script to execute the experiment.
By following these steps, you can quickly set up an Ethopy experiment with minimal manual configuration.
Creating Tasks¶
1. Session Parameters¶
Session parameters control the overall experiment behavior:
1 2 3 4 5 6 7 8 |
|
2. Stimulus Conditions¶
Define the parameters for your stimuli:
1 2 3 4 5 6 7 8 9 10 11 |
|
3. Creating Conditions¶
Use the experiment's Block class and make_conditions method:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
Helper Functions¶
Ethopy provides helper functions for task creation:
Get Parameters¶
1 2 3 4 |
|
Format Parameters¶
1 2 3 4 |
|
Example Tasks¶
1. Grating Test¶
Visual orientation discrimination experiment:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
|
Best Practices¶
-
Parameter Organization: - Group related parameters together - Use descriptive variable names - Document units in comments
-
Error Handling: - Validate parameters before running - Use helper functions to get required parameters - Check for missing or invalid values
-
Documentation: - Comment complex parameter combinations - Document dependencies - Include example usage
-
Testing: - Test with different parameter combinations - Verify stimulus timing - Check reward delivery
Common Issues¶
-
Parameter Errors: - Missing required parameters - Incorrect parameter types - Invalid parameter combinations
-
Timing Issues: - Incorrect duration values - Mismatched trial/stimulus timing - Intertrial interval problems
-
Hardware Configuration: - Wrong setup_conf_idx - Uncalibrated rewad ports - Missing hardware components