Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejhuang committed Nov 10, 2022
1 parent cfbd2db commit c7be0aa
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 189 deletions.
51 changes: 15 additions & 36 deletions allensdk/brain_observatory/behavior/behavior_ophys_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,22 @@
import pandas as pd
from pynwb import NWBFile

from allensdk.brain_observatory.behavior.behavior_session import (
BehaviorSession)
from allensdk.brain_observatory.behavior.behavior_session import BehaviorSession # NOQA
from allensdk.brain_observatory.behavior.data_files import SyncFile
from allensdk.brain_observatory.behavior.data_files\
.rigid_motion_transform_file import \
RigidMotionTransformFile
from allensdk.brain_observatory.behavior.data_objects import \
BehaviorSessionId
from allensdk.brain_observatory.behavior.data_objects.cell_specimens \
.cell_specimens import \
CellSpecimens, EventsParams
from allensdk.brain_observatory.behavior.data_objects.metadata \
.behavior_metadata.date_of_acquisition import \
DateOfAcquisitionOphys, DateOfAcquisition
from allensdk.brain_observatory.behavior.data_objects.metadata\
.behavior_ophys_metadata import \
BehaviorOphysMetadata
from allensdk.brain_observatory.behavior.data_objects.metadata\
.ophys_experiment_metadata.multi_plane_metadata.imaging_plane_group \
import \
ImagingPlaneGroup
from allensdk.brain_observatory.behavior.data_objects.metadata\
.ophys_experiment_metadata.multi_plane_metadata.multi_plane_metadata \
import \
MultiplaneMetadata
from allensdk.brain_observatory.behavior.data_objects.motion_correction \
import \
MotionCorrection
from allensdk.brain_observatory.behavior.data_objects.projections import \
Projections
from allensdk.brain_observatory.behavior.data_objects.stimuli.util import \
calculate_monitor_delay
from allensdk.brain_observatory.behavior.data_objects.timestamps \
.ophys_timestamps import \
OphysTimestamps, OphysTimestampsMultiplane
from allensdk.brain_observatory.behavior.data_files.rigid_motion_transform_file import RigidMotionTransformFile # NOQA
from allensdk.brain_observatory.behavior.data_objects import BehaviorSessionId
from allensdk.brain_observatory.behavior.data_objects.cell_specimens.cell_specimens import CellSpecimens, EventsParams # NOQA
from allensdk.brain_observatory.behavior.data_objects.metadata.behavior_metadata.date_of_acquisition import DateOfAcquisition, DateOfAcquisitionOphys # NOQA
from allensdk.brain_observatory.behavior.data_objects.metadata.behavior_ophys_metadata import BehaviorOphysMetadata # NOQA
from allensdk.brain_observatory.behavior.data_objects.metadata.ophys_experiment_metadata.multi_plane_metadata.imaging_plane_group import ImagingPlaneGroup # NOQA
from allensdk.brain_observatory.behavior.data_objects.metadata.ophys_experiment_metadata.multi_plane_metadata.multi_plane_metadata import MultiplaneMetadata # NOQA
from allensdk.brain_observatory.behavior.data_objects.motion_correction import MotionCorrection # NOQA
from allensdk.brain_observatory.behavior.data_objects.projections import Projections # NOQA
from allensdk.brain_observatory.behavior.data_objects.stimuli.util import calculate_monitor_delay # NOQA
from allensdk.brain_observatory.behavior.data_objects.timestamps.ophys_timestamps import OphysTimestamps, OphysTimestampsMultiplane # NOQA
from allensdk.brain_observatory.behavior.image_api import Image
from allensdk.core.auth_config import LIMS_DB_CREDENTIAL_MAP
from allensdk.deprecated import legacy
from allensdk.brain_observatory.behavior.image_api import Image
from allensdk.internal.api import db_connection_creator


