Skip to content

Commit

Permalink
Merge pull request #53 from B612-Asteroid-Institute/jm/aberrated-ephe…
Browse files Browse the repository at this point in the history
…meris

Add the aberrated orbit to the Ephemeris table
  • Loading branch information
moeyensj authored Aug 29, 2023
2 parents dbeb788 + 4e07e0b commit 6d0f3f6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 62 deletions.
72 changes: 10 additions & 62 deletions adam_core/orbits/ephemeris.py
Original file line number Diff line number Diff line change
@@ -1,71 +1,19 @@
import pandas as pd
from quivr import StringColumn, Table
from typing_extensions import Self

from ..coordinates.cartesian import CartesianCoordinates
from ..coordinates.spherical import SphericalCoordinates


class Ephemeris(Table):

orbit_id = StringColumn(nullable=False)
object_id = StringColumn()
coordinates = SphericalCoordinates.as_column(nullable=False)

def to_dataframe(self) -> pd.DataFrame:
"""
Convert the Ephemeris table to a pandas DataFrame.
Returns
-------
df : `~pandas.DataFrame`
The Ephemeris table as a DataFrame.
"""
df = pd.DataFrame()
df["orbit_id"] = self.orbit_id
df["object_id"] = self.object_id
df_coordinates = self.coordinates.to_dataframe()

df = pd.concat([df, df_coordinates], axis=1)
df.rename(
columns={
"lon": "ra",
"lat": "dec",
"vlon": "vra",
"vlat": "vdec",
},
inplace=True,
)
return df

@classmethod
def from_dataframe(cls, df: pd.DataFrame) -> Self:
"""
Instantiate an Ephemeris table from a pandas DataFrame.
Parameters
----------
df : `~pandas.DataFrame`
The Ephemeris table as a DataFrame.
Returns
-------
ephemeris : `~adam_core.orbits.ephemeris.Ephemeris`
The Ephemeris table.
"""
coordinates = SphericalCoordinates.from_dataframe(
df.rename(
columns={
"ra": "lon",
"dec": "lat",
"vra": "vlon",
"vdec": "vlat",
"obs_code": "origin.code",
},
),
"equatorial",
)
return cls.from_kwargs(
orbit_id=df["orbit_id"],
object_id=df["object_id"],
coordinates=coordinates,
)
coordinates = SphericalCoordinates.as_column()

# The coordinates as observed by the observer will be the result of
# light emitted or reflected from the object at the time of the observation.
# Light, however, has a finite speed and so the object's observed cooordinates
# will be different from its actual geometric coordinates at the time of observation.
# Aberrated coordinates are coordinates that account for the light travel time
# from the time of emission/reflection to the time of observation
aberrated_coordinates = CartesianCoordinates.as_column(nullable=True)
17 changes: 17 additions & 0 deletions adam_core/propagator/pyoorb.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,23 @@ def _generate_ephemeris(
origin=Origin.from_kwargs(code=codes),
frame="equatorial",
),
aberrated_coordinates=CartesianCoordinates.from_kwargs(
x=ephemeris[:, 24],
y=ephemeris[:, 25],
z=ephemeris[:, 26],
vx=ephemeris[:, 27],
vy=ephemeris[:, 28],
vz=ephemeris[:, 29],
time=Times.from_astropy(
Time(
ephemeris[:, 0],
scale="utc",
format="mjd",
)
),
origin=Origin.from_kwargs(code=["SUN" for i in range(len(codes))]),
frame="ecliptic",
),
)
ephemeris_list.append(ephemeris)

Expand Down

0 comments on commit 6d0f3f6

Please sign in to comment.