-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cfbd2db
commit c7be0aa
Showing
9 changed files
with
112 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 33 additions & 24 deletions
57
...ervatory/behavior/data_objects/metadata/ophys_experiment_metadata/target_imaging_depth.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,54 @@ | ||
from pynwb import NWBFile | ||
|
||
from allensdk.core import DataObject | ||
from allensdk.core import \ | ||
JsonReadableInterface, LimsReadableInterface, NwbReadableInterface | ||
from allensdk.core import DataObject, JsonReadableInterface, LimsReadableInterface, NwbReadableInterface # NOQA | ||
from allensdk.internal.api import PostgresQueryMixin | ||
|
||
|
||
class TargetImagingDepth(DataObject, LimsReadableInterface, NwbReadableInterface, | ||
JsonReadableInterface): | ||
class TargetImagingDepth( | ||
DataObject, | ||
LimsReadableInterface, | ||
NwbReadableInterface, | ||
JsonReadableInterface, | ||
): | ||
def __init__(self, target_imaging_depth: int): | ||
super().__init__(name='target_imaging_depth', value=target_imaging_depth) | ||
super().__init__( | ||
name="target_imaging_depth", value=target_imaging_depth | ||
) | ||
|
||
@classmethod | ||
def from_lims(cls, ophys_experiment_id: int, | ||
lims_db: PostgresQueryMixin) -> "TargetImagingDepth": | ||
def from_lims( | ||
cls, ophys_experiment_id: int, lims_db: PostgresQueryMixin | ||
) -> "TargetImagingDepth": | ||
query_container_id = """ | ||
SELECT visual_behavior_experiment_container_id | ||
FROM ophys_experiments_visual_behavior_experiment_containers | ||
WHERE ophys_experiment_id = {} | ||
""".format(ophys_experiment_id) | ||
|
||
SELECT visual_behavior_experiment_container_id | ||
FROM ophys_experiments_visual_behavior_experiment_containers | ||
WHERE ophys_experiment_id = {} | ||
""".format( | ||
ophys_experiment_id | ||
) | ||
|
||
container_id = lims_db.fetchone(query_container_id, strict=True) | ||
|
||
query_depths = """ | ||
SELECT id.depth | ||
FROM ophys_experiments_visual_behavior_experiment_containers ec | ||
JOIN ophys_experiments oe ON oe.id = ec.ophys_experiment_id | ||
JOIN ophys_sessions os ON oe.ophys_session_id = os.id | ||
LEFT JOIN imaging_depths id ON id.id = oe.imaging_depth_id | ||
WHERE ec.visual_behavior_experiment_container_id = {}; | ||
""".format(container_id) | ||
|
||
SELECT id.depth | ||
FROM ophys_experiments_visual_behavior_experiment_containers ec | ||
JOIN ophys_experiments oe ON oe.id = ec.ophys_experiment_id | ||
JOIN ophys_sessions os ON oe.ophys_session_id = os.id | ||
LEFT JOIN imaging_depths id ON id.id = oe.imaging_depth_id | ||
WHERE ec.visual_behavior_experiment_container_id = {}; | ||
""".format( | ||
container_id | ||
) | ||
|
||
imaging_depths = lims_db.fetchall(query_depths) | ||
target_imaging_depth = sum(imaging_depths)/len(imaging_depths) | ||
target_imaging_depth = sum(imaging_depths) / len(imaging_depths) | ||
return cls(target_imaging_depth=target_imaging_depth) | ||
|
||
@classmethod | ||
def from_json(cls, dict_repr: dict) -> "TargetImagingDepth": | ||
return cls(target_imaging_depth=dict_repr['targeted_imaging_depth']) | ||
return cls(target_imaging_depth=dict_repr["targeted_imaging_depth"]) | ||
|
||
@classmethod | ||
def from_nwb(cls, nwbfile: NWBFile) -> "TargetImagingDepth": | ||
metadata = nwbfile.lab_meta_data['metadata'] | ||
metadata = nwbfile.lab_meta_data["metadata"] | ||
return cls(target_imaging_depth=metadata.target_imaging_depth) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.