コード例 #1
0
	def read_geo_file(s, geo_filename):	
		from scipy.io.numpyio import fread

		print 'Reading the line-array from the %s.line.geo...' % geo_filename
		fd	=	open(geo_filename + '.line.geo', 'rb')
		data_line_array	=	fread(fd, 3*(s.Nx+1)*(s.Ny+1)*(s.Nz+1), 'f')	
		data_line_array	=	data_line_array.reshape(3, s.Nx+1, s.Ny+1, s.Nz+1)
		s.line_x	=	data_line_array[0]
		s.line_y	=	data_line_array[1]
		s.line_z	=	data_line_array[2]
		fd.close()

		print 'Reading the area-array from the %s.area.geo...' % geo_filename
		fd	=	open(geo_filename + '.area.geo', 'rb')
		data_area_array	=	fread(fd, 3*(s.Nx+2)*(s.Ny+2)*(s.Nz+2), 'f')	
		data_area_array	=	data_area_array.reshape(3, s.Nx+2, s.Ny+2, s.Nz+2)
		s.area_x	=	data_area_array[0]
		s.area_y	=	data_area_array[1]
		s.area_z	=	data_area_array[2]
		fd.close()

		s.arr	=	{'x':(s.line_x,s.area_x), 'y':(s.line_y,s.area_y), 'z':(s.line_z,s.area_z)}
		s.geo_dirname	=	'%s.gview' % geo_filename

		import os
		try:
			os.mkdir(s.geo_dirname)
		except:
			print 'Remove the exist dir \'%s\'' %s.geo_dirname
			cmd	=	'rm -rf %s' %s.geo_dirname
			os.system(cmd)
			os.mkdir(s.geo_dirname)
		print 'Create the png dir \'%s\'' %s.geo_dirname	
コード例 #2
0
ファイル: MNIST_data.py プロジェクト: ageek/kaggle
    def __init__(self,dir):
        """Constructor

        @param dir -- path of MNIST dataset

        """
        fd = open(dir+'/train-labels.idx1-ubyte')
        fread(fd,8,'c')
        self.data_labels = np.fromfile(file=fd, dtype=np.uint8).reshape((60000,1))
        fd.close()

        fd = open(dir+'/train-images.idx3-ubyte')
        fread(fd,16,'c')
        self.data = np.fromfile(file=fd, dtype=np.uint8).reshape((60000,784))
        fd.close()

        fd = open(dir+'/t10k-images.idx3-ubyte')
        fread(fd,16,'c')
        self.test = np.fromfile(file=fd, dtype=np.uint8).reshape((10000,784))
        fd.close()

        fd = open(dir+'/t10k-labels.idx1-ubyte')
        fread(fd,8,'c')
        self.test_labels = np.fromfile(file=fd, dtype=np.uint8).reshape((10000,1))
        fd.close()
コード例 #3
0
    def __init__(self, dir):
        """Constructor

        @param dir -- path of MNIST dataset

        """
        fd = open(dir + '/train-labels.idx1-ubyte')
        fread(fd, 8, 'c')
        self.data_labels = np.fromfile(file=fd, dtype=np.uint8).reshape(
            (60000, 1))
        fd.close()

        fd = open(dir + '/train-images.idx3-ubyte')
        fread(fd, 16, 'c')
        self.data = np.fromfile(file=fd, dtype=np.uint8).reshape((60000, 784))
        fd.close()

        fd = open(dir + '/t10k-images.idx3-ubyte')
        fread(fd, 16, 'c')
        self.test = np.fromfile(file=fd, dtype=np.uint8).reshape((10000, 784))
        fd.close()

        fd = open(dir + '/t10k-labels.idx1-ubyte')
        fread(fd, 8, 'c')
        self.test_labels = np.fromfile(file=fd, dtype=np.uint8).reshape(
            (10000, 1))
        fd.close()
