4

Python 3.4.1, GDAL 1.11.0, OSGEO4W, Windows 7, OSGEO4W Windows Shell

All 64-bit

(ArcGIS is installed as well 10.2 with Python 2.7)

So gdal_translate works fine.

gdal_calc provides perfect outputs but at the end of each process I get the error below. This is a problem as I cannot automate anything due to this pop up error. I hit close and the error goes away, the output file is 100% perfect but then the next gdal_calc line gives me the same error.

This is a sample line of code that gives the error (almost all my gdal_calc commands give the error but not gdal_translate).

gdal_calc.py -A 2000025-2000032.s0481pfv50-sst-16b.hdf.tiff_C.tiff -B C:\temp\QUAL\2000025-2000032.m0481pfv50-qual.hdf.tiffBINARY.tiff  --outfile=A25_32_SSTQUAL4.tiff --calc="A*B"

and this is the error. As I say the process actually works and will continue when I close the error box. After the word DONE appears the error pops up, I close the window and then the next line of code runs, then the error pops up again and so on.

enter image description here

enter image description here

Additional Error message generated

> Problem signature:
  Problem Event Name:   APPCRASH
  Application Name: python.EXE
  Application Version:  0.0.0.0
  Application Timestamp:    5193f3af
  Fault Module Name:    ntdll.dll
  Fault Module Version: 6.1.7601.18247
  Fault Module Timestamp:   521eaf24
  Exception Code:   c0000005
  Exception Offset: 0000000000053290
  OS Version:   6.1.7601.2.1.0.256.48
  Locale ID:    1033
  Additional Information 1: 8c64
  Additional Information 2: 8c64dfac0942d27b36722f7434c64847
  Additional Information 3: e156
  Additional Information 4: e156d5603c95b65c33088aa70929b4be
12
  • How do you call the python script? From a form, toolbox, command line, double click? Jun 13, 2014 at 2:23
  • I just paste the commands as shown into the OSGEO4W window shown above.. I do not per use write any python or use Idle etc. See here, this is what I do gdal.org/gdal_calc.html Jun 13, 2014 at 2:40
  • What's the %path% on the OSGEO4W command? It's possible it's going to the wrong python or using the wrong libraries. Type in set path (no equals) and it will tell you what it is for that window. Jun 13, 2014 at 2:58
  • Path=C:\OSGEO4~1\apps\Python27\Scripts;C:\OSGEO4~1\bin;C:\Windows\system32;C:\Wi ndows;C:\Windows\WBem;C:\OSGEO4~1\apps\msys\bin PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.PY Jun 13, 2014 at 3:08
  • 1
    and the pythonhome environment variable? Jun 13, 2014 at 3:13

2 Answers 2

2

As an extremely heavy-handed, last-ditch-effort approach to this, you can disable the crash dialogs in Windows using the DontShowUI value in the Windows Error Reporting registry keys.

1
2

I have the same error from the OSGEO4W window... It may be that it's a problem with the setup of the environment, something about a library missing when I delve into it:

    from _sre import MAXREPEAT
ImportError: cannot import name MAXREPEAT

However, in a normal command window it works just fine.. I have added GDAL_DATA and other environment variables which are important to get GDAL working in python and I'm using python 2.7 (that came with ArcMap).

Environments variables that GDAL uses:

GDAL_DATA        C:\Program Files\QGIS Dufour\share\gdal
GDAL_DRIVER_PATH C:\Program Files\QGIS Dufour\bin\gdalplugins
GEOTIFF_CSV      C:\Program Files\QGIS Dufour\share\epsg_csv
PROJ_LIB         C:\Program Files\QGIS Dufour\share\proj     

You will have to find these folders in your local system, they should be fairly close.

To automate save your list of python commands with the extension ".bat" and double click. If you aren't comfortable with permanently setting your environment variables then use a format like this:

set GDAL_DATA=C:\Program Files\QGIS Dufour\share\gdal
set GDAL_DRIVER_PATH=C:\Program Files\QGIS Dufour\bin\gdalplugins
set GEOTIFF_CSV=C:\Program Files\QGIS Dufour\share\epsg_csv
set PROJ_LIB=C:\Program Files\QGIS Dufour\share\proj     
gdal_calc.py -A 2000025-2000032.s0481pfv50-sst-16b.hdf.tiff_C.tiff -B C:\temp\QUAL\2000025-2000032.m0481pfv50-qual.hdf.tiffBINARY.tiff  --outfile=A25_32_SSTQUAL4.tiff --calc="A*B"
pause

