I am processing .tif raster files in an arcpy script that converts a mosaicked tiff into a grayscale image. As the input raster InputRaster file is a mosaic and quite large (uncompressed size around 50GB) I would like to apply compression setting LZW to the grayscaled version using the setting arcpy.env.compression = "LZW" in arcpy. The LZW compression in the script works executed with ArcGIS 10.4.1 Python 2.7 environment (I am using IDLE and a standalone version), however I am having problems with implementing this in with Python 3.6 (Jupyter Notebook, installed with ArcGIS Pro 2.2.2). The grayscaled .tif file is created but still uncompressed. As I would like to use 64bit background processing coming with ArcGIS Pro, I am wondering if anyone has had similar experiences?

Arcpy script (Python 3.6) is below

import arcpy
import os
from arcpy import env
from arcpy.sa import *

arcpy.env.overwriteOutput = True

# Define the output settings for compression
arcpy.env.pyramid = "PYRAMIDS -1 BILINEAR LZW 10"
arcpy.env.compression = "LZW"

## compression settings
pylevel = "-1"
skipfirst = "NONE"
resample = "BILINEAR"
compress = "LZ77"
quality = "10"
skipexist = "SKIP_EXISTING"

mosaicname = r"D:InputRaster.tif"
subdirectory_gray = r'D:\DataExport'
Band_1 = arcpy.Raster(os.path.join(mosaicname, "Band_1"))
Band_2 = arcpy.Raster(os.path.join(mosaicname, "Band_2"))
Band_3 = arcpy.Raster(os.path.join(mosaicname, "Band_3"))
print("Bands read in")

# calculate SW grayscale image and compress it
arcpy.env.compression = "LZW"
SW_raster = (Band_1 + Band_2 + Band_3)/3
filename = os.path.basename(mosaicname)
mosaicname_SW = os.path.join(subdirectory_gray, filename) 
mosaicname_SW = mosaicname_SW.replace(".tif", "_SW.tif")
print("Saving grayscale image")
print("Building pyramids")
inras = mosaicname_SW
arcpy.BuildPyramids_management(in_raster_dataset= inras, pyramid_level=pylevel, resample_technique=resample,compression_type=compress, compression_quality=quality, skip_existing=skipexist)
print("Grayscale image saved at: " + mosaicname_SW)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.