I have daily GRIB data which I want to extract their subdataset and convert the result to .tif files. I wrote a code in python but I received this erroe:
"Traceback (most recent call last):
File "D:/NASA/Data/SPoRT LIS/Extract-subdata.py", line 24, in <module>
for raster in rasterList:
TypeError: 'NoneType' object is not iterable"
What is my code's problem? Your help is really appreciated.
# Import arcpy module
import arcpy
# Load required toolboxes
arcpy.ImportToolbox("Model Functions")
# Script arguments
LIS_HIST_201601010000_d01_grb = arcpy.GetParameterAsText(0)
if LIS_HIST_201601010000_d01_grb == '#' or not LIS_HIST_201601010000_d01_grb:
LIS_HIST_201601010000_d01_grb = "D:\\NASA\\Data\\SPoRT LIS\\201601\\LIS_HIST_201601050000.d01.grb" # provide a default value if unspecified
v_Name__tif = arcpy.GetParameterAsText(1)
if v_Name__tif == '#' or not v_Name__tif:
v_Name__tif = "D:\\NASA\\Data\\SPoRT LIS\\Output\\%Name%.tif" # provide a default value if unspecified
# Local variables:
v201601 = "D:\\NASA\\Data\\SPoRT LIS\\201601"
Subdataset_ID = "3"
Name = "LIS_HIST_201601050000.d01.grb"
# Process: Iterate Rasters
arcpy.IterateRasters_mb(v201601, "", "", "NOT_RECURSIVE")
# Process: Extract Subdataset
arcpy.ExtractSubDataset_management(LIS_HIST_201601010000_d01_grb, v_Name__tif, Subdataset_ID)
Hint: check out https://community.esri.com/people/curtvprice/blog/2014/09/25/posting-code-blocks-in-the-new-geonet?s... to help with syntax and spacing, and so other can respond with line numbers.
I'm not familiar with grb format, but add a few print statements in your code to make sure your variables are being set correctly. If I assuming
v_Name__tif = arcpy.GetParameterAsText(1)
wasn't set, and instead set it manually,
v_Name__tif = "D:\\NASA\\Data\\SPoRT LIS\\Output\\%Name%.tif"
print(v_Name__tif)
D:\NASA\Data\SPoRT LIS\Output\%Name%.tif
You have a path with %Name% in it. I'm assuming that is not what you want, and maybe you are trying to substitute another variable in there? You should also try to avoid spaces and other special characters in path names