[julia-users] Re: Parametric splines?

2016-03-19 Thread Kaj Wiik
Replying to myself...sorry.

It seems that the easiest way for now is to call SciPy:

using PyCall
@pyimport scipy.interpolate as interpolate
t = collect(0:.1:1)
x = sin(2π*t)
y = cos(2π*t)
p = Array[]
push!(p, x)
push!(p, y)
tck, u = interpolate.splprep(p, s=0)
unew = collect(0:0.01:1)
out = interpolate.splev(unew, tck)

using Winston
plot(x, y, "o", out[1], out[2], "-r")

BTW, is there an easier way to create an array of vectors?

Cheers,
Kaj

On Saturday, March 19, 2016 at 4:13:19 PM UTC+2, Kaj Wiik wrote:
>
>
> Is there a Julia package that implements parametric splines? 
>
> I noticed that the Dierckx Fortran library has an implementation but the 
> corresponding Julia package does not does not have bindings for it.
>
> Thanks,
> Kaj
>


Re: [julia-users] Re: Parametric splines?

2016-03-19 Thread Kyle Barbary
Hi Kaj,

A pull request adding a wrapper for this to Dierckx.jl would be most
welcome. This would be a matter of reading the docstring for the parcur
function here

and then writing a wrapper function that sets up the arguments correctly
and calls the Fortran function with ccall. There are a lot of examples in
Dierckx.jl. It’s a bit tedious but mostly straight forward. Fortunately
(for me anyway) knowing Fortran is not a requirement. I usually consult the
relevant scipy.interpolate wrapper (e.g., this one for splprep
)
to see how they handled things, and look at the tests in that package as
well.

You can construct an array of vectors by prepending the element type, which
in your example would be Vector{Float64}. For example:

julia> a = [1., 2.];

julia> b = [3., 4.];

julia> Vector{Float64}[a, b]
2-element Array{Array{Float64,1},1}:
 [1.0,2.0]
 [3.0,4.0]

The plan for Julia 0.5, is that you won’t need to prepend the element type:
just [a, b] will do.

By the way, collect is often not necessary. For example:

julia> t = 0.0:0.1:0.5
0.0:0.1:0.5

julia> sin(2*pi*t)
6-element Array{Float64,1}:
 0.0
 0.587785
 0.951057
 0.951057
 0.587785
 1.22465e-16

Best,
— Kyle
​

On Sat, Mar 19, 2016 at 3:24 PM, Kaj Wiik  wrote:

> Replying to myself...sorry.
>
> It seems that the easiest way for now is to call SciPy:
>
> using PyCall
> @pyimport scipy.interpolate as interpolate
> t = collect(0:.1:1)
> x = sin(2π*t)
> y = cos(2π*t)
> p = Array[]
> push!(p, x)
> push!(p, y)
> tck, u = interpolate.splprep(p, s=0)
> unew = collect(0:0.01:1)
> out = interpolate.splev(unew, tck)
>
> using Winston
> plot(x, y, "o", out[1], out[2], "-r")
>
> BTW, is there an easier way to create an array of vectors?
>
> Cheers,
> Kaj
>
>
> On Saturday, March 19, 2016 at 4:13:19 PM UTC+2, Kaj Wiik wrote:
>>
>>
>> Is there a Julia package that implements parametric splines?
>>
>> I noticed that the Dierckx Fortran library has an implementation but the
>> corresponding Julia package does not does not have bindings for it.
>>
>> Thanks,
>> Kaj
>>
>


Re: [julia-users] Re: Parametric splines?

2016-03-20 Thread Tomas Lycken


I tried googling for “parametric splines” but didn’t end up with a concise 
definition of what they are. If B-splines fit your needs (and it seems from 
the SciPy documentation that it might do), maybe Interpolations.jl 
 would be useful enough? The 
API is a little different, but I think this does what you’re after:

using Interpolations

t = 0:.1:.9
x = sin(2π*t)
y = cos(2π*t)
A = hcat(x,y)

itp = scale(interpolate(A, (BSpline(Cubic(Periodic())), NoInterp()), OnGrid()), 
t, 1:2)

tfine = 0:.01:1
xs, ys = [itp[t,1] for t in tfine], [itp[t,2] for t in tfine]

using Gadfly
plot(layer(x=x,y=y,Geom.point),layer(x=xs,y=ys,Geom.path))

Results on my machine:



// T

On Sunday, March 20, 2016 at 3:04:12 AM UTC+1, Kyle Barbary wrote:

