|
| 1 | +from argparse import ArgumentParser |
| 2 | +from pathlib import Path |
| 3 | + |
| 4 | +from cmip7_ancil_argparse import ( |
| 5 | + grid_parser, |
| 6 | + path_parser, |
| 7 | +) |
| 8 | +from cmip7_ancil_common import save_ancil |
| 9 | +from cmip7_ancil_constants import ANCIL_TODAY |
| 10 | +from cmip7_ancil_ukesm import ( |
| 11 | + fix_cmip7_ukesm, |
| 12 | + load_cmip7_ukesm, |
| 13 | + ukesm_parser, |
| 14 | +) |
| 15 | + |
| 16 | + |
| 17 | +def parse_args(): |
| 18 | + parser = ArgumentParser( |
| 19 | + parents=[path_parser(), grid_parser(), ukesm_parser()], |
| 20 | + prog="cmip7_AM_amip_generate", |
| 21 | + description=( |
| 22 | + "Generate input files from UK CMIP7 AMIP forcings" |
| 23 | + ), |
| 24 | + ) |
| 25 | + return parser.parse_args() |
| 26 | + |
| 27 | + |
| 28 | +def esm_am_amip_save_dirpath(args): |
| 29 | + return ( |
| 30 | + Path(args.ancil_target_dirname) |
| 31 | + / "modern" |
| 32 | + / "amip" |
| 33 | + / "atmosphere" |
| 34 | + / "boundary_conditions" |
| 35 | + / args.esm_grid_rel_dirname |
| 36 | + / ANCIL_TODAY |
| 37 | + ) |
| 38 | + |
| 39 | + |
| 40 | +def save_cmip7_am_amip(args, cube): |
| 41 | + # Save as an ancillary file |
| 42 | + save_dirpath = esm_am_amip_save_dirpath(args) |
| 43 | + save_ancil(cube, save_dirpath, args.save_filename, replace_bounds=True) |
| 44 | + |
| 45 | + |
| 46 | +if __name__ == "__main__": |
| 47 | + args = parse_args() |
| 48 | + |
| 49 | + # Load the CMIP7 datasets |
| 50 | + ukesm_cube = load_cmip7_ukesm(args) |
| 51 | + # Match the ESM1.5 mask |
| 52 | + esm_cube = fix_cmip7_ukesm(args, ukesm_cube) |
| 53 | + # Save the ancillary |
| 54 | + save_cmip7_am_amip(args, esm_cube) |
0 commit comments