Python script

566
1
06-08-2013 12:26 AM
WaqasAhmad
New Contributor
Dear Experts,

I am new to this forum and want your help to solve my problem.
I am using ArcGIS 10 and my problem states as:

I have a set of 46 monthly rainfall rasters
1. i want to extract the maximum and minimum pixel value from the the stack of 46 raster as MAX and MIN
2. Then using the equation shown in attached figure [ATTACH=CONFIG]25149[/ATTACH] I have to calculate the cumulative probability of each x
3. where x is each individual raster (total 46)
4. I have already calculated the values of "a" also in the form of a raster and would like the program to pick these values from that respective raster.
5. The summation equation should run from n=1 to n=Max repeatedly

I would highly appreciate of a python expert who writes a few lines script for me to solve this
Tags (2)
0 Kudos
1 Reply
RhettZufelt
MVP Frequent Contributor
One way would be to get raster properties, but, of course, you need to make sure that the raster datasets all have staticstics calculated first.

Not sure if there is a faster way, as getrasterproperties is not the "fastest" method around.

import arcpy


arcpy.env.workspace = "\\\\mcflight01\\MCFlightData\\HGIS\\Data\\imagery.gdb"

rasters = arcpy.ListRasters("*", "All")



for raster in rasters:

      # Process: Get Raster Properties
      min = arcpy.GetRasterProperties_management(raster, "MINIMUM", "")

      # Process: Get Raster Properties (2)
      max = arcpy.GetRasterProperties_management(raster, "MAXIMUM", "")
      print "max for ",str(raster)," = ", max
      print "min for ",str(raster)," = ", min


The above code will list all raster data sets in the workspace, then iterate through them and print out the max/min for each dataset that has statistics.  Might want to run a separate script to calculate the statistics, as it is pretty time intesive, and would not need to be run each time.

You would put the math that you need here where the print statements are, and  it should perform your equation on each raster dataset in the workspace.

R_
0 Kudos