Evan, <div><br></div><div>Thanks for the info. Setting debug to on has allowed me to trace the problem to this line:</div><div><br></div><div>scanBlock = band.ReadAsArray(h,i,numberColumns, numberRows).astype(numpy.float)</div>
<div><br></div><div>showing this error / information:</div><div><br></div><div><div><div>C:\Py_Scripts\RunningSD>python ISCopy.py P01_001468_1534_XI_26S034W.jp2 -vus 5</div><div>JPEG2000: IHDR box found. Dump: width=9973, height=34577, numcmpts=1, bpp=8</div>
<div>JPEG2000: Component 0: bpp=8, signedness=0</div><div>GDALJP2Metadata: Got projection from GeoJP2 (geotiff) box: PROJCS["Mars_Equidistant_Cylindrical_Sphere",GEOGCS["GCS_Mars_Sphere",DATUM["Mars_Sphere",SPHEROID["Mars_Spher</div>
<div>METER["standard_parallel_1",0],PARAMETER["false_easting",0],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]]]</div><div>GDAL: GDALOpen(P01_001468_1534_XI_26S034W.jp2, this=034E8230) succeeds as JPEG2000.</div>
<div>GDAL: QuietDelete(output.tif) invoking Delete()</div><div>GDAL: GDALOpen(output.tif, this=01D5F260) succeeds as GTiff.</div><div>GDAL: GDALDefaultOverviews::OverviewScan()</div><div>GDAL: GDALClose(output.tif, this=01D5F260)</div>
<div>GDAL: GDALDriver::Create(GTiff,output.tif,9973,34577,1,Byte,00000000)</div><div>Processing band: 1</div><div>error: cannot decode code stream</div><div>JPEG2000: Unable to decode image. Format: jp2, 4</div><div>Traceback (most recent call last):</div>
<div> File "ISCopy.py", line 357, in <module></div><div> main()</div><div> File "ISCopy.py", line 343, in main</div><div> perform_stretch(dataset,outdataset,**options.__dict__)</div><div>
File "ISCopy.py", line 235, in perform_stretch</div><div> input_array = normalize(input_array, bandMin, bandMax)</div><div> File "ISCopy.py", line 52, in normalize</div><div> inputBand -= bandMin</div>
<div> File "C:\Python26\ArcGIS10.0\lib\site-packages\numpy\ma\core.py", line 3698, in __isub__</div><div> ndarray.__isub__(self._data, np.where(self._mask, 0, getdata(other)))</div><div>TypeError: unsupported operand type(s) for -: 'NoneType' and 'float'</div>
<div>GDAL: GDALClose(P01_001468_1534_XI_26S034W.jp2, this=034E8230)</div><div>GDAL: GDALClose(output.tif, this=01D5F260)</div><div>GDAL: GDALDeregister_GTiff() called.</div></div><div><br></div><div>Removing "astype" solves the attribute error, but the line is still returning "None" when it should be returning an array. Entering gdal_translate in the command line without arguments shows that:</div>
<div><br></div><div><div>The following format drivers are configured and support output:</div><div> ECW: ERDAS Compressed Wavelets (SDK 3.x)</div><div> JP2ECW: ERDAS JPEG2000 (SDK 3.x)</div></div><div><br></div><div>Using "gdal.GetDriverByName("JPEG2000").Deregister()" to unload the JPEG2000 driver results in this error:</div>
<div><br></div><div>RuntimeError: `P01_001468_1534_XI_26S034W.jp2' not recognised as a supported file format.</div><div><br></div><div>The ECW driver was downloaded and installed from gisinternals last evening.</div><div>
<br></div><div>I have a sample JP2 that is 28MB zipped. What is the best way to get that to you? I can upload it to a webspace and get you the link if that is easiest.</div><div><br></div><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
Not sure to follow you. What is the "fast" method for getting the min/max ?<br>band.ComputeRasterMinMax(False) ?</blockquote><div><br></div><div>I had found that band.GetMinimum() and band.GetMaximum(), which processed quite quickly, often returned "None" is statistics had not already been calculated for the raster. Using band.ComputeRasterMinMax(), while slower, always allowed me to get a value. Is there a better way to get the band Min/Max?</div>
<div><br></div><div>Many thanks, </div><div>Jay</div><div> </div><br><div class="gmail_quote">On Sat, Jul 30, 2011 at 9:12 AM, Even Rouault <span dir="ltr"><<a href="mailto:even.rouault@mines-paris.org">even.rouault@mines-paris.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Le samedi 30 juillet 2011 17:37:48, Jay L. a écrit :<br>
<div class="im">> Morning all,<br>
><br>
> I have a rather large JP2 file (created using the Kakadu driver I believe)<br>
> that I am trying to process with a python script. I am able to open the<br>
> dataset and grab the first band.<br>
><br>
> To calculate band statistics I use the following code which returns 1000<br>
> lines of error before exiting<br>
><br>
> def get_band_stats(band):<br>
> NDV = band.GetNoDataValue()<br>
> bandMin = band.GetMinimum()<br>
> bandMax = band.GetMaximum()<br>
> if bandMin is None or bandMax is None:<br>
> #Approx has to be set to false to ensure that an accurate Min/Max<br>
> are calculated...<br>
> (bandMin, bandMax) = band.ComputeRasterMinMax(False)<br>
> return NDV, bandMin, bandMax<br>
><br>
> ....<br>
> ERROR 1: IReadBlock failed at X offset 20, Y offset 25<br>
> ERROR 1: IReadBlock failed at X offset 21, Y offset 25<br>
> ....<br>
><br>
> This cuts off after 1000 lines.<br>
><br>
> Commenting out the if statement, thereby using the "fast" method for<br>
> getting the min/max returns the following error:<br>
><br>
> error: cannot decode code stream<br>
> ERROR 1: IReadBlock failed at X offset 0, Y offset 0<br>
> ERROR 1: GetBlockRef failed at X block offset 0, Y block offset 0<br>
<br>
</div>Not sure to follow you. What is the "fast" method for getting the min/max ?<br>
band.ComputeRasterMinMax(False) ?<br>
<br>
Did you try running with CPL_DEBUG=ON defined as an environment variable to<br>
check which driver is used and if there are other interesting warnings ?<br>
<div class="im"><br>
><br>
> Finally, using gdalinfo I see that the image is being opened with the<br>
> ECWJP2000 driver. I am also able to calculate statistics without a problem<br>
> and the returned values are within the expected range.<br>
<br>
</div>Hum, strange, ComputeRasterMinMax() and ComputeRasterStatistics() are very<br>
silmilar : they use the same way of fetching the data, so I'd assume that if<br>
one works, the other one would too.<br>
<div class="im"><br>
> I am also able to<br>
> use gdal_translate to convert these to .tif prior to processing, but I<br>
> would rather avoid this method. Do I need to alter my code to work with<br>
> JP2 as they are compressed?<br>
<br>
</div>Theroretically no. If it doesn't work, it's a defect of the driver. Could you<br>
share your JP2 file ?<br>
<div class="im"><br>
><br>
> Can I implicitly define the driver to be used with JP2 within my python<br>
> code without performing the unload all / load what I want method?<br>
<br>
</div>You can unload a driver this way :<br>
gdal.GetDriverByName("short_name_of_driver").Deregister()<br>
<br>
><br>
> Many thanks,<br>
> Jay<br>
</blockquote></div><br></div>