Skip to content

Fix slope azimuth of exactly east- or west-facing cells - #194

Merged
BenjaminRodenberg merged 1 commit into
mainfrom
fix-slope-gamma-zero-slope-y
Oct 26, 2026
Merged

BenjaminRodenberg merged 1 commit into
mainfrom
fix-slope-gamma-zero-slope-y

Conversation

@BenjaminRodenberg

@BenjaminRodenberg BenjaminRodenberg commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator

For MATLAB and NetCDF meshes, slope_gamma was built from a chain of arctan cases whose generic branches equal arctan2(slope_x, slope_y), but the slope_y == 0 special cases had the wrong sign: an east-facing cell got the azimuth of a west-facing one and vice versa, so its direct insolation peaked in the afternoon.

Replace the chain with slope_azimuth(), i.e. arctan2, keeping flat cells at 0 (arctan2(0, -0.0) is pi).

On examples/dem_and_mask.mat, 20 of 37993 cells are affected. In a 10-day June run (shading on and off) Tsurf changes by up to 1.7 K there; all other cells agree to 1e-15 (1-ulp differences in slope_gamma).

Assisted-by: Claude Code:claude-opus-5-5

Author's Todos

  • I ran the pre-commit hooks and fixed all issues
  • I added an entry under develop in the CHANGELOG.md (may be skipped for minor changes not observable for the user)

@BenjaminRodenberg BenjaminRodenberg self-assigned this Oct 20, 2026
@BenjaminRodenberg BenjaminRodenberg added the bug Something isn't working label Oct 20, 2026
@BenjaminRodenberg BenjaminRodenberg added this to the v0.9.0 milestone Oct 20, 2026
@BenjaminRodenberg
BenjaminRodenberg force-pushed the fix-slope-gamma-zero-slope-y branch 2 times, most recently from 0b1fc72 to 3b3f7c0 Compare October 20, 2026 16:03
@BenjaminRodenberg BenjaminRodenberg mentioned this pull request Oct 20, 2026
8 of 9 tasks
@BenjaminRodenberg
BenjaminRodenberg force-pushed the fix-slope-gamma-zero-slope-y branch from 3b3f7c0 to 046e9db Compare October 21, 2026 16:11
For MATLAB and NetCDF meshes, slope_gamma was built from a chain of
arctan cases whose generic branches equal arctan2(slope_x, slope_y),
but the slope_y == 0 special cases had the wrong sign: an east-facing
cell got the azimuth of a west-facing one and vice versa, so its
direct insolation peaked in the afternoon.

Replace the chain with slope_azimuth(), i.e. arctan2, keeping flat
cells at 0 (arctan2(0, -0.0) is pi).

On examples/dem_and_mask.mat, 20 of 37993 cells are affected. In a
10-day June run (shading on and off) Tsurf changes by up to 1.7 K
there; all other cells agree to 1e-15 (1-ulp differences in
slope_gamma).

Assisted-by: Claude Code:claude-opus-5-5
@BenjaminRodenberg
BenjaminRodenberg force-pushed the fix-slope-gamma-zero-slope-y branch from 046e9db to adf2951 Compare October 26, 2026 15:39
@BenjaminRodenberg
BenjaminRodenberg merged commit 4266dc8 into main Oct 26, 2026
43 of 44 checks passed
@BenjaminRodenberg
BenjaminRodenberg deleted the fix-slope-gamma-zero-slope-y branch October 26, 2026 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants