Hi,
I have multiple netCDF files I need to make a "netCDF raster" layer and then "project raster" and save as a ".tif" file. I have the following script but this gives me an error message.
Please see the code and error message below:
Thanks in advance.
<SPAN class="comment token"># Import system modules </SPAN>
<SPAN class="keyword token">import</SPAN> arcpy<SPAN class="punctuation token">,</SPAN> sys
<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"># Input data source </SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">=</SPAN> r<SPAN class="string token">"C:/Users/jayaskeradl/Desktop/weekly_avg_project"</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>overwriteOutput <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">True</SPAN>
<SPAN class="comment token"># Set output folder </SPAN>
OutputFolder <SPAN class="operator token">=</SPAN> r<SPAN class="string token">"C:/Users/jayaskeradl/Desktop/weekly_avg_project/output"</SPAN>
<SPAN class="comment token"># Loop through a list of files in the workspace </SPAN>
NCfiles <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListFiles<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"*.nc"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">for</SPAN> filename <SPAN class="keyword token">in</SPAN> NCfiles<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Processing: "</SPAN> <SPAN class="operator token">+</SPAN> filename<SPAN class="punctuation token">)</SPAN>
inNCfiles <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">+</SPAN> <SPAN class="string token">"//"</SPAN> <SPAN class="operator token">+</SPAN> filename
fileroot <SPAN class="operator token">=</SPAN> filename<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="punctuation token">(</SPAN>len<SPAN class="punctuation token">(</SPAN>filename<SPAN class="punctuation token">)</SPAN><SPAN class="operator token">-</SPAN><SPAN class="number token">3</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">]</SPAN>
TempLayerFile <SPAN class="operator token">=</SPAN> <SPAN class="string token">"SM_amount"</SPAN>
outRaster <SPAN class="operator token">=</SPAN> OutputFolder <SPAN class="operator token">+</SPAN> <SPAN class="string token">"//"</SPAN> <SPAN class="operator token">+</SPAN> fileroot
<SPAN class="comment token"># Process: Make NetCDF Raster Layer </SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>MakeNetCDFRasterLayer_md<SPAN class="punctuation token">(</SPAN>filename<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"var250"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"lon"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"lat"</SPAN><SPAN class="punctuation token">,</SPAN> TempLayerFile<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">"BY_VALUE"</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>ProjectRaster_management<SPAN class="punctuation token">(</SPAN>filename<SPAN class="punctuation token">,</SPAN> TempLayerFile<SPAN class="punctuation token">,</SPAN><SPAN class="string token">"GEOGCS['GCS_North_American_1983',DATUM['D_North_American_1983',SPHEROID['GRS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]]"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"NEAREST"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"0.125 0.125"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"NAD_1983_To_WGS_1984_1"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]]"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Process: Copy Raster </SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>CopyRaster_management<SPAN class="punctuation token">(</SPAN>TempLayerFile<SPAN class="punctuation token">,</SPAN> outRaster <SPAN class="operator token">+</SPAN> <SPAN class="string token">".tif"</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">""</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">print</SPAN> <SPAN class="string token">"***DONE!!!"</SPAN>
<SPAN class="keyword token">print</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetMessages<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
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>
Undefined coordinate system <SPAN class="keyword token">for</SPAN> input dataset<SPAN class="punctuation token">.</SPAN>
Failed to execute <SPAN class="punctuation token">(</SPAN>ProjectRaster<SPAN class="punctuation token">)</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><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>