Skip to content

Commit

Permalink
Rename Dimension to StorageDimension. Update stubs.
Browse files Browse the repository at this point in the history
  • Loading branch information
aliddell committed Feb 22, 2024
1 parent 3758afe commit 2a7565e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 44 deletions.
40 changes: 7 additions & 33 deletions python/acquire/acquire.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,7 @@ class Capabilities:
def dict(self) -> Dict[str, Any]: ...

@final
class ChunkingCapabilities:
is_supported: bool

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

@final
class Dimension:
class StorageDimension:
name: str
kind: DimensionType
array_size_px: int
Expand All @@ -88,9 +82,10 @@ class Dimension:
@final
class DimensionType:
NONE: ClassVar[DimensionType]
Spatial: ClassVar[DimensionType]
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: ...
Expand Down Expand Up @@ -191,12 +186,6 @@ class InputTriggers:

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

@final
class MultiscaleCapabilities:
is_supported: bool

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

@final
class OffsetShapeCapabilities:
x: Property
Expand Down Expand Up @@ -294,12 +283,6 @@ class SampleType:
def __lt__(self, other: object) -> bool: ...
def __ne__(self, other: object) -> bool: ...

@final
class ShardingCapabilities:
is_supported: bool

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

@final
class SignalIOKind:
Input: ClassVar[SignalIOKind]
Expand Down Expand Up @@ -335,9 +318,9 @@ class Storage:

@final
class StorageCapabilities:
chunking: ChunkingCapabilities
sharding: ShardingCapabilities
multiscale: MultiscaleCapabilities
chunking_is_supported: bool
sharding_is_supported: bool
multiscale_is_supported: bool

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

Expand All @@ -347,16 +330,7 @@ class StorageProperties:
filename: Optional[str]
first_frame_id: int
pixel_scale_um: Tuple[float, float]
acquisition_dimensions: Tuple[
Dimension,
Dimension,
Dimension,
Dimension,
Dimension,
Dimension,
Dimension,
Dimension,
]
acquisition_dimensions: List[StorageDimension]
append_dimension: int
enable_multiscale: bool

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ fn acquire(py: Python, m: &PyModule) -> PyResult<()> {
m.add_class::<camera::InputTriggers>()?;
m.add_class::<camera::OutputTriggers>()?;
m.add_class::<storage::DimensionType>()?;
m.add_class::<storage::Dimension>()?;
m.add_class::<storage::StorageDimension>()?;
m.add_class::<storage::StorageProperties>()?;

m.add_class::<components::Direction>()?;
Expand Down
22 changes: 12 additions & 10 deletions src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ cvt!(DimensionType => capi::DimensionType,

#[pyclass]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Dimension {
pub struct StorageDimension {
#[pyo3(get, set)]
#[serde(default)]
pub(crate) name: Option<String>,
Expand All @@ -57,7 +57,7 @@ pub struct Dimension {
pub(crate) shard_size_chunks: u32,
}

impl Default for Dimension {
impl Default for StorageDimension {
fn default() -> Self {
Self {
name: Default::default(),
Expand All @@ -69,9 +69,9 @@ impl Default for Dimension {
}
}

impl_plain_old_dict!(Dimension);
impl_plain_old_dict!(StorageDimension);

impl TryFrom<capi::StorageDimension> for Dimension {
impl TryFrom<capi::StorageDimension> for StorageDimension {
type Error = anyhow::Error;

fn try_from(value: capi::StorageDimension) -> Result<Self, Self::Error> {
Expand Down Expand Up @@ -115,7 +115,7 @@ pub struct StorageProperties {
pub(crate) pixel_scale_um: (f64, f64),

#[pyo3(get, set)]
pub(crate) acquisition_dimensions: Vec<Py<Dimension>>,
pub(crate) acquisition_dimensions: Vec<Py<StorageDimension>>,

#[pyo3(get, set)]
pub(crate) enable_multiscale: bool,
Expand Down Expand Up @@ -159,13 +159,15 @@ impl TryFrom<capi::StorageProperties> for StorageProperties {
)
};

let mut acquisition_dimensions: Vec<Py<Dimension>> = Default::default();
let mut acquisition_dimensions: Vec<Py<StorageDimension>> = Default::default();
for i in 1..value.acquisition_dimensions.size {
acquisition_dimensions.push(Python::with_gil(|py| {
Py::new(
py,
Dimension::try_from(unsafe { *value.acquisition_dimensions.data.add(i) })
.unwrap(),
StorageDimension::try_from(unsafe {
*value.acquisition_dimensions.data.add(i)
})
.unwrap(),
)
.unwrap()
}));
Expand Down Expand Up @@ -373,10 +375,10 @@ impl Default for capi::StorageDimension {
}
}

impl TryFrom<&Dimension> for capi::StorageDimension {
impl TryFrom<&StorageDimension> for capi::StorageDimension {
type Error = anyhow::Error;

fn try_from(value: &Dimension) -> Result<Self, Self::Error> {
fn try_from(value: &StorageDimension) -> Result<Self, Self::Error> {
let mut out: capi::StorageDimension = unsafe { std::mem::zeroed() };
// Careful: x needs to live long enough
let x = if let Some(name) = &value.name {
Expand Down

0 comments on commit 2a7565e

Please sign in to comment.