Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

region collector never finishes if start_time after end_time (probably stuck in infinite loop) #82

Open
gerritholl opened this issue Apr 13, 2021 · 0 comments

Comments

@gerritholl
Copy link
Contributor

When the end time for a granule is before the start time, the region collector is apparently supposed to do something clever, judging from this code block:

if start_time > end_time:
old_end_time = end_time
end_date = start_time.date()
if end_time.time() < start_time.time():
end_date += timedelta(days=1)
end_time = datetime.combine(end_date, end_time.time())
LOG.debug('Adjusted end time from %s to %s.',
old_end_time, end_time)

However, I've tried to write a unit test for this, see #77 or

https://github.com/gerritholl/pytroll-collectors/blob/1ad53748b5b2c267f6513a13a1cb5d6b23cfc50c/pytroll_collectors/tests/test_region_collector.py

where this unit test never finishes, apparently stuck in an infinite loop:

@unittest.mock.patch("pyorbital.tlefile.urlopen", new=_fakeopen)
def test_faulty_end_time(europe_collector, caplog):
    """Test adapting if end_time before start_time."""
    granule_metadata = {
        "platform_name": "Metop-C",
        "sensor": "avhrr",
        "start_time": datetime.datetime(2021, 4, 11, 0, 0),
        "end_time": datetime.datetime(2021, 4, 10, 23, 58)}
    with caplog.at_level(logging.DEBUG):
        europe_collector(granule_metadata)
    assert "Adjusted end time" in caplog.text

which I suspect to be either one of those two:

while True:
gr_time += self.granule_duration
gr_pass = Pass(platform, gr_time,
gr_time + self.granule_duration,
instrument=self.sensor)
if not gr_pass.area_coverage(self.region) > 0:
break
self.planned_granule_times.add(gr_time)
gr_time = start_time
while True:
gr_time -= self.granule_duration
gr_pass = Pass(platform, gr_time,
gr_time + self.granule_duration,
instrument=self.sensor)
if not gr_pass.area_coverage(self.region) > 0:
break
self.planned_granule_times.add(gr_time)

@gerritholl gerritholl changed the title region collector never finished is end_time before start_time (probably stuck in infinite loop) region collector never finished start_time after end_time (probably stuck in infinite loop) Apr 13, 2021
@gerritholl gerritholl changed the title region collector never finished start_time after end_time (probably stuck in infinite loop) region collector never finishes if start_time after end_time (probably stuck in infinite loop) Apr 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant