LorenFrankLab / rec_to_nwb

Data Migration REC -> NWB 2.0 Service
Other
2 stars 8 forks source link

Attribute error when getting unique timestamps #25

Closed acomrie closed 2 years ago

acomrie commented 2 years ago

I ran into this error after pulling the latest commit that looks for unique pos timestamps. Please see debugging and traceback below. Looks like you might be trying to do a data conversion here as well @edeno so I'm not sure what your preferred fix is. Alternatively, if this did not arise in others' testing and is an issue on my end, any thoughts on what might be going on are greatly appreciated. Thanks much.

Error: 'numpy.ndarray' object has no attribute 'to_numpy'

Debugging:

/home/alison/Src/rec_to_nwb/rec_to_nwb/processing/nwb/components/position/pos_timestamp_manager.py(35)_get_timestamps() 33 self.directories[dataset_id][0]) 34 position = pd.DataFrame(pos_online['data']) ---> 35 return position.time.unique().to_numpy(dtype='int64') 36 37 def retrieve_real_timestamps(self, dataset_id):

ipdb> position.time.unique()

array([37429635, 37430514, 37431434, ..., 91520405, 91521307, 91522500], dtype=uint32)

ipdb> position.time.unique().to_numpy()

*** AttributeError: 'numpy.ndarray' object has no attribute 'to_numpy'

Traceback:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/tmp/ipykernel_3965895/3392245823.py in <module>
     36                               video_path=video_path,
     37                               trodes_rec_export_args = trodes_rec_export_args)
---> 38         content = builder.build_nwb()
     39         print(content) #just to look
     40         # Automatically delete preprocessing files? Not for this guy given old pipeline use still

~/Src/rec_to_nwb/rec_to_nwb/processing/builder/raw_to_nwb_builder.py in build_nwb(self, run_preprocessing, process_mda_valid_time, process_mda_invalid_time, process_pos_valid_time, process_pos_invalid_time)
    224             process_mda_invalid_time=process_mda_invalid_time,
    225             process_pos_valid_time=process_pos_valid_time,
--> 226             process_pos_invalid_time=process_pos_invalid_time)
    227         logger.info('Done...\n')
    228 

~/Src/rec_to_nwb/rec_to_nwb/processing/builder/raw_to_nwb_builder.py in __build_nwb_file(self, process_mda_valid_time, process_mda_invalid_time, process_pos_valid_time, process_pos_invalid_time)
    238             logger.info('Date: {}'.format(date))
    239             nwb_builder = self.get_nwb_builder(date)
--> 240             content = nwb_builder.build()
    241             nwb_builder.write(content)
    242             if self.is_old_dataset:

~/Src/rec_to_nwb/rec_to_nwb/processing/builder/nwb_file_builder.py in build(self)
    375             self.associated_files_originator.make(nwb_content)
    376 
--> 377         self.position_originator.make(nwb_content)
    378 
    379         valid_map_dict = self.__build_corrupted_data_manager()

~/Src/rec_to_nwb/rec_to_nwb/processing/tools/beartype/beartype.py in func_beartyped(__beartype_func, *args, **kwargs)

~/Src/rec_to_nwb/rec_to_nwb/processing/builder/originators/position_originator.py in make(self, nwb_content)
     34     def make(self, nwb_content: NWBFile):
     35         logger.info('Position: Building')
---> 36         fl_positions = self.fl_position_manager.get_fl_positions()
     37         logger.info('Position: Creating')
     38         position = self.position_creator.create_all(fl_positions)

~/Src/rec_to_nwb/rec_to_nwb/processing/tools/beartype/beartype.py in func_beartyped(__beartype_func, *args, **kwargs)

~/Src/rec_to_nwb/rec_to_nwb/processing/nwb/components/position/fl_position_manager.py in get_fl_positions(self)
     35         columns_labels = self.fl_position_extractor.get_columns_labels()
     36         if self.process_timestamps:
---> 37             timestamps = self.fl_position_extractor.get_timestamps()
     38 
     39             validate_parameters_equal_length(

~/Src/rec_to_nwb/rec_to_nwb/processing/nwb/components/position/fl_position_extractor.py in get_timestamps(self)
     70             for position_directory, continuous_time_directory in zip(
     71                 self.all_position_directories,
---> 72                 self.continuous_time_directories)
     73         ]

~/Src/rec_to_nwb/rec_to_nwb/processing/nwb/components/position/fl_position_extractor.py in <listcomp>(.0)
     68                     convert_timestamps=self.convert_timestamps
     69                 ))
---> 70             for position_directory, continuous_time_directory in zip(
     71                 self.all_position_directories,
     72                 self.continuous_time_directories)

~/Src/rec_to_nwb/rec_to_nwb/processing/nwb/components/position/pos_timestamp_manager.py in __init__(self, directories, continuous_time_directories, convert_timestamps)
     24                  convert_timestamps=True):
     25         TimestampManager.__init__(
---> 26             self, directories, continuous_time_directories)
     27         self.convert_timestamps = convert_timestamps
     28 

~/Src/rec_to_nwb/rec_to_nwb/processing/nwb/common/timestamps_manager.py in __init__(self, directories, continuous_time_directories)
     25 
     26         self.number_of_datasets = self._get_number_of_datasets()
---> 27         self.file_lengths_in_datasets = self.__calculate_file_lengths_in_datasets()
     28 
     29     @abc.abstractmethod

~/Src/rec_to_nwb/rec_to_nwb/processing/nwb/common/timestamps_manager.py in __calculate_file_lengths_in_datasets(self)
     52 
     53     def __calculate_file_lengths_in_datasets(self):
---> 54         return [self._get_data_shape(i) for i in range(self.number_of_datasets)]
     55 
     56     def _get_number_of_datasets(self):

~/Src/rec_to_nwb/rec_to_nwb/processing/nwb/common/timestamps_manager.py in <listcomp>(.0)
     52 
     53     def __calculate_file_lengths_in_datasets(self):
---> 54         return [self._get_data_shape(i) for i in range(self.number_of_datasets)]
     55 
     56     def _get_number_of_datasets(self):

~/Src/rec_to_nwb/rec_to_nwb/processing/nwb/common/timestamps_manager.py in _get_data_shape(self, dataset_num)
     58 
     59     def _get_data_shape(self, dataset_num):
---> 60         return np.shape(self.read_timestamps_ids(dataset_num))[0]

~/Src/rec_to_nwb/rec_to_nwb/processing/nwb/common/timestamps_manager.py in read_timestamps_ids(self, dataset_id)
     40 
     41     def read_timestamps_ids(self, dataset_id):
---> 42         return self._get_timestamps(dataset_id)
     43 
     44     def get_final_data_shape(self):

~/Src/rec_to_nwb/rec_to_nwb/processing/nwb/components/position/pos_timestamp_manager.py in _get_timestamps(self, dataset_id)
     33             self.directories[dataset_id][0])
     34         position = pd.DataFrame(pos_online['data'])
---> 35         return position.time.unique().to_numpy(dtype='int64')
     36 
     37     def retrieve_real_timestamps(self, dataset_id):

AttributeError: 'numpy.ndarray' object has no attribute 'to_numpy'
edeno commented 2 years ago

This should not be relevant anymore given the new position pipeline processing.