simply_nwb.transforms package
Submodules
simply_nwb.transforms.blackrock module
- simply_nwb.transforms.blackrock.blackrock_all_spiketrains(filename: str) list
Load data from a blackrock file (nev, ns5 and nsX files) and grab all the spike trains into a single list Uses the NEO Library
NEO Docs https://neo.readthedocs.io/en/stable/core.html
NEO Github https://github.com/NeuralEnsemble/python-neo/tree/master
- Parameters:
filename – file to load data from
- Returns:
list of numpy arrays for spiketrains
- simply_nwb.transforms.blackrock.blackrock_load_data(filename: str, raw: bool = False) list[dict]
Load data from a blackrock file (nev, ns5 and nsX files) into a list of dictionaries Uses the NEO Library
NEO Docs https://neo.readthedocs.io/en/stable/core.html
NEO Github https://github.com/NeuralEnsemble/python-neo/tree/master
- Parameters:
filename – filename to load
raw – If raw == True, don’t process into a dict, return what NEO returns
- Returns:
list dicts of data
simply_nwb.transforms.csv module
- simply_nwb.transforms.csv.csv_load_dataframe(filename: str, **kwargs) DataFrame
Simple wrapper around pd.read_csv for file checks
- Parameters:
filename – str filename
kwargs – extra args to pass to pandas.read_csv()
- Returns:
pandas.DataFrame
- simply_nwb.transforms.csv.csv_load_dataframe_str(strdata: str, **kwargs) DataFrame
Simple wrapper around pd.read_csv for a string rather than a file
- Parameters:
strdata – str to parse
kwargs – extra args to pass to pandas.read_csv()
- Returns:
pandas.DataFrame
simply_nwb.transforms.eyetracking module
- simply_nwb.transforms.eyetracking.eyetracking_load_dlc(dlc_filepath: str) DataFrame
Load eyetracking data from DLC into a Pandas Dataframe :param dlc_filepath: :return:
simply_nwb.transforms.labjack module
- simply_nwb.transforms.labjack.labjack_concat_files(file_list: list[str], alignment_key: str = 'Time') dict
Load a list of labjack files and concat them all, using a column as the alignment key (defaults to “Time”)
- Returns:
a dict like {col1: [data1], …}
- simply_nwb.transforms.labjack.labjack_load_file(filename: str) dict
Returns labjack data and labjack metadata from a given filename
- Parameters:
filename – file to parse
- Returns:
data dict ‘data’ dataframe, ‘metadata’ dataframe, ‘date’ datetime
simply_nwb.transforms.mp4 module
- simply_nwb.transforms.mp4.mp4_read_data(filename: str) -> (<class 'numpy.ndarray'>, <class 'int'>)
Read the data from an MP4 file into a numpy array and get the framecount
- Parameters:
filename – mp4 file to read
- Returns:
(numpy arr, framecount)
simply_nwb.transforms.neuropixels module
- simply_nwb.transforms.neuropixels.df_from_phy(path: str, site_positions: ndarray | None = None) DataFrame
Create a pandas dataframe from phy data
- Parameters:
path – Path to the Phy data
site_positions – Positions of the channels on the probe
- Returns:
Pandas Dataframe
- simply_nwb.transforms.neuropixels.get_peak_waveform_from_template(template: ndarray) ndarray
Get the peak waveform from a given template
- Parameters:
template – Template from an NWB
- Returns:
Numpy array of the waveform
- simply_nwb.transforms.neuropixels.load_phy_template(path: str, site_positions: ndarray | None = None, samplingrate: float = 30000.0) dict
Load spike data that has been manually sorted with the phy-template GUI the site_positions should contain coordinates of the channels in probe space. for example, in um on the face of the probe
- Parameters:
path – Path to the Phy data
site_positions – Positions of the channels on the probe
samplingrate – Rate at which the Neuropixels probe sampled the data, defaults to 30kHz
- Returns:
A dictionary of ‘good’ units with keys times: spike times, in seconds template: template used for matching ypos: y position on the probe, calculated from the template. requires an accurate site_positions. averages template from 100 spikes. xpos: x position on the probe, calcualted from the template. requires an accurate site_positions. averages template from 100 spikes.
- simply_nwb.transforms.neuropixels.load_unit_data(recording_path: str, probe_depth: int = 3840, site_positions: ndarray | None = None, probe_name: str | None = None, spikes_filename: str = 'spike_secs.npy', aligned: bool = True, df: bool = True, **kwargs) DataFrame | list[dict]
Load the unit data from a given recording
- Parameters:
recording_path – path to the recording str
probe_depth – depth of the probe
site_positions – Channel positions on the neuropixels probe
probe_name – Name of the probe, defaults to the recording path
spikes_filename – Spikes filename, defaults to spike_secs.npy
aligned – bool if the spike times are aligned along the sampling rate, if not will be converted
df – Return data as a dataframe
- Returns:
Dict or Dataframe of the unit data
- simply_nwb.transforms.neuropixels.load_unit_data_from_phy(recording_path: str, chanmap: dict | None = None, insertion_depth: int = 3840, insertion_angle: float = 0) dict
Load unit data from Phy Requires that phy has been run to generate cluster_info.tsv searches the folder for the chanmap the KS used, or searches one folder up for it
- Parameters:
recording_path – Path to the recording data
chanmap – Channel map, if not provided will attempt to find a file matching ‘*hanMap.mat’
insertion_angle – insertion angle
insertion_depth – insertion depth
- Returns:
dict of unit data
- simply_nwb.transforms.neuropixels.make_spike_secs(probe_folder)
Make spike_secs.npy, a file containing spike times along seconds
- Parameters:
probe_folder – string path to the probe folder
- Returns:
None, will save file in directory
- simply_nwb.transforms.neuropixels.multi_load_unit_data(recording_folder, probe_names=['A', 'B', 'C', 'D'], probe_depths=[3840, 3840, 3840, 3840], spikes_filename='spike_secs.npy', aligned=True)
Load multiple units
- simply_nwb.transforms.neuropixels.recreate_probe_timestamps_from_TTL(directory: str) None
Recreate probe timestamps from a TTL feed. Will create files new_timestamps/’templates.npy’ and new_timestamps/’sample_numbers.npy’
- Parameters:
directory – str to the directory
- Returns:
None, will create files on FS
simply_nwb.transforms.p_erg module
- simply_nwb.transforms.p_erg.perg_parse_to_table(filename: str, reformat_column_names: bool = True) -> (<class 'dict'>, <class 'dict'>)
Parse the output of a pERG reading into a dict
- Parameters:
filename – filename of the pERG data to parse
reformat_column_names – reformat the column names, e.g ‘Data Pnt(ms):’ -> ‘data_pnt_ms’
- Returns:
dict of data
simply_nwb.transforms.plaintext module
- simply_nwb.transforms.plaintext.drifting_grating_metadata_read(filename: str, data_to_numpy: bool = True, columns_key: str = 'Columns', max_line_len: int = 100000, filename_str: str = 'filename') {<class 'str'>: typing.Union[str, list]}
Read in data for a drifting grating metadata like if data_to_numpy is True, will convert the numerical part of the file to a numpy array max_line_len is how far along a line we should parse for ‘(’ and ‘)’ if reached will error (number of chars) Dunno why I wrote a token parser for this lol
Meta1: desc1 Meta2: desc2 Columns: col1, col2, col3, … … 1,2,3,4 6,7,8,9 …
Where the top section is key: value and the bottom is just a csv Will turn it into a dict like {col1: [1, 6, ..], col2: [2, 7, ..]], Meta1: desc1, Meta1: desc2, …, <columns_key>: [col1, col2, …]}
- simply_nwb.transforms.plaintext.drifting_grating_metadata_read_from_filelist(files: list[str], data_to_numpy: bool = True, columns_key: str = 'Columns', max_line_len: int = 100000, alignment_key: str = 'Timestamp', filelen_str: str = 'file_len', filename_str: str = 'filename', expand_file_keys: bool = False) {<class 'str'>: typing.Union[str, list]}
Grab a list of labjack files and concat them together into a single data structure. Will arrange the data based on an alignment key, defaults to ‘Timestamp’
- simply_nwb.transforms.plaintext.plaintext_metadata_read(filename: str, sep: str = ':') {<class 'str'>: <class 'str'>}
Read in data in a ‘metadata’ like format such as
Key: val Key2: val2
- Parameters:
filename – str filename to read from
sep – Separator for keys and values, defaults to ‘:’
- Returns:
dict of metadata data
simply_nwb.transforms.tif module
- exception simply_nwb.transforms.tif.ImageLoadError
Bases:
Exception
- simply_nwb.transforms.tif.read_filelist(filelist: list[str], skip_on_error: bool = False, show_error: bool = True) list[ndarray]
Load a list of files and return them
- Parameters:
filelist – list of str filenames
skip_on_error – skip any images that fail
show_error – show an error when images fail to load
- Returns:
list of loaded file data
- simply_nwb.transforms.tif.tif_read_directory(foldername: str, filename_glob: str = '*.tif', skip_on_error: bool = False) ndarray
Read a directory of TIF files, giving a filename glob for specific TIFs to grab
- Parameters:
foldername – Folder that contains the TIF images, directly inside
skip_on_error – Skip any files that fail to load
filename_glob – naming scheme for the TIF files to be collected. e.g. ‘image_*.tif’
- Returns:
numpy array
- simply_nwb.transforms.tif.tif_read_image(filename: str, show_error: bool = True) ndarray
Read TIF Image into a numpy array
- Parameters:
filename – TIF file to read
show_error – Print out errors or not, defaults to true
- Returns:
numpy array
- simply_nwb.transforms.tif.tif_read_subfolder_directory(parent_folder: str, subfolder_glob: str, file_glob: str, subfolder_glob_fail_on_file_found: bool = False, skip_on_error: bool = False) ndarray
Read a directory that contains folders that contain TIFs, and read each TIF from each subfolder into memory
- Parameters:
parent_folder – main folder containing more folders
subfolder_glob – glob to specify which subfolders to look into e.g. ‘folder_num_*’
subfolder_glob_fail_on_file_found – If the subfolder glob returns a file, fail the operation. Defaults to True and if a file is matched, it will ignore it
file_glob – TIF file glob to specify which TIFs from the subfolders to read, e.g. ‘image0*.tif’
skip_on_error – Skip any files that fail to load
- Returns:
numpy array
simply_nwb.transforms.yaml module
- simply_nwb.transforms.yaml.yaml_read_file(filename: str) dict
Read a YAML file into a dict
- Parameters:
filename – filename of the yaml file
- Returns:
dict of data