コード例 #1
0
 def __init__(self,
              filename,
              group,
              shape,
              dtype,
              block='D',
              *args,
              name='',
              **kwargs):
     self.fn = filename
     self.id = group
     self.name = name
     if os.path.isfile(self.fn):  # import existing layer file
         self.file = h5py.File(self.fn, 'a')
         self.group = self.file['D']
         self.attrs = {'_type': 'Disc'}
         self.attrs.update(self.file.attrs)
     else:  # new layer file
         self.file = h5py.File(self.fn, 'a')
         self.group = self.file.create_group("D")
         self.attrs = {'_type': 'Disc'}
         lshape, dshape = deshape(shape)
         self.file.attrs['_shape'] = shape
         self.file.attrs['_lshape'] = lshape
         self.file.attrs['_dshape'] = dshape
         self.file.attrs['_offset'] = (0, 0)
         self.file.attrs['_dtype'] = str(dtype)
         self.file.attrs['_block'] = block
         self.attrs.update(self.file.attrs)
         self.group.create_group("P")  # Preview subgroup
         self.group.create_dataset("D", (np.prod(lshape), ) + dshape,
                                   dtype=dtype)  # create data layer
コード例 #2
0
ファイル: LayerData.py プロジェクト: mohseniaref/PyRAT
 def __init__(self, name, shape, dtype, *args, **kwargs):
     self.name = name
     self.attrs = {}
     self.attrs['_type'] = 'Memory'
     lshape, dshape = deshape(shape)
     self.attrs['_shape'] = shape
     self.attrs['_lshape'] = lshape
     self.attrs['_dshape'] = dshape
     self.attrs['_offset'] = (0, 0)
     self.attrs['_dtype'] = str(dtype)
     self.attrs['_block'] = kwargs['block']
     nchannels = np.prod(lshape)
     self.data = np.empty((nchannels,) + dshape, dtype=dtype)
コード例 #3
0
 def __init__(self, name, shape, dtype, *args, **kwargs):
     self.name = name
     self.attrs = {}
     self.attrs['_type'] = 'Memory'
     lshape, dshape = deshape(shape)
     self.attrs['_shape'] = shape
     self.attrs['_lshape'] = lshape
     self.attrs['_dshape'] = dshape
     self.attrs['_offset'] = (0, 0)
     self.attrs['_dtype'] = str(dtype)
     self.attrs['_block'] = kwargs['block']
     nchannels = np.prod(lshape)
     self.data = np.empty((nchannels, ) + dshape, dtype=dtype)
コード例 #4
0
ファイル: LayerData.py プロジェクト: mohseniaref/PyRAT
 def __init__(self, filename, group, shape, dtype, block='D', *args, **kwargs):
     self.fn = filename
     self.name = group
     self.group = h5py.File(self.fn, 'a')
     self.attrs = {}
     self.attrs['_type'] = 'Disc'
     lshape, dshape = deshape(shape)
     self.attrs['_shape'] = shape
     self.attrs['_lshape'] = lshape
     self.attrs['_dshape'] = dshape
     self.attrs['_offset'] = (0, 0)
     self.attrs['_dtype'] = str(dtype)
     self.attrs['_block'] = block
     self.group.create_group("P")  # Preview subgroup * not yet there
     self.group.create_dataset("D", (np.prod(lshape),) + dshape, dtype=dtype)  # create 2D Data layer
コード例 #5
0
    def addLayer(self, array=None, shape=None, dtype='float32', file=None, memory=False, block='D', **kwargs):
        """
        Adds a new layer to the existing PyRat Data object. One can
        add one or multiple existing ndarrays (as list), or specify the 
        shape / dtype of a (single) new layer to be later filled with data.
        
        :author: Andreas Reigber
        :returns: list of layer names as strings
        """
        if isinstance(array, np.ndarray) or array is None:
            array = [array]
        if isinstance(array, tuple):
            array = list(array)

        addedgroups = []
        if file is not None:   # this is for adding an existing DiscLayer file
            group = '/L' + str(self.laynam)
            self.layers[group] = DiscLayer(file, group, None, None, block=block)
            addedgroups.append(group)
            self.laynam += 1
        else:
            for arr in array:  # Loop over all arrays in list
                if arr is not None:
                    shape = np.squeeze(arr).shape
                    dtype = arr.dtype
                group = '/L' + str(self.laynam)
                if memory is False:
                    logging.debug('Creating disc layer ' + group + ' = ' + str(dtype) + ' ' + str(shape))
                    filename = tempfile.mktemp(suffix='.hd5', prefix='pyrat_', dir=self.tmpdir)
                    self.layers[group] = DiscLayer(filename, group, shape, dtype, block=block)
                else:
                    logging.debug('Creating memory layer ' + group + ' = ' + str(dtype) + ' ' + str(shape))
                    self.layers[group] = MemoryLayer(group, shape, dtype, block=block)
                if arr is not None:
                    lshape, dshape = deshape(shape)
                    nchannels = np.prod(lshape)
                    arr = arr.reshape((nchannels,) + dshape)
                    self.layers[group].setData(arr)  # write data
                addedgroups.append(group)
                self.laynam += 1

        if len(addedgroups) == 1:
            return addedgroups[0]
        else:
            return addedgroups
コード例 #6
0
ファイル: LayerData.py プロジェクト: birgander2/PyRAT
 def __init__(self, filename, group, shape, dtype, block='D', *args, name='', **kwargs):
     self.fn = filename
     self.id = group
     self.name = name
     if os.path.isfile(self.fn):                                            # import existing layer file
         self.file = h5py.File(self.fn, 'a')
         self.group = self.file['D']
         self.attrs = {'_type':  'Disc'}
         self.attrs.update(self.file.attrs)
     else:                                                                  # new layer file
         self.file = h5py.File(self.fn, 'a')
         self.group = self.file.create_group("D")
         self.attrs = {'_type':  'Disc'}
         lshape, dshape = deshape(shape)
         self.file.attrs['_shape'] = shape
         self.file.attrs['_lshape'] = lshape
         self.file.attrs['_dshape'] = dshape
         self.file.attrs['_offset'] = (0, 0)
         self.file.attrs['_dtype'] = str(dtype)
         self.file.attrs['_block'] = block
         self.attrs.update(self.file.attrs)
         self.group.create_group("P")                                              # Preview subgroup
         self.group.create_dataset("D", (np.prod(lshape),) + dshape, dtype=dtype)  # create data layer