Skip to content

Commit

Permalink
Wrappers for azlrec, dazldr, drdazl, recazl (#27)
Browse files Browse the repository at this point in the history
* added azlrec, recazl, dazldr, drdazl routines

* added tests for azlrec

* added tests for recazl

* added tests for drdazl and dazldr

* extend docstrings for azlrec, dazldr, drdazl, recazl

* fix docs in reclat

* tentative fix to CI.yml

* fix env for SPICEApplication tests
  • Loading branch information
afossa authored Jun 29, 2024
1 parent ce373f4 commit 4d26662
Show file tree
Hide file tree
Showing 9 changed files with 273 additions and 12 deletions.
1 change: 0 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ jobs:
${{ runner.os }}-
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
with:
env:
GROUP: ${{ matrix.package}}
- uses: julia-actions/julia-processcoverage@v1
Expand Down
5 changes: 3 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

[extras]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
RemoteFiles = "cbe49d4c-5af1-5b60-bb70-0a60aa018e1b"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[compat]
julia = "1.6"
CSPICE_jll = "67"

[targets]
test = ["LinearAlgebra", "Test", "Random", "RemoteFiles"]
test = ["LinearAlgebra", "Pkg", "Random", "RemoteFiles", "Test"]
32 changes: 31 additions & 1 deletion src/a.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export axisar
export
axisar,
azlrec

"""
axisar(axis, angle)
Expand All @@ -24,3 +26,31 @@ function axisar(axis, angle)
ccall((:axisar_c, libcspice), Cvoid, (Ref{SpiceDouble}, SpiceDouble, Ref{SpiceDouble}), axis, angle, r)
permutedims(r)
end

"""
azlrec(range, az, el, azccw, elplsz)
Convert from range, azimuth and elevation of a point to rectangular coordinates.
### Arguments ###
- `range`: Distance of the point from the origin
- `az`: Azimuth in radians
- `el`: Elevation in radians
- `azccw`: Flag indicating how azimuth is measured. If `true`, the azimuth increases in the counterclockwise direction; otherwise it increases in the clockwise direction
- `elplsz`: Flag indicating how elevation is measured. If `true`, the elevation increases from the XY plane toward +Z; otherwise toward -Z
### Output ###
- `rectan`: Rectangular coordinates of the point
### References ###
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/azlrec_c.html)
"""
function azlrec(range, az, el, azccw, elplsz)
rectan = Array{SpiceDouble}(undef, 3)
ccall((:azlrec_c, libcspice), Cvoid, (SpiceDouble, SpiceDouble, SpiceDouble, SpiceBoolean, SpiceBoolean, Ref{SpiceDouble}),
range, az, el, azccw, elplsz, rectan)
rectan
end
62 changes: 62 additions & 0 deletions src/d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export
dasopr,
dasopw,
dasrfr,
dazldr,
dcyldr,
deltet,
dgeodr,
Expand All @@ -43,6 +44,7 @@ export
dpmax,
dpmin,
dpr,
drdazl,
drdcyl,
drdgeo,
drdlat,
Expand Down Expand Up @@ -785,6 +787,36 @@ function dasrfr(handle, idwlen=128, ifnlen=256)
Int(nresvr[]), Int(nresvc[]), Int(ncomr[]), Int(ncomc[])
end

"""
dazldr(x, y, z, azccw, elplsz)
Compute the Jacobian matrix of the transformation from rectangular to azimuth/elevation coordinates.
### Arguments ###
- `x`: X-coordinate of point
- `y`: Y-coordinate of point
- `z`: Z-coordinate of point
- `azccw`: Flag indicating how azimuth is measured. If `true`, the azimuth increases in the counterclockwise direction; otherwise it increases in the clockwise direction
- `elplsz`: Flag indicating how elevation is measured. If `true`, the elevation increases from the XY plane toward +Z; otherwise toward -Z
### Output ###
Returns the matrix of partial derivatives.
### References ###
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/dazldr_c.html)
"""
function dazldr(x, y, z, azccw, elplsz)
jacobi = Array{SpiceDouble}(undef, 3, 3)
ccall((:dazldr_c, libcspice), Cvoid,
(SpiceDouble, SpiceDouble, SpiceDouble, SpiceBoolean, SpiceBoolean, Ref{SpiceDouble}),
x, y, z, azccw, elplsz, jacobi)
handleerror()
permutedims(jacobi)
end

"""
dcyldr(x, y, z)
Expand Down Expand Up @@ -1177,6 +1209,36 @@ end
"""
dpr

"""
drdazl(range, az, el, azccw, elplsz)
Compute the Jacobian matrix of the transformation from azimuth/elevation to rectangular coordinates.
### Arguments ###
- `range`: Distance of a point from the origin
- `az`: Azimuth of input point in radians
- `el`: Elevation of input point in radians
- `azccw`: Flag indicating how azimuth is measured. If `true`, the azimuth increases in the counterclockwise direction; otherwise it increases in the clockwise direction
- `elplsz`: Flag indicating how elevation is measured. If `true`, the elevation increases from the XY plane toward +Z; otherwise toward -Z
### Output ###
Returns the matrix of partial derivatives.
### References ###
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/drdazl_c.html)
"""
function drdazl(range, az, el, azccw, elplsz)
jacobi = Array{SpiceDouble}(undef, 3, 3)
ccall((:drdazl_c, libcspice), Cvoid,
(SpiceDouble, SpiceDouble, SpiceDouble, SpiceBoolean, SpiceBoolean, Ref{SpiceDouble}),
range, az, el, azccw, elplsz, jacobi)
handleerror()
permutedims(jacobi)
end

"""
drdcyl(r, lon, z)
Expand Down
39 changes: 37 additions & 2 deletions src/r.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export
radrec,
rav2xf,
raxisa,
recazl,
reccyl,
recgeo,
reclat,
Expand Down Expand Up @@ -110,6 +111,40 @@ function raxisa(matrix)
axis, angle[]
end

