Skip to content

Commit

Permalink
added docstring and reformatted average_container_depth query
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejhuang committed Nov 14, 2022
1 parent b6d9d21 commit f2b35fe
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ class AverageContainerDepth(
NwbReadableInterface,
JsonReadableInterface,
):
"""Data object loads and stores the average `imaging_depth`s
(microns) across experiments in the container that an experiment is
associated with.
"""
def __init__(self, average_container_depth: int):
super().__init__(
name="average_container_depth", value=average_container_depth
Expand All @@ -30,19 +34,16 @@ def from_lims(
container_id = lims_db.fetchone(query_container_id, strict=True)

query_depths = """
SELECT id.depth
SELECT AVG(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
LEFT JOIN imaging_depths imd ON imd.id = oe.imaging_depth_id
WHERE ec.visual_behavior_experiment_container_id = {};
""".format(
container_id
)

imaging_depths = lims_db.fetchall(query_depths)
average_container_depth = round(sum(imaging_depths) /
len(imaging_depths))
average_container_depth = lims_db.fetchone(query_depths)
return cls(average_container_depth=average_container_depth)

@classmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

class ImagingDepth(DataObject, LimsReadableInterface, NwbReadableInterface,
JsonReadableInterface):
"""Data object loads and stores the imaging_depth (microns) for an
experiments. This is the calculated difference between measured
z-depths of the surface and imaging_depth.
"""
def __init__(self, imaging_depth: int):
super().__init__(name='imaging_depth', value=imaging_depth)

Expand All @@ -18,7 +22,7 @@ def from_lims(cls, ophys_experiment_id: int,
SELECT id.depth
FROM ophys_experiments oe
JOIN ophys_sessions os ON oe.ophys_session_id = os.id
LEFT JOIN imaging_depths id ON id.id = oe.imaging_depth_id
LEFT JOIN imaging_depths imd ON imd.id = oe.imaging_depth_id
WHERE oe.id = {};
""".format(ophys_experiment_id)
imaging_depth = lims_db.fetchone(query, strict=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ def _get_multiplane_meta(self):
ophys_container_id=ophys_experiment_metadata._ophys_container_id,
field_of_view_shape=ophys_experiment_metadata._field_of_view_shape,
imaging_depth=ophys_experiment_metadata._imaging_depth,
average_container_depth=ophys_experiment_metadata._average_container_depth, # noqa E501
average_container_depth=ophys_experiment_metadata.
_average_container_depth,
project_code=ophys_experiment_metadata._project_code,
imaging_plane_group=imaging_plane_group
)
Expand Down

0 comments on commit f2b35fe

Please sign in to comment.