コード例 #4
0
def read_scbin_2d(scbin_path, Nx, Ny):
	fd = open(scbin_path, 'rb')
	array = fread(fd, Nx*Ny, 'f')
	array = array.reshape(Nx, Ny)
	fd.close()

	return array
コード例 #5
0
    def read_geo_file(s, geo_filename):
        from scipy.io.numpyio import fread

        print 'Reading the line-array from the %s.line.geo...' % geo_filename
        fd = open(geo_filename + '.line.geo', 'rb')
        data_line_array = fread(fd, 3 * (s.Nx + 1) * (s.Ny + 1) * (s.Nz + 1),
                                'f')
        data_line_array = data_line_array.reshape(3, s.Nx + 1, s.Ny + 1,
                                                  s.Nz + 1)
        s.line_x = data_line_array[0]
        s.line_y = data_line_array[1]
        s.line_z = data_line_array[2]
        fd.close()

        print 'Reading the area-array from the %s.area.geo...' % geo_filename
        fd = open(geo_filename + '.area.geo', 'rb')
        data_area_array = fread(fd, 3 * (s.Nx + 2) * (s.Ny + 2) * (s.Nz + 2),
                                'f')
        data_area_array = data_area_array.reshape(3, s.Nx + 2, s.Ny + 2,
                                                  s.Nz + 2)
        s.area_x = data_area_array[0]
        s.area_y = data_area_array[1]
        s.area_z = data_area_array[2]
        fd.close()

        s.arr = {
            'x': (s.line_x, s.area_x),
            'y': (s.line_y, s.area_y),
            'z': (s.line_z, s.area_z)
        }
        s.geo_dirname = '%s.gview' % geo_filename

        import os
        try:
            os.mkdir(s.geo_dirname)
        except:
            print 'Remove the exist dir \'%s\'' % s.geo_dirname
            cmd = 'rm -rf %s' % s.geo_dirname
            os.system(cmd)
            os.mkdir(s.geo_dirname)
        print 'Create the png dir \'%s\'' % s.geo_dirname
コード例 #6
0
def bin2lut(descfname, **kwargs):
    """Load a raw binary file as lut directly. 
    Parameters:
        descfname: a description txt file in the format below:
            # Comment lines starts with #
            binary_file : /path/to/binary_file
            dtype : datatype of the lut, a character in 'cb1silfdFD'
            dimname1 : 1 2 3 4 5
            dimname2 : 10.0, 20.0, 30.0, 40.0
            ...
            # dims can either be seperated with ',' or ' '
        kwargs: 
            mem_type:
                a character in 'cb1silfdFD'
            byteswap:
                0 : no swap
                1 : swap
"""
    from scipy.io.numpyio import fread
    descf_folder_path = os.path.dirname(descfname)
    descf_basename = os.path.basename(descfname)
    descf = open(descfname)
    dims = []
    shp = []
    binary_file = '%s.bin' % descf_basename
    dtype = 'f'
    for l in descf:
        l = l.strip()
        if len(l) == 0 or l.startswith('#'):
            continue
        name, value = l.split(':', 1)
        name = name.strip()
        value = value.strip()
        if name == 'binary_file':
            binary_file = value
        elif name == 'dtype':
            dtype = value
        else:
            if ',' in value:
                sep = ','
            else:
                sep = ' '
            arrayvalue = np.fromstring(value, sep=sep, dtype='f4')
            dims.append((name, arrayvalue))
            shp.append(arrayvalue.shape[0])
    total_elements_num = np.multiply.reduce(shp)
    shp = tuple(shp)
    binary_file_abspath = os.path.join(descf_folder_path, binary_file)
    f = open(binary_file_abspath, 'rb')
    lut_arr = fread(f, total_elements_num, dtype).reshape(shp)
    f.close()
    lut = lookup_table(lut_arr, dims)
    return lut
