Created
September 25, 2018 01:14
-
-
Save daleroberts/4010d06d74d9c1a64d336b28c7887061 to your computer and use it in GitHub Desktop.
Fill in holes in data.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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