Exemplo n.º 1
0
def test_varwise_decoding( srcPath, aOri ):

    gtSrc       = gtopen( srcPath, 'r', struct='simple' )
    gtVar       = gtSrc.vars['test']

    print '\t## variable-wise decoding (version: %s) ###'%gtSrc.__version__
    print '\t   source file:', srcPath
    print

    print '\t   variables in gt file:', gtSrc.vars
    print '\t   "test" variable     :', gtVar
    print '\t   header of "test" var:', gtVar.header

    aSrc       = gtVar[:]

    for a in aSrc:

        print '\t\titer aSrc:', a.shape, a.min(), a.max()

    print '='*80

    chkFlag     = all(aSrc.flatten() == aOri.flatten())

    print
    print '\t   identical to aOri?', chkFlag, aSrc.shape
    print '='*80

    return chkFlag
Exemplo n.º 2
0
def test_modification( srcPath ):
    gtSrc       = gtopen( srcPath, 'r+' )#, struct='simple' )
    gtVar       = gtSrc.vars['']

    print '\t## modification (version: %s) ###'%gtSrc.__version__
    print '\t   source file:', srcPath
    print

    print '\t origial header'
    print gtVar.header

    varName     = 'test'
    gtVar.header['ITEM']    = varName
    print '\t   set "ITEM" as "test"'

    sDTime      = datetime.datetime(2000,1,1)
    delT        = datetime.timedelta(days=1)
    DTime       = [sDTime+delT*i for i in range( gtVar.shape[0] ) ]
    TStamp      = [dtime.strftime('%Y%m%d %H%M%S ') for dtime in DTime ]
    gtVar.header['DATE']    = TStamp
    print '\t   set "DATE" as %s - %s'%(TStamp[0], TStamp[-1])

    print gtVar.header
    print '='*80

    chkFlag     = ( gtVar.header['DATE'] == tuple(TStamp) )     \
                 &( varName == gtVar.header['ITEM'].strip() )

    return chkFlag
Exemplo n.º 3
0
def test_chunkwise_encoding( aSrc, outPath ):
    gtOut       = gtopen( outPath, mode='w+' )

    print '\t## encoding (version: %s) ###'%gtOut.__version__
    print '\t   source array:', aSrc.shape, aSrc.dtype, 'Min:%s'%aSrc.min(), 'Max:%s'%aSrc.max()
    print

    for a in aSrc:

        print '\t\tappend:', a.shape, a.min(), a.max()
        gtOut.append( a )

    print
    print '\t   out path: %s'%outPath, gtOut.vars
    print '='*80

    return True
Exemplo n.º 4
0
def test_chunkwise_decoding( srcPath, aSrc ):
    gtSrc       = gtopen( srcPath, 'r' )
    print '\t## decoding (version: %s) ###'%gtSrc.__version__
    print '\t   source file:', srcPath
    print

    Data    = []
    for chunk in gtSrc:

        data    = chunk.data
        print '\t\tget a chunk:', data.shape, data.min(), data.max(), data.dtype

        Data.append( data )

    Data    = array( Data )
    chkFlag     = all(Data.flatten() == aSrc.flatten())

    print
    print '\t   identical to aSrc?', chkFlag, Data.shape
    print '='*80

    return chkFlag