Ejemplo n.º 1
0
    def testCompoundTypeItem(self):
        dt = np.dtype([("temp", np.float32), ("pressure", np.float32),
                       ("wind", np.int16)])
        typeItem = hdf5dtype.getTypeItem(dt)
        typeSize = hdf5dtype.getItemSize(typeItem)
        self.assertEqual(typeItem['class'], 'H5T_COMPOUND')
        self.assertTrue('fields' in typeItem)
        fields = typeItem['fields']
        self.assertEqual(len(fields), 3)
        tempField = fields[0]
        self.assertEqual(tempField['name'], 'temp')
        self.assertTrue('type' in tempField)
        tempFieldType = tempField['type']
        self.assertEqual(tempFieldType['class'], 'H5T_FLOAT')
        self.assertEqual(tempFieldType['base'], 'H5T_IEEE_F32LE')
        self.assertEqual(typeSize, 10)

        typeItem = hdf5dtype.getTypeResponse(typeItem)  # non-verbose format
        typeSize = hdf5dtype.getItemSize(typeItem)
        self.assertEqual(typeItem['class'], 'H5T_COMPOUND')
        self.assertTrue('fields' in typeItem)
        fields = typeItem['fields']
        self.assertEqual(len(fields), 3)
        tempField = fields[0]
        self.assertEqual(tempField['name'], 'temp')
        self.assertTrue('type' in tempField)
        tempFieldType = tempField['type']
        self.assertEqual(tempFieldType['class'], 'H5T_FLOAT')
        self.assertEqual(tempFieldType['base'], 'H5T_IEEE_F32LE')
        self.assertEqual(typeSize, 10)
Ejemplo n.º 2
0
 def testOpaqueTypeItem(self):
     dt = np.dtype('V200')
     typeItem = hdf5dtype.getTypeItem(dt)
     typeSize = hdf5dtype.getItemSize(typeItem)
     self.assertEqual(typeItem['class'], 'H5T_OPAQUE')
     self.assertTrue('base' not in typeItem)
     self.assertEqual(typeSize, 200)
Ejemplo n.º 3
0
 def testBaseStringTypeItem(self):
     dt = np.dtype('S3')
     typeItem = hdf5dtype.getTypeItem(dt)
     self.assertEqual(typeItem['class'], 'H5T_STRING')
     self.assertEqual(typeItem['length'], 3)
     self.assertEqual(typeItem['strPad'], 'H5T_STR_NULLPAD')
     self.assertEqual(typeItem['charSet'], 'H5T_CSET_ASCII')
Ejemplo n.º 4
0
    def testCompoundArrayVlenStringTypeItem(self):
        dt_vlen = special_dtype(vlen=bytes)
        dt_arr = np.dtype((dt_vlen, (4, )))
        dt_compound = np.dtype([('VALUE1', np.float64), ('VALUE2', np.int64),
                                ('VALUE3', dt_arr)])
        typeItem = hdf5dtype.getTypeItem(dt_compound)

        typeSize = hdf5dtype.getItemSize(typeItem)
        self.assertEqual(typeSize, 'H5T_VARIABLE')
        self.assertEqual(typeItem['class'], 'H5T_COMPOUND')
        fields = typeItem['fields']
        field_a = fields[0]
        self.assertEqual(field_a['name'], 'VALUE1')
        field_a_type = field_a['type']
        self.assertEqual(field_a_type['class'], 'H5T_FLOAT')
        self.assertEqual(field_a_type['base'], 'H5T_IEEE_F64LE')
        field_b = fields[1]
        self.assertEqual(field_b['name'], 'VALUE2')
        field_b_type = field_b['type']
        self.assertEqual(field_b_type['class'], 'H5T_INTEGER')
        self.assertEqual(field_b_type['base'], 'H5T_STD_I64LE')
        field_c = fields[2]
        field_c_type = field_c['type']

        self.assertEqual(field_c_type['class'], 'H5T_ARRAY')
        self.assertEqual(field_c_type['dims'], (4, ))
        field_c_base_type = field_c_type['base']
        self.assertEqual(field_c_base_type['class'], 'H5T_STRING')
        self.assertEqual(field_c_base_type['length'], 'H5T_VARIABLE')
        self.assertEqual(field_c_base_type['charSet'], 'H5T_CSET_ASCII')
Ejemplo n.º 5
0
 def testBaseStringUTFTypeItem(self):
     dt = np.dtype('U3')
     try:
         typeItem = hdf5dtype.getTypeItem(dt)
         self.assertTrue(typeItem is not None)  # avoid pyflakes error
         self.assertTrue(False)  # expected exception
     except TypeError:
         pass  # expected
