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

More informative log message when granule covers #77

Merged
merged 17 commits into from
May 5, 2021

Conversation

gerritholl
Copy link
Contributor

@gerritholl gerritholl commented Feb 4, 2021

Write a more informative log message when granule does cover the area of interest, and add a unit test for region_collector.

I had a case where a granule appeared to be added to both an Arctic and an Antarctic area:

    [DEBUG: 2021-02-03 17:21:27 : pytroll_collectors.trigger] mda: {'path': '', 'platform_name': 'Metop-B', 'start_time': datetime.datetime(2021, 2, 3, 16, 28, 3), 'end_time': datetime.datetime(2021, 2, 3, 16, 31, 3), 'processing_time': datetime.datetime(2021, 2, 3, 17, 19, 5), 'uri': '/data/pytroll/IN/EMC_AVR/AVHR_xxx_1B_M01_20210203162803Z_20210203163103Z_N_O_20210203171905Z', 'uid': 'AVHR_xxx_1B_M01_20210203162803Z_20210203163103Z_N_O_20210203171905Z', 'sensor': ['avhrr/3'], 'orig_platform_name': 'M01'}
    [DEBUG: 2021-02-03 17:21:27 : pytroll_collectors.region_collector] Adding area ID to metadata: eurol
    [INFO: 2021-02-03 17:21:27 : pytroll_collectors.region_collector] Added Metop-B (2021-02-03 16:28:03) granule to area eurol                                                                                                                              
    [DEBUG: 2021-02-03 17:21:27 : pytroll_collectors.region_collector] Adding area ID to metadata: nparktis1km
    [INFO: 2021-02-03 17:21:27 : pytroll_collectors.region_collector] Added Metop-B (2021-02-03 16:28:03) granule to area nparktis1km                                                                                                                        
    [DEBUG: 2021-02-03 17:21:27 : pytroll_collectors.region_collector] Adding area ID to metadata: spantarktis3km
    [INFO: 2021-02-03 17:21:27 : pytroll_collectors.region_collector] Added Metop-B (2021-02-03 16:28:03) granule to area spantarktis3km                                                                                                                     
    [DEBUG: 2021-02-03 17:21:27 : pytroll_collectors.region_collector] Adding area ID to metadata: npgroenland2200m
    [INFO: 2021-02-03 17:21:27 : pytroll_collectors.region_collector] Platform name Metop-B and sensor ['avhrr/3']: Start and end times = 20210203 16:28:03 20210203 16:31:03                                                                                

This doesn't happen systematically, but it should never happen. This PR adds a log message with information about the fraction of coverage that may hopefully help to debug this if/when it happens again (I have not yet been able to construct a reproducible case). In the end it turned out that the log messages were misleading; improved logging such as added in this PR will be helpful.

Also added unit tests for region_collector.

@ghost
Copy link

ghost commented Feb 5, 2021

DeepCode failed to analyze this pull request

Something went wrong despite trying multiple times, sorry about that.
Please comment this pull request with "Retry DeepCode" to manually retry, or contact us so that a human can look into the issue.

@gerritholl gerritholl marked this pull request as ready for review April 12, 2021 09:53
@gerritholl gerritholl marked this pull request as draft April 12, 2021 10:01
@gerritholl
Copy link
Contributor Author

There appear to be no unit tests for region_collector.py at all yet. I suppose I should add some before this PR can be processed?

Add unit test for region collector.  Incomplete, but tests the improved
logging added in the last commits.
@gerritholl gerritholl marked this pull request as ready for review April 12, 2021 15:00
@gerritholl
Copy link
Contributor Author

gerritholl commented Apr 12, 2021

Any volunteers for reviewing this? @pnuu @mraspaud? I don't have the rights to officially ask a review from you.

@pnuu pnuu requested review from pnuu, adybbroe and mraspaud April 12, 2021 15:06
@gerritholl
Copy link
Contributor Author

