19
19
from esmgrids .mom_grid import MomGrid # noqa
20
20
from esmgrids .core2_grid import Core2Grid # noqa
21
21
from esmgrids .jra55_grid import Jra55Grid # noqa
22
+ from esmgrids .era5_grid import Era5Grid # noqa
22
23
from esmgrids .jra55_river_grid import Jra55RiverGrid # noqa
23
24
from esmgrids .daitren_runoff_grid import DaitrenRunoffGrid # noqa
24
25
@@ -121,9 +122,9 @@ def create_weights(src_grid, dest_grid, npes, method,
121
122
return regrid_weights
122
123
123
124
124
- def find_grid_defs (input_dir , jra55_input , core_input ):
125
+ def find_ocean_grid_defs (input_dir ):
125
126
"""
126
- Return a dictionary containing the grid definition files.
127
+ Return a dictionary containing ocean grid definition files.
127
128
"""
128
129
129
130
d = {}
@@ -133,51 +134,39 @@ def find_grid_defs(input_dir, jra55_input, core_input):
133
134
os .path .join (input_dir , 'mom_025deg' , 'ocean_mask.nc' ))
134
135
d ['MOM01' ] = (os .path .join (input_dir , 'mom_01deg' , 'ocean_hgrid.nc' ),
135
136
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
-
142
137
return d
143
138
144
139
145
140
def main ():
146
141
147
142
parser = argparse .ArgumentParser ()
148
- parser .add_argument ('input_dir' , help = """
143
+ parser .add_argument ('--accessom2_input_dir' , required = True , help = """
149
144
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 = """
155
148
Atmosphere grid to regrid from, can be one of:
156
- CORE2, JRA55, JRA55_runoff, Daitren_runoff""" )
149
+ CORE2, JRA55, JRA55_runoff, Daitren_runoff, ERA5 """ )
157
150
parser .add_argument ('--ocean' , default = None , help = """
158
151
Ocean grid to regrid to, can be one of:
159
152
MOM1, MOM01, MOM025""" )
160
153
parser .add_argument ('--method' , default = None , help = """
161
154
The interpolation method to use, can be patch, conserve or conserve2nd""" )
162
155
parser .add_argument ('--npes' , default = None , help = """
163
156
The number of PEs to use.""" )
164
- parser .add_argument ('--unmask_dest' ,
157
+ parser .add_argument ('--unmask_dest' ,
165
158
action = 'store_true' ,
166
159
help = 'Ignore destination grid mask' )
167
160
168
161
args = parser .parse_args ()
169
- atm_options = ['JRA55' , 'JRA55_runoff' , 'CORE2' , 'Daitren_runoff' ]
162
+ atm_options = ['JRA55' , 'JRA55_runoff' , 'CORE2' , 'Daitren_runoff' , 'ERA5' ]
170
163
ocean_options = ['MOM1' , 'MOM025' , 'MOM01' ]
171
164
method_options = ['patch' , 'conserve' , 'conserve2nd' ]
172
165
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
181
170
182
171
if args .ocean is None :
183
172
args .ocean = ocean_options
@@ -197,37 +186,38 @@ def main():
197
186
import multiprocessing as mp
198
187
args .npes = mp .cpu_count () // 2
199
188
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 )
201
190
202
191
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 ],
205
194
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
219
195
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 :
221
211
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
229
219
230
- shutil .move (weights , '{}_{}_{}.nc' .format (atm , ocean , method ))
220
+ shutil .move (weights , '{}_{}_{}.nc' .format (args . atm , ocean , method ))
231
221
232
222
return 0
233
223
0 commit comments