Software (ソフト)‎ > ‎Saplab‎ > ‎

Saplab Hacks

Useful tips

  • Showing all tables that a database "sap" has
    • sap.showTables() # Type this after constructing Saplab object "sap"
    • You will see something like:
      • 0 xxxx
      • 1 yyyy
      • ...
    • You can access the table "xxxx" as sap.tables[0], and "yyyy" as sap.tables[1].
  • Deleting a field in a database "sap", say "year", from a table
import mysqlinter
msql = mysqlinter.MysqlInter("sap", "root", "")

Developmental birdsong analysis

One effective way to look at developmental birdsong data is the age-based analysis. For this, we need upgrade a sap table by adding "year" and "age" fields into it.
  • Upgrade a sap table
    • sap.upgradeTable(bird, 2006, 2007, age=48)  # the numbers are startYear, endYear, startAge in recording
  • Or upgrade a sap table with date reconstruction from file names, if the table has fake values in "month" and "day" for some reasons
    • sap.upgradeTable(bird, 2006, 2007, 48, dateReconst=True)
  • After the upgrade, make a sapdat object again to set the new table data:
    • bird = sap.getdat("syll_g6_1_clustered")
We can analyze the development data more flexibly by using the upgraded table. Here are some examples.
  • Scatter plot of note-duration vs. mean_entropy at age=161
    • cond = "age=161 and duration>=20 and duration<=200"
    • d161 = sap.getdat(bird, "duration", cond)
    • e161 = sap.getdat(bird, "mean_entropy", cond)
    • scatter(d161, e161, marker="o", color="r", s=1) or hexbin(d161, e161)
  • Get inter-onset-interval data at age=48, and make its histogram
    • ioi48 = sap.getIXIdat(bird, "start_on", "age=48 and duration>=20 and duration<=200") 
    • hist(ioi48, bins=20, range=(0, 1000))
  • Make a 2D histogram of note-duration vs mean_entropy at age=161, and plot this
    • hist2d, drange, erange = histogram2d(e161, d161, bins=20, range=((-8, 0), (20, 200)))
    • pcolor(erange, drange, hist2d) #  (-8, 0) for mean_entropy range and (20, 200) for duration range
  • Information distance between the histogram of duration at age=48 and one at age=161
    • d48 = sap.getdat(bird, "duration", "age=48")
    • d161 = sap.getdat(bird, "duration", "age=161")
    • print sap.infoDistance(d48, d161, bins=20, range=(20, 200))
  • Developmental histogram of note-duration
    • fid, d = sap.devHistdat(bird, "duration", "duration>=20 and duration<=200")
    • hexbin(fid, d)
  • Write and read data into/from a text file
    • sap.writedat2d(fid, d, "temp.dat") # space-separated format
    • fid = sap.readdat("temp.dat", colNum=0)
    • d = sap.readdat("temp.dat", colNum=1)
  • Evaluation of duration development with information distance (JS-distance)
    • dist = sap.evalDev(bird, "duration", bins=20, range=(20, 200))
    • age = bird.ages
    • plot(age, dist)

Scripts for more complex anlaysis

With saplab, you can make Phython scripts when you do more complex analysis. Here's a simple example to draw many histograms of note-durations at a time
Put it into your working directory and type: 
  • python
or double-crick it if window. To make such scripts, you'll need basic knowledge of Python as well as matplotlib. There are lots of refereces on the web. Don't worry!

Currently available functions