コード例 #7
0
def read_structure_files():
    print 'Reading the structure files...' 
    structures = []
    s_number = 0

    flist = glob.glob('./structures/*')
    for file in flist:
        if '_info' in file:
            print file
            structures.append( __import__(file) )
            structure = structures[-1]
            Nx, Ny, Nz = structure.discrete_effective_region_sides

            filename = './structures/%.3d_%s_ispts_x.scbin' \
                    % (s_number, structure.__name__)
            print filename
            array_file = open(filename, 'rb')
            ISPTs_array_x = fread(filename, 2*Ny*Nz, 'f').reshape(2,Ny,Nz)
            array_file.close()
            filename = './structures/%.3d_%s_ispts_y.scbin' \
                    % (s_number, structure.__name__)
            print filename
            array_file = open(filename, 'rb')
            ISPTs_array_y = fread(filename, 2*Nx*Nz, 'f').reshape(2,Nx,Nz)
            array_file.close()
            filename = './structures/%.3d_%s_ispts_z.scbin' \
                    % (s_number, structure.__name__)
            print filename
            array_file = open(filename, 'rb')
            ISPTs_array_z = fread(filename, 2*Nx*Ny, 'f').reshape(2,Nx,Ny)
            array_file.close()

            structure.intersection_points_arrays = [ \
                    ISPTs_array_x, ISPTs_array_y, ISPTs_array_z]
            s_number += 1

    return structures
コード例 #8
0
 def test_basic(self):
     # Generate some data
     a = 255*rand(20)
     # Open a file
     fname = tempfile.mktemp('.dat')
     fid = open(fname,"wb")
     # Write the data as shorts
     numpyio.fwrite(fid,20,a,N.Int16)
     fid.close()
     # Reopen the file and read in data
     fid = open(fname,"rb")
     if verbose >= 3:
         print "\nDon't worry about a warning regarding the number of bytes read."
     b = numpyio.fread(fid,1000000,N.Int16,N.Int)
     fid.close()
     assert(N.product(a.astype(N.Int16) == b,axis=0))
     os.remove(fname)
コード例 #9
0
 def test_basic(self):
     # Generate some data
     a = 255 * rand(20)
     # Open a file
     fname = tempfile.mktemp('.dat')
     fid = open(fname, "wb")
     # Write the data as shorts
     numpyio.fwrite(fid, 20, a, N.Int16)
     fid.close()
     # Reopen the file and read in data
     fid = open(fname, "rb")
     if verbose >= 3:
         print "\nDon't worry about a warning regarding the number of bytes read."
     b = numpyio.fread(fid, 1000000, N.Int16, N.Int)
     fid.close()
     assert (N.product(a.astype(N.Int16) == b, axis=0))
     os.remove(fname)
コード例 #10
0
ファイル: binary_read.py プロジェクト: cardiosolv/pyCarpUtil
def petsc_binary_read(filename, spymatrix):
    
    fd = open(filename,'rb');
    datatype = 'i'
    header = fread(fd, 2, datatype, datatype, 1)

    if np.size(header) <= 0:
        print 'File does not have that many items'
        sys.exit(1)

    if header[0] == 1211216:  # read matrix
        m      = header[1]
        header = fread(fd, 2, datatype, datatype, 1)
        n      = header[0]
        nz     = header[1]
        nnz    = fread(fd, m, datatype, datatype, 1)

        j   = fread(fd, nz, 'i', 'i', 1) + 1 # columns
        s   = fread(fd, nz, 'd', 'd', 1)     # data
        i   = np.ones((nz))                  # pointers

        cnt = 0
        for k in xrange(m):
            next          = cnt + nnz[k] - 1
            i[cnt:next+1] = k * np.ones((nnz[k]))
            cnt           = next + 1

        # adjust to python-zero based indexing
        j = j - 1

        A = sparse.coo_matrix( (s,(i,j)), (m,n) )

        if spymatrix == 1:
            plt.spy(A,marker='.')
            plt.show()

        fd.close()
        return A

    elif header[0] == 1211214: # read vector
        m = header[1]
        datatype = 'd'
        v = fread(fd, m, datatype, datatype, 1)
        
        fd.close()
        return v
