1

I want to 'cap' the values of a raster if it exceeds the percentile value. For example if the 95th percentile value of the raster was 10000, then anything at or above that value would be assigned a value of 10000. I have a manual way of doing this in Raster Calculator, but this involves me finding the percentile value beforehand:

Con( "Extract_h1_d1">10000,10000, "Extract_h1_d1")

Is there a way to include the percentile within Raster Calculator function itself?

1 Answer 1

0

This can be done in model builder using the Calculate Value tool to run a tiny piece of python. Model is just this:

Model

Calculate Value tool is set up as it:

Calculate Value tool

The code in code block is this:

import arcpy
import numpy as np
def per95(raster):
    npArray = arcpy.RasterToNumPyArray(raster)
    p = np.percentile(npArray, 95)
    return p

The CON tool is set up as is:

CON tool

Note output of Calculate Value tool is a precondition to CON tool.

2
  • Is there a way to set the 'Input true raster or constant value' equal to the Value calculated in the python code?
    – Daniel Sim
    Commented Jun 20, 2023 at 7:05
  • Just use inline variable substitution.
    – Hornbydd
    Commented Jun 20, 2023 at 10:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.