-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add sample data and reader plugin (#18)
* add sample data plugin * add demo CLI * add comments * add obj file reader plugin * add higher level import * add higher level import
- Loading branch information
1 parent
69a4d75
commit 982d28c
Showing
9 changed files
with
175 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ install_requires = | |
magicgui | ||
mrcfile | ||
numpy | ||
pooch | ||
qtpy | ||
rich | ||
scikit-image | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from surforama.data._datasets import thylakoid_membrane | ||
|
||
__all__ = ("thylakoid_membrane",) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
from typing import List, Tuple | ||
|
||
import mrcfile | ||
import numpy as np | ||
import pooch | ||
from napari.types import LayerDataTuple | ||
|
||
from surforama.io.mesh import read_obj_file | ||
|
||
_data_registry = pooch.create( | ||
path=pooch.os_cache("mypackage"), | ||
base_url="doi:10.5281/zenodo.10814409", | ||
registry={ | ||
"S1_M3b_StII_grow2_1_mesh_data.mrc": "md5:a6e34bbf4edc767aa6c2c854c81c9c97", | ||
"S1_M3b_StII_grow2_1_mesh_data.obj": "md5:63b7d681204d7d3a3937154a0f4d7fc1", | ||
"S1_M3b_StII_grow2_1_mesh_data_seg.mrc": "md5:d88460eb3bdf3164be6053d281fc45be", | ||
"S1_M3c_StOI_grow2_1_mesh_data.mrc": "md5:296fbc48917c2baab7784a5ede6aae70", | ||
"S1_M3c_StOI_grow2_1_mesh_data.obj": "md5:076e6e8a825f67a24e28beba09edcf70", | ||
"S1_M3c_StOI_grow2_1_mesh_data_seg.mrc": "md5:878d4b3fc076dfc01e788cc08f9c9201", | ||
}, | ||
) | ||
|
||
|
||
def thylakoid_membrane() -> ( | ||
Tuple[np.ndarray, Tuple[np.ndarray, np.ndarray, np.ndarray]] | ||
): | ||
"""Fetch the thylakoid membrane sample data. | ||
Data originally from Wietrzynski and Schaffer et al., eLife, 2020. | ||
https://doi.org/10.7554/eLife.53740 | ||
""" | ||
# get the tomogram | ||
tomogram_path = _data_registry.fetch( | ||
"S1_M3b_StII_grow2_1_mesh_data.mrc", progressbar=True | ||
) | ||
tomogram = mrcfile.read(tomogram_path) | ||
|
||
# get the mesh | ||
mesh_path = _data_registry.fetch( | ||
"S1_M3b_StII_grow2_1_mesh_data.obj", progressbar=True | ||
) | ||
mesh_data = read_obj_file(mesh_path) | ||
|
||
return tomogram, mesh_data | ||
|
||
|
||
def _thylakoid_membrane_sample_data_plugin() -> List[LayerDataTuple]: | ||
"""napari sample data plugin for thylakoid membrane dataset.""" | ||
|
||
# get the data | ||
tomogram, mesh_data = thylakoid_membrane() | ||
|
||
return [ | ||
(tomogram, {"name": "tomogram"}, "image"), | ||
(mesh_data, {"name": "mesh"}, "surface"), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from surforama.io.mesh import read_obj_file | ||
|
||
__all__ = ("read_obj_file",) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from typing import Callable, List | ||
|
||
from napari.types import LayerDataTuple | ||
|
||
from surforama.io import read_obj_file | ||
|
||
|
||
def mesh_reader_plugin(path: str) -> Callable[[str], LayerDataTuple]: | ||
if isinstance(path, str) and path.endswith(".obj"): | ||
return obj_reader | ||
|
||
# format not recognized | ||
return None | ||
|
||
|
||
def obj_reader(path: str) -> List[LayerDataTuple]: | ||
mesh_data = read_obj_file(path) | ||
return [(mesh_data, {}, "surface")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import numpy as np | ||
import trimesh | ||
|
||
|
||
def read_obj_file(file_path): | ||
mesh = trimesh.load(file_path, file_type="obj", process=True) | ||
|
||
# Subdivide | ||
# verts, faces = trimesh.remesh.subdivide_to_size( | ||
# mesh.vertices, mesh.faces, 1 | ||
# ) | ||
|
||
# Subdivide can introduce holes | ||
# mesh = trimesh.Trimesh(vertices=verts, faces=faces) | ||
# trimesh.repair.fill_holes(mesh) | ||
|
||
verts = mesh.vertices | ||
faces = mesh.faces | ||
|
||
verts = verts[:, [2, 1, 0]] | ||
|
||
values = np.ones((len(verts),)) | ||
|
||
return verts, faces, values |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters