rasterarcgisesriarcpy

How can I extract the 'Pixel Depth' of a raster as a value using Model Builder in ArcGIS Pro (or evt. a python script)


In ArcGIS Pro I want to automate some tests on rasters, either stored in .gdb- or .tiff-files.

One of the tests requires checking the Pixel Type and Pixel Depth of the raster (has to be floating point with at least 32 Bit). These can be manually accessed trough the 'Raster information' section in the Layer Properties.

I can get the Pixel Type using the tool 'Get Raster Properties' selecting for 'Cell value type', however, there doesn't appear to be an option to select for 'Pixel Depth'.

'Build Raster Attribute Table (Data Management)' mentions 'You cannot build a raster attribute table for a raster dataset that is a pixel type of 32-bit floating point.', so if I would be able to execute this function I would be nearly sure the raster is not an integer pixel type, but that wouldn't exclude other reasons why 'Build Raster Attribute Table' might fail. Alsop it would be quite unintuitive for maintainers of the tool.

If someone knows a python function that could help out I could build a script tool so that would work as well.

Any help would be greatly appreciated.


Solution

  • If you need a raster with a floating-point representation, you may convert your raster using arcpy.management.CopyRaster.

    You may also want to look into arcpy.ia.Float (requires a specialized license).

    The pixel depth is a value applying to the whole raster:

    The bit depth (pixel depth) of a pixel determines the range of values that a particular raster file can store, which is based on the formula 2n (where n is the bit depth). For example, an 8-bit raster can have 256 unique values that range from 0 to 255.

    (Source: Bit depth capacity for raster dataset pixels)

    You could also analyze the raster/image using an Imaging Library such as pillow. However, this would only works if the raster is available as a file.

    The library pillow seems to call the pixel depth modes:

    The current release supports the following standard modes:

    • 1 (1-bit pixels, black and white, stored with one pixel per byte)
    • [...]
    • F (32-bit floating point pixels)

    (Source: pillow.readthedocs.io)

    from PIL import Image
    with Image.open("raster.jpg") as image:
        print(image.mode)  # prints F if 32-bit floating point pixels
    

    Please note: I haven't tried it myself.