Hi Kaj,
>
> A pull request adding a wrapper for this to Dierckx.jl would be most 
> welcome. This would be a matter of reading the docstring for the parcur 
> function here 
> 
>  
> and then writing a wrapper function that sets up the arguments correctly 
> and calls the Fortran function with ccall. There are a lot of examples in 
> Dierckx.jl. It’s a bit tedious but mostly straight forward. Fortunately 
> (for me anyway) knowing Fortran is not a requirement. I usually consult the 
> relevant scipy.interpolate wrapper (e.g., this one for splprep 
> )
>  
> to see how they handled things, and look at the tests in that package as 
> well.
>
> You can construct an array of vectors by prepending the element type, 
> which in your example would be Vector{Float64}. For example:
>
> julia> a = [1., 2.];
>
> julia> b = [3., 4.];
>
> julia> Vector{Float64}[a, b]
> 2-element Array{Array{Float64,1},1}:
>  [1.0,2.0]
>  [3.0,4.0]
>
> The plan for Julia 0.5, is that you won’t need to prepend the element 
> type: just [a, b] will do.
>
> By the way, collect is often not necessary. For example:
>
> julia> t = 0.0:0.1:0.5
> 0.0:0.1:0.5
>
> julia> sin(2*pi*t)
> 6-element Array{Float64,1}:
>  0.0
>  0.587785   
>  0.951057   
>  0.951057   
>  0.587785   
>  1.22465e-16
>
> Best,
> — Kyle
> ​
>
> On Sat, Mar 19, 2016 at 3:24 PM, Kaj Wiik 
> > wrote:
>
>> Replying to myself...sorry.
>>
>> It seems that the easiest way for now is to call SciPy:
>>
>> using PyCall
>> @pyimport scipy.interpolate as interpolate
>> t = collect(0:.1:1)
>> x = sin(2π*t)
>> y = cos(2π*t)
>> p = Array[]
>> push!(p, x)
>> push!(p, y)
>> tck, u = interpolate.splprep(p, s=0)
>> unew = collect(0:0.01:1)
>> out = interpolate.splev(unew, tck)
>>
>> using Winston
>> plot(x, y, "o", out[1], out[2], "-r")
>>
>> BTW, is there an easier way to create an array of vectors?
>>
>> Cheers,
>> Kaj
>>
>>
>> On Saturday, March 19, 2016 at 4:13:19 PM UTC+2, Kaj Wiik wrote:
>>>
>>>
>>> Is there a Julia package that implements parametric splines? 
>>>
>>> I noticed that the Dierckx Fortran library has an implementation but the 
>>> corresponding Julia package does not does not have bindings for it.
>>>
>>> Thanks,
>>> Kaj
>>>
>>
> ​


Re: [julia-users] Re: Parametric splines?

2016-03-21 Thread Kaj Wiik
Hi Kyle,

I'll probably try to write a wrapper when I have more time, considered it 
already but I had to finish something quite quickly. Thanks for the tips 
for using collect and arrays of arrays.

Kaj


On Sunday, March 20, 2016 at 4:04:12 AM UTC+2, Kyle Barbary wrote:
>
> Hi Kaj,
>
> A pull request adding a wrapper for this to Dierckx.jl would be most 
> welcome. This would be a matter of reading the docstring for the parcur 
> function here 
> 
>  
> and then writing a wrapper function that sets up the arguments correctly 
> and calls the Fortran function with ccall. There are a lot of examples in 
> Dierckx.jl. It’s a bit tedious but mostly straight forward. Fortunately 
> (for me anyway) knowing Fortran is not a requirement. I usually consult the 
> relevant scipy.interpolate wrapper (e.g., this one for splprep 
> )
>  
> to see how they handled things, and look at the tests in that package as 
> well.
>
> You can construct an array of vectors by prepending the element type, 
> which in your example would be Vector{Float64}. For example:
>
> julia> a = [1., 2.];
>
> julia> b = [3., 4.];
>
> julia> Vector{Float64}[a, b]
> 2-element Array{Array{Float64,1},1}:
>  [1.0,2.0]
>  [3.0,4.0]
>
> The plan for Julia 0.5, is that you won’t need to prepend the element 
> type: just [a, b] will do.
>
> By the way, collect is often not necessary. For example:
>
> julia> t = 0.0:0.1:0.5
> 0.0:0.1:0.5
>
> julia> sin(2*pi*t)
> 6-element Array{Float64,1}:
>  0.0
>  0.587785   
>  0.951057   
>  0.951057   
>  0.587785   
>  1.22465e-16
>
> Best,
> — Kyle
> ​
>
> On Sat, Mar 19, 2016 at 3:24 PM, Kaj Wiik 
> > wrote:
>
>> Replying to myself...sorry.
>>
>> It seems that the easiest way for now is to call SciPy:
>>
>> using PyCall
>> @pyimport scipy.interpolate as interpolate
>> t = collect(0:.1:1)
>> x = sin(2π*t)
>> y = cos(2π*t)
>> p = Array[]
>> push!(p, x)
>> push!(p, y)
>> tck, u = interpolate.splprep(p, s=0)
>> unew = collect(0:0.01:1)
>> out = interpolate.splev(unew, tck)
>>
>> using Winston
>> plot(x, y, "o", out[1], out[2], "-r")
>>
>> BTW, is there an easier way to create an array of vectors?
>>
>> Cheers,
>> Kaj
>>
>>
>> On Saturday, March 19, 2016 at 4:13:19 PM UTC+2, Kaj Wiik wrote:
>>>
>>>
>>> Is there a Julia package that implements parametric splines? 
>>>
>>> I noticed that the Dierckx Fortran library has an implementation but the 
>>> corresponding Julia package does not does not have bindings for it.
>>>
>>> Thanks,
>>> Kaj
>>>
>>
>

