Repository navigation
Description
Brief summary of bug
From some code inspection, I see what look like minor bugs in crop phenology when running with a Gregorian calendar.
General bug information
CTSM version you are using: latest master
Does this bug cause significantly incorrect results in the model's science? Maybe: I haven't thought carefully or investigated the magnitude of the impact. I suspect the impact is small, but I'm not positive about that.
Configurations affected: Runs with prognostic crops and a Gregorian calendar
Details of bug
I see two issues that look like bugs (though there may be others as well):
-
Some crops have a
max_SH_planting_dateof 1231. Normallyget_caldaywill turn this into the value 365. However, if the run uses a Gregorian calendar, thenget_caldayuses a year of 0 for this date (because the general format isyyyymmdd, so 1231 implicitly has a year of 0); year 0 is considered a leap year, soget_caldayactually returns a value of 366 for these crops. This is true with or without the Gregorian calendar "hack" that I just removed in c432b6d (since the value is exactly 366.0, that hack wasn't getting triggered for this value). I'm not sure what the implications of this are, but it seems possible that planting gets skipped entirely in some circumstances on non-leap years. -
The calculation of days past planting:
CTSM/src/biogeochem/CNPhenologyMod.F90
Line 2033 in 5717571
idpp = int(dayspyr) + jday - idop(p) uses the number of days per year in the current year. However, I think what's relevant here is the number of days per year in the previous year. (Imagine that it's now Jan 2, and planting happened on Dec. 30 of the previous year. Whether this year is a leap year is irrelevant; what matters for doing this day subtraction is whether last year was a leap year, and so whether Dec 30 was day of year 364 or 365 last year.) I haven't followed this through the code to see the impact of this issue, though my gut feeling is that it's probably relatively small.
Activity
[-]Minor(?) bugs in crop phenology when running with a Gregorian calendar[/-][+]Bugs in crop phenology when running with a Gregorian calendar[/+]billsacks commentedon Jan 7, 2022
Thinking about (1) more, I think it really may lead to certain crops sometimes not getting planted at all on non-leap years when running with a Gregorian calendar. I'd suggest a solution for (1) of: After reading in the mmdd planting dates, add 10000 before converting them to a real-valued day of year, so that they are treated as being in year 1 (a non-leap year) instead of year 0. This will mean that, in leap years, planting happens one day earlier than the specified date, but that seems acceptable, and much better than possibly not planting at all.
samsrabin commentedon Feb 12, 2024
Confirming that (2) is still an issue after my crop calendar work:
CTSM/src/biogeochem/CNPhenologyMod.F90
Line 2749 in c030c23
Another, possibly simpler workaround for (1) might be to set a maximum
m[nx][NS]Hplantdateof 365 after conversion to day of year.DaysPastPlanting() now uses # days in LAST year, not THIS year.
DaysPastPlanting() now uses # days in LAST year, not THIS year.
wwieder commentedon Oct 1, 2026
@samsrabin it looks like you have #2461 drafted. Will this make a CLM6 deadline or is 6.1 more realistic?
My reading is this won't change answers with no-leap calendars, but that could influence the timing?
samsrabin commentedon Oct 1, 2026
The real question is what the latest acceptable milestone is, right? So that depends on how important it is. @billsacks what do you think?
billsacks commentedon Oct 1, 2026
Reading back through this, it seems like issue (1) may be important in cases where a crop configuration is used with a Gregorian calendar. My impression is that a Gregorian calendar is most commonly used when someone is running with close comparisons with data, such as for data assimilation or maybe running at a particular site. It's hard for me to say how common this is. Personally I'm fine with this being deferred, but I don't know that I'm the best person to be able to make the call as to its importance... but happy to be part of a discussion if that would help.