Skip to content

Commit

Permalink
User/wbodo/add row names to analog (#498)
Browse files Browse the repository at this point in the history
  • Loading branch information
wbodo authored Jul 22, 2020
1 parent 255964a commit 9401bf1
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 11 deletions.
5 changes: 3 additions & 2 deletions rec_to_nwb/processing/nwb/components/analog/analog_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def create(cls, fl_analog, unit):
behavioral_events.add_timeseries(
AnalogCreator.__build_timeseries(
name='analog',
description=fl_analog.description,
data=fl_analog.data,
timestamps=fl_analog.timestamps,
unit=unit
Expand All @@ -27,9 +28,9 @@ def __create_behavioral_events():
return BehavioralEvents(name="analog")

@staticmethod
def __build_timeseries(name, data, timestamps, unit):
def __build_timeseries(name, description, data, timestamps, unit):
return TimeSeries(name=name,
description='-',
description=description,
data=data,
timestamps=timestamps,
unit=unit
Expand Down
5 changes: 3 additions & 2 deletions rec_to_nwb/processing/nwb/components/analog/fl_analog.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class FlAnalog:

def __init__(self, data, timestamps):
def __init__(self, data, timestamps, description):
self.data = data
self.timestamps = timestamps
self.timestamps = timestamps
self.description = description
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
class FlAnalogBuilder:

@staticmethod
def build(data, timestamps):
return FlAnalog(data, timestamps)
def build(data, timestamps, description):
return FlAnalog(data, timestamps, description)
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def extract_analog_for_single_dataset(analog_files, continuous_time_file):
if not 'timestamps' in analog_file:
analog_data = readTrodesExtractedDataFile(analog_files[analog_file])
values = analog_data['data']
single_dataset_data[analog_file] = values
single_dataset_data[analog_data['id']] = values
else:
continuous_time_dict = ContinuousTimeExtractor.get_continuous_time_dict_file(continuous_time_file)
timestamp = readTrodesExtractedDataFile(analog_files[analog_file])
Expand All @@ -29,3 +29,5 @@ def extract_analog_for_single_dataset(analog_files, continuous_time_file):
return single_dataset_data




15 changes: 12 additions & 3 deletions rec_to_nwb/processing/nwb/components/analog/fl_analog_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,26 @@ def get_analog(self) -> FlAnalog:
)
)
merged_epochs = self.__merge_epochs(all_analog_data)
description = self.__merge_row_description(all_analog_data)
analog_data = self.__merge_analog_sensors(merged_epochs)
return FlAnalogBuilder.build(analog_data, self.__get_timestamps(merged_epochs))
return FlAnalogBuilder.build(analog_data, self.__get_timestamps(merged_epochs), description)

@staticmethod
def __merge_epochs(data_from_multiple_datasets):
merged_epochs = data_from_multiple_datasets[0]
for single_dataset_data in data_from_multiple_datasets[1:]:
for analog_file in single_dataset_data.keys():
merged_epochs[analog_file] = np.hstack((merged_epochs[analog_file], single_dataset_data[analog_file]))
for row in single_dataset_data.keys():
merged_epochs[row] = np.hstack((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 = ''
for id in row_ids:
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]
Expand Down
2 changes: 1 addition & 1 deletion rec_to_nwb/test/processing/analog/test_analogCreator.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def setUp(self):
)

self.timestamp = numpy.array([1, 2, 3, 4])
self.fl_analog = FlAnalog(self.data, self.timestamp)
self.fl_analog = FlAnalog(self.data, self.timestamp, 'description')

def test_creator_create_analog_successfully(self):
analog = AnalogCreator.create(self.fl_analog, 'um')
Expand Down

0 comments on commit 9401bf1

Please sign in to comment.