nwb-linkml/nwb_linkml/models/core_nwb_image.py

182 lines
16 KiB
Python
Raw Normal View History

from __future__ import annotations
from datetime import datetime, date
from enum import Enum
from typing import List, Dict, Optional, Any, Union
from pydantic import BaseModel as BaseModel, Field
from nptyping import NDArray, Shape, Float, Float32, Double, Float64, LongLong, Int64, Int, Int32, Int16, Short, Int8, UInt, UInt32, UInt16, UInt8, UInt64, Number, String, Unicode, Unicode, Unicode, String, Bool, Datetime64
import sys
if sys.version_info >= (3, 8):
from typing import Literal
else:
from typing_extensions import Literal
from .core_nwb_base import (
TimeSeriesStartingTime,
Image,
TimeSeries,
TimeSeriesSync
)
metamodel_version = "None"
version = "None"
class ConfiguredBaseModel(BaseModel,
validate_assignment = True,
validate_default = True,
extra = 'forbid',
arbitrary_types_allowed = True,
use_enum_values = True):
pass
class GrayscaleImage(Image):
"""
A grayscale image.
"""
name:str= Field(...)
array:Optional[NDArray[Shape["* x, * y"], Number]]= Field(None)
resolution:Optional[float]= Field(None, description="""Pixel resolution of the image, in pixels per centimeter.""")
description:Optional[str]= Field(None, description="""Description of the image.""")
class RGBImage(Image):
"""
A color image.
"""
name:str= Field(...)
array:Optional[NDArray[Shape["* x, * y, 3 r_g_b"], Number]]= Field(None)
resolution:Optional[float]= Field(None, description="""Pixel resolution of the image, in pixels per centimeter.""")
description:Optional[str]= Field(None, description="""Description of the image.""")
class RGBAImage(Image):
"""
A color image with transparency.
"""
name:str= Field(...)
array:Optional[NDArray[Shape["* x, * y, 4 r_g_b_a"], Number]]= Field(None)
resolution:Optional[float]= Field(None, description="""Pixel resolution of the image, in pixels per centimeter.""")
description:Optional[str]= Field(None, description="""Description of the image.""")
class ImageSeries(TimeSeries):
"""
General image data that is common between acquisition and stimulus time series. Sometimes the image data is stored in the file in a raw format while other times it will be stored as a series of external image files in the host file system. The data field will either be binary data, if the data is stored in the NWB file, or empty, if the data is stored in an external image stack. [frame][x][y] or [frame][x][y][z].
"""
name:str= Field(...)
data:ImageSeriesData= Field(..., description="""Binary data representing images across frames. If data are stored in an external file, this should be an empty 3D array.""")
dimension:Optional[List[int]]= Field(default_factory=list, description="""Number of pixels on x, y, (and z) axes.""")
external_file:Optional[List[str]]= Field(default_factory=list, description="""Paths to one or more external file(s). The field is only present if format='external'. This is only relevant if the image series is stored in the file system as one or more image file(s). This field should NOT be used if the image is stored in another NWB file and that file is linked to this file.""")
format:Optional[str]= Field(None, description="""Format of image. If this is 'external', then the attribute 'external_file' contains the path information to the image files. If this is 'raw', then the raw (single-channel) binary data is stored in the 'data' dataset. If this attribute is not present, then the default format='raw' case is assumed.""")
description:Optional[str]= Field(None, description="""Description of the time series.""")
comments:Optional[str]= Field(None, description="""Human-readable comments about the TimeSeries. This second descriptive field can be used to store additional information, or descriptive information if the primary description field is populated with a computer-readable string.""")
starting_time:Optional[TimeSeriesStartingTime]= Field(None, description="""Timestamp of the first sample in seconds. When timestamps are uniformly spaced, the timestamp of the first sample can be specified and all subsequent ones calculated from the sampling rate attribute.""")
timestamps:Optional[List[float]]= Field(default_factory=list, description="""Timestamps for samples stored in data, in seconds, relative to the common experiment master-clock stored in NWBFile.timestamps_reference_time.""")
control:Optional[List[int]]= Field(default_factory=list, description="""Numerical labels that apply to each time point in data for the purpose of querying and slicing data by these values. If present, the length of this array should be the same size as the first dimension of data.""")
control_description:Optional[List[str]]= Field(default_factory=list, description="""Description of each control value. Must be present if control is present. If present, control_description[0] should describe time points where control == 0.""")
sync:Optional[TimeSeriesSync]= Field(None, description="""Lab-specific time and sync information as provided directly from hardware devices and that is necessary for aligning all acquired time information to a common timebase. The timestamp array stores time in the common timebase. This group will usually only be populated in TimeSeries that are stored external to the NWB file, in files storing raw data. Once timestamp data is calculated, the contents of 'sync' are mostly for archival purposes.""")
class ImageSeriesData(ConfiguredBaseModel):
"""
Binary data representing images across frames. If data are stored in an external file, this should be an empty 3D array.
"""
name:Literal["data"]= Field("data")
array:Optional[Union[
NDArray[Shape["* frame, * x, * y"], Number],
NDArray[Shape["* frame, * x, * y, * z"], Number]
]]= Field(None)
class ImageMaskSeries(ImageSeries):
"""
An alpha mask that is applied to a presented visual stimulus. The 'data' array contains an array of mask values that are applied to the displayed image. Mask values are stored as RGBA. Mask can vary with time. The timestamps array indicates the starting time of a mask, and that mask pattern continues until it's explicitly changed.
"""
name:str= Field(...)
data:ImageSeriesData= Field(..., description="""Binary data representing images across frames. If data are stored in an external file, this should be an empty 3D array.""")
dimension:Optional[List[int]]= Field(default_factory=list, description="""Number of pixels on x, y, (and z) axes.""")
external_file:Optional[List[str]]= Field(default_factory=list, description="""Paths to one or more external file(s). The field is only present if format='external'. This is only relevant if the image series is stored in the file system as one or more image file(s). This field should NOT be used if the image is stored in another NWB file and that file is linked to this file.""")
format:Optional[str]= Field(None, description="""Format of image. If this is 'external', then the attribute 'external_file' contains the path information to the image files. If this is 'raw', then the raw (single-channel) binary data is stored in the 'data' dataset. If this attribute is not present, then the default format='raw' case is assumed.""")
description:Optional[str]= Field(None, description="""Description of the time series.""")
comments:Optional[str]= Field(None, description="""Human-readable comments about the TimeSeries. This second descriptive field can be used to store additional information, or descriptive information if the primary description field is populated with a computer-readable string.""")
starting_time:Optional[TimeSeriesStartingTime]= Field(None, description="""Timestamp of the first sample in seconds. When timestamps are uniformly spaced, the timestamp of the first sample can be specified and all subsequent ones calculated from the sampling rate attribute.""")
timestamps:Optional[List[float]]= Field(default_factory=list, description="""Timestamps for samples stored in data, in seconds, relative to the common experiment master-clock stored in NWBFile.timestamps_reference_time.""")
control:Optional[List[int]]= Field(default_factory=list, description="""Numerical labels that apply to each time point in data for the purpose of querying and slicing data by these values. If present, the length of this array should be the same size as the first dimension of data.""")
control_description:Optional[List[str]]= Field(default_factory=list, description="""Description of each control value. Must be present if control is present. If present, control_description[0] should describe time points where control == 0.""")
sync:Optional[TimeSeriesSync]= Field(None, description="""Lab-specific time and sync information as provided directly from hardware devices and that is necessary for aligning all acquired time information to a common timebase. The timestamp array stores time in the common timebase. This group will usually only be populated in TimeSeries that are stored external to the NWB file, in files storing raw data. Once timestamp data is calculated, the contents of 'sync' are mostly for archival purposes.""")
class OpticalSeries(ImageSeries):
"""
Image data that is presented or recorded. A stimulus template movie will be stored only as an image. When the image is presented as stimulus, additional data is required, such as field of view (e.g., how much of the visual field the image covers, or how what is the area of the target being imaged). If the OpticalSeries represents acquired imaging data, orientation is also important.
"""
name:str= Field(...)
distance:Optional[float]= Field(None, description="""Distance from camera/monitor to target/eye.""")
field_of_view:Optional[OpticalSeriesFieldOfView]= Field(None, description="""Width, height and depth of image, or imaged area, in meters.""")
data:OpticalSeriesData= Field(..., description="""Images presented to subject, either grayscale or RGB""")
orientation:Optional[str]= Field(None, description="""Description of image relative to some reference frame (e.g., which way is up). Must also specify frame of reference.""")
dimension:Optional[List[int]]= Field(default_factory=list, description="""Number of pixels on x, y, (and z) axes.""")
external_file:Optional[List[str]]= Field(default_factory=list, description="""Paths to one or more external file(s). The field is only present if format='external'. This is only relevant if the image series is stored in the file system as one or more image file(s). This field should NOT be used if the image is stored in another NWB file and that file is linked to this file.""")
format:Optional[str]= Field(None, description="""Format of image. If this is 'external', then the attribute 'external_file' contains the path information to the image files. If this is 'raw', then the raw (single-channel) binary data is stored in the 'data' dataset. If this attribute is not present, then the default format='raw' case is assumed.""")
description:Optional[str]= Field(None, description="""Description of the time series.""")
comments:Optional[str]= Field(None, description="""Human-readable comments about the TimeSeries. This second descriptive field can be used to store additional information, or descriptive information if the primary description field is populated with a computer-readable string.""")
starting_time:Optional[TimeSeriesStartingTime]= Field(None, description="""Timestamp of the first sample in seconds. When timestamps are uniformly spaced, the timestamp of the first sample can be specified and all subsequent ones calculated from the sampling rate attribute.""")
timestamps:Optional[List[float]]= Field(default_factory=list, description="""Timestamps for samples stored in data, in seconds, relative to the common experiment master-clock stored in NWBFile.timestamps_reference_time.""")
control:Optional[List[int]]= Field(default_factory=list, description="""Numerical labels that apply to each time point in data for the purpose of querying and slicing data by these values. If present, the length of this array should be the same size as the first dimension of data.""")
control_description:Optional[List[str]]= Field(default_factory=list, description="""Description of each control value. Must be present if control is present. If present, control_description[0] should describe time points where control == 0.""")
sync:Optional[TimeSeriesSync]= Field(None, description="""Lab-specific time and sync information as provided directly from hardware devices and that is necessary for aligning all acquired time information to a common timebase. The timestamp array stores time in the common timebase. This group will usually only be populated in TimeSeries that are stored external to the NWB file, in files storing raw data. Once timestamp data is calculated, the contents of 'sync' are mostly for archival purposes.""")
class OpticalSeriesFieldOfView(ConfiguredBaseModel):
"""
Width, height and depth of image, or imaged area, in meters.
"""
name:Literal["field_of_view"]= Field("field_of_view")
array:Optional[Union[
NDArray[Shape["2 width_height"], Float32],
NDArray[Shape["2 width_height, 3 width_height_depth"], Float32]
]]= Field(None)
class OpticalSeriesData(ConfiguredBaseModel):
"""
Images presented to subject, either grayscale or RGB
"""
name:Literal["data"]= Field("data")
array:Optional[Union[
NDArray[Shape["* frame, * x, * y"], Number],
NDArray[Shape["* frame, * x, * y, 3 r_g_b"], Number]
]]= Field(None)
class IndexSeries(TimeSeries):
"""
Stores indices to image frames stored in an ImageSeries. The purpose of the IndexSeries is to allow a static image stack to be stored in an Images object, and the images in the stack to be referenced out-of-order. This can be for the display of individual images, or of movie segments (as a movie is simply a series of images). The data field stores the index of the frame in the referenced Images object, and the timestamps array indicates when that image was displayed.
"""
name:str= Field(...)
data:List[int]= Field(default_factory=list, description="""Index of the image (using zero-indexing) in the linked Images object.""")
description:Optional[str]= Field(None, description="""Description of the time series.""")
comments:Optional[str]= Field(None, description="""Human-readable comments about the TimeSeries. This second descriptive field can be used to store additional information, or descriptive information if the primary description field is populated with a computer-readable string.""")
starting_time:Optional[TimeSeriesStartingTime]= Field(None, description="""Timestamp of the first sample in seconds. When timestamps are uniformly spaced, the timestamp of the first sample can be specified and all subsequent ones calculated from the sampling rate attribute.""")
timestamps:Optional[List[float]]= Field(default_factory=list, description="""Timestamps for samples stored in data, in seconds, relative to the common experiment master-clock stored in NWBFile.timestamps_reference_time.""")
control:Optional[List[int]]= Field(default_factory=list, description="""Numerical labels that apply to each time point in data for the purpose of querying and slicing data by these values. If present, the length of this array should be the same size as the first dimension of data.""")
control_description:Optional[List[str]]= Field(default_factory=list, description="""Description of each control value. Must be present if control is present. If present, control_description[0] should describe time points where control == 0.""")
sync:Optional[TimeSeriesSync]= Field(None, description="""Lab-specific time and sync information as provided directly from hardware devices and that is necessary for aligning all acquired time information to a common timebase. The timestamp array stores time in the common timebase. This group will usually only be populated in TimeSeries that are stored external to the NWB file, in files storing raw data. Once timestamp data is calculated, the contents of 'sync' are mostly for archival purposes.""")
# Model rebuild
# see https://pydantic-docs.helpmanual.io/usage/models/#rebuilding-a-model
GrayscaleImage.model_rebuild()
RGBImage.model_rebuild()
RGBAImage.model_rebuild()
ImageSeries.model_rebuild()
ImageSeriesData.model_rebuild()
ImageMaskSeries.model_rebuild()
OpticalSeries.model_rebuild()
OpticalSeriesFieldOfView.model_rebuild()
OpticalSeriesData.model_rebuild()
IndexSeries.model_rebuild()