Skip to content

Commit

Permalink
Fix x and start r
Browse files Browse the repository at this point in the history
  • Loading branch information
helgee committed Feb 8, 2019
1 parent 6b990a6 commit 76ae306
Show file tree
Hide file tree
Showing 5 changed files with 298 additions and 77 deletions.
8 changes: 4 additions & 4 deletions function-tracker.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@
* [ ] [GETCML_C](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/getcml_c.html) - Get the command line
* [ ] [GETELM_C](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/getelm_c.html) - Get the components from two-line elements
* [ ] [GETFAT_C](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/getfat_c.html) - Get file architecture and type
* [ ] [GETFOV_C](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/getfov_c.html) - Get instrument FOV parameters
* [x] [GETFOV_C](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/getfov_c.html) - Get instrument FOV parameters
* [ ] [GETMSG_C](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/getmsg_c.html) - Get Error Message
* [ ] [GFBAIL_C](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/gfbail_c.html) - GF, interrupt signal indicator
* [ ] [GFCLRH_C](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/gfclrh_c.html) - GF, clear interrupt signal handler status
Expand Down Expand Up @@ -483,7 +483,7 @@
* [ ] [SHELLD_C](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/shelld_c.html) - Shell sort a double precision array
* [ ] [SHELLI_C](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/shelli_c.html) - Shell sort an integer array
* [ ] [SIGERR_C](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/sigerr_c.html) - Signal Error Condition
* [ ] [SINCPT_C](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/sincpt_c.html) - Surface intercept
* [x] [SINCPT_C](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/sincpt_c.html) - Surface intercept
* [ ] [SIZE_C](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/size_c.html) - Size of a cell
* [ ] [SPD_C](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/spd_c.html) - Seconds per day
* [ ] [SPHCYL_C](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/sphcyl_c.html) - Spherical to cylindrical coordinates
Expand Down Expand Up @@ -552,9 +552,9 @@
* [ ] [SUMAD_C](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/sumad_c.html) - Sum of a double precision array
* [ ] [SUMAI_C](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/sumai_c.html) - Sum of an integer array
* [ ] [SURFNM_C](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/surfnm_c.html) - Surface normal vector on an ellipsoid
* [ ] [SURFPT_C](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/surfpt_c.html) - Surface point on an ellipsoid
* [x] [SURFPT_C](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/surfpt_c.html) - Surface point on an ellipsoid
* [ ] [SURFPV_C](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/surfpv_c.html) - Surface point and velocity
* [ ] [SWPOOL_C](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/swpool_c.html) - Set watch on a pool variable
* [x] [SWPOOL_C](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/swpool_c.html) - Set watch on a pool variable
* [ ] [SXFORM_C](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/sxform_c.html) - State Transformation Matrix
* [ ] [SZPOOL_C](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/szpool_c.html) - Get size limitations of the kernel pool

Expand Down
16 changes: 8 additions & 8 deletions src/r.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export
export
rav2xf,
reclat,
recpgr,
Expand Down Expand Up @@ -28,8 +28,8 @@ function rav2xf(rot, av)
xform = Array{SpiceDouble}(undef, 6, 6)
ccall((:rav2xf_c, libcspice), Cvoid,
(Ptr{SpiceDouble}, Ptr{SpiceDouble}, Ptr{SpiceDouble}),
rot, av, xform)
xform
permutedims(rot), av, xform)
permutedims(xform)
end

"""
Expand Down Expand Up @@ -99,10 +99,10 @@ end
"""
rotate(angle, iaxis)
Calculate the 3x3 rotation matrix generated by a rotation
of a specified angle about a specified axis. This rotation
is thought of as rotating the coordinate system.
Calculate the 3x3 rotation matrix generated by a rotation
of a specified angle about a specified axis. This rotation
is thought of as rotating the coordinate system.
### Arguments ###
- `angle`: Angle of rotation (radians)
Expand All @@ -127,7 +127,7 @@ end
Convert rectangular coordinates to range, right ascension, and
declination.
### Arguments ###
- `rectan`: Rectangular coordinates of a point
Expand Down
7 changes: 5 additions & 2 deletions src/x.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ that indicates whether these are a unique representation.
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/xf2eul_c.html)
"""
function xf2eul(xform, axisa, axisb, axisc)
size(xform) != (6, 6) && throw(ArgumentError("`xform` must be a 6x6 matrix."))
eulang = Array{SpiceDouble}(undef, 6)
unique = Ref{SpiceBoolean}()
ccall((:xf2eul_c, libcspice), Cvoid,
Expand Down Expand Up @@ -57,12 +58,13 @@ associated with `xform`.
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/xf2rav_c.html)
"""
function xf2rav(xform)
size(xform) != (6, 6) && throw(ArgumentError("`xform` must be a 6x6 matrix."))
rot = Array{SpiceDouble}(undef, 3, 3)
av = Array{SpiceDouble}(undef, 3)
ccall((:xf2rav_c, libcspice), Cvoid,
(Ptr{SpiceDouble}, Ptr{SpiceDouble}, Ptr{SpiceDouble}),
xform, rot, av)
rot, av
permutedims(xform), rot, av)
permutedims(rot), av
end

