#Convert NetCDF files to Imagine img files #Jason Geck jgeck@alaskapacific.edu #Make a separate raster *.img file for each dimension value (time) in a netcdf file # 2012.07.03 Modified by Sergio Bernardes/Chris Strother import arcpy, os, time, datetime, calendar # Set local variables arcpy.env.overwriteOutput = True arcpy.env.scratchWorkspace = "C:\\Scratch\\" path = "C:\\PRCP\\" path_rasters = "C:\\PRCPRasters\\" extension = ".nc" dirList=os.listdir(path) #Loops thru all days of year (including leap days) #Year info Yr = range (1982,2008) #Month info allmnths = range(1,13) for fname in dirList: if fname.lower().endswith(extension): tile, Yr, datatype = fname.split("_") intYr = int(Yr) #print tile, yr, datatype for mnths in allmnths: Lastday = calendar.monthrange(intYr, mnths)[1] MRange = range(1,Lastday+1) for dyy in MRange: dyys =int(dyy) mnthsss = int(mnths) yrs = int(Yr) stringMonth = str(mnthsss) stringDays = str(dyys) a = stringMonth.zfill(2) + "/" + stringDays.zfill(3)+"/"+Yr b = stringMonth.zfill(2) + "_" + stringDays.zfill(3) +"_"+Yr print a,b inDate = "time " + a prcp_nc = path + fname prcp_Layer = "prcp_Layer" + b test_img = path_rasters + tile + "_" + b + ".img" # Process: Make NetCDF Raster Layer arcpy.MakeNetCDFRasterLayer_md(prcp_nc, "prcp", "x", "y", prcp_Layer, "", inDate, "BY_VALUE") print "Created NetCDF Layer for " + prcp_Layer # Process: Copy Raster arcpy.CopyRaster_management(prcp_Layer, test_img, "", "", "", "NONE", "NONE", "") print "Created Raster for " + prcp_Layer print "------------- finished"
Solved! Go to Solution.
#Convert NetCDF files to Imagine img files #Jason Geck jgeck@alaskapacific.edu #Make a separate raster *.img file for each dimension value (time) in a netcdf file # 2012.07.03 Modified by Sergio Bernardes/Chris Strother import arcpy, os, time, datetime, calendar, traceback, sys # Set local variables arcpy.env.overwriteOutput = True arcpy.env.scratchWorkspace = "C:\\Scratch\\" path = "C:\\PRCP\\" path_rasters = "C:\\PRCPRasters\\" extension = ".nc" dirList=os.listdir(path) #Loops thru all days of year (including leap days) #Year info Yr = range (1982,2008) #Month info allmnths = range(1,13) try: for fname in dirList: if fname.lower().endswith(extension): tile, Yr, datatype = fname.split("_") intYr = int(Yr) #print tile, yr, datatype for mnths in allmnths: Lastday = calendar.monthrange(intYr, mnths)[1] MRange = range(1,Lastday+1) for dyy in MRange: dyys =int(dyy) mnthsss = int(mnths) yrs = int(Yr) stringMonth = str(mnthsss) stringDays = str(dyys) a = stringMonth.zfill(2) + "/" + stringDays.zfill(3)+"/"+Yr b = stringMonth.zfill(2) + "_" + stringDays.zfill(3) +"_"+Yr print a,b inDate = "time " + a prcp_nc = path + fname prcp_Layer = "prcp_Layer" + b test_img = path_rasters + tile + "_" + b + ".img" # Process: Make NetCDF Raster Layer arcpy.MakeNetCDFRasterLayer_md(prcp_nc, "prcp", "x", "y", prcp_Layer, "", [["time", inDate]], "BY_VALUE") print "Created NetCDF Layer for " + prcp_Layer temp = arcpy.Raster(prcp_Layer) temp.save(test_img) arcpy.Delete_management(prcp_Layer) del temp # Process: Copy Raster # arcpy.CopyRaster_management(prcp_Layer, test_img, "", "", "", "NONE", "NONE", "") print "Created Raster for " + prcp_Layer print "------------- finished" except: tbinfo = traceback.format_tb(sys.exc_info()[2]) print "Traceback Info:\n" for item in tbinfo: print item + "\n" print "Error Info:\n{0}: {1}\n".format(sys.exc_type, sys.exc_value)
How large are your netCDF files? Unless they are extremely resolved spatially, I doubt it's a memory problem.
If you don't find anything there, pin down what line is throwing the error. Are any output files being produced and, if so, are they correct?
#Convert NetCDF files to Imagine img files #Jason Geck jgeck@alaskapacific.edu #Make a separate raster *.img file for each dimension value (time) in a netcdf file # 2012.07.03 Modified by Sergio Bernardes/Chris Strother import arcpy, os, time, datetime, calendar, traceback, sys # Set local variables arcpy.env.overwriteOutput = True arcpy.env.scratchWorkspace = "C:\\Scratch\\" path = "C:\\PRCP\\" path_rasters = "C:\\PRCPRasters\\" extension = ".nc" dirList=os.listdir(path) #Loops thru all days of year (including leap days) #Year info Yr = range (1982,2008) #Month info allmnths = range(1,13) try: for fname in dirList: if fname.lower().endswith(extension): tile, Yr, datatype = fname.split("_") intYr = int(Yr) #print tile, yr, datatype for mnths in allmnths: Lastday = calendar.monthrange(intYr, mnths)[1] MRange = range(1,Lastday+1) for dyy in MRange: dyys =int(dyy) mnthsss = int(mnths) yrs = int(Yr) stringMonth = str(mnthsss) stringDays = str(dyys) a = stringMonth.zfill(2) + "/" + stringDays.zfill(3)+"/"+Yr b = stringMonth.zfill(2) + "_" + stringDays.zfill(3) +"_"+Yr print a,b inDate = "time " + a prcp_nc = path + fname prcp_Layer = "prcp_Layer" + b test_img = path_rasters + tile + "_" + b + ".img" # Process: Make NetCDF Raster Layer arcpy.MakeNetCDFRasterLayer_md(prcp_nc, "prcp", "x", "y", prcp_Layer, "", [["time", inDate]], "BY_VALUE") print "Created NetCDF Layer for " + prcp_Layer temp = arcpy.Raster(prcp_Layer) temp.save(test_img) arcpy.Delete_management(prcp_Layer) del temp # Process: Copy Raster # arcpy.CopyRaster_management(prcp_Layer, test_img, "", "", "", "NONE", "NONE", "") print "Created Raster for " + prcp_Layer print "------------- finished" except: tbinfo = traceback.format_tb(sys.exc_info()[2]) print "Traceback Info:\n" for item in tbinfo: print item + "\n" print "Error Info:\n{0}: {1}\n".format(sys.exc_type, sys.exc_value)