Select to view content in your preferred language

Conversion multiple Raster to NetCDF using Arcpy

6028
24
Jump to solution
01-18-2017 10:24 PM
ShouvikJha
Occasional Contributor III

Dear all,

I have multiples raster files, i am trying to convert it in NetCDF file using Arcpy script . below script i am using for conversion. While  i ran the below script , i am getting the error, 

Below i have attached my raster file also, which i trying to convert in NetCDF format. 

Error Code 

ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000840: The value is not a Raster Layer.
ERROR 000840: The value is not a Raster Catalog.
Failed to execute (RasterToNetCDF).‍‍‍‍

Below script i am using for conversion of raster to NetCDF. 

import arcpy
from arcpy import env

# Set environment settings
env.workspace = "D:\2012A"

# Set local variables
inRaster = "D:\2012A"
outNetCDFFile = "D:\2012A/nppnetcdf.nc"
variable = "NPP"
units = "gCSqm"
XDimension = "x"
YDimension = "y"
bandDimension = ""

# Process: RasterToNetCDF
arcpy.RasterToNetCDF_md(inRaster, outNetCDFFile, variable, units,
                        XDimension, YDimension, bandDimension)‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
Tags (2)
0 Kudos
24 Replies
ShouvikJha
Occasional Contributor III

Dan PattersonXander Bakker‌, Sorry for the late reply. I was out of station.

Thank you very much. Script is perfect working. 

Xander Bakker‌ As you mentioned the UNIT seems to be invalid, Actually I tried to assign the unit my own "gram carbon per square meter (gcsqm) " Howover it's not taking as a valid UNIT so I changed it to  "Gram" now it's working perfectly. 

xander_bakker i  have one more request, can we convert those NetCDF as a time dimension single NetCDF ?

Once again thanks to all for your valuable contribution to solve the issue.  

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi shouvik jha , I'm glad you could solve the unit problem. 

Not sure if ArcGIS can do this be default, but maybe the netCDF4 module could help:

netCDF4 API documentation 

DanPatterson_Retired
MVP Emeritus

I think it is in the conda distribution for ArcGIS PRO... but I would have to check

BennyIstanto
New Contributor II

Dear Xander Bakker

Sorry to open this thread again.

Let say all the input file has date information in filename ie. r001_NPP_YYYY.MM.tif

From your script, is it possible to make the time dimension enabled based on date in the filename when saving into netCDF?

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi Benny Istanto ,

To be honest, I don't see any option in the "arcpy.RasterToNetCDF_md" tool to allow this. Perhaps using the "band_dimension" parameter in combination with the "fields_to_dimensions" parameter you could do something, but I am not sure.

0 Kudos