Example #1
0
# the file COPYING, which can be found at the root of the source code        #
# distribution tree.  If you do not have access to this file, you may        #
# request a copy from [email protected].                                     #
##############################################################################
import config
import numpy as np

if config.get("use_h5py"):
    import h5py
else:
    import h5pyd as h5py

  
from common import ut, TestCase

        
class TestCommittedType(TestCase):
    def test_createtype(self):
        filename = self.getFileName("committed_type")
        print("filename:", filename)
        f = h5py.File(filename, "w")
        # create a compound numpy type 
        dt = np.dtype([('real', np.float), ('img', np.float)])
        f['complex_type'] = dt
 
        dset = f.create_dataset('complex_dset', (10,), dtype=f['complex_type'])
        f.close()  
        
if __name__ == '__main__':
    ut.main()
Example #2
0
class TestDatasetCompound(TestCase):
    def test_create_compound_dset(self):
        filename = self.getFileName("create_compound_dset")
        print("filename:", filename)
        f = h5py.File(filename, "w")

        #curl -v --header "Host: create_compound_dset.h5pyd_test.hdfgroup.org" http://127.0.0.1:5000

        count = 10

        dt = np.dtype([('real', np.float), ('img', np.float)])
        dset = f.create_dataset('complex', (count, ), dtype=dt)

        elem = dset[0]
        for i in range(count):
            theta = (4.0 * math.pi) * (float(i) / float(count))
            elem['real'] = math.cos(theta)
            elem['img'] = math.sin(theta)
            dset[i] = elem

        val = dset[0]
        self.assertEqual(val['real'], 1.0)
        f.close()


if __name__ == '__main__':
    loglevel = logging.ERROR
    logging.basicConfig(format='%(asctime)s %(message)s', level=loglevel)
    ut.main()