Skip to content

Commit 9278c5c

Browse files
authored
Merge pull request #149 from GEOS-ESM/feature/wjiang/cnclm51
add cnclm51 remapping; provide default "zoom" value for remap_restarts yaml file
2 parents 4f683e2 + b909338 commit 9278c5c

File tree

6 files changed

+48
-32
lines changed

6 files changed

+48
-32
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12+
- Added cnclm51 remapping
13+
1214
### Changed
1315

1416
- Expand user home path '~' in remap python scripts
1517
- Moved from `f2py2` to `f2py3` to enable removal of Python 2 support
1618

1719
### Fixed
1820

21+
- Provide default "zoom" value for remap_restarts yaml file
22+
1923
### Removed
2024

2125
### Deprecated

pre/remap_restart/remap_command_line.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def parse_args(program_description):
6565
p_command.add_argument('-in_stretch', default=False, help='Stretched CS params of input restarts', choices=choices_stretch)
6666
p_command.add_argument('-out_stretch', default=False, help='Stretched CS params for new restarts', choices=choices_stretch)
6767

68-
# Unlike remap_questions.py, command-line feature does not deduce Catch vs. CatchCN[40,45] for simplicity, thus requires input argument
68+
# Unlike remap_questions.py, command-line feature does not deduce Catch vs. CatchCN[40,51] for simplicity, thus requires input argument
6969
p_command.add_argument('-catch_model',default='catch', help='Catchment[CN] model', choices=choices_catchmodel)
7070

7171
p_command.add_argument('-nobkg', action='store_true', help="Do not remap bkg files")
@@ -146,8 +146,7 @@ def get_answers_from_command_line(cml):
146146
if cml.zoom:
147147
answers["input:surface:zoom"] = cml.zoom
148148
else:
149-
# zoom_default fills 'input:shared:agrid'
150-
answers["input:surface:zoom"] = zoom_default(answers)
149+
answers["input:surface:zoom"] = get_zoom(answers)
151150

152151
if cml.in_wemin :
153152
answers["input:surface:wemin"] = cml.in_wemin

pre/remap_restart/remap_lake_landice_saltwater.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@
1616
import glob
1717
import ruamel.yaml
1818
import shlex
19-
from remap_base import remap_base
20-
from remap_utils import get_label
21-
from remap_utils import get_geomdir
19+
from remap_base import remap_base
20+
from remap_utils import get_label, get_geomdir, get_zoom
2221
from remap_bin2nc import bin2nc
2322

2423
class lake_landice_saltwater(remap_base):
@@ -53,17 +52,19 @@ def remap(self):
5352
stretch = config['input']['shared']['stretch']
5453
in_tile_file = config['input']['surface']['catch_tilefile']
5554
if not in_tile_file :
56-
in_geomdir = get_geomdir(in_bc_base, in_bc_version, agrid=agrid, ogrid=ogrid, omodel=omodel, stretch=stretch)
57-
in_tile_file = glob.glob(in_geomdir+ '/*-Pfafstetter.til')[0]
55+
EASE_grid = config['input']['surface'].get('EASE_grid', None)
56+
in_geomdir = get_geomdir(in_bc_base, in_bc_version, agrid=agrid, ogrid=ogrid, omodel=omodel, stretch=stretch, grid=EASE_grid)
57+
in_tile_file = glob.glob(in_geomdir+ '/*.til')[0]
5858

5959
agrid = config['output']['shared']['agrid']
6060
ogrid = config['output']['shared']['ogrid']
6161
omodel = config['output']['shared']['omodel']
6262
stretch = config['output']['shared']['stretch']
6363
out_tile_file = config['output']['surface']['catch_tilefile']
6464
if not out_tile_file :
65-
out_geomdir = get_geomdir(out_bc_base, out_bc_version, agrid=agrid, ogrid=ogrid, omodel=omodel, stretch=stretch)
66-
out_tile_file = glob.glob(out_geomdir+ '/*-Pfafstetter.til')[0]
65+
EASE_grid = config['output']['surface'].get('EASE_grid', None)
66+
out_geomdir = get_geomdir(out_bc_base, out_bc_version, agrid=agrid, ogrid=ogrid, omodel=omodel, stretch=stretch, grid=EASE_grid)
67+
out_tile_file = glob.glob(out_geomdir+ '/*.til')[0]
6768

6869
types = '.bin'
6970
type_str = sp.check_output(['file','-b', os.path.realpath(restarts_in[0])])
@@ -118,23 +119,26 @@ def remap(self):
118119
if 'saltwater_import' in f : saltwater_import = f
119120
if 'seaicethermo_internal' in f : seaicethermo_internal = f
120121
if 'seaicethermo_import' in f : seaicethermo_import = f
121-
if 'landice' in f : landice = f
122-
if 'lake' in f : lake = f
123-
if 'roue' in f : route = f
124-
if 'openwater' in f : openwater = f
122+
if 'landice' in f : landice = f
123+
if 'lake' in f : lake = f
124+
if 'roue' in f : route = f
125+
if 'openwater' in f : openwater = f
125126

126127
in_til = InData_dir+'/' + os.path.basename(in_tile_file)
127128
out_til = OutData_dir+'/'+ os.path.basename(out_tile_file)
128129

