Skip to content

Commit b361ee9

Browse files
dgmccartaliddell
andauthored
Alphabetizing the python API file and splitting OffsetShapeCapabilities 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 <aliddell@chanzuckerberg.com>
1 parent f716731 commit b361ee9

File tree

3 files changed

+94
-64
lines changed

3 files changed

+94
-64
lines changed

python/acquire/acquire.pyi

Lines changed: 52 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@ from typing import (
1212

1313
from numpy.typing import NDArray
1414

15+
@final
16+
class AvailableData:
17+
def frames(self) -> Iterator[VideoFrame]: ...
18+
def get_frame_count(self) -> int: ...
19+
def __iter__(self) -> Iterator[VideoFrame]: ...
20+
1521
@final
1622
class AvailableDataContext:
1723
def __enter__(self) -> AvailableData: ...
1824
def __exit__(
1925
self, exc_type: Any, exc_value: Any, traceback: Any
2026
) -> None: ...
2127

22-
@final
23-
class AvailableData:
24-
def frames(self) -> Iterator[VideoFrame]: ...
25-
def get_frame_count(self) -> int: ...
26-
def __iter__(self) -> Iterator[VideoFrame]: ...
27-
2828
@final
2929
class Camera:
3030
identifier: Optional[DeviceIdentifier]
@@ -39,8 +39,8 @@ class CameraCapabilities:
3939
line_interval_us: Property
4040
readout_direction: Property
4141
binning: Property
42-
offset: OffsetShapeCapabilities
43-
shape: OffsetShapeCapabilities
42+
offset: OffsetCapabilities
43+
shape: ShapeCapabilities
4444
supported_pixel_types: List[SampleType]
4545
digital_lines: DigitalLineCapabilities
4646
triggers: TriggerCapabilities
@@ -69,35 +69,6 @@ class Capabilities:
6969
def __init__(self, *args: None, **kwargs: Any) -> None: ...
7070
def dict(self) -> Dict[str, Any]: ...
7171

72-
@final
73-
class DimensionType:
74-
"""The storage dimension type.
75-
76-
Space: spatial dimension.
77-
Channel: color channel dimension.
78-
Time: time dimension.
79-
Other: other dimension.
80-
81-
When downsampling, Space and Time dimensions are downsampled by the same factor.
82-
Channel and Other dimensions are not downsampled.
83-
84-
This value is also reflected in the dimension metadata of an OME-Zarr dataset.
85-
"""
86-
87-
Space: ClassVar[DimensionType]
88-
Channel: ClassVar[DimensionType]
89-
Time: ClassVar[DimensionType]
90-
Other: ClassVar[DimensionType]
91-
92-
def __init__(self, *args: None, **kwargs: Any) -> None: ...
93-
def __eq__(self, other: object) -> bool: ...
94-
def __ge__(self, other: object) -> bool: ...
95-
def __gt__(self, other: object) -> bool: ...
96-
def __int__(self) -> int: ...
97-
def __le__(self, other: object) -> bool: ...
98-
def __lt__(self, other: object) -> bool: ...
99-
def __ne__(self, other: object) -> bool: ...
100-
10172
@final
10273
class DeviceIdentifier:
10374
id: Tuple[int, int]
@@ -164,6 +135,35 @@ class DigitalLineCapabilities:
164135

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

138+
@final
139+
class DimensionType:
140+
"""The storage dimension type.
141+
142+
Space: spatial dimension.
143+
Channel: color channel dimension.
144+
Time: time dimension.
145+
Other: other dimension.
146+
147+
When downsampling, Space and Time dimensions are downsampled by the same factor.
148+
Channel and Other dimensions are not downsampled.
149+
150+
This value is also reflected in the dimension metadata of an OME-Zarr dataset.
151+
"""
152+
153+
Space: ClassVar[DimensionType]
154+
Channel: ClassVar[DimensionType]
155+
Time: ClassVar[DimensionType]
156+
Other: ClassVar[DimensionType]
157+
158+
def __init__(self, *args: None, **kwargs: Any) -> None: ...
159+
def __eq__(self, other: object) -> bool: ...
160+
def __ge__(self, other: object) -> bool: ...
161+
def __gt__(self, other: object) -> bool: ...
162+
def __int__(self) -> int: ...
163+
def __le__(self, other: object) -> bool: ...
164+
def __lt__(self, other: object) -> bool: ...
165+
def __ne__(self, other: object) -> bool: ...
166+
167167
@final
168168
class Direction:
169169
Backward: ClassVar[Direction]
@@ -186,7 +186,7 @@ class InputTriggers:
186186
def dict(self) -> Dict[str, Any]: ...
187187

188188
@final
189-
class OffsetShapeCapabilities:
189+
class OffsetCapabilities:
190190
x: Property
191191
y: Property
192192

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

212+
@final
213+
class Properties:
214+
video: Tuple[VideoStream, VideoStream]
215+
216+
def __init__(self, *args: None, **kwargs: Any) -> None: ...
217+
def dict(self) -> Dict[str, Any]: ...
218+
212219
@final
213220
class Property:
214221
writable: bool
@@ -234,13 +241,6 @@ class PropertyType:
234241
def __lt__(self, other: object) -> bool: ...
235242
def __ne__(self, other: object) -> bool: ...
236243

237-
@final
238-
class Properties:
239-
video: Tuple[VideoStream, VideoStream]
240-
241-
def __init__(self, *args: None, **kwargs: Any) -> None: ...
242-
def dict(self) -> Dict[str, Any]: ...
243-
244244
@final
245245
class Runtime:
246246
def __init__(self, *args: None, **kwargs: Any) -> None: ...
@@ -282,6 +282,13 @@ class SampleType:
282282
def __lt__(self, other: object) -> bool: ...
283283
def __ne__(self, other: object) -> bool: ...
284284

285+
@final
286+
class ShapeCapabilities:
287+
x: Property
288+
y: Property
289+
290+
def dict(self) -> Dict[str, Any]: ...
291+
285292
@final
286293
class SignalIOKind:
287294
Input: ClassVar[SignalIOKind]

src/camera.rs

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -267,20 +267,20 @@ impl Default for capi::CameraProperties_camera_properties_shape_s {
267267
}
268268
}
269269

