Python 运行matpplotlib';s specgram命令

Python 运行matpplotlib';s specgram命令,python,matplotlib,ubuntu-12.04,Python,Matplotlib,Ubuntu 12.04,我衷心感谢您在以下方面的帮助: 我正试图在我的双启动笔记本电脑(-Ubuntu 12.04 LTS,64位和MS Windows 7 64位)上运行一些python代码(使用Ipython,python版本2.7.3)。在windows中运行代码效果很好,但由于某些原因,在Ubuntu中会出现内存错误。我不确定这是python问题还是操作系统问题。我会坚持在微软的windows上运行代码,但这也有我自己的问题,包括导入库等,我在Ubuntu中运行代码时没有这些问题 该守则相当直截了当。作为参考,

我衷心感谢您在以下方面的帮助:

我正试图在我的双启动笔记本电脑(-Ubuntu 12.04 LTS,64位和MS Windows 7 64位)上运行一些python代码(使用Ipython,python版本2.7.3)。在windows中运行代码效果很好,但由于某些原因,在Ubuntu中会出现内存错误。我不确定这是python问题还是操作系统问题。我会坚持在微软的windows上运行代码,但这也有我自己的问题,包括导入库等,我在Ubuntu中运行代码时没有这些问题

该守则相当直截了当。作为参考,我有一个大的二进制文件,它表示实验室仪器中3个通道的16位有符号数字。数据以10ms/s的速度采样。该文件为~1.G GB,表示大约25秒的数据。在下面的代码中,我将数据读入“data”,现在希望使用Matplotlib的specgram函数绘制光谱图。这一部分在Windows中运行良好,但在Ubuntu中不起作用

一些代码

import os
import sys
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab
file = "data_stream.srm"
with open(file,'rb') as fd:
fd.seek(0)
data = np.fromfile(fd,dtype=[('ch0','<i2'),('ch1','<i2'),('ch2','<i2')]) 
返回,2611144000

下一个问题是使用matplotlib的specgram函数的光谱图

   specgram(x, NFFT=256, Fs=2, Fc=0, detrend=mlab.detrend_none,
    window=mlab.window_hanning, noverlap=128,
    cmap=None, xextent=None, pad_to=None, sides='default',
    scale_by_freq=None, **kwargs)
一些代码

ADCR = 12        # ADC Resolution in bits
    VOLT = 5.0       # Voltage range
    SF = VOLT/(2**ADCR)  # scaling factor to convert raw ADC values to volts  

    w_length= 512 
    nFFT=2 * w_length
    n_overlap=np.fix(w_length/2)
    p_to = 4 *w_length
    cmap=plt.cm.seismic
    Fs = 10E6 # Sampling Frequency
    fig=plt.figure()
    ax=fig.add_subplot(111)
    Pxx, freqs, bins,im =    


plt.specgram((data['ch1'])*SF,NFFT=nFFT,Fs=Fs,noverlap=n_overlap,pad_to=p_to,cmap=cmap)
运行最后一个命令在windows中有效,但在Ubuntu中无效。我收到以下信息:

内存错误。。。“无法发布图像,因为我需要10个声誉才能发布”

MemoryError回溯(最近一次调用)
/介质/IomegaHDD/in()
---->1 Pxx,频率,箱,im=plt.specgram((数据['ch1'])*SF,NFFT=NFFT,Fs=Fs,detrend=mlab.detrend\u线性,noverlap=n\u重叠,pad\u to=p\u to,scale\u by\u freq=True,cmap=cmap)
/specgram中的usr/lib/pymodules/python2.7/matplotlib/pyplot.pyc(x、NFFT、Fs、Fc、detrend、window、noverlap、cmap、xextent、pad_to、sides、按频率缩放、保持、**kwargs)
2609斧头保持(保持)
2610尝试:
->2611 ret=最大规格图(x、NFFT、Fs、Fc、detrend、窗口、noverlap、cmap、xextent、焊盘至、侧面、按频率缩放,**kwargs)
2612 draw_if_interactive()
2613最后:
/specgram中的usr/lib/pymodules/python2.7/matplotlib/axes.pyc(self、x、NFFT、Fs、Fc、detrend、window、novelap、cmap、xextent、pad_to、sides、scale_by_freq、**kwargs)
8146
8147 Pxx,频率,料仓=mlab.specgram(x,NFFT,Fs,detrend,
->8148窗户,noverlap,墙板,侧面,按频率缩放)
8149
8150 Z=10。*np.log10(Pxx)
/specgram中的usr/lib/pymodules/python2.7/matplotlib/mlab.pyc(x、NFFT、Fs、detrend、window、noverlap、pad_to、sides、scale_by_freq)
458
459 Pxx,freqs,t=_spectrum_helper(x,x,NFFT,Fs,detrend,window,
-->460 noverlap,pad_to,side,scale_by_freq)
461 Pxx=Pxx.real#需要,因为helper一般实现
462
/usr/lib/pymodules/python2.7/matplotlib/mlab.pyc in_spectrum_helper(x、y、NFFT、Fs、detrend、window、noverlap、pad_to、sides、scale_by_freq)
256 ind=np.arange(0,len(x)-NFFT+1,步长)
257 n=len(ind)
-->258 Pxy=np.零((numfreks,n),np.复数)
259
260#对切片进行FFT
记忆错误:
正如我所说,也许这是Ubuntu的问题,我不知道,因为我在Windows中运行代码时没有遇到这个问题。然而,这与代码的其他后续部分有着自身的问题

