Hi All,
I have one NetCDF file, that contain monthly value for the different year (1910 - 2014). I want to extract few years data (e.g 2000 - 2014), date range reading from a csv file and save it as a raster map as the name format of year-month-date. I am working on below script but I am getting error
Below i have attached the csv file which i am using for date range purpose.
Any help would be greatly appreciated! Thanks
The image showing the format of Year-month-date

Error massage
Traceback <SPAN class="punctuation token">(</SPAN>most recent call last<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
File <SPAN class="string token">"<module4>"</SPAN><SPAN class="punctuation token">,</SPAN> line <SPAN class="number token">18</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">in</SPAN> <SPAN class="operator token"><</SPAN>module<SPAN class="operator token">></SPAN>
ValueError<SPAN class="punctuation token">:</SPAN> <SPAN class="string token">'Date'</SPAN> <SPAN class="keyword token">is</SPAN> <SPAN class="operator token">not</SPAN> <SPAN class="keyword token">in</SPAN> list<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Here what i have so far
<SPAN class="keyword token">import</SPAN> os<SPAN class="punctuation token">,</SPAN> sys
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="comment token"># Check out any necessary licenses</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>CheckOutExtension<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"spatial"</SPAN><SPAN class="punctuation token">)</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"># Script arguments</SPAN>
netCDF <SPAN class="operator token">=</SPAN> <SPAN class="string token">"C:\\Users\\Downloads\\SPIE"</SPAN>
rainfall <SPAN class="operator token">=</SPAN> <SPAN class="string token">"C:\\Users\\Downloads\\SPIE\\New folder"</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">=</SPAN> netCDF
<SPAN class="comment token"># Read Date from csv file</SPAN>
eveDate <SPAN class="operator token">=</SPAN> open <SPAN class="punctuation token">(</SPAN><SPAN class="string token">"C:\\Users\\Downloads\\SPIE\\Name1.csv"</SPAN><SPAN class="punctuation token">)</SPAN>
headerLine <SPAN class="operator token">=</SPAN> eveDate<SPAN class="punctuation token">.</SPAN>readline<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
valueList <SPAN class="operator token">=</SPAN> headerLine<SPAN class="punctuation token">.</SPAN>split<SPAN class="punctuation token">(</SPAN><SPAN class="string token">","</SPAN><SPAN class="punctuation token">)</SPAN>
dateValueIndex <SPAN class="operator token">=</SPAN> valueList<SPAN class="punctuation token">.</SPAN>index<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Date"</SPAN><SPAN class="punctuation token">)</SPAN>
eventList <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="keyword token">for</SPAN> line <SPAN class="keyword token">in</SPAN> eveDate<SPAN class="punctuation token">.</SPAN>readlines<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
segmenLine <SPAN class="operator token">=</SPAN> line<SPAN class="punctuation token">.</SPAN>split<SPAN class="punctuation token">(</SPAN><SPAN class="string token">","</SPAN><SPAN class="punctuation token">)</SPAN>
variable <SPAN class="operator token">=</SPAN> <SPAN class="string token">"spei"</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>
<SPAN class="keyword token">for</SPAN> year <SPAN class="keyword token">in</SPAN> range<SPAN class="punctuation token">(</SPAN><SPAN class="number token">2010</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
nc_name <SPAN class="operator token">=</SPAN> <SPAN class="string token">'spei.%d.nc'</SPAN> <SPAN class="operator token">%</SPAN> <SPAN class="punctuation token">(</SPAN>year<SPAN class="punctuation token">,</SPAN><SPAN class="punctuation token">)</SPAN>
valueSelectionMethod <SPAN class="operator token">=</SPAN> <SPAN class="string token">"BY_VALUE"</SPAN>
outFile <SPAN class="operator token">=</SPAN> <SPAN class="string token">"Pre"</SPAN>
<SPAN class="comment token"># extract dimensionValues from csv file</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>MakeNetCDFRasterLayer_md<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"spei.nc"</SPAN><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> outFile<SPAN class="punctuation token">,</SPAN> band_dimension<SPAN class="punctuation token">,</SPAN> segmenLine<SPAN class="punctuation token">[</SPAN>dateValueIndex<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> valueSelectionMethod<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="string token">"layer done"</SPAN>
<SPAN class="comment token">#copy and save as raster tif file</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>CopyRaster_management<SPAN class="punctuation token">(</SPAN>outFile<SPAN class="punctuation token">,</SPAN> rainfall <SPAN class="operator token">+</SPAN> segmenLine<SPAN class="punctuation token">[</SPAN>dateValueIndex<SPAN class="punctuation token">]</SPAN> <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">"raster done"</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>