Re: [julia-users] Re: Parametric splines?

2016-03-21 Thread Kaj Wiik
Tomas,

That's exactly I was after, thanks!

Kaj

On Sunday, March 20, 2016 at 6:55:19 PM UTC+2, Tomas Lycken wrote:
>
> I tried googling for “parametric splines” but didn’t end up with a concise 
> definition of what they are. If B-splines fit your needs (and it seems from 
> the SciPy documentation that it might do), maybe Interpolations.jl 
>  would be useful enough? 
> The API is a little different, but I think this does what you’re after:
>
> using Interpolations
>
> t = 0:.1:.9
> x = sin(2π*t)
> y = cos(2π*t)
> A = hcat(x,y)
>
> itp = scale(interpolate(A, (BSpline(Cubic(Periodic())), NoInterp()), 
> OnGrid()), t, 1:2)
>
> tfine = 0:.01:1
> xs, ys = [itp[t,1] for t in tfine], [itp[t,2] for t in tfine]
>
> using Gadfly
> plot(layer(x=x,y=y,Geom.point),layer(x=xs,y=ys,Geom.path))
>
> Results on my machine:
>
>
> 
>
> // T
>
> On Sunday, March 20, 2016 at 3:04:12 AM UTC+1, Kyle Barbary wrote:
>
> Hi Kaj,
>>
>> A pull request adding a wrapper for this to Dierckx.jl would be most 
>> welcome. This would be a matter of reading the docstring for the parcur 
>> function here 
>> 
>>  
>> and then writing a wrapper function that sets up the arguments correctly 
>> and calls the Fortran function with ccall. There are a lot of examples 
>> in Dierckx.jl. It’s a bit tedious but mostly straight forward. Fortunately 
>> (for me anyway) knowing Fortran is not a requirement. I usually consult the 
>> relevant scipy.interpolate wrapper (e.g., this one for splprep 
>> )
>>  
>> to see how they handled things, and look at the tests in that package as 
>> well.
>>
>> You can construct an array of vectors by prepending the element type, 
>> which in your example would be Vector{Float64}. For example:
>>
>> julia> a = [1., 2.];
>>
>> julia> b = [3., 4.];
>>
>> julia> Vector{Float64}[a, b]
>> 2-element Array{Array{Float64,1},1}:
>>  [1.0,2.0]
>>  [3.0,4.0]
>>
>> The plan for Julia 0.5, is that you won’t need to prepend the element 
>> type: just [a, b] will do.
>>
>> By the way, collect is often not necessary. For example:
>>
>> julia> t = 0.0:0.1:0.5
>> 0.0:0.1:0.5
>>
>> julia> sin(2*pi*t)
>> 6-element Array{Float64,1}:
>>  0.0
>>  0.587785   
>>  0.951057   
>>  0.951057   
>>  0.587785   
>>  1.22465e-16
>>
>> Best,
>> — Kyle
>> ​
>>
>> On Sat, Mar 19, 2016 at 3:24 PM, Kaj Wiik  wrote:
>>
>>> Replying to myself...sorry.
>>>
>>> It seems that the easiest way for now is to call SciPy:
>>>
>>> using PyCall
>>> @pyimport scipy.interpolate as interpolate
>>> t = collect(0:.1:1)
>>> x = sin(2π*t)
>>> y = cos(2π*t)
>>> p = Array[]
>>> push!(p, x)
>>> push!(p, y)
>>> tck, u = interpolate.splprep(p, s=0)
>>> unew = collect(0:0.01:1)
>>> out = interpolate.splev(unew, tck)
>>>
>>> using Winston
>>> plot(x, y, "o", out[1], out[2], "-r")
>>>
>>> BTW, is there an easier way to create an array of vectors?
>>>
>>> Cheers,
>>> Kaj
>>>
>>>
>>> On Saturday, March 19, 2016 at 4:13:19 PM UTC+2, Kaj Wiik wrote:


 Is there a Julia package that implements parametric splines? 

 I noticed that the Dierckx Fortran library has an implementation but 
 the corresponding Julia package does not does not have bindings for it.

 Thanks,
 Kaj

>>>
>> ​
>