The Python Raster function allows you to create custom raster functions. You can write image processing algorithms in Python, and apply them to mosaic datasets and raster datasets. The Python Raster function can be inserted into a function chain just like any other function. It accepts one of two inputs: a .py file or a .pyd (compiled Cython) file. The parameters for the function are specified within the Python script. When you point to a script, the table will be populated with the available parameters.
The Python Raster function can be inserted into a function chain by right-clicking on an existing function in the function dialog box. Unlike the out-of-the box functions, it is located in the first context menu, as soon as you right-click on an existing function.
There are three inputs within this function:
- Python Module
- Class Name
- Parameters
Python Module
The Python model is the path to the Python script. The input can be in the form of a Python file (.py), or a compiled Cython file (.pyd). Inside the Python code, there will be methods, which are used to describe information about the function, the parameters, and the output. Once this parameter has been specified, the Class Name and Parameter sections will be populated.
For more information about the Python Raster function, see Python Raster Functions on GitHub.
Class Name
The Class Name is the name given to a block of code being used from the Python script. A Python input usually only has one class, but it can have multiple classes. When you specify a Class Name, the parameters will be automatically populated with the available parameters.
Parameters
Once the Class Name is specified, the Parameter table is populated with the parameter names and values that are defined by the Python script. You can edit the Value field to customize your output.
There are five possible data types that can be used as parameters: numeric, string, raster, rasters, and boolean. Domains can be created for parameters, within your Python script, in order to limit the list of input values that a user can chose from. In this case, when clicking on the value, a drop-down menu will appear. The getParameterInfo() method within the Python script controls the input parameters that are set. More information on the getParameterInfo() method is available on GitHub.
If the parameter type is set to rasters, you can click on the Value section of the parameter and a window will open. This window allows you to add rasters from multiple sources. The following options are available when adding rasters from this dialog box.
- Add raster from disk—Add a raster that is on disk. You can add raster datasets, mosaic datasets, and raster products.
- Add function chain—Add a function chain as an input.
- Add scalar—Add a scalar value. Scalar values must be numeric.
- Add reference to selected input—Add a referenced copy of the selected raster or the selected function chain input. A change in the referenced raster or the function chain will be reflected in this referenced copy. This can be useful when creating many functions that may use the same referenced input.
- Add copy of selected input—Add a static copy of the selected function chain input. A change in the copied function chain will not reflect this static copy. This can be useful when creating many similar functions where there is a slight change in the function chains.