diff --git a/adam_core/coordinates/cartesian.py b/adam_core/coordinates/cartesian.py index d7894f9b..1130f2dd 100644 --- a/adam_core/coordinates/cartesian.py +++ b/adam_core/coordinates/cartesian.py @@ -1,5 +1,5 @@ import logging -from typing import TYPE_CHECKING, Literal, Optional +from typing import TYPE_CHECKING, Optional import numpy as np import pandas as pd @@ -341,9 +341,7 @@ def to_dataframe( ) @classmethod - def from_dataframe( - cls, df: pd.DataFrame, frame: Literal["ecliptic", "equatorial"] - ) -> "CartesianCoordinates": + def from_dataframe(cls, df: pd.DataFrame) -> "CartesianCoordinates": """ Create coordinates from a pandas DataFrame. @@ -351,8 +349,6 @@ def from_dataframe( ---------- df : `~pandas.Dataframe` DataFrame containing coordinates. - frame : {"ecliptic", "equatorial"} - Frame in which coordinates are defined. Returns ------- @@ -360,5 +356,5 @@ def from_dataframe( Cartesian coordinates. """ return coords_from_dataframe( - cls, df, coord_names=["x", "y", "z", "vx", "vy", "vz"], frame=frame + cls, df, coord_names=["x", "y", "z", "vx", "vy", "vz"] ) diff --git a/adam_core/coordinates/cometary.py b/adam_core/coordinates/cometary.py index 0ef949cb..d76f515b 100644 --- a/adam_core/coordinates/cometary.py +++ b/adam_core/coordinates/cometary.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING, Literal, Optional +from typing import TYPE_CHECKING, Optional import numpy as np import pandas as pd @@ -356,9 +356,7 @@ def to_dataframe( ) @classmethod - def from_dataframe( - cls, df: pd.DataFrame, frame: Literal["ecliptic", "equatorial"] - ) -> "CometaryCoordinates": + def from_dataframe(cls, df: pd.DataFrame) -> "CometaryCoordinates": """ Create coordinates from a pandas DataFrame. @@ -366,8 +364,6 @@ def from_dataframe( ---------- df : `~pandas.Dataframe` DataFrame containing coordinates. - frame : {"ecliptic", "equatorial"} - Frame in which coordinates are defined. Returns ------- @@ -375,5 +371,5 @@ def from_dataframe( Cometary coordinates. """ return coords_from_dataframe( - cls, df, coord_names=["q", "e", "i", "raan", "ap", "tp"], frame=frame + cls, df, coord_names=["q", "e", "i", "raan", "ap", "tp"] ) diff --git a/adam_core/coordinates/io.py b/adam_core/coordinates/io.py index a02194ac..54a0655a 100644 --- a/adam_core/coordinates/io.py +++ b/adam_core/coordinates/io.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING, List, Literal, Optional, Type, Union +from typing import TYPE_CHECKING, List, Optional, Type, Union import numpy as np import pandas as pd @@ -35,7 +35,9 @@ def coords_to_dataframe( coords : {CartesianCoordinates, CometaryCoordinates, KeplerianCoordinates, SphericalCoordinates} Coordinates to store. coord_names : list of str - Names of the coordinates to store. + Names of the coordinates to store. The coordinate reference frame will be appended to the + coordinate names, e.g., "x" will become "x_ec" for ecliptic coordinates and "x_eq" for + equatorial coordinates. sigmas : bool, optional If None, will check if any sigmas are defined (via covariance matrix) and add them to the dataframe. If True, include 1-sigma uncertainties in the DataFrame regardless. If False, do not include 1-sigma @@ -54,6 +56,13 @@ def coords_to_dataframe( # Gather times and put them into a dataframe df_times = coords.time.to_dataframe(flatten=True) + if coords.frame == "ecliptic": + coord_names = [f"{coord}_ec" for coord in coord_names] + elif coords.frame == "equatorial": + coord_names = [f"{coord}_eq" for coord in coord_names] + else: + raise ValueError(f"Frame {coords.frame} not recognized.") + df_coords = pd.DataFrame( data=coords.values, columns=coord_names, @@ -92,7 +101,6 @@ def coords_from_dataframe( cls: "Type[CoordinateType]", df: pd.DataFrame, coord_names: List[str], - frame: Literal["ecliptic", "equatorial"], ) -> "CoordinateType": """ Return coordinates from a pandas DataFrame that was generated with @@ -104,9 +112,9 @@ def coords_from_dataframe( df : `~pandas.Dataframe` DataFrame containing coordinates and covariances. coord_names : list of str - Names of the coordinates dimensions. - frame : {"ecliptic", "equatorial"} - Frame in which the coordinates are defined. + Names of the coordinate dimensions. The coordinate reference frame will be appended to the + coordinate names, e.g., "x" will become "x_ec" for ecliptic coordinates and "x_eq" for + equatorial coordinates. Returns ------- @@ -123,7 +131,26 @@ def coords_from_dataframe( df[["origin.code"]].rename(columns={"origin.code": "code"}) ) covariances = CoordinateCovariances.from_dataframe(df, coord_names=coord_names) - coords = {col: df[col].values for col in coord_names} + + coord_names_ec = [f"{coord}_ec" for coord in coord_names] + coord_names_eq = [f"{coord}_eq" for coord in coord_names] + if all(col in df.columns for col in coord_names_ec): + coords = { + col: df[col_frame].values + for col, col_frame in zip(coord_names, coord_names_ec) + } + frame = "ecliptic" + elif all(col in df.columns for col in coord_names_eq): + coords = { + col: df[col_frame].values + for col, col_frame in zip(coord_names, coord_names_eq) + } + frame = "equatorial" + else: + raise ValueError( + "DataFrame does not contain the expected columns for the coordinate values:\n" + f"Expected: {coord_names_ec} or {coord_names_eq}\n" + ) return cls.from_kwargs( **coords, time=times, origin=origin, frame=frame, covariance=covariances diff --git a/adam_core/coordinates/keplerian.py b/adam_core/coordinates/keplerian.py index 0b169dbc..e39b1e28 100644 --- a/adam_core/coordinates/keplerian.py +++ b/adam_core/coordinates/keplerian.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING, Literal, Optional +from typing import TYPE_CHECKING, Optional import numpy as np import pandas as pd @@ -332,9 +332,7 @@ def to_dataframe( ) @classmethod - def from_dataframe( - cls, df: pd.DataFrame, frame: Literal["ecliptic", "equatorial"] - ) -> "KeplerianCoordinates": + def from_dataframe(cls, df: pd.DataFrame) -> "KeplerianCoordinates": """ Create coordinates from a pandas DataFrame. @@ -342,8 +340,6 @@ def from_dataframe( ---------- df : `~pandas.Dataframe` DataFrame containing coordinates. - frame : {"ecliptic", "equatorial"} - Frame in which coordinates are defined. Returns ------- @@ -351,5 +347,5 @@ def from_dataframe( Keplerian coordinates. """ return coords_from_dataframe( - cls, df, coord_names=["a", "e", "i", "raan", "ap", "M"], frame=frame + cls, df, coord_names=["a", "e", "i", "raan", "ap", "M"] ) diff --git a/adam_core/coordinates/spherical.py b/adam_core/coordinates/spherical.py index 32734a5c..7bed6563 100644 --- a/adam_core/coordinates/spherical.py +++ b/adam_core/coordinates/spherical.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING, Literal, Optional +from typing import TYPE_CHECKING, Optional import numpy as np import pandas as pd @@ -280,9 +280,7 @@ def to_dataframe( ) @classmethod - def from_dataframe( - cls, df: pd.DataFrame, frame: Literal["ecliptic", "equatorial"] - ) -> "SphericalCoordinates": + def from_dataframe(cls, df: pd.DataFrame) -> "SphericalCoordinates": """ Create coordinates from a pandas DataFrame. @@ -290,8 +288,6 @@ def from_dataframe( ---------- df : `~pandas.Dataframe` DataFrame containing coordinates. - frame : {"ecliptic", "equatorial"} - Frame in which coordinates are defined. Returns ------- @@ -299,8 +295,5 @@ def from_dataframe( Spherical coordinates. """ return coords_from_dataframe( - cls, - df, - coord_names=["rho", "lon", "lat", "vrho", "vlon", "vlat"], - frame=frame, + cls, df, coord_names=["rho", "lon", "lat", "vrho", "vlon", "vlat"] ) diff --git a/adam_core/coordinates/tests/test_io.py b/adam_core/coordinates/tests/test_io.py new file mode 100644 index 00000000..421e4d20 --- /dev/null +++ b/adam_core/coordinates/tests/test_io.py @@ -0,0 +1,111 @@ +import numpy as np +from astropy.time import Time + +from ..cartesian import CartesianCoordinates +from ..covariances import CoordinateCovariances +from ..origin import Origin +from ..times import Times + +coords_ec = CartesianCoordinates.from_kwargs( + time=Times.from_astropy( + Time([59000.0, 59001.0, 59002.0], format="mjd", scale="tdb") + ), + x=[1, 2, 3], + y=[4, 5, 6], + z=[7, 8, 9], + vx=[0.1, 0.2, 0.3], + vy=[0.4, 0.5, 0.6], + vz=[0.7, 0.8, 0.9], + covariance=CoordinateCovariances.from_sigmas( + np.array( + [ + [0.01, 0.01, 0.01, 0.01, 0.01, 0.01], + [0.02, 0.02, 0.02, 0.02, 0.02, 0.02], + [0.03, 0.03, 0.03, 0.03, 0.03, 0.03], + ] + ), + ), + frame="ecliptic", + origin=Origin.from_kwargs(code=["SUN" for i in range(3)]), +) + +coords_eq = CartesianCoordinates.from_kwargs( + time=coords_ec.time, + x=coords_ec.x, + y=coords_ec.y, + z=coords_ec.z, + vx=coords_ec.vx, + vy=coords_ec.vy, + vz=coords_ec.vz, + covariance=coords_ec.covariance, + frame="equatorial", + origin=coords_ec.origin, +) + + +def test_coords_to_dataframe(): + # Cartesian coordinates defined in the ecliptic frame + df = coords_ec.to_dataframe() + np.testing.assert_equal(df["x_ec"].values, coords_ec.x.to_numpy()) + np.testing.assert_equal(df["y_ec"].values, coords_ec.y.to_numpy()) + np.testing.assert_equal(df["z_ec"].values, coords_ec.z.to_numpy()) + np.testing.assert_equal(df["vx_ec"].values, coords_ec.vx.to_numpy()) + np.testing.assert_equal(df["vy_ec"].values, coords_ec.vy.to_numpy()) + np.testing.assert_equal(df["vz_ec"].values, coords_ec.vz.to_numpy()) + np.testing.assert_equal( + df["cov_x_x"].values, coords_ec.covariances.sigmas[:, 0] ** 2 + ) + np.testing.assert_equal( + df["cov_y_y"].values, coords_ec.covariances.sigmas[:, 1] ** 2 + ) + np.testing.assert_equal( + df["cov_z_z"].values, coords_ec.covariances.sigmas[:, 2] ** 2 + ) + np.testing.assert_equal( + df["cov_vx_vx"].values, coords_ec.covariances.sigmas[:, 3] ** 2 + ) + np.testing.assert_equal( + df["cov_vy_vy"].values, coords_ec.covariances.sigmas[:, 4] ** 2 + ) + np.testing.assert_equal( + df["cov_vz_vz"].values, coords_ec.covariances.sigmas[:, 5] ** 2 + ) + + # Cartesian coordinates defined in the equatorial frame + df = coords_eq.to_dataframe() + np.testing.assert_equal(df["x_eq"].values, coords_eq.x.to_numpy()) + np.testing.assert_equal(df["y_eq"].values, coords_eq.y.to_numpy()) + np.testing.assert_equal(df["z_eq"].values, coords_eq.z.to_numpy()) + np.testing.assert_equal(df["vx_eq"].values, coords_eq.vx.to_numpy()) + np.testing.assert_equal(df["vy_eq"].values, coords_eq.vy.to_numpy()) + np.testing.assert_equal(df["vz_eq"].values, coords_eq.vz.to_numpy()) + np.testing.assert_equal( + df["cov_x_x"].values, coords_eq.covariances.sigmas[:, 0] ** 2 + ) + np.testing.assert_equal( + df["cov_y_y"].values, coords_eq.covariances.sigmas[:, 1] ** 2 + ) + np.testing.assert_equal( + df["cov_z_z"].values, coords_eq.covariances.sigmas[:, 2] ** 2 + ) + np.testing.assert_equal( + df["cov_vx_vx"].values, coords_eq.covariances.sigmas[:, 3] ** 2 + ) + np.testing.assert_equal( + df["cov_vy_vy"].values, coords_eq.covariances.sigmas[:, 4] ** 2 + ) + np.testing.assert_equal( + df["cov_vz_vz"].values, coords_eq.covariances.sigmas[:, 5] ** 2 + ) + + +def test_coords_from_dataframe(): + # Cartesian coordinates defined in the ecliptic frame + df = coords_ec.to_dataframe() + coords_ec2 = CartesianCoordinates.from_dataframe(df) + assert coords_ec2.frame == coords_ec.frame + + # Cartesian coordinates defined in the equatorial frame + df = coords_eq.to_dataframe() + coords_eq2 = CartesianCoordinates.from_dataframe(df) + assert coords_eq2.frame == coords_eq.frame diff --git a/adam_core/observers/observers.py b/adam_core/observers/observers.py index 51964357..96b58b8b 100644 --- a/adam_core/observers/observers.py +++ b/adam_core/observers/observers.py @@ -150,18 +150,17 @@ def from_dataframe(cls, df: pd.DataFrame) -> Self: columns={ "obs_jd1_tdb": "jd1_tdb", "obs_jd2_tdb": "jd2_tdb", - "obs_x": "x", - "obs_y": "y", - "obs_z": "z", - "obs_vx": "vx", - "obs_vy": "vy", - "obs_vz": "vz", + "obs_x_ec": "x_ec", + "obs_y_ec": "y_ec", + "obs_z_ec": "z_ec", + "obs_vx_ec": "vx_ec", + "obs_vy_ec": "vy_ec", + "obs_vz_ec": "vz_ec", "obs_origin.code": "origin.code", } ) coordinates = CartesianCoordinates.from_dataframe( df_renamed, - frame="ecliptic", ) return cls.from_kwargs( code=df["obs_code"].values, diff --git a/adam_core/observers/tests/test_state.py b/adam_core/observers/tests/test_state.py index 3c28a883..db55c635 100644 --- a/adam_core/observers/tests/test_state.py +++ b/adam_core/observers/tests/test_state.py @@ -24,7 +24,7 @@ def test_get_observer_state_X05(): index_col=False, float_precision="round_trip", ) - states_expected = CartesianCoordinates.from_dataframe(states_df, "ecliptic") + states_expected = CartesianCoordinates.from_dataframe(states_df) if origin == "sun": origin_code = OriginCodes.SUN @@ -64,7 +64,7 @@ def test_get_observer_state_I41(): index_col=False, float_precision="round_trip", ) - states_expected = CartesianCoordinates.from_dataframe(states_df, "ecliptic") + states_expected = CartesianCoordinates.from_dataframe(states_df) if origin == "sun": origin_code = OriginCodes.SUN @@ -104,7 +104,7 @@ def test_get_observer_state_W84(): index_col=False, float_precision="round_trip", ) - states_expected = CartesianCoordinates.from_dataframe(states_df, "ecliptic") + states_expected = CartesianCoordinates.from_dataframe(states_df) if origin == "sun": origin_code = OriginCodes.SUN @@ -144,7 +144,7 @@ def test_get_observer_state_000(): index_col=False, float_precision="round_trip", ) - states_expected = CartesianCoordinates.from_dataframe(states_df, "ecliptic") + states_expected = CartesianCoordinates.from_dataframe(states_df) if origin == "sun": origin_code = OriginCodes.SUN @@ -184,7 +184,7 @@ def test_get_observer_state_500(): index_col=False, float_precision="round_trip", ) - states_expected = CartesianCoordinates.from_dataframe(states_df, "ecliptic") + states_expected = CartesianCoordinates.from_dataframe(states_df) if origin == "sun": origin_code = OriginCodes.SUN diff --git a/adam_core/observers/tests/testdata/000_ssb.csv b/adam_core/observers/tests/testdata/000_ssb.csv index f9f82222..afc9bcf4 100644 --- a/adam_core/observers/tests/testdata/000_ssb.csv +++ b/adam_core/observers/tests/testdata/000_ssb.csv @@ -1,4 +1,4 @@ -jd1_tdb,jd2_tdb,x,y,z,vx,vy,vz,origin.code +jd1_tdb,jd2_tdb,x_ec,y_ec,z_ec,vx_ec,vy_ec,vz_ec,origin.code 2456294.0,-0.5,-0.1813123008536652,0.9642567063183674,-4.833496674147619e-05,-0.01734825790931131,-0.003237379343823814,1.21949051178308e-05,SOLAR_SYSTEM_BARYCENTER 2456304.0,-0.5,-0.3495365809036956,0.9173141278619189,-5.226032560484219e-05,-0.01652816355637974,-0.006212415258402789,2.281598837606869e-05,SOLAR_SYSTEM_BARYCENTER 2456314.0,-0.5,-0.5069408144755393,0.841733434480988,-4.854020146841657e-05,-0.0151723170338897,-0.008987779395331729,3.434318543145048e-05,SOLAR_SYSTEM_BARYCENTER diff --git a/adam_core/observers/tests/testdata/000_sun.csv b/adam_core/observers/tests/testdata/000_sun.csv index e9d1bccc..347c767a 100644 --- a/adam_core/observers/tests/testdata/000_sun.csv +++ b/adam_core/observers/tests/testdata/000_sun.csv @@ -1,4 +1,4 @@ -jd1_tdb,jd2_tdb,x,y,z,vx,vy,vz,origin.code +jd1_tdb,jd2_tdb,x_ec,y_ec,z_ec,vx_ec,vy_ec,vz_ec,origin.code 2456294.0,-0.5,-0.1800273018063675,0.9667121514073976,-6.378711439944006e-06,-0.01735440367205481,-0.003236061286125001,1.23255424846845e-05,SUN 2456304.0,-0.5,-0.3483131075702085,0.9197822736878748,-8.994630735237697e-06,-0.01653432313310219,-0.006211192791949638,2.294728811964002e-05,SUN 2456314.0,-0.5,-0.5057790121100412,0.8442133348692583,-3.956956849056922e-06,-0.01517849197134488,-0.008986650741521034,3.447544551477245e-05,SUN diff --git a/adam_core/observers/tests/testdata/500_ssb.csv b/adam_core/observers/tests/testdata/500_ssb.csv index 93ead7cf..98ac1161 100644 --- a/adam_core/observers/tests/testdata/500_ssb.csv +++ b/adam_core/observers/tests/testdata/500_ssb.csv @@ -1,4 +1,4 @@ -jd1_tdb,jd2_tdb,x,y,z,vx,vy,vz,origin.code +jd1_tdb,jd2_tdb,x_ec,y_ec,z_ec,vx_ec,vy_ec,vz_ec,origin.code 2456294.0,-0.5,-0.181307558040144,0.964219482495517,-6.839146835100089e-05,-0.01718334419560864,-0.003209800035739284,6.723347229454263e-09,SOLAR_SYSTEM_BARYCENTER 2456304.0,-0.5,-0.3495274283253644,0.9172780078181042,-7.280158333687245e-05,-0.01637084501177808,-0.006159340639420078,-4.146855635842961e-07,SOLAR_SYSTEM_BARYCENTER 2456314.0,-0.5,-0.5069275235493012,0.8416990945753542,-6.985903551958244e-05,-0.01502723741120484,-0.008910776111960686,7.558457588687759e-07,SOLAR_SYSTEM_BARYCENTER diff --git a/adam_core/observers/tests/testdata/500_sun.csv b/adam_core/observers/tests/testdata/500_sun.csv index 2b89ac2a..d909b41d 100644 --- a/adam_core/observers/tests/testdata/500_sun.csv +++ b/adam_core/observers/tests/testdata/500_sun.csv @@ -1,4 +1,4 @@ -jd1_tdb,jd2_tdb,x,y,z,vx,vy,vz,origin.code +jd1_tdb,jd2_tdb,x_ec,y_ec,z_ec,vx_ec,vy_ec,vz_ec,origin.code 2456294.0,-0.5,-0.1800225589928464,0.9666749275845473,-2.643521304941891e-05,-0.01718948995835214,-0.003208481978040471,1.373607140831574e-07,SUN 2456304.0,-0.5,-0.3483039549918773,0.9197461536440601,-2.953588846721816e-05,-0.01637700458850053,-0.006158118172966928,-2.833858200124515e-07,SUN 2456314.0,-0.5,-0.505765721183803,0.8441789949636246,-2.527579090022279e-05,-0.01503341234866001,-0.00890964745814999,8.881058421917694e-07,SUN diff --git a/adam_core/observers/tests/testdata/F51_ssb.csv b/adam_core/observers/tests/testdata/F51_ssb.csv index 2d640174..dc189ba2 100644 --- a/adam_core/observers/tests/testdata/F51_ssb.csv +++ b/adam_core/observers/tests/testdata/F51_ssb.csv @@ -1,4 +1,4 @@ -jd1_tdb,jd2_tdb,x,y,z,vx,vy,vz,origin.code +jd1_tdb,jd2_tdb,x_ec,y_ec,z_ec,vx_ec,vy_ec,vz_ec,origin.code 2456294.0,-0.5,-0.1812851567986696,0.9641951078359843,-4.152024954174702e-05,-0.0169751064206432,-0.003080526820042112,-5.632842365612273e-05,SOLAR_SYSTEM_BARYCENTER 2456304.0,-0.5,-0.3494996998050676,0.9172575930457804,-4.765464952086801e-05,-0.01618981866605964,-0.005999259213852705,-7.006798238699276e-05,SOLAR_SYSTEM_BARYCENTER 2456314.0,-0.5,-0.5068952856930927,0.8416834182916996,-4.677274510567472e-05,-0.01487876605647617,-0.008724611801158912,-8.015943377719216e-05,SOLAR_SYSTEM_BARYCENTER diff --git a/adam_core/observers/tests/testdata/F51_sun.csv b/adam_core/observers/tests/testdata/F51_sun.csv index 550d0f4b..fa199257 100644 --- a/adam_core/observers/tests/testdata/F51_sun.csv +++ b/adam_core/observers/tests/testdata/F51_sun.csv @@ -1,4 +1,4 @@ -jd1_tdb,jd2_tdb,x,y,z,vx,vy,vz,origin.code +jd1_tdb,jd2_tdb,x_ec,y_ec,z_ec,vx_ec,vy_ec,vz_ec,origin.code 2456294.0,-0.5,-0.180000157751372,0.9666505529250146,4.360057597851648e-07,-0.0169812521833867,-0.003079208762343298,-5.619778628926916e-05,SUN 2456304.0,-0.5,-0.3482762264715805,0.9197257388717363,-4.388954651263514e-06,-0.01619597824278209,-0.005998036747399554,-6.993668264342143e-05,SUN 2456314.0,-0.5,-0.5057334833275946,0.8441633186799697,-2.189500486315059e-06,-0.01488494099393134,-0.008723483147348218,-8.002717369386967e-05,SUN diff --git a/adam_core/observers/tests/testdata/I41_ssb.csv b/adam_core/observers/tests/testdata/I41_ssb.csv index 9d012918..e66b01b5 100644 --- a/adam_core/observers/tests/testdata/I41_ssb.csv +++ b/adam_core/observers/tests/testdata/I41_ssb.csv @@ -1,4 +1,4 @@ -jd1_tdb,jd2_tdb,x,y,z,vx,vy,vz,origin.code +jd1_tdb,jd2_tdb,x_ec,y_ec,z_ec,vx_ec,vy_ec,vz_ec,origin.code 2456294.0,-0.5,-0.1812733392356919,0.9642194480308203,-4.30117139372874e-05,-0.01711954405579465,-0.003012202499746585,-8.574486958237361e-05,SOLAR_SYSTEM_BARYCENTER 2456304.0,-0.5,-0.3494919806692268,0.917283479169238,-4.981054831943909e-05,-0.01634485771427273,-0.005954620658788238,-8.92007572881333e-05,SOLAR_SYSTEM_BARYCENTER 2456314.0,-0.5,-0.5068918925235325,0.8417101840169622,-4.930389048125285e-05,-0.01503983002254541,-0.008704976680982275,-8.844387091636017e-05,SOLAR_SYSTEM_BARYCENTER diff --git a/adam_core/observers/tests/testdata/I41_sun.csv b/adam_core/observers/tests/testdata/I41_sun.csv index d5610097..129368f7 100644 --- a/adam_core/observers/tests/testdata/I41_sun.csv +++ b/adam_core/observers/tests/testdata/I41_sun.csv @@ -1,4 +1,4 @@ -jd1_tdb,jd2_tdb,x,y,z,vx,vy,vz,origin.code +jd1_tdb,jd2_tdb,x_ec,y_ec,z_ec,vx_ec,vy_ec,vz_ec,origin.code 2456294.0,-0.5,-0.1799883401883942,0.9666748931198503,-1.055458635705413e-06,-0.01712568981853815,-0.003010884442047772,-8.561423221551991e-05,SUN 2456304.0,-0.5,-0.3482685073357397,0.9197516249951938,-6.544853449784794e-06,-0.01635101729099517,-0.005953398192335087,-8.90694575445617e-05,SUN 2456314.0,-0.5,-0.5057300901580344,0.8441900844052326,-4.720645861893196e-06,-0.01504600496000058,-0.008703848027171581,-8.831161083303769e-05,SUN diff --git a/adam_core/observers/tests/testdata/W84_ssb.csv b/adam_core/observers/tests/testdata/W84_ssb.csv index 1c0b86a0..3e26207c 100644 --- a/adam_core/observers/tests/testdata/W84_ssb.csv +++ b/adam_core/observers/tests/testdata/W84_ssb.csv @@ -1,4 +1,4 @@ -jd1_tdb,jd2_tdb,x,y,z,vx,vy,vz,origin.code +jd1_tdb,jd2_tdb,x_ec,y_ec,z_ec,vx_ec,vy_ec,vz_ec,origin.code 2456294.0,-0.5,-0.1812754833742774,0.964227691609461,-9.52203529802444e-05,-0.01729802990124553,-0.003024172092446104,-8.030465672313721e-05,SOLAR_SYSTEM_BARYCENTER 2456304.0,-0.5,-0.3494989434022667,0.9172910139415262,-0.0001017050900842771,-0.01651845902873458,-0.005994445928940809,-7.169091453480055e-05,SOLAR_SYSTEM_BARYCENTER 2456314.0,-0.5,-0.5069034699891678,0.8417162635873274,-0.0001005610560626254,-0.01520342238292174,-0.008771482048224272,-5.938138075013586e-05,SOLAR_SYSTEM_BARYCENTER diff --git a/adam_core/observers/tests/testdata/W84_sun.csv b/adam_core/observers/tests/testdata/W84_sun.csv index 31f74d30..cc6cd30a 100644 --- a/adam_core/observers/tests/testdata/W84_sun.csv +++ b/adam_core/observers/tests/testdata/W84_sun.csv @@ -1,4 +1,4 @@ -jd1_tdb,jd2_tdb,x,y,z,vx,vy,vz,origin.code +jd1_tdb,jd2_tdb,x_ec,y_ec,z_ec,vx_ec,vy_ec,vz_ec,origin.code 2456294.0,-0.5,-0.1799904843269797,0.966683136698491,-5.326409767866241e-05,-0.01730417566398903,-0.003022854034747291,-8.017401935628363e-05,SUN 2456304.0,-0.5,-0.3482754700687796,0.9197591597674822,-5.843939521467261e-05,-0.01652461860545702,-0.005993223462487658,-7.155961479122922e-05,SUN 2456314.0,-0.5,-0.5057416676236697,0.8441961639755977,-5.597781144321591e-05,-0.01520959732037692,-0.008770353394413578,-5.924912066681338e-05,SUN diff --git a/adam_core/observers/tests/testdata/X05_ssb.csv b/adam_core/observers/tests/testdata/X05_ssb.csv index d893a566..8b01c091 100644 --- a/adam_core/observers/tests/testdata/X05_ssb.csv +++ b/adam_core/observers/tests/testdata/X05_ssb.csv @@ -1,4 +1,4 @@ -jd1_tdb,jd2_tdb,x,y,z,vx,vy,vz,origin.code +jd1_tdb,jd2_tdb,x_ec,y_ec,z_ec,vx_ec,vy_ec,vz_ec,origin.code 2456294.0,-0.5,-0.1812755234719785,0.9642276897307412,-9.527365145371014e-05,-0.0172981526055832,-0.00302440344619394,-8.020418835344667e-05,SOLAR_SYSTEM_BARYCENTER 2456304.0,-0.5,-0.3494989862429964,0.917291005513248,-0.0001017555451980184,-0.01651853674742866,-0.005994693161064276,-7.158362577355637e-05,SOLAR_SYSTEM_BARYCENTER 2456314.0,-0.5,-0.5069035143101998,0.8417162482747041,-0.0001006085244962598,-0.0152034528218823,-0.0087717378608354,-5.927043863761253e-05,SOLAR_SYSTEM_BARYCENTER diff --git a/adam_core/observers/tests/testdata/X05_sun.csv b/adam_core/observers/tests/testdata/X05_sun.csv index bf0975ba..7f90f841 100644 --- a/adam_core/observers/tests/testdata/X05_sun.csv +++ b/adam_core/observers/tests/testdata/X05_sun.csv @@ -1,4 +1,4 @@ -jd1_tdb,jd2_tdb,x,y,z,vx,vy,vz,origin.code +jd1_tdb,jd2_tdb,x_ec,y_ec,z_ec,vx_ec,vy_ec,vz_ec,origin.code 2456294.0,-0.5,-0.1799905244246809,0.9666831348197713,-5.331739615212816e-05,-0.01730429836832669,-0.003023085388495128,-8.007355098659271e-05,SUN 2456304.0,-0.5,-0.3482755129095093,0.9197591513392039,-5.848985032836408e-05,-0.0165246963241511,-0.005993470694611126,-7.145232602998504e-05,SUN 2456314.0,-0.5,-0.5057417119447016,0.8441961486629744,-5.602527987685036e-05,-0.01520962775933748,-0.008770609207024703,-5.913817855428954e-05,SUN diff --git a/adam_core/orbits/ephemeris.py b/adam_core/orbits/ephemeris.py index 7969b487..7006aa70 100644 --- a/adam_core/orbits/ephemeris.py +++ b/adam_core/orbits/ephemeris.py @@ -20,6 +20,7 @@ def to_dataframe(self) -> pd.DataFrame: df : `~pandas.DataFrame` The Ephemeris table as a DataFrame. """ + assert self.coordinates.frame == "equatorial" df = pd.DataFrame() df["orbit_id"] = self.orbit_id df["object_id"] = self.object_id @@ -28,10 +29,13 @@ def to_dataframe(self) -> pd.DataFrame: df = pd.concat([df, df_coordinates], axis=1) df.rename( columns={ - "lon": "ra", - "lat": "dec", - "vlon": "vra", - "vlat": "vdec", + "origin.code": "obs_code", + "lon_eq": "ra", + "lat_eq": "dec", + "vlon_eq": "vra", + "vlat_eq": "vdec", + "rho_eq": "rho", + "vrho_eq": "vrho", }, inplace=True, ) @@ -55,14 +59,15 @@ def from_dataframe(cls, df: pd.DataFrame) -> Self: coordinates = SphericalCoordinates.from_dataframe( df.rename( columns={ - "ra": "lon", - "dec": "lat", - "vra": "vlon", - "vdec": "vlat", + "ra": "lon_eq", + "dec": "lat_eq", + "vra": "vlon_eq", + "vdec": "vlat_eq", + "rho": "rho_eq", + "vrho": "vrho_eq", "obs_code": "origin.code", }, ), - "equatorial", ) return cls.from_kwargs( orbit_id=df["orbit_id"], diff --git a/adam_core/orbits/orbits.py b/adam_core/orbits/orbits.py index 4f046362..846e703a 100644 --- a/adam_core/orbits/orbits.py +++ b/adam_core/orbits/orbits.py @@ -1,6 +1,5 @@ import logging import uuid -from typing import Literal import pandas as pd import quivr as qv @@ -45,9 +44,7 @@ def to_dataframe(self, sigmas: bool = False, covariances: bool = True): return df @classmethod - def from_dataframe( - cls, df: pd.DataFrame, frame: Literal["ecliptic", "equatorial"] - ) -> "Orbits": + def from_dataframe(cls, df: pd.DataFrame) -> "Orbits": """ Create an Orbits object from a pandas DataFrame. @@ -55,8 +52,6 @@ def from_dataframe( ---------- df : `~pandas.DataFrame` DataFrame containing orbits and their Cartesian elements. - frame : {"ecliptic", "equatorial"} - Frame in which coordinates are defined. Returns ------- @@ -65,7 +60,7 @@ def from_dataframe( """ orbit_id = df["orbit_id"].values object_id = df["object_id"].values - coordinates = CartesianCoordinates.from_dataframe(df, frame=frame) + coordinates = CartesianCoordinates.from_dataframe(df) return cls.from_kwargs( orbit_id=orbit_id, object_id=object_id, coordinates=coordinates ) diff --git a/adam_core/utils/helpers/data/orbits.csv b/adam_core/utils/helpers/data/orbits.csv index 7995406a..c25654e7 100644 --- a/adam_core/utils/helpers/data/orbits.csv +++ b/adam_core/utils/helpers/data/orbits.csv @@ -1,4 +1,4 @@ -orbit_id,object_id,jd1_tdb,jd2_tdb,x,y,z,vx,vy,vz,origin.code,cov_x_x,cov_y_x,cov_y_y,cov_z_x,cov_z_y,cov_z_z,cov_vx_x,cov_vx_y,cov_vx_z,cov_vx_vx,cov_vy_x,cov_vy_y,cov_vy_z,cov_vy_vx,cov_vy_vy,cov_vz_x,cov_vz_y,cov_vz_z,cov_vz_vx,cov_vz_vy,cov_vz_vz +orbit_id,object_id,jd1_tdb,jd2_tdb,x_ec,y_ec,z_ec,vx_ec,vy_ec,vz_ec,origin.code,cov_x_x,cov_y_x,cov_y_y,cov_z_x,cov_z_y,cov_z_z,cov_vx_x,cov_vx_y,cov_vx_z,cov_vx_vx,cov_vy_x,cov_vy_y,cov_vy_z,cov_vy_vx,cov_vy_vy,cov_vz_x,cov_vz_y,cov_vz_z,cov_vz_vx,cov_vz_vy,cov_vz_vz ,594913 'Aylo'chaxnim (2020 AV2),2459038.0,0.5,-0.31773656696340374,0.3682352083918984,0.11450843311283455,-0.01709566104887492,-0.018386448204185585,-0.004622877482778955,SUN,4.869530385232063e-13,4.640903301098472e-13,1.2471384045713769e-12,9.543033327268448e-14,-1.4191396478637558e-14,3.8761618305249535e-13,-2.4292973293765248e-14,-2.7157854012922844e-14,-3.0389473534277287e-15,1.3490068059358539e-15,2.681313191738109e-14,6.208754890245881e-14,3.965284424179218e-15,-1.6268949821043397e-15,3.305546943695162e-15,-2.738074993392154e-15,1.063115849467429e-14,1.6518612608504957e-15,1.3502986395998136e-16,4.0029448183087257e-16,4.237333352367026e-16 ,163693 Atira (2003 CP20),2457256.0,-0.5,0.4355071778313562,0.15249657809775613,-0.22029844001913157,-0.006439849854647203,0.026769974299912493,-9.019530091370332e-05,SUN,9.632409606450106e-16,2.8830312417328225e-15,1.8671527494729595e-14,6.33562751784606e-16,9.62865193396584e-16,1.6758080042401377e-15,-9.831382774736642e-17,-6.242047000033974e-16,-6.238917770283294e-17,2.1676494250748246e-17,-8.320983068123258e-17,-4.720761688711946e-16,-2.004707964938883e-17,1.5508217786666068e-17,1.2313012346962032e-17,4.904662701599506e-17,3.028632401068402e-16,1.4052022900097974e-18,-9.672046482013345e-18,-7.882531677368147e-18,5.1903362454451985e-18 ,(2010 TK7),2456758.0,-0.5,-0.3965125476909978,-0.902662032061103,0.18940557267014038,0.01296795225776535,-0.010266705881229375,-0.004472211963951022,SUN,1.197343462523061e-12,-6.198880452017768e-13,3.787041918570779e-13,4.28780940837666e-14,3.7257494200580047e-14,1.6197590667594596e-13,7.145921434012163e-15,-3.4651663887913023e-15,3.346055482896897e-16,4.792774265996632e-17,1.4151258890651688e-14,-8.174699099677494e-15,-3.767466749472695e-16,8.144434923064463e-17,1.8011622374695987e-16,-5.63607345421453e-15,2.8854419465332323e-15,5.44175221626996e-16,-2.4201764960428115e-17,-6.598945649322952e-17,6.370857017618151e-17 diff --git a/adam_core/utils/helpers/orbits.py b/adam_core/utils/helpers/orbits.py index ac377f0e..70dea345 100644 --- a/adam_core/utils/helpers/orbits.py +++ b/adam_core/utils/helpers/orbits.py @@ -40,7 +40,7 @@ def make_real_orbits(num_orbits: Optional[int] = None) -> Orbits: f"num_orbits must be less than or equal to the number of sample orbits ({len(df)})." ) - return Orbits.from_dataframe(df, "ecliptic")[:num_orbits] + return Orbits.from_dataframe(df)[:num_orbits] def make_simple_orbits(num_orbits: int = 10) -> Orbits: