Source code for allensdk.brain_observatory.behavior.data_objects.metadata.ophys_experiment_metadata.imaging_depth
from pynwb import NWBFile
from allensdk.core import DataObject
from allensdk.core import \
JsonReadableInterface, LimsReadableInterface, NwbReadableInterface
from allensdk.internal.api import PostgresQueryMixin
[docs]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)
[docs] @classmethod
def from_lims(cls, ophys_experiment_id: int,
lims_db: PostgresQueryMixin) -> "ImagingDepth":
query = """
SELECT imd.depth
FROM ophys_experiments oe
JOIN ophys_sessions os ON oe.ophys_session_id = os.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)
return cls(imaging_depth=imaging_depth)
[docs] @classmethod
def from_json(cls, dict_repr: dict) -> "ImagingDepth":
# TODO remove all of the from_json loading and validation step
# ticket 2607
return cls(imaging_depth=dict_repr['targeted_depth'])
[docs] @classmethod
def from_nwb(cls, nwbfile: NWBFile) -> "ImagingDepth":
metadata = nwbfile.lab_meta_data['metadata']
return cls(imaging_depth=metadata.imaging_depth)