Select to view content in your preferred language

Make NetCDF Raster Layer in Batch Error

519
1
04-17-2012 12:12 PM
AndreaMinano
Deactivated User
Hi,
I have written a script in Python to create NetCDF raster layers:

def Modelling(inPathNetCDF, inPathCov, outPath, concentration):
    netcdfName = os.path.basename(inPathNetCDF).split('.')[0]
    covName = os.path.basename(inPathCov)
    env.workspace = outPath
    netcdfList = netcdfName.split('_')[4]
    modelName = (netcdfName.split('_')[2]).lower()
    dateForTitle = netcdfList[6:8] + netcdfList[4:6] + netcdfList[:4]
    date18Z = netcdfList[6:8] + '/' + netcdfList[4:6] + '/' + netcdfList[:4]
    arcpy.MakeNetCDFRasterLayer_md(inPathNetCDF, 'IceConc', 'lon', 'lat', 'tmpNetCDF18', '', '"time" "%s 6:00:00 PM"' %date18Z, 'BY_VALUE')
    arcpy.CopyRaster_management('tmpNetCDF18', outPath + os.sep + outNetcdfName18Z)

Essentially, the script runs successfully sometimes, but the majority of the time Python completely crashes. I am wondering whether there is a bug with the MakeNetCDFRasterLayer module?
Tags (2)
0 Kudos
1 Reply
PhilMorefield
Frequent Contributor
First things first. When you're asking people to look over code, please use the "CODE" tags. There is a sticky post at the top of this forum called "How to post Python code" that explains how to do this. Also, indentation is very important in Python and if your example isn't displayed correctly, it's impossible for anyone to help you. Is this how your function is supposed to look?

def Modelling(inPathNetCDF, inPathCov, outPath, concentration):
    netcdfName = os.path.basename(inPathNetCDF).split('.')[0]
    covName = os.path.basename(inPathCov)
    env.workspace = outPath
    netcdfList = netcdfName.split('_')[4]
    modelName = (netcdfName.split('_')[2]).lower()
    dateForTitle = netcdfList[6:8] + netcdfList[4:6] + netcdfList[:4]
    date18Z = netcdfList[6:8] + '/' + netcdfList[4:6] + '/' + netcdfList[:4]
    arcpy.MakeNetCDFRasterLayer_md(inPathNetCDF, 'IceConc', 'lon', 'lat', 'tmpNetCDF18', '', '"time" "%s 6:00:00 PM"' %date18Z, 'BY_VALUE')
    arcpy.CopyRaster_management('tmpNetCDF18', outPath + os.sep + outNetcdfName18Z)
0 Kudos