Skip to content

Commit a25fb2c

Browse files
authored
Extend historical aerosol forcings to 1849-2023 (#117)
* Extend historical aerosol forcings to 1849-2023 * Extend the correct cube * Read datasets from 1850 onwards
1 parent 4e7e824 commit a25fb2c

10 files changed

+74
-66
lines changed

CMIP7/esm1p6/atmosphere/aerosol/cmip7_HI_Bio_interpolate.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,13 @@
88
load_cmip7_aerosol_biomass_list,
99
save_cmip7_aerosol_biomass,
1010
)
11-
from aerosol.cmip7_HI_aerosol import (
12-
CMIP7_HI_AEROSOL_BEG_YEAR,
13-
CMIP7_HI_AEROSOL_END_YEAR,
14-
esm_hi_aerosol_save_dirpath,
15-
)
11+
from aerosol.cmip7_HI_aerosol import esm_hi_aerosol_save_dirpath
1612
from cmip7_ancil_argparse import (
1713
common_parser,
1814
percent_parser,
1915
)
2016
from cmip7_ancil_common import cmip7_date_constraint_from_years
17+
from cmip7_HI import CMIP7_HI_BEG_YEAR, CMIP7_HI_END_YEAR
2118

2219

2320
def parse_args():
@@ -42,8 +39,8 @@ def load_cmip7_hi_aerosol_biomass(args, species):
4239
species,
4340
args.dataset_date_range_list,
4441
cmip7_date_constraint_from_years(
45-
CMIP7_HI_AEROSOL_BEG_YEAR,
46-
CMIP7_HI_AEROSOL_END_YEAR,
42+
CMIP7_HI_BEG_YEAR,
43+
CMIP7_HI_END_YEAR,
4744
),
4845
)
4946

@@ -54,8 +51,8 @@ def load_cmip7_hi_aerosol_biomass_percentage(args, species):
5451
species,
5552
args.percent_date_range,
5653
cmip7_date_constraint_from_years(
57-
CMIP7_HI_AEROSOL_BEG_YEAR,
58-
CMIP7_HI_AEROSOL_END_YEAR,
54+
CMIP7_HI_BEG_YEAR,
55+
CMIP7_HI_END_YEAR,
5956
),
6057
)
6158

CMIP7/esm1p6/atmosphere/aerosol/cmip7_HI_SO2_interpolate.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
from ast import literal_eval
55

66
from aerosol.cmip7_HI_aerosol import (
7-
CMIP7_HI_AEROSOL_BEG_YEAR,
8-
CMIP7_HI_AEROSOL_END_YEAR,
97
esm_hi_aerosol_ancil_dirpath,
108
esm_hi_aerosol_save_dirpath,
119
)
@@ -18,7 +16,11 @@
1816
common_parser,
1917
dms_filename_parser,
2018
)
21-
from cmip7_HI import fix_esm15_hi_ancil_date
19+
from cmip7_HI import (
20+
CMIP7_HI_BEG_YEAR,
21+
CMIP7_HI_END_YEAR,
22+
fix_esm15_hi_ancil_date,
23+
)
2224

2325

2426
def parse_args():
@@ -41,8 +43,8 @@ def load_cmip7_hi_so2_aerosol_anthro(args, species):
4143
return load_cmip7_hi_aerosol_anthro(
4244
args,
4345
species,
44-
beg_year=CMIP7_HI_AEROSOL_BEG_YEAR,
45-
end_year=CMIP7_HI_AEROSOL_END_YEAR,
46+
beg_year=CMIP7_HI_BEG_YEAR,
47+
end_year=CMIP7_HI_END_YEAR,
4648
)
4749

4850

CMIP7/esm1p6/atmosphere/aerosol/cmip7_HI_aerosol.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
from pathlib import Path
22

33
from cmip7_ancil_constants import ANCIL_TODAY
4-
from cmip7_HI import CMIP7_HI_BEG_YEAR, CMIP7_HI_END_YEAR
5-
6-
CMIP7_HI_AEROSOL_BEG_YEAR = CMIP7_HI_BEG_YEAR - 1
7-
CMIP7_HI_AEROSOL_END_YEAR = CMIP7_HI_END_YEAR
84

95

106
def esm_hi_aerosol_ancil_dirpath(ancil_root_dirname):

