Skip to content

Commit

Permalink
Merge pull request pytroll#2676 from pnuu/seviri-nanosecond-times
Browse files Browse the repository at this point in the history
  • Loading branch information
mraspaud authored Dec 12, 2023
2 parents 338817d + df26a58 commit f4725c2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
4 changes: 3 additions & 1 deletion satpy/readers/seviri_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,8 +475,10 @@ def get_cds_time(days, msecs):
days = np.array([days], dtype="int64")
msecs = np.array([msecs], dtype="int64")

# use nanosecond precision to silence warning from XArray
nsecs = 1000000 * msecs.astype("timedelta64[ns]")
time = np.datetime64("1958-01-01").astype("datetime64[ms]") + \
days.astype("timedelta64[D]") + msecs.astype("timedelta64[ms]")
days.astype("timedelta64[D]") + nsecs
time[time == np.datetime64("1958-01-01 00:00")] = np.datetime64("NaT")

if len(time) == 1:
Expand Down
19 changes: 12 additions & 7 deletions satpy/tests/reader_tests/test_seviri_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,28 @@ def test_chebyshev(self):
exp = chebyshev4(coefs, time, domain)
np.testing.assert_allclose(res, exp)

def test_get_cds_time(self):
"""Test the get_cds_time function."""
# Scalar
def test_get_cds_time_scalar(self):
"""Test the get_cds_time function for scalar inputs."""
assert get_cds_time(days=21246, msecs=12 * 3600 * 1000) == np.datetime64("2016-03-03 12:00")

# Array
def test_get_cds_time_array(self):
"""Test the get_cds_time function for array inputs."""
days = np.array([21246, 21247, 21248])
msecs = np.array([12*3600*1000, 13*3600*1000 + 1, 14*3600*1000 + 2])
expected = np.array([np.datetime64("2016-03-03 12:00:00.000"),
np.datetime64("2016-03-04 13:00:00.001"),
np.datetime64("2016-03-05 14:00:00.002")])
np.testing.assert_equal(get_cds_time(days=days, msecs=msecs), expected)
res = get_cds_time(days=days, msecs=msecs)
np.testing.assert_equal(res, expected)

def test_get_cds_time_nanoseconds(self):
"""Test the get_cds_time function for having nanosecond precision."""
days = 21246
msecs = 12*3600*1000
msecs = 12 * 3600 * 1000
expected = np.datetime64("2016-03-03 12:00:00.000")
np.testing.assert_equal(get_cds_time(days=days, msecs=msecs), expected)
res = get_cds_time(days=days, msecs=msecs)
np.testing.assert_equal(res, expected)
assert res.dtype == np.dtype("datetime64[ns]")

def test_pad_data_horizontally_bad_shape(self):
"""Test the error handling for the horizontal hrv padding."""
Expand Down

0 comments on commit f4725c2

Please sign in to comment.