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
-
Interactive Data Language (IDL)TThoye– TThoye2023年02月09日 16:30:46 +00:00Commented Feb 9, 2023 at 16:30
-
What is the output you expect?sappjw– sappjw2023年02月09日 21:57:17 +00:00Commented Feb 9, 2023 at 21:57
1 Answer 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
Sign up to request clarification or add additional context in comments.
3 Comments
TThoye
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 Thankssappjw
@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".TThoye
You are right. Your answer is more excellent. I never thought that way. Thanks
Explore related questions
See similar questions with these tags.
lang-py