This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """Generic parallel video writer for matplotlib animations. | |
| This module provides utilities for creating high-quality videos from matplotlib | |
| figures by rendering frames in parallel across multiple processes, then stitching | |
| them together with ffmpeg. This approach is significantly faster than single-process | |
| matplotlib animation for long videos, and more robust to memory leaks. | |
| The core pattern: | |
| 1. Partition frames across worker processes | |
| 2. Each worker independently renders its assigned frames to PNG files |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from loren_frank_data_processing import get_trial_time, get_interpolated_position_dataframe, make_neuron_dataframe | |
| import pandas as pd | |
| import numpy as np | |
| epoch_key = ('HPa', 3, 2) | |
| # Get time of epoch from first LFP | |
| SAMPLING_FREQUENCY = 500 # samples per second | |
| time = get_trial_time(epoch_key, ANIMALS) | |
| time = (pd.Series(np.ones_like(time, dtype=np.float), index=time) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from loren_frank_data_processing import get_interpolated_position_dataframe, get_spike_indicator_dataframe | |
| from src.parameters import ANIMALS | |
| epoch_key = ('HPa', 6, 2) | |
| def time_function(epoch_key, animals): | |
| neuron_info = make_neuron_dataframe(ANIMALS).xs(epoch_key, drop_level=False) | |
| neuron_key = neuron_info.index[0] | |
| return get_spike_indicator_dataframe(neuron_key, ANIMALS).resample('1ms').index |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def jspth(spikes1, spikes2): | |
| '''Joint Peristimulus Time Histogram | |
| Parameters | |
| ---------- | |
| spikes1, spikes2: ndarray, shape (n_time, n_trials) | |
| Returns | |
| ------- | |
| joint_histogram : ndarray, shape (n_time, n_time) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def occupancy_normalized_hexbin(x, y, all_x, all_y, ax=None, | |
| gridsize=(3, 3), **kwargs): | |
| '''Bins (x, y) into hexagonal grid and normalizes the | |
| count by the binned count of (all_x, all_y). | |
| Useful when measuring the frequency of events over time | |
| and space when the time spent in each bin is not equal. | |
| Parameters | |
| ---------- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def coherence_rate_adjustment(firing_rate_condition1, | |
| firing_rate_condition2, spike_power_spectrum, | |
| homogeneous_poisson_noise=0, dt=1): | |
| '''Correction for the spike-field or spike-spike coherence when the | |
| conditions have different firing rates. | |
| When comparing the coherence of two conditions, a change in firing rate | |
| results in a change in coherence without an increase in coupling. | |
| This adjustment modifies the coherence of one of the conditions, so | |
| that a difference in coherence between conditions indicates a change |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from subprocess import PIPE, run | |
| print(run(['git', 'rev-parse', 'HEAD'], | |
| stdout=PIPE, universal_newlines=True).stdout) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| % Wrapper function for save for use in parfor loops | |
| % Based on http://www.mathworks.com/matlabcentral/answers/135285#answer_149537 | |
| % Handles save options such as -append | |
| % | |
| % Test Example 1 | |
| % a = 10; | |
| % b = 'blah'; | |
| % c.test = 1; | |
| % d = {'a'}; | |
| % e = [100 100]; |