Ultrasession in opensesame
From Phonlab
Jump to navigationJump to searchThe recommended way to acquire ultrasound data in the Phonology Lab is via an Opensesame experiment. You can use Opensesame to display a series of prompts to a subject and use inline scripts to run and control the data acquisition utilities ultracomm and ultrasession.py. A simple experiment proceeds like this:
- Set configuration variables related to data acquisition. These are the imaging parameters and the location to store results.
- Initialize the ultrasound acquisition system.
- Loop over a list of stimuli which are used to prompt the subject.
- Display a preparatory prompt to the subject.
- Start data acquisition and wait until the ultrasound system confirms that it is imaging.
- Display a speaking prompt to the subject during data acquisition. This prompt can be shown for a defined duration, or it can be displayed until the subject presses a key.
- Send a signal to stop data acquisition.
- Repeat the loop.
Sample experiment
A sample experiment that contains the steps listed in the previous section is available in the ultracomm
repository on github. See the test experiment provided in the latest release.
The sample experiment relates to the listed steps as follows:
- The
ultrasound_arguments
inline script defines variables related to data acquisition, and you need to edit some variable definitions. The most important variables to change aremyparams
, which points to your imaging parameters file, anddatadir
, which is the parent directory for your timestamped acquisitions. In the Phonology Lab the data directory should be somewhere on theU:
drive. Setdo_log
toTrue
if you wantultracomm
to produce a detailed log of its activity.
- The
init_ultrasound
inline script initializes the Ultrasonix system. You should not need to make any changes to this script.
- The
stimuli
loop object contains a list of prompts to display to the subject. The prompts are provided in thestimulus
variable, and to keep things simple you should give your prompt variable the same name.
- The
display_word_prep
object shows the preparatory prompt to the subject. Customize this display for your own needs.
- The
run_ultrasession
inline script startsultrasession.py
and waits until the ultrasound system has confirmed it is imaging. You should not need to change this script unless you did not call your prompt variablestimulus
.
- The
display_word_while_acquiring
object displays the acquisition prompt to the subject. Customize this display for your own needs. It can end after a duration of your choosing, or on a keypress.
- The
stop_acquisition
inline script terminatesultrasession.py
. You should not need to change this script.
Troubleshooting
- Early versions of
ultracomm
andultrasession.py
had issues with occasional hangs when run in an Opensesame experiment. These problems are believed to have been resolved as of the Summer 2015 0.2.1-alpha release ofultracomm
when used with an up-to-dateultrasession.py
and following the inline scripts used in the sample experiment. Nevertheless, it is good form to check for instances ofsox
andultracomm
that continue to run after your experiment has concluded, as they may continue to write data to disk until they are terminated. To do this pressCtrl-Alt-Delete
and open the Task Manager. Check the Processes tab for instances ofrec.exe
(an alias forsox.exe
) andultracomm.exe
and use the End Process button to terminate these programs if they are present.
- A known issue is that the Ultrasonix system sometimes starts imaging but never sends data to the acquisition computer. This situation occurs in about 1% of acquisitions and results in empty
.bpr
and.bpr.idx.txt
files.
- There is an issue with
ultracomm
occasionally terminating with an access violation error. This error occurs at program end, after acquisition has completed and data files are closed. It is believed to be the result of a bug in the Ulterius library supplied by Ultrasonix and used byultracomm
. The error occurs at program end and doesn't seem to result in bad or missed data, but it can result in a Windows error dialog box popping up, which can interfere with the flow of a series of acquisitions in an experiment. The--av-hack
option is used to set the program's error reporting so that access violations do not result in popup messages:
ultracomm --params /path/to/params.cfg --output /path/to/output.bpr --av-hack
You can use the same parameter when calling ultracomm
via ultrasession.py
:
python C:\Anaconda\Scripts\ultrasession.py --params \path\to\params.cfg --datadir \path\to\output\dir --av-hack
- The Windows Error Reporting service has also been turned off on the data acquisition computer to help prevent popup error messages.
ultracomm
andultrasession.py
can generate lots of text sent to STDOUT and STDERR, especially in verbose mode. As a result it is safer to usecommunicate()
from the Pythonsubprocess
module rather thanwait()
when callingultrasession.py
orultracomm
becausewait()
can hang the calling script if either of these buffers fills up. See Python'ssubprocess
documentation for more information.