Skip to main content

Raster comparison plugin for rasterio

Project description

rio-diff

A rasterio plugin for comparing two raster files and showing differences between them.

Overview

rio-diff is a command-line tool that extends the functionality of Rasterio by providing a way to compare two raster files and highlight their differences. Inspired by the classic Unix diff command, this plugin enables users to identify differences in raster properties and pixel values.

Features

  • Compare various raster properties including dimensions, data types, coordinate reference systems, and metadata
  • Calculate pixel-by-pixel differences between compatible rasters
  • Optionally save the per-pixel difference raster (base - test) to disk
  • Show statistics on differences including count, percentage, maximum difference, and RMSE
  • Support for ignoring specific properties during comparison
  • Integration with Rasterio's command-line interface

Installation

Install the package using pip:

pip install rio-diff

After installation, the plugin will be available as a subcommand of rio.

Usage

Basic usage to compare two raster files:

rio diff base_raster.tif test_raster.tif

Options

  • --ignore-height: Ignore the height property during comparison
  • --ignore-width: Ignore the width property during comparison
  • --ignore-bands: Ignore the number of bands during comparison
  • --ignore-dtype: Ignore data type during comparison
  • --ignore-nodata: Ignore NoData values during comparison
  • --ignore-bbox: Ignore bounding box during comparison
  • --ignore-crs: Ignore coordinate reference system during comparison
  • --ignore-transform: Ignore affine transform during comparison
  • --ignore-metadata: Ignore metadata during comparison
  • --ignore-stats: Ignore statistics during comparison
  • --ignore-pixels: Ignore pixel values during comparison
  • --checksum: Also compare the whole-file checksum (strict byte-level equality; optional, off by default)
  • --save-diff PATH: Save the per-pixel difference raster (base - test) to the given path. When the rasters are byte-identical, the tool exits early and no diff raster is written.
  • --version: Show version information

Examples

Compare two raster files with default settings:

rio diff raster1.tif raster2.tif

Ignore metadata differences when comparing:

rio diff raster1.tif raster2.tif --ignore-metadata

Compare rasters but ignore differences in pixel values:

rio diff raster1.tif raster2.tif --ignore-pixels

Require strict byte-level equality via the whole-file checksum:

rio diff raster1.tif raster2.tif --checksum

Save the per-pixel difference raster to disk:

rio diff raster1.tif raster2.tif --save-diff diff.tif

If the rasters are byte-identical, the tool exits early and the diff raster is not written.

Comparison Details

The tool compares the following raster properties:

  • Checksum: MD5 hash of the file content (only when --checksum is passed).
  • Dimensions: Width and height in pixels
  • Bands: Number of channels/layers
  • Data Type: Bit depth and signed/unsigned nature
  • NoData Value: Value representing missing or invalid data
  • Bounding Box: Spatial extent in coordinate units
  • CRS: Coordinate Reference System
  • Transform: Affine transformation matrix
  • Metadata: Tags and attributes associated with the raster
  • Statistics: Basic statistical information about pixel values
  • Pixel Values: Actual pixel-by-pixel comparison (when rasters are compatible)

For compatible rasters, the tool calculates detailed statistics about pixel differences including:

  • Count of different pixels
  • Percentage of different pixels
  • Maximum difference value
  • Root Mean Square Error (RMSE)

Exit Codes

The command sets its exit code so it can be used in scripts and CI:

  • 0: No differences were found across the compared properties (also returned early when the files are byte-identical).
  • 1: At least one difference was found.
  • 2: Usage error (invalid arguments or missing input files).

Ignored properties (--ignore-*) do not affect the exit code. The whole-file checksum only affects it when --checksum is passed.

Inspiration

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rio_diff-1.0.0a0.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rio_diff-1.0.0a0-py3-none-any.whl (11.6 kB view details)

Uploaded Python 3

File details

Details for the file rio_diff-1.0.0a0.tar.gz.

File metadata

  • Download URL: rio_diff-1.0.0a0.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.4

File hashes

Hashes for rio_diff-1.0.0a0.tar.gz
Algorithm Hash digest
SHA256 e47421c0d08b1e0bdaa05524803935f063cbec9a235c865afb9151d3173b010e
MD5 6510c40be595623bd4cfcf2c3e41d0bf
BLAKE2b-256 d491bce605a491446653ceef1e0580cc62d85a58aed054afe63a580c46547edc

See more details on using hashes here.

File details

Details for the file rio_diff-1.0.0a0-py3-none-any.whl.

File metadata

File hashes

Hashes for rio_diff-1.0.0a0-py3-none-any.whl
Algorithm Hash digest
SHA256 45e4b6d171bccdc9144b6faa7563bfe343259b5b1e91c55bbce9b155d177751e
MD5 0e7065ca8be439073b8cf936444a3a80
BLAKE2b-256 27efd760b59f8ff28d7d32da7369bf7735e1ccdbf6bbb484daea1ec3ab0ef9c9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page