Should we set up CI before proceeding? The new unit tests pass for me, but I'm not very rigorous in testing locally with older Python versions.

@pnuu
Copy link
Member

pnuu commented Apr 12, 2021

I can have a go adding Github Actions for unit tests tomorrow morning.

The region gatherer unit test needs pyresample.  Install pyresample in
GitHub CI.
Unit tests need pytroll-schedule.  Add this as a test dependency.
Replace new Python syntax by syntax supported in Python 3.7.
@codecov
Copy link

codecov bot commented Apr 13, 2021

Codecov Report

Merging #77 (1ad5374) into master (7cb0d48) will increase coverage by 4.85%.
The diff coverage is 93.75%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #77      +/-   ##
==========================================
+ Coverage   72.85%   77.71%   +4.85%     
==========================================
  Files          13       14       +1     
  Lines        2461     2508      +47     
==========================================
+ Hits         1793     1949     +156     
+ Misses        668      559     -109     
Impacted Files Coverage Δ
pytroll_collectors/tests/test_region_collector.py 92.72% <92.72%> (ø)
pytroll_collectors/region_collector.py 78.35% <100.00%> (+78.35%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7cb0d48...1ad5374. Read the comment docs.

Satisfy codefactor by removing a FIXME and an unneccesary else after
return.
Copy link
Member

@pnuu pnuu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the work! I have some suggestions about the word orderings, take them or leave them 😁

pytroll_collectors/region_collector.py Outdated Show resolved Hide resolved
@@ -102,15 +102,14 @@ def collect(self, granule_metadata):
self.granule_times.add(ptime)
self.granules.append(granule_metadata)
self.last_file_added = True
LOG.info("Added %s (%s) granule to area %s",
LOG.info("Added %s (%s) granule to area %s because we expect it",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
LOG.info("Added %s (%s) granule to area %s because we expect it",
LOG.info("Added overlapping granule %s (%s) to area %s",

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chose a slightly different formulation instead. One aim was that I wanted to understand from my logs whether granules were added because they were expected, or because they were newly overlapping.

pytroll_collectors/region_collector.py Outdated Show resolved Hide resolved
@@ -127,8 +126,7 @@ def collect(self, granule_metadata):

if new_timeout < self.timeout:
self.timeout = new_timeout
LOG.info("Adjusted timeout: %s",
self.timeout.isoformat())
LOG.info(f"Adjusted timeout for {platform!s}: {self.timeout:%Y-%m-%d %H:%M:%S}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
LOG.info(f"Adjusted timeout for {platform!s}: {self.timeout:%Y-%m-%d %H:%M:%S}")
LOG.info(f"Adjusted timeout for {platform!s} to {self.timeout:%Y-%m-%d %H:%M:%S}")

@@ -160,7 +161,7 @@ def collect(self, granule_metadata):

if not self.planned_granule_times:
self.planned_granule_times.add(start_time)
LOG.info("Added %s (%s) granule to area %s",
LOG.info("Added %s (%s) granule to area %s because it overlaps",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
LOG.info("Added %s (%s) granule to area %s because it overlaps",
LOG.info("Added overlapping granule %s (%s) to area %s",

@@ -21,7 +21,7 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install -U pytest pytest-cov trollsift six netifaces watchdog posttroll pyyaml pyinotify
pip install -U pytest pytest-cov trollsift six netifaces watchdog posttroll pyyaml pyinotify pyresample pytroll-schedule
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catches!

gerritholl and others added 4 commits April 13, 2021 12:22
Improve test coverage in region_collector.  Remove code that I'm
convinced is never reached.
Co-authored-by: Panu Lahtinen <pnuu+git@iki.fi>
@gerritholl
Copy link
Contributor Author

Retry DeepCode

@pnuu pnuu merged commit 5429c1f into pytroll:main May 5, 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

Successfully merging this pull request may close these issues.

None yet

2 participants