129130
if os.path.exists(in_til) : shutil.remove(in_til)
130131
if os.path.exists(out_til) : shutil.remove(out_til)
131-
print('\n Copy ' + in_tile_file + ' to ' + in_til)
132+
print('\n Copy ' + in_tile_file + ' to ' + in_til)
132133
shutil.copy(in_tile_file, in_til)
133134
print('\n Copy ' + out_tile_file + ' to ' + out_til)
134135
shutil.copy(out_tile_file, out_til)
135136

136137
exe = bindir + '/mk_LakeLandiceSaltRestarts.x '
137138
zoom = config['input']['surface']['zoom']
139+
if zoom is None :
140+
zoom = get_zoom(config)
141+
138142
log_name = out_dir+'/remap_lake_landice_saltwater_log'
139143
if os.path.exists(log_name):
140144
os.remove(log_name)
@@ -227,7 +231,7 @@ def find_rst(self):
227231
"landice_internal_rst" ,
228232
"openwater_internal_rst" ,
229233
"saltwater_internal_rst" ,
230-
"saltwater_import_rst" ,
234+
"saltwater_import_rst" ,
231235
"seaicethermo_internal_rst",
232236
"seaicethermo_import_rst"]
233237

@@ -254,9 +258,9 @@ def copy_merra2(self):
254258

255259
expid = self.config['input']['shared']['expid']
256260
yyyymmddhh_ = str(self.config['input']['shared']['yyyymmddhh'])
257-
yyyy_ = yyyymmddhh_[0:4]
258-
mm_ = yyyymmddhh_[4:6]
259-
dd_ = yyyymmddhh_[6:8]
261+
yyyy_ = yyyymmddhh_[0: 4]
262+
mm_ = yyyymmddhh_[4: 6]
263+
dd_ = yyyymmddhh_[6: 8]
260264
hh_ = yyyymmddhh_[8:10]
261265

262266
suffix = yyyymmddhh_[0:8]+'_'+ hh_ + 'z.bin'

pre/remap_restart/remap_params.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ input:
2424
surface:
2525
zoom:
2626
wemin:
27-
# it supports three models: catch, catchcnclm40, catchcnclm45
27+
# it supports three models: catch, catchcnclm40, catchcnclm51
2828
catch_model: null
2929
# if catch_tilefile is null, it searches bc_dir
3030
catch_tilefile: null

pre/remap_restart/remap_questions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ def ask_questions():
420420
"type": "text",
421421
"name": "input:surface:zoom",
422422
"message": "Enter value of zoom parameter for surface restarts [1-8]? (Search radius, smaller value means larger radius.)\n",
423-
"default": lambda x: zoom_default(x)
423+
"default": lambda x: get_zoom(x)
424424
},
425425
{
426426
"type": "text",

pre/remap_restart/remap_utils.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import glob
1313
import shlex
1414
import netCDF4 as nc
15+
import linecache
1516

1617
# shared global variables
1718

@@ -36,7 +37,7 @@
3637

3738
choices_omodel = ['data', 'MOM5', 'MOM6']
3839

39-
choices_catchmodel = ['catch', 'catchcnclm40', 'catchcnclm45']
40+
choices_catchmodel = ['catch', 'catchcnclm40', 'catchcnclm51']
4041

4142
choices_ogrid_data = ['360x180 (Reynolds)','1440x720 (MERRA-2)','2880x1440 (OSTIA)','CS (same as atmosphere OSTIA cubed-sphere grid)']
4243

@@ -284,8 +285,8 @@ def catch_model(x):
284285
model = 'catch'
285286
if 'cnclm40' in fname.lower():
286287
model = 'catchcnclm40'
287-
if 'cnclm45' in fname.lower():
288-
model = 'catchcnclm45'
288+
if 'cnclm51' in fname.lower():
289+
model = 'catchcnclm51'
289290
return model
290291

291292
def data_ocean_default(resolution):
@@ -340,17 +341,25 @@ def show_wemin_default(x):
340341
# If neither MERRA2 or GEOS-IT is selected option will be shown on screen
341342
return True
342343

343-
def zoom_default(x):
344+
def get_zoom(x):
345+
# "zoom" approximates the (integer) number of grid cells per degree lat or lon (min=1, max=8);
346+
# for EASEv2 grid and lat/lon grid, always use the default value of 8.
344347
zoom_ = '8'
345-
cxx = x.get('input:shared:agrid')
346-
if cxx :
347-
lat = int(cxx[1:])
348-
zoom = lat /90.0
349-
zoom_ = str(int(zoom))
350-
if zoom < 1 : zoom_ = '1'
351-
if zoom > 8 : zoom_ = '8'
352348
if x.get('input:shared:MERRA-2') or x.get('input:shared:GEOS-IT'):
353349
zoom_ = '2'
350+
return zoom_
351+
agrid = None
352+
if 'input:shared:agrid' in x.keys():
353+
agrid = x.get('input:shared:agrid')
354+
elif 'input' in x.keys():
355+
agrid = x['input']['shared']['agrid']
356+
if agrid:
357+
if (agrid[0].upper() == 'C'): # for cube-sphere: agrid = C90, C180, C1440, ...
358+
lat = int(agrid[1:])
359+
zoom = lat /90.0
360+
if zoom < 1 : zoom = 1
361+
if zoom > 8 : zoom = 8
362+
zoom_= str(int(zoom))
354363
return zoom_
355364

356365
def get_account():

0 commit comments

Comments
 (0)