Attribute error when loading ResponseAnalysis object
Closed this issue · 5 comments
This code:
import visual_behavior.data_access.loading as loading
from visual_behavior.ophys.response_analysis.response_analysis import ResponseAnalysis
oeid = 1048483610
dataset = loading.get_ophys_dataset(oeid, include_invalid_rois=False)
session = ResponseAnalysis(
dataset,
overwrite_analysis_files=False,
use_extended_stimulus_presentations=True,
dataframe_format = 'wide'
)
Results in:
unable to locate analysis folder for experiment 1048483610 in //allen/programs/braintv/workgroups/nc-ophys/visual_behavior/visual_behavior_production_analysis
creating new analysis folder
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-4-96de2b726cb3> in <module>
4 oeid = 1048483610
5 dataset = loading.get_ophys_dataset(oeid, include_invalid_rois=False)
----> 6 session = ResponseAnalysis(
7 dataset,
8 overwrite_analysis_files=False,
~/Code/visual_behavior_analysis/visual_behavior/ophys/response_analysis/response_analysis.py in __init__(self, dataset, analysis_cache_dir, load_from_cache, use_events, use_extended_stimulus_presentations, overwrite_analysis_files, dataframe_format)
80 self.dataset = dataset
81 # promote ophys timestamps up to the top level
---> 82 self.ophys_timestamps = self.dataset.ophys_timestamps # THROWS WARNING
83 # promote stimulus_presentations to the top level
84 self.stimulus_presentations = self.dataset.stimulus_presentations
~/Code/visual_behavior_analysis/visual_behavior/data_access/loading.py in ophys_timestamps(self)
382 def ophys_timestamps(self):
383 if super().metadata['rig_name'] == 'MESO.1':
--> 384 self._ophys_timestamps = self.timestamps['ophys_frames']['timestamps'].copy()
385 else:
386 self._ophys_timestamps = super().ophys_timestamps
~/Code/visual_behavior_analysis/visual_behavior/data_access/loading.py in timestamps(self)
376 # need to get full set of timestamps because SDK only provides stimulus and ophys timestamps (not eye tracking for example)
377 lims_data = utilities.get_lims_data(self.ophys_experiment_id)
--> 378 self._timestamps = utilities.get_timestamps(lims_data, self.analysis_dir)
379 return self._timestamps
380
~/Code/visual_behavior_analysis/visual_behavior/data_access/loading.py in analysis_dir(self)
289 @property
290 def analysis_dir(self):
--> 291 self._analysis_dir = os.path.join(get_analysis_cache_dir(), self.analysis_folder)
292 return self._analysis_dir
293
~/Code/visual_behavior_analysis/visual_behavior/data_access/loading.py in analysis_folder(self)
275 analysis_cache_dir))
276 print('creating new analysis folder')
--> 277 m = self.dataset.metadata
278 date = m['experiment_datetime']
279 date = str(date)[:10]
AttributeError: 'BehaviorOphysDataset' object has no attribute 'dataset'
This doesn't fail for all sesssions. For example, substituting oeid = 974945686 results in a ResponseAnalysis object that is loaded without error.
It seems that this fails for sessions that do not have an existing folder at this path:
'//allen/programs/braintv/workgroups/nc-ophys/visual_behavior/visual_behavior_production_analysis'
I'm not clear how the folders at that path are being created.
More breadcrumbs...
The issue is ultimately due to this line (the lowest line in the traceback above):
The problem is that self
in this namespace is the BehaviorOphysDataset
object, which does not have a dataset
attribute. Only the ResponseAnalysis
object has a dataset
attribute.
I'm having trouble identifying when this line was added in the git blame. It seems like it should fail for all experiments. The reason it's only failing for some sessions is that this line is skipped altogether if the experiment already has a folder in the analysis cache folder.
Given that self is the BehaviorOphysDataset, it seems that line 277 should read self.metadata
instead of self.dataset.metdata
. @matchings suggested the same in a slack thread.
However, making that change results in a recursive loop that reaches the maximum recursion depth, then crashes the kernel
The recursive loop is caused by the extra call to the timestamps property while generating the folder. Removing the special case for mesoscope fixes that.
addressed with PR #683