Simulate zebrafish swim from tail angle tracking data
Project description
Zebrafish Tail Animator
Python toolbox to transform zebrafish tracking data to tail animations
Description
zf_animator
is a Python package used to create visualisation of how swimming data looks from high-speed tracking data.
The typical data used should be the tail angle along segments of the tail.
The package will convert these tail angles to x- y- coordinates, and interpolate many more points along the range of tracked tail segments.
These sets of coordinates will then transform slices of the zebrafish image, producing a stack of .png files that can be rendered into a mp4 file.
Animations of the larval zebrafish postures are warped using a piece wise affine transformation using the interpolated x-y coordinates.
Package installation
This package can be installed via pip
pip install fish-simulator
Alternatively, you can download and locally install the package.
cd path/to/save/package
git clone clone-latest-tag git@github.com:ThomasMullen/fish_simulator.git
cd ./fish_simulator
python -m build
pip install -e .
Requires ffmpeg
Installation instructions
To convert the .png
files to an .mp4
animation requires ffmpeg
to be installed on the running computer.
This can be install in Ubuntu in the terminal:
sudo apt install ffmpeg
Or with OS X can be installed:
brew install ffmpeg
Check it is installed by running which ffmpeg
in the terminal. More details can be found here.
Dependencies
Default Fish animation
Default Fish image
Example
Simple illustrative plot of posture
This displays a virtual structure of the fish posture. There are several plots you can perform, with the option of converting to a video.
These functions are plot_bout_elapse
, plot_skeletal_postures
, and plot_skeletal_postures_with_trace
. There are passed through the run
function. Here is an example.
import numpy as np
from fish_simulator import run
data_arr = np.load("fish_simulator/test/fixtures/swim01.npy")
run(
data_arr,
plot_func=plot_skeletal_postures_with_trace,
dir="path/to/dir/plts",
vid_fp="path/to/video/anim.mp4",
line_wid=1
)
Your browser does not support the video tag.
Real larval zebrafish simulation plot
There are two plotting functions using the real larvae: plot_tail_image
and plot_tail_image_with_trace
.
import numpy as np
from fish_simulator import run, plot_tail_image_with_trace, plot_tail_image
run(
data_arr,
plot_func=plot_tail_image_with_trace,
# plot_func=plot_tail_image,
dir="path/to/dir/plts",
vid_fp="path/to/video/anim.mp4",
n_intp_segs=40,
img_kwargs={"body_to_tail_mm": 156.3, "tail_to_tail_mm": -181.3},
line_wid=1,
)
Your browser does not support the video tag.
Generate a simulation of the fish tail posture
from fish_simulator.simulator import make_posture_simulation, make_video
make_posture_simulation(data=tail_angle_data, n_segments=30, png_dir="dir/to/save/png_files")
make_video(png_dir="dir/to/save/png_files", vid_fname="file/path/of/generated_vid.mp4")
Key Functions
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for fish_simulator-0.1.9-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a18e7192c5f01f072d4f16e05bcd4a0a295984848301d67d1d5d031c03e67bd |
|
MD5 | 8d4c635cec3b754b2291d458e01ef3ec |
|
BLAKE2b-256 | 32404e4e9301734747a1c6e729989991d662069631a5809cb22d3bf0337f0c89 |