Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 36 additions & 8 deletions CMIP7/esm1p6/atmosphere/cmip7_ancil_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def esm_grid_mask_cube(args):
return cube


def set_gregorian(var):
def set_gregorian(var, replace_bounds=False):
# Change the calendar to Gregorian for the model
time = var.coord("time")
origin = time.units.origin
Expand All @@ -59,17 +59,43 @@ def set_gregorian(var):
date.year, date.month, date.day, date.hour, date.minute, date.second
)
tvals[i] = newunits.date2num(newdate)
for j in range(2):
date = time.units.num2date(tbnds[i][j])
newdate = cftime.DatetimeProlepticGregorian(
if replace_bounds:
beg_date = cftime.DatetimeProlepticGregorian(
date.year,
date.month,
date.day,
1,
date.hour,
date.minute,
date.second,
)
tbnds[i][j] = newunits.date2num(newdate)
tbnds[i][0] = newunits.date2num(beg_date)
if date.month == 12:
end_year = date.year + 1
end_month = 1
else:
end_year = date.year
end_month = date.month + 1
end_date = cftime.DatetimeProlepticGregorian(
end_year,
end_month,
1,
date.hour,
date.minute,
date.second,
)
tbnds[i][1] = newunits.date2num(end_date)
else:
for j in range(2):
date = time.units.num2date(tbnds[i][j])
newdate = cftime.DatetimeProlepticGregorian(
date.year,
date.month,
date.day,
date.hour,
date.minute,
date.second,
)
tbnds[i][j] = newunits.date2num(newdate)
time.points = tvals
time.bounds = tbnds
time.units = newunits
Expand Down Expand Up @@ -134,7 +160,9 @@ def zero_poles(cube):
cube.data[:, -1] = 0.0


def save_ancil(cubes, save_dirpath, save_filename, gregorian=True):
def save_ancil(
cubes, save_dirpath, save_filename, gregorian=True, replace_bounds=False
):
"""
Handle both a list and a single cube
"""
Expand All @@ -148,7 +176,7 @@ def save_ancil(cubes, save_dirpath, save_filename, gregorian=True):
cube.attributes["grid_staggering"] = 3 # New dynamics
if gregorian:
cube.attributes["time_type"] = 1 # Gregorian
set_gregorian(cube)
set_gregorian(cube, replace_bounds=replace_bounds)
"""
ANTS doesn't set the calendar header for monthly fields
See fileformats/ancil/time_headers.py
Expand Down
2 changes: 1 addition & 1 deletion CMIP7/esm1p6/atmosphere/ozone/cmip7_HI_ozone_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def esm_hi_ozone_save_dirpath(args):
def save_cmip7_hi_ozone(args, cube):
# Save as an ancillary file
save_dirpath = esm_hi_ozone_save_dirpath(args)
save_ancil(cube, save_dirpath, args.save_filename, gregorian=False)
save_ancil(cube, save_dirpath, args.save_filename, replace_bounds=True)


if __name__ == "__main__":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def save_cmip7_pi_mean_ozone(args, cube):
cube.remove_coord("month_number")
# Save as an ancillary file
save_dirpath = esm_pi_ozone_save_dirpath(args)
save_ancil(cube, save_dirpath, args.save_filename, gregorian=False)
save_ancil(cube, save_dirpath, args.save_filename, replace_bounds=True)


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion CMIP7/esm1p6/atmosphere/ozone/cmip7_PI_ozone_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def esm_pi_ozone_save_dirpath(args):
def save_cmip7_pi_ozone(args, cube):
# Save as an ancillary file
save_dirpath = esm_pi_ozone_save_dirpath(args)
save_ancil(cube, save_dirpath, args.save_filename, gregorian=False)
save_ancil(cube, save_dirpath, args.save_filename, replace_bounds=True)


if __name__ == "__main__":
Expand Down
Loading