Exemplo n.º 1
0
 def setUp(self):
     BaseSlicing.setUp(self)
     sid = h5s.create(h5s.NULL)
     tid = h5t.C_S1.copy()
     tid.set_size(10)
     dsid = h5d.create(self.f.id, b'x', tid, sid)
     self.dataset = self.f['x']
Exemplo n.º 2
0
 def setUp(self):
     BaseAttrs.setUp(self)
     sid = h5s.create(h5s.NULL)
     tid = h5t.C_S1.copy()
     tid.set_size(10)
     aid = h5a.create(self.f.id, b'x', tid, sid)
     self.empty_obj = h5py.Empty(np.dtype("S10"))
Exemplo n.º 3
0
 def setUp(self):
     BaseSlicing.setUp(self)
     sid = h5s.create(h5s.NULL)
     tid = h5t.C_S1.copy()
     tid.set_size(10)
     dsid = h5d.create(self.f.id, b'x', tid, sid)
     self.dataset = self.f['x']
Exemplo n.º 4
0
 def setUp(self):
     BaseAttrs.setUp(self)
     sid = h5s.create(h5s.NULL)
     tid = h5t.C_S1.copy()
     tid.set_size(10)
     aid = h5a.create(self.f.id, b'x', tid, sid)
     self.empty_obj = h5py.Empty(np.dtype("S10"))
Exemplo n.º 5
0
    def __init__(self, fspace, args):
        if args == ():
            self.mshape = None
        elif args == (Ellipsis, ):
            self.mshape = ()
        else:
            raise ValueError("Illegal slicing argument for scalar dataspace")

        self.mspace = h5s.create(h5s.SCALAR)
        self.fspace = fspace
Exemplo n.º 6
0
    def __init__(self, fspace, args):
        if args == ():
            self.mshape = None
        elif args == (Ellipsis,):
            self.mshape = ()
        else:
            raise ValueError("Illegal slicing argument for scalar dataspace")

        self.mspace = h5s.create(h5s.SCALAR)
        self.fspace = fspace
Exemplo n.º 7
0
 def setUp(self):
     BaseAttrs.setUp(self)
     sid = h5s.create(h5s.NULL)
     tid = h5t.C_S1.copy()
     tid.set_size(10)
     aid = h5a.create(self.f.id, b'x', tid, sid)
Exemplo n.º 8
0
 def setUp(self):
     BaseAttrs.setUp(self)
     sid = h5s.create(h5s.NULL)
     tid = h5t.C_S1.copy()
     tid.set_size(10)
     aid = h5a.create(self.f.id, b'x', tid, sid)
Exemplo n.º 9
0
def create_attribute(_id, _name, _dims, _value):
  """
  Writes a HDF5 string attribute, ASCII, NULLTERM
 
  _id should be something like dset.id
 
  _dims should be a list.  For a scalar, use an empty list []
 
  """
 
# Make sure we don't have a unicode name
  _name=str_to_h5(_name)

# This routine for string attributes
  _dtype = h5t.FORTRAN_S1
# Create a scalar space (if dims len=0); otherwise a simple space
  if len(_dims) == 0:
    _sid=h5s.create(h5s.SCALAR)
  elif len(_dims) == 1 and _dims[0] == 0 :
    _sid=h5s.create(h5s.SCALAR)
  else:
    _sid=h5s.create_simple(tuple(_dims))
# endif
 
# Create the memory & file datatypes. Adjust if datatype is string.
  _mdtype = _dtype.copy()
  _fdtype = _dtype.copy()
  _classtype = _dtype.get_class()
  if _classtype == h5t.STRING:
    if isinstance(_value, list):
      _strlen=0
      for _part in _value: _strlen=max(_strlen, len(_part))
    else:
      _strlen = len(_value)
#   endif
    if _strlen < 1: return None
    _mdtype.set_size(_strlen)
    _mdtype.set_strpad(h5t.STR_SPACEPAD)
    _fdtype.set_size(_strlen+1)
    _fdtype.set_strpad(h5t.STR_NULLTERM)
# endif
 
## Either add or replace the attribute
#  if h5a.exists(_id, _name):
#    _aid = h5a.open(_id, name=_name)
#  else:
#    _aid=h5a.create(_id, _name, _fdtype, _sid)
# endif
# Either add or replace the attribute
  if h5a.exists(_id, _name):
    _aid = h5a.delete(_id, name=_name)
# endif
  _aid=h5a.create(_id, _name, _fdtype, _sid)

  if _classtype == h5t.STRING:
    if isinstance(_value, list):
      _value = np.array(_value, dtype=np.string_)
    else:
      _value = np.array(str_to_h5(_value))
#   endif
  else:
    _pytype = _fdtype.dtype
    _value = np.array(_value, dtype=_pytype)
# endif
  _aid.write(_value)
  return _aid