-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cadf550
commit ed8f547
Showing
23 changed files
with
2,343 additions
and
67 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
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,32 @@ | ||
from __future__ import annotations | ||
|
||
import numpy as np | ||
|
||
try: | ||
from dask.array.core import map_blocks | ||
except ImportError: | ||
raise ImportError("Please `pip install dask[array]` to run this example.") | ||
|
||
frame_size = (1024, 1024) | ||
|
||
|
||
def _dask_block(block_id: tuple[int, int, int, int, int]) -> np.ndarray | None: | ||
if isinstance(block_id, np.ndarray): | ||
return None | ||
data = np.random.randint(0, 255, size=frame_size, dtype=np.uint8) | ||
return data[(None,) * 3] | ||
|
||
|
||
chunks = [(1,) * x for x in (1000, 64, 3)] | ||
chunks += [(x,) for x in frame_size] | ||
dask_arr = map_blocks(_dask_block, chunks=chunks, dtype=np.uint8) | ||
|
||
if __name__ == "__main__": | ||
from qtpy import QtWidgets | ||
|
||
from ndv import NDViewer | ||
|
||
qapp = QtWidgets.QApplication([]) | ||
v = NDViewer(dask_arr) | ||
v.show() | ||
qapp.exec() |
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,20 @@ | ||
from __future__ import annotations | ||
|
||
try: | ||
import jax.numpy as jnp | ||
except ImportError: | ||
raise ImportError("Please install jax to run this example") | ||
from numpy_arr import generate_5d_sine_wave | ||
from qtpy import QtWidgets | ||
|
||
from ndv import NDViewer | ||
|
||
# Example usage | ||
array_shape = (10, 3, 5, 512, 512) # Specify the desired dimensions | ||
sine_wave_5d = jnp.asarray(generate_5d_sine_wave(array_shape)) | ||
|
||
if __name__ == "__main__": | ||
qapp = QtWidgets.QApplication([]) | ||
v = NDViewer(sine_wave_5d, channel_axis=1) | ||
v.show() | ||
qapp.exec() |
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,64 @@ | ||
from __future__ import annotations | ||
|
||
import numpy as np | ||
|
||
|
||
def generate_5d_sine_wave( | ||
shape: tuple[int, int, int, int, int], | ||
amplitude: float = 240, | ||
base_frequency: float = 5, | ||
) -> np.ndarray: | ||
"""5D dataset.""" | ||
# Unpack the dimensions | ||
angle_dim, freq_dim, phase_dim, ny, nx = shape | ||
|
||
# Create an empty array to hold the data | ||
output = np.zeros(shape) | ||
|
||
# Define spatial coordinates for the last two dimensions | ||
half_per = base_frequency * np.pi | ||
x = np.linspace(-half_per, half_per, nx) | ||
y = np.linspace(-half_per, half_per, ny) | ||
y, x = np.meshgrid(y, x) | ||
|
||
# Iterate through each parameter in the higher dimensions | ||
for phase_idx in range(phase_dim): | ||
for freq_idx in range(freq_dim): | ||
for angle_idx in range(angle_dim): | ||
# Calculate phase and frequency | ||
phase = np.pi / phase_dim * phase_idx | ||
frequency = 1 + (freq_idx * 0.1) # Increasing frequency with each step | ||
|
||
# Calculate angle | ||
angle = np.pi / angle_dim * angle_idx | ||
# Rotate x and y coordinates | ||
xr = np.cos(angle) * x - np.sin(angle) * y | ||
np.sin(angle) * x + np.cos(angle) * y | ||
|
||
# Compute the sine wave | ||
sine_wave = (amplitude * 0.5) * np.sin(frequency * xr + phase) | ||
sine_wave += amplitude * 0.5 | ||
|
||
# Assign to the output array | ||
output[angle_idx, freq_idx, phase_idx] = sine_wave | ||
|
||
return output | ||
|
||
|
||
try: | ||
from skimage import data | ||
|
||
img = data.cells3d() | ||
except Exception: | ||
img = generate_5d_sine_wave((10, 3, 8, 512, 512)) | ||
|
||
|
||
if __name__ == "__main__": | ||
from qtpy import QtWidgets | ||
|
||
from ndv import NDViewer | ||
|
||
qapp = QtWidgets.QApplication([]) | ||
v = NDViewer(img) | ||
v.show() | ||
qapp.exec() |
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,23 @@ | ||
from __future__ import annotations | ||
|
||
import numpy as np | ||
import tensorstore as ts | ||
from qtpy import QtWidgets | ||
|
||
from ndv import NDViewer | ||
|
||
shape = (10, 4, 3, 512, 512) | ||
ts_array = ts.open( | ||
{"driver": "zarr", "kvstore": {"driver": "memory"}}, | ||
create=True, | ||
shape=shape, | ||
dtype=ts.uint8, | ||
).result() | ||
ts_array[:] = np.random.randint(0, 255, size=shape, dtype=np.uint8) | ||
ts_array = ts_array[ts.d[:].label["t", "c", "z", "y", "x"]] | ||
|
||
if __name__ == "__main__": | ||
qapp = QtWidgets.QApplication([]) | ||
v = NDViewer(ts_array) | ||
v.show() | ||
qapp.exec() |
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,14 @@ | ||
from __future__ import annotations | ||
|
||
import xarray as xr | ||
from qtpy import QtWidgets | ||
|
||
from ndv import NDViewer | ||
|
||
da = xr.tutorial.open_dataset("air_temperature").air | ||
|
||
if __name__ == "__main__": | ||
qapp = QtWidgets.QApplication([]) | ||
v = NDViewer(da, colormaps=["thermal"], channel_mode="composite") | ||
v.show() | ||
qapp.exec() |
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,16 @@ | ||
from __future__ import annotations | ||
|
||
import zarr | ||
import zarr.storage | ||
from qtpy import QtWidgets | ||
|
||
from ndv import NDViewer | ||
|
||
URL = "https://s3.embl.de/i2k-2020/ngff-example-data/v0.4/tczyx.ome.zarr" | ||
zarr_arr = zarr.open(URL, mode="r") | ||
|
||
if __name__ == "__main__": | ||
qapp = QtWidgets.QApplication([]) | ||
v = NDViewer(zarr_arr["s0"]) | ||
v.show() | ||
qapp.exec() |
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 |
---|---|---|
|
@@ -8,3 +8,8 @@ | |
__version__ = "uninstalled" | ||
__author__ = "Talley Lambert" | ||
__email__ = "[email protected]" | ||
|
||
from .viewer._indexing import DataWrapper | ||
from .viewer._stack_viewer import NDViewer | ||
|
||
__all__ = ["NDViewer", "DataWrapper"] |
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 @@ | ||
"""viewer source.""" |
Oops, something went wrong.