I have single netCDF file which contain monthly data for different year. (Format of date e.g 2001-1-1, 2001-2-1, 2001-3-1…….2002-12-1...............2015-0-1......2015-12-1).
Here-with i have attached a snapshot of data format from Arc GIS multidimension tool
I trying to extract each month raster for selected year (e.g only 2002). Save it as 01-2002, 02-2002, 03-2002…..12-2002.
I appreciate any help you can provide on the crucial bottom code.
Here is what I have so far:
import arcpy
from arcpy import env
from arcpy.sa import *
outLoc = r"D:\MODIS_NPP_02_15"
inNetCDF = r"D:\MODIS_NPP_02_15\NPP_2001_15.nc"
variable = "npp"
x_dimension = "lon"
y_dimension = "lat"
band_dimension = ""
dimension = "time"
valueSelectionMethod = "BY_VALUE"
nc_FP = arcpy.NetCDFFileProperties(inNetCDF)
nc_Dim = nc_FP.getDimensions()
for dimension in nc_Dim:
if dimension == "time":
top = nc_FP.getDimensionSize(dimension)
for i in range(0, top):
dimension_values = nc_FP.getDimensionValue(dimension, i)
nowFile = str(dimension_values)
nowFile = nowFile.translate(None, '/')
if int(nowFile[-12]) > 6:
dv1 = ["time", dimension_values]
dimension_values = [dv1]
arcpy.MakeNetCDFRasterLayer_md(inNetCDF, variable, x_dimension, y_dimension, nowFile, band_dimension, dimension_values, valueSelectionMethod)
print "success"
outname = outLoc + nowFile
arcpy.CopyRaster_management(nowFile, outname, +".tif","", "", "", "NONE", "NONE", "")
else: print "DATA OUT OF RANGE"