Pyrex installation on windows XP: step-by-step guide
Do you wand to install Pyrex on Windows ? Here is a step-by-step guide explaining: A) how to install Pyrex on Windows XP. B) how to compile a Pyrex module. Julien Fiore, U. of Geneva --- ### A) Pyrex installation on Windows XP ### # step A.1 # Install Python (we used version 2.4.2) # step A.2 # Run the windows installer for Pyrex (e.g. Pyrex-0.9.3.1.win32.exe), available on the Pyrex homepage (http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/) # step A.3 # Install Mingw, the gcc compiler for Windows, available at http://www.mingw.org/download.shtml. (we downloaded the file MinGW-5.0.2.exe and installed only the "base tool" (this includes mingw-runtime 3.9, w32api-3.6, binutils 2.15.91 and gcc-core 3.4.2). Add Mingw path ("C:\MinGW\bin") to the Windows "Path" environment variable. If you already have cygwin installed, add C:\MinGW\bin before the Cygwin path. # step A.4 # Create or edit the file "c:/Python2x/Lib/distutils/distutils.cfg" and put the following into it: [build] compiler = mingw32 --- ### B) Create a Pyrex module ### # step B.1 # Create a working directory (e.g. D:\pyrex_module\). Write a pyrex module and save it with a "pyx" extension (e.g. "primes.pyx", code available on the Pyrex homepage) # step B.2 # Write the following python script and save it as "setup.py" in your working directory. from distutils.core import setup from distutils.extension import Extension from Pyrex.Distutils import build_ext setup( name = "PyrexGuide", ext_modules=[ Extension("primes", ["primes.pyx"]) ], cmdclass = {'build_ext': build_ext} ) If you want to compile several modules, duplicate the line starting with "Extension" and replace "primes" by your module names. # step B.3 # In your working directory, create a batch file called "build_and_install.bat" containing the following lines, where "PythonXX" should be replaces by your Python version (e.g. "Python24"). C:\Python24\python.exe setup.py build_ext install pause To run the batch, double-click the file. You will see many "Warning" messages during the building process: do not worry, it is normal. # step B.4 # Mission completed. The file "primes.pyd" (a "pyd" is a Python Extension DLL, equivalent of .so in Unix) is now located in "C:\Python24\Lib\site-packages" and the "primes" module is available in Python. In your working directory, you can delete the file "primes.c" and the "build" folder created by the building process. Test your new module at the python shell: >>> import primes >>> primes.primes(10) [2, 3, 5, 7, 11, 13, 17, 19, 23, 29] -- http://mail.python.org/mailman/listinfo/python-list
problems installling scipy.weave on windows
Hi, I have problems trying to install the scipy.weave package. I run Python 2.4 on windows XP and my C compiler is MinGW. Below is the output of scipy.weave.test(). I read that the tests should last several minutes, but in my case it only lasts a few seconds. Thanks in advance for any help. Julien Fiore >>> import scipy.weave >>> scipy.weave.test() Found 16 tests for scipy.weave.slice_handler Found 0 tests for scipy.weave.c_spec Found 2 tests for scipy.weave.blitz_tools building extensions here: c:\docume~1\julien~1\locals~1\temp\Julien\python24_compiled\m10 Found 1 tests for scipy.weave.ext_tools Found 74 tests for scipy.weave.size_check Found 9 tests for scipy.weave.build_tools Found 0 tests for scipy.weave.inline_tools Found 1 tests for scipy.weave.ast_tools Found 0 tests for scipy.weave.wx_spec Found 3 tests for scipy.weave.standard_array_spec Found 26 tests for scipy.weave.catalog Found 0 tests for __main__ ...EE..E..EEEE...warning: specified build_dir '_bad_path_' does not exist or is not writable. Trying default locations .warning: specified build_dir '_bad_path_' does not exist or is not writable. Trying default locations removing 'c:\docume~1\julien~1\locals~1\temp\tmpsavufxcat_test' (and everything under it) error removing c:\docume~1\julien~1\locals~1\temp\tmpsavufxcat_test: c:\docume~1\julien~1\locals~1\temp\tmpsavufxcat_test\win3224compiled_catalog: Permission denied error removing c:\docume~1\julien~1\locals~1\temp\tmpsavufxcat_test: c:\docume~1\julien~1\locals~1\temp\tmpsavufxcat_test: Directory not empty .removing 'c:\docume~1\julien~1\locals~1\temp\tmpt-_vddcat_test' (and everything under it) . == ERROR: check_error1 (scipy.weave.size_check.test_size_check.test_dummy_array) -- Traceback (most recent call last): File "C:\Python24\lib\site-packages\scipy\weave\tests\test_size_check.py", line 99, in check_error1 self.generic_error_test(x,y) File "C:\Python24\lib\site-packages\scipy\weave\tests\test_size_check.py", line 134, in generic_error_test self.generic_test('',x,y) File "C:\Python24\lib\site-packages\scipy\weave\tests\test_size_check.py", line 131, in generic_test self.assert_array_equal('',actual,desired) File "C:\Python24\lib\site-packages\scipy\weave\tests\test_size_check.py", line 110, in assert_array_equal assert(actual == desired) File "C:\Python24\lib\site-packages\scipy\weave\size_check.py", line 122, in __cmp__ if len(self.shape) == len(other.shape) == 0: AttributeError: 'tuple' object has no attribute 'shape' == ERROR: check_error2 (scipy.weave.size_check.test_size_check.test_dummy_array) -- Traceback (most recent call last): File "C:\Python24\lib\site-packages\scipy\weave\tests\test_size_check.py", line 102, in check_error2 self.generic_error_test(x,y) File "C:\Python24\lib\site-packages\scipy\weave\tests\test_size_check.py", line 134, in generic_error_test self.generic_test('',x,y) File "C:\Python24\lib\site-packages\scipy\weave\tests\test_size_check.py", line 131, in generic_test self.assert_array_equal('',actual,desired) File "C:\Python24\lib\site-packages\scipy\weave\tests\test_size_check.py", line 110, in assert_array_equal assert(actual == desired) File "C:\Python24\lib\site-packages\scipy\weave\size_check.py", line 122, in __cmp__ if len(self.shape) == len(other.shape) == 0: AttributeError: 'tuple' object has no attribute 'shape' == ERROR: check_1d_3 (scipy.weave.size_check.test_size_check.test_dummy_array_indexing) -- Traceback (most recent call last): File "C:\Python24\lib\site-packages\scipy\weave\tests\test_size_check.py", line 207, in check_1d_3 if nx.which[0] != "numarray": AttributeError: 'module' object has no attribute 'which' == ERROR: check_1d_6 (scipy.weave.size_check.test_size_check.test_dummy_array_indexing) -- Traceback (most recent call last): File "C:\Python24\lib\site-packages\scipy\weave\tests\test_size_check.py", line 214, in check_1d_6 if nx.which[0] != "numarray": AttributeError: 'module' object
Re: Pyrex installation on windows XP: step-by-step guide
To install Pyton, I simply used the python Windows installer (python-2.4.2.msi) available at python.org. Julien -- http://mail.python.org/mailman/listinfo/python-list
Re: Pyrex installation on windows XP: step-by-step guide
Thanks for your remark, Sturlamolden. Is there a free version of the "Visual C++ 2003" compiler available on the web? I have found "Visual C++ 2005 Express edition" (http://msdn.microsoft.com/vstudio/express/visualc/). According to Micrsoft, it replaces VC++2003 (http://msdn.microsoft.com/visualc/vctoolkit2003/). Is VC++2005ee the good compiler to compile a Pyrex module (or any Python extension) ? Does it link with msvcr71.dll ? -- http://mail.python.org/mailman/listinfo/python-list
Re: Pyrex installation on windows XP: step-by-step guide
sturlamolden wrote: > edit the text file "c:\mingw\lib\gcc\mingw32\3.2.4\specs" > and change "-lmsvcrt" to "-lmsvcr71". Thank you very much sturlamolden, This procedure should be added to the "step-by-step" guide (see 1st message of this thread) as "step A.5". For ignorant people like me, CRT = "C runtime library". -- http://mail.python.org/mailman/listinfo/python-list
Re: Pyrex installation on windows XP: step-by-step guide
I added "step A.5" to the guide and published it on the Python wiki, so that anyone can update it easily: http://wiki.python.org/moin/PyrexOnWindows -- http://mail.python.org/mailman/listinfo/python-list
Use of Python with GDAL. How to speed up ?
Hi, I wrote a function to compute openness (a digital elevation model attribute). The function opens the gdal-compatible input raster and reads the values in a square window around each cell. The results are stored in a "1 line buffer". At the end of the line, the buffer is written to the output raster. It runs very slowly and I suspect the raster access to be the main bottleneck. Do you have any idea to speed-up the process ? Thanks for any help. Julien Here is the code: # ## openness.py ## ## Julien Fiore, UNIGE ## ## code inspired by Matthew Perry's "slope.cpp" # import import numpy import gdal from gdal.gdalconst import * # for GA_ReadOnly in gdal.gdal.Open() def openness(infile, outfile, R=1): """ Calculates the openness of a gdal-supported raster DEM. Returns nothing. Parameters: infile: input file (georeferenced raster) outfile: output file (GeoTIF) R: opennness radius (in cells). Window size = (2*R + 1)**2 """ # open inGrid try: inGrid = gdal.gdal.Open(infile, GA_ReadOnly ) except IOError: print 'could not open inGrid' inGridBand = inGrid.GetRasterBand(1) # get raster band # get inGrid parameters geoTrans = inGrid.GetGeoTransform() # returns list (xOrigin,xcellsize,...) cellSizeX = geoTrans[1] cellSizeY = geoTrans[5] nXSize = inGrid.RasterXSize nYSize = inGrid.RasterYSize nullValue = inGridBand.GetNoDataValue() # Create openness output file format = "GTiff" driver = gdal.gdal.GetDriverByName( format ) outGrid=driver.CreateCopy(outfile,inGrid) # Creates output raster with # same properties as input outGridBand = outGrid.GetRasterBand(1) # Access Band 1 outGridBand.SetNoDataValue(nullValue) # moving window winSize= 2*R + 1 # openness buffer array (1 line) buff = inGridBand.ReadAsArray(xoff=0, yoff=0, win_xsize=nXSize, win_ysize=1) # create distance array for Openness dist=numpy.zeros((winSize,winSize),float) for i in range(winSize): for j in range(winSize): dist[i][j]=numpy.sqrt((cellSizeX*(i-R))**2 + (cellSizeY*(j-R))**2) # openness loop for i in range(nYSize): for j in range(nXSize): containsNull = 0 # excludes the edges if (i <= (R-1) or j <= (R-1) or i >= (nYSize-R) or j >= (nXSize-R) ): buff[0][j] = nullValue continue # continues with loop next iteration # read window win = inGridBand.ReadAsArray(j-R, i-R, winSize, winSize) # Check if window has null value for value in numpy.ravel(win): if value == nullValue : containsNull = 1 break # breaks out of the smallest enclosing loop if (containsNull == 1): # write Null value to buffer buff[0][j] = nullValue continue # continues with loop next iteration else: # openness calculation with "tan=opp/adj" # East E=180.0 # 180 = max angle possible between nadir and horizon for k in range(R+1,2*R): angle= 90.0 - numpy.arctan((win[k][R]-win[R][R])/dist[k][R]) if anglehttp://mail.python.org/mailman/listinfo/python-list
Re: Use of Python with GDAL. How to speed up ?
Thanks for the psyco information, Serge. > 2) Rewrite the code to be vectorized (don't use psyco) Right now your > code *doesn't* get any speed benefit from numpy I do not understand this point. How to rewrite the code ? Do you mean in C ? Julien -- http://mail.python.org/mailman/listinfo/python-list
Re: Use of Python with GDAL. How to speed up ?
Thanks Caleb for the advice, I profiled my code with the following lines: import profile, pstats profile.runctx('openness(infile,outfile,R)',globals(),locals(),'profile.log') p = pstats.Stats('profile.log') p.sort_stats('time') p.print_stats(10) The outputs tells me that the openness() function takes most of the time. This is not very useful for me, as openness() contains most of my code. How to know which instructions take most time in the openness function ? Do I have to separate the code into smaller functions ? -- http://mail.python.org/mailman/listinfo/python-list
Re: Use of Python with GDAL. How to speed up ?
Thank you Serge for this generous reply, Vectorized code seems a great choice to compute the distance. If I understand well, vectorized code can only work when you don't need to access the values of the array, but only need to know the indices. This works well for the distance, but I need to access the array values in the openness function. As regards array.array, it seems a bit complicated to reduce all my 2D arrays to 1D arrays because I am working with the gdal library, which works only with 'numeric' arrays. Julien -- http://mail.python.org/mailman/listinfo/python-list