Skip to content

Commit

Permalink
Satisfy pylint.
Browse files Browse the repository at this point in the history
  • Loading branch information
samsrabin committed Nov 14, 2024
1 parent c95ddc2 commit 15cd326
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions python/ctsm/crop_calendars/cropcal_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,21 @@ def import_output(
)

# Convert time axis to integer year, saving original as 'cftime'
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")
# Get number of harvests that would be missed if only seeing max 1 per calendar year
if np.any(this_ds_gs["NHARVESTS"] > 2):
raise RuntimeError("How to get NHARVEST_DISCREP for NHARVESTS > 2?")
this_ds_gs["NHARVEST_DISCREP"] = (this_ds_gs["NHARVESTS"] == 2).astype(int)

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
Expand All @@ -462,17 +477,10 @@ def import_output(
)
else:
raise RuntimeError(
f"{filename} seems to be neither an instantaneous file nor a combined/non-instantaneous file."
f"{filename} is neither an instantaneous nor a combined/non-instantaneous file."
)

# Get number of harvests
this_ds_gs["NHARVESTS"] = (this_ds_gs["GDDHARV_PERHARV"] > 0).sum(dim="mxharvests")
# Get number of harvests that would be missed if only seeing max 1 per calendar year
if np.any(this_ds_gs["NHARVESTS"] > 2):
raise RuntimeError("How to get NHARVEST_DISCREP for NHARVESTS > 2?")
this_ds_gs["NHARVEST_DISCREP"] = (this_ds_gs["NHARVESTS"] == 2).astype(int)

return this_ds_gs, any_bad
return this_ds_gs


def handle_zombie_crops(this_ds):
Expand Down

0 comments on commit 15cd326

Please sign in to comment.