Skip to content

Upsampling method US_LINEAR: why edges rather than midpoints? #6

@Huite

Description

@Huite

Hello,

While I was working on allowing different source and target coverage, I was a little puzzled by the bilinear interpolation option. As it seems to me now, it's not interpolation between the midpoints of the cells, but rather the edges of the grid.

For example, from one of the tests:

def test_interpolation_linear(self):
        self._test_upsample_2d([[1., 2., 3.]],
                               5, 1, gtr.US_LINEAR, -1.,
                               [[1, 1.5, 2, 2.5, 3]]),

Personally, I would have expected an output of [[1. 1.4 2. 2.6 3. ]], that is, assuming the midpoint is the point to measure from. In picture form, it's the difference between:

Marker = data
Solid = nearest
Dashed = linear interpolated

Linear interpolation from edges:
linear_ends

Linear interpolation from midpoints:
linear_midpoint

The bottom way of interpolating feels more consistent to me: it doesn't matter where the cell is located, the point "where to interpolate to" doesn't move on the x-axis.

I'm asking also because of the pull request: if source and target bounds don't line up, what's the consistent way of doing bilinear interpolation?

It's a few lines modification to change it to midpoint linear interpolation, but there's probably a reason for the current implementation I'm missing?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions