Before Sharing a GeoTIFF: Check Its Values and Location

Lesson 5 · Data Science with DEB

You have calculated NDVI, exported a GeoTIFF and made an attractive map. Before sharing it, ask two separate questions: did the file preserve the intended values, and did it preserve their intended locations? A successful export alone answers neither.

This lesson builds on the real-scene comparison in lesson four. It adapts the editorial draft prepared in ordinary Chat and adds executed checks. No new video accompanies this article.

Check the values and their location

A GeoTIFF can hold numerical bands and geographic referencing. For an affine-georeferenced raster, the CRS identifies the coordinate system and the transform maps pixel positions into it. Changing only a CRS label is not reprojection. Dimensions describe rows, columns and bands; after a deliberate crop or reprojection they may legitimately change. Compare against the intended output, not an assumption that every property must match the input.

For the supplied NDVI example, the expected grid is 72 rows × 63 columns, one band, EPSG:32643, ten-metre cells, and upper-left grid corner (576440, 3419510). Its bounds are (576440, 3418790, 577070, 3419510). The upper-left pixel centre is (576445, 3419505), five metres inward from each edge. These coordinates are metres, not longitude and latitude.

We made a separate, intentionally incorrect copy by shifting the transform 100 metres east while retaining every pixel value and the CRS. It opened normally and its numerical array was identical, but its bounds and transform differed. This is a controlled metadata error, not a new observation or a reprojection. Statistics alone cannot detect it.

Keep missing observations separate from valid zero values

The example uses −9999 as its declared nodata sentinel. A valid NDVI of zero must remain valid. Read with masked=True to use the applicable mask, then separately exclude non-finite values. A nodata value of None does not prove that every pixel is usable: a dataset may have another validity mask.

Rasterio’s GDAL-style mask marks valid cells with nonzero values; a NumPy masked array marks invalid cells with True. These conventions are opposite. If the dataset depends on an external mask or other auxiliary files, include them when sharing and test the actual delivery package. Mask precedence can depend on the available mask sources.

Choose a dtype and interpret scaling explicitly

A directly stored fractional NDVI raster can use float32. Converting fractions directly to an integer dtype can lose their decimal information. Scaled integers can also represent measurements, provided their scale and offset are documented and applied correctly.

The inspector below reads stored samples, removes masked and non-finite values, and explicitly calculates stored × scale + offset from the band metadata. If those metadata are absent or wrong, the script cannot infer the intended product conversion. Do not apply an additional conversion to a raster whose values are already in the target units.

Inspect the distribution without treating it as proof

Check minimum, maximum, mean and valid finite count. For NDVI made from non-negative red and NIR reflectance with a positive denominator, the algebra gives a range from −1 to +1. Investigate unexpected values rather than silently clipping them. The physical assumptions, preprocessing and quantity matter. A plausible distribution still cannot establish crop condition, scientific accuracy or correct geographic placement.

Same values, different colours

The same numerical NDVI array shown with grayscale and green palettes using identical display limits.
Both panels use the same NDVI array and limits −0.2 to 1.0. Only the display palette changes.

Changing display symbology does not require changing the numerical raster. Exporting a rendered RGB map is different: its colour-channel samples may no longer contain the original NDVI measurements. Share numerical outputs for analysis and a separate styled figure for communication. Check the export options of the software you use. No GIS menu or overlay workflow has been tested in this lesson.

Run the read-only inspector

Download the numerical NDVI example. Save the script below as inspect_geotiff.py. It reads the file without modifying it. It loads one band at a time into memory, so large rasters require a block-wise approach.

python -m pip install numpy==2.3.5 rasterio==1.4.4
python inspect_geotiff.py lesson-05-ndvi.tif
import rasterio
import numpy as np

import sys
file_path = sys.argv[1]

with rasterio.open(file_path) as src:

    print("----- SPATIAL INFORMATION -----")
    print("CRS:", src.crs)
    print("Transform:", src.transform)
    print("Bounds:", src.bounds)
    print("Resolution:", src.res)

    print("\n----- RASTER STRUCTURE -----")
    print("Width:", src.width)
    print("Height:", src.height)
    print("Bands:", src.count)
    print("Data types:", src.dtypes)
    print("Nodata values:", src.nodatavals)
    print("Scale factors:", src.scales)
    print("Offsets:", src.offsets)

    print("\n----- PIXEL INFORMATION -----")

    for band in range(1, src.count + 1):

        data = src.read(band, masked=True)
        raw = data.compressed()

        # Exclude non-finite stored values
        raw = raw[np.isfinite(raw)]

        # Interpret scale and offset
        values = (
            raw.astype("float64")
            * src.scales[band - 1]
            + src.offsets[band - 1]
        )

        values = values[np.isfinite(values)]

        print("\nBand:", band)
        print("Total pixels:", data.size)
        print("Valid finite pixels:", values.size)
        print(
            "Excluded pixels:",
            data.size - values.size
        )

        if values.size > 0:

            print("Minimum:", values.min())
            print("Maximum:", values.max())
            print("Mean:", values.mean())
            print("Std. deviation:", values.std())

        else:
            print("No valid finite pixels found.")

What was actually tested

The inspector ran with Rasterio 1.4.4 and NumPy 2.3.5 on these constructed cases:

CaseValid finite cellsInterpreted mean
Float with −9999 nodata3 of 40.5
Integer, scale 0.0001, offset −0.14 of 40.05
Explicit mask, no nodata sentinel3 of 40.5
Unmasked NaN3 of 40.5
All cells nodata0 of 4No mean reported

All expected counts and means passed. On the real-scene NDVI output, it reported 4,536 valid finite cells and a mean approximately 0.467969. Metadata checks matched the intended grid. This is archived Sentinel-2-derived data from Punjab, dated 13 October 2024; crop identity and condition remain unverified.

Reopen, compare, then inspect against a reference

Close the writer and reopen the actual saved file. Compare its CRS, transform, shape, dtype, nodata, mask and values with the intended result, using tolerances suitable for floating-point storage. The inspector reports properties; it does not automatically know your expected answer.

Then inspect the raster against a trusted geographic reference in a GIS. Matching metadata proves consistency with the declared grid, not absolute geolocation accuracy. That independent GIS overlay remains a recommended next check, not an action performed here.

Learner checklist

  • The delivered file reopens successfully, with any required auxiliary files.
  • CRS, transform, bounds, resolution, dimensions and band count match the intended output.
  • Dtype preserves the required precision; scale and offset are correctly interpreted.
  • Applicable masks and non-finite values are handled; valid zeros remain valid.
  • Reopened pixel values match the intended calculation within stated tolerances.
  • The spatial position is checked against a trusted reference.
  • Numerical data and rendered colour images are clearly distinguished.
  • Provenance, units, limitations and reuse terms accompany the output.

Test your understanding

1. Correct NDVI values, wrong location: what should you check first?
CRS and transform, then compare the footprint against the intended grid and a trusted reference.

2. Which dtype can directly store fractional NDVI?
Float32 is a practical choice, subject to its precision. Integers require an intentional encoding scheme.

3. Does changing only a display palette change stored NDVI?
No. A separately exported rendered image may instead store colour-channel values, so distinguish the two products.

Sources and reuse

Technical references: Rasterio georeferencing, nodata masks, and GDAL raster data model. Reviewed 26 November 2026.

Contains modified Copernicus Sentinel data 2024, processed through Google Earth Engine. Source data retain Copernicus terms. The lesson inspector, constructed tests and original figure are released under the MIT License, copyright 2026 Data Science with DEB.

Return to the learning path. Next: open numerical outputs in a GIS and inspect their placement and display settings.

Leave a Comment