Skip to content

Commit

Permalink
Merge pull request #55 from samuelbray32/fix_analog_name_overlap
Browse files Browse the repository at this point in the history
Fix analog name overlap
  • Loading branch information
edeno authored Aug 18, 2023
2 parents 653fa96 + 85cd84a commit 6edf70c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 25 deletions.
8 changes: 5 additions & 3 deletions rec_to_nwb/processing/nwb/components/analog/analog_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@


class AnalogFiles:

def __init__(self, directories):
self.directories = directories

Expand All @@ -13,7 +12,10 @@ def get_files(self):
@classmethod
def __get_dict(cls, directory):
analog_dict = {}
for file in glob.glob(os.path.join(directory, '*.dat')):
analog_name = file.split('.')[-2].split('_')[-1]
for file in glob.glob(os.path.join(directory, "*.dat")):
if "timestamps" in file:
analog_name = "timestamps"
else:
analog_name = file.split(".")[-2]
analog_dict[analog_name] = os.path.join(directory, file)
return analog_dict
52 changes: 30 additions & 22 deletions rec_to_nwb/processing/nwb/components/analog/fl_analog_manager.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
import numpy as np
from rec_to_nwb.processing.nwb.components.analog.fl_analog import FlAnalog
from rec_to_nwb.processing.nwb.components.analog.fl_analog_builder import \
FlAnalogBuilder
from rec_to_nwb.processing.nwb.components.analog.fl_analog_extractor import \
FlAnalogExtractor
from rec_to_nwb.processing.nwb.components.analog.fl_analog_builder import (
FlAnalogBuilder,
)
from rec_to_nwb.processing.nwb.components.analog.fl_analog_extractor import (
FlAnalogExtractor,
)
from rec_to_nwb.processing.tools.beartype.beartype import beartype
from rec_to_nwb.processing.tools.validate_parameters import \
validate_parameters_equal_length
from rec_to_nwb.processing.tools.validate_parameters import (
validate_parameters_equal_length,
)


class FlAnalogManager:

@beartype
def __init__(self, analog_files: list,
continuous_time_files: list,
convert_timestamps: bool = True,
return_timestamps: bool = True,
):
validate_parameters_equal_length(
__name__, analog_files, continuous_time_files)
def __init__(
self,
analog_files: list,
continuous_time_files: list,
convert_timestamps: bool = True,
return_timestamps: bool = True,
):
validate_parameters_equal_length(__name__, analog_files, continuous_time_files)

self.analog_files = analog_files
self.continuous_time_files = continuous_time_files
Expand All @@ -27,7 +30,7 @@ def __init__(self, analog_files: list,

@beartype
def get_analog(self) -> FlAnalog:
""""extract data from analog files"""
"""extract data from analog files"""

all_analog_data = []
number_of_datasets = len(self.analog_files)
Expand All @@ -36,7 +39,7 @@ def get_analog(self) -> FlAnalog:
FlAnalogExtractor.extract_analog_for_single_dataset(
self.analog_files[i],
self.continuous_time_files[i],
convert_timestamps=self.convert_timestamps
convert_timestamps=self.convert_timestamps,
)
)
merged_epochs = self.__merge_epochs(all_analog_data)
Expand All @@ -55,27 +58,32 @@ def __merge_epochs(data_from_multiple_datasets):
for single_dataset_data in data_from_multiple_datasets[1:]:
for row in single_dataset_data.keys():
merged_epochs[row] = np.hstack(
(merged_epochs[row], single_dataset_data[row]))
(merged_epochs[row], single_dataset_data[row])
)
return merged_epochs

@staticmethod
def __merge_row_description(data_from_multiple_datasets):
row_ids = data_from_multiple_datasets[0].keys()
description = ''
description = ""
for id in row_ids:
description += id + ' '
if "timestamp" not in id:
description += id + " "
return description

@classmethod
def __merge_analog_sensors(cls, merged_epochs):
analog_sensors = [merged_epochs[analog_sensor] for analog_sensor in merged_epochs.keys() if
'timestamp' not in analog_sensor]
analog_sensors = [
merged_epochs[analog_sensor]
for analog_sensor in merged_epochs.keys()
if "timestamp" not in analog_sensor
]
merged_analog_sensors = np.array(analog_sensors, np.int32)
transposed_analog_data = np.ndarray.transpose(merged_analog_sensors)
return transposed_analog_data

@classmethod
def __get_timestamps(cls, merged_epochs):
for analog_sensor in merged_epochs.keys():
if 'timestamps' in analog_sensor:
if "timestamps" in analog_sensor:
return merged_epochs[analog_sensor]

0 comments on commit 6edf70c

Please sign in to comment.