270-
/// CameraCapabilities::OffsetShapeCapabilities
270+
/// CameraCapabilities::OffsetCapabilities
271271
#[pyclass]
272272
#[derive(Debug, Clone, Serialize, Deserialize)]
273-
pub struct OffsetShapeCapabilities {
273+
pub struct OffsetCapabilities {
274274
#[pyo3(get)]
275275
x: Property,
276276

277277
#[pyo3(get)]
278278
y: Property,
279279
}
280280

281-
impl_plain_old_dict!(OffsetShapeCapabilities);
281+
impl_plain_old_dict!(OffsetCapabilities);
282282

283-
impl Default for OffsetShapeCapabilities {
283+
impl Default for OffsetCapabilities {
284284
fn default() -> Self {
285285
Self {
286286
x: Property::default(),
@@ -290,7 +290,7 @@ impl Default for OffsetShapeCapabilities {
290290
}
291291

292292
impl TryFrom<capi::CameraPropertyMetadata_camera_properties_metadata_offset_s>
293-
for OffsetShapeCapabilities
293+
for OffsetCapabilities
294294
{
295295
type Error = anyhow::Error;
296296

@@ -306,8 +306,30 @@ impl TryFrom<capi::CameraPropertyMetadata_camera_properties_metadata_offset_s>
306306
}
307307
}
308308

309+
/// CameraCapabilities::ShapeCapabilities
310+
#[pyclass]
311+
#[derive(Debug, Clone, Serialize, Deserialize)]
312+
pub struct ShapeCapabilities {
313+
#[pyo3(get)]
314+
x: Property,
315+
316+
#[pyo3(get)]
317+
y: Property,
318+
}
319+
320+
impl_plain_old_dict!(ShapeCapabilities);
321+
322+
impl Default for ShapeCapabilities {
323+
fn default() -> Self {
324+
Self {
325+
x: Property::default(),
326+
y: Property::default(),
327+
}
328+
}
329+
}
330+
309331
impl TryFrom<capi::CameraPropertyMetadata_camera_properties_metadata_shape_s>
310-
for OffsetShapeCapabilities
332+
for ShapeCapabilities
311333
{
312334
type Error = anyhow::Error;
313335

@@ -483,10 +505,10 @@ pub struct CameraCapabilities {
483505
binning: Property,
484506

485507
#[pyo3(get)]
486-
offset: Py<OffsetShapeCapabilities>,
508+
offset: Py<OffsetCapabilities>,
487509

488510
#[pyo3(get)]
489-
shape: Py<OffsetShapeCapabilities>,
511+
shape: Py<ShapeCapabilities>,
490512

491513
#[pyo3(get)]
492514
supported_pixel_types: Vec<SampleType>,
@@ -504,8 +526,8 @@ impl Default for CameraCapabilities {
504526
fn default() -> Self {
505527
let (offset, shape, digital_lines, triggers) = Python::with_gil(|py| {
506528
(
507-
Py::new(py, OffsetShapeCapabilities::default()).unwrap(),
508-
Py::new(py, OffsetShapeCapabilities::default()).unwrap(),
529+
Py::new(py, OffsetCapabilities::default()).unwrap(),
530+
Py::new(py, ShapeCapabilities::default()).unwrap(),
509531
Py::new(py, DigitalLineCapabilities::default()).unwrap(),
510532
Py::new(py, TriggerCapabilities::default()).unwrap(),
511533
)
@@ -529,8 +551,8 @@ impl TryFrom<capi::CameraPropertyMetadata> for CameraCapabilities {
529551

530552
fn try_from(value: capi::CameraPropertyMetadata) -> Result<Self, Self::Error> {
531553
let (offset, shape, digital_lines, triggers) = Python::with_gil(|py| -> PyResult<_> {
532-
let offset: OffsetShapeCapabilities = value.offset.try_into()?;
533-
let shape: OffsetShapeCapabilities = value.shape.try_into()?;
554+
let offset: OffsetCapabilities = value.offset.try_into()?;
555+
let shape: ShapeCapabilities = value.shape.try_into()?;
534556
let digital_lines: DigitalLineCapabilities = value.digital_lines.try_into()?;
535557
let triggers: TriggerCapabilities = value.triggers.try_into()?;
536558
Ok((
@@ -573,12 +595,12 @@ impl Default for capi::CameraPropertyMetadata_camera_properties_metadata_offset_
573595
}
574596
}
575597

576-
impl TryFrom<&OffsetShapeCapabilities>
598+
impl TryFrom<&OffsetCapabilities>
577599
for capi::CameraPropertyMetadata_camera_properties_metadata_offset_s
578600
{
579601
type Error = anyhow::Error;
580602

581-
fn try_from(value: &OffsetShapeCapabilities) -> Result<Self, Self::Error> {
603+
fn try_from(value: &OffsetCapabilities) -> Result<Self, Self::Error> {
582604
Ok(Python::with_gil(|_| -> PyResult<_> {
583605
Ok(Self {
584606
x: (&value.x).try_into()?,
@@ -597,12 +619,12 @@ impl Default for capi::CameraPropertyMetadata_camera_properties_metadata_shape_s
597619
}
598620
}
599621

600-
impl TryFrom<&OffsetShapeCapabilities>
622+
impl TryFrom<&ShapeCapabilities>
601623
for capi::CameraPropertyMetadata_camera_properties_metadata_shape_s
602624
{
603625
type Error = anyhow::Error;
604626

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

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

743765
let shape = Python::with_gil(|py| -> PyResult<_> {
744-
let shape: OffsetShapeCapabilities = src.shape.extract(py)?;
766+
let shape: ShapeCapabilities = src.shape.extract(py)?;
745767
Ok(shape)
746768
})?;
747769

src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ fn acquire(py: Python, m: &PyModule) -> PyResult<()> {
7878
m.add_class::<camera::DigitalLineCapabilities>()?;
7979
m.add_class::<camera::TriggerCapabilities>()?;
8080
m.add_class::<camera::TriggerInputOutputCapabilities>()?;
81-
m.add_class::<camera::OffsetShapeCapabilities>()?;
81+
m.add_class::<camera::OffsetCapabilities>()?;
82+
m.add_class::<camera::ShapeCapabilities>()?;
8283
m.add_class::<storage::StorageCapabilities>()?;
8384
m.add_class::<components::Property>()?;
8485
m.add_class::<components::PropertyType>()?;

0 commit comments

Comments
 (0)