Animations¶
flyvision.analysis.animations.imshow¶
Classes¶
flyvision.analysis.animations.imshow.Imshow ¶
Bases: Animation
Animates an array of images using imshow.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
images |
ndarray
|
Array of images to animate (n_samples, n_frames, height, width). |
required |
fig |
Optional[Figure]
|
Existing Figure instance or None. |
None
|
ax |
Optional[Axes]
|
Existing Axis instance or None. |
None
|
update |
bool
|
Whether to update the canvas after an animation step. Must be False if this animation is composed with others. |
True
|
figsize |
List[int]
|
Size of the figure. |
[1, 1]
|
sleep |
float
|
Time to sleep between frames. |
0.01
|
**kwargs |
Additional arguments passed to plt.imshow. |
{}
|
Attributes:
Name | Type | Description |
---|---|---|
fig |
Figure
|
The figure object. |
ax |
Axes
|
The axes object. |
kwargs |
dict
|
Additional arguments for imshow. |
update |
bool
|
Whether to update the canvas after each step. |
n_samples |
int
|
Number of samples in the images array. |
frames |
int
|
Number of frames in each sample. |
images |
ndarray
|
Array of images to animate. |
sleep |
float
|
Time to sleep between frames. |
img |
AxesImage
|
The image object created by imshow. |
Note
The images
array should have shape (n_samples, n_frames, height, width).
Source code in flyvision/analysis/animations/imshow.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
|
init ¶
init(frame=0)
Initialize the animation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
frame |
int
|
The initial frame to display. |
0
|
Source code in flyvision/analysis/animations/imshow.py
66 67 68 69 70 71 72 73 74 |
|
animate ¶
animate(frame)
Animate a single frame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
frame |
int
|
The frame number to animate. |
required |
Source code in flyvision/analysis/animations/imshow.py
76 77 78 79 80 81 82 83 84 85 86 87 88 |
|
flyvision.analysis.animations.hexscatter¶
Classes¶
flyvision.analysis.animations.hexscatter.HexScatter ¶
Bases: Animation
Regular hex-scatter animation.
For hexals not on a regular hex grid, use the function pad_to_regular_hex.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hexarray |
ndarray
|
Shape (n_samples, n_frames, 1, n_input_elements). |
required |
u |
Optional[List[float]]
|
List of u coordinates of elements to plot. |
None
|
v |
Optional[List[float]]
|
List of v coordinates of elements to plot. |
None
|
cranges |
Optional[List[float]]
|
Color minimal and maximal abs value (n_samples). |
None
|
vmin |
Optional[float]
|
Color minimal value. |
None
|
vmax |
Optional[float]
|
Color maximal value. |
None
|
fig |
Optional[Figure]
|
Existing Figure instance or None. |
None
|
ax |
Optional[Axes]
|
Existing Axis instance or None. |
None
|
batch_sample |
int
|
Batch sample to start from. |
0
|
cmap |
Union[str, Colormap]
|
Colormap for the hex-scatter. |
get_cmap('binary_r')
|
edgecolor |
Optional[str]
|
Edgecolor for the hexals. None for no edge. |
None
|
update_edge_color |
bool
|
Whether to update the edgecolor after an animation step. |
True
|
update |
bool
|
Whether to update the canvas after an animation step. Must be False if this animation is composed with others using AnimationCollector. |
False
|
label |
str
|
Label of the animation. Formatted with the current sample and frame number per frame. |
'Sample: {}\nFrame: {}'
|
labelxy |
Tuple[float, float]
|
Location of the label. |
(0.1, 0.95)
|
fontsize |
float
|
Fontsize. |
5
|
cbar |
bool
|
Display colorbar. |
True
|
background_color |
str
|
Background color. |
'none'
|
midpoint |
Optional[float]
|
Midpoint for diverging colormaps. |
None
|
Attributes:
Name | Type | Description |
---|---|---|
fig |
Figure
|
Matplotlib figure instance. |
ax |
Axes
|
Matplotlib axes instance. |
background_color |
str
|
Background color. |
hexarray |
ndarray
|
Hex array data. |
cranges |
Optional[List[float]]
|
Color ranges. |
vmin |
Optional[float]
|
Minimum value for color mapping. |
vmax |
Optional[float]
|
Maximum value for color mapping. |
midpoint |
Optional[float]
|
Midpoint for diverging colormaps. |
kwargs |
dict
|
Additional keyword arguments. |
batch_sample |
int
|
Batch sample index. |
cmap |
Colormap for the hex-scatter. |
|
update |
bool
|
Whether to update the canvas after an animation step. |
label |
str
|
Label template for the animation. |
labelxy |
Tuple[float, float]
|
Label position. |
label_text |
Text object for the label. |
|
n_samples |
int
|
Number of samples. |
frames |
int
|
Number of frames. |
extent |
int
|
Hex extent. |
edgecolor |
Optional[str]
|
Edgecolor for the hexals. |
update_edge_color |
bool
|
Whether to update the edgecolor. |
fontsize |
float
|
Font size. |
cbar |
bool
|
Whether to display colorbar. |
u |
List[float]
|
U coordinates of elements to plot. |
v |
List[float]
|
V coordinates of elements to plot. |
Source code in flyvision/analysis/animations/hexscatter.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
|
init ¶
init(frame=0)
Initialize the animation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
frame |
int
|
Frame number to initialize. |
0
|
Source code in flyvision/analysis/animations/hexscatter.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
|
animate ¶
animate(frame)
Animate a single frame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
frame |
int
|
Frame number to animate. |
required |
Source code in flyvision/analysis/animations/hexscatter.py
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
|
flyvision.analysis.animations.hexflow¶
Classes¶
flyvision.analysis.animations.hexflow.HexFlow ¶
Bases: Animation
Hexscatter of a color encoded flow field.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
flow |
Union[ndarray, Tensor]
|
Optic flow of shape (n_samples, n_frames, 2, n_input_elements). |
required |
fig |
Optional[Figure]
|
Existing Figure instance or None. |
None
|
ax |
Optional[Axes]
|
Existing Axis instance or None. |
None
|
batch_sample |
int
|
Batch sample to start from. |
0
|
cmap |
Colormap
|
Colormap for the hex-scatter. |
cm_uniform_2d
|
cwheel |
bool
|
Display colorwheel. |
False
|
cwheelxy |
Tuple[float, float]
|
Colorwheel offset x and y. |
()
|
label |
str
|
Label of the animation. |
'Sample: {}\nFrame: {}'
|
labelxy |
Tuple[float, float]
|
Normalized x and y location of the label. |
(0, 1)
|
update |
bool
|
Whether to update the canvas after an animation step. |
False
|
path |
Optional[str]
|
Path to save the animation to. |
None
|
figsize |
List[float]
|
Figure size. |
[2, 2]
|
fontsize |
float
|
Font size. |
5
|
background_color |
Literal['none']
|
Background color of the figure and axis. |
'none'
|
Attributes:
Name | Type | Description |
---|---|---|
fig |
Figure
|
Figure instance. |
ax |
Axes
|
Axis instance. |
background_color |
str
|
Background color of the figure and axis. |
batch_sample |
int
|
Batch sample to start from. |
kwargs |
dict
|
Additional keyword arguments. |
update |
bool
|
Whether to update the canvas after an animation step. Must be False if this animation is composed with others using AnimationCollector. |
cmap |
Colormap for the hex-scatter. |
|
cwheel |
bool
|
Display colorwheel. |
cwheelxy |
Tuple[float, float]
|
Colorwheel offset x and y. |
label |
str
|
Label of the animation. |
labelxy |
Tuple[float, float]
|
Normalized x and y location of the label. |
label_text |
Text
|
Text instance for the label. |
sm |
ScalarMappable
|
ScalarMappable instance for color mapping. |
fontsize |
float
|
Font size. |
figsize |
List[float, float]
|
Figure size. |
flow |
ndarray
|
Optic flow data. |
n_samples |
int
|
Number of samples in the flow data. |
frames |
int
|
Number of frames in the flow data. |
extent |
Tuple[float, float, float, float]
|
Extent of the hexagonal grid. |
Note
All kwargs are passed to ~flyvision.analysis.visualization.plots.hex_flow.
Source code in flyvision/analysis/animations/hexflow.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
|
init ¶
init(frame=0)
Initialize the animation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
frame |
int
|
Frame number to initialize with. |
0
|
Source code in flyvision/analysis/animations/hexflow.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
|
animate ¶
animate(frame)
Animate a single frame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
frame |
int
|
Frame number to animate. |
required |
Source code in flyvision/analysis/animations/hexflow.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
|
flyvision.analysis.animations.sintel¶
Classes¶
flyvision.analysis.animations.sintel.SintelSample ¶
Bases: AnimationCollector
Sintel-specific animation of input, target, and groundtruth data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lum |
ndarray
|
Input of shape (n_samples, n_frames, n_hexals). |
required |
target |
ndarray
|
Target of shape (n_samples, n_frames, n_dims, n_features). |
required |
prediction |
Optional[ndarray]
|
Optional prediction of shape (n_samples, n_frames, n_dims, n_features). |
None
|
target_cmap |
str
|
Colormap for the target (depth). |
colormaps['binary_r']
|
fontsize |
float
|
Font size for labels and titles. |
5
|
labelxy |
Tuple[float, float]
|
Normalized x and y location of the label. |
(-0.1, 1)
|
max_figure_height_cm |
float
|
Maximum figure height in centimeters. |
22
|
panel_height_cm |
float
|
Height of each panel in centimeters. |
3
|
max_figure_width_cm |
float
|
Maximum figure width in centimeters. |
18
|
panel_width_cm |
float
|
Width of each panel in centimeters. |
3.6
|
title1 |
str
|
Title for the input panel. |
'input'
|
title2 |
str
|
Title for the target panel. |
'target'
|
title3 |
str
|
Title for the prediction panel. |
'prediction'
|
Attributes:
Name | Type | Description |
---|---|---|
fig |
Figure
|
Matplotlib figure instance. |
axes |
List[Axes]
|
List of matplotlib axes instances. |
lum |
ndarray
|
Input data. |
target |
ndarray
|
Target data. |
prediction |
Optional[ndarray]
|
Prediction data. |
extent |
Tuple[float, float, float, float]
|
Extent of the hexagonal grid. |
n_samples |
int
|
Number of samples. |
frames |
int
|
Number of frames. |
update |
bool
|
Whether to update the canvas after an animation step. |
labelxy |
Tuple[float, float]
|
Normalized x and y location of the label. |
animations |
List
|
List of animation objects. |
batch_sample |
int
|
Batch sample to start from. |
Source code in flyvision/analysis/animations/sintel.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
|
flyvision.analysis.animations.activations¶
Classes¶
flyvision.analysis.animations.activations.StimulusResponse ¶
Bases: AnimationCollector
Hex-scatter animations for input and responses.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stimulus |
ndarray
|
Hexagonal input. |
required |
responses |
Union[ndarray, List[ndarray]]
|
Hexagonal activation of particular neuron type. |
required |
batch_sample |
int
|
Batch sample to start from. |
0
|
figsize_scale |
float
|
Scale factor for figure size. |
1
|
fontsize |
int
|
Font size for the plot. |
5
|
u |
Optional[List[int]]
|
List of u coordinates of neurons to plot. |
None
|
v |
Optional[List[int]]
|
List of v coordinates of neurons to plot. |
None
|
max_figure_height_cm |
float
|
Maximum figure height in centimeters. |
22
|
panel_height_cm |
float
|
Height of each panel in centimeters. |
3
|
max_figure_width_cm |
float
|
Maximum figure width in centimeters. |
18
|
panel_width_cm |
float
|
Width of each panel in centimeters. |
3.6
|
Attributes:
Name | Type | Description |
---|---|---|
stimulus |
ndarray
|
Numpy array of stimulus data. |
responses |
List[ndarray]
|
List of numpy arrays of response data. |
update |
bool
|
Flag to indicate if update is needed. |
n_samples |
int
|
Number of samples. |
frames |
int
|
Number of frames. |
fig |
Figure
|
Matplotlib figure object. |
axes |
List[Axes]
|
List of matplotlib axes objects. |
animations |
List[HexScatter]
|
List of HexScatter animation objects. |
batch_sample |
int
|
Batch sample index. |
Note
If u and v are not specified, all neurons are plotted.
Source code in flyvision/analysis/animations/activations.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
|
flyvision.analysis.animations.network¶
Classes¶
flyvision.analysis.animations.network.WholeNetworkAnimation ¶
Bases: Animation
Create an animation of the whole network activity.
This class generates an animation that visualizes the activity of a neural network, including input, rendering, predicted flow, and target flow if provided.
Attributes:
Name | Type | Description |
---|---|---|
fig_backbone |
WholeNetworkFigure
|
The backbone figure for the animation. |
fig |
Figure
|
The main figure object. |
ax_dict |
dict
|
Dictionary of axes for different components of the animation. |
batch_sample |
int
|
The index of the batch sample to animate. |
kwargs |
dict
|
Additional keyword arguments. |
update |
bool
|
Whether to update the figure during animation. |
label |
str
|
Label format string for the animation. |
labelxy |
tuple[float, float]
|
Position of the label. |
fontsize |
int
|
Font size for labels. |
cmap |
Colormap
|
Colormap for the animation. |
n_samples |
int
|
Number of samples in the responses. |
frames |
int
|
Number of frames in the responses. |
responses |
LayerActivity
|
Layer activity data. |
cartesian_input |
Optional[Any]
|
Cartesian input data. |
rendered_input |
Optional[Any]
|
Rendered input data. |
predicted_flow |
Optional[Any]
|
Predicted flow data. |
target_flow |
Optional[Any]
|
Target flow data. |
color_norm_per |
str
|
Color normalization method. |
voltage_axes |
list
|
List of voltage axes for different cell types. |
Source code in flyvision/analysis/animations/network.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
|
init ¶
init(frame=0)
Initialize the animation components.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
frame |
int
|
The initial frame number. |
0
|
Source code in flyvision/analysis/animations/network.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
|
animate ¶
animate(frame)
Update the animation for a given frame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
frame |
int
|
The current frame number. |
required |
Source code in flyvision/analysis/animations/network.py
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
|
flyvision.analysis.animations.animations¶
Classes¶
flyvision.analysis.animations.animations.Animation ¶
Base class for animations.
Subclasses must implement init
and animate
methods.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
Optional[Union[str, Path]]
|
Path to save the animation. |
None
|
fig |
Optional[Figure]
|
Existing Figure instance or None. |
None
|
suffix |
str
|
Suffix for the animation path. |
'{}'
|
Attributes:
Name | Type | Description |
---|---|---|
fig |
Figure
|
Figure instance for the animation. |
update |
bool
|
Whether to update the canvas after each animation step. |
batch_sample |
int
|
Sample to animate. |
frames |
int
|
Number of frames in the animation. |
n_samples |
int
|
Number of samples in the animation. |
path |
Path
|
Path to save the animation. |
Source code in flyvision/analysis/animations/animations.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 |
|
init ¶
init(frame=0)
Initialize the animation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
frame |
int
|
Initial frame number. |
0
|
Raises:
Type | Description |
---|---|
NotImplementedError
|
If not implemented by subclass. |
Source code in flyvision/analysis/animations/animations.py
55 56 57 58 59 60 61 62 63 64 |
|
animate ¶
animate(frame)
Animate a single frame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
frame |
int
|
Frame number to animate. |
required |
Raises:
Type | Description |
---|---|
NotImplementedError
|
If not implemented by subclass. |
Source code in flyvision/analysis/animations/animations.py
66 67 68 69 70 71 72 73 74 75 |
|
update_figure ¶
update_figure(clear_output=True)
Update the figure canvas.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
clear_output |
bool
|
Whether to clear the previous output. |
True
|
Source code in flyvision/analysis/animations/animations.py
77 78 79 80 81 82 83 84 85 86 87 88 |
|
animate_save ¶
animate_save(frame, dpi=100)
Update the figure to the given frame and save it.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
frame |
int
|
Frame number to animate and save. |
required |
dpi |
int
|
Dots per inch for the saved image. |
100
|
Source code in flyvision/analysis/animations/animations.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
|
animate_in_notebook ¶
animate_in_notebook(frames='all', samples='all', repeat=1)
Play animation within a Jupyter notebook.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
frames |
Union[str, Iterable]
|
Frames to animate. |
'all'
|
samples |
Union[str, Iterable]
|
Samples to animate. |
'all'
|
repeat |
int
|
Number of times to repeat the animation. |
1
|
Source code in flyvision/analysis/animations/animations.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
|
plot ¶
plot(sample, frame)
Plot a single frame for a specific sample.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sample |
int
|
Sample number to plot. |
required |
frame |
int
|
Frame number to plot. |
required |
Source code in flyvision/analysis/animations/animations.py
192 193 194 195 196 197 198 199 200 201 202 203 204 |
|
to_vid ¶
to_vid(
fname,
frames="all",
dpi=100,
framerate=30,
samples="all",
delete_if_exists=False,
source_path=None,
dest_path=None,
type="webm",
)
Animate, save individual frames, and convert to video using ffmpeg.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fname |
str
|
Output filename. |
required |
frames |
Union[str, Iterable]
|
Frames to animate. |
'all'
|
dpi |
int
|
Dots per inch for saved images. |
100
|
framerate |
int
|
Frame rate of the output video. |
30
|
samples |
Union[str, Iterable]
|
Samples to animate. |
'all'
|
delete_if_exists |
bool
|
Whether to delete existing output file. |
False
|
source_path |
Optional[Union[str, Path]]
|
Source path for temporary files. |
None
|
dest_path |
Optional[Union[str, Path]]
|
Destination path for the output video. |
None
|
type |
Literal['mp4', 'webm']
|
Output video type. |
'webm'
|
Source code in flyvision/analysis/animations/animations.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 |
|
convert ¶
convert(
fname,
delete_if_exists=False,
framerate=30,
source_path=None,
dest_path=None,
type="mp4",
)
Convert PNG files in the animations directory to video.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fname |
str
|
Output filename. |
required |
delete_if_exists |
bool
|
Whether to delete existing output file. |
False
|
framerate |
int
|
Frame rate of the output video. |
30
|
source_path |
Optional[Union[str, Path]]
|
Source path for input PNG files. |
None
|
dest_path |
Optional[Union[str, Path]]
|
Destination path for the output video. |
None
|
type |
Literal['mp4', 'webm']
|
Output video type. |
'mp4'
|
Source code in flyvision/analysis/animations/animations.py
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 |
|
flyvision.analysis.animations.animations.AnimationCollector ¶
Bases: Animation
Collects Animations and updates all axes at once.
Subclasses must populate the animations
attribute with Animation objects
and adhere to the Animation interface.
Attributes:
Name | Type | Description |
---|---|---|
animations |
list[Animation]
|
List of Animation objects to collect. |
Source code in flyvision/analysis/animations/animations.py
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 |
|
init ¶
init(frame=0)
Initialize all collected animations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
frame |
int
|
Initial frame number. |
0
|
Source code in flyvision/analysis/animations/animations.py
380 381 382 383 384 385 386 387 388 |
|
animate ¶
animate(frame)
Animate all collected animations for a single frame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
frame |
int
|
Frame number to animate. |
required |
Source code in flyvision/analysis/animations/animations.py
390 391 392 393 394 395 396 397 398 399 |
|
__setattr__ ¶
__setattr__(key, val)
Set attributes for all Animation objects at once.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key |
str
|
Attribute name to set. |
required |
val |
Any
|
Value to set for the attribute. |
required |
Source code in flyvision/analysis/animations/animations.py
401 402 403 404 405 406 407 408 409 410 411 |
|
Functions¶
flyvision.analysis.animations.animations.convert ¶
convert(
directory, dest, framerate, delete_if_exists, type="mp4"
)
Convert PNG files in directory to MP4 or WebM.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
directory |
Union[str, Path]
|
Source directory containing PNG files. |
required |
dest |
Union[str, Path]
|
Destination path for the output video. |
required |
framerate |
int
|
Frame rate of the output video. |
required |
delete_if_exists |
bool
|
Whether to delete existing output file. |
required |
type |
Literal['mp4', 'webm']
|
Output video type. |
'mp4'
|
Raises:
Type | Description |
---|---|
ValueError
|
If unsupported video type is specified. |
FileExistsError
|
If output file exists and delete_if_exists is False. |
Source code in flyvision/analysis/animations/animations.py
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 |
|
flyvision.analysis.animations.traces¶
Classes¶
flyvision.analysis.animations.traces.Trace ¶
Bases: Animation
Animates a trace.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
trace |
ndarray
|
Trace of shape (n_samples, n_frames). |
required |
dt |
float
|
Time step in seconds for accurate time axis. |
1
|
fig |
Optional[Figure]
|
Existing Figure instance or None. |
None
|
ax |
Optional[Axes]
|
Existing Axis instance or None. |
None
|
update |
bool
|
Whether to update the canvas after an animation step. Must be False if this animation is composed with others. |
False
|
color |
Optional[Union[str, ndarray]]
|
Optional color of the trace. |
None
|
title |
str
|
Optional title of the animation. |
''
|
batch_sample |
int
|
Batch sample to start from. |
0
|
dynamic_ax_lims |
bool
|
Whether the ax limits of the trace are animated. |
True
|
ylims |
Optional[List[Tuple[float, float]]]
|
Static y-limits for the trace for each sample. |
None
|
ylabel |
str
|
Optional y-label of the trace. |
''
|
contour |
Optional[ndarray]
|
Optional background contour for trace in x direction. |
None
|
label |
str
|
Label of the animation. Formatted with the current sample and frame number. |
'Sample: {}\nFrame: {}'
|
labelxy |
Tuple[float, float]
|
Normalized x and y location of the label. |
(0.1, 0.95)
|
fontsize |
float
|
Fontsize. |
5
|
figsize |
Tuple[float, float]
|
Figure size. |
(2, 2)
|
Attributes:
Name | Type | Description |
---|---|---|
trace |
ndarray
|
Trace data. |
n_samples |
int
|
Number of samples. |
frames |
int
|
Number of frames. |
fig |
Optional[Figure]
|
Figure instance. |
ax |
Optional[Axes]
|
Axes instance. |
update |
bool
|
Update flag. |
color |
Optional[Union[str, ndarray]]
|
Color of the trace. |
label |
str
|
Label format string. |
labelxy |
Tuple[float, float]
|
Label position. |
label_text |
Label text object. |
|
batch_sample |
int
|
Current batch sample. |
fontsize |
float
|
Font size. |
dynamic_ax_lims |
bool
|
Dynamic axis limits flag. |
ylabel |
str
|
Y-axis label. |
ylims |
Optional[List[Tuple[float, float]]]
|
Y-axis limits. |
title |
str
|
Plot title. |
contour |
Optional[ndarray]
|
Contour data. |
contour_lims |
Optional[ndarray]
|
Contour limits. |
dt |
float
|
Time step. |
figsize |
Tuple[float, float]
|
Figure size. |
Source code in flyvision/analysis/animations/traces.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
|
init ¶
init(frame=0)
Initialize the animation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
frame |
int
|
Starting frame number. |
0
|
Source code in flyvision/analysis/animations/traces.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
|
animate ¶
animate(frame)
Animate a single frame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
frame |
int
|
Current frame number. |
required |
Source code in flyvision/analysis/animations/traces.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
|
flyvision.analysis.animations.traces.MultiTrace ¶
Bases: Animation
Animates multiple traces in single plot.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
trace |
ndarray
|
Trace of shape (n_samples, n_frames, n_traces). |
required |
dt |
float
|
Time step in seconds. |
1
|
fig |
Optional[Figure]
|
Existing Figure instance or None. |
None
|
ax |
Optional[Axes]
|
Existing Axis instance or None. |
None
|
update |
bool
|
Whether to update the figure after each frame. |
False
|
legend |
Optional[List[str]]
|
Legends of the traces. |
None
|
colors |
Optional[List[Union[str, ndarray]]]
|
Optional colors of the traces. |
None
|
title |
str
|
Optional title of the animation. |
''
|
batch_sample |
int
|
Batch sample to start from. |
0
|
dynamic_ax_lims |
bool
|
Whether the ax limits of the trace are animated. |
True
|
ylims |
Optional[List[Tuple[float, float]]]
|
Static y-limits for the trace for each sample. |
None
|
ylabel |
str
|
Optional y-label of the trace. |
''
|
contour |
Optional[ndarray]
|
Optional background contour for trace in x direction. |
None
|
label |
str
|
Label of the animation. Formatted with the current sample and frame number. |
'Sample: {}\nFrame: {}'
|
labelxy |
Tuple[float, float]
|
Normalized x and y location of the label. |
(0.1, 0.95)
|
fontsize |
float
|
Fontsize. |
5
|
path |
Optional[str]
|
Path object to save animation to. |
None
|
Attributes:
Name | Type | Description |
---|---|---|
trace |
ndarray
|
Trace data. |
n_samples |
int
|
Number of samples. |
frames |
int
|
Number of frames. |
n_trace |
int
|
Number of traces. |
fig |
Optional[Figure]
|
Figure instance. |
ax |
Optional[Axes]
|
Axes instance. |
update |
bool
|
Update flag. |
colors |
Optional[List[Union[str, ndarray]]]
|
Colors of the traces. |
label |
str
|
Label format string. |
labelxy |
Tuple[float, float]
|
Label position. |
label_text |
Label text object. |
|
legend |
Optional[List[str]]
|
Legend labels. |
batch_sample |
int
|
Current batch sample. |
fontsize |
float
|
Font size. |
dynamic_ax_lims |
bool
|
Dynamic axis limits flag. |
ylabel |
str
|
Y-axis label. |
ylims |
Optional[List[Tuple[float, float]]]
|
Y-axis limits. |
title |
str
|
Plot title. |
contour |
Optional[ndarray]
|
Contour data. |
dt |
float
|
Time step. |
Source code in flyvision/analysis/animations/traces.py
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 |
|
init ¶
init(frame=0)
Initialize the animation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
frame |
int
|
Starting frame number. |
0
|
Source code in flyvision/analysis/animations/traces.py
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 |
|
animate ¶
animate(frame)
Animate a single frame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
frame |
int
|
Current frame number. |
required |
Source code in flyvision/analysis/animations/traces.py
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 |
|