Skip to content

Conversation

@C1587S
Copy link
Contributor

@C1587S C1587S commented Jan 16, 2026

This PR adds geography-level aggregation support to MainRecipe, enabling damage calculations at different regional levels while maintaining backward compatibility

Changes

New parameters in MainRecipe.__init__:

  • geography: One of "ir" (impact region), "country", or "globe" (default)
  • country_mapping_path: Path to CSV mapping regions to countries (required for country aggregation)
  • individual_region: Optional filter for single-region calculations

New methods:

  • _aggregate_by_geography(): Internal helper for geography aggregation
  • _aggregate_to_country(): Helper for country-level aggregation
  • damages_dataset(): Returns damages as xr.Dataset with geography support
  • _filter_illegal_combinations_xr(): Xarray version of illegal combination filtering
  • _damage_function_points_pandas(): Original pandas-based implementation
  • _damage_function_points_xarray(): New xarray-based implementation

Dual-path execution:

  • When geography="globe" (default): uses original pandas path
  • When geography is "ir" or "country": uses new xarray path
  • Both paths return pd.DataFrame at the API boundary

Backward compatibility

  • Default geography="globe" preserves existing behavior
  • global_damages_calculation() returns pd.DataFrame (unchanged)
  • damage_function_points returns pd.DataFrame (unchanged)
  • All 238 existing tests pass without modification

Related PRs

Current status

  • All existing tests pass (238 passed, 5 skipped)
  • New geography tests verify aggregation logic
  • Pandas vs xarray path equivalence verified for globe geography
  • Return type consistency verified

@codecov
Copy link

codecov bot commented Jan 16, 2026

Codecov Report

❌ Patch coverage is 77.63158% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.07%. Comparing base (49eda98) to head (31010aa).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
src/dscim/menu/main_recipe.py 71.92% 16 Missing ⚠️
src/dscim/preprocessing/preprocessing.py 85.71% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #476      +/-   ##
==========================================
+ Coverage   68.94%   69.07%   +0.12%     
==========================================
  Files          15       15              
  Lines        1755     1814      +59     
==========================================
+ Hits         1210     1253      +43     
- Misses        545      561      +16     

☔ View full report in Codecov by Sentry.
📢 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.

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.

3 participants