当前位置: 首页>>代码示例>>Python>>正文


Python scipy.fromfile函数代码示例

本文整理汇总了Python中scipy.fromfile函数的典型用法代码示例。如果您正苦于以下问题:Python fromfile函数的具体用法?Python fromfile怎么用?Python fromfile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了fromfile函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_data

    def get_data(self):
        self.text_sym.set_text("Symbol: %d" % (self.symbol))

        derot_data = scipy.fromfile(self.h_derot_file, dtype=scipy.complex64, count=self.occ_tones)
        acq_data = scipy.fromfile(self.h_acq_file, dtype=scipy.complex64, count=self.occ_tones)
        fft_data = scipy.fromfile(self.h_fft_file, dtype=scipy.complex64, count=self.fft_size)
        if(len(acq_data) == 0):
            print "End of File"
        else:
            self.acq_data_reals = [r.real for r in acq_data]
            self.acq_data_imags = [i.imag for i in acq_data]
            self.derot_data_reals = [r.real for r in derot_data]
            self.derot_data_imags = [i.imag for i in derot_data]

            self.unequalized_angle = [math.atan2(x.imag, x.real) for x in fft_data]
            self.equalized_angle = [math.atan2(x.imag, x.real) for x in acq_data]
            self.derot_equalized_angle = [math.atan2(x.imag, x.real) for x in derot_data]

            self.time = [i*(1/self.sample_rate) for i in range(len(acq_data))]
            ffttime = [i*(1/self.sample_rate) for i in range(len(fft_data))]

            self.freq = self.get_freq(ffttime, self.sample_rate)

            for i in range(len(fft_data)):
                if(abs(fft_data[i]) == 0.0):
                    fft_data[i] = complex(1e-6,1e-6)
            self.fft_data = [20*log10(abs(f)) for f in fft_data]
开发者ID:Darren2340,项目名称:local_gnuradio,代码行数:27,代码来源:gr_plot_ofdm.py

示例2: NumpyTensorInitializerForVacancy

def NumpyTensorInitializerForVacancy(gridShape, filename, vacancyfile=None):
    """
    Initialize a 10 component plasticity state by reading from a numpy "tofile" type file or two files.
    """
    dict = {('x','x') : (0,0), ('x','y') : (0,1), ('x','z') : (0,2),\
            ('y','x') : (1,0), ('y','y') : (1,1), ('y','z') : (1,2),\
            ('z','x') : (2,0), ('z','y') : (2,1), ('z','z') : (2,2)}
    data = fromfile(filename)
    if vacancyfile is None:
        data = data.reshape([10] + list(gridShape))
    else:
        data = data.reshape([3,3] + list(gridShape))
        dataV = fromfile(vacancyfile)
        dataV = dataV.reshape(list(gridShape))
    state = VacancyState.VacancyState(gridShape)
    field = state.GetOrderParameterField() 
    if vacancyfile is None:
        i = 0
        for component in field.components:
            field[component] = copy(data[i]) 
            i += 1
    else:
        for component in field.components:
            if component[0] not in [x,y,z]:
                field[component] = copy(dataV) 
            else:
                field[component] = copy(data[dict[component]]) 
    return state
开发者ID:mattbierbaum,项目名称:cuda-plasticity,代码行数:28,代码来源:FieldInitializer.py

示例3: main

