Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pre/remap_restart/remap_command_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def parse_args(program_description):
p_command.add_argument('-in_stretch', default=False, help='Stretched CS params of input restarts', choices=choices_stretch)
p_command.add_argument('-out_stretch', default=False, help='Stretched CS params for new restarts', choices=choices_stretch)

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

p_command.add_argument('-nobkg', action='store_true', help="Do not remap bkg files")
Expand Down
36 changes: 20 additions & 16 deletions pre/remap_restart/remap_lake_landice_saltwater.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
import glob
import ruamel.yaml
import shlex
from remap_base import remap_base
from remap_utils import get_label
from remap_utils import get_geomdir
from remap_base import remap_base
from remap_utils import get_label, get_geomdir, get_zoom, get_gridname
from remap_bin2nc import bin2nc

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

agrid = config['output']['shared']['agrid']
ogrid = config['output']['shared']['ogrid']
omodel = config['output']['shared']['omodel']
stretch = config['output']['shared']['stretch']
out_tile_file = config['output']['surface']['catch_tilefile']
if not out_tile_file :
out_geomdir = get_geomdir(out_bc_base, out_bc_version, agrid=agrid, ogrid=ogrid, omodel=omodel, stretch=stretch)
out_tile_file = glob.glob(out_geomdir+ '/*-Pfafstetter.til')[0]
EASE_grid = config['output']['surface'].get('EASE_grid', None)
out_geomdir = get_geomdir(out_bc_base, out_bc_version, agrid=agrid, ogrid=ogrid, omodel=omodel, stretch=stretch, grid=EASE_grid)
out_tile_file = glob.glob(out_geomdir+ '/*.til')[0]

types = '.bin'
type_str = sp.check_output(['file','-b', os.path.realpath(restarts_in[0])])
Expand Down Expand Up @@ -118,23 +119,26 @@ def remap(self):
if 'saltwater_import' in f : saltwater_import = f
if 'seaicethermo_internal' in f : seaicethermo_internal = f
if 'seaicethermo_import' in f : seaicethermo_import = f
if 'landice' in f : landice = f
if 'lake' in f : lake = f
if 'roue' in f : route = f
if 'openwater' in f : openwater = f
if 'landice' in f : landice = f
if 'lake' in f : lake = f
if 'roue' in f : route = f
if 'openwater' in f : openwater = f

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

if os.path.exists(in_til) : shutil.remove(in_til)
if os.path.exists(out_til) : shutil.remove(out_til)
print('\n Copy ' + in_tile_file + ' to ' + in_til)
print('\n Copy ' + in_tile_file + ' to ' + in_til)
shutil.copy(in_tile_file, in_til)
print('\n Copy ' + out_tile_file + ' to ' + out_til)
shutil.copy(out_tile_file, out_til)

exe = bindir + '/mk_LakeLandiceSaltRestarts.x '
zoom = config['input']['surface']['zoom']
if zoom is None :
gridname = get_gridname(in_til)
zoom = get_zoom(gridname)
log_name = out_dir+'/remap_lake_landice_saltwater_log'
if os.path.exists(log_name):
os.remove(log_name)
Expand Down Expand Up @@ -227,7 +231,7 @@ def find_rst(self):
"landice_internal_rst" ,
"openwater_internal_rst" ,
"saltwater_internal_rst" ,
"saltwater_import_rst" ,
"saltwater_import_rst" ,
"seaicethermo_internal_rst",
"seaicethermo_import_rst"]

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

expid = self.config['input']['shared']['expid']
yyyymmddhh_ = str(self.config['input']['shared']['yyyymmddhh'])
yyyy_ = yyyymmddhh_[0:4]
mm_ = yyyymmddhh_[4:6]
dd_ = yyyymmddhh_[6:8]
yyyy_ = yyyymmddhh_[0: 4]
mm_ = yyyymmddhh_[4: 6]
dd_ = yyyymmddhh_[6: 8]
hh_ = yyyymmddhh_[8:10]

suffix = yyyymmddhh_[0:8]+'_'+ hh_ + 'z.bin'
Expand Down
2 changes: 1 addition & 1 deletion pre/remap_restart/remap_params.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ input:
surface:
zoom:
wemin:
# it supports three models: catch, catchcnclm40, catchcnclm45
# it supports three models: catch, catchcnclm40, catchcnclm51
catch_model: null
# if catch_tilefile is null, it searches bc_dir
catch_tilefile: null
Expand Down
34 changes: 31 additions & 3 deletions pre/remap_restart/remap_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import glob
import shlex
import netCDF4 as nc
import linecache

# shared global variables

Expand All @@ -36,7 +37,7 @@

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

choices_catchmodel = ['catch', 'catchcnclm40', 'catchcnclm45']
choices_catchmodel = ['catch', 'catchcnclm40', 'catchcnclm51']

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

Expand Down Expand Up @@ -284,8 +285,8 @@ def catch_model(x):
model = 'catch'
if 'cnclm40' in fname.lower():
model = 'catchcnclm40'
if 'cnclm45' in fname.lower():
model = 'catchcnclm45'
if 'cnclm51' in fname.lower():
model = 'catchcnclm51'
return model

def data_ocean_default(resolution):
Expand Down Expand Up @@ -353,6 +354,33 @@ def zoom_default(x):
zoom_ = '2'
return zoom_

def get_zoom(gridname):
# W.J notes: no idea how zoom is calculated in EASE grid.
zoom_ = '8'
if '-CF' in gridname:
j = gridname.find('x')
lat = int(gridname[2:j]) # gridname PEiiiixjjjj-CF
zoom = lat /90.0
zoom_ = str(int(zoom))
if zoom < 1 : zoom_ = '1'
if zoom > 8 : zoom_ = '8'
return zoom_

def get_gridname(tilefile):
gridname_ =''
tmptile = os.path.realpath(tilefile)
extension = os.path.splitext(tmptile)[1]
if extension == '.domain':
extension = os.path.splitext(tmptile)[0]
if extension == '.til':
gridname_ = linecache.getline(tmptile, 3).strip()
else:
nc_file = netCDF4.Dataset(tmptile,'r')
gridname_ = nc_file.getncattr('Grid_Name')
# in case it is an old name: SMAP-EASEvx-Mxx
gridname_ = gridname_.replace('SMAP-','').replace('-M','_M')
return gridname_

def get_account():
cmd = 'id -gn'
p = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE)
Expand Down
Loading