-
Notifications
You must be signed in to change notification settings - Fork 6
/
pulsar_clock_corrections.py
1670 lines (1460 loc) · 58 KB
/
pulsar_clock_corrections.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""Maintain up-to-date clock corrections."""
import inspect
import re
import tempfile
from io import StringIO
from pathlib import Path
from functools import partial
from textwrap import dedent, indent
from typing import List, Optional, Iterable, Union
import astropy.units as u
import numpy as np
from astropy.time import Time
from astropy.utils.data import download_file
from pint.observatory.clock_file import ClockFile
import bipm
import iers
import pks
public_repo_url_raw = (
"https://raw.githubusercontent.com/ipta/pulsar-clock-corrections/main/"
)
def base_location() -> Path:
return Path(__file__).parent
def list_candidate_clock_files() -> List[Path]:
return sorted(base_location().glob("tempo/clock/time*_*.dat")) + sorted(
base_location().glob("T2runtime/clock/*2*.clk")
)
class ValidationError(RuntimeError):
pass
class FileUpdater:
def __init__(
self,
short_description: str,
filename: str,
authority: str = "temporary",
invalid_if_older_than: Optional[Time] = None,
update_interval_days: float = 7,
description: str = "",
):
self.filename = filename
self.short_description = short_description
self.filepath: Path = base_location() / self.filename
self.authority = authority
self.invalid_if_older_than = invalid_if_older_than
self.update_interval_days = update_interval_days
self.description = inspect.cleandoc(description)
self._last_log_entry: Optional[str] = None
self.log_entry_re = re.compile(r"([0-9 :.-]+) - ([^:]+)(: (.*))?")
self.interval_fuzz: u.Quantity = 1 * u.hour
self._clock_file = None
self._tstart = None
self._tend = None
@property
def tstart(self):
return self._tstart
@property
def tend(self):
return self._tend
def needs_update(self) -> bool:
"""Check whether the update process needs to run.
This normally involves checking the current time against
the update schedule, but subclasses may override this
(for example checking whether other files have changed
recently).
"""
try:
t, r, m = self.parse_log_entry(self.last_log_entry)
except FileNotFoundError:
# Never looked before, go ahead
return True
else:
return (Time.now() - t).sec > (
self.update_interval_days * u.day - self.interval_fuzz
).to_value(u.s)
@property
def log_file(self):
"""Return the name of the log file. If it does not exist, also initialize."""
logfilename = base_location() / "log" / f"{self.filename}.log"
if not logfilename.exists():
with open(logfilename, "w") as f:
entry = f"{Time.now().iso} - " + "Initialized" + "\n"
f.write(entry)
return logfilename
def add_to_log(self, msg):
entry = f"{Time.now().iso} - " + msg.replace("\n", " ") + "\n"
with open(self.log_file, "at") as f:
f.write(entry)
self._last_log_entry = entry
@property
def last_log_entry(self) -> str:
if self._last_log_entry is None:
self._last_log_entry = open(self.log_file, "rt").readlines()[-1]
return self._last_log_entry
def parse_log_entry(self, entry):
r = self.log_entry_re.match(entry.strip())
reason = r.group(4)
if reason is None:
reason = ""
return Time(r.group(1), format="iso"), r.group(2), reason
def get(self, cache=False) -> Path:
raise NotImplementedError
def validate(self, new_file):
raise NotImplementedError
def try_update(self, cache=False, respect_interval=True, force=False):
if not force and respect_interval and not self.needs_update():
# No new data to be had, no log entry
return True
try:
f = self.get(cache=cache)
except IOError as e:
self.add_to_log(f"Failed to download: {e}")
return False
new_contents = Path(f).read_text()
try:
old_contents = self.filepath.read_text()
except FileNotFoundError:
pass
else:
if old_contents == new_contents:
self.add_to_log("Unchanged")
return True
try:
self.validate(f)
except ValidationError as e:
self.add_to_log(f"Validation failed: {e}")
if not force:
return False
self.filepath.write_text(new_contents)
self._clock_file = None
if force:
self.add_to_log("Updated overriding validation failure")
else:
self.add_to_log("Updated")
return True
def __repr__(self):
return (
f"{self.__class__.__name__}({self.short_description!r}, {self.filename!r})"
)
class ClockFileUpdater(FileUpdater):
def __init__(
self,
short_description: str,
filename: str,
authority: str = "temporary",
download_url: Optional[str] = None,
format: str = "tempo",
bogus_last_correction: bool = False,
obscode: Optional[str] = None,
invalid_if_older_than: Time = None,
update_interval_days: float = 7,
description: str = "",
):
super().__init__(
short_description,
filename,
authority=authority,
invalid_if_older_than=invalid_if_older_than,
update_interval_days=update_interval_days,
description=description,
)
self.format = format
self.bogus_last_correction = bogus_last_correction
self.download_url = download_url
self.obscode = obscode
self._last_log_entry: Optional[str] = None
self.log_entry_re = re.compile(r"([0-9 :.-]+) - ([^:]+)(: (.*))?")
def get(self, cache=False):
if self.download_url is not None:
return Path(download_file(self.download_url, cache=cache))
self.add_to_log(f"No way to download: {self.filename!r}")
return None
@property
def clock_file(self):
if self._clock_file is None:
if self.obscode is not None:
self._clock_file = ClockFile.read(
str(base_location() / self.filename),
format=self.format,
bogus_last_correction=self.bogus_last_correction,
obscode=self.obscode,
)
else:
self._clock_file = ClockFile.read(
str(base_location() / self.filename),
format=self.format,
bogus_last_correction=self.bogus_last_correction,
)
return self._clock_file
@property
def tstart(self):
if self.clock_file is None or len(self.clock_file.time) == 0:
return None
return self.clock_file.time[0]
@property
def tend(self):
if self.clock_file is None or len(self.clock_file.time) == 0:
return None
return self._clock_file.time[-1]
def validate(self, new_file):
old = self.clock_file
try:
if self.obscode is not None:
new = ClockFile.read(
str(new_file),
format=self.format,
bogus_last_correction=self.bogus_last_correction,
obscode=self.obscode,
)
else:
new = ClockFile.read(
str(new_file),
format=self.format,
bogus_last_correction=self.bogus_last_correction,
)
except ValueError as e:
raise ValidationError(
f"Unable to read new version of {self.filename}: {e}"
) from e
if len(old.time) > len(new.time):
raise ValidationError(
f"New version of {self.filename} has decreased from {len(old.clock)} "
f"to {len(new.clock)} measurements."
)
d = old.time != new.time[: len(old.time)]
if np.any(d):
raise ValidationError(
f"New version of {self.filename} MJDs differ from old "
f"version where they overlap in {np.sum(d)} places"
)
if len(old.clock) > 0:
d = old.clock[:-1] != new.clock[: len(old.clock) - 1]
else:
d = old.clock != new.clock[: len(old.clock)]
if np.any(d):
raise ValidationError(
f"New version of {self.filename} clock corrections differ from old "
f"version where they overlap in {np.sum(d)} places"
)
def details_page(self, make_plots_in_dir: Optional[Path] = None) -> str:
# Just ensure that this was loaded
self.clock_file
last_date, result, details = self.parse_log_entry(self.last_log_entry)
log_url = f"{public_repo_url_raw}log/{self.filename}.log"
f = StringIO()
f.write(
dedent(
f"""
## {self.short_description}
"""
)
)
f.write(self.description)
f.write(
dedent(
f"""
| | |
|:--- |:--- |
| File | `{self.filename}` |
| Authority | {self.authority} |
| URL in repository | <{public_repo_url_raw + self.filename}> |
| Original download URL | <{self.download_url}> |
| Format | {self.format} |
| Bogus last correction | {self.bogus_last_correction} |
| Clock file start | {short_date_and_mjd(self.tstart)} |
| Clock file end | {short_date_and_mjd(self.tend)} |
| Update interval (days) | {self.update_interval_days} |
| Last update attempt | {short_date(last_date)} |
| Last update result | {result} |
Log entries from the last few update attempts:
"""
)
)
f.write("```\n")
for line in self.log_file.open().readlines()[-10:]:
f.write(line)
f.write("```\n")
f.write(f"[Full log]({log_url})\n")
if self.clock_file.leading_comment:
self._write_leading_comment(f)
if make_plots_in_dir:
self._write_plot(make_plots_in_dir, f)
return f.getvalue()
def _write_plot(self, make_plots_in_dir: Path, f):
import matplotlib.pyplot as plt
from astropy.visualization import quantity_support
quantity_support()
size = (5, 2)
plt.figure()
plt.plot(self.clock_file.time.mjd, self.clock_file.clock.to(u.ns), ".")
self._finalize_plot(plt, size)
dpi = 144
plt.savefig(make_plots_in_dir / f"{self.filename}.png", dpi=dpi)
plt.close()
plt.figure()
n = 90
plt.plot(
self.clock_file.time.mjd[-n:], self.clock_file.clock[-n:].to(u.ns), "."
)
self._finalize_plot(plt, size)
plt.savefig(make_plots_in_dir / f"{self.filename}.short.png", dpi=dpi)
plt.close()
f.write(
dedent(
f"""
All clock corrections:
![plot of all clock corrections]({self.filepath.name}.png "All corrections")
Recent clock corrections:
![plot of recent clock corrections]({self.filepath.name}.short.png "Recent corrections")
""" # noqa
)
)
def _finalize_plot(self, plt, size):
plt.xlabel("MJD")
plt.ylabel("corr. (ns)")
plt.title(self.filename)
plt.gcf().set_size_inches(size)
plt.tight_layout()
def _write_leading_comment(self, f):
f.write("\n")
f.write("Leading comments from clock file:\n")
f.write("\n")
f.write(indent(self.clock_file.leading_comment, 4 * " "))
f.write("\n")
f.write("\n")
class ClockFileConverterUpdater(ClockFileUpdater):
def __init__(
self,
short_description,
filename,
updater: FileUpdater,
format="tempo2",
hdrline="",
description="",
):
super().__init__(
short_description,
filename,
authority="converted",
format=format,
update_interval_days=updater.update_interval_days,
description=description,
)
# FIXME: allow merging
self.hdrline = hdrline
self.updater = updater
def needs_update(self):
"""Check whether the converted file needs an update.
Essentially we need to check whether the last update of this file is
newer than the last update of the file it was converted from.
"""
try:
our_log = self.log_file.open().readlines()
except IOError:
return True
try:
other_log = self.updater.log_file.open().readlines()
except IOError:
# If *it* doesn't have a log file we're in trouble
return True
for e in our_log[::-1]:
our_t, msg, _ = self.parse_log_entry(e)
if msg.startswith("Updated"):
break
else:
# Seems we've never updated the file
return True
for e in other_log[::-1]:
other_t, msg, _ = self.parse_log_entry(e)
if msg.startswith("Updated"):
break
else:
# Seems we've never updated the other file?
return True
return our_t < other_t
def get(self, cache=False):
# combine self.updaters and write out an appropriate file
# need to write this somewhere temporary but persistent enough to last until
# it can be validated and used or discarded
# FIXME: get should return contents not a filename
filename = Path(tempfile.mkdtemp()) / "converted"
# FIXME: this results in a changed file every time the update checker
# is run, just because the conversion date is updated. We need to
# check and do updates only if the source file has been updated.
comments = (
f"# This file was automatically converted from "
f"{self.updater.filename} on {Time.now().iso}\n"
)
if self.format == "tempo2":
self.updater.clock_file.write_tempo2_clock_file(
str(filename),
self.hdrline,
extra_comment=comments,
)
else:
raise ValueError(f"Unknown format {self.format}")
return filename
class ClockFileCallableUpdater(ClockFileUpdater):
def __init__(
self,
short_description,
filename,
authority,
callable,
update_interval_days=1,
format="tempo2",
description="",
):
super().__init__(
short_description,
filename,
authority=authority,
format=format,
update_interval_days=update_interval_days,
description=description,
)
# FIXME: allow merging
self.callable = callable
def get(self, cache=False):
# FIXME: get should return contents not a filename
filename = Path(tempfile.mkdtemp()) / "converted"
clock_file = self.callable()
if self.format == "tempo2":
clock_file.write_tempo2_clock_file(filename)
else:
raise ValueError(f"Unknown format {self.format}")
return filename
class CallableUpdater(FileUpdater):
"""Updater for files that aren't clock files exactly."""
def __init__(
self,
short_description,
filename,
authority,
callable,
update_interval_days=0,
description="",
):
super().__init__(
short_description,
filename,
authority=authority,
update_interval_days=update_interval_days,
description=description,
)
self.callable = callable
def get(self, cache=False):
try:
contents, tstart, tend = self.callable()
except (IOError, ValueError) as e:
self.add_to_log(f"Exception: Problem computing new value {e}")
raise
# FIXME: no way to get tstart/tend if there hasn't been a get()
self._tstart, self._tend = tstart, tend
filename = Path(tempfile.mkdtemp()) / "generated"
filename.write_text(contents)
return filename
def validate(self, filename):
# No idea what to check, sorry
pass
def details_page(self, make_plots_in_dir=None):
last_date, result, details = self.parse_log_entry(self.last_log_entry)
log_url = f"{public_repo_url_raw}log/{self.filename}.log"
f = StringIO()
f.write(
dedent(
f"""
## {self.short_description}
"""
)
)
f.write(self.description)
f.write(
dedent(
f"""
| | |
|:--- |:--- |
| File | `{self.filename}` |
| Authority | {self.authority} |
| File start | {short_date_and_mjd(self.tstart)} |
| File end | {short_date_and_mjd(self.tend)} |
| Update interval (days) | {self.update_interval_days} |
| Last update attempt | {short_date(last_date)} |
| Last update result | {result} |
Log entries from the last few update attempts:
"""
)
)
f.write("```\n")
for line in self.log_file.open().readlines()[-10:]:
f.write(line)
f.write("```\n")
f.write(f"[Full log]({log_url})\n")
return f.getvalue()
tempo_repository_url = (
"https://sourceforge.net/p/tempo/tempo/ci/master/tree/clock/{}?format=raw"
)
tempo2_repository_url = (
"https://bitbucket.org/psrsoft/tempo2/raw/HEAD/T2runtime/clock/{}"
)
updaters: List[FileUpdater] = []
def get_updater(name: str) -> FileUpdater:
for updater in updaters:
if (
updater.short_description.lower() == name.lower()
or updater.filename == name
or Path(updater.filename).name == name
):
return updater
raise ValueError(f"Unable to find an updater for {name}")
def try_all_updates(respect_interval=True):
for updater in updaters:
updater.try_update(respect_interval=respect_interval)
print(f"{updater.short_description:20} {updater.last_log_entry.strip()}")
def short_date(t: Time) -> str:
return "---" if t is None else t.datetime.strftime("%Y-%m-%d")
def short_date_and_mjd(t: Time) -> str:
return "---" if t is None else f"{short_date(t)} MJD {t.mjd:.1f}"
def generate_index_txt():
with open(base_location() / "index.txt", "wt") as f:
print(f"{'# File':40s} {'Update (days)':13s} Invalid if older than", file=f)
for updater in updaters:
print(
f"{updater.filename:40s} {updater.update_interval_days:13.1f} "
f"{short_date(updater.invalid_if_older_than)}",
file=f,
)
def updater_summary_table(updaters: Iterable[FileUpdater], detail_urls=False) -> str:
o = StringIO()
print(
"| Name "
"| File "
"| Corrections start "
"| Corrections end "
"| Last check date "
"| Last check result ",
file=o,
)
print("|:--- |:--- | --- | --- | --- |:--- ", file=o)
for updater in updaters:
last_date, result, details = updater.parse_log_entry(updater.last_log_entry)
if (
hasattr(updater, "download_url")
and updater.download_url is None
and not np.isfinite(updater.update_interval_days)
):
result = "Static"
elif result not in {"Unchanged", "Updated"}:
result = f"**{result}**"
detail_url = f"{updater.filename}.html"
if detail_urls:
print(
f"| [{updater.short_description}]({detail_url}) "
f"| `{updater.filename}` "
f"| {short_date_and_mjd(updater.tstart)} "
f"| {short_date_and_mjd(updater.tend)} "
f"| {short_date(last_date)} "
f"| {result} ",
file=o,
)
else:
print(
f"| {updater.short_description} "
f"| `{updater.filename}` "
f"| {short_date_and_mjd(updater.tstart)} "
f"| {short_date_and_mjd(updater.tend)} "
f"| {short_date(last_date)} "
f"| {result} ",
file=o,
)
print(file=o)
return o.getvalue()
class PagesUpdater:
"""Update the gh_pages site.
The object should be pointed at a git repository with the gh_pages branch
checked out. It will update the information there, overwriting the
automatically generated files.
"""
def __init__(self, directory: Union[Path, str]):
self.directory = Path(directory)
if not (self.directory / ".this_is_gh_pages").exists():
raise ValueError(
f"Directory {directory} does not appear to contain the gh_pages branch."
)
def update_summary(self):
good_updaters = []
static_updaters = []
default_updaters = []
for updater in updaters:
if not np.isfinite(updater.update_interval_days):
static_updaters.append(updater)
elif (
updater.authority == "observatory"
or updater.authority == "converted"
and updater.updater.authority == "observatory"
):
good_updaters.append(updater)
elif not np.isfinite(updater.update_interval_days):
static_updaters.append(updater)
else:
default_updaters.append(updater)
with (self.directory / "status.md").open("wt") as f:
f.write(
dedent(
"""
## Clock correction status
This automatically generated file summarizes the status of
the clock corrections. It reports the date range covered by
the clock corrections as well as when the last attempt was
made to update the clock corrections and what happened. The
name of each clock file links to a page with more details.
"""
)
)
self._write_subsection(
f, "Files with fully automatic updates", good_updaters
)
self._write_subsection(f, "Files that should be static", static_updaters)
self._write_subsection(
f, "Files that require manual updates", default_updaters
)
f.write(
dedent(
"""
### Further information:
- [What is this repository?](index.html)
- [Instructions for using this repository with various software](instructions.html)
""" # noqa
)
)
def _write_subsection(self, f, title, contents):
f.write("\n\n")
f.write(f"### {title}\n\n")
f.write(updater_summary_table(contents, detail_urls=True))
def generate_details_pages(self):
for updater in updaters:
filename = self.directory / f"{updater.filename}.md"
filename.parent.mkdir(parents=True, exist_ok=True)
# FIXME: footer?
filename.write_text(updater.details_page(make_plots_in_dir=self.directory))
updaters.append(
ClockFileUpdater(
"GPS to UTC (TEMPO2)",
"T2runtime/clock/gps2utc_tempo2.clk",
download_url=tempo2_repository_url.format("gps2utc.clk"),
authority="temporary",
format="tempo2",
bogus_last_correction=True,
description="""GPS to UTC clock corrections
This file is used in the clock correction process for almost all
observatories.
This file is pulled from the TEMPO2 repository and may not be fully
up-to-date.
In TEMPO2 this file was traditionally generated by a script that parsed
BIPM Circular T and merged any new data into this file. This has
resulted in some anomalous entries at the merge points and also
a change in entries as Circular T has redefined what it publishes
(early entries in this file are from the column C0, later entries
are from the column C0').
""",
)
)
updaters.append(
ClockFileCallableUpdater(
"GPS to UTC",
"T2runtime/clock/gps2utc.clk",
authority="observatory",
callable=bipm.get_gps_merged,
description="""GPS to UTC clock corrections
This file is constructed from BIPM published data and should be up-to-date.
The BIPM publishes two different corrections from GPS to UTC:
the first, C0, corrects from the GPS Combined Clock to UTC. The second,
C0', corrects from a timescale that takes advantage of the broadcast
GPS almanac data to track UTC more closely.
This file uses C0' data when available, but that is only since 2011.
Prior to that this uses C0.
You may want to consider whether your GPS time standard is returning
the Combined Clock or whether it is using the almanac data. There are
more specific correction files suitable for one case or the other.
If you have questions about this, contact Anne Archibald
<[email protected]>. For more detailed questions
about the BIPM's published corrections, contact <[email protected]>.
""",
)
)
updaters.append(
ClockFileCallableUpdater(
"GPS to UTC (Combined Clock)",
"T2runtime/clock/gps2utc_cc.clk",
authority="observatory",
callable=bipm.get_gps_c0,
description="""GPS to UTC clock corrections (Combined Clock)
This file is constructed from BIPM published data and should be up-to-date.
The BIPM publishes two different corrections from GPS to UTC:
the first, C0, corrects from the GPS Combined Clock to UTC. The second,
C0', corrects from a timescale that takes advantage of the broadcast
GPS almanac data to track UTC more closely.
This file uses C0 data, that is, it is for GPS time standards that
do not take advantage of the almanac data to improve their time
correction.
If you have questions about this, contact Anne Archibald
<[email protected]>. For more detailed questions
about the BIPM's published corrections, contact <[email protected]>.
""",
)
)
updaters.append(
ClockFileCallableUpdater(
"GPS to UTC (Corrected)",
"T2runtime/clock/gps2utc_c0p.clk",
authority="observatory",
callable=bipm.get_gps_c0p,
description="""GPS to UTC clock corrections (Corrected)
This file is constructed from BIPM published data and should be up-to-date.
The BIPM publishes two different corrections from GPS to UTC:
the first, C0, corrects from the GPS Combined Clock to UTC. The second,
C0', corrects from a timescale that takes advantage of the broadcast
GPS almanac data to track UTC more closely.
This file uses C0' data, that is, it is for GPS time standards that
take advantage of the almanac data to improve their time correction.
Unfortunately the BIPM only publishes these corrections going back
to 2011.
If you have questions about this, contact Anne Archibald
<[email protected]>. For more detailed questions
about the BIPM's published corrections, contact <[email protected]>.
""",
)
)
updaters.append(
ClockFileUpdater(
"GBT",
"tempo/clock/time_gbt.dat",
download_url="https://www.gb.nrao.edu/~fghigo/timer/time_gbt.dat",
authority="observatory",
format="tempo",
obscode="1",
update_interval_days=1,
description="""Green Bank Telescope clock correction file
This file records the difference between UTC(GBT) and UTC(GPS).
The observatory distributes this file on the Web, updated about daily.
A discrepancy arose between the observatory-distributed file and the
file in this repository (which had been identical to the
observatory-distributed one up to that point). Around
2023-03-20 (MJD 60023), the first ~11 entries in the
observatory-distributed file were changed to zero.
Ryan Lynch expressed surprise that this had occurred, but no
resolution had arisen as of 2024-02-14. Since this resulted in
the new file failing validation and the file in this repository
not updating, at that point I (Anne Archibald) decided to
switch those entries to match the observatory values. The old values
are available from the version of the file in git tag
"gbt-mystery-values".
If questions arise, contact Ryan S. Lynch <[email protected]>.
""",
)
)
updaters.append(
ClockFileUpdater(
"GBT (TEMPO2)",
"T2runtime/clock/gbt2gps_tempo2.clk",
download_url=tempo2_repository_url.format("gbt2gps.clk"),
authority="temporary",
format="tempo2",
description="""Green Bank Telescope clock corrections (TEMPO2 version)
This file is pulled from the TEMPO2 repository and may not be fully
up-to-date.
""",
)
)
updaters.append(
ClockFileConverterUpdater(
"GBT (TEMPO2 converted from TEMPO)",
"T2runtime/clock/gbt2gps.clk",
format="tempo2",
description="""Green Bank Telescope clock corrections (TEMPO2 converted version)
This file is automativally converted from the TEMPO-format GBT
clock corrections, which are obtained directly from the observatory.
Thus these can be expected to be fully up to date. Please see the
GBT clock corrections file entry for further details.
If questions arise about the original data, contact Ryan S. Lynch
If questions arise about the conversion, contact Anne Archibald
""",
hdrline="# UTC(GBT) UTC(GPS)",
updater=get_updater("GBT"),
)
)
updaters.append(
ClockFileUpdater(
"Jodrell Bank (TEMPO)",
"tempo/clock/time_jb.dat",
download_url=tempo_repository_url.format("time_jb.dat"),
authority="temporary",
format="tempo",
obscode="8",
bogus_last_correction=True,
description="""Jodrell Bank clock correction file
This file is pulled from the TEMPO repository and may not be fully
up-to-date.
""",
)
)
updaters.append(
ClockFileUpdater(
"Jodrell Bank",
"T2runtime/clock/jb2gps.clk",
download_url=tempo2_repository_url.format("jb2gps.clk"),
authority="observatory",
format="tempo2",
bogus_last_correction=True,
description="""Jodrell Bank clock corrections file (TEMPO2)
Michael Keith periodically generates, manually checks, and updates
this file in the TEMPO2 repository.
Note that this contains only corrections for the main site clock;
data observed with a specific backend (Roach or DFB) also
need the corrections associated with that backend.
If questions arise, contact Michael Keith
""",
)
)
updaters.append(
ClockFileUpdater(
"Jodrell Bank Roach",
"T2runtime/clock/jbroach2jb.clk",
download_url=tempo2_repository_url.format("jbroach2jb.clk"),
authority="observatory",
format="tempo2",
bogus_last_correction=True,
description="""Jodrell Bank Roach backend
Michael Keith periodically generates, manually checks, and updates
this file in the TEMPO2 repository.
Note that this contains corrections for the Roach backend referenced
to the observatory clock.
If questions arise, contact Michael Keith
""",
)
)
updaters.append(
ClockFileUpdater(
"Jodrell Bank DFB",
"T2runtime/clock/jbdfb2jb.clk",
download_url=tempo2_repository_url.format("jbdfb2jb.clk"),
authority="observatory",
format="tempo2",
bogus_last_correction=True,
description="""Jodrell Bank DFB backend
Michael Keith periodically generates, manually checks, and updates
this file in the TEMPO2 repository.
Note that this contains corrections for the DFB backend referenced
to the observatory clock.
If questions arise, contact Michael Keith
""",
)
)
updaters.append(
ClockFileUpdater(
"Arecibo",
"tempo/clock/time_ao.dat",
download_url=tempo_repository_url.format("time_ao.dat"),
authority="temporary",