timholy / Grid.jl

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

wrong array size? #28

Closed mzalam closed 10 years ago

mzalam commented 10 years ago

in the following code cg should be 256X256 array. but it returns 258X258 array. Why?

n = 256 d= 0.1 x = -n_d/2.0:d:(n_d - d)/2

da = rand(256, 256) cg = CoordInterpGrid((x, x), da, 0.0, InterpLinear)

tomasaschan commented 10 years ago

Actually, cg isn't really an array, but an interpolation object. The size reflects its number of grid points. When you use the BCfill boundary condition (which you do by supplying the fill value 0.0 to 'CoordInterpGrid`), a "padding" of one cell is added around your supplied data array, to store the fill value, so the data array of the inner points is still 256x256.

If you try a different boundary condition, you'll find a different behavior:

julia> cg = CoordInterpGrid((x,x),da,BCnan,InterpLinear)
256x256 CoordInterpGrid{Float64,2,BCnan,InterpLinear,FloatRange{Float64}}:
# etc...