create_binned_data_from_raster_data
This helper function takes the name of a directory that contains files in raster-format and creates data that is in binned-format from these files. The function has the following form:
saved_binned_data_file_name = create_binned_data_from_raster_data(raster_file_directory_name, save_prefix_name, bin_width, sampling_interval, [start_time], [end_time])
The arguments to this function are:
-
raster_file_directory_name
The path to the directory that contains the files in raster format.
-
save_prefix_name
The beginning of a file name (possibly including a directory name) that specifies the name that the binned data should be saved as. Appended on to the end of this name when the binned data is saved is the bin width, step size, and possibly start and end times used.
-
bin_width
The bin size that is averaged over when creating binned-format features. For example, if the raster files have spike times given with millisecond precision, and bin_width = 500, then the binned-format data will contain average firing rates (i.e., the spike-count rate) in 500 ms bins. If bin_width is a vector that is the same size as sampling_interval then different bin widths can be specified for different time periods (e.g., if bin_widths = [50 500, 100], then the first bin will average over 50 ms of data, the second over 500 ms of data, and the third over 100 ms of data).
-
sampling_interval
Specifies the sampling interval between successive binned-data points. For example, if the raster files have spike times given with millisecond precision, and if sampling_interval = 50, then a binned data point will be computed at 50ms intervals. If sampling_interval is a vector, then the values in this vector will specify the start times for the bins (e.g., if sampling_interval = [1 200 500], then the first bin will start time 1, the second bin will start at time 200, and the third bin will start at time 500).
Optional arguments:
-
start_time
This specifies the time to start the binning process. If this argument is not set, then the binning will start with the first data point in the raster files (i.e., the first bin will use raster_data(:, 1:bin_width), the second bin will use data from raster_data(:, (step_size+1):(step_size+bin_width)), etc.).
-
end_time
This specifies the time when to end the binning process. If this argument is not set, then the binning will end with the last data point in the raster files.
Note: if sampling_interval is a vector, the arguments 5 and 6 can not be set (this is because the start bin times have already been exactly specified by the sampling_interval vector).
The output of this function is to saves a file in the directory specified by the save_prefix_name (the name of the file is returned in the variable saved_binned_data_file_name). The saved file contains the three variables needed to conform to binned-format which are: binned_data which contains the data, binned_labels which contains the labels, and binned_site_info which contains the any extra information about each site. The data in the three saved variables are extracted from the raster-format files that are contained in the input directory. Additionally, additional information is saved in binned_site_info.binning_parameters that contains the bin_width, sampling interval, etc., that were used to create this binned data.
Examples
Example 1:
Suppose we had a directory called my_raster_file_directory/ that contained a number of files in raster-data format from the spike times of neurons specified at 1 ms resolution. Then running:
create_binned_data_from_raster_data('my_raster_file_directory/', ...
'my_save_dir/binned_data', 150, 50, 200, 1000)
will create a file called binned_data_150ms_bins_50ms_sampled_200start_time_1000end_time that will be saved in the directory my_save_dir/. This file will contain the average firing rate calculated over 150 ms intervals for all neurons in the directory my_raster_file_directory/. The firing rates will be sampled every 50 ms, starting 200 ms into the raster-format data and ending 1000 ms into the raster-format data.
Example 2:
Suppose we had a directory called my_raster_file_directory/ that contained a number of files in raster-data format from the spike times of neurons specified at 1 ms resolution. Then running:
create_binned_data_from_raster_data('my_raster_file_directory/', ...
'my_save_dir/binned_data_100ms_bins_plus_2_extra', ...
100 .* ones(10, 1) 250 250], [1:50:500 1 251]); [
will create a file in the binned_data_100ms_bins_plus_2_extra_custom_bins_custom_sampled that will be saved in the directory my_save_dir/. This file will contain the average firing rate calculated over 100 ms intervals for all neurons in the directory my_raster_file_directory/ and will be sampled every 50 ms for the first 500 ms of data. Additionally, there will be two 250 ms bins at the end of the binned data that have the average firing rates over 1-250 ms into the trial and 251-500 ms into the trial.