コード例 #11
0
ファイル: mIO.py プロジェクト: lbaehren/lofarsoft
 def fort_read(self,fmt,dtype=None):
     lookup_dict = {'ieee-le':"<",'ieee-be':">",'native':''}
     if dtype is None:
         fmt = lookup_dict[self.format] + fmt
         numbytes = struct.calcsize(fmt)
         nn = struct.calcsize("i");
         self.fid.read(nn)
         data = struct.unpack(fmt,self.fid.read(numbytes))
         self.fid.read(nn)
         return data
     else:  # Ignore format string and read in next record as an array.
         fmt = lookup_dict[self.format] + "i"
         nn = struct.calcsize(fmt)
         nbytes = struct.unpack(fmt,self.fid.read(nn))[0]
         howmany, dtype = getsize_type(dtype)
         ncount = nbytes / howmany
         if ncount*howmany != nbytes:
             self.rewind(4)
             raise ValueError, "A mismatch between the type requested and the data stored."
         retval = numpyio.fread(self.fid, ncount, dtype, dtype, self.bs)
         if len(retval) == 1:
             retval = retval[0]
         self.fid.read(nn)
         return retval
コード例 #12
0
ファイル: read_HDS.py プロジェクト: fastest10/netica_assat
def read_head_MODFLOW(infile,nlay,nrow,ncol,ss,nan_flag):
	ifp = open(infile,'rb')
	# holders for the data reading in
	kstp    = []
	kper    = []
	pertim  = []
	totim   = []
	heads   = []
	newTime = True
	i=-1
	while 1:
		kstp_tmp = fread(ifp,1,'i')
		if not kstp_tmp:
			break
		else:
			kstp.append(kstp_tmp[0])
			if newTime == True:
				heads.append(hds(nlay,nrow,ncol,kstp[-1]))
				newTime = False
				i +=1
			kper.append(fread(ifp,1,'i')[0])
			pertim.append(fread(ifp,1,'f')[0])
			totim.append(fread(ifp,1,'f')[0])
			junkus = fread(ifp,16,'c')
			pos = fread(ifp,3,'i')
			headin = fread(ifp,pos[0]*pos[1],'f').reshape(nrow,ncol)
			if nan_flag:
				headin[headin==999] = np.nan
			heads[i].heads[:,:,pos[2]-1]=headin
			if pos[2]==nlay:
				newTime = True
				# here we break out after only one pass if seeking only one
				# stress period (ss means steady-state).  probably not really necessary....
				if ss == True:
					break
	return kstp,kper,heads, pertim
コード例 #13
0
import matplotlib.colors
import sys
from scipy.io.numpyio import fwrite, fread

filename=sys.argv[1]
#slide_number=int(sys.argv[2])
#print dir,slide_number

#rcParams['font.colors']='w'


fd=open(filename, 'rb')
datatype = 'i'
size = 2
shape=(2)
size=fread(fd, size, datatype)
nx=size[0]
ny=size[1]
data = zeros((nx,ny,3))

datatype='d'
size=nx*ny*3
shape=(3,ny,nx)
data=fread(fd, size, datatype)
data=data.reshape(shape)
    
print "Dimensions",nx,ny

nx1=0
nx2=800
ny1=0
コード例 #14
0
ファイル: pad_mnist.py プロジェクト: stjordanis/CUV
import numpy as np
from scipy.io.numpyio import fwrite, fread
import ipdb as pdb
import os
import sys

sys.excepthook = __IPYTHON__.excepthook

path = "/home/local/datasets/MNIST"

with open(os.path.join(path, 't10k-images.idx3-ubyte')) as fd:
    #with open(os.path.join(path,'train-images.idx3-ubyte')) as fd:
    fread(fd, 16, 'c')
    #data = np.fromfile(file=fd, dtype=np.uint8).reshape( (60000,784) )
    data = np.fromfile(file=fd, dtype=np.uint8).reshape((10000, 784))

padded_data = []
for image in data:
    padded_image = np.zeros((32, 32))
    padded_image[2:30, 2:30] = image.reshape(28, 28)
    padded_data.append(padded_image.flatten())

#np.save(os.path.join(path,'mnist_padded'),np.array(padded_data).T.astype(np.uint8))
np.save(os.path.join(path, 'mnist_padded_test'),
        np.array(padded_data).T.astype(np.uint8))
コード例 #15
0
def read_scbin_1d(scbin_path, Nx):
	fd = open(scbin_path, 'rb')
	array = fread(fd, Nx, 'f')
	fd.close()

	return array
コード例 #16
0
ファイル: fft-python.py プロジェクト: JasVixBan/kamasu
# generate signal
#
sr = 48000.0
winlen = 2048
nfreqs = winlen//2+1
winstep = 64

nsamples = os.stat(sys.argv[1])[ST_SIZE] / 4
print nsamples, " samples"

if len(sys.argv) == 4:
    nsamples = int(sys.argv[3])

fd = open(sys.argv[1], 'rb')

signal = fread(fd, nsamples, 'f')
print "signals is", type(signal), signal.shape

starts = range(0, (len(signal)-winlen), winstep)

results = n.zeros((len(starts), nfreqs))

# x_labels = n.array(starts)/sr
# y_labels = n.array([(sr*x)/winlen for x in range(winlen/2)])
# print x_labels
# print y_labels

index = 0
for start_off in starts:
    if start_off % 1000 == 0:
        # print "****", start_off, "****"
コード例 #17
0
ファイル: check.py プロジェクト: domaubert/Cudaton
def main():

    NBND=16;
    NBND2=2*NBND
    
    dirout=sys.argv[1]
    NCELL=int(sys.argv[2])

    NGPUX=int(sys.argv[3])
    NGPUY=int(sys.argv[4])
    NGPUZ=int(sys.argv[5])

    ISNAP=int(sys.argv[6])

    NGPUTOT=NGPUX*NGPUY*NGPUZ

    NX=NCELL/NGPUX
    NY=NCELL/NGPUY
    NZ=NCELL/NGPUZ


    x=np.zeros([NCELL,NCELL,NCELL])
    t=np.zeros([NCELL,NCELL,NCELL])

    for k in range(NGPUZ):
        for j in range(NGPUY):
            for i in range(NGPUX):
                idx=i+j*NGPUX+k*NGPUX*NGPUY

                fname=dirout+'/snap.%05d.p%05d'%(ISNAP,idx)
                print 'reading '+fname

                fbuf=open(fname,mode="rb")
                nc=fread(fbuf,1,'i')
                tt=fread(fbuf,1,'f')
                xtemp=fread(fbuf,(NX+NBND2)*(NY+NBND2)*(NZ+NBND2),'f')
                ttemp=fread(fbuf,(NX+NBND2)*(NY+NBND2)*(NZ+NBND2),'f')
                fbuf.close()

                xtemp=xtemp.reshape((NZ+NBND2,NY+NBND2,NX+NBND2))
                ttemp=ttemp.reshape((NZ+NBND2,NY+NBND2,NX+NBND2))

                
                x[k*NZ:(k+1)*NZ,j*NY:(j+1)*NY,i*NX:(i+1)*NX]=xtemp[NBND:NBND+NZ,NBND:NBND+NY,NBND:NBND+NX]
                t[k*NZ:(k+1)*NZ,j*NY:(j+1)*NY,i*NX:(i+1)*NX]=ttemp[NBND:NBND+NZ,NBND:NBND+NY,NBND:NBND+NX]


    xx=np.linspace(-6.6,6.6,NCELL)
    plt.title('time='+str(tt))
    plt.subplot(221)
    plt.imshow(1.-x[NCELL/2,:,:])
    plt.subplot(222)
    plt.plot(xx,1.-x[NCELL/2,NCELL/2,:])
    plt.xlim(-6.6,6.6)
    plt.yscale('log')

    plt.subplot(223)
    plt.imshow(t[NCELL/2,:,:])
    plt.subplot(224)
    plt.plot(xx,t[NCELL/2,NCELL/2,:])
    plt.yscale('log')
    plt.xlim(-6.6,6.6)
    plt.ylim(5000.,3e4)
    plt.show()
