Skip to content

Commit

Permalink
Nontrivial chunking (#8)
Browse files Browse the repository at this point in the history
* Update submodules. Fix DM bugs in test_basic.py

* Update submodules.

* Update submodules.

* Expand StorageProperties to support chunking and compression parameters.

* Update acquire-driver-zarr submodule. Add chunking test.

* Squashed commit of the following:

commit 750f6f66ef66649769356d3b057a61738edb457e
Author: Alan Liddell <[email protected]>
Date:   Wed May 10 10:37:05 2023 -0400

    Address PR comments.

commit 5a256f74d5299223f62ee0b4d99d42f5f265efc7
Author: Alan Liddell <[email protected]>
Date:   Tue May 9 13:29:49 2023 -0400

    Clean up build script

commit a88e12a1bdd953e3489116373068593af6377bc1
Author: Alan Liddell <[email protected]>
Date:   Tue May 9 13:12:43 2023 -0400

    add GH token to environment variables in typing test.

commit df8256684ce7f2840f0d24823065c53e2fac8a2d
Merge: 652c401 b07cbb3
Author: Alan Liddell <[email protected]>
Date:   Tue May 9 12:56:25 2023 -0400

    Merge remote-tracking branch 'nclack/testing' into submodule-updates

commit 652c401257aba0c738cbf5a273948b391514d568
Author: Alan Liddell <[email protected]>
Date:   Tue May 9 12:22:45 2023 -0400

    update dcam and egrabber test yamls

commit 3cc7cddb96b8188200ee9f8133da1d886204c0f1
Author: Alan Liddell <[email protected]>
Date:   Tue May 9 12:10:00 2023 -0400

    remove driver submodules

commit e4b9e01152c403fd9a6dc46005f784936eaa8bcd
Author: Alan Liddell <[email protected]>
Date:   Tue May 9 11:51:14 2023 -0400

    build and test passes

commit 0b27539148ece38e1f569795db30cb7cc6df7534
Author: Nathan Clack <[email protected]>
Date:   Mon May 8 16:41:49 2023 -0700

    fix packaging

commit b07cbb370a6db2b29cf1bdc8606498cd9555ff11
Author: Nathan Clack <[email protected]>
Date:   Mon May 8 17:09:18 2023 -0700

    get dcam test to pass

commit bc54ff2f4214b5ecc01eaa622703f53abd5725ba
Author: Nathan Clack <[email protected]>
Date:   Mon May 8 16:57:21 2023 -0700

    packaging: remove old setuptools options

commit afba01d3f7476142b6f0aaf671eca8b05df29ee9
Author: Nathan Clack <[email protected]>
Date:   Mon May 8 16:41:49 2023 -0700

    fix packaging

commit a887683cf348b89c4327fb33fc67a5cf72c36c60
Author: Alan Liddell <[email protected]>
Date:   Mon May 8 17:22:09 2023 -0400

    update build and test yamls

commit 8e08001f72408485acb5c341871bab1458cd7e96
Author: Alan Liddell <[email protected]>
Date:   Mon May 8 17:19:31 2023 -0400

    wip

commit 7b3180fd3c78422380983010051277ee72025366
Author: Alan Liddell <[email protected]>
Date:   Mon May 8 16:56:02 2023 -0400

    update submodules

commit 6e41aff47b5bdb189e5356e69a3f663b3239fd1f
Author: Nathan Clack <[email protected]>
Date:   Mon May 8 10:00:42 2023 -0700

    fix trigger assignment

commit 9cd29151070a8e6edfa9e51495ad0a26847f63e0
Author: Nathan Clack <[email protected]>
Date:   Fri May 5 15:38:23 2023 -0700

    testing (wip)

commit b5bf4f97e341932d8e350bed6647e2c272e3a76d
Author: Nathan Clack <[email protected]>
Date:   Fri May 5 15:29:32 2023 -0700

    update deps, tests

commit 20ea3a0737adea45d8354ed18f212d95be51e40e
Author: Alan Liddell <[email protected]>
Date:   Thu May 4 12:24:23 2023 -0400

    update acquire-driver-zarr submodule.

commit 941027c15d326ce79353bb3df94c0e7a773777c4
Author: Alan Liddell <[email protected]>
Date:   Thu May 4 11:38:06 2023 -0400

    Update acquire-driver-common and acquire-video-runtime submodules

commit 5fcd566ea7bdcafb7b8652b6d60862e5a37fe0f6
Author: Alan Liddell <[email protected]>
Date:   Thu May 4 10:55:14 2023 -0400

    Update typing and dcam tests

commit d68d40f0e7122e350270f823605ecff1c9b64358
Author: Alan Liddell <[email protected]>
Date:   Wed May 3 15:47:45 2023 -0400

    Try again to enable long paths in CI.

commit 34647a7803fe0b2bcd9ca3892327b2caab56faea
Author: Alan Liddell <[email protected]>
Date:   Wed May 3 15:41:40 2023 -0400

    Try to enable long paths in CI.

commit 1d79e247bb87b924bded9e918470b3a16c852172
Author: Alan Liddell <[email protected]>
Date:   Wed May 3 15:24:57 2023 -0400

    Restore capital-T Tiff.

commit 5b317b9386bbed4bbc54deae502b02548a65d3d8
Author: Alan Liddell <[email protected]>
Date:   Wed May 3 15:23:54 2023 -0400

    Update acquire-driver-common and acquire-driver-hdcam. Restore recursive submodule checkout in CI.

commit 5d170ddfb2f15cd76108345227dd0972252f8480
Merge: f989feb 51a7ea1
Author: Alan Liddell <[email protected]>
Date:   Wed May 3 13:40:46 2023 -0400

    Merge branch 'main' into submodule-updates

commit 51a7ea1
Author: Alan Liddell <[email protected]>
Date:   Wed May 3 13:38:25 2023 -0400

    remove uses of PAT from workflow files, set submodules from recursive to true

* Update driver hashes.

* Squashed commit of the following:

commit 6909668
Author: Alan Liddell <[email protected]>
Date:   Wed May 10 19:08:01 2023 -0400

    Use artifact downloads instead of submodules (#2)

    * Update submodules. Fix DM bugs in test_basic.py

    * Update acquire-driver-common and acquire-driver-hdcam. Restore recursive submodule checkout in CI.

    * Restore capital-T Tiff.

    * Try to enable long paths in CI.

    * Try again to enable long paths in CI.

    * Update typing and dcam tests

    * Update acquire-driver-common and acquire-video-runtime submodules

    * update acquire-driver-zarr submodule.

    * update deps, tests

    * testing (wip)

    * fix trigger assignment

    * update submodules

    * wip

    * update build and test yamls

    * fix packaging

    * packaging: remove old setuptools options

    * get dcam test to pass

    * fix packaging

    * build and test passes

    * remove driver submodules

    * update dcam and egrabber test yamls

    * add GH token to environment variables in typing test.

    * Clean up build script

    * Address PR comments.

    * update zarr sha

    * update shas

    ---------

    Co-authored-by: Nathan Clack <[email protected]>

* update acquire-video-runtime

* wip: update zarr driver (?)

* wip

* Update drivers, fix bindings, fix tests.

* Misc fixes

* Ran black and flake8

* fix readme
  • Loading branch information
aliddell authored Jul 6, 2023
1 parent 238cd35 commit 06fd9be
Show file tree
Hide file tree
Showing 10 changed files with 212 additions and 56 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "acquire-imaging"
authors = ["Nathan Clack <[email protected]>"]
version = "0.1.3"
version = "0.1.4"
edition = "2021"

[lib]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ This project uses [`pre-commit`](https://pre-commit.com/) to run required
checks as git hooks.

```bash
pip install precommit
pip install pre-commit
pre-commit install
```

Expand Down
2 changes: 1 addition & 1 deletion acquire-video-runtime
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ fn fetch_acquire_driver(dst: &std::path::PathBuf, name: &str, tag: &str) {
} else {
format!("v{tag}")
};
let uri = format!("https://github.com/acquire-project/{name}/releases/download/{vstring}/{name}-{tag}-{build}.zip");
let uri = format!("https://github.com/acquire-project/{name}/releases/download/{vstring}/{name}-{vstring}-{build}.zip");
let request = client
.get(uri)
.header("Accept", "application/vnd.github+json")
Expand Down
8 changes: 4 additions & 4 deletions drivers.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"acquire-driver-common": "0.1.1",
"acquire-driver-zarr": "0.1.1",
"acquire-driver-egrabber": "0.1.1",
"acquire-driver-hdcam": "0.1.2"
"acquire-driver-common": "0.1.3",
"acquire-driver-zarr": "0.1.2",
"acquire-driver-egrabber": "0.1.2",
"acquire-driver-hdcam": "0.1.4"
}
15 changes: 14 additions & 1 deletion python/acquire/acquire.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,26 @@ class Storage:
settings: StorageProperties
def dict(self) -> Dict[str, Any]: ...

@final
class TileShape:
width: int
height: int
planes: int
def dict(self) -> Dict[str, Any]: ...

@final
class ChunkingProperties:
max_bytes_per_chunk: int
tile: TileShape
def dict(self) -> Dict[str, Any]: ...

@final
class StorageProperties:
bytes_per_chunk: int
external_metadata_json: Optional[str]
filename: Optional[str]
first_frame_id: int
pixel_scale_um: Tuple[float, float]
chunking: ChunkingProperties
def dict(self) -> Dict[str, Any]: ...

@final
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ fn acquire(py: Python, m: &PyModule) -> PyResult<()> {
m.add_class::<camera::CameraProperties>()?;
m.add_class::<camera::InputTriggers>()?;
m.add_class::<camera::OutputTriggers>()?;
m.add_class::<storage::TileShape>()?;
m.add_class::<storage::ChunkingProperties>()?;
m.add_class::<storage::StorageProperties>()?;

m.add_class::<components::Direction>()?;
Expand Down
148 changes: 144 additions & 4 deletions src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,49 @@ use std::{

#[pyclass]
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct TileShape {
#[pyo3(get, set)]
#[serde(default)]
pub(crate) width: u32,

#[pyo3(get, set)]
#[serde(default)]
pub(crate) height: u32,

#[pyo3(get, set)]
#[serde(default)]
pub(crate) planes: u32,
}

impl_plain_old_dict!(TileShape);

#[pyclass]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ChunkingProperties {
#[pyo3(get, set)]
#[serde(default)]
pub(crate) max_bytes_per_chunk: u64,

#[pyo3(get, set)]
pub(crate) tile: Py<TileShape>,
}

impl_plain_old_dict!(ChunkingProperties);

impl Default for ChunkingProperties {
fn default() -> Self {
let tile = Python::with_gil(|py| {
Py::new(py, TileShape::default()).unwrap()
});
Self {
max_bytes_per_chunk: Default::default(),
tile,
}
}
}

#[pyclass]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StorageProperties {
#[pyo3(get, set)]
#[serde(default)]
Expand All @@ -27,11 +70,26 @@ pub struct StorageProperties {
pub(crate) pixel_scale_um: (f64, f64),

#[pyo3(get, set)]
pub(crate) bytes_per_chunk: u32,
pub(crate) chunking: Py<ChunkingProperties>,
}

impl_plain_old_dict!(StorageProperties);

impl Default for StorageProperties {
fn default() -> Self {
let chunking = Python::with_gil(|py| {
Py::new(py, ChunkingProperties::default()).unwrap()
});
Self {
filename: Default::default(),
external_metadata_json: Default::default(),
first_frame_id: Default::default(),
pixel_scale_um: Default::default(),
chunking,
}
}
}

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

Expand All @@ -54,12 +112,25 @@ impl TryFrom<capi::StorageProperties> for StorageProperties {
.to_owned(),
)
};

let chunking = Python::with_gil(|py| {
let tile = Py::new(py, TileShape {
width: value.chunking.tile.width,
height: value.chunking.tile.height,
planes: value.chunking.tile.planes,
}).unwrap();
Py::new(py, ChunkingProperties {
max_bytes_per_chunk: value.chunking.max_bytes_per_chunk,
tile,
}).unwrap()
});

Ok(Self {
filename,
first_frame_id: value.first_frame_id,
external_metadata_json,
pixel_scale_um: (value.pixel_scale_um.x, value.pixel_scale_um.y),
bytes_per_chunk: value.bytes_per_chunk,
chunking,
})
}
}
Expand Down Expand Up @@ -93,6 +164,16 @@ impl TryFrom<&StorageProperties> for capi::StorageProperties {
(null(), 0)
};

