|
POST
|
Thank you. Output raster i am trying to save in tif format. I am getting following error massage. Message File Name Line Position
Traceback
<module> D:\Arc-GIS-Python-Script\NetCDF_RASTER_TIME_SERIES.py 30
IndexError: string index out of range
... View more
09-11-2016
11:58 PM
|
1
|
4
|
2564
|
|
POST
|
I have single netCDF file which contain monthly data for different year. (Format of date e.g 2001-1-1, 2001-2-1, 2001-3-1…….2002-12-1...............2015-0-1......2015-12-1). Here-with i have attached a snapshot of data format from Arc GIS multidimension tool I trying to extract each month raster for selected year (e.g only 2002). Save it as 01-2002, 02-2002, 03-2002…..12-2002. I appreciate any help you can provide on the crucial bottom code. Here is what I have so far: # Import system modules
import arcpy
from arcpy import env
from arcpy.sa import *
#Workspace
outLoc = r"D:\MODIS_NPP_02_15"
inNetCDF = r"D:\MODIS_NPP_02_15\NPP_2001_15.nc"
#Veriable
variable = "npp"
x_dimension = "lon"
y_dimension = "lat"
band_dimension = ""
dimension = "time"
valueSelectionMethod = "BY_VALUE"
nc_FP = arcpy.NetCDFFileProperties(inNetCDF)
nc_Dim = nc_FP.getDimensions()
for dimension in nc_Dim:
if dimension == "time":
top = nc_FP.getDimensionSize(dimension)
for i in range(0, top):
dimension_values = nc_FP.getDimensionValue(dimension, i)
nowFile = str(dimension_values)
nowFile = nowFile.translate(None, '/')
# I needed only the years 2002
if int(nowFile[-12]) > 6:
dv1 = ["time", dimension_values]
dimension_values = [dv1]
arcpy.MakeNetCDFRasterLayer_md(inNetCDF, variable, x_dimension, y_dimension, nowFile, band_dimension, dimension_values, valueSelectionMethod)
print "success"
outname = outLoc + nowFile
arcpy.CopyRaster_management(nowFile, outname, +".tif","", "", "", "NONE", "NONE", "")
else: print "DATA OUT OF RANGE"
... View more
09-11-2016
10:18 PM
|
0
|
13
|
5258
|
|
POST
|
FC Basson, yes exactly ,Good suggestion , i have added the line
... View more
09-06-2016
08:11 AM
|
0
|
0
|
996
|
|
POST
|
FC Basson. Thank you very much. Code perfectly working
... View more
09-06-2016
02:42 AM
|
0
|
1
|
996
|
|
POST
|
I having trouble to save raster statistics value into csv or text format. Below is my working code. Below code only print the raster statistics value, but i am interested to save the output value to text or csv format. I appreciate any help you can provide on the crucial bottom code. Thank you import arcpy
arcpy.env.workspace = r"D:\2008A"
rasterList = arcpy.ListRasters()
for raster in rasterList:
rasterObj = arcpy.Raster(raster)
print raster
bands = arcpy.GetRasterProperties_management(raster, "MEAN")
print "MEAN VALUE: %s" %bands
bands = arcpy.GetRasterProperties_management(raster, "STD")
print "STANDARD DEV: %s" %bands
bands = arcpy.GetRasterProperties_management(raster, "MINIMUM")
print "MIN VALUE: %s" %bands
bands = arcpy.GetRasterProperties_management(raster, "MAXIMUM")
print "Max VALUE: %s" %bands
... View more
09-06-2016
02:01 AM
|
0
|
4
|
2043
|
|
POST
|
jskinner-esristaff. I found the reason of error. Actually in between OCTOBER and SEPTEMBER, there were one another file. I deleted it and rerun the program. Now program runs perfectly. Thank you very much for your kind cooperation.
... View more
09-02-2016
09:42 AM
|
0
|
0
|
959
|
|
POST
|
Jake Skinner. Thank you. I ran the code except SEPTEMBER month all months are calculating correctly. While it execute on month of SEPTEMBER, its showing error massage. Traceback (most recent call last):
File "<module1>", line 23, in <module>
IndexError: list index out of range
... View more
09-02-2016
08:13 AM
|
0
|
1
|
959
|
|
POST
|
Hi Jake, Thank you. i have replaced the line but still same issue. there is no output. Actually earlier whatever CSV we converted to point shape for month wise, then we merged it and save it in different month's folder. Now using above programme i just want to make a loop function that program can take automatically point shape file from different month folder to perform IDW, and save it as same month folder along with month number and Z filed name (e.g. For JANUARY: 001_Max_Temper, 001_Min_Temper, 001_Wind, 001_Precipitat, 002_Relative_H, 001_Solar, For FEBRUARY: 002_Max_Temper, 002_Min_Temper, 002_Wind, 002_Precipitat, 002_Relative_H, 002_Solar) Below i have attached a reference vector. Kindly find it.
... View more
09-02-2016
05:28 AM
|
0
|
3
|
959
|
|
POST
|
xander_bakker, Thank you. Now code perfectly running
... View more
09-02-2016
04:59 AM
|
0
|
1
|
1084
|
|
POST
|
Hi Jake, Thank you . I am running the code on Pyscripter. I have updated my code, there is nothing error with my code, but i am not getting any output raster from IDW, below is my updated code. Whats the possible error import arcpy, os, calendar
from arcpy import env
from arcpy.sa import *
arcpy.CheckOutExtension("Spatial")
topWorkspace = r'D:\NPP_GUJARAT\WEATHER_DATA1\2011'
arcpy.env.workspace = topWorkspace
# Get dict of months and month-number (i.e. January = 001, March = 003 etc.)
months = {calendar.month_name[i].upper(): str(i).zfill(3) for i in range(1, 13)} # Get dict of months and month number (i.e. January = 001, March = 003 etc.)
# Step through list of all folders
for folderPath in arcpy.ListWorkspaces():
baseName = os.path.basename(folderPath).upper()
if baseName in months: # Test that subfolder is a month name
monthNumber = months[baseName] # Get month-number for use in output filename
arcpy.env.workspace = folderPath
#Loop every month folder ta take shape file from each month (e.g. Merged_001 (JANUARY), Merged_002 (FEBRUARY)....Merged_012 (DECEMBER))
shapeFiles = arcpy.ListFeatureClasses('Merged_{}*.shp')
zFields = ["Max_Temper", "Min_Temper", "Precipitat", "Wind", "Relative_H", "Solar"]
# IDW variable
cellSize = 0.002298707671
power = 2
searchRadius = RadiusVariable(10, 150000)
#Mask region of interest
mask="D:\Gujarta Shape file\GUJARATSTATE.shp"
for shape_num in shapeFiles:
Zfield_num = arcpy.ListFeatureClasses(os.path.join(folderPath, shape_num))
# Execute IDW
for zField in zFields:
outIDW = Idw(shapeFiles, zField, cellSize, power, searchRadius)
# Execute Mask
IDWMASk = ExtractByMask(outIDW, mask)
if not zField == "Solar":
# Save output, except Solar Radiation raster (e.g for JANUARY:001_Max_Temper, FEBRUARY:002_Max_Temper)
out_name_IDW = os.path.join(topWorkspace, '(months)_.TIF'.format(zField_num))
IDWMASk.save(out_name_IDW)
else:
#Only for Solar Radiation raster
PAR = (IDWMASk * 30) * 0.5
#Save output, Only for Solar Radiation raster
out_name_IDW = os.path.join(topWorkspace, '(months)_.TIF'.format(zField))
PAR.save(out_name_IDW)
#print done
print 'done'
... View more
09-02-2016
01:36 AM
|
0
|
1
|
1593
|
|
POST
|
Xander Bakker, In just trying to modify above code, instead of multiplying 0.98, i just want to replace it by constant raster , below is my updated code. but its not working, i tried both line to replace 0.98 by constant raster.
ras_LUE = getRaster(D:\MOD-REF\NDVI\LUE-CASA.img)
ras_LUE = arcpy.raster (D:\MOD-REF\NDVI\LUE-CASA.img) for ras_num in [str(i).zfill(3) for i in range(1, 13)]:
# get required rasters for current month number
ras_APAR = getRasterFromList(ras_num, lst_ras_APAR, ws_in_apar)
ras_TSCALAR = getRasterFromList(ras_num, lst_ras_TSCALAR, ws_in_tscalar)
ras_WSCALAR = getRasterFromList(ras_num, lst_ras_WSCALAR, ws_in_wscalar)
#ras_LUE
# verify if raster are valid
if all([not ras_APAR is None, not ras_TSCALAR is None, not ras_WSCALAR is None]):
# 0.98 will replace by constant raster (ras_LUE)
ras_NPP = (ras_APAR * ras_TSCALAR * ras_WSCALAR * 0.98)
... View more
09-01-2016
08:25 PM
|
0
|
1
|
1084
|
|
POST
|
Jake Skinner, I am trying to solve the above script problem, but i am getting continue error. Error displaying IndentationError
unexpected indent (IDW_PAR_Year_WISE.py, line 10) How to resolve the issue. Thanks
... View more
09-01-2016
10:44 AM
|
0
|
3
|
1593
|
|
POST
|
xander_bakker. Excellent. A totally new work i learned from you. Thank you very much
... View more
09-01-2016
07:51 AM
|
0
|
0
|
295
|
|
POST
|
Hi Jake,I am trying to modify above code, as keep it IDW function same, But instead of giving path for every month shape file , I just trying to use loop function that program can automatic take shape file from different month folder (Name of point shape file in different month folder : JANUARY: Merged_001, FEBRUARY: Merged_002.....DECEMBER: Merged_012 ) and save as it same folder along with month number and Z field name (e.g for JANUARY : 001_Max_Temper, 001_Min_Temper, 001_Precipitat, FEBRUARY : 002_Max_Temper, 002_Min_Temper, 002_Precipitatetc.) . Below is my working code. But its showing error. import arcpy, os, calendar
arcpy.CheckOutExtension("Spatial")
topWorkspace = r'D:\NPP_GUJARAT\WEATHER_DATA\2011'
arcpy.env.workspace = topWorkspace
# Get dict of months and month-number (i.e. January = 001, March = 003 etc.)
months = {calendar.month_name[i].upper(): str(i).zfill(3) for i in range(1, 13)} # Get dict of months and month number (i.e. January = 001, March = 003 etc.)
# Step through list of all folders
for folderPath in arcpy.ListWorkspaces():
baseName = os.path.basename(folderPath).upper()
if baseName in months: # Test that subfolder is a month name
monthNumber = months[baseName] # Get month-number for use in output filename
arcpy.env.workspace = folderPath
#Loop every month folder ta take shape file from each month (e.g. Merged_001 (JANUARY), Merged_002 (FEBRUARY)....Merged_012 (DECEMBER))
shapeFiles = arcpy.ListFeatureClasses('*Merged_{}.shp')
zFields = ["Max_Temper", "Min_Temper", "Precipitat", "Wind", "Relative_H", "Solar"]
# IDW variable
cellSize = 0.002298707671
power = 2
searchRadius = RadiusVariable(10, 150000)
#Mask region of interest
mask="D:\Gujarta Shape file\GUJARATSTATE.shp"
for shape_num in shapeFiles:
Zfield_num = arcpy.ListFeatureClasses(os.path.join(folderPath, shape_num))
# Execute IDW
for zField in zFields:
outIDW = Idw(shapeFiles, zField, cellSize, power, searchRadius)
# Execute Mask
IDWMASk = ExtractByMask(outIDW, mask)
if not zField == "Solar":
# Save output, except Solar Radiation raster (e.g for JANUARY:001_Max_Temper, FEBRUARY:002_Max_Temper)
out_name_IDW = os.path.join(topWorkspace, '(months)_.TIF'.format(zField_num))
IDWMASk.save(out_name_IDW)
else:
#Only for Solar Radiation raster
PAR = (IDWMASk * 30) * 0.5
#Save output, Only for Solar Radiation raster
out_name_IDW = os.path.join(topWorkspace, '(months)_.TIF'.format(zField))
PAR.save(out_name_IDW)
#print done
print 'done'
... View more
09-01-2016
05:40 AM
|
0
|
4
|
1593
|
|
POST
|
Thank you. I am trying to do it. I am also not sure Multi-plot facility in Arc GIS has or not. I am taking suggestion from other developer also. Hopefully problem would be be resolve. Which snapshot i have attached, there i have added 3 data frame for reference purpose only. similarly i want to add total 12 raster into one frame and export it to pdf format.
... View more
09-01-2016
04:23 AM
|
0
|
1
|
2544
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 02-01-2017 09:56 PM | |
| 1 | 01-19-2017 08:03 AM | |
| 1 | 07-31-2017 11:57 AM | |
| 1 | 08-25-2016 09:38 AM | |
| 1 | 08-17-2016 11:13 AM |
| Online Status |
Offline
|
| Date Last Visited |
11-11-2020
02:25 AM
|