|
1 | 1 | from __future__ import annotations
|
2 | 2 |
|
3 |
| -import numpy as np |
4 |
| - |
5 |
| - |
6 |
| -def generate_5d_sine_wave( |
7 |
| - shape: tuple[int, int, int, int, int], |
8 |
| - amplitude: float = 240, |
9 |
| - base_frequency: float = 5, |
10 |
| -) -> np.ndarray: |
11 |
| - """5D dataset.""" |
12 |
| - # Unpack the dimensions |
13 |
| - angle_dim, freq_dim, phase_dim, ny, nx = shape |
14 |
| - |
15 |
| - # Create an empty array to hold the data |
16 |
| - output = np.zeros(shape) |
17 |
| - |
18 |
| - # Define spatial coordinates for the last two dimensions |
19 |
| - half_per = base_frequency * np.pi |
20 |
| - x = np.linspace(-half_per, half_per, nx) |
21 |
| - y = np.linspace(-half_per, half_per, ny) |
22 |
| - y, x = np.meshgrid(y, x) |
23 |
| - |
24 |
| - # Iterate through each parameter in the higher dimensions |
25 |
| - for phase_idx in range(phase_dim): |
26 |
| - for freq_idx in range(freq_dim): |
27 |
| - for angle_idx in range(angle_dim): |
28 |
| - # Calculate phase and frequency |
29 |
| - phase = np.pi / phase_dim * phase_idx |
30 |
| - frequency = 1 + (freq_idx * 0.1) # Increasing frequency with each step |
31 |
| - |
32 |
| - # Calculate angle |
33 |
| - angle = np.pi / angle_dim * angle_idx |
34 |
| - # Rotate x and y coordinates |
35 |
| - xr = np.cos(angle) * x - np.sin(angle) * y |
36 |
| - np.sin(angle) * x + np.cos(angle) * y |
37 |
| - |
38 |
| - # Compute the sine wave |
39 |
| - sine_wave = (amplitude * 0.5) * np.sin(frequency * xr + phase) |
40 |
| - sine_wave += amplitude * 0.5 |
41 |
| - |
42 |
| - # Assign to the output array |
43 |
| - output[angle_idx, freq_idx, phase_idx] = sine_wave |
44 |
| - |
45 |
| - return output |
46 |
| - |
| 3 | +import ndv |
47 | 4 |
|
48 | 5 | try:
|
49 |
| - from skimage import data |
50 |
| - |
51 |
| - img = data.cells3d() |
52 |
| -except Exception: |
53 |
| - img = generate_5d_sine_wave((10, 3, 8, 512, 512)) |
54 |
| - |
55 |
| - |
56 |
| -if __name__ == "__main__": |
57 |
| - from qtpy import QtWidgets |
58 |
| - |
59 |
| - from ndv import NDViewer |
| 6 | + img = ndv.data.cells3d() |
| 7 | +except Exception as e: |
| 8 | + print(e) |
| 9 | + img = ndv.data.nd_sine_wave((10, 3, 8, 512, 512)) |
60 | 10 |
|
61 |
| - qapp = QtWidgets.QApplication([]) |
62 |
| - v = NDViewer(img) |
63 |
| - v.show() |
64 |
| - qapp.exec() |
| 11 | +ndv.imshow(img) |
0 commit comments