I have several single band, 32 bit float raster datasets (fgdbr) that i want to use to build a raster stack (depth) in numpy by doing something like this dv = np.dstack((d_array, v_array))

With reference to the code snippet below,

import arcpy
d = r'P:\Sample.gdb\D_0100yr_Max'
dr  = arcpy.Raster(d)
dr.minimum # returns  0.000562695786356926
dr.maximum # returns 2.8690600395202637
dr.noDataValue # prints nothing
dr.pixelType # returns F32

d_array = arcpy.RasterToNumPyArray(dr.catalogPath, "#", "#", "#", dr.noDataValue)

d_array.max() # returns 2.86906
d_array.min() # returns -3.4028231e+38

If dr.noDataValue prints nothing, where does the RasterToNumpyArray function read the no data value from such that d_array.min() returns -3.4028231e+38 ?

enter image description here

  • I think you didn't determine constant value for "NoData" I know in ArcGIS values (usually 0 or -9999) are representing "NoData" therefore the minimum value is correct and you have not any "NoData" in your raster. may be "ndppy" would be helpful, I'm not sure but I hope nasa-develop.github.io/dnppy/index.html – Predator X Nov 15 '16 at 5:51

this is a sample code I found in ESRI Documents. as you see in code, defined a constant value for "NoData"

import arcpy
import numpy

# Get input Raster properties
inRas = arcpy.Raster('C:/data/inRaster')
lowerLeft = arcpy.Point(inRas.extent.XMin,inRas.extent.YMin)
cellSize = ras.meanCellWidth

# Convert Raster to numpy array
arr = arcpy.RasterToNumPyArray(inRas,nodata_to_value=0)

# Calculate percentage of the row for each cell value
arrSum = arr.sum(1)
arrSum.shape = (arr.shape[0],1)
arrPerc = (arr)/arrSum

#Convert Array to raster (keep the origin and cellsize the same as the input)
newRaster = arcpy.NumPyArrayToRaster(arrPerc,lowerLeft,cellSize,

you can find more information in detail here "RasterToNumPyArray"

| improve this answer | |
  • Thanks but that is not quite what I was after. I can explicitly set the no data value as shown in your answer above, but what i want to know is where does the RasterToNumpyArray tool read the value from if you haven't set it explicitly or if it is not stored in the noDataValue property of the raster object: dr.noDataValue – Nxaunxau Nov 15 '16 at 6:24
  • @Nxaunxau some references mentioned nodata is in "metadata" but I found NoData in layer properties in raster information section. – Predator X Nov 15 '16 at 6:51

When you create a raster object dr = arcpy.Raster(d), the file is read "virtually", which provides the descriptive properties of the file, but does not load the underlying array of data in to memory. The no data property and the array are written to the raster band separately, and the array does not have any indication of which values are meant to be no data.

In your case, the raster P:\Sample.gdb\D_0100yr_Max did not have the no data value written to the file at the time of creation, which is why you get None when reading it. When you use the arcpy.RasterToNumPyArray() method, the underlying array of raster data are read into memory, which allows you to see the values.

It appears that you're aware that the minimum value of the array should be the no data value. This is only known by you!

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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