1
$\begingroup$

I'm using astropy and I need to convert dates like this: 2012.06.22_17:56:15_TAI into julian day number. I tried:

from astropy.time import Time
hmitime = hminew['MidTime']
i=0
print(hmitime[i])
hmi0=Time(hmitime[i],scale='tai')
print(hmi0.jd)

where hmitime it's just the matrix with my dates. But python shows me this:

ValueError: Input values did not match any of the formats where the format keyword is optional [u'datetime', u'iso', u'isot', u'yday', u'fits', u'byear_str', u'jyear_str']

Does anyone know what is wrong? How can I convert my dates?? Thanks

$\endgroup$
2
  • $\begingroup$ I think an actual verbatim example of your input data including spaces etc might be crucial to identify your problem... it's a ValueError after all. $\endgroup$ Jun 13, 2020 at 22:58
  • $\begingroup$ what is the dictionay hminew? Can you create a minimal example that I could copy and paste to generate this error? $\endgroup$
    – James K
    Jun 14, 2020 at 7:42

2 Answers 2

3
$\begingroup$

The accepted string formats for date-hms are:

Format  Class    Example argument

fits    TimeFITS    ‘2000-01-01T00:00:00.000’
iso     TimeISO     ‘2000-01-01 00:00:00.000’
isot    TimeISOT    ‘2000-01-01T00:00:00.000’

https://docs.astropy.org/en/stable/time/index.html

You can either change one of these, or you can define your own format by deriving a class for the format from the TimeFormat class. https://docs.astropy.org/en/stable/api/astropy.time.TimeFormat.html#astropy.time.TimeFormat

$\endgroup$
1
$\begingroup$

It looks as if your input had the wrong format. Read the algorithm to see what formats is expected.

There is an algorithm for converting between our current date and time to Julian date. The reference for this is here. I also have a very short fortran code that calculate JD as well.

You can add this to your Python script.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .