Skip to content

Commit

Permalink
Handle scans starting earlier than planned
Browse files Browse the repository at this point in the history
  • Loading branch information
sfinkens committed Feb 13, 2024
1 parent 67dd4a8 commit 911bc4d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 11 deletions.
31 changes: 28 additions & 3 deletions satpy/readers/ahi_hsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -792,10 +792,35 @@ def _modify_observation_time_for_nominal(self, observation_time):
stacklevel=3
)
return observation_time
timeline = self._get_closest_timeline(observation_time)
dt = self._get_offset_relative_to_timeline()
return observation_time.replace(
hour=self.timeline.hour, minute=self.timeline.minute + dt//60,
second=dt % 60, microsecond=0)
return timeline + timedelta(minutes=dt//60, seconds=dt % 60)

def _get_closest_timeline(self, observation_time):
"""Find the closest timeline for the given observation time.
Needs to check surrounding days because the observation might start
a little bit before the planned time.
Observation start time: 2022-12-31 23:59
Timeline: 0000
=> Nominal start time: 2023-01-01 00:00
"""
delta_days = [-1, 0, 1]
surrounding_dates = [
(observation_time + timedelta(days=delta)).date()
for delta in delta_days
]
timelines = [
datetime.combine(date, self.timeline)
for date in surrounding_dates
]
diffs = [
abs((timeline - observation_time))
for timeline in timelines
]
argmin = np.argmin(diffs)
return timelines[argmin]

def _get_offset_relative_to_timeline(self):
if self.area == "FLDK":
Expand Down
16 changes: 8 additions & 8 deletions satpy/tests/reader_tests/test_ahi_hsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,16 +707,16 @@ def test_areas(self, area, expected):
("timeline", "obs_start_time", "expected"),
[
(
"1200",
datetime(2023, 1, 1, 12, 0, 1),
{"tstart": datetime(2023, 1, 1, 12, 0, 0),
"tend": datetime(2023, 1, 1, 12, 10, 0)}
"2350",
datetime(2022, 12, 31, 23, 50, 1),
{"tstart": datetime(2022, 12, 31, 23, 50, 0),
"tend": datetime(2023, 1, 1, 0, 0, 0)}
),
(
"1200",
datetime(2023, 1, 1, 11, 59, 59),
{"tstart": datetime(2023, 1, 1, 12, 0, 0),
"tend": datetime(2023, 1, 1, 12, 10, 0)}
"2350",
datetime(2022, 12, 31, 23, 49, 59),
{"tstart": datetime(2022, 12, 31, 23, 50, 0),
"tend": datetime(2023, 1, 1, 0, 0, 0)}
),
(
"0000",
Expand Down

0 comments on commit 911bc4d

Please sign in to comment.