"""
Expand All @@ -86,6 +88,7 @@ Returns the converted output state.
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/xfmsta_c.html)
"""
function xfmsta(input_state, input_coord_sys, output_coord_sys, body)
length(input_state) != 6 && throw(ArgumentError("Lenght of `input_state` must be 6."))
output_state = Array{SpiceDouble}(undef, 6)
ccall((:xfmsta_c, libcspice), Cvoid,
(Ptr{SpiceDouble}, Cstring, Cstring, Cstring, Ptr{SpiceDouble}),
Expand Down
272 changes: 237 additions & 35 deletions test/r.jl
Original file line number Diff line number Diff line change
@@ -1,54 +1,256 @@
@testset "R" begin
@testset "rotate" begin
act = rotate/4, 3)
exp = [sqrt(2)/2.0 sqrt(2)/2.0 0.0;
-sqrt(2)/2.0 sqrt(2)/2.0 0.0;
0.0 0.0 1.0]
@testset for i in eachindex(act, exp)
@test act[i] exp[i]
@testset "R" begin
#= @testset "radrec" begin =#
#= npt.assert_array_almost_equal([1.0, 0.0, 0.0], radrec(1.0, 0.0, 0.0)) =#
#= npt.assert_array_almost_equal([0.0, 1.0, 0.0], radrec(1.0, 90.0 * rpd(), 0.0)) =#
#= npt.assert_array_almost_equal([0.0, 0.0, 1.0], radrec(1.0, 0.0, 90.0 * rpd())) =#
#= =#
#= =#
@testset "rav2xf" begin
e = [1.0, 0.0, 0.0]
rz = [0.0 1.0 0.0; -1.0 0.0 0.0; 0.0 0.0 1.0]
exp = [0.0 1.0 0.0 0.0 0.0 0.0;
-1.0 0.0 0.0 0.0 0.0 0.0;
0.0 0.0 1.0 0.0 0.0 0.0;
0.0 0.0 1.0 0.0 1.0 0.0;
0.0 0.0 0.0 -1.0 0.0 0.0;
0.0 -1.0 0.0 0.0 0.0 1.0]
act = rav2xf(rz, e)
@testset for i in eachindex(exp, act)
@test exp[i] act[i]
end
end
#= @testset "raxisa" begin =#
#= axis = [1.0, 2.0, 3.0] =#
#= angle = 0.1 * twopi() =#
#= rotate_matrix = axisar(axis, angle) =#
#= axout, angout = raxisa(rotate_matrix) =#
#= expectedAngout = [0.26726124, 0.53452248, 0.80178373] =#
#= npt.assert_approx_equal(angout, 0.62831853, significant=7) =#
#= npt.assert_array_almost_equal(axout, expectedAngout) =#
#= =#
#= =#
#= @testset "reccyl" begin =#
#= expected1 = array([0.0, 0.0, 0.0]) =#
#= expected2 = array([1.0, 90.0 * rpd(), 0.0]) =#
#= expected3 = array([1.0, 270.0 * rpd(), 0.0]) =#
#= npt.assert_array_almost_equal(expected1, reccyl([0.0, 0.0, 0.0]), decimal=7) =#
#= npt.assert_array_almost_equal(expected2, reccyl([0.0, 1.0, 0.0]), decimal=7) =#
#= npt.assert_array_almost_equal(expected3, reccyl([0.0, -1.0, 0.0]), decimal=7) =#
#= =#
#= =#
#= @testset "recgeo" begin =#
#= kclear() =#
#= furnsh(CoreKernels.testMetaKernel) =#
#= num_vals, radii = bodvrd("EARTH", "RADII", 3) =#
#= flat = (radii[0] - radii[2]) / radii[0] =#
#= x = [-2541.748162, 4780.333036, 3360.428190] =#
#= lon, lat, alt = recgeo(x, radii[0], flat) =#
#= actual = [lon * dpr(), lat * dpr(), alt] =#
#= expected = [118.000000, 32.000000, 0.001915518] =#
#= npt.assert_array_almost_equal(actual, expected, decimal=4) =#
#= kclear() =#
#= =#
#= =#
@testset "reclat" begin
act1 = reclat([1.0, 0.0, 0.0])
act2 = reclat([0.0, 1.0, 0.0])
act3 = reclat((-1.0, 0.0, 0.0))
@test [act1[1], act1[2], act1[3]] [1.0, 0.0, 0.0]
@test [act2[1], act2[2], act2[3]] [1.0, deg2rad(90.0), 0.0]
@test [act3[1], act3[2], act3[3]] [1.0, deg2rad(180.0), 0.0]
end
@testset "recpgr" begin
try
furnsh(path(CORE, :lsk), path(CORE, :pck), path(CORE, :spk))
radii = bodvrd("MARS", "RADII", 3)
flat = (radii[1] - radii[3]) / radii[1]
x = [0.0, -2620.678914818178, 2592.408908856967]
lon, lat, alt = recpgr("MARS", x, radii[1], flat)
actual = [rad2deg(lon), rad2deg(lat), alt]
expected = [90., 45, 300]
@test actual expected
finally
kclear()
end
end
@testset "recrad" begin
act1 = collect(recrad([1.0, 0.0, 0.0]))
act2 = collect(recrad([0.0, 1.0, 0.0]))
act3 = collect(recrad([0.0, 0.0, 1.0]))
exp1=[1.0, 0.0, 0.0]
exp1 = [1.0, 0.0, 0.0]
@testset for i in eachindex(act1, exp1)
@test act1[i] exp1[i]
end
exp2=[1.0, deg2rad(90), 0.0]
exp2 = [1.0, deg2rad(90), 0.0]
@testset for i in eachindex(act2, exp2)
@test act2[i] exp2[i]
end
exp3=[1.0, 0.0, deg2rad(90)]
exp3 = [1.0, 0.0, deg2rad(90)]
@testset for i in eachindex(act3, exp3)
@test act3[i] exp3[i]
end
end
@testset "recpgr" begin
try
furnsh(
path(CORE, :lsk),
path(CORE, :pck),
path(CORE, :spk),
)
radii = bodvrd("MARS", "RADII", 3)
flat = (radii[1] - radii[3])/ radii[1]
x = [0.0, -2620.678914818178, 2592.408908856967]
lon, lat, alt = recpgr("mars", x, radii[1], flat)
actual = [rad2deg(lon), rad2deg(lat), alt]
expected = [90., 45, 300]
@test actual expected
finally
kclear()
#= @testset "recsph" begin =#
#= v1 = array([-1.0, 0.0, 0.0]) =#
#= assert recsph(v1) == (1.0, pi/2, pi) =#
#= =#
#= =#
#= @testset "removc" begin =#
#= cell = cell_char(10, 10) =#
#= items = ["one", "two", "three", "four"] =#
#= for i in items: =#
#= insrtc(i, cell) =#
#= removeItems = ["three", "four"] =#
#= for r in removeItems: =#
#= removc(r, cell) =#
#= expected = ["one", "two"] =#
#= assert expected == [x for x in cell] =#
#= =#
#= =#
#= @testset "removd" begin =#
#= cell = cell_double(10) =#
#= items = [0.0, 1.0, 1.0, 2.0, 3.0, 5.0, 8.0, 13.0, 21.0] =#
#= for i in items: =#
#= insrtd(i, cell) =#
#= removeItems = [0.0, 2.0, 4.0, 6.0, 8.0, 12.0] =#
#= for r in removeItems: =#
#= removd(r, cell) =#
#= expected = [1.0, 3.0, 5.0, 13.0, 21.0] =#
#= for x, y in zip(cell, expected): =#
#= assert x == y =#
#= =#
#= =#
#= @testset "removi" begin =#
#= cell = cell_int(10) =#
#= items = [0, 1, 1, 2, 3, 5, 8, 13, 21] =#
#= for i in items: =#
#= insrti(i, cell) =#
#= removeItems = [0, 2, 4, 6, 8, 12] =#
#= for r in removeItems: =#
#= removi(r, cell) =#
#= expected = [1, 3, 5, 13, 21] =#
#= for x, y in zip(cell, expected): =#
#= assert x == y =#
#= =#
#= =#
#= @testset "reordc" begin =#
#= array = ["one", "three", "two", "zero"] =#
#= iorder = [3, 0, 2, 1] =#
#= outarray = reordc(iorder, 4, 5, array) =#
#= # reordc appears to be broken... =#
#= with pytest.raises(AssertionError): =#
#= assert outarray == ["zero", "one", "two", "three"] =#
#= =#
#= @testset "reordd" begin =#
#= array = [1.0, 3.0, 2.0] =#
#= iorder = [0, 2, 1] =#
#= outarray = reordd(iorder, 3, array) =#
#= npt.assert_array_almost_equal(outarray, [1.0, 2.0, 3.0]) =#
#= =#
#= =#
#= @testset "reordi" begin =#
#= array = [1, 3, 2] =#
#= iorder = [0, 2, 1] =#
#= outarray = reordi(iorder, 3, array) =#
#= npt.assert_array_almost_equal(outarray, [1, 2, 3]) =#
#= =#
#= =#
#= @testset "reordl" begin =#
#= array = [True, True, False] =#
#= iorder = [0, 2, 1] =#
#= outarray = reordl(iorder, 3, array) =#
#= npt.assert_array_almost_equal(outarray, [True, False, True]) =#
#= =#
#= =#
#= @testset "repmc" begin =#
#= stringtestone = "The truth is #" =#
#= outstringone = repmc(stringtestone, "#", "SPICE") =#
#= assert outstringone == "The truth is SPICE" =#
#= =#
#= =#
#= @testset "repmct" begin =#
#= stringtestone = "The value is #" =#
#= outstringone = repmct(stringtestone, '#', 5, 'U') =#
#= outstringtwo = repmct(stringtestone, '#', 5, 'l') =#
#= assert outstringone == "The value is FIVE" =#
#= assert outstringtwo == "The value is five" =#
#= =#
#= =#
#= @testset "repmd" begin =#
#= stringtestone = "The value is #" =#
#= outstringone = repmd(stringtestone, '#', 5.0e11, 1) =#
#= assert outstringone == "The value is 5.E+11" =#
#= =#
#= =#
#= @testset "repmf" begin =#
#= stringtestone = "The value is #" =#
#= outstringone = repmf(stringtestone, '#', 5.0e3, 5, 'f') =#
#= outstringtwo = repmf(stringtestone, '#', -5.2e-9, 3, 'e') =#
#= assert outstringone == "The value is 5000.0" =#
#= assert outstringtwo == "The value is -5.20E-09" =#
#= =#
#= =#
#= @testset "repmi" begin =#
#= stringtest = "The value is <opcode>" =#
#= outstring = repmi(stringtest, "<opcode>", 5) =#
#= assert outstring == "The value is 5" =#
#= =#
#= =#
#= @testset "repmot" begin =#
#= stringtestone = "The value is #" =#
#= outstringone = repmot(stringtestone, '#', 5, 'U') =#
#= outstringtwo = repmot(stringtestone, '#', 5, 'l') =#
#= assert outstringone == "The value is FIFTH" =#
#= assert outstringtwo == "The value is fifth" =#
#= =#
#= =#
#= @testset "reset" begin =#
#= reset() =#
#= assert not failed() =#
#= =#
#= =#
#= @testset "return_c" begin =#
#= reset() =#
#= assert not return_c() =#
#= reset() =#
#= =#
#= =#
@testset "rotate" begin
act = rotate/ 4, 3)
exp = [sqrt(2) / 2.0 sqrt(2) / 2.0 0.0;
-sqrt(2) / 2.0 sqrt(2) / 2.0 0.0;
0.0 0.0 1.0]
@testset for i in eachindex(act, exp)
@test act[i] exp[i]
end
end
@testset "reclat" begin
act1 = reclat([1.0, 0.0, 0.0])
act2 = reclat([0.0, 1.0, 0.0])
act3 = reclat((-1.0, 0.0, 0.0))
@test [act1[1], act1[2], act1[3]] [1.0, 0.0, 0.0]
@test [act2[1], act2[2], act2[3]] [1.0, deg2rad(90.0), 0.0]
@test [act3[1], act3[2], act3[3]] [1.0, deg2rad(180.0), 0.0]
end
#= @testset "rotmat" begin =#
#= ident = ident() =#
#= expectedR = [[0.0, 0.0, -1.0], =#
#= [0.0, 1.0, 0.0], =#
#= [1.0, 0.0, 0.0]] =#
#= rOut = rotmat(ident, halfpi(), 2) =#
#= npt.assert_array_almost_equal(rOut, expectedR) =#
#= =#
#= =#
#= @testset "rotvec" begin =#
#= vin = [sqrt(2), 0.0, 0.0] =#
#= angle = pi() / 4 =#
#= iaxis = 3 =#
#= vExpected = [1.0, -1.0, 0.0] =#
#= vout = rotvec(vin, angle, iaxis) =#
#= npt.assert_array_almost_equal(vout, vExpected) =#
#= =#
#= =#
#= @testset "rpd" begin =#
#= assert rpd() == arccos(-1.0) / 180.0 =#
#= =#
#= =#
#= @testset "rquad" begin =#
#= # solve x^2 + 2x + 3 = 0 =#
#= root1, root2 = rquad(1.0, 2.0, 3.0) =#
#= expectedRootOne = [-1.0, sqrt(2.0)] =#
#= expectedRootTwo = [-1.0, -sqrt(2.0)] =#
#= npt.assert_array_almost_equal(root1, expectedRootOne) =#
#= npt.assert_array_almost_equal(root2, expectedRootTwo) =#
end

0 comments on commit 76ae306

Please sign in to comment.