Select to view content in your preferred language

gp.Describe fails on second iteration of loop

1002
5
12-08-2010 06:17 AM
jamessample
Emerging Contributor
Hi all,

I'm having some problems with the gp.Describe method in 9.3.1 and Python 2.5. If anyone can help I'd appreciate it.

I have a folder called "Timeseries_All" which contains sub-folders called "1961", "1962" etc. Each of these folders contains 12 ESRI grids named "rain_year_month" (e.g. rain_1961_7 etc.). I want to get the no-data values for each of these rasters. My simple test code is as follows:

# Import modules
import arcgisscripting, os

# Create geoprocessor
gp = arcgisscripting.create(9.3)

# Set timeseries folder
tsFolder = "D:\Timeseries_All"

for year in range (1961, 1991):
    for month in range(1, 13):
        # Path to raster
        path = os.path.join(tsFolder, str(year), 'rain_' + str(year) + '_' + str(month))

        # Describe and return no-data value
        noDatVal = gp.Describe(path).NoDataValue

        # Print the result
        print noDatVal


This works correctly for the first iteration of the loop and returns the no data value of rain_1961_1 (which is -32768). I get an error on the second iteration, though:

>>> -32768
Traceback (most recent call last):
  File "C:\Python25\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 325, in RunScript
    exec codeObject in __main__.__dict__
  File "D:\James_S\Sarah_Tarland_Burn\Python\NoDataTest.py", line 14, in <module>
    rnNoData = gp.Describe(rnMon).NoDataValue
RuntimeError: DescribeData: Get attribute NoDataValue does not exist


The second dataset is not corrupt: I get the same message regardless of where I start in my data and all of my datasets appear to be fine. Anyone have any suggestions?

Thanks!
Tags (2)
0 Kudos
5 Replies
DanPatterson_Retired
MVP Emeritus
can't comment on the whole problem but this line
tsFolder = "D:\Timeseries_All"

is going to cause problems since Python expects paths to be written as
tsFolder = "D:\\Timeseries_All"   or
tsFolder = r"D:\Timeseries_All"   or
tsFolder = "D:/Timeseries_All"
print it out as well, since you may be missing the required \\ or / in the full path/filename
0 Kudos
RDHarles
Regular Contributor
I don't know anything about rasters, but if it's not bad/empty data, then it must be the path.
I'd recommend printing the path with the value to make sure nothing is going wrong with the loop:

print path+" "+noDatVal
0 Kudos
jamessample
Emerging Contributor
Thanks to both of you for the replies.

I'd forgotten about using the double backslash in my path names - that's definitely a good idea. Luckily, in this case, os.path.join seems to have corrected my mistake for me: it inserted the double slashes into the path automatically and returned a properly formatted string. I've tried making the modifications that you suggest, but I still get the same problem.

I have made some progress since yesterday though: the problem only occurs when I try to get the no data value of an 8-bit or 16-bit unsigned integer grid. It works for everything else. Am I missing something really obvious here? 8- or 16-bit unsigned integer grids can have no data values, right?

If I right-click on one of these grids in ArcCatalog and choose "Properties", it tells me that the no data value is 0. If I try to get this value using gp.Describe(r"PathToGrid").NoDataValue I get this error:

DescribeData: Get attribute NoDataValue does not exist


If I do the same thing for a signed integer grid or a floating point grid the code runs fine and I get the same value as in the ArcCatalog "Properties" window.

Based on this I've 'solved' my problem by adding a try/except block to my code so that if gp.Describe() works I get the correct value, otherwise I assume the no data value is 0. I'm still puzzled as to why it's failing though - is this some really basic "lore of rasters" that's so far eluded me, or is my system being weird?

Thanks again for the suggestions!
0 Kudos
KarenSchleeweis1
New Contributor
Hello,

I have no resolution, but want to report the same problem.  describe.NoDataValue for Raster Band Properties of U16 rasters is not working properly in Python (python2.5 and ArcGis 9.3.1)

I would like to know if any one comes up with a resolution or if this is a bug.

cheers,
Karen
0 Kudos
StephenPage
Emerging Contributor
...and I'll report the same problem! describe.NoDataValue for Raster Band Properties of unsigned 8 bit rasters fails as cited in this thread. (in python 2.5 and ArcGis 9.3) Mine are '.img' (ERDAS) format rather than grid format. Properties in ArcCatalog shows a NoData value of 255

Note that it also fails if the raster doesn't have a NoData value set.

Thanks to all for your posts. I've wasted enough time on this - your posts will save me wasting more time on it! 🙂 Disappointed that no-one from ESRI has answered your questions about whether its a bug, or inherent to these data types!

thanks again,

Steve
0 Kudos