谢谢你的帮助

多谢各位

问候,


威尔。

你确定你正在运行32位Ubuntu发行版吗?您还必须运行64位版本的python

如果这就是问题所在,那就是32位操作系统(和程序)无法处理64位系统所能处理的大内存块

要判断您是否有64位Linux,请运行(在Ubuntu中)

寻找

  • x86\u 64 GNU/Linux
    ——64位
  • ia64 GNU/Linux
    ——64位
  • i386 GNU/Linux
    ——32位
要查看是否有32位python可执行文件,请查看

$ file -L `which python`

注意64秒或32秒。

错误消息还有其他内容吗?没有。这就是全部内容。您有多少内存?linux端有交换分区吗?嗨。具有8 GB RAM,并使用交换。键入cat/proc/swaps显示Filename/host/ubuntu/disks/swap.disk,键入file,大小262140,使用8,优先级-1再次澄清一下,我肯定运行的是64位版本的ubuntu和64位版本的python。请看下面。Linux ubuntu 3.2.0-38-generic#61 ubuntu SMP周二2月19日12:18:21 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux。[1]中:在[2]中导入平台:打印平台.architecture()[0]64位
ADCR = 12        # ADC Resolution in bits
    VOLT = 5.0       # Voltage range
    SF = VOLT/(2**ADCR)  # scaling factor to convert raw ADC values to volts  

    w_length= 512 
    nFFT=2 * w_length
    n_overlap=np.fix(w_length/2)
    p_to = 4 *w_length
    cmap=plt.cm.seismic
    Fs = 10E6 # Sampling Frequency
    fig=plt.figure()
    ax=fig.add_subplot(111)
    Pxx, freqs, bins,im =    


plt.specgram((data['ch1'])*SF,NFFT=nFFT,Fs=Fs,noverlap=n_overlap,pad_to=p_to,cmap=cmap)
MemoryError                               Traceback (most recent call last)
/media/IomegaHDD/<ipython-input-28-5144fe0c6918> in <module>()
----> 1 Pxx, freqs, bins, im = plt.specgram((data['ch1'])*SF,NFFT=nFFT,Fs=Fs,detrend=mlab.detrend_linear,noverlap=n_overlap,pad_to=p_to,scale_by_freq=True,cmap=cmap)

/usr/lib/pymodules/python2.7/matplotlib/pyplot.pyc in specgram(x, NFFT, Fs, Fc, detrend, window, noverlap, cmap, xextent, pad_to, sides, scale_by_freq, hold, **kwargs)
   2609         ax.hold(hold)
   2610     try:
-> 2611         ret = ax.specgram(x, NFFT, Fs, Fc, detrend, window, noverlap, cmap, xextent, pad_to, sides, scale_by_freq, **kwargs)
   2612         draw_if_interactive()
   2613     finally:

/usr/lib/pymodules/python2.7/matplotlib/axes.pyc in specgram(self, x, NFFT, Fs, Fc, detrend, window, noverlap, cmap, xextent, pad_to, sides, scale_by_freq, **kwargs)
   8146 
   8147         Pxx, freqs, bins = mlab.specgram(x, NFFT, Fs, detrend,
-> 8148              window, noverlap, pad_to, sides, scale_by_freq)
   8149 
   8150         Z = 10. * np.log10(Pxx)

/usr/lib/pymodules/python2.7/matplotlib/mlab.pyc in specgram(x, NFFT, Fs, detrend, window, noverlap, pad_to, sides, scale_by_freq)
    458 
    459     Pxx, freqs, t = _spectral_helper(x, x, NFFT, Fs, detrend, window,
--> 460         noverlap, pad_to, sides, scale_by_freq)
    461     Pxx = Pxx.real #Needed since helper implements generically
    462 

/usr/lib/pymodules/python2.7/matplotlib/mlab.pyc in _spectral_helper(x, y, NFFT, Fs, detrend, window, noverlap, pad_to, sides, scale_by_freq)
    256     ind = np.arange(0, len(x) - NFFT + 1, step)
    257     n = len(ind)
--> 258     Pxy = np.zeros((numFreqs, n), np.complex_)
    259 
    260     # do the ffts of the slices


MemoryError: 
$ uname -a
$ file -L `which python`