Skip to content

feat: guard CMORisation against missing input files#554

Merged
rbeucher merged 2 commits into
mainfrom
feat/file-completeness-check
Jul 24, 2026
Merged

feat: guard CMORisation against missing input files#554
rbeucher merged 2 commits into
mainfrom
feat/file-completeness-check

Conversation

@rbeucher

@rbeucher rbeucher commented Jul 24, 2026

Copy link
Copy Markdown
Member

Summary

Add a filename-based completeness check to file_discovery so that missing
monthly (or yearly) raw output files are caught before any file I/O or
CMORisation begins.

Changes

src/access_moppy/file_discovery.py

  • _extract_year_month_from_path(path) — extends the year parser to also return
    the month, covering all known ACCESS filename conventions.
  • MissingInputFilesError(FileDiscoveryError) — new exception with a .missing
    list of (year, month) tuples.
  • check_file_completeness(paths, freq) — public, filename-only function that
    returns missing monthly or annual slots. Works for all sub-annual frequencies
    (mon, day, 3hr, 6hr, 1hr) and falls back to annual for yr / ocean files.
  • discover_files(..., check_completeness=False) — when True, raises
    MissingInputFilesError before any file I/O. fx fields are exempt.

tests/unit/test_file_discovery.py

  • 20 new unit tests covering all new code paths.

Usage

files = discover_files(
    archive_root, "6hrPlevPt.hurs",
    model_id="ACCESS-ESM1-6",
    check_completeness=True,   # raises MissingInputFilesError if months absent
)

rbeucher added 2 commits July 24, 2026 12:33
Add filename-based completeness check to file discovery:

- Add `_extract_year_month_from_path()` that returns (year, month) or
  (year, None) for all known ACCESS filename conventions.
- Add `MissingInputFilesError(FileDiscoveryError)` with a `.missing`
  attribute listing the absent (year, month) slots.
- Add public `check_file_completeness(paths, freq)` that inspects
  filenames only (no file I/O) and returns missing monthly or annual
  slots. Works for all sub-annual frequencies (mon, day, 3hr, 6hr, 1hr)
  via YYYYMM filename parsing, and falls back to annual checking for yr
  or ocean annual files.
- Add `check_completeness=False` parameter to `discover_files()`:
  when True, raises `MissingInputFilesError` before any file I/O if
  expected monthly/yearly files are absent. fx fields are exempt.
- Export new symbols from `__all__`.
- Add 20 unit tests covering all new code paths.
@codecov

codecov Bot commented Jul 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.00000% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.5%. Comparing base (f14320a) to head (2a7c80b).

Files with missing lines Patch % Lines
src/access_moppy/file_discovery.py 90.0% 3 Missing and 4 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##            main    #554     +/-   ##
=======================================
+ Coverage   74.3%   74.5%   +0.1%     
=======================================
  Files         36      36             
  Lines       7274    7343     +69     
  Branches    1354    1373     +19     
=======================================
+ Hits        5408    5470     +62     
- Misses      1581    1584      +3     
- Partials     285     289      +4     
Flag Coverage Δ
unit 74.5% <90.0%> (+0.1%) ⬆️

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.

@rbeucher
rbeucher merged commit ebba7fb into main Jul 24, 2026
4 checks passed
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.

1 participant