Skip to content

Commit

Permalink
try to fix tests on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Nina.Hakansson committed Mar 6, 2024
1 parent 799c697 commit 8f201b6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
8 changes: 3 additions & 5 deletions satpy/readers/viirs_vgac_l1c_nc.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,11 @@ def extract_time_data(self, data, nc):
reference_time = np.datetime64(datetime.strptime(nc["proj_time0"].attrs["units"],
"days since %d/%m/%YT%H:%M:%S"))
delta_part_of_day, delta_full_days = np.modf(nc["proj_time0"].values[0])
delta_full_days = np.timedelta64(delta_full_days.astype(np.int64), "D")
delta_part_of_day = delta_part_of_day * np.timedelta64(1, "D").astype("timedelta64[ns]")
delta_hours = data.values * np.timedelta64(1, "h").astype("timedelta64[ns]")
delta_full_days = np.timedelta64(delta_full_days.astype(np.int64), "D").astype("timedelta64[us]")
delta_part_of_day = delta_part_of_day * np.timedelta64(1, "D").astype("timedelta64[us]")
delta_hours = data.values * np.timedelta64(1, "h").astype("timedelta64[us]")
time_data = xr.DataArray(reference_time + delta_full_days + delta_part_of_day + delta_hours,
coords=data.coords, attrs={"long_name": "Scanline time"})
self._start_time = self.dt64_to_datetime(time_data[0].values)
self._end_time = self.dt64_to_datetime(time_data[-1].values)
return time_data

def decode_time_variable(self, data, file_key, nc):
Expand Down
33 changes: 17 additions & 16 deletions satpy/tests/reader_tests/test_viirs_vgac_l1c_nc.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"""


import datetime
from datetime import datetime

import numpy as np
import pytest
Expand All @@ -33,7 +33,7 @@
@pytest.fixture()
def nc_filename(tmp_path):
"""Create an nc test data file and return its filename."""
now = datetime.datetime.utcnow()
now = datetime.utcnow()
filename = f"VGAC_VJ10XMOD_A{now:%Y%j_%H%M}_n004946_K005.nc"
filename_str = str(tmp_path / filename)
# Create test data
Expand Down Expand Up @@ -65,7 +65,7 @@ def nc_filename(tmp_path):
tb_lut[:] = np.array(range(0, n_lut)) * 0.5
tb_lut.units = "Kelvin"
reference_time = np.datetime64("2010-01-01T00:00:00")
start_time = np.datetime64("2023-03-28T09:08:07") + np.timedelta64(123, "ms")
start_time = np.datetime64("2023-03-28T09:08:07") + np.timedelta64(123000, "us")
delta_days = start_time - reference_time
delta_full_days = delta_days.astype("timedelta64[D]")
hidden_reference_time = reference_time + delta_full_days
Expand Down Expand Up @@ -95,28 +95,29 @@ def test_read_vgac(self, nc_filename):
reader="viirs_vgac_l1c_nc",
filenames=[nc_filename])
scn_.load(["M05", "M15", "scanline_timestamps"])
diff_s = (scn_["scanline_timestamps"][0] - np.datetime64("2023-03-28T09:08:07")
- np.timedelta64(123, "ms"))
diff_e = np.datetime64("2023-03-28T10:11:12") - scn_["scanline_timestamps"][-1]
assert (diff_e < np.timedelta64(5000, "ns"))
assert (diff_s < np.timedelta64(5000, "ns"))
assert (diff_e > np.timedelta64(-5000, "ns"))
assert (diff_s > np.timedelta64(-5000, "ns"))
diff_s = (scn_["scanline_timestamps"][0].values.astype('datetime64[us]') -
np.datetime64('2023-03-28T09:08:07.123000').astype('datetime64[us]'))
diff_e = (np.datetime64("2023-03-28T10:11:12.000000").astype('datetime64[us]') -
scn_["scanline_timestamps"][-1].values.astype('datetime64[us]'))
assert (diff_s < np.timedelta64(5, "us"))
assert (diff_e < np.timedelta64(5, "us"))
assert (diff_s > np.timedelta64(-5, "us"))
assert (diff_e > np.timedelta64(-5, "us"))
assert (scn_["M05"][0, 0] == 100)
assert (scn_["M15"][0, 0] == 400)
assert scn_.start_time == datetime.datetime(year=2023, month=3, day=28,
hour=9, minute=8, second=7)
assert scn_.end_time == datetime.datetime(year=2023, month=3, day=28,
hour=10, minute=11, second=12)
assert scn_.start_time == datetime(year=2023, month=3, day=28,
hour=9, minute=8, second=7)
assert scn_.end_time == datetime(year=2023, month=3, day=28,
hour=10, minute=11, second=12)

def test_dt64_to_datetime(self):
"""Test datetime conversion branch."""
from satpy.readers.viirs_vgac_l1c_nc import VGACFileHandler
fh = VGACFileHandler(filename="",
filename_info={"start_time": "2023-03-28T09:08:07"},
filetype_info="")
in_dt = datetime.datetime(year=2023, month=3, day=28,
hour=9, minute=8, second=7)
in_dt = datetime(year=2023, month=3, day=28,
hour=9, minute=8, second=7)
out_dt = fh.dt64_to_datetime(in_dt)
assert out_dt == in_dt

Expand Down

0 comments on commit 8f201b6

Please sign in to comment.