Ejemplo n.º 6
0
 def testBaseFloat16TypeItem(self):
     dt = np.dtype('<f2')
     typeItem = hdf5dtype.getTypeItem(dt)
     self.assertEqual(typeItem['class'], 'H5T_FLOAT')
     self.assertEqual(typeItem['base'], 'H5T_IEEE_F16LE')
     typeItem = hdf5dtype.getTypeResponse(typeItem)  # non-verbose format
     self.assertEqual(typeItem['class'], 'H5T_FLOAT')
     self.assertEqual(typeItem['base'], 'H5T_IEEE_F16LE')
Ejemplo n.º 7
0
 def testBaseIntegerTypeItem(self):
     dt = np.dtype('<i1')
     typeItem = hdf5dtype.getTypeItem(dt)
     self.assertEqual(typeItem['class'], 'H5T_INTEGER')
     self.assertEqual(typeItem['base'], 'H5T_STD_I8LE')
     typeItem = hdf5dtype.getTypeResponse(typeItem)  # non-verbose format
     self.assertEqual(typeItem['class'], 'H5T_INTEGER')
     self.assertEqual(typeItem['base'], 'H5T_STD_I8LE')
Ejemplo n.º 8
0
 def testBaseVLenUnicodeTypeItem(self):
     dt = special_dtype(vlen=str)
     typeItem = hdf5dtype.getTypeItem(dt)
     typeSize = hdf5dtype.getItemSize(typeItem)
     self.assertEqual(typeItem['class'], 'H5T_STRING')
     self.assertEqual(typeItem['length'], 'H5T_VARIABLE')
     self.assertEqual(typeItem['strPad'], 'H5T_STR_NULLTERM')
     self.assertEqual(typeItem['charSet'], 'H5T_CSET_UTF8')
     self.assertEqual(typeSize, 'H5T_VARIABLE')
Ejemplo n.º 9
0
 def testVlenDataItem(self):
     dt = special_dtype(vlen=np.dtype('int32'))
     typeItem = hdf5dtype.getTypeItem(dt)
     typeSize = hdf5dtype.getItemSize(typeItem)
     self.assertEqual(typeItem['class'], 'H5T_VLEN')
     self.assertEqual(typeItem['size'], 'H5T_VARIABLE')
     baseItem = typeItem['base']
     self.assertEqual(baseItem['base'], 'H5T_STD_I32LE')
     self.assertEqual(typeSize, 'H5T_VARIABLE')
Ejemplo n.º 10
0
 def testBaseArrayTypeItem(self):
     dt = np.dtype('(2,2)<int32')
     typeItem = hdf5dtype.getTypeItem(dt)
     typeSize = hdf5dtype.getItemSize(typeItem)
     self.assertEqual(typeItem['class'], 'H5T_ARRAY')
     baseItem = typeItem['base']
     self.assertEqual(baseItem['class'], 'H5T_INTEGER')
     self.assertEqual(baseItem['base'], 'H5T_STD_I32LE')
     self.assertEqual(typeSize, 16)
Ejemplo n.º 11
0
 def testObjReferenceTypeItem(self):
     dt = special_dtype(ref=Reference)
     typeItem = hdf5dtype.getTypeItem(dt)
     typeSize = hdf5dtype.getItemSize(typeItem)
     self.assertEqual(typeItem['class'], 'H5T_REFERENCE')
     self.assertEqual(typeItem['base'], 'H5T_STD_REF_OBJ')
     # length of obj id, e.g.:
     # g-b2c9a750-a557-11e7-ab09-0242ac110009
     self.assertEqual(typeSize, 48)
Ejemplo n.º 12
0
 def testBaseEnumTypeItem(self):
     mapping = {'RED': 0, 'GREEN': 1, 'BLUE': 2}
     dt = special_dtype(enum=(np.int8, mapping))
     typeItem = hdf5dtype.getTypeItem(dt)
     typeSize = hdf5dtype.getItemSize(typeItem)
     self.assertEqual(typeItem['class'], 'H5T_ENUM')
     baseItem = typeItem['base']
     self.assertEqual(baseItem['class'], 'H5T_INTEGER')
     self.assertEqual(baseItem['base'], 'H5T_STD_I8LE')
     self.assertTrue('mapping' in typeItem)
     self.assertEqual(typeItem['mapping']['GREEN'], 1)
     self.assertEqual(typeSize, 1)
Ejemplo n.º 13
0
 def testBaseBoolTypeItem(self):
     typeItem = hdf5dtype.getTypeItem(np.dtype('bool'))
     typeSize = hdf5dtype.getItemSize(typeItem)
     self.assertEqual(typeItem['class'], 'H5T_ENUM')
     baseItem = typeItem['base']
     self.assertEqual(baseItem['class'], 'H5T_INTEGER')
     self.assertEqual(baseItem['base'], 'H5T_STD_I8LE')
     self.assertTrue('mapping' in typeItem)
     mapping = typeItem['mapping']
     self.assertEqual(len(mapping), 2)
     self.assertEqual(mapping['FALSE'], 0)
     self.assertEqual(mapping['TRUE'], 1)
     self.assertEqual(typeSize, 1)
Ejemplo n.º 14
0
    def testEnumArrayTypeItem(self):
        mapping = {'RED': 0, 'GREEN': 1, 'BLUE': 2}
        dt_enum = special_dtype(enum=(np.int8, mapping))
        typeItem = hdf5dtype.getTypeItem(dt_enum)
        dt_array = np.dtype('(2,3)' + dt_enum.str,
                            metadata=dict(dt_enum.metadata))

        typeItem = hdf5dtype.getTypeItem(dt_array)

        self.assertEqual(typeItem['class'], 'H5T_ARRAY')
        self.assertTrue("dims" in typeItem)
        self.assertEqual(typeItem["dims"], (2, 3))
        baseItem = typeItem['base']
        self.assertEqual(baseItem['class'], 'H5T_ENUM')
        self.assertTrue('mapping' in baseItem)
        self.assertEqual(baseItem['mapping']['GREEN'], 1)
        self.assertTrue("base" in baseItem)
        basePrim = baseItem["base"]
        self.assertEqual(basePrim["class"], 'H5T_INTEGER')
        self.assertEqual(basePrim['base'], 'H5T_STD_I8LE')
        typeSize = hdf5dtype.getItemSize(typeItem)
        self.assertEqual(typeSize,
                         6)  # one-byte for base enum type * shape of (2,3)
Ejemplo n.º 15
0
 def testCompoundArrayTypeItem(self):
     dt = np.dtype([('a', '<i1'), ('b', 'S1', (10, ))])
     typeItem = hdf5dtype.getTypeItem(dt)
     typeSize = hdf5dtype.getItemSize(typeItem)
     self.assertEqual(typeItem['class'], 'H5T_COMPOUND')
     fields = typeItem['fields']
     field_a = fields[0]
     self.assertEqual(field_a['name'], 'a')
     field_a_type = field_a['type']
     self.assertEqual(field_a_type['class'], 'H5T_INTEGER')
     self.assertEqual(field_a_type['base'], 'H5T_STD_I8LE')
     field_b = fields[1]
     self.assertEqual(field_b['name'], 'b')
     field_b_type = field_b['type']
     self.assertEqual(field_b_type['class'], 'H5T_ARRAY')
     self.assertEqual(field_b_type['dims'], (10, ))
     field_b_basetype = field_b_type['base']
     self.assertEqual(field_b_basetype['class'], 'H5T_STRING')
     self.assertEqual(typeSize, 11)
Ejemplo n.º 16
0
    def testCompoundofCompoundTypeItem(self):
        dt1 = np.dtype([("x", np.float32), ("y", np.float32)])
        dt2 = np.dtype([("a", np.float32), ("b", np.float32),
                        ("c", np.float32)])
        dt = np.dtype([("field1", dt1), ("field2", dt2)])
        typeItem = hdf5dtype.getTypeItem(dt)

        typeSize = hdf5dtype.getItemSize(typeItem)
        self.assertEqual(typeSize, 20)
        self.assertEqual(typeItem['class'], 'H5T_COMPOUND')
        self.assertTrue('fields' in typeItem)
        fields = typeItem['fields']
        self.assertEqual(len(fields), 2)
        field1 = fields[0]

        self.assertEqual(field1['name'], "field1")
        field1_type = field1['type']
        self.assertEqual(field1_type['class'], 'H5T_COMPOUND')
        field2 = fields[1]

        self.assertEqual(field2['name'], "field2")
        field2_type = field2['type']
        self.assertEqual(field2_type['class'], 'H5T_COMPOUND')
Ejemplo n.º 17
0
 def testRegionReferenceTypeItem(self):
     dt = special_dtype(ref=RegionReference)
     typeItem = hdf5dtype.getTypeItem(dt)
     typeSize = hdf5dtype.getItemSize(typeItem)
     self.assertEqual(typeItem['class'], 'H5T_REFERENCE')