Skip to content

Commit

Permalink
make azccw, elplsz and method optional kwargs
Browse files Browse the repository at this point in the history
  • Loading branch information
afossa committed Jul 8, 2024
1 parent fbe2720 commit e25b99e
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 59 deletions.
1 change: 1 addition & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[deps]
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
SPICE = "5bab7191-041a-5c2e-a744-024b9c3a5062"
SPICEApplications = "e12e0822-0612-48d4-a4bb-92984dd6b6ec"

[compat]
Expand Down
24 changes: 15 additions & 9 deletions src/a.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,27 @@ function axisar(axis, angle)
end

"""
azlcpo(method, target, et, abcorr, azccw, elplsz, obspos, obsctr, obsref)
azlcpo(target, et, abcorr, obspos, obsctr, obsref; method="ELLIPSOID", azccw=true, elplsz=true)
Return the azimuth/elevation coordinates of a specified target relative to an "observer,"
where the observer has constant position in a specified reference frame.
The observer's position is provided by the calling program rather than by loaded SPK files.
### Arguments ###
- `method`: Method to obtain the surface normal vector. The only choice currently supported is `"ELLIPSOID"`
- `target`: Name of target ephemeris object
- `et`: Observation epoch
- `abcorr`: Aberration correction
- `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
- `obspos`: Observer position relative to center of motion
- `obsctr`: Center of motion of observer
- `obsref`: Body-fixed, body-centered frame of observer's center
### Keyword Arguments ###
- `method`: Method to obtain the surface normal vector. The only (and default) choice currently supported is `"ELLIPSOID"`
- `azccw`: Flag indicating how azimuth is measured. If `true` (the default), the azimuth increases in the counterclockwise direction; otherwise it increases in the clockwise direction
- `elplsz`: Flag indicating how elevation is measured. If `true` (the default), the elevation increases from the XY plane toward +Z; otherwise toward -Z
### Output ###
- `azlsta`: State of target with respect to observer, in azimuth/elevation coordinates: `azlsta = [r, az, el, dr/dt, daz/dt, del/dt]`
Expand All @@ -56,7 +59,7 @@ The observer's position is provided by the calling program rather than by loaded
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/azlcpo_c.html)
"""
function azlcpo(method, target, et, abcorr, azccw, elplsz, obspos, obsctr, obsref)
function azlcpo(target, et, abcorr, obspos, obsctr, obsref; method="ELLIPSOID", azccw=true, elplsz=true)
@checkdims 3 obspos
azlsta = Array{SpiceDouble}(undef, 6)
lt = Ref{SpiceDouble}()
Expand All @@ -67,7 +70,7 @@ function azlcpo(method, target, et, abcorr, azccw, elplsz, obspos, obsctr, obsre
end

"""
azlrec(range, az, el, azccw, elplsz)
azlrec(range, az, el; azccw=true, elplsz=true)
Convert from range, azimuth and elevation of a point to rectangular coordinates.
Expand All @@ -76,8 +79,11 @@ Convert from range, azimuth and elevation of a point to rectangular coordinates.
- `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
### Keyword Arguments ###
- `azccw`: Flag indicating how azimuth is measured. If `true` (the default), the azimuth increases in the counterclockwise direction; otherwise it increases in the clockwise direction
- `elplsz`: Flag indicating how elevation is measured. If `true` (the default), the elevation increases from the XY plane toward +Z; otherwise toward -Z
### Output ###
Expand All @@ -87,7 +93,7 @@ Convert from range, azimuth and elevation of a point to rectangular coordinates.
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/azlrec_c.html)
"""
function azlrec(range, az, el, azccw, elplsz)
function azlrec(range, az, el; azccw=true, elplsz=true)
rectan = Array{SpiceDouble}(undef, 3)
ccall((:azlrec_c, libcspice), Cvoid, (SpiceDouble, SpiceDouble, SpiceDouble, SpiceBoolean, SpiceBoolean, Ref{SpiceDouble}),
range, az, el, azccw, elplsz, rectan)
Expand Down
22 changes: 14 additions & 8 deletions src/d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ function dasrfr(handle, idwlen=128, ifnlen=256)
end

"""
dazldr(x, y, z, azccw, elplsz)
dazldr(x, y, z; azccw=true, elplsz=true)
Compute the Jacobian matrix of the transformation from rectangular to azimuth/elevation coordinates.
Expand All @@ -797,8 +797,11 @@ Compute the Jacobian matrix of the transformation from rectangular to azimuth/el
- `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
### Keyword Arguments ###
- `azccw`: Flag indicating how azimuth is measured. If `true` (the default), the azimuth increases in the counterclockwise direction; otherwise it increases in the clockwise direction
- `elplsz`: Flag indicating how elevation is measured. If `true` (the default), the elevation increases from the XY plane toward +Z; otherwise toward -Z
### Output ###
Expand All @@ -808,7 +811,7 @@ Returns the matrix of partial derivatives.
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/dazldr_c.html)
"""
function dazldr(x, y, z, azccw, elplsz)
function dazldr(x, y, z; azccw=true, elplsz=true)
jacobi = Array{SpiceDouble}(undef, 3, 3)
ccall((:dazldr_c, libcspice), Cvoid,
(SpiceDouble, SpiceDouble, SpiceDouble, SpiceBoolean, SpiceBoolean, Ref{SpiceDouble}),
Expand Down Expand Up @@ -1210,7 +1213,7 @@ end
dpr

"""
drdazl(range, az, el, azccw, elplsz)
drdazl(range, az, el; azccw=true, elplsz=true)
Compute the Jacobian matrix of the transformation from azimuth/elevation to rectangular coordinates.
Expand All @@ -1219,8 +1222,11 @@ Compute the Jacobian matrix of the transformation from azimuth/elevation to rect
- `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
### Keyword Arguments ###
- `azccw`: Flag indicating how azimuth is measured. If `true` (the default), the azimuth increases in the counterclockwise direction; otherwise it increases in the clockwise direction
- `elplsz`: Flag indicating how elevation is measured. If `true` (the default), the elevation increases from the XY plane toward +Z; otherwise toward -Z
### Output ###
Expand All @@ -1230,7 +1236,7 @@ Returns the matrix of partial derivatives.
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/drdazl_c.html)
"""
function drdazl(range, az, el, azccw, elplsz)
function drdazl(range, az, el; azccw=true, elplsz=true)
jacobi = Array{SpiceDouble}(undef, 3, 3)
ccall((:drdazl_c, libcspice), Cvoid,
(SpiceDouble, SpiceDouble, SpiceDouble, SpiceBoolean, SpiceBoolean, Ref{SpiceDouble}),
Expand Down
11 changes: 7 additions & 4 deletions src/r.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,18 @@ function raxisa(matrix)
end

"""
recazl(rectan, azccw, elplsz)
recazl(rectan; azccw=true, elplsz=true)
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
### Keyword Arguments ###
- `azccw`: Flag indicating how azimuth is measured. If `true` (the default), the azimuth increases in the counterclockwise direction; otherwise it increases in the clockwise direction
- `elplsz`: Flag indicating how elevation is measured. If `true` (the default), the elevation increases from the XY plane toward +Z; otherwise toward -Z
### Output ###
Expand All @@ -134,7 +137,7 @@ Returns a tuple consisting of:
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/recazl_c.html)
"""
function recazl(rectan, azccw, elplsz)
function recazl(rectan; azccw=true, elplsz=true)
@checkdims 3 rectan
range = Ref{SpiceDouble}()
az = Ref{SpiceDouble}()
Expand Down
24 changes: 12 additions & 12 deletions test/a.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
)
et = str2et("2003 Oct 13 06:00:00 UTC")
obspos = [-2353.621419700, -4641.341471700, 3677.052317800]
azlsta, lt = azlcpo("ELLIPSOID", "VENUS", et, "CN+S", false, true, obspos, "EARTH", "ITRF93")
azlsta, lt = azlcpo("VENUS", et, "CN+S", obspos, "EARTH", "ITRF93", azccw=false)
expected = [2.45721479e8, 5.13974044, -8.54270565e-1, -4.68189831, 7.02070016e-5, -5.39579640e-5]
@test all(azlsta expected)
finally
Expand All @@ -37,17 +37,17 @@
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))
act01 = collect(azlrec(0.0, deg2rad(0.0), deg2rad(0.0)))
act02 = collect(azlrec(1.0, deg2rad(0.0), deg2rad(0.0)))
act03 = collect(azlrec(1.0, deg2rad(270.0), deg2rad(0.0)))
act04 = collect(azlrec(1.0, deg2rad(0.0), deg2rad(-90.0)))
act05 = collect(azlrec(1.0, deg2rad(180.0), deg2rad(0.0)))
act06 = collect(azlrec(1.0, deg2rad(90.0), deg2rad(0.0)))
act07 = collect(azlrec(1.0, deg2rad(0.0), deg2rad(90.0)))
act08 = collect(azlrec(sqrt(2.0), deg2rad(315.0), deg2rad(0.0)))
act09 = collect(azlrec(sqrt(2.0), deg2rad(0.0), deg2rad(-45.0)))
act10 = collect(azlrec(sqrt(2.0), deg2rad(270.0), deg2rad(-45.0)))
act11 = collect(azlrec(sqrt(3.0), deg2rad(315.0), deg2rad(-35.264389682754654)))

