|
POST
|
OK. No error message this time but i cannot see the output.
... View more
08-28-2017
08:12 PM
|
0
|
6
|
2072
|
|
POST
|
Thanks Dan. I have updated the code (Please see the code above) but it is still not doing the job I want. Any idea?
... View more
08-28-2017
07:44 PM
|
0
|
8
|
2072
|
|
POST
|
Hi, I need to calculate the zonal mean (areal precipitation) for grids in a shape file for multiple rasters using a Python script. I have created a script but it gives me an error. Any help is appreciated to fix the issue. Please see the code below. import arcpy
from arcpy import env
from arcpy.sa import *
import os
import arcgisscripting, sys
arcpy.env.overwriteOutput = True
# Set environment settings
env.workspace = "C:/Users/Desktop/KS_All.gdb"
# Make a layer from the feature class
arcpy.MakeFeatureLayer_management("Public_Land_Survey_System", "lyr")
# Write the selected features to a new featureclass
arcpy.CopyFeatures_management("Public_Land_Survey_System", r"C:/Users/Desktop/KS_All.gdb/PLSS_KS_All_WeeklyPr_PRISM_800m_2016_new")
# Set environment settings
arcpy.env.workspace = "H:/PRISM_800m_Daily"
# Set local variables
inPointFeatures = r"C:/Users/Desktop/KS_All.gdb/PLSS_KS_All_WeeklyPr_PRISM_800m_2016_new.shp"
inRasterList = [["Week_1_Avg2016_10.tif", "Oct_PCPwk1"],
["Week_2_Avg2016_10.tif", "Oct_PCPwk2"],
["Week_3_Avg2016_10.tif", "Oct_PCPwk3"],
["Week_4_Avg2016_10.tif", "Oct_PCPwk4"],
["Week_5_Avg2016_10.tif", "Oct_PCPwk5"],
["Week_1_Avg2016_11.tif", "Nov_PCPwk1"],
["Week_2_Avg2016_11.tif", "Nov_PCPwk2"]]
arcpy.CheckOutExtension("Spatial")
zoneField = "S_R_T"
outZonalStatistics = ZonalStatistics(inPointFeatures, zoneField, inRasterList, "MEAN", "DATA")
# Save the output
outZonalStatistics.save("C:/Users/Desktop/KS_All.gdb/zonalstattblout")
fieldName = "YEAR"
expression = "getClass(!YEAR!)"
codeblock = """def getClass(YEAR):
if YEAR >= 1998:
return 2016
else:
return -9999"""
# Execute CalculateField
arcpy.CalculateField_management(inPointFeatures, fieldName, expression, "PYTHON_9.3", codeblock)
... View more
08-28-2017
02:30 PM
|
0
|
10
|
3532
|
|
POST
|
Thanks again. Weeks should be defined by the Julian day of the year. Please take a look at my revised code above. Hope you can understand. For example, if year is 1998 then September 01 to September 06 (Julian days are from 243 to 249. I need to revised my above code if I have all the files in one folder (Test_ONLY). My code above does the job but I need to change years and month after each run and replace the files in the Test_ONLY folder for the corresponding year. I would like to place all the files (From 1998 to 2016) in Test_ONLY folder and automate the process above. Hope this helps to understand.
... View more
08-13-2017
01:05 PM
|
0
|
1
|
1961
|
|
POST
|
Thanks Xander for the reply. The starting day does not matter for me. I just need to take the average for the weekly definition. For the week 5 it should take the remaining day for that month to average it. Let's say for the month of February it should take day 25 to 28 and average it. If it is a leap year up to 29. If the month is August 25 to 31 and for September 25 to 30 etc. I do not mind which day it starts Monday or Sunday. This week definition is defined with particular interest for the project I work on.
... View more
08-13-2017
11:03 AM
|
0
|
3
|
1961
|
|
POST
|
Thanks Ian for the reply. The file names are as follows: prism_ppt_us_30s_19980101.bil prism_ppt_us_30s_19980102.bil prism_ppt_us_30s_19980103.bil . . prism_ppt_us_30s_19981231.bil These files are in H:/Test_ONLY folder. I have years from 1998 to 2016. Hope this helps.
... View more
08-11-2017
03:04 PM
|
0
|
7
|
1961
|
|
POST
|
Hi, I have multiple rasters named as follows for each year. But, I need to calculate mean for weekly ONLY for 09, 10 and 11 months based on the following week definition. Week 1: Day 01, 02, 03, 04, 05, 06 Week 2: Day 07, 08, 09, 10, 11, 12 Week 3: Day 13, 14, 15, 16, 17, 18 Week 4: Day 19, 20, 21, 22, 23, 24 Week 5: Day 25, 26, 27, 28, 29, 30, 31 Can anybody suggest me a way to process months 9, 10 and 11 in one go for the following script.? Thanks in advance, import arcpy
import arcpy.sa
from arcpy.sa import *
from arcpy import env
import os
arcpy.CheckOutExtension("Spatial")
arcpy.OverwriteOutput = True
arcpy.env.workspace = r'H:\Test_ONLY'
scratch = r'H:\Test_ONLY\scratch'
year = 1998
month = 01
fmaskrasters = arcpy.ListRasters()
fmaskrasters.sort()
if year % 4 > 0 and month == 9:
fmaskrasters1 = fmaskrasters[243:249]
fmaskrasters2 = fmaskrasters[249:255]
fmaskrasters3 = fmaskrasters[255:261]
fmaskrasters4 = fmaskrasters[261:267]
fmaskrasters5 = fmaskrasters[267:273]
elif year % 4 == 0 and month == 9:
fmaskrasters1 = fmaskrasters[244:250]
fmaskrasters2 = fmaskrasters[250:256]
fmaskrasters3 = fmaskrasters[256:262]
fmaskrasters4 = fmaskrasters[262:268]
fmaskrasters5 = fmaskrasters[268:274]
elif year % 4 > 0 and month == 10:
fmaskrasters1 = fmaskrasters[273:279]
fmaskrasters2 = fmaskrasters[279:285]
fmaskrasters3 = fmaskrasters[285:291]
fmaskrasters4 = fmaskrasters[291:297]
fmaskrasters5 = fmaskrasters[297:304]
elif year % 4 == 0 and month == 10:
fmaskrasters1 = fmaskrasters[274:280]
fmaskrasters2 = fmaskrasters[280:286]
fmaskrasters3 = fmaskrasters[286:292]
fmaskrasters4 = fmaskrasters[292:298]
fmaskrasters5 = fmaskrasters[298:305]
elif year % 4 > 0 and month == 11:
fmaskrasters1 = fmaskrasters[304:310]
fmaskrasters2 = fmaskrasters[310:316]
fmaskrasters3 = fmaskrasters[316:322]
fmaskrasters4 = fmaskrasters[322:328]
fmaskrasters5 = fmaskrasters[328:334]
elif year % 4 == 0 and month == 11:
fmaskrasters1 = fmaskrasters[305:311]
fmaskrasters2 = fmaskrasters[311:317]
fmaskrasters3 = fmaskrasters[317:323]
fmaskrasters4 = fmaskrasters[323:329]
fmaskrasters5 = fmaskrasters[329:335]
else:
print("Not configured in the script!")
number = len(fmaskrasters)
# Week 1
finras1 = scratch + "\\" + "Week_1_Avg" + str(year) + "_" + str(month) + ".tif"
calc1 = arcpy.sa.CellStatistics([fmaskrasters1], statistics_type = "MEAN")
arcpy.CopyRaster_management(calc1,finras1,"","","","","","32_BIT_FLOAT")
# Week 2
finras2 = scratch + "\\" + "Week_2_Avg" + str(year) + "_" + str(month) + ".tif"
calc2 = arcpy.sa.CellStatistics([fmaskrasters2], statistics_type = "MEAN")
arcpy.CopyRaster_management(calc2,finras2,"","","","","","32_BIT_FLOAT")
# Week 3
finras3 = scratch + "\\" + "Week_3_Avg" + str(year) + "_" + str(month) + ".tif"
calc3 = arcpy.sa.CellStatistics([fmaskrasters3], statistics_type = "MEAN")
arcpy.CopyRaster_management(calc3,finras3,"","","","","","32_BIT_FLOAT")
# Week 4
finras4 = scratch + "\\" + "Week_4_Avg" + str(year) + "_" + str(month) + ".tif"
calc4 = arcpy.sa.CellStatistics([fmaskrasters4], statistics_type = "MEAN")
arcpy.CopyRaster_management(calc4,finras4,"","","","","","32_BIT_FLOAT")
# Week 5
finras5 = scratch + "\\" + "Week_5_Avg" + str(year) + "_" + str(month) + ".tif"
calc5 = arcpy.sa.CellStatistics([fmaskrasters5], statistics_type = "MEAN")
arcpy.CopyRaster_management(calc5,finras5,"","","","","","32_BIT_FLOAT")
... View more
08-10-2017
01:23 PM
|
0
|
9
|
2548
|
|
POST
|
The script in Pro creates the progress as 45% of the tif files but actually it doe not produce 45% of the tif files. I does the job manually in ArcGIS Pro.
... View more
08-02-2017
06:58 AM
|
0
|
0
|
815
|
|
POST
|
What do you mean by manually in ArcGIS Pro? I have imported the python script and ran it in Pro version.
... View more
08-01-2017
12:12 PM
|
0
|
2
|
815
|
|
POST
|
Hi, I have a python script that works fine with ArcMap 10.4.1 version and read some comments on how to modify to suit to run with ArcGIS Pro version using "arcpy.AnalyzeToolsForPro_management" tool. After doing some modifications to the script I ran it in ArcGIS PRO but initially it worked fine and showed the progress up to 45% and it does not progress after 45% and remains in the same position for a long time. I did it several times and it does not complete running the script. Basically, it converts to process netCDF file to extract a data variable, then project it and save it a .tif file. This process repeats for about 180 netCDF files. The original script works fine in ArcMap 10.4.1 version without any problem. Any comments or suggestions of what might be happening. Thanks.
... View more
08-01-2017
11:41 AM
|
0
|
4
|
1258
|
|
POST
|
Thanks a bunch again. I made it work. What you suggested was correct. I made the changes and it's correctly projecting the files. Thanks a lot again.
... View more
07-26-2017
02:32 PM
|
0
|
0
|
2201
|
|
POST
|
OK. Thanks again for taking your time and reply. I was able to export to the model builder to obtain the projection string as you can see in the code. I ran the model and it still gives me an error saying that "Undefined coordinate system for input dataset". The input file is a netCDF file which does not have projection information. How can i solve this problem and make the script running.? Please see the attached sample of netCDF files I am using. Thanks and appreciate your help again.
... View more
07-26-2017
01:38 PM
|
0
|
2
|
2201
|
|
POST
|
Thanks again Ian. I have tried what you mentioned in the above comment. (Please see the code and errors above). I would like to know how I can copy the string representation of a coordinate system using the model builder as you noted in 3rd bullet. I have opened the properties of the raster of same coordinate system but it does not provide string representation of a coordinate system. See the image below. Again your help is highly appreciated to make the script working and moving forward.
... View more
07-26-2017
10:52 AM
|
0
|
4
|
2201
|
|
POST
|
Thanks Ian. I appreciate your reply. I have considered your comments and modified in the script. (Please see the script and error above). My code still does not work. I get a different error now. I really appreciate if you can help me the script working. Thanks a lot again.
... View more
07-26-2017
09:42 AM
|
0
|
6
|
2201
|
|
POST
|
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. # Import system modules
import arcpy, sys
from arcpy import env
from arcpy.sa import *
# Input data source
arcpy.env.workspace = r"C:/Users/jayaskeradl/Desktop/weekly_avg_project"
arcpy.env.overwriteOutput = True
# Set output folder
OutputFolder = r"C:/Users/jayaskeradl/Desktop/weekly_avg_project/output"
# Loop through a list of files in the workspace
NCfiles = arcpy.ListFiles("*.nc")
for filename in NCfiles:
print("Processing: " + filename)
inNCfiles = arcpy.env.workspace + "//" + filename
fileroot = filename[0:(len(filename)-3)]
TempLayerFile = "SM_amount"
outRaster = OutputFolder + "//" + fileroot
# Process: Make NetCDF Raster Layer
arcpy.MakeNetCDFRasterLayer_md(filename, "var250", "lon", "lat", TempLayerFile, "", "", "BY_VALUE")
arcpy.ProjectRaster_management(filename, TempLayerFile,"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]]", "NEAREST", "0.125 0.125", "NAD_1983_To_WGS_1984_1", "", "GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]]")
# Process: Copy Raster
arcpy.CopyRaster_management(TempLayerFile, outRaster + ".tif", "", "", "", "NONE", "NONE", "")
print "***DONE!!!"
print arcpy.GetMessages()
ExecuteError: Failed to execute. Parameters are not valid.
Undefined coordinate system for input dataset.
Failed to execute (ProjectRaster).
... View more
07-26-2017
08:23 AM
|
0
|
8
|
2921
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 01-23-2015 04:00 PM | |
| 1 | 01-29-2015 04:14 PM | |
| 1 | 01-30-2015 12:59 PM | |
| 1 | 02-03-2015 12:04 PM | |
| 2 | 10-09-2017 09:41 AM |
| Online Status |
Offline
|
| Date Last Visited |
11-11-2020
02:23 AM
|