I wish to convert files (1000s) from NetCDF4 format to geotiff using an arcpy script. When I try to run the script, I do not see any output and after the fourth file, the python script abborts. Is this a problem with my code? Here is the code:

import arcpy
from arcpy import env
import os,sys
from arcpy.sa import *

arcpy.env.overwriteOutput = 1

env.workspace = inPath
arcpy.env.scratchWorkspace = inPath
nc4List = arcpy.ListFiles('*.NC4')


    var = "precipitation"
    xDim = "lon"
    yDim = "lat"

    for nc4 in nc4List:
        inNetCDFFile = nc4
        outRasterLayer = os.path.join(outPath, nc4.split(".")[1] + ".tif")
        arcpy.MakeNetCDFRasterLayer_md(inNetCDFFile, var, xDim, yDim,outRasterLayer,"","", "BY_VALUE")
        print "Making RasterLayer from ....."+str(nc4)
    print "Done"

    print arcpy.GetMessages()
  • 1
    Try to run the code on a single file step-by-step with the debugger to see the values variables reference to. Then you need to export your raster layer into a raster dataset; can be done with CopyRaster_management. See more gis.stackexchange.com/questions/16715/… – Alex Tereshenkov Nov 25 '16 at 16:52
  • If you remove the try/except what error is revealed? – PolyGeo Nov 25 '16 at 20:35

I think the problem is that you are not completing the parameters of MakeNetCDFRasterLayer tool.

You do not provide the dimension values, you have simply provided "".

So you have provided which variable you want to extract (precipitation) the X and Y but not the "when". I strongly suggest you create a layer using the tool in Arcmap then copy snippet to see the format that you need in python.

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.