skyfielders / python-skyfield

Elegant astronomy for Python
MIT License
1.41k stars 211 forks source link

Time Question #347

Closed cpbridges closed 4 years ago

cpbridges commented 4 years ago

I have a pandas dataframe with telemetry that I want to plot to see where on the planet the telemetry is being received. The data is either iso_time values or datetime values. They look like this: 2020-01-01 04:30:48.214938. All in UTC.

I'm trying to convert this to an object that can be used to get the subpoint but am getting odd / broken results. I'm attempting something like this:

from astropy.time import Time
t0 = df.at[0,'iso_time']
t1 = ts.utc(t0, 'utc')
geocentric = satellite.at(t1)

But the times are incorrect so the subpoints are in places I know have no groundstations.

I'm often getting close after an attempt with mjd, with errors looking like this but I'm still unclear how to bring this in and get the correct time. ValueError: please provide the at() method with a Time instance as its argument, instead of the value <Time object: scale='utc' format='mjd' value=58849.18805804326>

Can a pro help here? 73s C

cpbridges commented 4 years ago

More information:

# Testing Time Conversion
from astropy.time import Time
t0 = df.at[0,'iso_time']
print(t0)
print(type(t0))
t1 = Time(t0)
print(t1)
print(type(t1))
t1 = datetime(t0, tzinfo=utc)

Output:

2020-01-01 04:30:48.214938
<class 'pandas._libs.tslibs.timestamps.Timestamp'>
2020-01-01 04:30:48.214938
<class 'astropy.time.core.Time'>
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-98-109ba5b99b8d> in <module>
     16 # t2 = ts.utc(t1)
---> 18 t1 = datetime(t0, tzinfo=utc)
     20 # geocentric = satellite.at(t2)
TypeError: an integer is required (got type Timestamp)
cpbridges commented 4 years ago

Getting closer but still so far:

t1 = Time(t0)
t1.format = 'mjd'
print(t1)
print(type(t1))
t2 = ts.tai(t1.mjd)
print(t2)
print(type(t2))

Output:

58849.18805804326
<class 'astropy.time.core.Time'>
<Time tt=899797467.5003725>
<class 'skyfield.timelib.Time'>
cpbridges commented 4 years ago

Got it:

t1 = Time(t0)
t2 = ts.tai_jd(t1.mjd)
geocentric = satellite.at(t2)
brandon-rhodes commented 4 years ago

I was away from the keyboard last week, but am glad you were able to work through the API and figure out what calls you needed to make to solve your problem! Please feel free to make any suggestions about how the documentation might be made clearer for folks tackling similar problems.