POST
|
Back again, Dan. I have the attached histogram out now. I am working with a smaller AOI/subset of the original raster. I have also delimited the lower bound to the min val in the array, and set the upper bound using a 'where' statement as you have suggested (1.25 st dev * mean). I assume if I set the lower bound to an artificial value with (mean - (1.25 * st dev)) and there are no data values it may create empty bins? I would prefer to have all bins populated. By the looks of the histogram above, it might also be beneficial to have a separate zero-only bin. Not sure if that can be implemented and still retain the other 20 bin ranges. stds = [arr_min, arr_max] new_Arr = np.where((testImage_arr < stds[0]) | (testImage_arr > stds[1]), 0, testImage_arr) Printing the new np.histogram array yields this: (array([226603, 939, 1265, 1468, 1548, 1474, 1537, 1492, 1463, 1341, 1365, 1291, 1203, 1159, 1079, 1041, 1027, 967, 889, 849]), array([ 0. , 0.00114019, 0.00228038, 0.00342057, 0.00456075, 0.00570094, 0.00684113, 0.00798132, 0.00912151, 0.0102617 , 0.01140189, 0.01254207, 0.01368226, 0.01482245, 0.01596264, 0.01710283, 0.01824302, 0.0193832 , 0.02052339, 0.02166358, 0.02280377])) I think this looks pretty good, but I now need to get only the counts out into a new array that I can plot. A final format might look something like this (generated in Excel using random numbers). Is there a simple way to grab the count portion only and convert that to plot as a new histogram? Thanks.
... View more
12-09-2016
11:27 AM
|
0
|
1
|
1008
|
POST
|
Sorry, I took that to be like a conditional statement, whereby everything within the brackets would be set to the image values in the array, and everything excluded would be set to -1 (null). In your array you seem to keep the values outside the required range and set everything inside the range to -1. Clearly I had the syntax/logic all wrong. Thanks. It would help if I read the entire post instead of missing your final sentence. Seems I would want this usage: new_Arr = np.where((testImage_arr < stds[0]) | (testImage_arr > stds[1]), -1, testImage_arr)
... View more
12-02-2016
11:24 AM
|
0
|
3
|
1008
|
POST
|
Thanks Dan. Yes, lots of reading still to do on Numpy. I must be missing something here because it still isn't working properly. #Set Environment import arcpy from arcpy.sa import * from arcpy import env import numpy as np import sys, os, string, glob import matplotlib.pyplot as plt arcpy.CheckOutExtension("spatial") arcpy.env.overwriteOutput = True #Identify a test raster testImage = arcpy.Raster(r"F:\GIS_Dev\RCM_VAPs_Validate\0Comparisons\RS2_SQ28_SLC\freeman\reports\gamma_dbl_clip.tif") #Convert Raster to Numpy Array - raster is 1677 columns x 7155 rows, floating point 32 bit testImage_arr = arcpy.RasterToNumPyArray(testImage,lowerLeft,1677,7155, nodata_to_value=0) #Set some variables for stats calculations sdFact = 2.5 nb_Classes = 20 #Calculate the min, max, mean and standard deviation of the array testImage_min = np.min(testImage_arr) testImage_max = np.max(testImage_arr) testImage_mean = np.mean(testImage_arr) testImage_std = np.std(testImage_arr) #Calculate a min and max based on sdFact, mean, and sdev arr_min = (testImage_mean - (sdFact/2) * testImage_std) arr_max = (testImage_mean + (sdFact/2) * testImage_std) arr_range = arr_max - arr_min print arr_range stds = [arr_min, arr_max] print stds new_Arr = np.where((testImage_arr > stds[0]) | (testImage_arr < stds[1]), testImage_arr, -1) plt.hist(new_Arr, bins=nb_Classes) plt.title("Histogram") plt.xlabel("Value") plt.ylabel("Count") plt.grid(True) plt.show() This yields the attached graph, which seems to include all values in the original raster, and not only the masked range. The histogram is compressed to the low end and we want to expose greater detail here by binning the desired range (arr_range = 0.00555599341169) across 20 bins. For the test raster: min = 0 max = 0.349763 mean = 8.98602e-05 st dev = 0.0022224
... View more
12-02-2016
09:05 AM
|
0
|
5
|
1008
|
POST
|
So I have the array from the input raster. Is there an efficient way to define the range I want based on mean and st dev? We would like only values that fall 1.25 st dev on either side of the mean. I found the numpy.clip function but it seems to reset data values above and below the specified min/max thresholds to those thresholds and what I need is to eliminate those values completely. I have extracted the mean and st dev from the original array as follows (sdFact previously defined as 2.5): #Calculate the min, max, mean and standard deviation of the array testImage_min = np.min(testImage_arr) testImage_max = np.max(testImage_arr) testImage_mean = np.mean(testImage_arr) testImage_std = np.std(testImage_arr) #Calculate a min and max based on sdFact, mean, and sdev arr_min = (testImage_mean - (sdFact/2) * testImage_std) arr_max = (testImage_mean + (sdFact/2) * testImage_std)
... View more
12-02-2016
07:23 AM
|
0
|
7
|
1008
|
POST
|
I am fairly new to ArcPy/Python and have been asked to do the following: Generate a histogram of bin counts based on an input 32-bit float raster image. I have generated the array for the image using ArcPy (ArcMap 10.4). The requirement is to determine the mean and stdev for this array (done as well with Numpy) and then set a new upper (max) and lower (min) value based on a 2.5 stdev spread across the mean (done too). This image data range must now go into an array with an arbitrary number of bins (say 20) each with a value width of ((new max - new min)/bins). Then I would need to count the total instances of values that fall within each bin, and plot to a histogram that can be saved. I have seen lots of promising information related to the Numpy and Matplotlib functions that can help in this regard, but can't seem to get it off the ground. At some point I will need to do the same for a variable number of input images (2 - 6 possible), determining the min and max values using stdev from all inputs, then plotting all based on this range. For now a single image would be a great start. Any suggestions greatly appreciated. Thanks.
... View more
12-01-2016
08:15 AM
|
0
|
10
|
2096
|
POST
|
For anyone interested, the following code solved this problem. mask = arcpy.GetParameterAsText(3)
MinX, MinY, MaxX, MaxY = mask.split( " ")
MinX = float( MinX)
MinY = float( MinY)
MaxX = float( MaxX)
MaxY = float( MaxY) The variables were then passed as follows: outExtent = Extent(MinX, MinY, MaxX, MaxY)
outConstRaster = CreateConstantRaster(constantValue, "INTEGER",
cellSize, outExtent) (Curtis Price added code formatting)
... View more
09-23-2016
09:44 AM
|
0
|
1
|
203
|
POST
|
I am developing an ArcPy tool that will enable a user to define a custom mask extent, which will be converted to a constant value raster and then used as input for a Zonalstats operator. I have the extent parameter added to the menu, but need some help in passing those values back to the script. The snippet of code below shows the context. The values from the menu for 'Mask Extent' have to populate Extent(xmin, ymin, xmax, ymax). I have tried setting the returned values with a GetParameterAsText, but that doesn't seem to work. Any help appreciated. # Set local variables constantValue = 255 cellSize = 1 outExtent = Extent(200, -800, 600, -400)
... View more
09-22-2016
10:17 AM
|
0
|
2
|
1061
|
POST
|
Thanks very much for your help, Jake. I will give this a try today.
... View more
03-16-2016
06:40 AM
|
0
|
0
|
766
|
POST
|
I have many hundreds of GeoTiff files to mosaic. The problem is that they are stored in a sub-directory structure whereby I need to traverse down into each sub-directory, mosaic all rasters in that location, and then go back up and down into all the other sub-directories sequentially to perform the same action. Some example directories would appear as follows: c:\dem\250k\001 (do all rasters here) ............. \002 (do all rasters here) ............. \003 (do all rasters here) I found the following Python snippet on the forum, but it finds and mosaics all rasters in all sub-directories to a single output layer. I need to find a way to "walk" into the sub-directories and output a single output for each. Thanks. import arcpy import os workspace = r"c:\dem\250k" arcpy.CheckOutExtension("Spatial") rasters = [] walk = arcpy.da.Walk(workspace, topdown=True, datatype="RasterDataset") for dirpath, dirnames, filenames in walk: dirpaths.append(os.path.join(dirpath, dirnames) for filename in filenames: rasters.append(os.path.join(dirpath, filename)) ras_list = ";".join(rasters) arcpy.MosaicToNewRaster_management(ras_list,workspace, "test.tif", "", "16_BIT_SIGNED", "", "1", "LAST") # return SA license arcpy.CheckInExtension("Spatial")
... View more
03-16-2016
04:52 AM
|
0
|
2
|
2329
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:25 AM
|