"""
recazl(rectan, azccw, elplsz)
Convert rectangular coordinates of a point to range, azimuth and elevation.
### Arguments ###
- `rectan`: Rectangular coordinates of a point
- `azccw`: Flag indicating how azimuth is measured. If `true`, the azimuth increases in the counterclockwise direction; otherwise it increases in the clockwise direction
- `elplsz`: Flag indicating how elevation is measured. If `true`, the elevation increases from the XY plane toward +Z; otherwise toward -Z
### Output ###
Returns a tuple consisting of:
- `range`: Distance of the point from the origin
- `az`: Azimuth in radians
- `el`: Elevation in radians
### References ###
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/recazl_c.html)
"""
function recazl(rectan, azccw, elplsz)
@checkdims 3 rectan
range = Ref{SpiceDouble}()
az = Ref{SpiceDouble}()
el = Ref{SpiceDouble}()
ccall((:recazl_c, libcspice), Cvoid,
(Ref{SpiceDouble}, SpiceBoolean, SpiceBoolean, Ref{SpiceDouble}, Ref{SpiceDouble}, Ref{SpiceDouble}),
collect(rectan), azccw, elplsz, range, az, el)
range[], az[], el[]
end

"""
reccyl(rectan)
Expand Down Expand Up @@ -189,8 +224,8 @@ Convert from rectangular coordinates to latitudinal coordinates.
Returns a tuple consisting of:
- `rad`: Distance of the point from the origin
- `lon`: Planetographic longitude of the point (radians)
- `lat`: Planetographic latitude of the point (radians)
- `lon`: Longitude of the point (radians)
- `lat`: Latitude of the point (radians)
### References ###
Expand Down
71 changes: 66 additions & 5 deletions test/a.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,68 @@
@testset "A" begin
axis = [0.0, 0.0, 1.0]
output = axisar(axis, π/2)
expected = [0.0 -1.0 0.0; 1.0 0.0 0.0; 0.0 0.0 1.0]
@test output expected
@test_throws ArgumentError axisar(axis[1:2], π/2)
@testset "axisar" begin
axis = [0.0, 0.0, 1.0]
output = axisar(axis, π/2)
expected = [0.0 -1.0 0.0; 1.0 0.0 0.0; 0.0 0.0 1.0]
@test output expected
@test_throws ArgumentError axisar(axis[1:2], π/2)
end
@testset "azlrec" begin
exp01 = [0.0, 0.0, 0.0]
exp02 = [1.0, 0.0, 0.0]
exp03 = [-0.0, -1.0, 0.0]
exp04 = [0.0, 0.0, -1.0]
exp05 = [-1.0, 0.0, 0.0]
exp06 = [0.0, 1.0, 0.0]
exp07 = [0.0, 0.0, 1.0]
exp08 = [1.0, -1.0, 0.0]
exp09 = [1.0, 0.0, -1.0]
exp10 = [-0.0, -1.0, -1.0]
exp11 = [1.0, -1.0, -1.0]

act01 = collect(azlrec(0.0, deg2rad(0.0), deg2rad(0.0), true, true))
act02 = collect(azlrec(1.0, deg2rad(0.0), deg2rad(0.0), true, true))
act03 = collect(azlrec(1.0, deg2rad(270.0), deg2rad(0.0), true, true))
act04 = collect(azlrec(1.0, deg2rad(0.0), deg2rad(-90.0), true, true))
act05 = collect(azlrec(1.0, deg2rad(180.0), deg2rad(0.0), true, true))
act06 = collect(azlrec(1.0, deg2rad(90.0), deg2rad(0.0), true, true))
act07 = collect(azlrec(1.0, deg2rad(0.0), deg2rad(90.0), true, true))
act08 = collect(azlrec(sqrt(2.0), deg2rad(315.0), deg2rad(0.0), true, true))
act09 = collect(azlrec(sqrt(2.0), deg2rad(0.0), deg2rad(-45.0), true, true))
act10 = collect(azlrec(sqrt(2.0), deg2rad(270.0), deg2rad(-45.0), true, true))
act11 = collect(azlrec(sqrt(3.0), deg2rad(315.0), deg2rad(-35.264389682754654), true, true))

@testset for i in eachindex(act01, exp01)
@test act01[i] exp01[i] atol=1e-16
end
@testset for i in eachindex(act02, exp02)
@test act02[i] exp02[i] atol=1e-16
end
@testset for i in eachindex(act03, exp03)
@test act03[i] exp03[i] atol=1e-15
end
@testset for i in eachindex(act04, exp04)
@test act04[i] exp04[i] atol=1e-16
end
@testset for i in eachindex(act05, exp05)
@test act05[i] exp05[i] atol=1e-15
end
@testset for i in eachindex(act06, exp06)
@test act06[i] exp06[i] atol=1e-16
end
@testset for i in eachindex(act07, exp07)
@test act07[i] exp07[i] atol=1e-16
end
@testset for i in eachindex(act08, exp08)
@test act08[i] exp08[i] atol=1e-15
end
@testset for i in eachindex(act09, exp09)
@test act09[i] exp09[i] atol=1e-15
end
@testset for i in eachindex(act10, exp10)
@test act10[i] exp10[i] atol=1e-15
end
@testset for i in eachindex(act11, exp11)
@test act11[i] exp11[i] atol=1e-15
end
end
end
24 changes: 24 additions & 0 deletions test/d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,18 @@
kclear()
end
end
@testset "dazldr" begin
out1 = dazldr(1.0, 1.0, 0.0, true, true)
exp1 = [sqrt(2.0)/2.0 sqrt(2.0)/2.0 0.0;
-0.5 0.5 0.0;
-0.0 -0.0 sqrt(2.0)/2.0]
out2 = dazldr(1.0, 1.0, 0.0, false, false)
exp2 = [sqrt(2.0)/2.0 sqrt(2.0)/2.0 0.0;
0.5 -0.5 -0.0;
0.0 0.0 -sqrt(2.0)/2.0]
@test out1 exp1
@test out2 exp2
end
@testset "dcyldr" begin
output = dcyldr(1.0, 0.0, 0.0)
expected = [1.0 0.0 0.0;
Expand Down Expand Up @@ -348,6 +360,18 @@
@testset "dpr" begin
@test SPICE._dpr() == rad2deg(1.0)
end
@testset "drdazl" begin
out1 = drdazl(1.0, deg2rad(45.0), 0.0, true, true)
exp1 = [sqrt(2.0)/2.0 -sqrt(2.0)/2.0 -0.0;
sqrt(2.0)/2.0 sqrt(2.0)/2.0 -0.0;
0.0 0.0 1.0]
out2 = drdazl(1.0, deg2rad(45.0), 0.0, false, false)
exp2 = [sqrt(2.0)/2.0 -sqrt(2.0)/2.0 -0.0;
-sqrt(2.0)/2.0 -sqrt(2.0)/2.0 0.0;
-0.0 -0.0 -1.0]
@test out1 exp1
@test out2 exp2
end
@testset "drdcyl" begin
output = drdcyl(1.0, deg2rad(180.0), 1.0)
expected = [-1.0 0.0 0.0;
Expand Down
49 changes: 49 additions & 0 deletions test/r.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,55 @@ using LinearAlgebra: I
@test_throws SpiceError raxisa(randn(3, 3))
@test_throws ArgumentError raxisa(randn(2, 2))
end
@testset "recazl" begin
exp01 = [0.0, 0.0, 0.0]
exp02 = [1.0, 0.0, 0.0]
exp03 = [1.0, deg2rad(270.0), 0.0]
exp04 = [1.0, 0.0, deg2rad(-90.0)]
exp05 = [1.0, deg2rad(180.0), 0.0]
exp06 = [1.0, deg2rad(90.0), 0.0]
exp07 = [1.0, 0.0, deg2rad(90.0)]
exp08 = [sqrt(2.0), deg2rad(315.0), 0.0]
exp09 = [sqrt(2.0), 0.0, deg2rad(-45.0)]
exp10 = [sqrt(2.0), deg2rad(270.0), deg2rad(-45.0)]
exp11 = [sqrt(3.0), deg2rad(315.0), deg2rad(-35.264389682754654)]

@test all(recazl([0.0, 0.0, 0.0], false, false) .≈ exp01)
@test all(recazl([1.0, 0.0, 0.0], false, false) .≈ exp02)
@test all(recazl([0.0, 1.0, 0.0], false, false) .≈ exp03)
@test all(recazl([0.0, 0.0, 1.0], false, false) .≈ exp04)
@test all(recazl([-1.0, 0.0, 0.0], false, false) .≈ exp05)
@test all(recazl([0.0, -1.0, 0.0], false, false) .≈ exp06)
@test all(recazl([0.0, 0.0, -1.0], false, false) .≈ exp07)
@test all(recazl([1.0, 1.0, 0.0], false, false) .≈ exp08)
@test all(recazl([1.0, 0.0, 1.0], false, false) .≈ exp09)
@test all(recazl([0.0, 1.0, 1.0], false, false) .≈ exp10)
@test all(recazl([1.0, 1.0, 1.0], false, false) .≈ exp11)

exp21 = [0.0, 0.0, 0.0]
exp22 = [1.0, 0.0, 0.0]
exp23 = [1.0, deg2rad(90.0), 0.0]
exp24 = [1.0, 0.0, deg2rad(90.0)]
exp25 = [1.0, deg2rad(180.0), 0.0]
exp26 = [1.0, deg2rad(270.0), 0.0]
exp27 = [1.0, 0.0, deg2rad(-90.0)]
exp28 = [sqrt(2.0), deg2rad(45.0), 0.0]
exp29 = [sqrt(2.0), 0.0, deg2rad(45.0)]
exp30 = [sqrt(2.0), deg2rad(90.0), deg2rad(45.0)]
exp31 = [sqrt(3.0), deg2rad(45.0), deg2rad(35.264389682754654)]

@test all(recazl([0.0, 0.0, 0.0], true, true) .≈ exp21)
@test all(recazl([1.0, 0.0, 0.0], true, true) .≈ exp22)
@test all(recazl([0.0, 1.0, 0.0], true, true) .≈ exp23)
@test all(recazl([0.0, 0.0, 1.0], true, true) .≈ exp24)
@test all(recazl([-1.0, 0.0, 0.0], true, true) .≈ exp25)
@test all(recazl([0.0, -1.0, 0.0], true, true) .≈ exp26)
@test all(recazl([0.0, 0.0, -1.0], true, true) .≈ exp27)
@test all(recazl([1.0, 1.0, 0.0], true, true) .≈ exp28)
@test all(recazl([1.0, 0.0, 1.0], true, true) .≈ exp29)
@test all(recazl([0.0, 1.0, 1.0], true, true) .≈ exp30)
@test all(recazl([1.0, 1.0, 1.0], true, true) .≈ exp31)
end
@testset "reccyl" begin
expected1 = (0.0, 0.0, 0.0)
expected2 = (1.0, π/2, 0.0)
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ if get(ENV, "GROUP", "SPICE") == "SPICE"

else
import Pkg
Pkg.activate(joinpath(@__DIR__, "lib", ENV["GROUP"]))
Pkg.activate(joinpath(dirname(@__DIR__), "lib", ENV["GROUP"]))
Pkg.instantiate()
Pkg.test()
end

0 comments on commit 4d26662

Please sign in to comment.