@@ -241,3 +241,38 @@ def test_orbit_conversion_realdata():
241241 converted = np .array (parse_orbit_row (orbit_types [i ], epochJD_TDB , None , sun_dict , gm_sun , gm_total ))
242242 for j in range (6 ):
243243 assert np .isclose (converted [j ], vec_bary [j ], 1e-8 )
244+
245+ from sorcha .ephemeris .orbit_conversion_utilities import universal_keplerian
246+ from sorcha .ephemeris .simulation_constants import ECL_TO_EQ_ROTATION_MATRIX
247+
248+ # let's finalize this by testing universal_keplerian
249+
250+ newx = np .array ([orbit_types ["BCART" ]["x" ], orbit_types ["BCART" ]["y" ], orbit_types ["BCART" ]["z" ]])
251+ newv = np .array (
252+ [orbit_types ["BCART" ]["xdot" ], orbit_types ["BCART" ]["ydot" ], orbit_types ["BCART" ]["zdot" ]]
253+ )
254+
255+ newa , newe , newi , newlan , newaop , newma = universal_keplerian (
256+ gm_total , newx [0 ], newx [1 ], newx [2 ], newv [0 ], newv [1 ], newv [2 ], epochJD_TDB - 2400000.5
257+ )
258+
259+ assert np .isclose (orbit_types ["BKEP" ]["a" ], newa , 1e-8 )
260+ assert np .isclose (orbit_types ["BKEP" ]["e" ], newe , 1e-8 )
261+ assert np .isclose (orbit_types ["BKEP" ]["inc" ], newi * 180 / np .pi , 1e-8 )
262+ assert np .isclose (orbit_types ["BKEP" ]["node" ], newlan * 180 / np .pi , 1e-8 )
263+ assert np .isclose (orbit_types ["BKEP" ]["argPeri" ], newaop * 180 / np .pi , 1e-8 )
264+ assert np .isclose (orbit_types ["BKEP" ]["ma" ] - 360.0 , newma * 180 / np .pi , 1e-8 ) # wrap angle
265+
266+ newx = np .array ([orbit_types ["CART" ]["x" ], orbit_types ["CART" ]["y" ], orbit_types ["CART" ]["z" ]])
267+ newv = np .array ([orbit_types ["CART" ]["xdot" ], orbit_types ["CART" ]["ydot" ], orbit_types ["CART" ]["zdot" ]])
268+
269+ newa , newe , newi , newlan , newaop , newma = universal_keplerian (
270+ gm_sun , newx [0 ], newx [1 ], newx [2 ], newv [0 ], newv [1 ], newv [2 ], epochJD_TDB - 2400000.5
271+ )
272+
273+ assert np .isclose (orbit_types ["KEP" ]["a" ], newa , 1e-8 )
274+ assert np .isclose (orbit_types ["KEP" ]["e" ], newe , 1e-8 )
275+ assert np .isclose (orbit_types ["KEP" ]["inc" ], newi * 180 / np .pi , 1e-8 )
276+ assert np .isclose (orbit_types ["KEP" ]["node" ], newlan * 180 / np .pi , 1e-8 )
277+ assert np .isclose (orbit_types ["KEP" ]["argPeri" ], newaop * 180 / np .pi , 1e-8 )
278+ assert np .isclose (orbit_types ["KEP" ]["ma" ] - 360.0 , newma * 180 / np .pi , 1e-8 ) # same
0 commit comments