When saved as a batch file (.bat) and double clicked it will open a command window, run the command and then prompt the user to press enter to continue (exit). The environment settings are not permanent when done this way and only apply to that window. If you are concerned about which version of python is running the code then use set path=<your python path>;%path% to limit the path to just the one version.

In a batch file %A is replaced by %%A, the command processor removes the first %:

set GDAL_DATA=C:\Program Files\QGIS Valmiera\share\gdal
set GDAL_DRIVER_PATH=C:\Program Files\QGIS Valmiera\bin\gdalplugins
set GEOTIFF_CSV=C:\Program Files\QGIS Valmiera\share\epsg_csv
set PROJ_LIB=C:\Program Files\QGIS Valmiera\share\proj
pause
for %%A in ("C:\temp\*.hdf") do gdal_translate -of GTiff -a_srs "+init=epsg:4326" -a_ullr -180 90 180 -90 -co "COMPRESS=PACKBITS" -sds "%%A" "%%A.tiff"
for %%A in ("C:\temp\*.tiff") do gdalinfo "%%A" >>"%%A.txt"
for %%A in ("C:\temp\*.tiff") do gdal_calc.py -A "%%A" --outfile="%%ABINARY.tiff" --calc="0*(A<3)" --calc="1*(A>3)"
for %%A in ("C:\temp\*.tiff") do gdal_calc.py -A "%%A" --outfile="%%A_C.tiff" --calc="A*(0.07500000298)"
gdal_calc.py -A 2000001-2000008.s0481pfv50-sst-16b.hdf.tiff_C.tiff -B C:\temp\2000001-2000008.m0481pfv50-qual.hdf.tiffBINARY.tiff  --outfile=A1_8_SSTQUAL4.tiff --calc="A*B"
gdal_calc.py -A 2000009-2000016.s0481pfv50-sst-16b.hdf.tiff_C.tiff -B C:\temp\2000009-2000016.m0481pfv50-qual.hdf.tiffBINARY.tiff  --outfile=A9_16_SSTQUAL4.tiff --calc="A*B"
gdal_calc.py -A 2000017-2000024.s0481pfv50-sst-16b.hdf.tiff_C.tiff -B C:\temp\2000017-2000024.m0481pfv50-qual.hdf.tiffBINARY.tiff  --outfile=A17_24_SSTQUAL4.tiff --calc="A*B"
gdal_calc.py -A 2000025-2000032.s0481pfv50-sst-16b.hdf.tiff_C.tiff -B C:\temp\2000025-2000032.m0481pfv50-qual.hdf.tiffBINARY.tiff  --outfile=A25_32_SSTQUAL4.tiff --calc="A*B"
gdal_calc.py -A A1_8_SSTQUAL4.tiff -B A9_16_SSTQUAL4.tiff -C A17_24_SSTQUAL4.tiff -D A25_32_SSTQUAL4.tiff --outfile=SST_SUM_C.tiff --calc="A+B+C+D"
gdal_calc.py -A 2000001-2000008.m0481pfv50-qual.hdf.tiffBINARY.tiff -B 2000009-2000016.m0481pfv50-qual.hdf.tiffBINARY.tiff -C 2000017-2000024.m0481pfv50-qual.hdf.tiffBINARY.tiff -D 2000025-2000032.m0481pfv50-qual.hdf.tiffBINARY.tiff  --outfile=QUAL_final.tiff --calc="A+B+C+D"
gdal_calc.py -A SST_SUM_C.tiff -B C:\temp\QUAL_final.tiff  --outfile=SST_Final_C.tiff --calc="A/B"
gdal_translate SST_Final_C.tiff -of GTiff -ot Float32 -a_nodata 0 SST_Final_C_NoData.tiff
gdal_fillnodata SST_Final_C_NoData.tiff -md 5 -si 2 SST_Final_C_NoData_Foc.tiff
for %%A in ("C:\temp\landmask\*.hdf") do gdal_translate -of GTiff -a_srs "+init=epsg:4326" -a_nodata 2 -a_ullr -180 90 180 -90 -co "COMPRESS=PACKBITS" -sds "%%A" "%%A.tiff"
for %%A in ("C:\temp\landmask\*.tiff") do gdal_calc.py -A "%%A" --outfile="%%A_FINAL.tiff"  --calc="1*(A<5)"
gdal_calc.py -A SST_Final_C_NoData_Foc.tiff -B C:\temp\landmask\pfv50_land.m04.hdf.tiff_FINAL.tiff  --outfile=SST.tiff --calc="A*B"
gdal_translate SST.tiff -of GTiff -ot UInt16 -a_nodata 0 -stats -co "COMPRESS=LZW" SST_ALLDONE.tiff
pause
11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.