Skip to main content

GeoTIFF

Read a GeoTIFF with the Fused utils.read_tiff utility function, which reads a portion of a tiff file based on the spatial extent of a provided bbox.

@fused.udf
def udf(bbox: fused.types.TileGDF=None, year="2022", chip_len=256):
import numpy as np

utils = fused.load(
"https://github.com/fusedio/udfs/tree/f928ee1/public/common/"
).utils

input_tiff_path = f"s3://fused-asset/data/cdls/{year}_30m_cdls.tif"
arr, color_map = utils.read_tiff(
bbox, input_tiff_path, output_shape=(chip_len, chip_len), return_colormap=True
)

colored_array = (
np.array([color_map[value] for value in arr.flat], dtype=np.uint8)
.reshape(arr.shape + (4,))
.transpose(2, 0, 1)
)
return colored_array