let chunking_props = Python::with_gil(|py| -> PyResult<_> {
let chunking_props: ChunkingProperties = value.chunking.extract(py)?;
Ok(chunking_props)
})?;

let tile_shape = Python::with_gil(|py| -> PyResult<_> {
let tile_shape: TileShape = chunking_props.tile.extract(py)?;
Ok(tile_shape)
})?;

// This copies the string into a buffer owned by the return value.
if !unsafe {
capi::storage_properties_init(
Expand All @@ -106,7 +187,15 @@ impl TryFrom<&StorageProperties> for capi::StorageProperties {
x: value.pixel_scale_um.0,
y: value.pixel_scale_um.1,
},
value.bytes_per_chunk,
) == 1
} {
Err(anyhow::anyhow!("Failed acquire api status check"))
} else if !unsafe {
capi::storage_properties_set_chunking_props(&mut out,
tile_shape.width,
tile_shape.height,
tile_shape.planes,
chunking_props.max_bytes_per_chunk,
) == 1
} {
Err(anyhow::anyhow!("Failed acquire api status check"))
Expand All @@ -123,7 +212,7 @@ impl Default for capi::StorageProperties {
first_frame_id: Default::default(),
external_metadata_json: Default::default(),
pixel_scale_um: Default::default(),
bytes_per_chunk: Default::default(),
chunking: Default::default(),
}
}
}
Expand All @@ -147,6 +236,57 @@ impl Default for capi::PixelScale {
}
}

impl Default for capi::StorageProperties_storage_properties_chunking_s_storage_properties_chunking_tile_s {
fn default() -> Self {
Self {
width: Default::default(),
height: Default::default(),
planes: Default::default(),
}
}
}

impl Default for capi::StorageProperties_storage_properties_chunking_s {
fn default() -> Self {
Self {
max_bytes_per_chunk: Default::default(),
tile: Default::default(),
}
}
}

impl Default for capi::ImageShape_image_dims_s {
fn default() -> Self {
Self {
channels: Default::default(),
width: Default::default(),
height: Default::default(),
planes: Default::default(),
}
}
}

impl Default for capi::ImageShape_image_strides_s {
fn default() -> Self {
Self {
channels: Default::default(),
width: Default::default(),
height: Default::default(),
planes: Default::default(),
}
}
}

impl Default for capi::ImageShape {
fn default() -> Self {
Self {
dims: Default::default(),
strides: Default::default(),
type_: Default::default(),
}
}
}

impl Display for capi::String {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let s = unsafe { CStr::from_ptr(self.str_) }.to_string_lossy();
Expand Down
Loading

0 comments on commit 06fd9be

Please sign in to comment.