Python package to load and parse H5 files in the Dewan Lab.
Project description
Dewan Lab H5 Library
This library serves to load, parse, and serve the contents of H5 files from the lab's Arduino- and Voyeur-based behavior setups.
Installation
- Using PyPi: Simply run
pip install dewan_h5and the latest version will be pulled from PyPi - Local Installation
- Clone the repository using
git clone https://github.com/OlfactoryBehaviorLab/dewan_h5 - Navigate into the
dewan_h5directory - Execute
pip install .orpip install -e .if you want the repository to be editable
- Clone the repository using
Usage
Info: The DewanH5 class is intended to be used within a Python context manager.
Usage outside a context manager is not supported
Example:
from dewan_h5 import DewanH5
file_path = 'path/to/h5/file/file.h5'
with DewanH5(file_path) as dh5:
# Do things here
# When done, the file is automatically closed when the context is exited
print(dh5) # Print summary of contents of file
# Context is now exited
Class Constructor
DewanH5(file_path, trim_trials=True, suppress_errors=False)
file_path : None, Path, or strPath to the H5 file- None: If None is explicitly supplied, a file selector will open
- Path: pathlib.Path representing the location of the H5 file
- str: string containing raw path to H5 file; internally converted to a pathlib.Path
trim_trials : boolIndicates whether below trials are trimmed from the raw dataset- When set to
truethe following are trimmed:- The first 10 Go Trials
- If three Go trials are missed in a row, everything after (and including) the third missed trial are dropped
- When set to
suppress_errors : boolDetermines whether certain errors are suppressed and handled silently or allowed to propagate to the context manager
Public Parameters
Constructor Parameters
file_path : pathlib.PathSystem-agnostic path to the H5 filefile_name : strFilename with suffixsuppress_errors : boolDetermines whether errors are suppressed and handled silently or allowed to propagate to the context managertrim_trial : boolNormally, certain trials are trimmed from the raw dataset. This indicates whether those trials were trimmed or left in the dataset
General Parameters
date : strDate the H5 file was createdtime : strTime the H5 file was createdmouse : intID number of animal ran in experimentrig : strRig name experiment was ran in
Odor Information
odors : list[str]List of all odors present in H5 File- This includes blank
concentrations : list[str]List of all concentrations present in H5 file
Performance Values
All performance values are calculated after trimming (if applicable)
total_trials : intTotal number of trials in experimentgo_performance : floatPercentage of correct go trials vs total number of go trialsnogo_performance : floatPercentage of correct nogo trials vs total number of nogo trialstotal_performance : floatPercentage of correct go and nogo trials vs total number of trials- (correct go trials + correct nogo trials) / total number of trials
three_missed : boolIndicates whether the animal missed three go trials in a rowlast_good_trial : intIf three_missed is true, this is the last trial included in the datadid_cheat : boolIndicates whether cheating was detected- See description of cheating check below
cheat_check_tirals : list[int]List of cheating check trial indices
Data Containers
Note 1: If trimming the dataset, the below containers are also trimmed
Note 2: All the timestamps are offset by the FV on time. Negative values represent events before the FV turned on
trial_parameters : pd.DataFramePandas DataFrame containing the parameters recorded for each trial- See list of important parameters below
sniff : dict[int, pd.Series]Dictionary where each key is an int representing a trial number; each Pandas Series contains timestamped samples representing data recorded from the sniff sensorlick1 : dict[int, list]Dictionary where each key is an int representing a trial number; each list contains timestamps for licks of lick sensor 1lick2: dict[int, list]Dictionary where each key is an int representing a trial number; each list contains timestamps for licks of lick sensor 2
H5 File Structure
- Values:
N-> number of trialsn-> references any arbitrary trialx-> arbitrary number
- File Structure
/: Contains N number of Groups for each trial with an additional group containing the trial data matrixTrials: Matrix containing n rows with columns for multiple parameters captured for each trialTrial000n[type: group] (one group per trial): Holds samples for each trialEvents[type: dataset] (x number of tuples): (timestamp, number of sniff samples)lick1[type: dataset] (x number of arrays): each array contains a variable number of lick timestamps for the 'left' lick tubelick2[type: dataset] (x number of arrays): each array contains a variable number of lick timestamps for the 'right' lick tubesniff[type: dataset] (len(Events) number of arrays): each array contains samples recorded from the sniff sensor
Pertinent Trial Parameters:
Matrix located at /Trials that contains parameters for each trial
Each entry in the following format Common Name [column_name, data type]
Note: the column names are strings, but I have left the quotations off for clarity
Trial Type [Trialtype, int]: Value which encodes the trial type- 1: Go (no licking)
- 2: NoGo (licking)
Response [_result, int]: Value that represents the response of the animal- 1: Correct "Go" Response >>> The stimulus was a 'Go' stimulus and the animal correctly withheld licking
- 2: Correct "NoGo" Response >>> The stimulus was a 'NoGo' stimulus and the animal correctly licked
- 3: False Alarm / Incorrect "NoGo" Response >>> The stimulus was a "NoGo" stimulus and the animal incorrectly withheld licking
- 4: Unused
- 5: Missed "Go" Response >>> The stimulus was a 'Go' stimulus and the animal incorrectly licked
Note: Some trials are designated "cheating checks" to test whether the animal is utilizing a non-odor cue to get extra water rewards. A cheating check is identified by a trial type of
2with an odor ofblank.
- A response of2indicates CHEATING
- A response of3indicates NO CHEATING
Odor Name [Odor, str]: Name of odorant presented during the trialOdor Concentration [Odorconc, str]: Concentration of odorant presented during the trialOdor Vial Number [Odorvial, int]: Olfactometer vial used to deliver the odorant during the trialInter Trial Interval (ITI) [iti, str]: Time in milliseconds between current trial and next trialMouse ID [mouse, int]: ID number of animal ran in the experimentRig Name [rig, str]: Name of behavioral chamber
License
This project is licensed under GNU General Public License v3.0. You can find the included copy of the license here. For more information about the license and its terms, please visit SPDX
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dewan_h5-1.2.3.tar.gz.
File metadata
- Download URL: dewan_h5-1.2.3.tar.gz
- Upload date:
- Size: 50.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
168b20cf28241dfd749e082c8d33af0d8965ffb721606e65a6f26a7ce046f847
|
|
| MD5 |
543256584c71cc54d896cdc3196deb54
|
|
| BLAKE2b-256 |
436fca551613a2844857404340640ff68758fbbe09270f7d82c8d9f5d5413ff7
|
File details
Details for the file dewan_h5-1.2.3-py3-none-any.whl.
File metadata
- Download URL: dewan_h5-1.2.3-py3-none-any.whl
- Upload date:
- Size: 34.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c9597833f7b81a2399444d51fc234fdf1ed6363ad412fcef0c468aa7ecf0b526
|
|
| MD5 |
b8dde481b4117f2717a5876594f2a990
|
|
| BLAKE2b-256 |
17aacbe2cf8895958b8b2a541a04dfd1b67b3c91e10e4e0286cb5cd86b7aa327
|