rioxarray.GeoTIFFDataset
kedro_datasets_experimental.rioxarray.GeoTIFFDataset ¶
GeoTIFFDataset(
*,
filepath,
load_args=None,
save_args=None,
version=None,
metadata=None
)
Bases: AbstractVersionedDataset[DataArray, DataArray]
GeoTIFFDataset loads and saves raster data files and reads them as xarray DataArrays. The underlying functionality is supported by rioxarray, rasterio, and xarray.
Reading and writing of single and multiband GeoTIFF data is supported. There are sanity checks to ensure that a coordinate reference system (CRS) is present.
Supported dimensions are ("band", "x", "y") and ("x", "y"). xarray DataArrays with other dimensions cannot be saved to a GeoTIFF file.
If you need other formats, consider using NetCDF.
Example usage for the YAML API¶
sentinal_data:
type: rioxarray.GeoTIFFDataset
filepath: sentinal_data.tif
Example usage for the Python API:¶
from kedro_datasets.rioxarray import GeoTIFFDataset
import xarray as xr
import numpy as np
data = xr.DataArray(
np.random.randn(2, 3, 2),
dims=("band", "y", "x"),
coords={"band": [1, 2], "y": [0.5, 1.5, 2.5], "x": [0.5, 1.5]},
)
data_crs = data.rio.write_crs("epsg:4326")
data_spatial_dims = data_crs.rio.set_spatial_dims("x", "y")
dataset = GeoTIFFDataset(filepath="test.tif")
dataset.save(data_spatial_dims)
reloaded = dataset.load()
xr.testing.assert_allclose(data_spatial_dims, reloaded, rtol=1e-5)
Parameters:
-
filepath(str) –Filepath in POSIX format to a rasterdata file. The prefix should be any protocol supported by
fsspec. -
load_args(dict[str, Any] | None, default:None) –rioxarray options for loading rasterdata files. Here you can find all available arguments: https://corteva.github.io/rioxarray/html/rioxarray.html#rioxarray-open-rasterio All defaults are preserved.
-
save_args(dict[str, Any] | None, default:None) –options for rioxarray for data without the band dimension and rasterio otherwhise.
-
version(Version | None, default:None) –If specified, should be an instance of
kedro.io.core.Version. If itsloadattribute is None, the latest version will be loaded. If itssaveattribute is None, save version will be autogenerated. -
metadata(dict[str, Any] | None, default:None) –Any arbitrary metadata. This is ignored by Kedro, but may be consumed by users or external plugins.
Source code in kedro_datasets_experimental/rioxarray/geotiff_dataset.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
_describe ¶
_describe()
Source code in kedro_datasets_experimental/rioxarray/geotiff_dataset.py
109 110 111 112 113 114 115 116 | |
_exists ¶
_exists()
Source code in kedro_datasets_experimental/rioxarray/geotiff_dataset.py
141 142 143 144 145 146 147 | |
_invalidate_cache ¶
_invalidate_cache()
Invalidate underlying filesystem caches.
Source code in kedro_datasets_experimental/rioxarray/geotiff_dataset.py
153 154 155 156 | |
_release ¶
_release()
Source code in kedro_datasets_experimental/rioxarray/geotiff_dataset.py
149 150 151 | |
_sanity_check ¶
_sanity_check(data)
Perform sanity checks on the data to ensure it meets the requirements.
Source code in kedro_datasets_experimental/rioxarray/geotiff_dataset.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 | |
_save_multiband ¶
_save_multiband(data, save_path)
Saving multiband raster data to a geotiff file.
Source code in kedro_datasets_experimental/rioxarray/geotiff_dataset.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |
load ¶
load()
Source code in kedro_datasets_experimental/rioxarray/geotiff_dataset.py
118 119 120 121 122 123 124 125 126 | |
save ¶
save(data)
Source code in kedro_datasets_experimental/rioxarray/geotiff_dataset.py
128 129 130 131 132 133 134 135 136 137 138 139 | |