コード例 #18
0
# know the datatype of your array, its size and its shape.
# 
# <codecell>


>>> from scipy.io.numpyio import fwrite, fread
>>> data = zeros((3,3))
>>>#write:  fd = open('myfile.dat', 'wb')
>>> fwrite(fd, data.size, data)
>>> fd.close()
>>>#read:
>>> fd = open('myfile.dat', 'rb')
>>> datatype = 'i'
>>> size = 9
>>> shape = (3,3)
>>> read_data = fread(fd, size, datatype)
>>> read_data = data.reshape(shape)

# <markdowncell>

# Or, you can simply use and . Following the previous example:
# 
# <codecell>


>>> data.tofile('myfile.dat')
>>> fd = open('myfile.dat', 'rb')
>>> read_data = numpy.fromfile(file=fd, dtype=numpy.uint8).reshape(shape)

# <markdowncell>
コード例 #19
0
ファイル: plot_slice.py プロジェクト: sleitner/cart
#!/usr/bin/python -Wignore

from scipy.io.numpyio import fread, fwrite
from pylab import *
import sys

# load data
for slice in ( sys.argv[1:] ) :
	print slice

	input = open( slice, "r" )

	(nx,nz) = fread( input, 2, 'i' )
	density = fread( input, nx*nz, 'f' ).reshape(nz,nx)
	input.close()

	figure( figsize=(float(nz)/72,float(nx)/72), dpi=72 )
	a = axes([0,0,1,1])
	a.axis('off')
	a.imshow(density,cmap=cm.jet,origin="lower",interpolation="Nearest")
	a.set_autoscale_on(False)
	savefig(slice.replace("dat","png"),dpi=72)
	clf()
コード例 #20
0
ファイル: plotter_npz.py プロジェクト: vasyafon/PythonImaging
from pylab import *
from numpy import ma
import matplotlib.pyplot as plt
import numpy as np
import array
import scipy
#d:\Temp\POY\2\SP\node_0 
rootdir ="f:/data/Bank/Constant Speed 001/RESULTS_MPI4-50ms/IM"
outdir = rootdir 
maindir = rootdir + "/IMAGE.npz" 
N = 1 #number of nodes
from scipy.io.numpyio import fwrite, fread
#/////////////////////////
Xsize = 13201
Zsize = 1921
vmodel = fread (open('f:/data/BP2004/modelq.bin','rb'),Xsize*Zsize,'f').reshape ((13201,1921)).transpose()
partmod = vmodel[::1,0:2600:1]
partmod = partmod - scipy.ndimage.filters.gaussian_filter(partmod,2)
partmod = np.abs (np.clip (partmod*0.001,-1.,1.))
modrgba = np.zeros ((partmod.shape[0],partmod.shape[1],4),dtype = 'f')
modrgba[:,:,0] = partmod
modrgba[:,:,3] = 1.



Image = np.load("%s"%maindir, mmap_mode='r')['arr_0.npy']
#SNorm = np.load("%s/s_norm.npz"%rootdir, mmap_mode='r')['arr_0.npy']
#sigma =3
#blurred = scipy.ndimage.filters.gaussian_filter(Image,sigma)
#
#filtered = Image - blurred
コード例 #21
0
ファイル: pad_mnist.py プロジェクト: 0rchard/CUV
import numpy as np
from scipy.io.numpyio import fwrite, fread
import ipdb as pdb
import os
import sys

sys.excepthook = __IPYTHON__.excepthook

path="/home/local/datasets/MNIST"

with open(os.path.join(path,'t10k-images.idx3-ubyte')) as fd:
#with open(os.path.join(path,'train-images.idx3-ubyte')) as fd:
    fread(fd,16,'c')
    #data = np.fromfile(file=fd, dtype=np.uint8).reshape( (60000,784) )
    data = np.fromfile(file=fd, dtype=np.uint8).reshape( (10000,784) )

