Created
May 6, 2022 19:01
Pygeoprocessing raster_calculator call to convert from a TauDEM D8 flow direction to pygeoprocessing D8 flow direction.
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
import numpy | |
import pygeoprocessing | |
from osgeo import gdal | |
def convert_taudem_flow_dir_to_pygeoprocessing( | |
taudem_flow_dir_raster_path, target_flow_dir_raster_path): | |
source_nodata = pygeoprocessing.get_raster_info( | |
taudem_flow_dir_raster_path)['nodata'][0] | |
dest_nodata = 128 # Matches pygeoprocessing-produced flow dir nodata. | |
def _convert(taudem_flow_dir_array): | |
dest_array = numpy.full(taudem_flow_dir_array.shape, dest_nodata, | |
dtype=numpy.uint8) | |
valid_pixels = (taudem_flow_dir_array != source_nodata) | |
dest_array[valid_pixels] = taudem_flow_dir_array[valid_pixels] - 1 | |
return dest_array | |
pygeoprocessing.raster_calculator( | |
[(taudem_flow_dir_raster_path, 1)], _convert, | |
target_flow_dir_raster_path, gdal.GDT_Byte, dest_nodata) | |
if __name__ == '__main__': | |
convert_taudem_flow_dir_to_pygeoprocessing( | |
'my_taudem_d8_flow_dir_raster.tif', | |
'pygeoprocessing_d8_flow_dir.tif') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment