Skip to content
Open
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
58 changes: 58 additions & 0 deletions CMIP7/esm1p6/atmosphere/amip/cmip7_AM_amip_generate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from argparse import ArgumentParser
from pathlib import Path

from cmip7_ancil_argparse import (
grid_parser,
path_parser,
)
from cmip7_ancil_common import save_ancil
from cmip7_ancil_constants import ANCIL_TODAY
from cmip7_ancil_ukesm import (
fix_cmip7_ukesm,
load_cmip7_ukesm,
ukesm_parser,
)


def parse_args():
parser = ArgumentParser(
parents=[path_parser(), grid_parser(), ukesm_parser()],
prog="cmip7_AM_amip_generate",
description="Generate input files from UK CMIP7 AMIP forcings",
)
return parser.parse_args()


def esm_am_amip_save_dirpath(args):
return (
Path(args.ancil_target_dirname)
/ "modern"
/ "amip"
/ "atmosphere"
/ "boundary_conditions"
/ args.esm_grid_rel_dirname
/ ANCIL_TODAY
)


def save_cmip7_am_amip(args, cube):
# Save as an ancillary file
save_dirpath = esm_am_amip_save_dirpath(args)
save_ancil(
cube,
save_dirpath,
args.save_filename,
gregorian=False,
replace_bounds=True,
Comment on lines +45 to +46
)


if __name__ == "__main__":
args = parse_args()

# Load the CMIP7 datasets
ukesm_cube = load_cmip7_ukesm(args)
# Match the ESM1.5 mask
esm_cube = fix_cmip7_ukesm(args, ukesm_cube)
# Save the ancillary
save_cmip7_am_amip(args, esm_cube)
31 changes: 31 additions & 0 deletions CMIP7/esm1p6/atmosphere/cmip7_ancil_ukesm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from argparse import ArgumentParser
from pathlib import Path

import iris
from cmip7_ancil_common import fix_coords


def ukesm_parser():
parser = ArgumentParser(add_help=False)
parser.add_argument("--ukesm-ancil-dirpath")
parser.add_argument("--ukesm-netcdf-filename")
parser.add_argument("--save-filename")
return parser
Comment on lines +8 to +13

@penguian penguian Jul 3, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. I left the ozone/cmip7_ozone.py code in deliberately, partly because it does not affect AMIP generation, and partly because it might make for a good first refactoring task for Valentina.



def cmip7_ukesm_filepath(args):
dirpath = Path(args.ukesm_ancil_dirpath)
filename = args.ukesm_netcdf_filename
return dirpath / filename


def load_cmip7_ukesm(args):
filepath = cmip7_ukesm_filepath(args)
return iris.load_cube(filepath)


def fix_cmip7_ukesm(args, cube):
# Make the coordinates compatible with the ESM1.5 grid mask
fix_coords(args, cube)
cube.data = cube.data.filled(0.0)
return cube
Loading