File tree Expand file tree Collapse file tree 4 files changed +45
-2
lines changed
brain_observatory/behavior Expand file tree Collapse file tree 4 files changed +45
-2
lines changed Original file line number Diff line number Diff line change 11import numpy as np
22import pandas as pd
33import xarray as xr
4- from typing import Any
4+ from typing import Any , Optional
55import logging
66
77
@@ -98,6 +98,13 @@ def ophys_experiment_id(self) -> int:
9898 """
9999 return self .api .get_ophys_experiment_id ()
100100
101+ @property
102+ def behavior_session_id (self ) -> Optional [int ]:
103+ """Returns the unique identifier for the behavior session
104+ associated with this experiment, if applicable.
105+ """
106+ return self .api .get_behavior_session_id ()
107+
101108 @property
102109 def max_projection (self ) -> Image :
103110 """2D max projection image.
Original file line number Diff line number Diff line change @@ -14,6 +14,13 @@ class BehaviorBase(abc.ABC):
1414 Child classes should be instantiated with a fetch API that implements these
1515 methods.
1616 """
17+ @abc .abstractmethod
18+ def get_behavior_session_id (self ) -> int :
19+ """Returns the behavior_session_id associated with this experiment,
20+ if applicable.
21+ """
22+ raise NotImplementedError ()
23+
1724 @abc .abstractmethod
1825 def get_licks (self ) -> pd .DataFrame :
1926 """Get lick data from pkl file.
Original file line number Diff line number Diff line change 11import abc
2+ from typing import Optional
23
34import numpy as np
45import pandas as pd
@@ -12,8 +13,16 @@ class BehaviorOphysBase(BehaviorBase):
1213 behavior+ophys session data.
1314
1415 Child classes should be instantiated with a fetch API that implements these
15- methods. Both fetch API and session object should inherit from this base.
16+ methods.
1617 """
18+
19+ @abc .abstractmethod
20+ def get_ophys_session_id (self ) -> Optional [int ]:
21+ """Returns the ophys_session_id associated with this experiment,
22+ if applicable.
23+ """
24+ raise NotImplementedError ()
25+
1726 @abc .abstractmethod
1827 def get_average_projection (self ) -> Image :
1928 """Get an image whose values are the average obtained values at
Original file line number Diff line number Diff line change @@ -83,6 +83,26 @@ def get_imaging_plane_group(self) -> Optional[int]:
8383 else :
8484 return None
8585
86+ @memoize
87+ def get_behavior_session_id (self ) -> Optional [int ]:
88+ """Returns the behavior_session_id associated with this experiment,
89+ if applicable.
90+ """
91+ query = f"""
92+ SELECT bs.id
93+ FROM ophys_experiments oe
94+ -- every ophys_experiment should have an ophys_session
95+ JOIN ophys_sessions os ON oe.ophys_session_id = os.id
96+ -- but not every ophys_session has a behavior_session
97+ LEFT JOIN behavior_sessions bs ON os.id = bs.ophys_session_id
98+ WHERE oe.id = { self .get_ophys_experiment_id ()}
99+ """
100+ response = self .lims_db .fetchall (query ) # Can be null
101+ if not len (response ):
102+ return None
103+ else :
104+ return response [0 ]
105+
86106 @memoize
87107 def get_ophys_experiment_dir (self ):
88108 query = '''
You can’t perform that action at this time.
0 commit comments