Skip to content

Commit

Permalink
Alphabetizing the python API file and splitting OffsetShapeCapabiliti…
Browse files Browse the repository at this point in the history
…es into 2 classes (#194)

1. Alphabetizing the python API file 
2. Splitting OffsetShapeCapabilities into OffsetCapabilities and
ShapeCapabilities since the x, y properties represent different physical
locations depending on if its an offset or describing the shape of the
frame

---------

Co-authored-by: Alan Liddell <[email protected]>
  • Loading branch information
dgmccart and aliddell authored May 28, 2024
1 parent f716731 commit b361ee9
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 64 deletions.
97 changes: 52 additions & 45 deletions python/acquire/acquire.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ from typing import (

from numpy.typing import NDArray

@final
class AvailableData:
def frames(self) -> Iterator[VideoFrame]: ...
def get_frame_count(self) -> int: ...
def __iter__(self) -> Iterator[VideoFrame]: ...

@final
class AvailableDataContext:
def __enter__(self) -> AvailableData: ...
def __exit__(
self, exc_type: Any, exc_value: Any, traceback: Any
) -> None: ...

@final
class AvailableData:
def frames(self) -> Iterator[VideoFrame]: ...
def get_frame_count(self) -> int: ...
def __iter__(self) -> Iterator[VideoFrame]: ...

@final
class Camera:
identifier: Optional[DeviceIdentifier]
Expand All @@ -39,8 +39,8 @@ class CameraCapabilities:
line_interval_us: Property
readout_direction: Property
binning: Property
offset: OffsetShapeCapabilities
shape: OffsetShapeCapabilities
offset: OffsetCapabilities
shape: ShapeCapabilities
supported_pixel_types: List[SampleType]
digital_lines: DigitalLineCapabilities
triggers: TriggerCapabilities
Expand Down Expand Up @@ -69,35 +69,6 @@ class Capabilities:
def __init__(self, *args: None, **kwargs: Any) -> None: ...
def dict(self) -> Dict[str, Any]: ...

@final
class DimensionType:
"""The storage dimension type.
Space: spatial dimension.
Channel: color channel dimension.
Time: time dimension.
Other: other dimension.
When downsampling, Space and Time dimensions are downsampled by the same factor.
Channel and Other dimensions are not downsampled.
This value is also reflected in the dimension metadata of an OME-Zarr dataset.
"""

Space: ClassVar[DimensionType]
Channel: ClassVar[DimensionType]
Time: ClassVar[DimensionType]
Other: ClassVar[DimensionType]

def __init__(self, *args: None, **kwargs: Any) -> None: ...
def __eq__(self, other: object) -> bool: ...
def __ge__(self, other: object) -> bool: ...
def __gt__(self, other: object) -> bool: ...
def __int__(self) -> int: ...
def __le__(self, other: object) -> bool: ...
def __lt__(self, other: object) -> bool: ...
def __ne__(self, other: object) -> bool: ...

@final
class DeviceIdentifier:
id: Tuple[int, int]
Expand Down Expand Up @@ -164,6 +135,35 @@ class DigitalLineCapabilities:

def dict(self) -> Dict[str, Any]: ...

@final
class DimensionType:
"""The storage dimension type.
Space: spatial dimension.
Channel: color channel dimension.
Time: time dimension.
Other: other dimension.
When downsampling, Space and Time dimensions are downsampled by the same factor.
Channel and Other dimensions are not downsampled.
This value is also reflected in the dimension metadata of an OME-Zarr dataset.
"""

Space: ClassVar[DimensionType]
Channel: ClassVar[DimensionType]
Time: ClassVar[DimensionType]
Other: ClassVar[DimensionType]

def __init__(self, *args: None, **kwargs: Any) -> None: ...
def __eq__(self, other: object) -> bool: ...
def __ge__(self, other: object) -> bool: ...
def __gt__(self, other: object) -> bool: ...
def __int__(self) -> int: ...
def __le__(self, other: object) -> bool: ...
def __lt__(self, other: object) -> bool: ...
def __ne__(self, other: object) -> bool: ...

@final
class Direction:
Backward: ClassVar[Direction]
Expand All @@ -186,7 +186,7 @@ class InputTriggers:
def dict(self) -> Dict[str, Any]: ...

@final
class OffsetShapeCapabilities:
class OffsetCapabilities:
x: Property
y: Property

Expand All @@ -209,6 +209,13 @@ class PID:
def __init__(self, *args: None, **kwargs: Any) -> None: ...
def dict(self) -> Dict[str, Any]: ...

@final
class Properties:
video: Tuple[VideoStream, VideoStream]

def __init__(self, *args: None, **kwargs: Any) -> None: ...
def dict(self) -> Dict[str, Any]: ...

@final
class Property:
writable: bool
Expand All @@ -234,13 +241,6 @@ class PropertyType:
def __lt__(self, other: object) -> bool: ...
def __ne__(self, other: object) -> bool: ...

@final
class Properties:
video: Tuple[VideoStream, VideoStream]

def __init__(self, *args: None, **kwargs: Any) -> None: ...
def dict(self) -> Dict[str, Any]: ...

@final
class Runtime:
def __init__(self, *args: None, **kwargs: Any) -> None: ...
Expand Down Expand Up @@ -282,6 +282,13 @@ class SampleType:
def __lt__(self, other: object) -> bool: ...
def __ne__(self, other: object) -> bool: ...

@final
class ShapeCapabilities:
x: Property
y: Property

def dict(self) -> Dict[str, Any]: ...

@final
class SignalIOKind:
Input: ClassVar[SignalIOKind]
Expand Down
58 changes: 40 additions & 18 deletions src/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,20 +267,20 @@ impl Default for capi::CameraProperties_camera_properties_shape_s {
}
}

/// CameraCapabilities::OffsetShapeCapabilities
/// CameraCapabilities::OffsetCapabilities
#[pyclass]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OffsetShapeCapabilities {
pub struct OffsetCapabilities {
#[pyo3(get)]
x: Property,

#[pyo3(get)]
y: Property,
}

impl_plain_old_dict!(OffsetShapeCapabilities);
impl_plain_old_dict!(OffsetCapabilities);

impl Default for OffsetShapeCapabilities {
impl Default for OffsetCapabilities {
fn default() -> Self {
Self {
x: Property::default(),
Expand All @@ -290,7 +290,7 @@ impl Default for OffsetShapeCapabilities {
}

impl TryFrom<capi::CameraPropertyMetadata_camera_properties_metadata_offset_s>
for OffsetShapeCapabilities
for OffsetCapabilities
{
type Error = anyhow::Error;

Expand All @@ -306,8 +306,30 @@ impl TryFrom<capi::CameraPropertyMetadata_camera_properties_metadata_offset_s>
}
}

/// CameraCapabilities::ShapeCapabilities
#[pyclass]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ShapeCapabilities {
#[pyo3(get)]
x: Property,

#[pyo3(get)]
y: Property,
}

impl_plain_old_dict!(ShapeCapabilities);

impl Default for ShapeCapabilities {
fn default() -> Self {
Self {
x: Property::default(),
y: Property::default(),
}
}
}

impl TryFrom<capi::CameraPropertyMetadata_camera_properties_metadata_shape_s>
for OffsetShapeCapabilities
for ShapeCapabilities
{
type Error = anyhow::Error;

Expand Down Expand Up @@ -483,10 +505,10 @@ pub struct CameraCapabilities {
binning: Property,

#[pyo3(get)]
offset: Py<OffsetShapeCapabilities>,
offset: Py<OffsetCapabilities>,

#[pyo3(get)]
shape: Py<OffsetShapeCapabilities>,
shape: Py<ShapeCapabilities>,

#[pyo3(get)]
supported_pixel_types: Vec<SampleType>,
Expand All @@ -504,8 +526,8 @@ impl Default for CameraCapabilities {
fn default() -> Self {
let (offset, shape, digital_lines, triggers) = Python::with_gil(|py| {
(
Py::new(py, OffsetShapeCapabilities::default()).unwrap(),
Py::new(py, OffsetShapeCapabilities::default()).unwrap(),
Py::new(py, OffsetCapabilities::default()).unwrap(),
Py::new(py, ShapeCapabilities::default()).unwrap(),
Py::new(py, DigitalLineCapabilities::default()).unwrap(),
Py::new(py, TriggerCapabilities::default()).unwrap(),
)
Expand All @@ -529,8 +551,8 @@ impl TryFrom<capi::CameraPropertyMetadata> for CameraCapabilities {

fn try_from(value: capi::CameraPropertyMetadata) -> Result<Self, Self::Error> {
let (offset, shape, digital_lines, triggers) = Python::with_gil(|py| -> PyResult<_> {
let offset: OffsetShapeCapabilities = value.offset.try_into()?;
let shape: OffsetShapeCapabilities = value.shape.try_into()?;
let offset: OffsetCapabilities = value.offset.try_into()?;
let shape: ShapeCapabilities = value.shape.try_into()?;
let digital_lines: DigitalLineCapabilities = value.digital_lines.try_into()?;
let triggers: TriggerCapabilities = value.triggers.try_into()?;
Ok((
Expand Down Expand Up @@ -573,12 +595,12 @@ impl Default for capi::CameraPropertyMetadata_camera_properties_metadata_offset_
}
}

impl TryFrom<&OffsetShapeCapabilities>
impl TryFrom<&OffsetCapabilities>
for capi::CameraPropertyMetadata_camera_properties_metadata_offset_s
{
type Error = anyhow::Error;

fn try_from(value: &OffsetShapeCapabilities) -> Result<Self, Self::Error> {
fn try_from(value: &OffsetCapabilities) -> Result<Self, Self::Error> {
Ok(Python::with_gil(|_| -> PyResult<_> {
Ok(Self {
x: (&value.x).try_into()?,
Expand All @@ -597,12 +619,12 @@ impl Default for capi::CameraPropertyMetadata_camera_properties_metadata_shape_s
}
}

impl TryFrom<&OffsetShapeCapabilities>
impl TryFrom<&ShapeCapabilities>
for capi::CameraPropertyMetadata_camera_properties_metadata_shape_s
{
type Error = anyhow::Error;

fn try_from(value: &OffsetShapeCapabilities) -> Result<Self, Self::Error> {
fn try_from(value: &ShapeCapabilities) -> Result<Self, Self::Error> {
Ok(Python::with_gil(|_| -> PyResult<_> {
Ok(Self {
x: (&value.x).try_into()?,
Expand Down Expand Up @@ -736,12 +758,12 @@ impl TryFrom<&CameraCapabilities> for capi::CameraPropertyMetadata {

fn try_from(src: &CameraCapabilities) -> Result<Self, Self::Error> {
let offset = Python::with_gil(|py| -> PyResult<_> {
let offset: OffsetShapeCapabilities = src.offset.extract(py)?;
let offset: OffsetCapabilities = src.offset.extract(py)?;
Ok(offset)
})?;

let shape = Python::with_gil(|py| -> PyResult<_> {
let shape: OffsetShapeCapabilities = src.shape.extract(py)?;
let shape: ShapeCapabilities = src.shape.extract(py)?;
Ok(shape)
})?;

Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ fn acquire(py: Python, m: &PyModule) -> PyResult<()> {
m.add_class::<camera::DigitalLineCapabilities>()?;
m.add_class::<camera::TriggerCapabilities>()?;
m.add_class::<camera::TriggerInputOutputCapabilities>()?;
m.add_class::<camera::OffsetShapeCapabilities>()?;
m.add_class::<camera::OffsetCapabilities>()?;
m.add_class::<camera::ShapeCapabilities>()?;
m.add_class::<storage::StorageCapabilities>()?;
m.add_class::<components::Property>()?;
m.add_class::<components::PropertyType>()?;
Expand Down

0 comments on commit b361ee9

Please sign in to comment.