CMIP7/esm1p6/atmosphere/aerosol/cmip7_HI_aerosol_anthro.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,10 @@
55
cmip7_aerosol_anthro_interpolate,
66
load_cmip7_aerosol_anthro_list,
77
)
8-
from aerosol.cmip7_HI_aerosol import (
9-
CMIP7_HI_AEROSOL_BEG_YEAR,
10-
CMIP7_HI_AEROSOL_END_YEAR,
11-
esm_hi_aerosol_save_dirpath,
12-
)
8+
from aerosol.cmip7_HI_aerosol import esm_hi_aerosol_save_dirpath
139
from cmip7_ancil_argparse import common_parser
1410
from cmip7_ancil_common import cmip7_date_constraint_from_years
11+
from cmip7_HI import CMIP7_HI_BEG_YEAR, CMIP7_HI_END_YEAR
1512

1613

1714
def parse_args(species):
@@ -30,8 +27,8 @@ def parse_args(species):
3027
def load_cmip7_hi_aerosol_anthro(
3128
args,
3229
species,
33-
beg_year=CMIP7_HI_AEROSOL_BEG_YEAR,
34-
end_year=CMIP7_HI_AEROSOL_END_YEAR,
30+
beg_year=CMIP7_HI_BEG_YEAR,
31+
end_year=CMIP7_HI_END_YEAR,
3532
):
3633
return load_cmip7_aerosol_anthro_list(
3734
args,

CMIP7/esm1p6/atmosphere/aerosol/cmip7_SO2_interpolate.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from cmip7_ancil_common import (
1313
INTERPOLATION_SCHEME,
1414
esm_grid_mask_cube,
15+
extend_years,
1516
save_ancil,
1617
)
1718

@@ -97,6 +98,12 @@ def save_cmip7_so2_aerosol_anthro(
9798
# Need to remove the sector coordinate before saving
9899
# because high doesn't have it
99100
so2_low.remove_coord("sector")
101+
102+
# Extend the historical time series, if any,
103+
# by duplicating the first and last years
104+
so2_low = extend_years(so2_low)
105+
so2_high = extend_years(so2_high)
106+
100107
# Use the CMIP6 DMS
101108
cmip6_dms = dms_load_fn(args)
102109

CMIP7/esm1p6/atmosphere/aerosol/cmip7_aerosol_anthro.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from cmip7_ancil_common import (
1010
INTERPOLATION_SCHEME,
1111
esm_grid_mask_cube,
12+
extend_years,
1213
fix_coords,
1314
save_ancil,
1415
)
@@ -74,4 +75,7 @@ def cmip7_aerosol_anthro_interpolate(
7475
esm_cube.attributes["STASH"] = iris.fileformats.pp.STASH(
7576
model=1, section=0, item=stash_item
7677
)
78+
# Extend the historical time series, if any,
79+
# by duplicating the first and last years
80+
esm_cube = extend_years(esm_cube)
7781
save_ancil(esm_cube, save_dirpath, args.save_filename)

CMIP7/esm1p6/atmosphere/aerosol/cmip7_aerosol_biomass.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from cmip7_ancil_common import (
1212
INTERPOLATION_SCHEME,
1313
esm_grid_mask_cube,
14+
extend_years,
1415
save_ancil,
1516
set_coord_system,
1617
)
@@ -140,6 +141,11 @@ def save_cmip7_aerosol_biomass(args, load_pc_fn, load_fn, save_dirpath):
140141
model=1, section=0, item=131
141142
)
142143

144+
# Extend the historical time series, if any,
145+
# by duplicating the first and last years
146+
low_esm = extend_years(low_esm)
147+
high_esm = extend_years(high_esm)
148+
143149
save_ancil([low_esm, high_esm], save_dirpath, args.save_filename)
144150

145151
now = datetime.now()
Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import calendar
22
from pathlib import Path
33

4-
import iris
54
import mule
65
from cmip7_ancil_constants import (
76
ANCIL_TODAY,
8-
MONTHS_IN_A_YEAR,
97
UM_VERSION,
108
)
119
from cmip7_PI import CMIP7_PI_YEAR
@@ -46,39 +44,3 @@ def fix_esm15_hi_ancil_date(ifile, ofile):
4644
field.lbdatd = calendar.monthrange(field.lbyr, field.lbmon)[1]
4745

4846
ff.to_file(ofile)
49-
50-
51-
def extend_hi_years(cube):
52-
"""
53-
Extend a cube representing a monthly time series by duplicating
54-
and adjusting the first and last years.
55-
Based on Crown copyright code from ozone_cmip6_ancillary_for_suite.py
56-
by Steven Hardiman of the UK Met Office.
57-
"""
58-
time_coord = cube.coord("time")
59-
time_points = time_coord.points
60-
if (months := len(time_points)) <= MONTHS_IN_A_YEAR:
61-
raise ValueError(
62-
f"Cannot extend a cube containing {months} months of data. "
63-
f"More than {MONTHS_IN_A_YEAR} months are required."
64-
)
65-
66-
# Duplicate the first year.
67-
length_one_year = time_points[MONTHS_IN_A_YEAR] - time_points[0]
68-
beg_year = cube[:MONTHS_IN_A_YEAR].copy()
69-
beg_year_tc = beg_year.coord("time")
70-
beg_year_tc.points = beg_year_tc.points - length_one_year
71-
if time_coord.has_bounds():
72-
beg_year_tc.bounds = beg_year_tc.bounds - length_one_year
73-
74-
# Duplicate the last year.
75-
length_one_year = time_points[-1] - time_points[-1 - MONTHS_IN_A_YEAR]
76-
end_year = cube[-MONTHS_IN_A_YEAR:].copy()
77-
end_year_tc = end_year.coord("time")
78-
end_year_tc.points = end_year_tc.points + length_one_year
79-
if time_coord.has_bounds():
80-
end_year_tc.bounds = end_year_tc.bounds + length_one_year
81-
82-
# Return a cube with extended years.
83-
cubelist = iris.cube.CubeList((beg_year, cube, end_year))
84-
return cubelist.concatenate_cube()

CMIP7/esm1p6/atmosphere/cmip7_ancil_common.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
import iris
1111
import mule
1212
import numpy as np
13-
from cmip7_ancil_constants import UM_VERSION
13+
from cmip7_ancil_constants import (
14+
MONTHS_IN_A_YEAR,
15+
UM_VERSION,
16+
)
1417

1518
INTERPOLATION_SCHEME = iris.analysis.AreaWeighted(mdtol=0.5)
1619

@@ -72,6 +75,40 @@ def set_gregorian(var):
7275
time.units = newunits
7376

7477

78+
def extend_years(cube):
79+
"""
80+
Extend a cube representing a monthly time series by duplicating
81+
and adjusting the first and last years.
82+
Based on Crown copyright code from ozone_cmip6_ancillary_for_suite.py
83+
by Steven Hardiman of the UK Met Office.
84+
"""
85+
time_coord = cube.coord("time")
86+
time_points = time_coord.points
87+
# Do not extend a cube containing less than two years of data.
88+
if len(time_points) < MONTHS_IN_A_YEAR * 2:
89+
return cube
90+
91+
# Duplicate the first year.
92+
length_one_year = time_points[MONTHS_IN_A_YEAR] - time_points[0]
93+
beg_year = cube[:MONTHS_IN_A_YEAR].copy()
94+
beg_year_tc = beg_year.coord("time")
95+
beg_year_tc.points = beg_year_tc.points - length_one_year
96+
if time_coord.has_bounds():
97+
beg_year_tc.bounds = beg_year_tc.bounds - length_one_year
98+
99+
# Duplicate the last year.
100+
length_one_year = time_points[-1] - time_points[-1 - MONTHS_IN_A_YEAR]
101+
end_year = cube[-MONTHS_IN_A_YEAR:].copy()
102+
end_year_tc = end_year.coord("time")
103+
end_year_tc.points = end_year_tc.points + length_one_year
104+
if time_coord.has_bounds():
105+
end_year_tc.bounds = end_year_tc.bounds + length_one_year
106+
107+
# Return a cube with extended years.
108+
cubelist = iris.cube.CubeList((beg_year, cube, end_year))
109+
return cubelist.concatenate_cube()
110+
111+
75112
def set_coord_system(cube):
76113
coord_system = iris.coord_systems.GeogCS(6371229.0)
77114
cube.coord("latitude").coord_system = coord_system

CMIP7/esm1p6/atmosphere/nitrogen/cmip7_HI_nitrogen_generate.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
from pathlib import Path
33

44
from cmip7_ancil_argparse import common_parser
5+
from cmip7_ancil_common import extend_years
56
from cmip7_ancil_constants import ANCIL_TODAY
6-
from cmip7_HI import extend_hi_years
77
from nitrogen.cmip7_nitrogen import (
88
cmip7_nitrogen_dirpath,
99
load_cmip7_nitrogen,
@@ -54,6 +54,6 @@ def esm_hi_nitrogen_save_dirpath(args):
5454
# Load the CMIP7 datasets
5555
nitrogen_cube = load_cmip7_nitrogen(args, cmip7_hi_nitrogen_filepath)
5656
# Regrid to match the ESM1.5 mask and extend the time series
57-
esm_cube = extend_hi_years(regrid_cmip7_nitrogen(args, nitrogen_cube))
57+
esm_cube = extend_years(regrid_cmip7_nitrogen(args, nitrogen_cube))
5858
# Save the ancillary
5959
save_cmip7_nitrogen(args, esm_cube, esm_hi_nitrogen_save_dirpath)

0 commit comments

Comments
 (0)