Skip to content

Instantly share code, notes, and snippets.

@daleroberts
Created September 25, 2018 01:14
Show Gist options
  • Save daleroberts/4010d06d74d9c1a64d336b28c7887061 to your computer and use it in GitHub Desktop.
Save daleroberts/4010d06d74d9c1a64d336b28c7887061 to your computer and use it in GitHub Desktop.
Fill in holes in data.
#!/usr/bin/env python3
import numpy as np
import gdal
import sys
MV = 8500
gdal.UseExceptions()
fn = sys.argv[1]
fd = gdal.Open(fn, gdal.GA_Update)
data = fd.ReadAsArray()
rb = fd.GetRasterBand(1)
nodata = rb.GetNoDataValue()
mask = (data > MV).any(axis=0)
data[:, mask] = nodata
for i in range(fd.RasterCount):
rb = fd.GetRasterBand(i + 1)
rb.WriteArray(data[i, :, :])
rb.SetNoDataValue(nodata)
gdal.FillNodata(rb, None, 5, 0, [], None)
fd = None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment