| IOLink Python 1.11.0

Loading...
Searching...
No Matches
diskImageView.py

This code demonstrates how to create an image view on disk and write/read data to/from it.

This code demonstrates how to create an image view on disk and write/read data to/from it. The code creates a 3D image of size 100x100x100 without allocating any CPU memory, and writes a line of data in each slice. Finally, it then reads and prints the value of the last written sample.

1 import iolink
2
3 import numpy as np
4
5
10 def diskImageView():
11 shape = iolink.VectorXu64(100, 100, 100)
12 dt = iolink.DataTypeId.DOUBLE
13
14 image = iolink.ImageViewFactory.create_on_disk(shape, dt)
15
16 print("Writing some data slice by slice, line by line")
17
18 lineSize = iolink.VectorXu64(shape[0], 1, 1)
19 valueInit = 0
20 for i in range(0, shape[2]):
21 for j in range(0, shape[1]):
22 lineRegion = iolink.RegionXu64((0, j, i), lineSize)
23 # create a buffer corresponding to the line size, and
24 # initialize it to the same value
25 lineBuffer = np.full((shape[0], 1), valueInit, dtype=float)
26 image.write_region(lineRegion, lineBuffer)
27 valueInit+=1
28
29 print("Writing completed")
30
31 return image
32
33
34image = diskImageView()
35
36print("Reading last sample")
37lastSampleValue = image.read((99, 99, 99))
38print("Last sample value:", lastSampleValue)
39
40print("SUCCESS")
diskImageView
Definition diskImageView.py:1