Rendering¶
BoxEye¶
flyvision.datasets.rendering.eye.BoxEye ¶
BoxFilter to produce an array of hexals matching the photoreceptor array.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
extent |
int
|
Radius, in number of receptors, of the hexagonal array. |
15
|
kernel_size |
int
|
Photon collection radius, in pixels. |
13
|
Attributes:
Name | Type | Description |
---|---|---|
extent |
int
|
Radius, in number of receptors, of the hexagonal array. |
kernel_size |
int
|
Photon collection radius, in pixels. |
receptor_centers |
Tensor
|
Tensor of shape (hexals, 2) containing the y, x coordinates of the hexal centers. |
hexals |
int
|
Number of hexals in the array. |
min_frame_size |
Tensor
|
Minimum frame size to contain the hexal array. |
pad |
Tuple[int, int, int, int]
|
Padding to apply to the frame before convolution. |
conv |
Conv2d
|
Convolutional box filter to apply to the frame. |
Source code in flyvision/datasets/rendering/eye.py
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 |
|
__call__ ¶
__call__(sequence, ftype='mean', hex_sample=True)
Apply a box kernel to all frames in a sequence.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sequence |
Tensor
|
Cartesian movie sequences of shape (samples, frames, height, width). |
required |
ftype |
Literal['mean', 'sum', 'median']
|
Filter type. |
'mean'
|
hex_sample |
bool
|
If False, returns filtered cartesian sequences. |
True
|
Returns:
Type | Description |
---|---|
Tensor
|
torch.Tensor: Shape (samples, frames, 1, hexals) if hex_sample is True, otherwise (samples, frames, height, width). |
Source code in flyvision/datasets/rendering/eye.py
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 |
|
hex_render ¶
hex_render(sequence)
Sample receptor locations from a sequence of cartesian frames.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sequence |
Tensor
|
Cartesian movie sequences of shape (samples, frames, height, width). |
required |
Returns:
Type | Description |
---|---|
Tensor
|
torch.Tensor: Shape (samples, frames, 1, hexals). |
Note
Resizes the sequence to the minimum frame size if necessary.
Source code in flyvision/datasets/rendering/eye.py
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
|
illustrate ¶
illustrate()
Illustrate the receptive field centers and the hexagonal sampling.
Returns:
Type | Description |
---|---|
Figure
|
plt.Figure: Matplotlib figure object. |
Source code in flyvision/datasets/rendering/eye.py
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 |
|
HexEye¶
flyvision.datasets.rendering.eye.HexEye ¶
Hexagonal eye model for more precise rendering.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_ommatidia |
int
|
Number of ommatidia in the eye. Must currently fill a regular hex grid. |
721
|
ppo |
int
|
Pixels per ommatidium. |
25
|
monitor_height_px |
Optional[int]
|
Monitor height in pixels. |
None
|
monitor_width_px |
Optional[int]
|
Monitor width in pixels. |
None
|
device |
device
|
Computation device. |
device
|
dtype |
dtype
|
Data type for computations. |
float16
|
Attributes:
Name | Type | Description |
---|---|---|
monitor_width_px |
int
|
Monitor width in pixels. |
monitor_height_px |
int
|
Monitor height in pixels. |
is_inside |
Tensor
|
Boolean mask for pixels inside hexagons. |
n_ommatidia |
int
|
Number of ommatidia in the eye. |
omm_width_rad |
float
|
Ommatidium width in radians. |
omm_height_rad |
float
|
Ommatidium height in radians. |
ppo |
int
|
Pixels per ommatidium. |
n_hex_circfer |
float
|
Number of hexagons in the circumference. |
device |
device
|
Computation device. |
dtype |
dtype
|
Data type for computations. |
Source code in flyvision/datasets/rendering/eye.py
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 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 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 |
|
__call__ ¶
__call__(stim, mode='mean', n_chunks=1)
Process stimulus through the hexagonal eye model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stim |
Tensor
|
Input stimulus tensor (n_frames, height, width) or (n_frames, height * width). Height and width must correspond to the monitor size. |
required |
mode |
Literal['mean', 'median', 'sum']
|
Processing mode. |
'mean'
|
n_chunks |
int
|
Number of chunks to process the stimulus in. |
1
|
Returns:
Type | Description |
---|---|
Tensor
|
torch.Tensor: Processed stimulus. |
Source code in flyvision/datasets/rendering/eye.py
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 |
|
render_bar ¶
render_bar(
bar_width_rad,
bar_height_rad,
bar_loc_theta,
bar_loc_phi,
n_bars,
bar_intensity,
bg_intensity,
moving_angle,
cartesian=False,
mode="mean",
)
Render a bar stimulus.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bar_width_rad |
float
|
Width of bars in radians. |
required |
bar_height_rad |
float
|
Height of bars in radians. |
required |
bar_loc_theta |
float
|
Horizontal location of bars in radians. |
required |
bar_loc_phi |
float
|
Vertical location of bars in radians. |
required |
n_bars |
int
|
Number of bars. |
required |
bar_intensity |
float
|
Intensity of the bar. |
required |
bg_intensity |
float
|
Intensity of the background. |
required |
moving_angle |
float
|
Rotation angle in degrees. |
required |
cartesian |
bool
|
If True, return cartesian coordinates. |
False
|
mode |
Literal['mean', 'median', 'sum']
|
Processing mode. |
'mean'
|
Returns:
Type | Description |
---|---|
Union[ndarray, Tensor]
|
Union[np.ndarray, torch.Tensor]: Generated bar stimulus. |
Source code in flyvision/datasets/rendering/eye.py
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 412 413 414 415 416 417 418 419 420 421 422 |
|
render_grating ¶
render_grating(
period_rad,
phase_rad,
intensity,
bg_intensity,
moving_angle,
width_rad=None,
height_rad=None,
cartesian=False,
mode="mean",
)
Render a grating stimulus.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
period_rad |
float
|
Period of the grating in radians. |
required |
phase_rad |
float
|
Phase of the grating in radians. |
required |
intensity |
float
|
Intensity of the grating. |
required |
bg_intensity |
float
|
Intensity of the background. |
required |
moving_angle |
float
|
Rotation angle in degrees. |
required |
width_rad |
Optional[float]
|
Width of the grating in radians. |
None
|
height_rad |
Optional[float]
|
Height of the grating in radians. |
None
|
cartesian |
bool
|
If True, return cartesian coordinates. |
False
|
mode |
Literal['mean', 'median', 'sum']
|
Processing mode. |
'mean'
|
Returns:
Type | Description |
---|---|
Union[ndarray, Tensor]
|
Union[np.ndarray, torch.Tensor]: Generated grating stimulus. |
Source code in flyvision/datasets/rendering/eye.py
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 |
|
render_grating_offsets ¶
render_grating_offsets(
period_rad,
intensity,
bg_intensity,
moving_angle,
width_rad=None,
height_rad=None,
cartesian=False,
mode="mean",
)
Render grating stimuli with a range of offsets.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
period_rad |
float
|
Period of the grating in radians. |
required |
intensity |
float
|
Intensity of the grating. |
required |
bg_intensity |
float
|
Intensity of the background. |
required |
moving_angle |
float
|
Rotation angle in degrees. |
required |
width_rad |
Optional[float]
|
Width of the grating in radians. |
None
|
height_rad |
Optional[float]
|
Height of the grating in radians. |
None
|
cartesian |
bool
|
If True, return cartesian coordinates. |
False
|
mode |
Literal['mean', 'median', 'sum']
|
Processing mode. |
'mean'
|
Returns:
Type | Description |
---|---|
Union[ndarray, Tensor]
|
Union[np.ndarray, torch.Tensor]: Generated grating stimuli with offsets. |
Source code in flyvision/datasets/rendering/eye.py
478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 |
|
render_offset_bars ¶
render_offset_bars(
bar_width_rad,
bar_height_rad,
n_bars,
offsets,
bar_intensity,
bg_intensity,
moving_angle,
bar_loc_horizontal=np.radians(90),
bar_loc_vertical=np.radians(90),
mode="mean",
)
Render bars with a range of offsets.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bar_width_rad |
float
|
Width of bars in radians. |
required |
bar_height_rad |
float
|
Height of bars in radians. |
required |
n_bars |
int
|
Number of bars. |
required |
offsets |
List[float]
|
Offsets of bars wrt. the center in radians. |
required |
bar_intensity |
float
|
Intensity of the bar. |
required |
bg_intensity |
float
|
Intensity of the background. |
required |
moving_angle |
float
|
Rotation angle in degrees. |
required |
bar_loc_horizontal |
float
|
Horizontal location of bars in radians. |
radians(90)
|
bar_loc_vertical |
float
|
Vertical location of bars in radians. |
radians(90)
|
mode |
Literal['mean', 'median', 'sum']
|
Processing mode. |
'mean'
|
Returns:
Type | Description |
---|---|
Tensor
|
torch.Tensor: Generated offset bars. |
Source code in flyvision/datasets/rendering/eye.py
527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 |
|
render_bar_movie ¶
render_bar_movie(
t_stim,
dt,
bar_width_rad,
bar_height_rad,
n_bars,
offsets,
bar_intensity,
bg_intensity,
moving_angle,
t_pre=0.0,
t_between=0.0,
t_post=0.0,
bar_loc_horizontal=np.radians(90),
bar_loc_vertical=np.radians(90),
)
Render moving bars.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
t_stim |
float
|
Stimulus duration. |
required |
dt |
float
|
Temporal resolution. |
required |
bar_width_rad |
float
|
Width of bars in radians. |
required |
bar_height_rad |
float
|
Height of bars in radians. |
required |
n_bars |
int
|
Number of bars. |
required |
offsets |
List[float]
|
Offsets of bars wrt. the center in radians. |
required |
bar_intensity |
float
|
Intensity of the bar. |
required |
bg_intensity |
float
|
Intensity of the background. |
required |
moving_angle |
float
|
Rotation angle in degrees. |
required |
t_pre |
float
|
Grey pre stimulus duration. |
0.0
|
t_between |
float
|
Grey between offset stimulus duration. |
0.0
|
t_post |
float
|
Grey post stimulus duration. |
0.0
|
bar_loc_horizontal |
float
|
Horizontal location of bars in radians. |
radians(90)
|
bar_loc_vertical |
float
|
Vertical location of bars in radians. |
radians(90)
|
Returns:
Type | Description |
---|---|
Tensor
|
torch.Tensor: Generated moving bars. |
Source code in flyvision/datasets/rendering/eye.py
574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 |
|
illustrate ¶
illustrate(figsize=[5, 5], fontsize=5)
Illustrate the hexagonal eye model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
figsize |
List[int]
|
Figure size. |
[5, 5]
|
fontsize |
int
|
Font size for the plot. |
5
|
Returns:
Type | Description |
---|---|
Tuple[Figure, Axes]
|
Tuple[plt.Figure, plt.Axes]: Matplotlib figure and axes objects. |
Source code in flyvision/datasets/rendering/eye.py
647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 |
|
Utils¶
flyvision.datasets.rendering.utils ¶
Rendering utils
median ¶
median(x, kernel_size, stride=1, n_chunks=10)
Apply median image filter with reflected padding.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
Tensor
|
Input array or tensor of shape (n_samples, n_frames, height, width). First and second dimensions are optional. |
required |
kernel_size |
int
|
Size of the filter kernel. |
required |
stride |
int
|
Stride for the filter operation. |
1
|
n_chunks |
int
|
Number of chunks to process the data if memory is limited. Recursively increases the chunk size until the data fits in memory. |
10
|
Returns:
Type | Description |
---|---|
Tensor
|
Filtered array or tensor of the same shape as input. |
Note
On GPU, this creates a tensor of kernel_size ** 2 * prod(x.shape) elements, consuming significant memory (e.g., ~14 GB for 50 frames of 436x1024 with kernel_size 13). In case of a RuntimeError due to memory, the method processes the data in chunks.
Source code in flyvision/datasets/rendering/utils.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 |
|
split ¶
split(
array, out_nelements, n_splits, center_crop_fraction=0.7
)
Split an array into overlapping segments along the last dimension.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
array |
Union[ndarray, Tensor]
|
Input array of shape (…, nelements). |
required |
out_nelements |
int
|
Number of elements in each output split. |
required |
n_splits |
int
|
Number of splits to create. |
required |
center_crop_fraction |
Optional[float]
|
If not None, the array is centrally cropped in the last dimension to this fraction before splitting. |
0.7
|
Returns:
Type | Description |
---|---|
Union[ndarray, Tensor]
|
A new array of shape (n_splits, …, out_nelements) containing the splits. |
Raises:
Type | Description |
---|---|
ValueError
|
If n_splits is less than 0. |
TypeError
|
If the input array is neither a numpy array nor a torch tensor. |
Note
- If n_splits is 1, the entire array is returned (with an added dimension).
- If n_splits is None or 0, the original array is returned unchanged.
- Splits may overlap if out_nelements * n_splits > array.shape[-1].
Source code in flyvision/datasets/rendering/utils.py
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 |
|
center_crop ¶
center_crop(array, out_nelements_ratio)
Centrally crop an array along the last dimension with given ratio.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
array |
Union[ndarray, Tensor]
|
Array of shape (…, nelements). |
required |
out_nelements_ratio |
float
|
Ratio of output elements to input elements. |
required |
Returns:
Type | Description |
---|---|
Union[ndarray, Tensor]
|
Cropped array of shape (…, out_nelements). |
Source code in flyvision/datasets/rendering/utils.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
|
hex_center_coordinates ¶
hex_center_coordinates(
n_hex_area, img_width, img_height, center=True
)
Calculate hexagon center coordinates for a given area.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_hex_area |
int
|
Number of hexagons in the area. |
required |
img_width |
int
|
Width of the image. |
required |
img_height |
int
|
Height of the image. |
required |
center |
bool
|
If True, center the hexagon grid in the image. |
True
|
Returns:
Type | Description |
---|---|
Tuple[ndarray, ndarray, Tuple[float, float]]
|
Tuple containing x coordinates, y coordinates, and (dist_w, dist_h). |
Source code in flyvision/datasets/rendering/utils.py
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 |
|
is_inside_hex ¶
is_inside_hex(
x,
y,
x_centers,
y_centers,
dist_to_edge,
tilt,
device=flyvision.device,
dtype=torch.float16,
)
Find whether given points are inside the given hexagons.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
Tensor
|
Cartesian x-coordinates of the points (n_points). |
required |
y |
Tensor
|
Cartesian y-coordinates of the points (n_points). |
required |
x_centers |
Tensor
|
Cartesian x-centers of the hexagons (n_hexagons). |
required |
y_centers |
Tensor
|
Cartesian y-centers of the hexagons (n_hexagons). |
required |
dist_to_edge |
float
|
Euclidean distance from center to edge of the hexagon. |
required |
tilt |
Union[float, Tensor]
|
Angle of hexagon counter-clockwise tilt in radians. |
required |
device |
device
|
Torch device to use for computations. |
device
|
dtype |
dtype
|
Data type for torch tensors. |
float16
|
Returns:
Type | Description |
---|---|
Tensor
|
Tuple containing: |
Tensor
|
|
Tuple[Tensor, Tensor]
|
|
Credits
Adapted from Roman Vaxenburg’s original implementation.
Source code in flyvision/datasets/rendering/utils.py
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 |
|
render_bars_cartesian ¶
render_bars_cartesian(
img_height_px,
img_width_px,
bar_width_px,
bar_height_px,
bar_loc_horizontal_px,
bar_loc_vertical_px,
n_bars,
bar_intensity,
bg_intensity,
rotate=0,
)
Render bars in a cartesian coordinate system.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
img_height_px |
int
|
Height of the image in pixels. |
required |
img_width_px |
int
|
Width of the image in pixels. |
required |
bar_width_px |
int
|
Width of each bar in pixels. |
required |
bar_height_px |
int
|
Height of each bar in pixels. |
required |
bar_loc_horizontal_px |
int
|
Horizontal location of the bars in pixels. |
required |
bar_loc_vertical_px |
int
|
Vertical location of the bars in pixels. |
required |
n_bars |
int
|
Number of bars to generate. |
required |
bar_intensity |
float
|
Intensity of the bars. |
required |
bg_intensity |
float
|
Intensity of the background. |
required |
rotate |
float
|
Rotation angle in degrees. |
0
|
Returns:
Type | Description |
---|---|
ndarray
|
Generated image as a numpy array. |
Source code in flyvision/datasets/rendering/utils.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 |
|
render_gratings_cartesian ¶
render_gratings_cartesian(
img_height_px,
img_width_px,
spatial_period_px,
grating_intensity,
bg_intensity,
grating_height_px=None,
grating_width_px=None,
grating_phase_px=0,
rotate=0,
)
Render gratings in a cartesian coordinate system.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
img_height_px |
int
|
Height of the image in pixels. |
required |
img_width_px |
int
|
Width of the image in pixels. |
required |
spatial_period_px |
float
|
Spatial period of the gratings in pixels. |
required |
grating_intensity |
float
|
Intensity of the gratings. |
required |
bg_intensity |
float
|
Intensity of the background. |
required |
grating_height_px |
Optional[int]
|
Height of the grating area in pixels. |
None
|
grating_width_px |
Optional[int]
|
Width of the grating area in pixels. |
None
|
grating_phase_px |
float
|
Phase of the gratings in pixels. |
0
|
rotate |
float
|
Rotation angle in degrees. |
0
|
Returns:
Type | Description |
---|---|
ndarray
|
Generated image as a numpy array. |
Source code in flyvision/datasets/rendering/utils.py
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 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 412 413 414 415 416 |
|
rotate_image ¶
rotate_image(img, angle=0)
Rotate an image by a given angle.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
img |
ndarray
|
Input image as a numpy array. |
required |
angle |
float
|
Rotation angle in degrees. |
0
|
Returns:
Type | Description |
---|---|
ndarray
|
Rotated image as a numpy array. |
Source code in flyvision/datasets/rendering/utils.py
419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 |
|
resample ¶
resample(
stims,
t_stim,
dt,
dim=0,
device=flyvision.device,
return_indices=False,
)
Resample a set of stimuli for a given stimulus duration and time step.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stims |
Tensor
|
Stimuli tensor of shape (#conditions, #hexals). |
required |
t_stim |
float
|
Stimulus duration in seconds. |
required |
dt |
float
|
Integration time constant in seconds. |
required |
dim |
int
|
Dimension along which to resample. |
0
|
device |
device
|
Torch device to use for computations. |
device
|
return_indices |
bool
|
If True, return the indices used for resampling. |
False
|
Returns:
Type | Description |
---|---|
Union[Tensor, Tuple[Tensor, Tensor]]
|
Resampled stimuli tensor of shape (#frames, #hexals), or a tuple of |
Union[Tensor, Tuple[Tensor, Tensor]]
|
(resampled stimuli, indices) if return_indices is True. |
Source code in flyvision/datasets/rendering/utils.py
455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 |
|
shuffle ¶
shuffle(stims, randomstate=None)
Randomly shuffle stimuli along the frame dimension.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stims |
Tensor
|
Stimuli tensor of shape (N (optional), #frames, #hexals). |
required |
randomstate |
Optional[RandomState]
|
Random state for reproducibility. |
None
|
Returns:
Type | Description |
---|---|
Tensor
|
Shuffled stimuli tensor. |
Source code in flyvision/datasets/rendering/utils.py
487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 |
|
resample_grating ¶
resample_grating(grating, t_stim, dt, temporal_frequency)
Resample a grating stimulus for a given duration and temporal frequency.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
grating |
Tensor
|
Input grating tensor. |
required |
t_stim |
float
|
Stimulus duration in seconds. |
required |
dt |
float
|
Time step in seconds. |
required |
temporal_frequency |
float
|
Temporal frequency of the grating. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
Resampled grating tensor. |
Source code in flyvision/datasets/rendering/utils.py
514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 |
|
pad ¶
pad(stim, t_stim, dt, fill=0, mode='end', pad_mode='value')
Pad the second to last dimension of a stimulus tensor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stim |
Tensor
|
Stimulus tensor of shape (…, n_frames, n_hexals). |
required |
t_stim |
float
|
Target stimulus duration in seconds. |
required |
dt |
float
|
Integration time constant in seconds. |
required |
fill |
float
|
Value to fill with if pad_mode is “value”. |
0
|
mode |
Literal['end', 'start']
|
Padding mode, either “end” or “start”. |
'end'
|
pad_mode |
Literal['value', 'continue', 'reflect']
|
Padding type, either “value”, “continue”, or “reflect”. |
'value'
|
Returns:
Type | Description |
---|---|
Tensor
|
Padded stimulus tensor. |
Source code in flyvision/datasets/rendering/utils.py
536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 |
|
repeat_last ¶
repeat_last(stim, dim, n_repeats)
Repeat the last frame of a stimulus tensor along a specified dimension.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stim |
Tensor
|
Input stimulus tensor. |
required |
dim |
int
|
Dimension along which to repeat. |
required |
n_repeats |
int
|
Number of times to repeat the last frame. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
Stimulus tensor with the last frame repeated. |
Source code in flyvision/datasets/rendering/utils.py
578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 |
|