def main(argv):
    inputfile=''
    original_file=''
    indices_file=''
    try:
        opts, args = getopt.getopt(argv,"h:d:i:o:",["dfile=","itype=","ofile="])
    except getopt.GetoptError:
        print 'file.py -d <file_to_decode>  -o <original_file>  -i <indices_file>'
        sys.exit(2)
    for opt, arg in opts:
        print opt ,arg,
        if opt == '-h':
            print 'file.py -d <file_to_decode>  -o <original_file> -i <indices_file> '
            sys.exit()
        elif opt in ("-d", "--dfile"):
            inputfile = arg
        elif opt in ("-i", "--itype"):
            indices_file = arg
        elif opt in ("-o", "--ofile"):
            original_file = arg
        else:
            print "check help for usage" 
            sys.exit()

    print inputfile
    print    inputfile.split('_')

    to_decode_file = scipy.fromfile(open(inputfile), dtype=scipy.float32)
    original_string = scipy.fromfile(open(original_file), dtype=scipy.float32)
    oracle_indices = np.load(indices_file)
    print "\n lengths for measured data:" , len(to_decode_file), "length of orig transmission: ",len(original_string)
    get_index=start_index(to_decode_file)
    start_data_index = get_index+1 # get_index+1 #(m-get_index)  #m - (len(preamble) - get_index) +1
    print "starting of data is  ", start_data_index
    plt.plot(to_decode_file[:start_data_index],'*-')
    plt.savefig('abhinav.pdf')
    plt.clf()
    original_message =original_string[len(preamble):]
    to_decode_data1= to_decode_file[start_data_index:]
    to_decode_data= to_decode_data1.astype(np.int64)
    #print "lengths of data going in:", len(original_message), len(to_decode_data)
    #bin_rep_to_decode=decoding_maj3(oracle_indices,to_decode_data)
    bin_rep_to_decode=single_demod(oracle_indices,to_decode_data)
    ber_single(oracle_indices,to_decode_data, original_message)
    print "\nGoing to decode"
    rs= reedsolo.RSCodec(32)
    message_decoded =''
    try:
        message_decoded = rs.decode(bin_rep_to_decode)
    except:
        print "Cannot decode using RS decoder " 
    print "decoded message is ",message_decoded
    print "\n"
开发者ID:abnarain,项目名称:emperor,代码行数:53,代码来源:decoder.py

示例4: readdatafile

def readdatafile(fname):
    root, ext = os.path.splitext(fname)
    path, base = os.path.split(root)
    datafilename = base + ext
    parfile = root + '.par'
    
    (common, channels) = readparfile(parfile)

    channelindex = [n for n,d in enumerate(channels) if d['file'] == datafilename][0]
    thechannel = channels[channelindex]
    
    i = Data.Image()
    i.Name = datafilename
    i.ImageType = 'Topo'
    i.XPos = float(common['X Offset'])
    i.YPos = float(common['Y Offset'])
    i.XSize = float(common['Field X Size in nm'])
    i.YSize = float(common['Field Y Size in nm'])
    i.XRes = int(common['Image Size in X'])
    i.YRes = int(common['Image Size in Y'])
    i.ZScale = (float(thechannel['maxphys']) - float(thechannel['minphys'])) / \
        (float(thechannel['maxraw']) - float(thechannel['minraw']))
    i.UBias = float(pickValueForMode(common,thechannel,'Gap Voltage'))
    i.ISet = float(pickValueForMode(common,thechannel,'Feedback Set'))
    i.ScanSpeed = float(common['Scan Speed'])
    i.d = scipy.fromfile(file=fname,dtype=scipy.int16)
    i.d = i.d.byteswap()
    i.d.shape = i.XRes, i.YRes
    i.updateDataRange()
    return i
开发者ID:fmarczin,项目名称:pysxm,代码行数:30,代码来源:Omikron.py

示例5: after_record

def after_record(tb, cf):
    tb.stop()
    tb.wait()

    import scipy
    vals = scipy.fromfile(open("out"), dtype=float)
    #print vals
    print len(vals)

    readings_per_sample = 2048
    samples = len(vals)/readings_per_sample
    sums = ([0] * readings_per_sample)
    for i in range(samples):
        sample = vals[i*readings_per_sample:(i+1)*readings_per_sample]
        for j in range(readings_per_sample):
            sums[j] += sample[j]
    for i in xrange(readings_per_sample):
        sums[i] /= samples 
         
    #print sums
    #for i in range(readings_per_sample):
     #print sums[i].imag ,sums[i].real 
     #print sums[i].real 
    print len(sums)
    x = [cf-1e6+i*(4e6/readings_per_sample) for i in range(readings_per_sample/2)]
    y = [10*(math.log10((sums[i])/10**5)) for i in range(readings_per_sample/2)]


      #if x[i] == cf:
        #y=0
    with open(get_record_filename(cf), "w") as f:
        f.write(str(zip(x, y)))
