-
Notifications
You must be signed in to change notification settings - Fork 18
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
More informative log message when granule covers #77
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
66028e8
More informative log message when granule covers
gerritholl 8842248
Add missing whitespace character
gerritholl 2380c76
Differentiate between reasons for adding granule
gerritholl d8de77a
Be more verbose in logging planned granules
gerritholl 2ecd079
Add platform to more debug messages
gerritholl 49221e9
Add unit test for region collector
gerritholl a8b4ef5
PEP8 fixes
gerritholl 3135b13
Merge branch 'master' into improve-logging
gerritholl ef0ac71
Add pyresample as test dependency
gerritholl ae287dc
Add pytroll-schedule as test dependency
gerritholl 0096d29
Replace new by old Python syntax
gerritholl 19d8ff3
Satisfy codefactor
gerritholl 9d7ec59
Improve test coverage in region_collector
gerritholl 1ddb325
Apply some suggestions from code review
gerritholl 5b0ebbb
Reformulate log messages
gerritholl 0205dbf
Merge branch 'improve-logging' of github.com:gerritholl/pytroll-colle…
gerritholl 1ad5374
Adapt unit test to new log formulation
gerritholl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
"""Test region collector functionality.""" | ||
|
||
import logging | ||
import pytest | ||
import datetime | ||
import unittest.mock | ||
import io | ||
|
||
yaml_europe = """ | ||
euro_ma: | ||
description: euro_ma | ||
projection: | ||
proj: stere | ||
lat_0: 45 | ||
lon_0: 15 | ||
k: 1 | ||
x_0: 0 | ||
y_0: 0 | ||
ellps: WGS84 | ||
no_defs: null | ||
shape: | ||
height: 1069 | ||
width: 1538 | ||
area_extent: | ||
lower_left_xy: | ||
- -3845890.2472199923 | ||
- -2150868.4484187816 | ||
upper_right_xy: | ||
- 3845890.2472199923 | ||
- 3198354.325865823 | ||
units: m | ||
""" | ||
|
||
tles = b""" | ||
METOP-C | ||
1 43689U 18087A 21101.60865186 .00000002 00000-0 20894-4 0 9998 | ||
2 43689 98.6928 163.0161 0002296 181.8672 178.2497 14.21491657125954 | ||
""" | ||
|
||
|
||
@pytest.fixture | ||
def europe(): | ||
"""Return european AreaDefinition.""" | ||
from pyresample.area_config import load_area_from_string | ||
return load_area_from_string(yaml_europe) | ||
|
||
|
||
@pytest.fixture | ||
def europe_collector(europe): | ||
"""Construct RegionCollector for Central Europe.""" | ||
from pytroll_collectors.region_collector import RegionCollector | ||
return RegionCollector(europe) | ||
|
||
|
||
def _fakeopen(url): | ||
return io.BytesIO(tles) | ||
|
||
|
||
def test_init(europe): | ||
"""Test that initialisation appears to work.""" | ||
from pytroll_collectors.region_collector import RegionCollector | ||
RegionCollector(europe) | ||
|
||
|
||
@unittest.mock.patch("pyorbital.tlefile.urlopen", new=_fakeopen) | ||
def test_collect(europe_collector, caplog): | ||
"""Test that granules can be collected.""" | ||
granule_metadata = { | ||
"platform_name": "Metop-C", | ||
"sensor": "avhrr"} | ||
|
||
with caplog.at_level(logging.DEBUG): | ||
for s_min in (0, 3, 6, 9, 12, 15, 18): | ||
europe_collector.collect( | ||
{**granule_metadata, | ||
**{"start_time": datetime.datetime(2021, 4, 11, 10, s_min, 0), | ||
"end_time": datetime.datetime(2021, 4, 11, 10, s_min+3, 0), | ||
"uri": f"file://{s_min:d}"}}) | ||
|
||
assert "Granule file://0 is overlapping region euro_ma by fraction 0.03685" in caplog.text | ||
assert "Added new overlapping granule Metop-C (2021-04-11 10:00:00) to area euro_ma" in caplog.text | ||
assert "Collection finished for Metop-C area euro_ma" in caplog.text | ||
for n in (3, 6, 9, 12, 15): | ||
assert f"Added expected granule Metop-C (2021-04-11 10:{n:>02d}:00) to area euro_ma" in caplog.text | ||
assert "Granule file://18 is not overlapping euro_ma" | ||
|
||
|
||
@unittest.mock.patch("pyorbital.tlefile.urlopen", new=_fakeopen) | ||
def test_collect_duration(europe): | ||
"""Test with tle_platform_name, without end_time, using call syntax.""" | ||
from pytroll_collectors.region_collector import RegionCollector | ||
alt_europe_collector = RegionCollector( | ||
europe, | ||
timeliness=datetime.timedelta(seconds=300), | ||
granule_duration=datetime.timedelta(seconds=120)) | ||
granule_metadata = { | ||
"sensor": ["avhrr"], | ||
"tle_platform_name": "Metop-C", | ||
"start_time": datetime.datetime(2021, 4, 11, 0, 0)} | ||
alt_europe_collector(granule_metadata) | ||
|
||
|
||
@unittest.mock.patch("pyorbital.tlefile.urlopen", new=_fakeopen) | ||
def test_adjust_timeout(europe, caplog): | ||
"""Test timeout adjustment.""" | ||
from pytroll_collectors.region_collector import RegionCollector | ||
granule_metadata = { | ||
"sensor": "avhrr", | ||
"tle_platform_name": "Metop-C", | ||
"uri": "file://alt/0"} | ||
alt_europe_collector = RegionCollector( | ||
europe, | ||
granule_duration=datetime.timedelta(seconds=180)) | ||
|
||
with caplog.at_level(logging.DEBUG): | ||
alt_europe_collector.collect( | ||
{**granule_metadata, | ||
"start_time": datetime.datetime(2021, 4, 11, 10, 0)}) | ||
alt_europe_collector.collect( | ||
{**granule_metadata, | ||
"start_time": datetime.datetime(2021, 4, 11, 10, 15)}) | ||
alt_europe_collector.collect( | ||
{**granule_metadata, | ||
"start_time": datetime.datetime(2021, 4, 11, 10, 12)}) | ||
assert "Adjusted timeout" in caplog.text | ||
|
||
|
||
@pytest.mark.skip(reason="test never finishes") | ||
@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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catches!