Tap the full potential of SAP

is an interface that mediates SAP (Sound Analysis Pro) data table in
MySQL, PyLab (= IPython + NumPy + SciPy + Matplotlib), and R. SAP is a powerful analytical engine for bioacoustics developed by Dr. Tchernichovski et al., measuring acoustic features from sequential sound and making its data table into MySQL. Using saplab, you can handle SAP table, and visualize data with PyLab and study statistics with R. In addition, this provides a number of useful functions for analyzing bioacoustic data. Saplab is written in Python, one of the best glue languages, so you can do anything you want by using and extending this with Python at every platform. Saplab is currently under construction, but a beta version is available now. This beta version allows us to interact with SAP table, analyzing data using PyLab (R will be availble in the next version).



  • 2009.06.04: Date reconstruction method improved (ver. 20090604) New!!
  • 2009.05.22:   Bug fix release (ver. 20090522)
    • Saplab beta ver. 20090515 or olders have a problem handing SAP Live format files.
  • 2009.05.15:   A new function, infoDistance2d was introduced (ver. 20090515)
  • 2009.05.11:   Saplab beta release (ver. 20090511)


Saplab requires Python and Python tools for scientific computation as follows:
  • IPython: a powerful interactive shell
  • NumPy: a fundamental package of multi-dimensional arrays and its manipulation
  • SciPy: a collection of scientific and engineering tools that builds on NumPy
  • Matplotlib: a MATLAB-like plotting library
  • wxPython: a cross-platform GUI toolkit
  • MySQL-Python: an interface to MySQL
While there are lots of ways to setup these (e.g., apt-get, emerge, and port), the easiest way is EPD, Enthought Python Distribution. This includes all the libraries you need (and more), and is free for educational use. Saplab is a correction of Python programs, distributed as zip file. Whenever you work with saplab, MySQL must be running.

To sum, all you need is download and setup the programs listed bellow:
  • EPD: Use the installer and see README
  • Saplab (ver. 20090604): Unzip and put *.py in your working folder

Getting started

Suppose we have a table "syll_g6_1_clustered" in a database "sap," and that root user in MySQL is available without password.

  • Start up IPython
    • Windows:
      Click PyLab icon and go to your working folder (e.g., "Birdsong" in C drive)
      cd C:¥Birdsong

    • Mac and Linux:
      Go to your working folder, and type
      ipython -pylab
  • Import Saplab library, make a Saplab object (e.g., sap)
    • import saplab
    • sap = saplab.Saplab()
      ※This is the same as sap = saplab.Saplab(db="sap",user="root",passwd="")
      Different database, user, password are available by using the above arguments.
  • Make a Sapdata object (e.g., bird) and set the table data into it
    • bird = sap.setTable("syll_g6_1_clustered")
Now you're ready to handle data in the table. Here's how to access the data.
  • Show available fields in bird object (e.g., syll_g6_1_clustered)
    • sap.showFields(bird) or  bird.fields
  • Get all the duration data at once and print it
    • print sap.getdat(bird, "duration")
  • Get duration data that meets 20<= duration <= 200 and make a histogram
    • d = sap.getdat(bird, "duration", "duration>=20 and duration<=200")
    • hist(d, bins=20)
  • Plot recnum vs. mean_entropy data in the file 0601_January_28_2007_16_06_02.wav
    • cond = "file_name='0601_January_28_2007_16_06_02.wav'"
    • n = sap.getdat(bird, "recnum", cond)
    • e = sap.getdat(bird, "mean_entropy", cond)
    • plot(n,e)


If you have questions, comments, and bug reports, please email to:


サブページ (2): Saplab Hacks Saplab script example