Nodata utilities
convert_raster_nodata(input_raster, old_nodata=None, new_nodata=-9999)
Convert existing nodata values with a new nodata value for a raster.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_raster |
DatasetReader
|
Input raster dataset. |
required |
new_nodata |
Number
|
New nodata value that will be used to replace existing nodata for all bands. Defaults to -9999. |
-9999
|
Returns:
Type | Description |
---|---|
Tuple[ndarray, dict]
|
The input raster data and metadata updated with the new nodata. |
Raises:
Type | Description |
---|---|
InvalidParameterValueException
|
Nodata is not defined in raster metadata and old_nodata was not specified. |
Source code in eis_toolkit/utilities/nodata.py
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 |
|
handle_nodata_as_nan(func)
Replace nodata_values with np.nan for function execution and reverses the replacement afterwards.
Source code in eis_toolkit/utilities/nodata.py
135 136 137 138 139 140 141 142 143 144 145 146 |
|
nan_to_nodata(data, nodata_value)
Convert np.nan values to specified nodata_value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
ndarray
|
Input data as a numpy array. |
required |
nodata_value |
Number
|
Value that np.nan is converted to. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
Input array where np.nan has been converted to specified nodata. |
Source code in eis_toolkit/utilities/nodata.py
121 122 123 124 125 126 127 128 129 130 131 132 |
|
nodata_to_nan(data, nodata_value)
Convert specified nodata_value to np.nan.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
ndarray
|
Input data as a numpy array. |
required |
nodata_value |
Number
|
Value that is converted to np.nan. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
Input array where specified nodata has been converted to np.nan. |
Source code in eis_toolkit/utilities/nodata.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
|
set_raster_nodata(raster_meta, new_nodata)
Set new nodata value for raster metadata or profile.
Note that this function does not convert any data values, it only changes the metadata. The inteded use case for this tool is fixing metadata with invalid nodata value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
raster_meta |
Union[Dict, Profile]
|
Raster metadata or profile to be updated. |
required |
nodata_value |
New nodata value. |
required |
Returns:
Type | Description |
---|---|
Union[Dict, Profile]
|
Raster metadata / profile with updated nodata value. |
Source code in eis_toolkit/utilities/nodata.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
|
unify_raster_nodata(input_rasters, new_nodata=-9999)
Unifies nodata for the input rasters.
All old nodata values in the input rasters are converted to the new nodata value. Raster metadatas is also updated with the new nodata value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_rasters |
Sequence[DatasetReader]
|
|
required |
new_nodata |
Number
|
New nodata value that will be used to replace existing nodata for all bands in all input rasters. Defaults to -9999. |
-9999
|
Returns:
Type | Description |
---|---|
Sequence[Tuple[ndarray, dict]]
|
Output raster list. List elements are tuples where first element is raster data and second element is raster metadata. |
Raises:
Type | Description |
---|---|
InvalidParameterValueException
|
Input raster list contains only one raster. |
Source code in eis_toolkit/utilities/nodata.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
|