Expose reading and setting of the ERFA leap second table#9329
Expose reading and setting of the ERFA leap second table#9329mhvk merged 7 commits intoastropy:masterfrom
Conversation
| from astropy.utils.misc import check_broadcast | ||
|
|
||
| from . import ufunc | ||
| from .ufunc import (dt_eraASTROM, dt_eraLDBODY, dt_pv, |
There was a problem hiding this comment.
Removed imports here since they are not used anyway, and make much more sense in the _erfa module.
dd664bb to
07afb61
Compare
|
@eteq - one possible issue with the whole procedure is that the ERFA update is, per definition, global, ie., it will affect anything else that has the library in memory (sub-process, etc.). Similarly, the module is not sub-process safe. Of course, this is an issue only if different subprocesses had different wishes for the leap-second table, which is arguably very unlikely. I guess in principle it might be better instead to offer a hook in Anyway, my own sense is to punt on this for now, and leave this for 5.0 or so. |
|
@eteq - yet another issue: if we go for an astropy-only approach on this for 4.0, it will not work for any distribution that separately ships Or would it work for those to compile just |
07afb61 to
9e3055b
Compare
|
@eteq - would you be able to review? For now, I decided to forge ahead - we can worry about the distribution aspect later. |
| """ | ||
| Interfaces to the ERFA library, in particular for leap seconds. | ||
| """ | ||
| from datetime import datetime, timedelta |
There was a problem hiding this comment.
It would be nice to use Time but that leads to round-trip issues when adding auto-updates upon loading of _erfa.
There was a problem hiding this comment.
None of this is actually instantiated at import time, right? So can't we just use time imports inside the functions? I think that's a more consistent approach.
(If I missed an import-time requirement, then you can ignore this, though. It's not that bad since it's easy to transition between Time and datetime anyway)
There was a problem hiding this comment.
I wish!! (and tried). The problem is that Time initiation needs erfa installed (even the plainest formats like 'iso' rely on it). More specifically, Time.now() needs to have the leap seconds up to date (in case 'now' is on a leap-second day), yet here I need to have Time.now() accessible to tell whether to update the leap-second table.
9e3055b to
bf0fcd4
Compare
There was a problem hiding this comment.
I think this is overall the right direction, @mhvk. I think we don't need to worry a whole lot about the interface since nominally this is all "private" so we can iterate on it and not worry too much about backwards compatibility. So if #9365 + this is ready and we're bumping up against feature freeze, I'm ok with merging this without worrying a ton about some of these items and sort it out later.
But two broad issues to bring up in addition to my inline comments:
- Can the changes to
datgo in a separate file? this would probably require adding it toerfaextras.hor something, but I think that will be easier to manage than thedat.cchanges. My worry being this is a very substansive change and easy to screw up the "bring in a new erfa version process" if it's mixed indat.cwhereas if we diddat_extras.cor similar then we can just leave that file alone during the update process. - The class level singleton seems a bit odd to me. Why use that approach instead of either a singleton instance (which I imagine is basically just a find-and-replace), vs standard module functions with globals as the shared state?
astropy/_erfa/interface.py
Outdated
| @@ -0,0 +1,177 @@ | |||
| # Licensed under a 3-clause BSD style license - see LICENSE.rst | |||
| """ | |||
| Interfaces to the ERFA library, in particular for leap seconds. | |||
There was a problem hiding this comment.
I think it's better to make this only about leap seconeds. I.e., something like:
| Interfaces to the ERFA library, in particular for leap seconds. | |
| Interfaces to controlling leap seconds in the ERFA library. |
and then change the name of the module file from interface.py to leap_seconds.py
| """ | ||
| Interfaces to the ERFA library, in particular for leap seconds. | ||
| """ | ||
| from datetime import datetime, timedelta |
There was a problem hiding this comment.
None of this is actually instantiated at import time, right? So can't we just use time imports inside the functions? I think that's a more consistent approach.
(If I missed an import-time requirement, then you can ignore this, though. It's not that bad since it's easy to transition between Time and datetime anyway)
|
Yes, I've been wondering about making the changes to On |
|
p.s. The reason for a singleton class is that I started with |
bf0fcd4 to
5dc7813
Compare
|
@eteq - I managed to get out most of the changes to I looked a bit at the module replacement for the current |
|
@eteq - from the commits, it may not be so clear, but the total change in |
|
@eteq - this is still the simplest PR of the two - could you re-review? |
|
@mhvk - ok in its current state I think this is basically good. I didn't merge though because I wanted to give one more try of suggesting a change from the name (But I approved because I think this is good other than that one name change.) |
|
I'm quite happy to change the name, but not to |
|
@mhvk - EDIT: after a moments more thought I decided I do prefer |
|
Why not leap first can make it |
|
@eteq - thanks, may be needed. But right now pushing up a version with |
This avoids locking us in to the C routines. Also, the update method is needed to interface with leap-second lists, and is much easier done in python.
5dc7813 to
04a0e83
Compare
|
coverage failure is a false positive. Since approved before, merging... |
@eteq - this is step 1 to using/updating the leap second table. I went a bit beyond @jwoillez's implementation by also allowing one to retrieve the current leap second table, using a new
eraGetLeapSeconds. With that, it seemed it would be better to also renameeraUpdateLeapSecondstoeraSetLeapSeconds.One can now retrieve these as structured arrays using
EDIT (name change):_erfa.get_leap_second_tableand_erfa.set_leap_second_table.erfa.get_leap_secondsand_erfa.set_leap_seconds.EDIT 2: I hid the C functions behind a new leap_second singleton, with
get,set, andupdatemethods.