@testset for i in eachindex(act01, exp01)
@test act01[i] exp01[i] atol=1e-16
Expand Down
8 changes: 4 additions & 4 deletions test/d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,11 @@
end
end
@testset "dazldr" begin
out1 = dazldr(1.0, 1.0, 0.0, true, true)
out1 = dazldr(1.0, 1.0, 0.0)
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)
out2 = dazldr(1.0, 1.0, 0.0, azccw=false, elplsz=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]
Expand Down Expand Up @@ -361,11 +361,11 @@
@test SPICE._dpr() == rad2deg(1.0)
end
@testset "drdazl" begin
out1 = drdazl(1.0, deg2rad(45.0), 0.0, true, true)
out1 = drdazl(1.0, deg2rad(45.0), 0.0)
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)
out2 = drdazl(1.0, deg2rad(45.0), 0.0, azccw=false, elplsz=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]
Expand Down
44 changes: 22 additions & 22 deletions test/r.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@ using LinearAlgebra: I
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)
@test all(recazl([0.0, 0.0, 0.0], azccw=false, elplsz=false) .≈ exp01)
@test all(recazl([1.0, 0.0, 0.0], azccw=false, elplsz=false) .≈ exp02)
@test all(recazl([0.0, 1.0, 0.0], azccw=false, elplsz=false) .≈ exp03)
@test all(recazl([0.0, 0.0, 1.0], azccw=false, elplsz=false) .≈ exp04)
@test all(recazl([-1.0, 0.0, 0.0], azccw=false, elplsz=false) .≈ exp05)
@test all(recazl([0.0, -1.0, 0.0], azccw=false, elplsz=false) .≈ exp06)
@test all(recazl([0.0, 0.0, -1.0], azccw=false, elplsz=false) .≈ exp07)
@test all(recazl([1.0, 1.0, 0.0], azccw=false, elplsz=false) .≈ exp08)
@test all(recazl([1.0, 0.0, 1.0], azccw=false, elplsz=false) .≈ exp09)
@test all(recazl([0.0, 1.0, 1.0], azccw=false, elplsz=false) .≈ exp10)
@test all(recazl([1.0, 1.0, 1.0], azccw=false, elplsz=false) .≈ exp11)

exp21 = [0.0, 0.0, 0.0]
exp22 = [1.0, 0.0, 0.0]
Expand All @@ -68,17 +68,17 @@ using LinearAlgebra: I
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)
@test all(recazl([0.0, 0.0, 0.0]) .≈ exp21)
@test all(recazl([1.0, 0.0, 0.0]) .≈ exp22)
@test all(recazl([0.0, 1.0, 0.0]) .≈ exp23)
@test all(recazl([0.0, 0.0, 1.0]) .≈ exp24)
@test all(recazl([-1.0, 0.0, 0.0]) .≈ exp25)
@test all(recazl([0.0, -1.0, 0.0]) .≈ exp26)
@test all(recazl([0.0, 0.0, -1.0]) .≈ exp27)
@test all(recazl([1.0, 1.0, 0.0]) .≈ exp28)
@test all(recazl([1.0, 0.0, 1.0]) .≈ exp29)
@test all(recazl([0.0, 1.0, 1.0]) .≈ exp30)
@test all(recazl([1.0, 1.0, 1.0]) .≈ exp31)
end
@testset "reccyl" begin
expected1 = (0.0, 0.0, 0.0)
Expand Down

0 comments on commit e25b99e

Please sign in to comment.