Difference between revisions of "Ultrasession in opensesame"

From Phonlab
Jump to navigationJump to search
 
(26 intermediate revisions by the same user not shown)
Line 1: Line 1:
The 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 run and control the acquisition utilities in inline scripts. A simple experiment proceeds like this:
+
The 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:
   
# variables related to data acquisition are set
+
# Set configuration variables related to data acquisition. These are the imaging parameters and the location to store results.
# the ultrasound acquisition system is initialized
+
# Initialize the ultrasound acquisition system.
# the experiment loops over a list of stimuli which are used to prompt the subject
+
# Loop over a list of stimuli which are used to prompt the subject.
## a preparatory prompt is shown to the subject
+
## Display a preparatory prompt to the subject.
## <code>ultrasession.py</code> is started and delays until the ultrasound system confirms that it is imaging
+
## Start data acquisition and wait until the ultrasound system confirms that it is imaging.
## a speaking prompt is shown to the subject. This prompt can be shown for a defined duration, or it can be displayed until the subject presses a key.
+
## 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.
## <code>ultrasession.py</code> is sent a signal to stop acquisition
+
## Send a signal to stop data acquisition.
  +
## Repeat the loop.
   
   
 
== Sample experiment ==
 
== Sample experiment ==
   
The steps shown above are followed in a sample experiment available on github. See the test experiment provided in [https://github.com/rsprouse/ultracomm/releases the latest release].
+
A sample experiment that contains the steps listed in the previous section is available in the <code>ultracomm</code> repository on github. See the test experiment provided in [https://github.com/rsprouse/ultracomm/releases the latest release].
   
The sample experiment relates to the steps as follows:
+
The sample experiment relates to the listed steps as follows:
   
* the <code>ultrasound_arguments</code> inline script defines variables related to data acquisition. The most important variables to change are <code>myparams</code>, which points to your imaging parameters file, and <code>datadir</code>, which is the parent directory for your timestamped acquisitions. In the Phonology Lab the datadir should be somewhere on the <code>U:</code> drive. Set <code>do_log</code> to <code>True</code> if you want <code>ultracomm</code> to produce a detailed log of its activity.
+
* The <code>ultrasound_arguments</code> inline script defines variables related to data acquisition, and you need to edit some variable definitions. The most important variables to change are <code>myparams</code>, which points to your imaging parameters file, and <code>datadir</code>, which is the parent directory for your timestamped acquisitions. In the Phonology Lab the data directory should be somewhere on the <code>U:</code> drive. Set <code>do_log</code> to <code>True</code> if you want <code>ultracomm</code> to produce a detailed log of its activity.
   
* the <code>init_ultrasound</code> inline script initializes the Ultrasonix system. You should not need to make any changes to this script.
 
   
 
* The <code>init_ultrasound</code> inline script initializes the Ultrasonix system. You should not need to make any changes to this script.
* the <code>stimuli</code> object contains a list of prompts to display to the subject. The prompts are provided in the <code>stimulus</code> variable, and it will be simplest if you give your variable the same name.
 
   
* the <code>display_word_prep</code> object shows the prepartory prompt to the subject. Customize a display for your own needs.
+
* The <code>stimuli</code> loop object contains a list of prompts to display to the subject. The prompts are provided in the <code>stimulus</code> variable, and to keep things simple you should give your prompt variable the same name.
   
 
* The <code>display_word_prep</code> object shows the preparatory prompt to the subject. Customize this display for your own needs.
* the <code>run_ultrasession</code> inline script starts <code>ultrasession.py</code> and waits until the ultrasound system has confirmed it is imaging. You should not need to change this script unless you did not name your prompt variable <code>stimulus</code>.
 
   
 
* The <code>run_ultrasession</code> inline script starts <code>ultrasession.py</code> 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 variable <code>stimulus</code>.
* the <code>display_word_while_acquiring</code> 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 <code>display_word_while_acquiring</code> 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 <code>stop_acquisition</code> inline script terminates <code>ultrasession.py</code>. You should not need to change this script.
 
  +
 
* The <code>stop_acquisition</code> inline script terminates <code>ultrasession.py</code>. You should not need to change this script.
  +
  +
== Troubleshooting ==
  +
  +
* Early versions of <code>ultracomm</code> and <code>ultrasession.py</code> 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 of <code>ultracomm</code> when used with an up-to-date <code>ultrasession.py</code> and following the inline scripts used in the sample experiment. Nevertheless, it is good form to check for instances of <code>sox</code> and <code>ultracomm</code> 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 press <code>Ctrl-Alt-Delete</code> and open the Task Manager. Check the Processes tab for instances of <code>rec.exe</code> (an alias for <code>sox.exe</code>) and <code>ultracomm.exe</code> 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 <code>.bpr</code> and <code>.bpr.idx.txt</code> files.
  +
  +
* There is an issue with <code>ultracomm</code> 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 by <code>ultracomm</code>. 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 <code>--av-hack</code> 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 <code>ultracomm</code> via <code>ultrasession.py</code>:
  +
  +
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.
  +
  +
* <code>ultracomm</code> and <code>ultrasession.py</code> can generate lots of text sent to STDOUT and STDERR, especially in verbose mode. As a result it is safer to use <code>communicate()</code> from the Python <code>subprocess</code> module rather than <code>wait()</code> when calling <code>ultrasession.py</code> or <code>ultracomm</code> because <code>wait()</code> can hang the calling script if either of these buffers fills up. See Python's <code>subprocess</code> documentation for more information.

Latest revision as of 14:44, 21 August 2015

The 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:

  1. Set configuration variables related to data acquisition. These are the imaging parameters and the location to store results.
  2. Initialize the ultrasound acquisition system.
  3. Loop over a list of stimuli which are used to prompt the subject.
    1. Display a preparatory prompt to the subject.
    2. Start data acquisition and wait until the ultrasound system confirms that it is imaging.
    3. 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.
    4. Send a signal to stop data acquisition.
    5. 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 are myparams, which points to your imaging parameters file, and datadir, which is the parent directory for your timestamped acquisitions. In the Phonology Lab the data directory should be somewhere on the U: drive. Set do_log to True if you want ultracomm 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 the stimulus 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 starts ultrasession.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 variable stimulus.
  • 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 terminates ultrasession.py. You should not need to change this script.

Troubleshooting

  • Early versions of ultracomm and ultrasession.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 of ultracomm when used with an up-to-date ultrasession.py and following the inline scripts used in the sample experiment. Nevertheless, it is good form to check for instances of sox and ultracomm 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 press Ctrl-Alt-Delete and open the Task Manager. Check the Processes tab for instances of rec.exe (an alias for sox.exe) and ultracomm.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 by ultracomm. 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 and ultrasession.py can generate lots of text sent to STDOUT and STDERR, especially in verbose mode. As a result it is safer to use communicate() from the Python subprocess module rather than wait() when calling ultrasession.py or ultracomm because wait() can hang the calling script if either of these buffers fills up. See Python's subprocess documentation for more information.