开发者ID:pradeepgodara,项目名称:SPECTRUM-ANALYSIS-using-GNU-RADIO-,代码行数:32,代码来源:record.py

示例6: read_pst

def read_pst(pst_path):
    """ read tillvision based .pst files as uint16.
    note: this func was flagged deprecated ("use the version in gioIO" instead,
    but that one never existed ... ")
    problematic: does not work on all .pst on my machine """

    inf_path = os.path.splitext(pst_path)[0] + '.inf'

    # reading stack size from inf
    meta = {}
    with open(inf_path,'r') as fh:
    #    fh.next()
        for line in fh.readlines():
            try:
                k,v = line.strip().split('=')
                meta[k] = v
            except:
                pass

    shape = sp.int32((meta['Width'],meta['Height'],meta['Frames']))


    raw = sp.fromfile(pst_path,dtype='int16')
    data = sp.reshape(raw,shape,order='F')
    return data.astype('uint16')
开发者ID:grg2rsr,项目名称:ILTIS,代码行数:25,代码来源:IOtools.py

示例7: do_GET

	def do_GET(self):
		self.send_response(200)
		self.send_header("Content-type","text/html")
		self.end_headers()
		query_string = urlparse.urlparse(self.path).query
		if(self.path == PATH_FLOW_GRAPH):
			fp = open(PATH_FLOW_GRAPH,"rb")
			self.wfile.write(fp.read())
		else:
			query_string = urllib.unquote(query_string)
			#Gather individual parameters
			param_list = query_string.split("&")
		
			#append filename of xml parsing file
			param_list.insert(0,"./xmlparse.py")
			xmlproc = subprocess.Popen(param_list)	
			xmlproc.wait()
			process = subprocess.Popen([PATH_TOP_BLOCK], stdout=subprocess.PIPE)
			time.sleep(2)
			process.kill()
			arr = scipy.fromfile(OUT_FILE_PATH,dtype=scipy.float32,count=NUM_VALUES)
			value = []
			for i in range(NUM_VALUES):
				value.append([str(i),float(arr[i])])
			description = [('Output number','string'),('Result','number')]
			table = gviz_api.DataTable(description)
			path_flow_graph = PATH_FLOW_GRAPH
			res = """
			<html>
	 	 		<head>
	    				<script type="text/javascript" src="https://www.google.com/jsapi"></script>
	    				<script type="text/javascript">
	      					google.load("visualization", "1", {packages:["corechart"]});
	      					google.setOnLoadCallback(drawChart);
	      					function drawChart()
						{
							var data = new google.visualization.DataTable(%(values)s,0.6);
							var options = {
		  						title: 'Square Plot'
								};

							var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
							chart.draw(data, options);
	      					}
	    				</script>
	  			</head>
	  			<body>
					<h1>FLOW GRAPH:</h1><br/>
					<img src=%(path_flow_graph)s alt="flow graph" height="700" width="900" align="middle">
					<h1>PLOT:</h1><br/>
	    				<div id="chart_div" style="width: 1200px; height: 350px;"></div>
	  			</body>
			</html>
	"""
			
			table.AppendData(value)
			values = table.ToJSon(columns_order=('Output number','Result'))
			result = res % vars()
			self.wfile.write(result)
开发者ID:FOSSE-Sandhi,项目名称:internship,代码行数:59,代码来源:server.py

示例8: NumpyTensorInitializer

def NumpyTensorInitializer(gridShape, filename, bin=True):
    """
    Initialize a 9 component plasticity state by reading from a numpy "tofile" type file.
    """
    if bin:
        data = fromfile(filename)
    else:
        data = fromfile(filename,sep='  ')
    data = data.reshape([3,3] + list(gridShape))
    state = PlasticityState.PlasticityState(gridShape)
    dict = {('x','x') : (0,0), ('x','y') : (0,1), ('x','z') : (0,2),\
            ('y','x') : (1,0), ('y','y') : (1,1), ('y','z') : (1,2),\
            ('z','x') : (2,0), ('z','y') : (2,1), ('z','z') : (2,2)}
    field = state.GetOrderParameterField()
    for component in field.components:
        field[component] = copy(data[dict[component]]) 
    return state
开发者ID:mattbierbaum,项目名称:cuda-plasticity,代码行数:17,代码来源:FieldInitializer.py

示例9: volume_from_file

def volume_from_file(filename, frameshape=(512, 512)):
    with file(filename) as fp:
        arr = scipy.fromfile(fp, dtype=scipy.uint8)
    x, y = frameshape
    n, = arr.shape
    n /=  x * y
    arr.shape = n, x, y
    return arr
开发者ID:saahil,项目名称:MSSegmentation,代码行数:8,代码来源:data.py

示例10: read_dat

 def read_dat(self, filename=None):
     if not filename:
         filename = self.filename
     try:
         return sp.fromfile(filename)
     except:
         CXP.log.error('Could not extract data from data file.')
         raise
开发者ID:buzmakov,项目名称:cxphasing,代码行数:8,代码来源:CXFileReader.py

示例11: get_data

 def get_data(self, hfile):
     self.text_file_pos.set_text("File Position: %d" % (hfile.tell()//self.sizeof_data))
     f = scipy.fromfile(hfile, dtype=self.datatype, count=self.block_length)
     #print "Read in %d items" % len(self.f)
     if(len(f) == 0):
         print "End of File"
     else:
         self.f = f
         self.time = [i*(1/self.sample_rate) for i in range(len(self.f))]
开发者ID:GREO,项目名称:GNU-Radio,代码行数:9,代码来源:plot_data.py

示例12: get_data

 def get_data(self, hfile):
     self.text_file_pos.set_text("File Position: %d" % (hfile.tell() // self.sizeof_data))
     try:
         f = scipy.fromfile(hfile, dtype=self.datatype, count=self.block_length)
     except MemoryError:
         print "End of File"
     else:
         self.f = scipy.array(f)
         self.time = scipy.array([i * (1 / self.sample_rate) for i in range(len(self.f))])
开发者ID:zeokav,项目名称:sandhi,代码行数:9,代码来源:plot_data.py

示例13: _fromfile

 def _fromfile(self, fileid):
     self.header=sc.rec.fromfile(fileid, dtype=_HEADER_1, shape=1, byteorder='<')[0]
     dtype=self.get_dtype(self.header.datatype)
     xdim=self.header.xdim
     ydim=self.header.ydim
     nfram=self.header.NumFrames
     
     data=sc.fromfile(fileid, dtype=dtype, count=nfram*xdim*ydim)
     self.frames=sc.reshape(data,(nfram, ydim, xdim,))
开发者ID:kshmirko,项目名称:SPEScec,代码行数:9,代码来源:spespec.py

示例14: get_data

 def get_data(self):
     self.text_file_pos.set_text("File Position: %d" % (self.hfile.tell()//self.sizeof_data))
     try:
         self.iq = scipy.fromfile(self.hfile, dtype=self.datatype, count=self.block_length)
     except MemoryError:
         print "End of File"
     else:
         self.reals = scipy.array([r.real for r in self.iq])
         self.imags = scipy.array([i.imag for i in self.iq])
         self.time = scipy.array([i*(1/self.sample_rate) for i in range(len(self.reals))])
开发者ID:GREO,项目名称:gnuradio-git,代码行数:10,代码来源:gr_plot_iq.py

示例15: filereader

def filereader(filename): 
    z= scipy.fromfile(open(filename), dtype=scipy.complex64)
    # dtype with scipy.int16, scipy.int32, scipy.float32, scipy.complex64 or whatever type you were using.
    mag, phase,x,y = [], [], [], []
    for i in range(0, len(z)):
        mag.append(np.absolute(z[i]))
        x.append(z[i].real)
        y.append(z[i].imag)
        phase.append(np.angle(z[i]))
    return [x,y,mag, phase,z]
开发者ID:abnarain,项目名称:emperor,代码行数:10,代码来源:plot_plc.py


注:本文中的scipy.fromfile函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。