Ejemplo n.º 1
0
    def append(self, Data, headers=None, **kwargs):
        '''
        Data    : nd-array in rank-3 (Z, Y, X)
        headers : <type>    in [ __gtHdr__, iterable, ]??,
        '''

        if headers == None:
            native_code = sys.byteorder == 'little' and '<' or '>'
            byteorder   = Data.dtype.byteorder
            byteorder   = byteorder if byteorder != '=' else native_code


            if byteorder == '<':
                Data        = Data.byteswap()
                byteorder   = '>'

            dtypedescr  = byteorder + Data.dtype.kind + str(Data.dtype.itemsize)
            Data.dtype  = dtypedescr

            dfmt        = self.dictDFMT[ Data.dtype ]

            aend3, aend2, aend1  = Data.shape

            kwargs[ 'AEND1' ]   = aend1,
            kwargs[ 'AEND2' ]   = aend2,
            kwargs[ 'AEND3' ]   = aend3,
            kwargs[ 'DFMT'  ]   = dfmt,
            kwargs[ 'SIZE'  ]   = aend1*aend2*aend3,


        if kwargs != {}:
            headers             = self.auto_fill( headers=headers, **kwargs )


        for data, header in map(None, Data, headers):

            chunk       = __gtChunk__( data, header=header )
            self.__chunks__.append( chunk )

            varName     = header[2].strip()

            if not varName in self.__vars__:
                self.__vars__[varName] = []

            self.__vars__[varName].append( chunk )

            # write to memmap --------------------------------------------------
            pos         = self.__rawArray__.size
            __memmap__          = memmap( self.gtPath, 'S1', 'r+',
                                          shape=(self.__rawArray__.size+chunk.size)
                                        )
            __memmap__[pos:]    = chunk.__rawArray__
            self.__rawArray__   = __memmap__
#            self.__rawArray__[pos:]     = chunk.__rawArray__

            '''
Ejemplo n.º 2
0
    def next(self):

        if self.curr == self.size:
            self.curr   = 0
            raise StopIteration

        chunkSize   = self.get_chunksize( self.curr )

        chunk       = __gtChunk__( self.__rawArray__, self.curr, chunkSize )

        self.curr += chunkSize

        return chunk
Ejemplo n.º 3
0
    def __init__(self, gtPath, mode='r', struct='native'):
        '''
        struct  : ['simple', 'native']
                   'simple' : uniform file structure (singel var)
                   'native' : contains multiple vars & dims
        '''

        if mode in ['r','c','r+']:
            self.__rawArray__   = memmap(gtPath, 'S1', mode)

        elif mode == 'w+':
            gtFile  = open(gtPath, 'w')
            gtFile.close()

            self.__rawArray__   = array([], 'S1')
            self.gtPath         = gtPath

        else:
            raise ValueError, '%s is not supported option'%mode


        self.curr       = 0
        self.hdrBytes   = __gtConfig__.hdrsize
        self.size       = self.__rawArray__.size

        self.__chunks__ = []
        self.__vars__   = OrderedDict()

        self.__pos__    = OrderedDict()

        self.struct     = struct

        if struct == 'simple':
            # cache varName for simple structure

            self.set_uniform_pos()

            size            = self.__pos__[0]
            self.varName    = __gtChunk__( self.__rawArray__, 0, size ).header['ITEM'].strip()


        self.iomode     = mode
        self.__version__= __gtConfig__.version