fix(sipnet): use max timesteps per day to detect out_day, fixing partial first-day edge case#3989
Open
anshul23102 wants to merge 1 commit into
Open
Conversation
1c4a00d to
3d21280
Compare
mdietze
approved these changes
May 17, 2026
The previous code counted timesteps only from the first day of the simulation year to determine out_day (timesteps per day). If the simulation started mid-day, day 1 would have fewer rows than a complete day, causing out_day to be undercounted and all flux unit conversions to be off by a corresponding factor. Fix by counting rows per day across the entire first year and taking the maximum, which correctly represents a complete day regardless of whether the first or last day is partial. The old comment "switched to day 2 in case first day is partial" also suggested this intent, but the code still used [1] (day 1). This removes the ambiguity. Adds a regression test that verifies GPP conversion is correct when day 1 has only one timestep and subsequent days have two. Fixes PecanProject#3624.
c84f908 to
109f16b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #3624.
model2netcdf.SIPNETdetermines how many output timesteps SIPNET writes per day (out_day) by counting rows for a single day. The old code always used the first day of the simulation year:The comment acknowledged the problem (partial first day) but the code still read from day 1 (
[1]), not day 2. If SIPNET started mid-day, day 1 would have fewer rows than a complete day, makingout_daytoo small and applying an incorrect timestep to all flux unit conversions for the entire year.The fix counts rows per day across all days in the first simulation year and takes the maximum, which is the correct count for a complete day regardless of whether the first or last day is partial:
Changes
models/sipnet/R/model2netcdf.SIPNET.R: replace single-day row count withmax(table(...))over all daysmodels/sipnet/tests/testthat/test-model2netcdf.SIPNET.R: add regression test with a partial first day (1 timestep on day 1, 2 on days 2 and 3) that would have produced wrong GPP values under the old codemodels/sipnet/NEWS.md: changelog entryTest plan
"out_day is correct when the first day of output is partial"passes