Höfling et al. 2024 Dataset
Dataloaders
extract_data_info_from_dataloaders(dataloaders)
Extracts the data_info dictionary from the provided dataloaders. Args: dataloaders: A dictionary of dataloaders for different sessions. Returns: data_info: A dictionary containing input_dimensions, input_channels, and output_dimension for each session, nested with these attributes as the first level keys and sessions as the second level.
Source code in openretina/data_io/hoefling_2024/dataloaders.py
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 |
|
filter_different_size(batch)
Filters out batches that do not have the same shape as most of the other batches.
Source code in openretina/data_io/hoefling_2024/dataloaders.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
|
filter_nan_collate(batch)
Filters out batches containing NaN values and then calls the default_collate function. Can happen for inferred spikes exported with CASCADE. To be used as a collate_fn in a DataLoader.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
batch
|
list
|
A list of tuples representing the batch. |
required |
Returns:
Type | Description |
---|---|
tuple of torch.Tensor: The collated batch after filtering out NaN values. |
Source code in openretina/data_io/hoefling_2024/dataloaders.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
|
get_dims_for_loader_dict(dataloaders)
Borrowed from nnfabrik/utility/nn_helpers.py.
Given a dictionary of DataLoaders, returns a dictionary with same keys as the
input and shape information (as returned by get_io_dims
) on each keyed DataLoader.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataloaders
|
dict of DataLoader
|
Dictionary of dataloaders. |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
dict[str, dict[str, tuple[int, ...]] | tuple]
|
A dict containing the result of calling |
Source code in openretina/data_io/hoefling_2024/dataloaders.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
|
get_io_dims(data_loader)
Borrowed from nnfabrik/utility/nn_helpers.py.
Returns the shape of the dataset for each item within an entry returned by the data_loader
The DataLoader object must return either a namedtuple, dictionary or a plain tuple.
If data_loader
entry is a namedtuple or a dictionary, a dictionary with the same keys as the
namedtuple/dict item is returned, where values are the shape of the entry. Otherwise, a tuple of
shape information is returned.
Note that the first dimension is always the batch dim with size depending on the data_loader configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_loader
|
DataLoader
|
is expected to be a pytorch Dataloader object returning either a namedtuple, dictionary, or a plain tuple. |
required |
Returns: dict or tuple: If data_loader element is either namedtuple or dictionary, a ditionary of shape information, keyed for each entry of dataset is returned. Otherwise, a tuple of shape information is returned. The first dimension is always the batch dim with size depending on the data_loader configuration.
Source code in openretina/data_io/hoefling_2024/dataloaders.py
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 |
|
Stimuli
gen_start_indices(random_sequences, val_clip_idx, clip_length, chunk_size, num_clips)
Optimized function to generate a list of indices for training chunks while excluding validation clips.
:param random_sequences: int np array; 108 x 20, giving the ordering of the 108 training clips for the 20 different sequences :param val_clip_idx: list of integers indicating the clips to be used for validation :param clip_length: clip length in frames (5s*30frames/s = 150 frames) :param chunk_size: temporal chunk size per sample in frames (50) :param num_clips: total number of training clips (108) :return: dict; with keys train, validation, and test, and index list as values
Source code in openretina/data_io/hoefling_2024/stimuli.py
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 |
|
get_all_movie_combinations(movie_train, movie_test, random_sequences, validation_clip_indices, num_clips=NUM_CLIPS, clip_length=CLIP_LENGTH)
Generates combinations of movie data for 'left' and 'right' perspectives and prepares training, validation, and test datasets. It reorders the training movies based on random sequences and flips the movies for the 'left' perspective.
Parameters: - movie_train: Tensor representing the training movie data. - movie_test: Tensor representing the test movie data. - random_sequences: Numpy array of random sequences for reordering training movies. - val_clip_idx: list of indices for validation clips. Needs to be between 0 and the number of clips.
- movies: Dictionary with processed movies for 'left' and 'right' perspectives, each containing 'train', 'validation', and 'test' datasets.
Source code in openretina/data_io/hoefling_2024/stimuli.py
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 |
|
movies_from_pickle(file_path)
Load movie data from a pickle file and return it as a MoviesTrainTestSplit object.
Source code in openretina/data_io/hoefling_2024/stimuli.py
11 12 13 14 15 |
|
Responses
NeuronDataSplitHoefling
Source code in openretina/data_io/hoefling_2024/responses.py
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 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 |
|
__init__(neural_responses, val_clip_idx, num_clips, clip_length, roi_mask=None, roi_ids=None, scan_sequence_idx=None, random_sequences=None, eye=None, group_assignment=None, key=None, use_base_sequence=False, **kwargs)
Initialize the NeuronData object. Boilerplate class to store neuron data train/test/validation splits before feeding into a dataloader. Customized for compatibility with the data format in Hoefling et al., 2024.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
eye
|
str
|
The eye from which the neuron data is recorded. |
None
|
group_assignment
|
Float[ndarray, n_neurons]
|
The group assignment of neurons. |
None
|
key
|
dict
|
The key information for the neuron data, includes date, exp_num, experimenter, field_id, stim_id. |
None
|
responses_final
|
Float[ndarray, 'n_neurons n_timepoints']
|
The responses of neurons. |
required |
roi_coords
|
Float[ndarray, 'n_neurons 2']
|
The coordinates of regions of interest (ROIs). |
required |
roi_ids
|
Float[ndarray, n_neurons]
|
The IDs of regions of interest (ROIs). |
None
|
scan_sequence_idx
|
int
|
The index of the scan sequence. |
None
|
stim_id
|
int
|
The ID of the stimulus. 5 is mouse natural scenes. |
required |
random_sequences
|
Float[ndarray, 'n_clips n_sequences']
|
The random sequences of clips. |
None
|
val_clip_idx
|
List[int]
|
The indices of validation clips. |
required |
num_clips
|
int
|
The number of clips. |
required |
clip_length
|
int
|
The length of each clip. |
required |
use_base_sequence
|
bool
|
Whether to re-order all training responses to use the same "base" sequence. |
False
|
Source code in openretina/data_io/hoefling_2024/responses.py
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 |
|
roi2readout(single_roi_mask, roi_mask_pixelsize=2, readout_mask_pixelsize=50, x_offset=2.75, y_offset=2.75)
Maps a roi mask of a single roi from recording coordinates to model readout coordinates :param single_roi_mask: 2d array with nonzero values indicating the pixels of the current roi :param roi_mask_pixelsize: size of a pixel in the roi mask in um :param readout_mask_pixelsize: size of a pixel in the readout mask in um :param x_offset: x offset indicating the start of the recording field in readout mask :param y_offset: y offset indicating the start of the recording field in readout mask :return:
Source code in openretina/data_io/hoefling_2024/responses.py
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 |
|
filter_responses(all_responses, filter_cell_types=False, cell_types_list=None, chirp_qi=0.35, d_qi=0.6, qi_logic='or', filter_counts=True, count_threshold=10, classifier_confidence=0.25, verbose=False)
This function processes the input dictionary of neuron responses, applying various filters to exclude unwanted data based on the provided parameters. It can filter by cell types, quality indices, classifier confidence, and the number of responding cells, while also providing verbose output for tracking the filtering process. Note: default arguments are from the Hoefling et al., 2024 paper.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
all_responses
|
Dict[str, dict]
|
A dictionary containing neuron response data. |
required |
filter_cell_types
|
bool
|
Whether to filter by specific cell types. Defaults to False. |
False
|
cell_types_list
|
Optional[List[int] | int]
|
List or single value of cell types to filter. Defaults to None. |
None
|
chirp_qi
|
float
|
Quality index threshold for chirp responses. Defaults to 0.35. |
0.35
|
d_qi
|
float
|
Quality index threshold for d responses. Defaults to 0.6. |
0.6
|
qi_logic
|
Literal['and', 'or']
|
The logic to combine different quality indices. Defaults to "and". |
'or'
|
filter_counts
|
bool
|
Whether to filter based on response counts. Defaults to True. |
True
|
count_threshold
|
int
|
Minimum number of responding cells required. Defaults to 10. |
10
|
classifier_confidence
|
float
|
Minimum confidence level for classifier responses. Defaults to 0.3. |
0.25
|
verbose
|
bool
|
If True, prints detailed filtering information. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
dict[str, dict]
|
Dict[str, dict]: A filtered dictionary of neuron responses that meet the specified criteria. |
Source code in openretina/data_io/hoefling_2024/responses.py
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 |
|
upsample_all_responses(data_dict, response_type='natural', trace_type='spikes', d_qi=None, chirp_qi=None, qi_logic='or', scale_traces=1.0, norm_by_std=True)
Converts inferred spikes into final responses by upsampling the traces of all sessions of a given response_type. This is to match the framerate used in the stimulus presentation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_dict
|
dict
|
A dictionary containing the data. |
required |
response_type
|
str
|
The type of response. Defaults to "natural". |
'natural'
|
Returns:
Name | Type | Description |
---|---|---|
dict |
The updated data dictionary with final responses. |
Raises: NotImplementedError: If the conversion is not yet implemented for the given response type.
Source code in openretina/data_io/hoefling_2024/responses.py
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 |
|
upsample_traces(triggertimes, traces, tracestimes, stim_id, target_fr=30, norm_by_std=True)
Upsamples the traces based on the stimulus type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
triggertimes
|
list
|
List of trigger times. |
required |
traces
|
list
|
List of traces. |
required |
tracestimes
|
list
|
List of trace times. |
required |
stim_id
|
int
|
Stimulus ID. |
required |
target_fr
|
int
|
Target frame rate for upsampling. Default is 30. |
30
|
Returns:
Type | Description |
---|---|
ndarray
|
numpy.ndarray: Upsampled responses. |
Raises:
Type | Description |
---|---|
NotImplementedError
|
If the stimulus ID is not implemented. |
Source code in openretina/data_io/hoefling_2024/responses.py
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 |
|