Expand Down Expand Up @@ -426,7 +404,8 @@ def metadata(self):
'field_of_view_width':
self._metadata.ophys_metadata.field_of_view_shape.width,
'imaging_depth': self._metadata.ophys_metadata.imaging_depth,
'target_imaging_depth': self._metadata.ophys_metadata.target_imaging_depth,
'target_imaging_depth':
self._metadata.ophys_metadata.target_imaging_depth,
'imaging_plane_group':
self._metadata.ophys_metadata.imaging_plane_group
if isinstance(self._metadata.ophys_metadata,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,13 @@

from pynwb import NWBFile

from allensdk.core import DataObject
from allensdk.brain_observatory.behavior.data_objects import BehaviorSessionId
from allensdk.core import \
JsonReadableInterface, NwbReadableInterface, \
LimsReadableInterface
from allensdk.core import \
NwbWritableInterface
from allensdk.brain_observatory.behavior.data_objects.metadata\
.behavior_metadata.behavior_metadata import \
BehaviorMetadata
from allensdk.brain_observatory.behavior.data_objects.metadata\
.ophys_experiment_metadata.multi_plane_metadata\
.multi_plane_metadata import \
MultiplaneMetadata
from allensdk.brain_observatory.behavior.data_objects.metadata\
.ophys_experiment_metadata.ophys_experiment_metadata import \
OphysExperimentMetadata
from allensdk.brain_observatory.behavior.schemas import \
OphysBehaviorMetadataSchema
from allensdk.brain_observatory.behavior.data_objects.metadata.behavior_metadata.behavior_metadata import BehaviorMetadata # NOQA
from allensdk.brain_observatory.behavior.data_objects.metadata.ophys_experiment_metadata.multi_plane_metadata.multi_plane_metadata import MultiplaneMetadata # NOQA
from allensdk.brain_observatory.behavior.data_objects.metadata.ophys_experiment_metadata.ophys_experiment_metadata import OphysExperimentMetadata # NOQA
from allensdk.brain_observatory.behavior.schemas import OphysBehaviorMetadataSchema # NOQA
from allensdk.brain_observatory.nwb import load_pynwb_extension
from allensdk.core import DataObject, JsonReadableInterface, LimsReadableInterface, NwbReadableInterface, NwbWritableInterface # NOQA
from allensdk.internal.api import PostgresQueryMixin


Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,13 @@
from pynwb import NWBFile

from allensdk.brain_observatory.behavior.data_objects.metadata \
.ophys_experiment_metadata.ophys_container_id import \
OphysContainerId
from allensdk.brain_observatory.behavior.data_objects.metadata \
.ophys_experiment_metadata.field_of_view_shape import \
FieldOfViewShape
from allensdk.brain_observatory.behavior.data_objects.metadata \
.ophys_experiment_metadata.imaging_depth import \
ImagingDepth
from allensdk.brain_observatory.behavior.data_objects.metadata \
.ophys_experiment_metadata.target_imaging_depth import \
TargetImagingDepth
from allensdk.brain_observatory.behavior.data_objects.metadata \
.ophys_experiment_metadata.multi_plane_metadata \
.imaging_plane_group import \
ImagingPlaneGroup
from allensdk.brain_observatory.behavior.data_objects.metadata \
.ophys_experiment_metadata.ophys_experiment_metadata import \
OphysExperimentMetadata
from allensdk.brain_observatory.behavior.data_objects.metadata \
.ophys_experiment_metadata.ophys_session_id import \
OphysSessionId
from allensdk.brain_observatory.behavior.data_objects.metadata \
.ophys_experiment_metadata.project_code import \
ProjectCode
from allensdk.brain_observatory.behavior.data_objects.metadata.ophys_experiment_metadata.field_of_view_shape import FieldOfViewShape # NOQA
from allensdk.brain_observatory.behavior.data_objects.metadata.ophys_experiment_metadata.imaging_depth import ImagingDepth # NOQA
from allensdk.brain_observatory.behavior.data_objects.metadata.ophys_experiment_metadata.multi_plane_metadata.imaging_plane_group import ImagingPlaneGroup # NOQA
from allensdk.brain_observatory.behavior.data_objects.metadata.ophys_experiment_metadata.ophys_container_id import OphysContainerId # NOQA
from allensdk.brain_observatory.behavior.data_objects.metadata.ophys_experiment_metadata.ophys_experiment_metadata import OphysExperimentMetadata # NOQA
from allensdk.brain_observatory.behavior.data_objects.metadata.ophys_experiment_metadata.ophys_session_id import OphysSessionId # NOQA
from allensdk.brain_observatory.behavior.data_objects.metadata.ophys_experiment_metadata.project_code import ProjectCode # NOQA
from allensdk.brain_observatory.behavior.data_objects.metadata.ophys_experiment_metadata.target_imaging_depth import TargetImagingDepth # NOQA
from allensdk.internal.api import PostgresQueryMixin


Expand Down Expand Up @@ -60,10 +43,10 @@ def from_lims(
return cls(
ophys_experiment_id=ophys_experiment_metadata.ophys_experiment_id,
ophys_session_id=ophys_experiment_metadata._ophys_session_id,
ophys_container_id=ophys_experiment_metadata._ophys_container_id, # noqa E501
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,
target_imaging_depth=ophys_experiment_metadata._target_imaging_depth,
target_imaging_depth=ophys_experiment_metadata._target_imaging_depth, # noqa E501
project_code=ophys_experiment_metadata._project_code,
imaging_plane_group=imaging_plane_group
)
Expand All @@ -75,10 +58,10 @@ def from_json(cls, dict_repr: dict) -> "MultiplaneMetadata":
return cls(
ophys_experiment_id=ophys_experiment_metadata.ophys_experiment_id,
ophys_session_id=ophys_experiment_metadata._ophys_session_id,
ophys_container_id=ophys_experiment_metadata._ophys_container_id, # noqa E501
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,
target_imaging_depth=ophys_experiment_metadata._target_imaging_depth,
target_imaging_depth=ophys_experiment_metadata._target_imaging_depth, # noqa E501
project_code=ophys_experiment_metadata._project_code,
imaging_plane_group=imaging_plane_group
)
Expand All @@ -90,10 +73,10 @@ def from_nwb(cls, nwbfile: NWBFile) -> "MultiplaneMetadata":
return cls(
ophys_experiment_id=ophys_experiment_metadata.ophys_experiment_id,
ophys_session_id=ophys_experiment_metadata._ophys_session_id,
ophys_container_id=ophys_experiment_metadata._ophys_container_id, # noqa E501
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,
target_imaging_depth=ophys_experiment_metadata._target_imaging_depth,
target_imaging_depth=ophys_experiment_metadata._target_imaging_depth, # noqa E501
project_code=ophys_experiment_metadata._project_code,
imaging_plane_group=imaging_plane_group
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,13 @@

from pynwb import NWBFile

from allensdk.core import DataObject
from allensdk.core import \
JsonReadableInterface, NwbReadableInterface, \
LimsReadableInterface
from allensdk.brain_observatory.behavior.data_objects.metadata\
.ophys_experiment_metadata.ophys_container_id import \
OphysContainerId
from allensdk.brain_observatory.behavior.data_objects.metadata\
.ophys_experiment_metadata.field_of_view_shape import \
FieldOfViewShape
from allensdk.brain_observatory.behavior.data_objects.metadata\
.ophys_experiment_metadata.imaging_depth import \
ImagingDepth
from allensdk.brain_observatory.behavior.data_objects.metadata\
.ophys_experiment_metadata.target_imaging_depth import \
TargetImagingDepth
from allensdk.brain_observatory.behavior.data_objects.metadata\
.ophys_experiment_metadata.ophys_session_id import \
OphysSessionId
from allensdk.brain_observatory.behavior.data_objects.metadata\
.ophys_experiment_metadata.project_code import \
ProjectCode
from allensdk.brain_observatory.behavior.data_objects.metadata.ophys_experiment_metadata.field_of_view_shape import FieldOfViewShape # NOQA
from allensdk.brain_observatory.behavior.data_objects.metadata.ophys_experiment_metadata.imaging_depth import ImagingDepth # NOQA
from allensdk.brain_observatory.behavior.data_objects.metadata.ophys_experiment_metadata.ophys_container_id import OphysContainerId # NOQA
from allensdk.brain_observatory.behavior.data_objects.metadata.ophys_experiment_metadata.ophys_session_id import OphysSessionId # NOQA
from allensdk.brain_observatory.behavior.data_objects.metadata.ophys_experiment_metadata.project_code import ProjectCode # NOQA
from allensdk.brain_observatory.behavior.data_objects.metadata.ophys_experiment_metadata.target_imaging_depth import TargetImagingDepth # NOQA
from allensdk.core import DataObject, JsonReadableInterface, LimsReadableInterface, NwbReadableInterface # NOQA
from allensdk.internal.api import PostgresQueryMixin


Expand Down Expand Up @@ -87,7 +72,9 @@ def from_json(cls, dict_repr: dict) -> "OphysExperimentMetadata":
ophys_experiment_id = dict_repr['ophys_experiment_id']
field_of_view_shape = FieldOfViewShape.from_json(dict_repr=dict_repr)
imaging_depth = ImagingDepth.from_json(dict_repr=dict_repr)
target_imaging_depth = TargetImagingDepth.from_json(dict_repr=dict_repr)
target_imaging_depth = TargetImagingDepth.from_json(
dict_repr=dict_repr
)

return OphysExperimentMetadata(
ophys_experiment_id=ophys_experiment_id,
Expand Down
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)
11 changes: 6 additions & 5 deletions allensdk/brain_observatory/behavior/schemas.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from marshmallow import Schema, fields, RAISE
import numpy as np

from marshmallow import RAISE, Schema, fields

STYPE_DICT = {fields.Float: 'float', fields.Int: 'int',
fields.String: 'text', fields.List: 'text',
Expand Down Expand Up @@ -150,9 +149,11 @@ class OphysMetadataSchema(NwbOphysMetadataSchema):
required=True,
)
target_imaging_depth = fields.Int(
doc=('Average Depth (microns) below the cortical surface '
'across experiments of a container.'
'targeted for two-photon acquisition'),
doc=(
"Average Depth (microns) below the cortical surface "
"across experiments of a container."
"targeted for two-photon acquisition"
),
required=True,
)
field_of_view_width = fields.Int(
Expand Down
Loading

0 comments on commit c7be0aa

Please sign in to comment.