Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions fastplotlib/utils/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,14 +408,9 @@ def parse_cmap_values(


def cuda_to_numpy(arr: CudaArrayProtocol) -> np.ndarray:
try:
import cupy
except ImportError:
raise ImportError(
"`cupy` is required to work with GPU arrays\npip install cupy"
)

return cupy.asnumpy(arr)

Comment thread
kushalkolar marked this conversation as resolved.
data = np.from_dlpack(arr, device='cpu')
return data

Comment thread
kushalkolar marked this conversation as resolved.

def subsample_array(
Expand Down
14 changes: 8 additions & 6 deletions fastplotlib/widgets/nd_widget/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,13 @@ def spatial_dims(self, sdims: Sequence[str]):

self._spatial_dims = tuple(sdims)

@property
def spatial_dims_indices(self) -> tuple[int, ...]:
"""
The ordered spatial dim indices that correspond to the named spatial dims
"""
return tuple(self.spatial_dims.index(d) for d in self.dims if d in self.spatial_dims)

Comment thread
kushalkolar marked this conversation as resolved.
@property
def tooltip(self) -> bool:
"""
Expand Down Expand Up @@ -529,12 +536,7 @@ async def get_window_output(self, indices: dict[str, Any]) -> ArrayProtocol:
f"windowed_slice.ndim != len(self.spatial_dims): {windowed_slice.ndim} != {len(self.spatial_dims)}"
)

# transpose to spatial dims
spatial_dims_int = tuple(
self.spatial_dims.index(d) for d in self.dims if d in self.spatial_dims
)

return windowed_slice.transpose(*spatial_dims_int)
return windowed_slice

async def _get_raw_data_slice(self, indices: dict[str, Any]) -> ArrayProtocol:
"""
Expand Down
2 changes: 1 addition & 1 deletion fastplotlib/widgets/nd_widget/_nd_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ async def get(self, indices: dict[str, Any]) -> ArrayProtocol:
if isinstance(window_output, CudaArrayProtocol):
window_output = await run_in_thread_pool(self._executor, cuda_to_numpy, window_output)

return window_output
return window_output.transpose(*self.spatial_dims_indices)

def _recompute_histogram(self):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ def __init__(
self.cmap_transform_each = cmap_transform_each
self.sizes = sizes


Comment thread
kushalkolar marked this conversation as resolved.
def _check_shape_feature(
self, prop: str, check_shape: tuple[int, int]
) -> tuple[int, int]:
Expand Down Expand Up @@ -555,6 +556,8 @@ async def get(self, indices: dict[str, Any]) -> dict[str, ArrayProtocol]:
if isinstance(data, CudaArrayProtocol):
data = await run_in_thread_pool(self._executor, cuda_to_numpy, data)

data = data.transpose(*self.spatial_dims_indices)

return {
"data": data,
**other,
Expand Down
4 changes: 2 additions & 2 deletions fastplotlib/widgets/nd_widget/_nd_vectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ async def get(self, indices: dict[str, Any]) -> ArrayProtocol:
Example: get((100, 5))

"""
# this will be squeezed output, with dims in the order of the user set spatial dims
# this will be squeezed output, with dims in the order of self.dims
window_output = await self.get_window_output(indices)

# apply spatial_func; CUDA arrays run inline, numpy goes through the thread pool
Expand All @@ -175,7 +175,7 @@ async def get(self, indices: dict[str, Any]) -> ArrayProtocol:
if isinstance(window_output, CudaArrayProtocol):
window_output = await run_in_thread_pool(self._executor, cuda_to_numpy, window_output)

return window_output
return window_output.transpose(*self.spatial_dims_indices)


class NDVectors(NDGraphic):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ keywords = [
]
requires-python = ">= 3.10"
dependencies = [
"numpy>=1.23.0",
"numpy>=2.1.0",
"pygfx==0.16.0",
"wgpu", # Let pygfx constrain the wgpu version
"cmap>=0.1.3",
Expand Down