timholy / Grid.jl

Interpolation and related operations on grids
MIT License
47 stars 26 forks source link

CoordInterpGrid incorrectly gives DimensionMismatch error #29

Closed tomasaschan closed 10 years ago

tomasaschan commented 10 years ago

Try the following:

xg = -10:.5:10
yg = -3:.15:3.5
zg = Float64[sin(x)*cos(y) for x in xg, y in yg]
CoordInterpGrid((xg,yg),zg, 0, InterpLinear)
ERROR: DimensionMismatch("Coordinate lengths do not match grid size.")
 in CoordInterpGrid at /home/tlycken/.julia/v0.3/Grid/src/coord.jl:7
 in CoordInterpGrid at /home/tlycken/.julia/v0.3/Grid/src/coord.jl:13
 in CoordInterpGrid at /home/tlycken/.julia/v0.3/Grid/src/coord.jl:21

This happens because for certain combinations of boundary conditions and interpolation types, the matrix with interpolation coefficients is extended with a "frame" of extra values. Because of this, size(grid) from here doesn't return the size of the original data array, and thus the assertion here fails, although the data provided by the user is actually valid.

I think the easiest fix is to provide methods for size which take this into account, and I'll probably try to put together a PR to this effect. (There might be further problems with InterpCubic related to this matrix resize, too...) However, it'll be a while, since I currently have to focus on finishing up my thesis.

timholy commented 10 years ago

Thanks for reporting this and figuring out the problem!

Off-topic, but it turns out our travis script was not actually running the tests. I just turned that on, and also fixed another problem that cropped up due to changes in Julia over the last couple of weeks. Hopefully we'll be good to go, but it's possible we may get PkgEvaluator failures for a little bit.

simonp0420 commented 10 years ago

I am still getting this error with InterpCubic:

using Grid
x = 0:0.1:6
y = 10:0.1:15
z = sin(x * y')
zi = CoordInterpGrid((x,y),z, BCnil,InterpCubic)

Results in ERROR: DimensionMismatch("Coordinate lengths do not match grid size.") in CoordInterpGrid at c:\home\simonp.julia\v0.3\Grid\src\coord.jl:7

tomasaschan commented 10 years ago

@simonp0420 InterpCubic isn't correctly implemented for all boundary conditions (yet). I thought I had made sure that attempting to construct an InterpGrid with boundary conditions that don't work correctly threw an error, but it seems I didn't :(

Thanks for reporting the issue - I'll see if I can spend some time on correctly implementing the remaining boundary conditions.