Exemplo n.º 1
0
 def __init__(self, bind):
     """ Create a new Datatype object by binding to a low-level TypeID.
     """
     with phil:
         if not isinstance(bind, TypeID):
             # todo: distinguish type from other hl objects
             raise ValueError("%s is not a TypeID" % bind)
         HLObject.__init__(self, bind)
         
         self._dtype = h5json.createDataType(self.id.type_json)
Exemplo n.º 2
0
    def __init__(self, bind):
        """ Create a new Datatype object by binding to a low-level TypeID.
        """
        with phil:
            if not isinstance(bind, TypeID):
                # todo: distinguish type from other hl objects
                raise ValueError("%s is not a TypeID" % bind)
            HLObject.__init__(self, bind)

            self._dtype = h5json.createDataType(self.id.type_json)
Exemplo n.º 3
0
    def __getitem__(self, name):
        """ Read the value of an attribute.
        """
        #attr = h5a.open(self._id, self._e(name))
        req = self._req_prefix + name
        attr_json = self._parent.GET(req)
        shape_json = attr_json['shape']
        type_json = attr_json['type']
        #if attr.get_space().get_simple_extent_type() == h5s.NULL:
        if shape_json['class'] == 'H5S_NULL':
            raise IOError("Empty attributes cannot be read")
        value_json = attr_json['value']

        #dtype = readtime_dtype(attr.dtype, [])
        dtype = h5json.createDataType(type_json)
        
        #shape = attr.shape
        if 'dims' in shape_json:
            shape = shape_json['dims']
        else:
            shape = ()
        
        # Do this first, as we'll be fiddling with the dtype for top-level
        # array types
        #htype = h5t.py_create(dtype)
        htype = dtype

        # NumPy doesn't support top-level array types, so we have to "fake"
        # the correct type and shape for the array.  For example, consider
        # attr.shape == (5,) and attr.dtype == '(3,)f'. Then:
        if dtype.subdtype is not None:
            subdtype, subshape = dtype.subdtype
            shape = attr.shape + subshape   # (5, 3)
            dtype = subdtype                # 'f'
            
        #arr = numpy.ndarray(shape, dtype=dtype, order='C')
        #attr.read(arr, mtype=htype)
         
        #print "value:", rsp['value']
        #print "new_dtype:", new_dtype
        arr = numpy.array(value_json, dtype=htype)

        if len(arr.shape) == 0:
            return arr[()]
        return arr
Exemplo n.º 4
0
    def __init__(self, bind):
        """ Create a new Dataset object by binding to a low-level DatasetID.
        """
        from threading import local

        if not isinstance(bind, DatasetID):
            raise ValueError("%s is not a DatasetID" % bind)
        HLObject.__init__(self, bind)

        self._dcpl = self.id.dcpl_json
        self._filters = [] # filters.get_filters(self._dcpl)  # todo
        self._local = None #local()
        # make a numpy dtype out of the type json
        
        self._dtype = h5json.createDataType(self.id.type_json)
        
        if self.id.shape_json['class'] == 'H5S_SCALAR':
            self._shape = []
        else:
            self._shape = self.id.shape_json['dims']