Topics

WarpedVRT and resampling ?


vincent.sarago@...
 

This was previously discussed on multiple Issues and PR: 
https://github.com/mapbox/rasterio/issues/1206
https://github.com/mapbox/rasterio/pull/1238
https://github.com/mapbox/rasterio/pull/1239

While working with https://github.com/cogeotiff/rio-tiler on different data format (Int16, Float ...) I've encountered some strange behavior when using non-nearest resampling algorithm. 

## Contexte 

When working with `WarpedVRT` you can choose the resampling algorithm twice: 
```
with WarpedVRT(src, resampling=enums.Resampling.nearest) as vrt:
    arr = vrt.read(out_shape=(1, 512, 512, resampling=enums.Resampling.nearest))
```
Sean try to explain this in https://github.com/mapbox/rasterio/pull/1238#issuecomment-353123776

rio-tiler code: https://github.com/cogeotiff/rio-tiler/blob/master/rio_tiler/utils.py#L296-L321

## Behavior 

On the images attached we can see that there are `blurry` lines on the bottom. Those lines appear on the bottom of the tile returned by `rio-tiler` (bottom of the WarpedVRT returned value). 

Observation: 
- Only visible when working on Linux (https://github.com/RemotePixel/amazonlinux-gdal/tree/gdal2.4.0, or with rasterio wheels) 
- Only with Int16 data with negative NoData 
- Not visible when using gdalwarp directly
- Visible only when not using `resampling=enums.Resampling.nearest` in WarpedVRT params

I'm not 100% to understand what is going on and if I should or should not use `enums.Resampling.nearest`  as default resampling in WarpedVRT params so I'm looking for guidance here. 

Thanks,

Vincent 


Sean Gillies
 

Hi Vincent,

Can you explain what processes produced those images? What program produced the blurry one and what program produced the non-blurry one? Which resampling algorithms were used?

Yes, you can introduce resampling in two places. I think it is not a good idea to do so: if you use the WarpedVRT, you should define its extents so that you don't need to use any resampling at all when you read from it. Also, I don't fully understand the edge effects when you resample in read().


On Fri, Apr 19, 2019 at 9:37 PM <vincent.sarago@...> wrote:
This was previously discussed on multiple Issues and PR: 
https://github.com/mapbox/rasterio/issues/1206
https://github.com/mapbox/rasterio/pull/1238
https://github.com/mapbox/rasterio/pull/1239

While working with https://github.com/cogeotiff/rio-tiler on different data format (Int16, Float ...) I've encountered some strange behavior when using non-nearest resampling algorithm. 

## Contexte 

When working with `WarpedVRT` you can choose the resampling algorithm twice: 
```
with WarpedVRT(src, resampling=enums.Resampling.nearest) as vrt:
    arr = vrt.read(out_shape=(1, 512, 512, resampling=enums.Resampling.nearest))
```
Sean try to explain this in https://github.com/mapbox/rasterio/pull/1238#issuecomment-353123776

rio-tiler code: https://github.com/cogeotiff/rio-tiler/blob/master/rio_tiler/utils.py#L296-L321

## Behavior 

On the images attached we can see that there are `blurry` lines on the bottom. Those lines appear on the bottom of the tile returned by `rio-tiler` (bottom of the WarpedVRT returned value). 

Observation: 
- Only visible when working on Linux (https://github.com/RemotePixel/amazonlinux-gdal/tree/gdal2.4.0, or with rasterio wheels) 
- Only with Int16 data with negative NoData 
- Not visible when using gdalwarp directly
- Visible only when not using `resampling=enums.Resampling.nearest` in WarpedVRT params

I'm not 100% to understand what is going on and if I should or should not use `enums.Resampling.nearest`  as default resampling in WarpedVRT params so I'm looking for guidance here. 

Thanks,

Vincent 



--
Sean Gillies


vincent.sarago@...
 

Hi Sean, sorry for not being really clear. 

> Can you explain what processes produced those images? What program produced the blurry one and what program produced the non-blurry one? Which resampling algorithms were used? 

Those two image were produced by `rio-tiler`. One on linux (blurry) the other on Mac OS (both with wheels, but also tried with gdal sources). The resampling algorithm that produced blurry lines are non-nearest: cubic, bilinear, cubic spline.  

>  if you use the WarpedVRT, you should define its extents so that you don't need to use any resampling at all when you read from it. Also, I don't fully understand the edge effects when you resample in read().

in https://github.com/cogeotiff/rio-tiler/blob/master/rio_tiler/utils.py#L296-L321, what we do first is to calculated the bounds of the VRT (mercator tiles) and then do (decimated) reads. 

The interesting part is the bilinear resampling introduce the blurry lines only when using it on the `WarpedVRT` params and not on the `read`. 

here is a gist showing how to reproduce it: https://gist.github.com/vincentsarago/0b229741c3261a9a447c7ab5dbd9eb05