I have single NetCDF file which is time dimension NetCDF file, the netCDF file contains the monthly weather data for 20 years. I want to convert the NetCDF to raster tiff format and output of the raster as same the month and year name. below is code but it's producing the error in line number 29. Time format of the data is YY-MM-DD 2013-01-01 12:00, 2013-02-01 12:00, so on. How to loop all the time dimension.
updated download link for input files: 2013.nc - Google Drive
I tried to extract the layer manually using ArcGIS tool, it's successfully extracted. I have copied the code from ArcGIS
arcpy<SPAN class="punctuation token">.</SPAN>MakeNetCDFRasterLayer_md<SPAN class="punctuation token">(</SPAN>in_netCDF_file<SPAN class="operator token">=</SPAN><SPAN class="string token">"E:/Weather/2002.nc"</SPAN><SPAN class="punctuation token">,</SPAN>
variable<SPAN class="operator token">=</SPAN><SPAN class="string token">"slhf"</SPAN><SPAN class="punctuation token">,</SPAN>
x_dimension<SPAN class="operator token">=</SPAN><SPAN class="string token">"longitude"</SPAN><SPAN class="punctuation token">,</SPAN>
y_dimension<SPAN class="operator token">=</SPAN><SPAN class="string token">"latitude"</SPAN><SPAN class="punctuation token">,</SPAN>
out_raster_layer<SPAN class="operator token">=</SPAN><SPAN class="string token">"sshf_Layer"</SPAN><SPAN class="punctuation token">,</SPAN>
band_dimension<SPAN class="operator token">=</SPAN><SPAN class="string token">""</SPAN><SPAN class="punctuation token">,</SPAN>
dimension_values<SPAN class="operator token">=</SPAN><SPAN class="string token">"time '01-01-2013 12:00:00'"</SPAN><SPAN class="punctuation token">,</SPAN>
value_selection_method<SPAN class="operator token">=</SPAN><SPAN class="string token">"BY_VALUE"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
<SPAN class="comment token"># Import system modules</SPAN>
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="keyword token">from</SPAN> arcpy <SPAN class="keyword token">import</SPAN> env
<SPAN class="keyword token">from</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>sa <SPAN class="keyword token">import</SPAN> <SPAN class="operator token">*</SPAN>
<SPAN class="comment token">#Workspace</SPAN>
outLoc <SPAN class="operator token">=</SPAN> r<SPAN class="string token">"E:\Weather/"</SPAN>
inNetCDF <SPAN class="operator token">=</SPAN> r<SPAN class="string token">"E:\Weather\2002.nc"</SPAN>
<SPAN class="comment token">#Veriable</SPAN>
variable <SPAN class="operator token">=</SPAN> <SPAN class="string token">"slhf"</SPAN>
x_dimension <SPAN class="operator token">=</SPAN> <SPAN class="string token">"lon"</SPAN>
y_dimension <SPAN class="operator token">=</SPAN> <SPAN class="string token">"lat"</SPAN>
band_dimension <SPAN class="operator token">=</SPAN> <SPAN class="string token">""</SPAN>
dimension <SPAN class="operator token">=</SPAN> <SPAN class="string token">"time"</SPAN>
valueSelectionMethod <SPAN class="operator token">=</SPAN> <SPAN class="string token">"BY_VALUE"</SPAN>
nc_FP <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>NetCDFFileProperties<SPAN class="punctuation token">(</SPAN>inNetCDF<SPAN class="punctuation token">)</SPAN>
nc_Dim <SPAN class="operator token">=</SPAN> nc_FP<SPAN class="punctuation token">.</SPAN>getDimensions<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">for</SPAN> dimension <SPAN class="keyword token">in</SPAN> nc_Dim<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">if</SPAN> dimension <SPAN class="operator token">==</SPAN> <SPAN class="string token">"time"</SPAN><SPAN class="punctuation token">:</SPAN>
top <SPAN class="operator token">=</SPAN> nc_FP<SPAN class="punctuation token">.</SPAN>getDimensionSize<SPAN class="punctuation token">(</SPAN>dimension<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">for</SPAN> i <SPAN class="keyword token">in</SPAN> range<SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN> top<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
dimension_values <SPAN class="operator token">=</SPAN> nc_FP<SPAN class="punctuation token">.</SPAN>getDimensionValue<SPAN class="punctuation token">(</SPAN>dimension<SPAN class="punctuation token">,</SPAN> i<SPAN class="punctuation token">)</SPAN>
nowFile <SPAN class="operator token">=</SPAN> str<SPAN class="punctuation token">(</SPAN>dimension_values<SPAN class="punctuation token">)</SPAN>
nowFile <SPAN class="operator token">=</SPAN> nowFile<SPAN class="punctuation token">.</SPAN>translate<SPAN class="punctuation token">(</SPAN>None<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'/'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># I needed after 2013</SPAN>
<SPAN class="keyword token">if</SPAN> int<SPAN class="punctuation token">(</SPAN>nowFile<SPAN class="punctuation token">.</SPAN>split<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>split<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'-'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="operator token">-</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="operator token">==</SPAN><SPAN class="number token">2013</SPAN><SPAN class="punctuation token">:</SPAN>
dv1 <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">"time"</SPAN><SPAN class="punctuation token">,</SPAN> dimension_values<SPAN class="punctuation token">]</SPAN>
dimension_values <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>dv1<SPAN class="punctuation token">]</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>MakeNetCDFRasterLayer_md<SPAN class="punctuation token">(</SPAN>inNetCDF<SPAN class="punctuation token">,</SPAN> variable<SPAN class="punctuation token">,</SPAN> x_dimension<SPAN class="punctuation token">,</SPAN> y_dimension<SPAN class="punctuation token">,</SPAN> nowFile<SPAN class="punctuation token">,</SPAN> band_dimension<SPAN class="punctuation token">,</SPAN> dimension_values<SPAN class="punctuation token">,</SPAN> valueSelectionMethod<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="string token">"success"</SPAN>
outname <SPAN class="operator token">=</SPAN> outLoc <SPAN class="operator token">+</SPAN> nowFile
arcpy<SPAN class="punctuation token">.</SPAN>CopyRaster_management<SPAN class="punctuation token">(</SPAN>nowFile<SPAN class="punctuation token">,</SPAN> outname<SPAN class="punctuation token">,</SPAN><SPAN class="string token">""</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"NONE"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"NONE"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">print</SPAN> <SPAN class="string token">"DATA OUT OF RANGE"</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Error message
ExecuteError<SPAN class="punctuation token">:</SPAN> Failed to execute<SPAN class="punctuation token">.</SPAN> Parameters are <SPAN class="operator token">not</SPAN> valid<SPAN class="punctuation token">.</SPAN>
ERROR <SPAN class="number token">000237</SPAN><SPAN class="punctuation token">:</SPAN> One <SPAN class="operator token">or</SPAN> more dimensions are invalid
ERROR <SPAN class="number token">000237</SPAN><SPAN class="punctuation token">:</SPAN> One <SPAN class="operator token">or</SPAN> more dimensions are invalid
Failed to execute <SPAN class="punctuation token">(</SPAN>MakeNetCDFRasterLayer<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>