Is there a means to check to see if any 2 given raster layers have identical content?
We have a problem on our corporate shared storage volume: it's now so big that it takes over 3 days to conduct a full back up. Preliminary investigation reveals one of the biggest space consuming culprits are on/off rasters that really should be stored as 1-bit layers with CCITT compression.
This sample image is currently 2bit (so 3 possible values) and saved as LZW compressed tiff, 11 MB in file system. After converting to 1bit (so 2 possible values) and applying CCITT Group 4 compression we get it down to 1.3 MB, almost a full order of magnitude of savings.
(This is actually a very well behaved citizen, there are others stored as 32bit float!)
This is fantastic news! However there are almost 7,000 images to apply this too. It would be straightforward to write a script to compress them:
for old_img in [list of images]:
convert_to_1bit_and_compress(old_img)
remove(old_img)
replace_with_new(old_img, new_img)
...but it's missing a vital test: is the newly compressed version content-identical?
if raster_diff(old_img, new_img) == "Identical":
remove(old_img)
rename(new_img, old_img)
Is there a tool or method which can automatically (dis)prove the content of Image-A is value-identical to the content of Image-B?
I have access to ArcGIS 10.2 and QGIS, but am also open to most anything else than can obviate the need to inspect all these images manually to ensure correctness before overwriting. It would be horrible to mistakenly convert and overwrite an image that really did have more than on/off values in it. Most cost thousands of dollars to gather and generate.
update: The biggest offenders are 32bit floats that range up to 100,000px to a side, so ~30GB uncompressed.
raster_diff(old_img, new_img) == "Identical"
would be to check that the zonal max of the absolute value of the difference equals 0, where the zone is taken over the entire grid extent. Is this the sort of solution you're looking for? (If so, it would need to be refined to check that any NoData values are consistent, too.)NoData
handling stays in the conversation.len(numpy.unique(yourraster)) == 2
, then you know that it has 2 unique values and you can safely do this.numpy.unique
is going to be more computationally expensive (both in terms of time and space) than most other ways to check that the difference is a constant. When confronted with a difference between two very large floating point rasters that exhibit many differences (such as comparing an original to a lossy compressed version) it would likely bog down forever or fail completely.gdalcompare.py
showed great promise (see answer)