1

I need to convert a time in UT combined with a longitude into local time. I am working on analyzing a future Earth observing satellite mission and need to do this conversion to continue.

I found a general solution to this problem here: T(lt) = T(ut) + lon/(360/24), however implementing it is driving me absolutely bonkers.

My data are datetime time objects:

In[9]: sattime[0] 
Out[9]: datetime.time(18, 0)

and longitude coordinates from 0 to 360 degrees.

I need to take this object and use the above equation to convert to a local time. I ONLY care about the time relative to midnight and NOT about the date (in fact the rest of my code is currently using the datetime.time object only and preferably the local time output would be the same type of object).

I have tried the following from here but am stuck getting the local variable back into a time object.

test = 4       
for (i,j) in zip(sattime, satloncor):
    td = datetime.datetime.combine(datetime.datetime.min, i) - datetime.datetime.min
    seconds = td  // datetime.timedelta(milliseconds=1)
    local = (seconds + (j/(360/86400)))/1000
    print (local)
    if test<0:
        break
    test-=1

The test part of the code just makes sure I am not wasting time doing the conversion for all ~400,000 data points.

So to summarize, I want to take a datetime.time object in UT coupled with a corresponding longitude, and convert it to local solar time as a datetime.time object.

This all seems super convoluted and seems like there should be an easier way. Any help is greatly appreciated! Thanks!

Will.Evo
  • 1,112
  • 13
  • 31

2 Answers2

1

I figured it out but it is not pretty.

localtimes = []
for (i,j) in zip(sattime, satloncor):
    td = dt.datetime.combine(dt.datetime.min, i) - dt.datetime.min
    seconds = td  // dt.timedelta(seconds=1)
    local = (seconds + (j/(360/86400)))/3600
    if local>24:
        local-=24
    strip = [math.modf(local)[1],math.modf(local)[0]*60 ]
    if strip[0]==24:
        localtimes.append(dt.time(0, int(strip[1]),0))
    else:
        localtimes.append(dt.time(int(strip[0]), int(strip[1]),0))
Will.Evo
  • 1,112
  • 13
  • 31
-1

Sorry, but it is super convoluted because it's a complicated subject. For just one example, did you know that every few years there is a day with 86401 seconds in it?

A couple of good web sites to start with:

http://www.ephemeris.com/books.html

I can recommend the "Practical Astronomy with your Calculator" book.

https://www.timeanddate.com/

Hope this helps.

Hugh Fisher
  • 2,321
  • 13
  • 8