POST
|
You are genius. I got the trick now. Thanks a bunch.
... View more
10-26-2017
06:55 AM
|
0
|
2
|
1388
|
POST
|
Thanks Xander for sharing this. I have tried the code below but it does not gives me the zonal mean statistics for all the S_R_T in the County_Grid shape file. But it does provide for some of the grids. I have no clue why it does not produce the zonal mean for all the S_R_Ts. I appreciate if If some one can help me to figure this out. Thanks a lot again. import arcpy, os, arcinfo from arcpy import env from arcpy.sa import * arcpy.env.overwriteOutput = True arcpy.CheckOutExtension("Spatial") env.workspace = "H:/outRaster/Rasters" # Select the shapefile containing the polygons to use as boundaries # for zonal statistics watershedFeat = "H:/outRaster/Grid/County_Grid.shp" # Select output folder for saving the output - zonal tables (.dbf files) outDir = "H:/Table/" x = arcpy.ListRasters() for raster in arcpy.ListRasters(): #[0:] raster_name = os.path.basename(raster).rstrip(os.path.splitext(raster)[1]) outTable = outDir + raster_name + "_TBL.dbf" arcpy.gp.ZonalStatisticsAsTable(watershedFeat,"S_R_T", raster, outTable,"NODATA","MEAN") arcpy.CheckInExtension("Spatial")
... View more
10-26-2017
06:47 AM
|
0
|
3
|
1225
|
POST
|
I used "R{}".format(int(!mtrs![11:13])) but I am not able to get the East "E" or "W" letter attached like R1E or R18W.
... View more
10-25-2017
03:00 PM
|
0
|
4
|
1388
|
POST
|
Apologies for the late reply. Your answers were very helpful. Is there a way I can extract RANGE using the "mtrs" column?
... View more
10-25-2017
02:16 PM
|
0
|
6
|
1388
|
POST
|
Thanks Dan. Yes I figured and it worked. I am a beginner to Python.
... View more
10-12-2017
02:12 PM
|
0
|
8
|
1388
|
POST
|
Hi, I have the following attribute table. I need to update the fields using the field calculator (SEC, TOWN, RANG) by using the "mtrs" and "label" columns(fields) in the attribute table. SEC: (letter S + label) TOWN: (string from mtrs) RANGE (string from mtrs) S_R_T (join the SEC+TOWN+RANG) S24 T1N R14W S24-T1N-R14W S4 T1N R14W S24-T1N-R14W S34 T2S R8W S34-T2S-R8W . . Can somebody help me to achieve this using the "Field Calculator" and Python parser functions? Thanks a lot in advance.
... View more
10-09-2017
09:41 AM
|
2
|
11
|
2530
|
POST
|
Randy, Thanks again. That is the output I want exactly but I would revise the last line like below. But, how can i modify the above code? print "\tH:\\PRISM_800m_weekly_sum_Normal\\{}\\Week_{}_Sum{}_{}.tif".format(year, week, year, month)
... View more
09-15-2017
12:06 PM
|
0
|
3
|
830
|
POST
|
Thanks Randy for the reply. I have revised my code and posted above. There is no error now and producing outputs but the output values are NOT correct. I am doing something wrong here. I have folders names "1981", "1982"....."2016" in "H:\PRISM_800m_weekly_sum_Normal" and each folder (year) has Weekly .tif files (for example Week_1_Sum1981_9.tif, Week_2_Sum1981_9.tif, ...., Week_5_Sum1981_9.tif,.....Week_5_Sum1981_9.tif) for the months from 9 to 11. Can you help me to fix this? Thanks in advance.
... View more
09-15-2017
09:00 AM
|
0
|
5
|
830
|
POST
|
Hi, I am trying to calculate the average using multiple rasters using years from 1981 to 2016. For example, average for week 1 for the month of 9 from years 1981 to 2016 is as follows: Normal_Week_1_1981_2016_9.tif =average [Week_1_Sum1981_9.tif . . Week_1_Sum2016_9.tif] My following code outputs all the tif files at the "out" path but at the end it gives me the error below. What I am doing wrong here.? Just noticed the output raster values are also wrong. Any help is appreciated. Thanks in advance. arcpy.CheckOutExtension("Spatial")
arcpy.OverwriteOutput = True
years = [1981,1982,1983,1984,1985,1986,1987,1988,1989,1990,1991,1992,1993,1994,1995,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016]
out = r'H:\PRISM_800m_weekly_sum\Normal_out'
path = r'H:\PRISM_800m_weekly_sum_Normal'
lstFiles = []
for root, dirs, files in os.walk(path):
arcpy.env.workspace = root
files = arcpy.ListRasters("*", "TIF")
for file in files:
(filename, extension) = os.path.splitext(file)
if(extension == ".tif"):
lstFiles.append(os.path.join(root, file))
print (lstFiles)
new_list1=[]
new_list2=[]
new_list3=[]
new_list4=[]
new_list5=[]
months=[9,10,11]
for month in months:
for file in lstFiles:
if fnmatch.fnmatch(file, "H:\\PRISM_800m_weekly_sum_Normal" + "*" + "\\" + "Week_1" + "_*_" + str(month) + ".tif"):
new_list1.append(file)
new_list1.sort()
print (new_list1)
env.workspace = out
finras1 = out + "\\" + "Normal_Week_1" + "_1981_2016" + "_" + str(month) + ".tif"
calc1 = arcpy.sa.CellStatistics(new_list1, statistics_type = "MEAN")
arcpy.CopyRaster_management(calc1,finras1,"","","","","","32_BIT_FLOAT")
for file in lstFiles:
if fnmatch.fnmatch(file, "H:\\PRISM_800m_weekly_sum_Normal" + "*" + "\\" + "Week_2" + "_*_" + str(month) + ".tif"):
new_list2.append(file)
new_list2.sort()
print (new_list2)
env.workspace = out
finras2 = out + "\\" + "Normal_Week_2" + "_1981_2016" + "_" + str(month) + ".tif"
calc2 = arcpy.sa.CellStatistics(new_list2, statistics_type = "MEAN")
arcpy.CopyRaster_management(calc2,finras2,"","","","","","32_BIT_FLOAT")
for file in lstFiles:
if fnmatch.fnmatch(file, "H:\\PRISM_800m_weekly_sum_Normal" + "*" + "\\" + "Week_3" + "_*_" + str(month) + ".tif"):
new_list3.append(file)
new_list3.sort()
print (new_list3)
env.workspace = out
finras3 = out + "\\" + "Normal_Week_3" + "_1981_2016" + "_" + str(month) + ".tif"
calc3 = arcpy.sa.CellStatistics(new_list3, statistics_type = "MEAN")
arcpy.CopyRaster_management(calc3,finras3,"","","","","","32_BIT_FLOAT")
for file in lstFiles:
if fnmatch.fnmatch(file, "H:\\PRISM_800m_weekly_sum_Normal" + "*" + "\\" + "Week_4" + "_*_" + str(month) + ".tif"):
new_list4.append(file)
new_list4.sort()
print (new_list4)
env.workspace = out
finras4 = out + "\\" + "Normal_Week_4" + "_1981_2016" + "_" + str(month) + ".tif"
calc4 = arcpy.sa.CellStatistics(new_list4, statistics_type = "MEAN")
arcpy.CopyRaster_management(calc4,finras4,"","","","","","32_BIT_FLOAT")
for file in lstFiles:
if fnmatch.fnmatch(file, "H:\\PRISM_800m_weekly_sum_Normal" + "*" + "\\" + "Week_5" + "_*_" + str(month) + ".tif"):
new_list5.append(file)
new_list5.sort()
print (new_list5)
env.workspace = out
finras5 = out + "\\" + "Normal_Week_5" + "_1981_2016" + "_" + str(month) + ".tif"
calc5 = arcpy.sa.CellStatistics(new_list5, statistics_type = "MEAN")
arcpy.CopyRaster_management(calc5,finras5,"","","","","","32_BIT_FLOAT")
... View more
09-14-2017
07:36 AM
|
0
|
8
|
1098
|
POST
|
Dan, I have revised the code below but still getting a error. Traceback (most recent call last):
File "C:\Users\jayaskeradl\Desktop\Arkansas Flood\My_Phyton_Scripts\Raster_Normal_US.py", line 63, in <module>
calc1 = CellStatistics(new_list, "MEAN","DATA")
File "c:\program files (x86)\arcgis\desktop10.4\arcpy\arcpy\sa\Functions.py", line 3116, in CellStatistics
ignore_nodata)
File "c:\program files (x86)\arcgis\desktop10.4\arcpy\arcpy\sa\Utils.py", line 53, in swapper
result = wrapper(*args, **kwargs)
File "c:\program files (x86)\arcgis\desktop10.4\arcpy\arcpy\sa\Functions.py", line 3112, in Wrapper
[function] + Utils.flattenLists(in_rasters_or_constants))
RuntimeError: ERROR 999998: Unexpected Error.
Failed to execute (RasterNormalUS). out = r'H:\PRISM_800m_weekly_sum\Normal_out'
new_list = []
for file in lstFiles:
for month in months:
for week in weeks:
if fnmatch.fnmatch(file, 'Week_' + str(week) + '_*_' + str(month) + '.tif'):
new_list.append(file)
calc1 = CellStatistics(new_list, "MEAN","DATA")
calc1.save(out + "\\" + "Normal_Week_" + str(week) + "_1981_2016" + "_" + str(month) + ".tif")
... View more
09-14-2017
06:39 AM
|
0
|
2
|
2169
|
POST
|
Thanks a lot again. Dan. I am facing another problem when I am trying the estimate the mean of cell and save it as .tif file. Below is my code. years = [1981,1982,1983]
months = [9,10,11]
weeks = [1,2,3,4,5]
out = r'H:\PRISM_800m_weekly_sum\Normal_out'
new_list = []
for file in lstFiles:
for month in months:
for week in weeks:
if fnmatch.fnmatch(file, 'Week_' + str(week) + '_*_' + str(month) + '.tif'):
new_list.append(file)
finras1 = out + "\\" + "Normal_Week_" + str(week) + "_1981_2016" + "_" + str(month) + ".tif"
calc1 = arcpy.sa.CellStatistics([new_list], statistics_type = "MEAN",ignore_nodata="DATA")
arcpy.CopyRaster_management(calc1,finras1,"","","","","","32_BIT_FLOAT") Error: Traceback (most recent call last):
File "C:\Users\jayaskeradl\Desktop\Arkansas Flood\My_Phyton_Scripts\Raster_Normal_US.py", line 61, in <module>
calc1 = arcpy.sa.CellStatistics([new_list], statistics_type = "MEAN",ignore_nodata="DATA")
File "c:\program files (x86)\arcgis\desktop10.4\arcpy\arcpy\sa\Functions.py", line 3116, in CellStatistics
ignore_nodata)
File "c:\program files (x86)\arcgis\desktop10.4\arcpy\arcpy\sa\Utils.py", line 53, in swapper
result = wrapper(*args, **kwargs)
File "c:\program files (x86)\arcgis\desktop10.4\arcpy\arcpy\sa\Functions.py", line 3112, in Wrapper
[function] + Utils.flattenLists(in_rasters_or_constants))
RuntimeError: ERROR 999998: Unexpected Error.
... View more
09-13-2017
08:51 PM
|
0
|
4
|
2169
|
POST
|
Dan, Now I need to read files from the above list "lstFiles". For example, I need to read and store rasters from the "lstFiles" and store in a different raster list. My code below print all the files I need to store but how can I store the below list in a raster list. Thanks again. week=5
month=10
for file in lstFiles:
if fnmatch.fnmatch(file, 'Week_' + str(week) + '_*_' + str(month) + '.tif'):
print (file)
Week_5_Sum1981_10.tif
Week_5_Sum1982_10.tif
Week_5_Sum1983_10.tif
Week_5_Sum1984_10.tif
Week_5_Sum1985_10.tif
Week_5_Sum1986_10.tif
Week_5_Sum1987_10.tif
Week_5_Sum1988_10.tif
Week_5_Sum1989_10.tif
Week_5_Sum1990_10.tif
Week_5_Sum1991_10.tif
Week_5_Sum1992_10.tif
Week_5_Sum1993_10.tif
Week_5_Sum1994_10.tif
Week_5_Sum1995_10.tif
Week_5_Sum1996_10.tif
Week_5_Sum1997_10.tif
Week_5_Sum1998_10.tif
Week_5_Sum1999_10.tif
Week_5_Sum2000_10.tif
Week_5_Sum2001_10.tif
Week_5_Sum2002_10.tif
Week_5_Sum2003_10.tif
Week_5_Sum2004_10.tif
Week_5_Sum2005_10.tif
Week_5_Sum2006_10.tif
Week_5_Sum2007_10.tif
Week_5_Sum2008_10.tif
Week_5_Sum2009_10.tif
Week_5_Sum2010_10.tif
Week_5_Sum2011_10.tif
Week_5_Sum2012_10.tif
Week_5_Sum2013_10.tif
Week_5_Sum2014_10.tif
Week_5_Sum2015_10.tif
Week_5_Sum2016_10.tif
... View more
09-13-2017
06:30 PM
|
0
|
6
|
2169
|
POST
|
Thanks a bunch Dan. It helps. New to python and learning day by day.
... View more
09-13-2017
11:55 AM
|
0
|
8
|
2169
|
Title | Kudos | Posted |
---|---|---|
1 | 02-03-2015 12:04 PM | |
1 | 01-23-2015 04:00 PM | |
1 | 01-29-2015 04:14 PM | |
1 | 01-30-2015 12:59 PM | |
2 | 10-09-2017 09:41 AM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|