Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP features (so far: Flat BC, Constant extrap) #8

Merged
merged 3 commits into from
Nov 24, 2014

Conversation

tomasaschan
Copy link
Contributor

Constant extrapolation, such that itp[1-x] == itp[1] and itp[n+x] == itp[n] for any x >= 0 (after interpolating a 1D array of length n).

Note that this doesn't necessarily mean that itp[1] == A[1], since some boundary conditions invalidate that assumption; I figured it was better to enforce continuity at the domain edges:

using Gadfly, Interpolations
A = rand(15)
itp = Interpolation(A, Quadratic(ExtendInner(), OnCell()), ExtrapConstant())
plot(
    layer(x=[1:15], y=A, Geom.point),
    layer(x=[-1:.1:17], y=[itp[x] for x in -1:.1:17], Geom.path)
)

extrap-constant

@tomasaschan tomasaschan mentioned this pull request Nov 23, 2014
17 tasks
@timholy
Copy link
Member

timholy commented Nov 23, 2014

Grid (with itp = InterpGrid(A, BCnearest, InterpQuadratic)) definitely doesn't do that weird thing at x=15:
grid

@tomasaschan
Copy link
Contributor Author

I found a bug in my quadratic implementation that hopefully fixes this; the index was clamped by size(itp,d)-2 in the upper end, rather than size(itp,d)-1. Bugfix coming...

@tomasaschan
Copy link
Contributor Author

I just pushed a fix to master; now Interpolations doesn't either =)

extrap-constant

Well, at least not as weird. Grid.jl still seems to match up the data array's outermost data points with the interpolation, with Interpolations.jl doesn't; since the type here is OnCell, ExtendInner, the interpolation centered at x = 2 (thus valid for all x in [1.5,2.5]) is continued to x=1, and it doesn't actually go through that data point. I'll take a look and see what Grid does differently, but I suspect it's with a different BC.

@tomasaschan
Copy link
Contributor Author

Yup, as I suspected: Grid implicitly uses a flat boundary condition for BCnearest, so the plot above isn't actually supposed to be a reproduction of Grid's behavior. I'll take a stab at implementing the flat BC for Interpolations next, to make comparison easier.

@timholy
Copy link
Member

timholy commented Nov 23, 2014

Nice!

@tomasaschan
Copy link
Contributor Author

There! Flat BC with constant extrapolation seems to reproduce the results from Grid.

Interpolations:

extrap-constant-flat

Grid:

extrap-constant-flat-grid

@tomasaschan tomasaschan changed the title Constrant extrap WIP features (so far: Flat BC, Constant extrap) Nov 24, 2014
@timholy
Copy link
Member

timholy commented Nov 24, 2014

Very sweet! This is clearly coming along nicely.

@tomasaschan
Copy link
Contributor Author

That's what happens when I suddenly have time to spend on this :)

tomasaschan pushed a commit that referenced this pull request Nov 24, 2014
WIP features (so far: Flat BC, Constant extrap)
@tomasaschan tomasaschan merged commit 1d03a0b into master Nov 24, 2014
@tomasaschan tomasaschan deleted the constant-extrap branch December 29, 2014 04:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants