Skip to content

Commit

Permalink
Merge pull request #1615 from NeuralEnsemble/black-formatting
Browse files Browse the repository at this point in the history
Black formatting
  • Loading branch information
zm711 authored Dec 15, 2024
2 parents 45ec350 + 4343a25 commit 49534ce
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
18 changes: 10 additions & 8 deletions neo/rawio/intanrawio.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def _parse_header(self):
self._block_size,
channel_number_dict,
) = read_rhd(self.filename, self.file_format)

#############################################
# memmap the raw data for each format type
#############################################
Expand Down Expand Up @@ -207,7 +207,6 @@ def _parse_header(self):
channel_file_paths = raw_file_paths_dict[stream_name]
channel_memmap_list = [np.memmap(fp, dtype=stream_dtype, mode="r") for fp in channel_file_paths]
self._raw_data[stream_name] = channel_memmap_list


# Data Integrity checks
# strictness of check is controlled by ignore_integrity_checks
Expand Down Expand Up @@ -747,12 +746,12 @@ def read_rhs(filename, file_format: str):

# Build a dictionary with channel count
special_cases_for_counting = [
"DC Amplifier channel",
"Stim channel",
"DC Amplifier channel",
"Stim channel",
]
names_to_count = [name for name in stream_names if name not in special_cases_for_counting]
channel_number_dict = {name: len(stream_name_to_channel_info_list[name]) for name in names_to_count}

# Both DC Amplifier and Stim streams have the same number of channels as the amplifier stream
channel_number_dict["DC Amplifier channel"] = channel_number_dict["RHS2000 amplifier channel"]
channel_number_dict["Stim channel"] = channel_number_dict["RHS2000 amplifier channel"]
Expand Down Expand Up @@ -1204,6 +1203,7 @@ def create_one_file_per_signal_dict_rhd(dirname):

return raw_file_paths_dict


stream_name_to_file_name_rhs = {
"RHS2000 amplifier channel": "amplifier.dat",
"RHS2000 auxiliary input channel": "auxiliary.dat",
Expand All @@ -1214,6 +1214,7 @@ def create_one_file_per_signal_dict_rhd(dirname):
"USB board digital output channel": "digitalout.dat",
}


def create_one_file_per_signal_dict_rhs(dirname):
"""Function for One File Per Signal Type
Expand Down Expand Up @@ -1275,10 +1276,10 @@ def create_one_file_per_channel_dict_rhd(dirname):
for stream_name, file_prefix in stream_name_to_file_prefix_rhd.items():
stream_files = [file for file in files if file_prefix in file.name]
# Map file name to channel name amp-A-000.dat -> A-000 amp-B-006.dat -> B-006 etc
file_path_to_channel_name = lambda x: '-'.join(x.stem.split('-')[1:])
file_path_to_channel_name = lambda x: "-".join(x.stem.split("-")[1:])
sorted_stream_files = sorted(stream_files, key=file_path_to_channel_name)
raw_file_paths_dict[stream_name] = sorted_stream_files

raw_file_paths_dict["timestamp"] = [Path(dirname / "time.dat")]
return raw_file_paths_dict

Expand All @@ -1294,6 +1295,7 @@ def create_one_file_per_channel_dict_rhd(dirname):
"USB board digital output channel": "board-DIGITAL-OUT",
}


def create_one_file_per_channel_dict_rhs(
dirname,
):
Expand All @@ -1316,7 +1318,7 @@ def create_one_file_per_channel_dict_rhs(
for stream_name, file_prefix in stream_name_to_file_prefix_rhs.items():
stream_files = [file for file in files if file_prefix in file.name]
# Map file name to channel name amp-A-000.dat -> A-000 amp-B-006.dat -> B-006 etc
file_path_to_channel_name = lambda x: '-'.join(x.stem.split('-')[1:])
file_path_to_channel_name = lambda x: "-".join(x.stem.split("-")[1:])
sorted_stream_files = sorted(stream_files, key=file_path_to_channel_name)
raw_file_paths_dict[stream_name] = sorted_stream_files

Expand Down
4 changes: 2 additions & 2 deletions neo/test/rawiotest/test_intanrawio.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ def test_annotations(self):
)
np.testing.assert_array_equal(signal_array_annotations["board_stream_num"][:10], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0])


def test_correct_reading_one_file_per_channel(self):
"Issue: https://github.com/NeuralEnsemble/python-neo/issues/1599"
# Test reading of one-file-per-channel format file. The channels should match the raw files
Expand All @@ -77,7 +76,7 @@ def test_correct_reading_one_file_per_channel(self):

# This should be the folder where the files of all the channels are stored
folder_path = file_path.parent

# The paths are named as amp-A-000.dat, amp-A-001.dat, amp-A-002.dat, ...
amplifier_file_paths = [path for path in folder_path.iterdir() if "amp" in path.name]
channel_names = [path.name[4:-4] for path in amplifier_file_paths]
Expand All @@ -87,5 +86,6 @@ def test_correct_reading_one_file_per_channel(self):
data_from_neo = intan_reader.get_analogsignal_chunk(channel_ids=[channel_name], stream_index=0).squeeze()
np.testing.assert_allclose(data_raw, data_from_neo)


if __name__ == "__main__":
unittest.main()

0 comments on commit 49534ce

Please sign in to comment.