-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Intan loader #76
Open
tdincer
wants to merge
34
commits into
datajoint:main
Choose a base branch
from
tdincer:intan
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add Intan loader #76
Changes from 33 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
15f4086
working example
tdincer 47befa3
code cleaning
tdincer 1c1b169
add time unit
tdincer 5b41b0a
read data based on the data type manual
tdincer c3f4540
return header as well
tdincer b7d1d70
read other files as well
tdincer 1e1abae
Merge pull request #73 from tdincer/intan
JaerongA f44416f
refactor: :art: streamline the code
JaerongA 500ca38
Update docstring
JaerongA fc5839f
remove unnecessary print statements
JaerongA d8cff9b
apply regex to filter data files
JaerongA 30960f5
Update element_interface/intan_loader.py
JaerongA 0d251e9
dtype=np.uint16 for some signal types
JaerongA e8d31c4
revert regex filtering
JaerongA 10f5e0e
suggestions from code review
JaerongA 661b705
Update element_interface/intan_loader.py
JaerongA c41260d
add a comment for the conversion fix
JaerongA 8b14781
Update element_interface/intan_loader.py
tdincer 9f2221f
Update element_interface/intan_loader.py
JaerongA 283aac3
allow reading only info and timestamps
JaerongA eb4d611
Merge pull request #75 from JaerongA/intan
tdincer 575b8e9
fix empty file_path
tdincer d1c9c1c
version bump
tdincer 081ed02
remove the condition before if
tdincer 449712a
add source reference
tdincer 3d056f2
single file loader
tdincer 1f99827
add code source
tdincer 1fe2997
Update element_interface/intanloader/rhsutilities.py
tdincer ec59cff
output header
JaerongA 947d27b
change import
tdincer 50caa0e
Merge branch 'intan' of https://github.com/tdincer/element-interface …
tdincer 00c9ac7
remove module
tdincer e2819d6
blackify
tdincer 791ef09
Merge branch 'main' into intan
dimitri-yatsenko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import numpy as np | ||
from pathlib import Path | ||
from intanrhsreader import read_header | ||
|
||
|
||
def load_rhs(folder: str, file_expr: str = "*"): | ||
"""Load rhs data | ||
|
||
Data type and coversions are based on https://intantech.com/files/Intan_RHS2000_data_file_formats.pdf. | ||
|
||
Example: | ||
# Read data | ||
>>> rhs_data = load_rhs("/home/inbox/organoids21/032520_US_885kHz_sham", file_expr="amp*dat") | ||
|
||
# Plot data | ||
>>> import matplotlib.pyplot as plt | ||
>>> plt.plot(rhs_data["time"], rhs_data["recordings"]["amp-B-000.dat"]) | ||
>>> plt.xlabel("Time (s)") | ||
>>> plt.ylabel("Reading") | ||
>>> plt.show() | ||
|
||
Args: | ||
folder (str): Folder that contains info.rhs, time.dat, and *.dat files | ||
file_expr (str): pattern matching of file names to be read. Defaults to "*" (read all files). | ||
|
||
Returns: | ||
rhs_data (dict): RHS data. | ||
rhs_data["header"] (dict): Header. | ||
rhs_data["recordings"] (dict): Readings from various files | ||
rhs_data["timestamps"] (np.array_like): Relative timestamps in seconds. | ||
""" | ||
|
||
rhs_data = {} | ||
|
||
# Get header | ||
header_filepath = next(Path(folder).glob("info.rhs")) | ||
with open(header_filepath, "rb") as fid: | ||
rhs_data["header"] = read_header(fid) | ||
|
||
# Get timestamps | ||
time_file = next(Path(folder).glob("time.dat")) | ||
|
||
rhs_data["timestamps"] = ( | ||
np.memmap(time_file, dtype=np.int32) | ||
/ rhs_data["header"]["frequency_parameters"]["amplifier_sample_rate"] | ||
) | ||
|
||
# Get data files | ||
file_paths = Path(folder).glob(file_expr) | ||
|
||
exclude_list = ["time", "info", "Zone.Identifier"] | ||
|
||
file_paths = [ | ||
file | ||
for file in file_paths | ||
if not any(string in file.as_posix() for string in exclude_list) | ||
] | ||
|
||
# Get recording data | ||
rhs_data["recordings"] = {} | ||
|
||
for file_path in sorted(file_paths): | ||
signal_type = file_path.stem.split("-")[0] | ||
|
||
if signal_type == "amp": | ||
signal = np.memmap(file_path, dtype=np.int16) | ||
signal = signal * 0.195 # Convert to microvolts | ||
|
||
elif signal_type == "board": | ||
signal = np.memmap(file_path, dtype=np.uint16) | ||
signal = (signal - 32768) * 0.0003125 # Convert to volts | ||
|
||
elif signal_type == "dc": | ||
signal = np.memmap(file_path, dtype=np.uint16) | ||
signal = (signal - 512) * 19.23 # Convert to milivolts | ||
|
||
elif signal_type == "stim": | ||
signal = np.memmap(file_path, dtype=np.uint16) | ||
# convert the signal from 9-bit one's complement to standard encoding | ||
current = np.bitwise_and(signal, 255) * rhs_data["header"]["stim_step_size"] | ||
sign = 1 - np.bitwise_and(signal, 256) // 128 | ||
signal = current * sign | ||
|
||
rhs_data["recordings"][file_path.stem] = signal | ||
return rhs_data |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
"""Package metadata""" | ||
|
||
__version__ = "0.5.0" | ||
__version__ = "0.6.0" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fudge factors. Please turn into named constants.