nodata option in CopyRaster

351
4
08-19-2013 12:20 PM
MikeKnowles
New Contributor
I'm working with a NETCDF file and am running the following code and the nodata option of the CopyRaster command doesn't appear to be working as I expect.  The CopyRaster successfully creates the raster but in the properties the maximum value is still displayed as the value in the CopyRaster command.  I've also tried entering the 36-digit number instead of the scientific notation and I get the same result.  I'm not sure if it's the large value that's the problem or if I'm overlooking something.

The nc variable I'm working with has the large value for water bodies and the remaining cells between 0-1 (floating point) so if the nodata option worked I'd expect a max <= 1.

import arcpy
from arcpy import env
arcpy.CheckOutExtension("spatial")
from arcpy.sa import *
arcpy.env.overwriteOutput = True

arcpy.env.workspace = r"G:\data\NETCDF"
NetCDFFile = r"G:\data\NETCDF\year.nc"
GDB = r"G:\data\NETCDF\GCM\Hist_Output_Part_Burn4.gdb"
NetCDFFileProp = arcpy.CreateObject("NetCDFFileProperties", NetCDFFile)

##for i in range(0,int(NetCDFFileProp.getDimensionSize("year"))):
for i in range(0,1):
## # convert month from a floating point to an integer (prevents error in naming raster)
 DIMENSION_VALUE = int(NetCDFFileProp.getDimensionValue("year",i))
 print 'Working on Dimension Value: ', DIMENSION_VALUE, '(index ', i, ')'

 # delete existing raster if it exists
 if arcpy.Exists( GDB + "\\" + "year" + str(DIMENSION_VALUE )):
  print '--- deleting ', "year" + str(DIMENSION_VALUE)
  arcpy.Delete_management( GDB + "\\" + "year" + str(DIMENSION_VALUE ))
 # create raster layer from NetCDF file
 arcpy.MakeNetCDFRasterLayer_md(NetCDFFile, "part_burn", "lon", "lat", "year_"+str(i), "", "year " + str(DIMENSION_VALUE))

 # create raster
 arcpy.CopyRaster_management("year_"+str(i), GDB + "\\" + "Hist_PB_"+str(DIMENSION_VALUE+1895), "", "", "9.96921e+036")

 #reclass raster
#Notify when finished
print "Finished!"


Thanks,
Mike
Tags (2)
0 Kudos
4 Replies
markdenil
Occasional Contributor III
Have you tried setting both background_value and nodata_value to the same number?
0 Kudos
MikeKnowles
New Contributor
I made the suggested change but it did not change any interior water bodies, only those that were on the boundary.  I again tried with both the actual and scientific notation numbers.
0 Kudos
markdenil
Occasional Contributor III
If you have Spatial Anayst, you could use Set Null,
but I am guessing that you don't.

You could try exporting using Raster to ASCII
and editing the ascii file by setting the NODATA_VALUE entry
and then using ASCII to raster
to get your raster back.
0 Kudos
MikeKnowles
New Contributor
mdenil, Thank you.  The SetNull option ended up accomplishing what I had wanted.
0 Kudos