diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index fca4a8315b..32e53646d7 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -27,6 +27,7 @@ d866510188d26d51bcd6d37239283db690af7e82 e096358c832ab292ddfd22dd5878826c7c788968 475831f0fb0e31e97f630eac4e078c886558b61c fd5f177131d63d39e79a13918390bdfb642d781e +a51816e0de380300b69db9fc3e2c7fa83b267b64 # Ran SystemTests and python/ctsm through black python formatter 5364ad66eaceb55dde2d3d598fe4ce37ac83a93c 8056ae649c1b37f5e10aaaac79005d6e3a8b2380 diff --git a/python/ctsm/crop_calendars/cropcal_module.py b/python/ctsm/crop_calendars/cropcal_module.py index 719d352665..3ea084e1d2 100644 --- a/python/ctsm/crop_calendars/cropcal_module.py +++ b/python/ctsm/crop_calendars/cropcal_module.py @@ -443,10 +443,7 @@ def import_output( ) # Convert time axis to integer year, saving original as 'cftime' - this_ds_gs = this_ds_gs.assign_coords( - {"cftime": this_ds["time_bounds"].isel({"hist_interval": 0})} - ) - this_ds_gs = this_ds_gs.assign_coords({"time": [t.year for t in this_ds_gs["cftime"].values]}) + this_ds_gs = convert_time_to_int_year(filename, this_ds, this_ds_gs) # Get number of harvests this_ds_gs["NHARVESTS"] = (this_ds_gs["GDDHARV_PERHARV"] > 0).sum(dim="mxharvests") @@ -458,6 +455,35 @@ def import_output( return this_ds_gs, any_bad +def convert_time_to_int_year(filename, this_ds, this_ds_gs): + """ + Convert time axis to integer year, saving original as 'cftime' + """ + if "time_bounds" in this_ds: + # Always true before PR #2838, when even files with all instantaneous variables got + # time_bounds saved. After that PR (and before the segregation of instantaneous and other + # variables onto separate files), files with an instantaneous variable first in their list + # do not get time_bounds saved. + this_ds_gs = this_ds_gs.assign_coords( + {"cftime": this_ds["time_bounds"].isel({"hist_interval": 0})} + ) + this_ds_gs = this_ds_gs.assign_coords( + {"time": [t.year for t in this_ds_gs["cftime"].values]} + ) + elif this_ds["time"].attrs["long_name"] == "time at end of time step": + # This is an "instantaneous file." + this_ds_gs = this_ds_gs.assign_coords({"cftime": this_ds["time"]}) + this_ds_gs = this_ds_gs.assign_coords( + {"time": [t.year - 1 for t in this_ds_gs["cftime"].values]} + ) + else: + raise RuntimeError( + f"{filename} is neither an instantaneous nor a combined/non-instantaneous file." + ) + + return this_ds_gs + + def handle_zombie_crops(this_ds): """ When doing transient runs, it's somehow possible for crops in newly-active patches to be