0

Please does anyone know how to convert the following python script to IDL,

hours = list(Timed)
start_date = datetime(year=1800, month=1, day=1, hour=0, minute=0, second=0)
days =[] 
Months =[]
Years =[]   
for hour in hours:
    date = start_date + timedelta(hours=hour)
    Months.append(date.month)
    Years.append(date.year) 

The script converts the data below to day, month, and year starting from 1800:00:00.0

Timed = [1.52887e+06,1.52959e+06,1.53034e+06,1.53108e+06,1.5318e+06,1.53254e+06,1.53326e+06,1.53401e+06,1.53475e+06,1.53542e+06,1.53617e+06,1.53689e+06,1.53763e+06]

I want to rewrite the Python script in IDL.

Andy A.
  • 1,392
  • 5
  • 15
  • 28
TThoye
  • 25
  • 5

1 Answers1

1

I suggest using CALDAT and JULDAY. You need to convert Timed to days.

IDL> start_date = julday(1, 1, 1800, 0, 0, 0)
IDL> Timed = [1.52887e+06,1.52959e+06,1.53034e+06,1.53108e+06,1.5318e+06,1.53254e+06,1.53326e+06,1.53401e+06,1.53475e+06,1.53542e+06,1.53617e+06,1.53689e+06,1.53763e+06]
IDL> caldat, start_date + (Timed / 24), month, day, year  ; convert Timed to days and add to start_date
IDL> year                                               
        1974        1974        1974        1974        1974        1974        1974        1975        1975        1975        1975
        1975        1975
IDL> month
           5           6           8           9          10          10          11           1           1           2           4
           5           5
IDL> day
          31          30           1           1           1          31          30           1          31          28           1
           1          31
sappjw
  • 373
  • 1
  • 14
  • Nice!! I just wanted to post the way I solved it. `Timediff = (Timed - 1490181)*3600 for t = 0L, N_ELEMENTS(Timediff)-1 do begin Time_Datax = SYSTIME(ELAPSED=Timediff(t)) BinTime = BIN_DATE(Time_Datax) Yeartime= BinTime[0] Monthtime = BinTime[1] daytime = BinTime[2] endfor ` Thanks – TThoye Feb 10 '23 at 11:20
  • @TThoye You can [add yours as an answer](https://stackoverflow.com/help/self-answer) and then accept the one that you think is best. The main advantages of the one I posted are probably speed (no `for` loop) and fewer "magic numbers". – sappjw Feb 10 '23 at 13:28
  • You are right. Your answer is more excellent. I never thought that way. Thanks – TThoye Feb 11 '23 at 14:58