padded_data=[]
for image in data:
    padded_image=np.zeros((32,32))
    padded_image[2:30,2:30]=image.reshape(28,28)
    padded_data.append(padded_image.flatten())

#np.save(os.path.join(path,'mnist_padded'),np.array(padded_data).T.astype(np.uint8))
np.save(os.path.join(path,'mnist_padded_test'),np.array(padded_data).T.astype(np.uint8))
コード例 #22
0
ファイル: igb_read.py プロジェクト: cardiosolv/pyCarpUtil
def read_igb_slice (filename, is_gzipped=False):
    """
    Reads IGB slice. If gzipped it uncompress and output a binary file
    that is used to read the data
    """
    if is_gzipped:
        igbFile = gunzipFile(filename)
    else:
        igbFile = filename

    hd = read_igb_header(igbFile, is_gzipped=False)

    filestats = os.stat(igbFile)
    filesize  = filestats[stat.ST_SIZE]

    if   hd.systeme == 'big_endian'   : byteswap=1
    elif hd.systeme == 'little_endian': byteswap=0

    # setup time slices to be read
    t_slices = xrange(1,hd.t+1)
    if size(t_slices) == 0:
        t_slices = 1
        print " WARNING: Trying to read at least one time slice!"

    # how many time slices we are going to read ?
    n_slices = len(t_slices)

    # expected data size
    data_in_file = hd.x * hd.y * hd.z * hd.t

    ## FORCE MY CASE in case of MEMORY ERROR ##
    #n_slices = 1001

    # data type
    if hd.type == 'float':  
        dbytes = 4
        dtype  = 'f'
        data   = zeros( (n_slices, hd.x, hd.y, hd.z), dtype=float32 )
    elif hd.type == 'double':
        dbytes = 8
        dtype = 'd'
        data  = zeros( (n_slices, hd.x, hd.y, hd.z), dtype=float64 )        

    # open data
    fh = open(igbFile,'rb')
   
    # size of one time slice
    slice_size = hd.x * hd.y * hd.z

    # read data till end of file
    actual_timesteps = 0
    for i in xrange(n_slices):
        # compute position of time slice i
        pos = (t_slices[i] - 1) * slice_size * dbytes + 1024        
        fh.seek(pos)

        slice_buf = fread(fh, slice_size, dtype, dtype, byteswap)

        count = size(slice_buf)

        if count == slice_size:
            data[i,:,:,:] = slice_buf.reshape(hd.x, hd.y, hd.z)
            actual_timesteps = actual_timesteps + 1
        #else:
        #    print " read_igb_slices: Incomplete time step %d of %d " % (i,n_slices)

    hd.t = actual_timesteps
    fh.close() 

    # if gzipped, remove temporary uncompressed file
    if is_gzipped:
        os.remove(igbFile)

    return data, hd
コード例 #23
0
ファイル: autocorrelate.py プロジェクト: JasVixBan/kamasu
import numpy as n
from pylab import *

#
# generate signal
#
sr = 48000.0

datfile = 'signal.dat'
nsamples = os.stat(datfile)[ST_SIZE] / 4

print "Reading %d samples from %s" % (nsamples, datfile)
fd = open(datfile, 'rb')
datatype = 'f'
shape = (nsamples,)
blob = fread(fd, nsamples, datatype)
signal = blob.reshape(shape)

#
# autocorr routine
#

def autocorrelate(a):
    winlen = int(sr/70)

    freqs = n.zeros((len(a)-winlen,))

    for outer in range(0, len(a)-(winlen*2)):

        corr_coeff = n.zeros((winlen,))
        for inner in range(winlen):
コード例 #24
0
ファイル: mIO.py プロジェクト: lbaehren/lofarsoft
 def fread(self,count,mtype):
     howmany,mtype = getsize_type(mtype)
     retval = numpyio.fread(self.fid, count, mtype, mtype, self.bs)
     if len(retval) == 1:
         retval = retval[0]
     return retval
コード例 #25
0
ファイル: plot_frequencies.py プロジェクト: JasVixBan/kamasu
#!/usr/bin/python


import numpy as n
from scipy.io.numpyio import fread
import os, sys
from stat import *
from pylab import *
#
# generate signal
#
sr = 48000.0

nsamples = os.stat(sys.argv[1])[ST_SIZE] / 4

fd = open(sys.argv[1], 'rb')

blob = fread(fd, nsamples, 'f')
shape = (nsamples,)
signal = blob.reshape(shape)

plot(signal)
show()
コード例 #26
0
ファイル: avs2vtkr_cut.py プロジェクト: klenovsky/CI
# Check whether the file is binary or ascii
#   The chenking is implemented by counting the number of
#   lines is ascii mode. If it is equal to size, the file
#   is an ascii file. 

        count=0
        for line in open(fname+'.dat','r'):
                if (line.strip() != ''): count += 1

        if (count == (size*veclen)):
                # Ascii file
                read_data=np.loadtxt(fname+'.dat')
        else:
                # Binary file
                fd=open(fname+'.dat','rb')
                read_data = fread(fd, size, 'd')
                fd.close()

        f_out=open(fname+'.vtk','w')
        f_out.write('# vtk DataFile Version 2.0\n')
        f_out.write(fname+'\n')
        f_out.write('ASCII\n')    
        f_out.write('DATASET RECTILINEAR_GRID\n')
        if(ndim==3):
                f_out.write('DIMENSIONS %6d %6d %6d\n'%(dim1-16,dim2-16,dim3-25))
        else:
                f_out.write('DIMENSIONS %6d %6d\n'%(dim1-16,dim2-16))
        f_out.write('X_COORDINATES %8d float\n'%(dim1-16))
        for i in range(8,dim1-8):
               f_out.write('%18.10f\n'%(coord_1[i]))
        f_out.write('Y_COORDINATES %8d float\n'%(dim2-16))
コード例 #27
0
ファイル: 051-plot-file.py プロジェクト: wbkifun/my_stuff
#!/usr/bin/env python

from pylab import *
from scipy.io.numpyio import fread

Nx, Ny = 400, 350
	
fd = open('./dat/050-A_binary.dat', 'rb')
A = fread( fd, Nx*Ny, 'f' )
A = A.reshape( Nx, Ny )
fd.close()

fd = open('./dat/050-dA_binary.dat', 'rb')
dA = fread( fd, Nx*Ny, 'f' )
dA = dA.reshape( Nx, Ny )
fd.close()

figure( figsize=(15,5) )
subplot(1,2,1)
imshow( A.T, cmap=cm.hot, origin='lower', interpolation='bilinear' )
title('2D Gaussian')
xlabel('x-axis')
ylabel('y-axis')
colorbar()

subplot(1,2,2)
imshow( dA.T, cmap=cm.hot, origin='lower', interpolation='bilinear' )
title('differential')
xlabel('x-axis')
ylabel('y-axis')
colorbar()
コード例 #28
0
ファイル: plot_fft.py プロジェクト: JasVixBan/kamasu
#!/usr/bin/python


import sys
import numpy as n
from scipy.io.numpyio import fread
import os, sys
from stat import *
from pylab import *
import matplotlib.ticker as mt
import matplotlib.mlab as mlab

print "Opening %s" % sys.argv[1]
fd = open(sys.argv[1], 'rb')

title = sys.argv[2]

shape = fread(fd, 2, 'f')
shape = shape.astype(n.int32)
print "shape=", shape, " going to read %d bytes", shape[0] * shape[1] 
blob = fread(fd, shape[0] * shape[1], 'f')
print "Blob size is %d" % blob.size
Z = blob.reshape(shape)

imshow(Z.T)  #, None)# , extent = (x_labels[0], x_labels[-1],y_labels[0], y_labels[-1]))

gca().axis('tight')
gca().set_title(title)
show()