Handle rasters without a defined NoData value in align_and_resize_raster_stack#477
Conversation
| chosen_nodata = choose_nodata(raster_info['numpy_type']) | ||
|
|
||
| if set(nodata_list) != {None}: | ||
| LOGGER.warning( |
There was a problem hiding this comment.
From what I can tell, gdal does not create geotiffs that have different NoData values (even if you try to explicitly set different NoData values for different bands, it won't work), so I think this would be a very rare situation and therefore not super important or easy to handle gracefully (i.e., by setting NoData only for the bands that lack a defined NoData value, since gdal doesn't support this for tiffs). I also decided not to raise an error as a raster that has the pygeoprocessing-approved NoData value for its datatype (e.g., 32767 for an int16 raster) would be fine.
There was a problem hiding this comment.
I think gdal handles different nodata values for different bands. See the "UNIFIED_SRC_NODATA" option from gdalwarpoptions.
dcdenu4
left a comment
There was a problem hiding this comment.
Thanks @claire-simpson , I had a comment about taking a look at gdalwarpoptions, to see if that also could be a clean way to pass along the desired destination nodata value to gdal.Warp.
| chosen_nodata = choose_nodata(raster_info['numpy_type']) | ||
|
|
||
| if set(nodata_list) != {None}: | ||
| LOGGER.warning( |
There was a problem hiding this comment.
I think gdal handles different nodata values for different bands. See the "UNIFIED_SRC_NODATA" option from gdalwarpoptions.
|
|
||
| vrt_path = os.path.join(temp_working_dir_nodata, | ||
| f'input_with_nodata_{index}.vrt') | ||
| vrt = gdal.Translate(vrt_path, raster, format='VRT', |
There was a problem hiding this comment.
I'm wondering if the creation of the VRT is necessary or if we could take advantage of gdal_warp_options and the dstnodata (?) argument. Like the resample list, could we keep a list of destination nodata values and pass those along through the gdal_warp_options?
I'm not sure it's a better approach than the VRT one other than it reduces a call to gdal.Translate.
If a raster input to
align_and_resize_raster_stackdoes not have a definedNoDatavalue, the function will now automatically pick one. It will also log a warning in the rare instance that a multiband raster input has some but not all bands with undefined NoData values. This is because in this instance, defined NoData values in any bands in that multiband raster (that has mixed NoData conditions) may be redefined as whateverpygeoprocessingpicks usingchoose_nodata.Steps:
NoDatavaluesNoDatavalue usingchoose_nodata(this is to avoid modifying a user's original data)NoDatadefined on any band, or (b) a multiband raster hasNoDatadefined on some bands but not others, in which case a singleNoDatavalue is applied to all bands in the temporary VRTFixes: #476