Skip to content

Commit 180b77d

Browse files
committed
update to Nic's /g/data/v45/nah599/access-om2/tools/make_remap_weights.* to support ERA5; COSIMA/esmgrids#4 ; #242
1 parent 49b8fb2 commit 180b77d

File tree

2 files changed

+43
-51
lines changed

2 files changed

+43
-51
lines changed

tools/make_remap_weights.py

+40-50
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from esmgrids.mom_grid import MomGrid # noqa
2020
from esmgrids.core2_grid import Core2Grid # noqa
2121
from esmgrids.jra55_grid import Jra55Grid # noqa
22+
from esmgrids.era5_grid import Era5Grid # noqa
2223
from esmgrids.jra55_river_grid import Jra55RiverGrid # noqa
2324
from esmgrids.daitren_runoff_grid import DaitrenRunoffGrid # noqa
2425

@@ -121,9 +122,9 @@ def create_weights(src_grid, dest_grid, npes, method,
121122
return regrid_weights
122123

123124

124-
def find_grid_defs(input_dir, jra55_input, core_input):
125+
def find_ocean_grid_defs(input_dir):
125126
"""
126-
Return a dictionary containing the grid definition files.
127+
Return a dictionary containing ocean grid definition files.
127128
"""
128129

129130
d = {}
@@ -133,51 +134,39 @@ def find_grid_defs(input_dir, jra55_input, core_input):
133134
os.path.join(input_dir, 'mom_025deg', 'ocean_mask.nc'))
134135
d['MOM01'] = (os.path.join(input_dir, 'mom_01deg', 'ocean_hgrid.nc'),
135136
os.path.join(input_dir, 'mom_01deg', 'ocean_mask.nc'))
136-
d['CORE2'] = os.path.join(core_input, 't_10.0001.nc')
137-
d['JRA55'] = os.path.join(jra55_input, 'RYF.t_10.1990_1991.nc')
138-
d['JRA55_runoff'] = os.path.join(jra55_input,
139-
'RYF.runoff_all.1990_1991.nc')
140-
d['Daitren_runoff'] = os.path.join(core_input, 'runoff.daitren.clim.10FEB2011.nc')
141-
142137
return d
143138

144139

145140
def main():
146141

147142
parser = argparse.ArgumentParser()
148-
parser.add_argument('input_dir', help="""
143+
parser.add_argument('--accessom2_input_dir', required=True, help="""
149144
The ACCESS-OM2 input directory.""")
150-
parser.add_argument('jra55_input', help="""
151-
The JRA55 input directory.""")
152-
parser.add_argument('core_input', help="""
153-
The CORE input directory.""")
154-
parser.add_argument('--atm', default=None, help="""
145+
parser.add_argument('--atm_forcing_file', required=True, help="""
146+
An atmospheric or runoff forcing field.""")
147+
parser.add_argument('--atm', required=True, default=None, help="""
155148
Atmosphere grid to regrid from, can be one of:
156-
CORE2, JRA55, JRA55_runoff, Daitren_runoff""")
149+
CORE2, JRA55, JRA55_runoff, Daitren_runoff, ERA5""")
157150
parser.add_argument('--ocean', default=None, help="""
158151
Ocean grid to regrid to, can be one of:
159152
MOM1, MOM01, MOM025""")
160153
parser.add_argument('--method', default=None, help="""
161154
The interpolation method to use, can be patch, conserve or conserve2nd""")
162155
parser.add_argument('--npes', default=None, help="""
163156
The number of PEs to use.""")
164-
parser.add_argument('--unmask_dest',
157+
parser.add_argument('--unmask_dest',
165158
action='store_true',
166159
help='Ignore destination grid mask')
167160

168161
args = parser.parse_args()
169-
atm_options = ['JRA55', 'JRA55_runoff', 'CORE2', 'Daitren_runoff']
162+
atm_options = ['JRA55', 'JRA55_runoff', 'CORE2', 'Daitren_runoff', 'ERA5']
170163
ocean_options = ['MOM1', 'MOM025', 'MOM01']
171164
method_options = ['patch', 'conserve', 'conserve2nd']
172165

173-
if args.atm is None:
174-
args.atm = atm_options
175-
else:
176-
if args.atm not in atm_options:
177-
print("Error: bad atm grid.", file=sys.stderr)
178-
parser.print_help()
179-
return 1
180-
args.atm = [args.atm]
166+
if args.atm not in atm_options:
167+
print("Error: bad atm grid.", file=sys.stderr)
168+
parser.print_help()
169+
return 1
181170

182171
if args.ocean is None:
183172
args.ocean = ocean_options
@@ -197,37 +186,38 @@ def main():
197186
import multiprocessing as mp
198187
args.npes = mp.cpu_count() // 2
199188

200-
grid_file_dict = find_grid_defs(args.input_dir, args.jra55_input, args.core_input)
189+
ocean_grid_file_dict = find_ocean_grid_defs(args.accessom2_input_dir)
201190

202191
for ocean in args.ocean:
203-
umask_file = grid_file_dict[ocean][1]
204-
dest_grid = MomGrid.fromfile(grid_file_dict[ocean][0],
192+
umask_file = ocean_grid_file_dict[ocean][1]
193+
dest_grid = MomGrid.fromfile(ocean_grid_file_dict[ocean][0],
205194
mask_file=umask_file)
206-
for atm in args.atm:
207-
208-
if atm == 'CORE2':
209-
src_grid = Core2Grid(grid_file_dict[atm])
210-
elif atm == 'Daitren_runoff':
211-
src_grid = DaitrenRunoffGrid(grid_file_dict[atm])
212-
elif atm == 'JRA55':
213-
src_grid = Jra55Grid(grid_file_dict[atm])
214-
elif atm == 'JRA55_runoff':
215-
src_grid = Jra55RiverGrid(grid_file_dict[atm], calc_areas=False)
216-
else:
217-
print('Unrecognised atmosphere grid: {}'.format(atm))
218-
return 1
219195

220-
for method in args.method:
196+
if args.atm == 'CORE2':
197+
src_grid = Core2Grid(args.atm_forcing_file)
198+
elif args.atm == 'Daitren_runoff':
199+
src_grid = DaitrenRunoffGrid(args.atm_forcing_file)
200+
elif args.atm == 'JRA55':
201+
src_grid = Jra55Grid(args.atm_forcing_file)
202+
elif args.atm == 'JRA55_runoff':
203+
src_grid = Jra55RiverGrid(args.atm_forcing_file, calc_areas=False)
204+
elif args.atm == 'ERA5':
205+
src_grid = Era5Grid(args.atm_forcing_file)
206+
else:
207+
print('Unrecognised atmosphere grid: {}'.format(atm))
208+
return 1
209+
210+
for method in args.method:
221211

222-
weights = create_weights(src_grid, dest_grid, args.npes,
223-
method, unmasked_dest=args.unmask_dest)
224-
if not weights:
225-
return 1
226-
weights = convert_to_scrip_output(weights)
227-
if not weights:
228-
return 1
212+
weights = create_weights(src_grid, dest_grid, args.npes,
213+
method, unmasked_dest=args.unmask_dest)
214+
if not weights:
215+
return 1
216+
weights = convert_to_scrip_output(weights)
217+
if not weights:
218+
return 1
229219

230-
shutil.move(weights, '{}_{}_{}.nc'.format(atm, ocean, method))
220+
shutil.move(weights, '{}_{}_{}.nc'.format(args.atm, ocean, method))
231221

232222
return 0
233223

tools/make_remap_weights.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
module purge
88
module load openmpi
99
module load nco
10-
module load esmf/7.1.0r-intel
10+
module load esmf
1111
module use /g/data/hh5/public/modules
1212
module load conda/analysis3
1313

14+
ulimit -s unlimited
15+
1416
# Make all 1 deg weights.
1517
time ./make_remap_weights.py /short/x77/nah599/access-om2/input/ /g/data/ua8/JRA55-do/RYF/v1-3/ /short/x77/nah599/access-om2/input/yatm_1deg/ --ocean MOM1 --npes 256
1618

0 commit comments

Comments
 (0)