Analysis codebase for An experimental method for evoking and characterizing dynamic color patterning of cuttlefish during prey capture
This folder contains the entire codebase necessary to replicate the analysis described in the paper "An experimental method for evoking and characterizing dynamic color patterning of cuttlefish during prey capture" by Danbee Kim, Kendra Buresch, Roger Hanlon, and Adam R. Kampff.
Download the full primary dataset from the Harvard Dataverse.
This analysis workflow uses two metrics for characterising the "Tentacle Shot Pattern" (TSP), a very brief and highly conspicuous body pattern displayed by cuttlefish just after "tentacles go ballistic" (TGB) during prey capture events, observed both in the lab and in the wild.
-
"Granularity" measure: For each frame, filter the image at seven octave-wide, isotropic spatial frequency bands (denoted as Frequency Band 0-6, frequency band 0 being the largest spatial frequency and 6 being the smallest). The sum of the squared pixel values in the resulting filtered images gives the total energy of the original video frame in that particular frequency band. This analysis produces seven timeseries of numeric values, one for each frequency band, which describe the body pattern during each tentacle shot. This is a modified version of a granularity analysis method originally developed to discriminate between uniform/stipple, mottle and disruptive patterns in still images (for details, see Barbosa, Alexandra, et al. "Cuttlefish camouflage: the effects of substrate contrast and size in evoking uniform, mottle or disruptive body patterns." Vision research 48.10 (2008): 1242-1253.).
-
"Edginess" measure: For each frame, detect high-contrast edges using the Canny Edge Detector computer vision algorithm and sum the number of pixels involved in the detected edges in order to generate an “edginess score” for each frame. This results in a timeseries of numeric values which describe the body pattern during each tentacle shot. Each timeseries is smoothed in order to remove noise from the overhead fluorescent lighting in the experiment room (which generated moving waves of “flicker” in the video), by applying a Savitzky–Golay filter with a smoothing window of 250 milliseconds and using a third order polynomial for fitting (Python,
scipy.signal library
, functionsavgol_filter
).
Our paper focuses on the "granularity" measure, and uses the "edginess" measure as an independent verification of the results from the "granularity" measure.
-
Download the .csv files containing the timestamps of various "moments of interest" (MOIs) during the experimental sessions.
-
Open file
CuttleShuttle_01_probabilityMOI.py
. Modify variabledataset_dir
to point to the folder location where you saved the full experimental dataset (or just the.csv
files). Modify the variableplots_dir
to a folder where you would like to save the output of this script (.png
image files). Save the file, then open a development environment set up to run python scripts, navigate to this folder, then run this script by typingpython CuttleShuttle_01_probabilityMOI.py --MOI catches
. Typepython CuttleShuttle_01_probabilityMOI.py -h
for more info/options. Note that this script will generate a logfile namedprobabilityMOIs_[today's date and time].log
.
-
Download the manually cropped and aligned videos of all tentacle shots made during the Cuttle Shuttle experiment (referred to as "TGB videos") from the Harvard Dataverse.
-
Open file
CuttleShuttle_02_ProcessCuttlePython_genBandEnergies.py
and find functionload_data
(line 47). Modify variablevideo_dir
to point to the folder location where you saved the TGB videos. Modify variableplots_dir
to point to a folder where you would like to save the output of this script (.png
and.npy
files). Save the file, then open a development environment set up to run python scripts, navigate to this folder, then run this script by typingpython CuttleShuttle_02_ProcessCuttlePython_genBandEnergies.py
. Typepython CuttleShuttle_02_ProcessCuttlePython_genBandEnergies.py -h
for more info/options. Note that this script will generate a logfile namedprocess_cuttle_python_01_[today's date and time].log
. -
Open file
CuttleShuttle_02_CannyEdgeDetector.bonsai
using the Bonsai visual language environment (to download visit the official Bonsai website). Click the node calledGetFiles
and modify thePath
parameter to point to the folder location where you saved the TGB videos. Click theStart
button in the upper left of the program window. This will generate.csv
files in the same folder as the one which contains the TGB videos. Files ending inCannyCount.csv
contain an edginess score for each frame of the TGB videos; files ending inPixelSum.csv
contain the sum of all pixels for each frame of the TGB videos. -
Open file
CuttleShuttle_03_analyseCatchVMiss.py
and find functionload_data
(line 55). Modify variabledata_dir_percentChange
to point to the folder location where you saved the output ofCuttleShuttle_02_ProcessCuttlePython_genBandEnergies.py
. Modify variabledata_dir_canny
to point to the folder location where you saved the output ofCuttleShuttle_02_CannyEdgeDetector.bonsai
. Modify variableplots_dir
to point to a folder where you would like to save the output of this script (.png
files). WARNING: This script executes a non-parametric statistical test called a "shuffle test" or "permutation test", and will run for a few hours. Save the file, then run this script in interactive python mode by typingpython -i CuttleShuttle_03_analyseCatchVMiss.py
. Typepython CuttleShuttle_03_analyseCatchVMiss.py -h
for more info/options. Note that this script will generate a logfile namedprocess_cuttle_python_03_[today's date and time].log
. -
Open file
CuttleShuttle_04_onsetTSP.py
and find functionload_data
(line 54). Modify variabledata_dir
to point to the folder location where you saved the output ofCuttleShuttle_02_ProcessCuttlePython_genBandEnergies.py
. Modify variableplots_dir
to point to a folder where you would like to save the output of this script (.png
files). Save the file, then run this script by typingpython CuttleShuttle_04_onsetTSP.py
. Typepython CuttleShuttle_04_onsetTSP.py -h
for more info/options. Note that this script will generate a logfile namedprocess_cuttle_python_04_[today's date and time].log
.