question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Time from astropy.time not precise

See original GitHub issue

Hello,

I encounter difficulties with Time. I’m working on a package to perform photometry and occultation.

For this last case, data need times values accurately estimated. Of course, data coming from different camera will will have different time format in the header.

to manage this without passing long time to build a time parser, i decided to use Time object which do exactly what i need. The problem is, i dont arrive to make accurate conversion between different format using Time.

let’s do an exemple:

t1 = '2022-03-24T23:13:41.390999'
t1 = Time(t1, format = 'isot', precision = len(t1.split('.')[-1]))
t2 = t1.to_value('jd')
# result is 2459663.4678401737

now let’s do reverse

t2 = Time(t2, format = 'jd', precision = len(str(t2).split('.')[-1]))
t3 = t2.to_value('isot')
# result is 2022-03-24T23:13:41.0551352177

as you can see i don’t fall back on the same value and the difference is quite high. I would like to fall back on the original one.

thank you in advance

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:13 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
maxnoecommented, Mar 30, 2022

Probably we should keep this open to address the issue with precsion > 9 that @saimn found?

0reactions
mhvkcommented, Apr 6, 2022

As for how to fix this, right now we do check precision as a property, but not on input:

In [42]: t = Time('J2000')

In [43]: t = Time('J2000', precision=10)

In [44]: t.precision
Out[44]: 10

In [45]: t.precision = 10
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-45-59f84a57d617> in <module>
----> 1 t.precision = 10

/usr/lib/python3/dist-packages/astropy/time/core.py in precision(self, val)
    608         del self.cache
    609         if not isinstance(val, int) or val < 0 or val > 9:
--> 610             raise ValueError('precision attribute must be an int between '
    611                              '0 and 9')
    612         self._time.precision = val

ValueError: precision attribute must be an int between 0 and 9

Seems reasonable to check on input as well.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Time and Dates (astropy.time) — Astropy v5.2
The precision setting affects string formats when outputting a value that includes seconds. It must be an integer between 0 and 9. There...
Read more >
Time and Dates (astropy.time) — Astropy v1.0.4
The Time object maintains an internal representation of time as a pair of double precision numbers expressing Julian days. The sum of the...
Read more >
Time and Dates (astropy.time) — Astropy v3.2.dev994
The Time object maintains an internal representation of time as a pair of double precision numbers expressing Julian days. The sum of the...
Read more >
Time and Dates (astropy.time)
The sum of the two numbers is the Julian Date for that time relative to the given time scale. Users requiring no better...
Read more >
Transition from datetime to astropy.time
Time can provide sub-nanosecond precision for time objects while ... Time . datetime has no support for leap second while ~astropy.time.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found