Skip to content
This repository has been archived by the owner on May 31, 2023. It is now read-only.

Commit

Permalink
Fix meshes (#122)
Browse files Browse the repository at this point in the history
* upgrade deps + fix get_meshes api
* pretty
  • Loading branch information
normanrz authored Jan 13, 2022
1 parent debad50 commit a663c4f
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 72 deletions.
96 changes: 64 additions & 32 deletions fast_wkw/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions fast_wkw/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ crate-type = ["cdylib"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
pyo3 = { version = "0.13", features = ["extension-module"] }
pyo3-asyncio = { version = "0.13", features = ["tokio-runtime"] }
tokio = "1.4"
pyo3 = { version = "0.15", features = ["extension-module"] }
pyo3-asyncio = { version = "0.15", features = ["tokio-runtime"] }
tokio = "1.15"
wkwrap = "1.6.0"
lz4_flex = "0.8"
lz4_flex = "0.9"
memmap = "0.7"
lru = "0.6"
lru = "0.7"
31 changes: 14 additions & 17 deletions fast_wkw/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ struct DatasetHandle {
impl DatasetHandle {
fn read_block(&self, py: Python, src_pos: (u32, u32, u32)) -> PyResult<PyObject> {
let dataset = self.dataset.clone();
pyo3_asyncio::tokio::into_coroutine(py, async move {
let result = pyo3_asyncio::tokio::future_into_py(py, async move {
let (buf, dtype, shape) = tokio::task::spawn_blocking(move || {
let offset = wkwrap::Vec3 {
x: src_pos.0,
Expand All @@ -92,27 +92,24 @@ impl DatasetHandle {
Python::with_gil(|py| {
let py_bytes = PyBytes::new(py, &buf);
let py_bytes: PyObject = py_bytes.into();
Ok(
Py::new(
py,
Block {
buf: py_bytes,
dtype,
shape,
},
)
.unwrap()
.into_py(py),
)
let py_block = Py::new(
py,
Block {
buf: py_bytes,
dtype,
shape,
},
)?;
Ok(py_block)
})
})
})?;
Ok(Py::from(result))
}
}

#[pymodule]
fn fast_wkw(py: Python, m: &PyModule) -> PyResult<()> {
pyo3_asyncio::try_init(py)?;
pyo3_asyncio::tokio::init_multi_thread_once();
fn fast_wkw(_py: Python, m: &PyModule) -> PyResult<()> {
pyo3::prepare_freethreaded_python();

m.add_class::<DatasetCache>()?;
m.add_class::<DatasetHandle>()?;
Expand Down
2 changes: 1 addition & 1 deletion fast_wkw/src/wkw_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl WkwFile {
.ok_or(String::from("Could not read block from disk"))?;

// decompress block
let byte_written = match decompress_into(&buf_from_disk, buf, 0) {
let byte_written = match decompress_into(&buf_from_disk, buf) {
Ok(byte_written) => byte_written,
Err(_) => return Err(String::from("Error in LZ4 decompress")),
};
Expand Down
12 changes: 6 additions & 6 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ mypy = "==0.770"
pep8-naming = "*"
py-spy = "*"
pylint = "2.8.3"
setuptools-rust = "^0.12.1"
setuptools-rust = "^1.1.2"

[build-system]
requires = ["poetry>=0.12", "wheel", "setuptools-rust"]
Expand Down
12 changes: 10 additions & 2 deletions wkconnect/backends/backend.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from abc import ABCMeta, abstractmethod
from typing import Dict, List, Optional
from typing import Dict, List, NamedTuple, Optional

import numpy as np
from aiohttp import ClientSession
Expand Down Expand Up @@ -54,7 +54,7 @@ async def read_data(

async def get_meshes(
self, dataset: DatasetInfo, layer_name: str
) -> Optional[List[str]]:
) -> Optional[List["MeshfileInfo"]]:
"""
List the available meshfiles of a layer from the backend.
Expand Down Expand Up @@ -104,3 +104,11 @@ def clear_dataset_cache(self, dataset: DatasetInfo) -> None:

async def on_shutdown(self) -> None:
pass


class MeshfileInfo(NamedTuple):
mesh_file_name: str
mapping_name: Optional[str] = None

def as_json(self) -> Dict[str, Optional[str]]:
return {"meshFileName": self.mesh_file_name, "mappingName": self.mapping_name}
6 changes: 3 additions & 3 deletions wkconnect/backends/neuroglancer/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from ...utils.exceptions import RuntimeErrorWithUserMessage
from ...utils.types import JSON, Box3D, Vec3D, Vec3Df
from ..backend import Backend, DatasetInfo
from ..backend import Backend, DatasetInfo, MeshfileInfo
from ..neuroglancer.meshes import Meshfile, MeshfileLod, MeshInfo
from .models import Dataset, Layer, Scale
from .sharding import MinishardInfo, ShardingInfo
Expand Down Expand Up @@ -428,10 +428,10 @@ async def __read_mesh_data(

async def get_meshes(
self, abstract_dataset: DatasetInfo, layer_name: str
) -> Optional[List[str]]:
) -> Optional[List[MeshfileInfo]]:
dataset = cast(Dataset, abstract_dataset)
if layer_name in dataset.layers and dataset.layers[layer_name].mesh:
return [MESH_NAME]
return [MeshfileInfo(mesh_file_name=MESH_NAME)]
return []

async def get_chunks_for_mesh(
Expand Down
Loading

0 comments on commit a663c4f

Please sign in to comment.