developmentseed / warp-resample-profiling

Guidance and profiling results for warp resampling in Python
https://developmentseed.org/warp-resample-profiling/
Apache License 2.0
15 stars 0 forks source link

Add guidance on when to apply mask and scale/offset before resampling #8

Open maxrjones opened 4 weeks ago

maxrjones commented 4 weeks ago

Despite potential modest performance hits, should the mask and scale always be applied before resampling to prevent accidental mistakes?

If not, I think this approach could work:

maxrjones commented 4 weeks ago

@vincentsarago @sharkinsspatial would either of you be able to provide guidance about the correct approach for unscaling during tile generation?

vincentsarago commented 4 weeks ago

in rio-tiler we apply unscaling after reprojection/resampling https://github.com/cogeotiff/rio-tiler/blob/0a8456122d3b4a256cdb63da466f32a3587df512/rio_tiler/reader.py#L264-L276

In GDAL, applying the scale and offset is done after reading the data

Note that applying scale and offset is of the responsibility of the user, and is not done by methods such as RasterIO() or ReadBlock().

About the mask we let GDAL handle everything https://gdal.org/en/latest/programs/gdalwarp.html#nodata-source-validity-mask-handling but the mask (either nodata / alpha / internal mask) has to be set before wrapping.

I see that with rioxarray you do the opposite (when using mask_and_scale=True), you'll read the dataset, upscale and then wrap (I think)

I'm not quite sure about the optimization but when unscaling the data you'll endup with float data which might take more memory 🤷‍♂️