Skip to content

🐛[BUG]: cos zenith computation does not account for leap seconds #1047

@nbren12

Description

@nbren12

Version

main

On which installation method(s) does this occur?

No response

Describe the issue

As @azrael417 noted, the cos zenith implementation in physicsnemo does not account for leap seconds.

The reason is that unix timestamps are not correctly being converted into the number of actual seconds elapsed since 2000 Jan 1. This is not simply the difference of the unix timestamps since unix timestamps don't account for leap seconds. So for later times, the result is shifted in lon by about 10 seconds = 10 / 86400 * 360 = 0.0625 degrees. This is small for many applications, but worth fixing.

Here is a fix proposed by chat GPT, though we may want to verify the list of leap seconds.

import torch

# Leap second insertion times as torch tensor
leap_seconds_unix = torch.tensor([
    78796800, 94694400, 126230400, 157766400, 189302400, 220924800,
    252460800, 283996800, 315532800, 362793600, 394329600, 425865600,
    489024000, 567993600, 631152000, 662688000, 709948800, 741484800,
    773020800, 820454400, 867715200, 915148800, 1136073600, 1230768000,
    1341100800, 1435708800, 1483228800
], dtype=torch.int64)

EPOCH_2000 = 946684800  # 2000-01-01 00:00:00 UTC
leap_before_2000 = torch.bucketize(
    torch.tensor([EPOCH_2000]), leap_seconds_unix, right=True
)[0]

def seconds_since_2000_with_leap_vectorized(unix_ts_tensor):
    # unix_ts_tensor: 1D or ND tensor of int64 Unix timestamps
    leap_counts = torch.bucketize(unix_ts_tensor, leap_seconds_unix, right=True)
    leap_deltas = leap_counts - leap_before_2000
    return (unix_ts_tensor - EPOCH_2000) + leap_deltas

Minimum reproducible example

Relevant log output

Environment details

Metadata

Metadata

Labels

? - Needs TriageNeed team to review and classifybugSomething isn't workingexternalIssues/PR filed by people outside the team

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions