Numpy Fft Memory Error
Contents |
here for a quick overview of the site Help Center Detailed numpy asarray memory error answers to any questions you might have Meta Discuss the numpy zeros memory error workings and policies of this site About Us Learn more about Stack Overflow the company python numpy array memory error Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join memoryerror python the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Can`t run Python code computing Fourier Transform on .tiff image? How to manage memory? up vote 1 down vote favorite 2 My
Python Sparse
Python code, designed for computation of Fourier Transform can`t complete the task. def fouriertransform(result): #function for FTM computation for filename in glob.iglob('*.tif'): imgfourier = scipy.misc.imread(filename, flatten = True) image = np.array([imgfourier])#make an array as np arr = np.abs(np.fft.fftshift(np.fft.fft2(image)))**2 with open('сomput.csv', 'wb') as csvfile: for elem in arr.flat[:50]: writer = csv.writer(csvfile, .....) writer.writerow([('{}\t'.format(elem))]) Traceback (most recent call last): File "C:\Python27\lib\site-packages\numpy\fft\fftpack.py", line 524, in _raw_fftnd a = function(a, n=s[ii], axis=axes[ii]) File "C:\Python27\lib\site-packages\numpy\fft\fftpack.py", line 164, in fft return _raw_fft(a, n, axis, fftpack.cffti, fftpack.cfftf, _fft_cache) File "C:\Python27\lib\site-packages\numpy\fft\fftpack.py", line 75, in _raw_fft r = work_function(a, wsave) MemoryError Image is large 90 MB, how to solve the problem if it works on 1-5 MB images somehow? Thank you python numpy fft share|improve this question asked Jul 3 '13 at 20:44 KvasDub 11910 add a comment| 1 Answer 1 active oldest votes up vote 1 down vote Some suggestions: The scipy.fftpack functions
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of
Gc.collect Python
this site About Us Learn more about Stack Overflow the company Business Learn python clear memory more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question numpy memmap x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up http://stackoverflow.com/questions/17457792/cant-run-python-code-computing-fourier-transform-on-tiff-image-how-to-manage Memory error using scipy.fftpack, how to avoid it? up vote 2 down vote favorite 1 I need to compute Fourier coefficients in Python from a .tiff medical image. The code produces a memory error: for filename in glob.iglob ('*.tif'): imgfourier = scipy.misc.imread (filename, flatten = True) image = numpy.array([imgfourier])#make an array # Take the fourier transform of the image. F1 = fftpack.fft2(image) # Now http://stackoverflow.com/questions/17263241/memory-error-using-scipy-fftpack-how-to-avoid-it shift so that low spatial frequencies are in the center. F2 = fftpack.fftshift(F1) # the 2D power spectrum is: psd2D = np.abs(F2)**2 print psd2D Any help would be really appreciated! Thanks python memory numpy scipy fft share|improve this question edited Jun 23 '13 at 18:06 Saullo Castro 23.9k657114 asked Jun 23 '13 at 17:14 KvasDub 11910 5 How big is your image, and how much memory do you have? –tiago Jun 23 '13 at 21:21 add a comment| 1 Answer 1 active oldest votes up vote 1 down vote I found this discussion where they identified memory leaks in scipy.fftpack, suggesting to use numpy.fft package instead. Also, you can save memory avoiding the intermediate variables: import numpy as np import glob import scipy.misc for filename in glob.iglob('*.tif'): imgfourier = scipy.misc.imread (filename, flatten = True) print np.abs(np.fft.fftshift(np.fft.fft2(np.array([imgfourier]))))**2 share|improve this answer edited Jun 23 '13 at 18:11 answered Jun 23 '13 at 18:02 Saullo Castro 23.9k657114 On my machine this code produces errors, thanks: –KvasDub Jun 23 '13 at 18:10 File "C:\Python27\lib\site-packages\numpy\fft\fftpack.py", line 75, in _raw_fft r = work_function(a, wsave) MemoryError –KvasDub Jun 23 '
»PythoncommentsWant to join? Log in or sign up in seconds.|Englishlimit my search to /r/Pythonuse the following search parameters to narrow your results:subreddit:subredditfind submissions in "subreddit"author:usernamefind submissions by "username"site:example.comfind submissions from "example.com"url:textsearch for "text" in urlselftext:textsearch for "text" in self https://www.reddit.com/r/Python/comments/hfavk/memory_problems_when_i_shouldnt_have_any/ post contentsself:yes (or self:no)include (or exclude) self postsnsfw:yes (or nsfw:no)include (or exclude) results marked as NSFWe.g. subreddit:aww site:imgur.com dogsee the search http://astrofrog-debug.readthedocs.org/en/latest/_modules/astropy/convolution/convolve.html faq for details.advanced search: by author, subreddit...this post was submitted on 19 May 201111 points (93% upvoted)shortlink: remember mereset passwordloginSubmit a new memory error linkSubmit a new text postPythonsubscribeunsubscribe140,095 readers146 users here nownews about the dynamic, interpreted, interactive, object-oriented, extensible programming language Python If you are about to ask a question, please consider r/learnpython. Homework-style questions will be removed, and you'll be encouraged to post there instead. array memory error Please don't use URL shorteners Posting code to this subreddit: Add 4 extra spaces before each line of code def fibonacci(): a, b = 0, 1 while True: yield a a, b = b, a + b Online Books and Resources Think Python Dive into Python 3 Automate the Boring Stuff with Python Invent Your Own Computer Games with Python Non-programmers Tutorial for Python 3 Beginner's Guide Reference Five life jackets to throw to the new coder (things to do after getting a handle on python) Full Stack Python Test-Driven Development with Python Program Arcade Games Online exercices codingbat pyschools codecademy Problem Solving with Algorithms and Data Structures How To Think Like a Computer Scientist Code School: Try Python programming chall
print_function, unicode_literals) import warnings import numpy as np from .core import Kernel, Kernel1D, Kernel2D, MAX_NORMALIZATION from ..utils.exceptions import AstropyUserWarning from ..utils.console import human_file_size from astropy import units as u # Disabling all doctests in this module until a better way of handling warnings # in doctests can be determined __doctest_skip__ = ['*'] [docs]def convolve(array, kernel, boundary='fill', fill_value=0., normalize_kernel=False): ''' Convolve an array with a kernel. This routine differs from `scipy.ndimage.convolve` because it includes a special treatment for ``NaN`` values. Rather than including ``NaN`` values in the array in the convolution calculation, which causes large ``NaN`` holes in the convolved array, ``NaN`` values are replaced with interpolated values using the kernel as an interpolation function. Parameters ---------- array : `numpy.ndarray` The array to convolve. This should be a 1, 2, or 3-dimensional array or a list or a set of nested lists representing a 1, 2, or 3-dimensional array. kernel : `numpy.ndarray` or `~astropy.convolution.Kernel` The convolution kernel. The number of dimensions should match those for the array, and the dimensions should be odd in all directions. boundary : str, optional A flag indicating how to handle boundaries: * `None` Set the ``result`` values to zero where the kernel extends beyond the edge of the array (default). * 'fill' Set values outside the array boundary to ``fill_value``. * 'wrap' Periodic boundary that wrap to the other side of ``array``. * 'extend' Set values outside the array to the nearest ``array`` value. fill_value : float, optional The value to use outside the array when using ``boundary='fill'`` normalize_kernel : bool, optional Whether to normalize the kernel prior to convolving Returns ------- result : `numpy.ndarray` An array with the same dimensions and as the input array, convolved with kernel. The data type depends on the input array type. If array is a floating point type, then the return array keeps the same data type, otherwise the type is ``numpy.float``. Notes ----- Masked arrays are not supported at this time. The convolution is always done at ``numpy.float`` precision. ''' from .boundary_none import (convolve1d_boundary_none