To have a uniform library that can be used for configuring both psychoacoustics and electrophys I wrote a set of python programs. These currently live on twinkle under colliculus/behaviourBoxes/software/ratCageProgramsV2 although we really ought to put them on github or similar (volunteers)?
The fundamental philosophy is to break down an experiment into a series of modules, each being its own python object. A typical experiment needs the following modules:
- A scheduler, whose job it is to make the other modules all play together nicely. Typically a scheduler knows about a schedule, which is a list of trials that need to be worked through or anther type of code that can decide what trials are up next, and when we are done. A scheduler also communicates with the other modules listed below to make sure they do what they need to do at the appropriate times. Typical example: class scheduler in listScheduler.py
- A stimulus module, whose job it is to make the appropriate stimuli ready when they are needed, as directed by the scheduler. Typical examples: any of the many objects derived from class stimObject in ClickTrainLibrary.py
- A data handler, which writes files to disk that contain information on the stimuli that were delivered and the responses that were recorded. Typical examples: class dataHandler in dataHandling.py or dataHandlingEphys.py
- A detectors module which instantiates buttons / spouts / user interface elements for the psychoacoustic responses. Currently a scheduler expects detectors, but if you do pure acute ephys you don't need them. In that case set them to "None". Typical examples: class detectors in spoutResponses.py or mouseResponses.py
- If you are planning to do ephys, you will also need an ephysRecorder. The ephys recorders are a bit apart, as they are meant to just run in the background and collect data continuously. So, unlike the other four modules listed here, they are not handled by the scheduler. If you want to do ephys, you simply instantiate an appropriate recorder and declare it in config, and make sure you use dataHandlingEphys. Then start the recorder before you start the scheduler, and stop it again when the schedule completes. ephysRecorder objects and their components are declared in RZ2ephys.py
Consider Ephys_ClicksThresh.py. This is a little script to record electrophysiological responses to a series of clicktrain stimuli.
In lines 22-32 we set up our ephys recorder.
In lines 36-63 we set up the stimulus module. We instantiate a clickTrainObject from library ClickTrainLibrary.py on line 49 and set its default parameters as required. Note that the stimulus module is written so that it allows stimuli to be presented through different types of hardware (PC or sound cards or TDT equipment) so we also specify (lines 40-46) whether we want to play these on the sound card or an RZ6 or a cochlear implant.
In line 76 we specify that we won't need detectors as there is no psyphys.
In line 79, 80 we set up the data handler
In lines 86-95 we set up the scheduler. The code mySchedule=listScheduler.schedule(["ABL (dB)"]); mySchedule.permute([myLevels],myRepeats) creates a schedule which ensures that the stimulus intensity parameter "ABL(dB)" will loop through the list of values given in myLevels the number of times specified in myRepeats. Once the scheduler has been created and handed the other objects it needs to orchestrate (line 95 scheduler=listScheduler.scheduler(detectors,stim,dataHandler,mySchedule) ) all that needs doing is to start the scheduler (see line 100) and the experiment will start running.