In [1]:
from tomokth.dataset import CalibrationData, ParticleData

Calibration Data


In [2]:
cd assignment/calibration_images/


/home/avmo/src/PIV/TomoKTH/examples/assignment/calibration_images

In [3]:
cdata = CalibrationData()
cdata.config()
cdata.create_h5()

The object cdata now manages all the calibration images. The images are converted to arrays into a file called calibration.h5. A HDF5 file can be opened using the utility HDFview. Data is arranged in the following hierarchy:


In [6]:
import json
print json.dumps(cdata.h5dict, indent=4) #Json used to print cdata.h5dict neatly


{
    "cam3": [
        "-3mm_cam3.tif", 
        "-6mm_cam3.tif", 
        "0mm_cam3.tif", 
        "3mm_cam3.tif", 
        "6mm_cam3.tif"
    ], 
    "cam2": [
        "-3mm_cam2.tif", 
        "-6mm_cam2.tif", 
        "0mm_cam2.tif", 
        "3mm_cam2.tif", 
        "6mm_cam2.tif"
    ], 
    "cam1": [
        "-3mm_cam1.tif", 
        "-6mm_cam1.tif", 
        "0mm_cam1.tif", 
        "3mm_cam1.tif", 
        "6mm_cam1.tif"
    ], 
    "cam0": [
        "-3mm_cam0.tif", 
        "-6mm_cam0.tif", 
        "0mm_cam0.tif", 
        "3mm_cam0.tif", 
        "6mm_cam0.tif"
    ]
}

To retrieve a specific calibration image, from the HDF5 file, as a numpy array:


In [9]:
arr = cdata.get_dset(camera=0, z_loc=-6) #Note: It returns a numpy array, not a h5py dataset!
print arr


Out[9]:
array([[0, 0, 0, ..., 0, 0, 0],
       [0, 0, 0, ..., 0, 0, 0],
       [0, 0, 0, ..., 0, 0, 0],
       ..., 
       [0, 0, 0, ..., 0, 0, 0],
       [0, 0, 0, ..., 0, 0, 0],
       [0, 0, 0, ..., 0, 0, 0]], dtype=uint16)

To retrieve a group of datasets by specifying just the camera:


In [11]:
grp = cdata.get_camera_grp(camera=0)
print grp


<HDF5 group "/cam0" (5 members)>

To iterate through the group use:

Note that the group and the datasets have attributes stored in them.


In [16]:
print 'Group attributes = ', grp.attrs.keys(), grp.attrs['cam']

for dset in grp.values():
    print dset
    print 'Dataset attributes = ', dset.attrs.keys(), dset.attrs['cam'], dset.attrs['z']
    arr = dset[...]
    print arr


Group attributes =  [u'cam'] 0
<HDF5 dataset "-3mm_cam0.tif": shape (500, 504), type "<u2">
Dataset attributes =  [u'cam', u'z'] 0 -3
[[0 0 0 ..., 0 0 0]
 [0 0 0 ..., 0 0 0]
 [0 0 0 ..., 0 0 0]
 ..., 
 [0 0 0 ..., 0 0 0]
 [0 0 0 ..., 0 0 0]
 [0 0 0 ..., 0 0 0]]
<HDF5 dataset "-6mm_cam0.tif": shape (500, 504), type "<u2">
Dataset attributes =  [u'cam', u'z'] 0 -6
[[0 0 0 ..., 0 0 0]
 [0 0 0 ..., 0 0 0]
 [0 0 0 ..., 0 0 0]
 ..., 
 [0 0 0 ..., 0 0 0]
 [0 0 0 ..., 0 0 0]
 [0 0 0 ..., 0 0 0]]
<HDF5 dataset "0mm_cam0.tif": shape (500, 504), type "<u2">
Dataset attributes =  [u'cam', u'z'] 0 0
[[0 0 0 ..., 0 0 0]
 [0 0 0 ..., 0 0 0]
 [0 0 0 ..., 0 0 0]
 ..., 
 [0 0 0 ..., 0 0 0]
 [0 0 0 ..., 0 0 0]
 [0 0 0 ..., 0 0 0]]
<HDF5 dataset "3mm_cam0.tif": shape (500, 504), type "<u2">
Dataset attributes =  [u'cam', u'z'] 0 3
[[0 0 0 ..., 0 0 0]
 [0 0 0 ..., 0 0 0]
 [0 0 0 ..., 0 0 0]
 ..., 
 [0 0 0 ..., 0 0 0]
 [0 0 0 ..., 0 0 0]
 [0 0 0 ..., 0 0 0]]
<HDF5 dataset "6mm_cam0.tif": shape (500, 504), type "<u2">
Dataset attributes =  [u'cam', u'z'] 0 6
[[0 0 0 ..., 0 0 0]
 [0 0 0 ..., 0 0 0]
 [0 0 0 ..., 0 0 0]
 ..., 
 [0 0 0 ..., 0 0 0]
 [0 0 0 ..., 0 0 0]
 [0 0 0 ..., 0 0 0]]

Particle Data


In [17]:
cd ../particle_images/


/home/avmo/src/PIV/TomoKTH/examples/assignment/particle_images

In [18]:
pdata = ParticleData()
pdata.config()
pdata.create_h5()

The object cdata now manages all the particle images. The images are converted to arrays into a file called particle.h5.

ParticleData object also behaves similarly as a CalibrationData object.

Note that the attributes are slightly different, hence the arguments for the function get_dset has slightly changed


In [22]:
arr = pdata.get_dset(camera=0, ab='a', time=47)

In [23]:
grp = pdata.get_camera_grp(camera=0)

In [ ]: