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 .&checktime(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,4625 gold badges18 silver badges30 bronze badges
asked Feb 9, 2023 at 15:15
2
  • Interactive Data Language (IDL) Commented Feb 9, 2023 at 16:30
  • What is the output you expect? Commented Feb 9, 2023 at 21:57

1 Answer 1

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
answered Feb 9, 2023 at 22:01
Sign up to request clarification or add additional context in comments.

3 Comments

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 You can add yours as an 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".
You are right. Your answer is more excellent. I never thought that way. Thanks

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.