Skip to content

Add bz2 support to the metimage_l1b_nc reader - #3433

Merged
djhoese merged 24 commits into
pytroll:mainfrom
FabMin94:feat-bz2-vii
Sep 9, 2026
Merged

djhoese merged 24 commits into
pytroll:mainfrom
FabMin94:feat-bz2-vii

Conversation

@FabMin94

@FabMin94 FabMin94 commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Adds bz2-compressed (.nc.bz2) file support to the VII/metimage readers, so compressed granules from the EUMETSAT data hub can be read without manual decompression first.

ViiNCBaseFileHandler.__init__ now decompresses via the existing unzip_file() helper (satpy.readers.core.utils) before opening the file, same approach used by ahi_l1b_gridded_bin.py. This lives in the shared base class, so it also applies to ViiL2NCFileHandler — L2 wasn't specifically tested here, but the change is in a code path both share identically.

Also updates the vii_l1b_nc.yaml file pattern to match .nc.bz2 filenames.

Trade-off: decompression happens eagerly per-granule (~113MB temp disk per
file); see #3432 for more detail on why this was chosen over a streaming
approach.

@codecov

codecov Bot commented Jul 31, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.34%. Comparing base (17bf08d) to head (542475f).
⚠️ Report is 11 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff            @@
##             main    #3433    +/-   ##
========================================
  Coverage   96.34%   96.34%            
========================================
  Files         465      465            
  Lines       59151    59376   +225     
========================================
+ Hits        56990    57208   +218     
- Misses       2161     2168     +7     
Flag Coverage Δ
behaviourtests 3.57% <0.00%> (-0.02%) ⬇️
unittests 96.43% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@gerritholl

Copy link
Copy Markdown
Member

Thanks for the PR! It looks like the tests are failing on Windows ☹. Unfortunately, I know very little about Windows coding myself. Maybe it would work with a pytest fixture for temporary files?

@djhoese djhoese left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Unfortunately I think @gerritholl is right and it may be easiest to use pytest fixtures and use tmp_path to manage the creation and deletion of these files. Extra unfortunately is that this test class is a unittest TestCase so it can't use pytest fixtures directly. It would have to be converted. That would movstly involve changing the setUp and tearDown into fixtures so they can be used by the new fixture(s) needed for your tests.

Comment thread satpy/readers/core/vii_nc.py Resolved
@FabMin94

FabMin94 commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for the pointer — makes sense. I converted the bz2-related tests (test_bz2_reading, test_corrupt_bz2_raises) to plain pytest functions with tmp_path fixtures, so there's no more manual filename/cleanup handling for those. Left the rest of the file (setUp/tearDown, existing TestCase methods) as-is for now — wasn't sure if a full conversion was expected here or as a separate change, happy to do it if you'd like.

Also took your point on the __del__ logging — removed the logger.warning() call, it just swallows the cleanup failure silently now. Added a small test to check __del__ doesn't raise even when removing the temp file fails.

On the Windows failures:

  • test_bz2_reading: __del__ was removing the decompressed temp file before the base class's file handle was released — fine on Linux/macOS, not on Windows. Reordered so the handle closes first.
  • test_corrupt_bz2_raises: turned out unrelated to my changes. On Windows this raises WinError 32 ("file in use by another
    process") directly from unzip_file() in satpy/readers/core/utils.py, before any VII code runs — confirmed via the log line
    pointing at the same temp file right before the error. Looks like unzip_file() opens/reopens the same temp path in a way
    that's fine on POSIX but not Windows. I've loosened my test to check exception type only (the message is locale- and
    platform-dependent), but this seems like a separate, pre-existing bug worth its own issue — happy to file one if useful.

@ameraner

ameraner commented Aug 4, 2026

Copy link
Copy Markdown
Member

Hi @FabMin94 , thank you for your work on this. Just note that we have renamed the reader and some class names therein, so you might need to deal with some conflicts now, sorry for that.. See #3395

@ameraner ameraner changed the title Add bz2 support to the vii_l1b_nc reader. Fixes #3432 Add bz2 support to the vii_l1b_nc reader Aug 4, 2026
@FabMin94

FabMin94 commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

Thank you all for the input.

@djhoese djhoese added enhancement code enhancements, features, improvements component:readers labels Sep 1, 2026
Comment thread satpy/readers/core/metimage_nc.py Resolved
…p test.

Delete the decompressed temp file directly and call __del__() on it,
instead of mocking os.remove to raise. FileNotFoundError is a real
OSError subclass, so this exercises the same suppress(AttributeError, OSError)
path in __del__ without depending on how os.remove happens to be
imported in production code.
@FabMin94 FabMin94 changed the title Add bz2 support to the vii_l1b_nc reader Add bz2 support to the metimage_l1b_nc reader Sep 2, 2026
@FabMin94
FabMin94 requested a review from djhoese September 2, 2026 08:38
@djhoese

djhoese commented Sep 2, 2026

Copy link
Copy Markdown
Member

Regarding @Manny7717's comment on the numpy warning, Claude confirmed that is in the netcdf4-python library and has been fixed upstream. Side note: @Manny7717 I sent you an email.

I'll make more comments about a few last changes...

Comment thread satpy/readers/core/metimage_nc.py Resolved
Comment thread satpy/etc/readers/metimage_l1b_nc.yaml Resolved
Comment thread satpy/readers/core/metimage_nc.py Resolved
@djhoese

djhoese commented Sep 2, 2026

Copy link
Copy Markdown
Member

Last comment for now: Any interest in adding your name to the AUTHORS.md list?

@FabMin94
FabMin94 requested a review from djhoese September 4, 2026 08:34

@djhoese djhoese left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think I'm done complaining. Thanks for sticking with this after all the changes I requested. I think this is in a good state (besides the #3456 bug that Claude found). @ameraner or @pnuu care to do one last review?

@pnuu pnuu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good to me.

@ameraner ameraner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good to me too, thank you for all the efforts!

@djhoese
djhoese merged commit 73ae7e4 into pytroll:main Sep 9, 2026
17 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component:readers enhancement code enhancements, features, improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support files from Metimage global data dumps

6 participants