From 4ebbdc187d087f3be5550470c4c1ca18717e7b97 Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Mon, 4 Dec 2023 10:07:19 -0500 Subject: [PATCH 01/26] add ease grid for remapping --- pre/remap_restart/remap_catchANDcn.py | 100 ++++++++++++++++-- .../remap_lake_landice_saltwater.py | 4 +- pre/remap_restart/remap_params.tpl | 2 + pre/remap_restart/remap_questions.py | 6 +- pre/remap_restart/remap_upper.py | 4 +- pre/remap_restart/remap_utils.py | 33 +++--- 6 files changed, 122 insertions(+), 27 deletions(-) diff --git a/pre/remap_restart/remap_catchANDcn.py b/pre/remap_restart/remap_catchANDcn.py index c374f493..fe4d5420 100755 --- a/pre/remap_restart/remap_catchANDcn.py +++ b/pre/remap_restart/remap_catchANDcn.py @@ -18,9 +18,8 @@ import mimetypes import netCDF4 as nc from remap_base import remap_base -from remap_utils import get_landdir -from remap_utils import get_geomdir -from remap_utils import get_label +from remap_params import * +from remap_utils import * class catchANDcn(remap_base): def __init__(self, **configs): @@ -65,7 +64,9 @@ def remap(self): ogrid = config['input']['shared']['ogrid'] omodel = config['input']['shared']['omodel'] stretch = config['input']['shared']['stretch'] - bc_geomdir = get_geomdir(in_bc_base, in_bc_version, agrid, ogrid, omodel, stretch) + EASE_grid = config['input']['surface'].get('EASE_grid', None) + + bc_geomdir = get_geomdir(in_bc_base, in_bc_version, agrid=agrid, ogrid=ogrid, omodel=omodel, stretch=stretch, grid=EASE_grid) in_tilefile = glob.glob(bc_geomdir + '/*.til')[0] agrid = config['output']['shared']['agrid'] @@ -73,12 +74,13 @@ def remap(self): omodel = config['output']['shared']['omodel'] stretch = config['output']['shared']['stretch'] out_tilefile = config['output']['surface']['catch_tilefile'] + EASE_grid = config['output']['surface'].get('EASE_grid', None) if not out_tilefile : - bc_geomdir = get_geomdir(out_bc_base, out_bc_version, agrid, ogrid, omodel, stretch) + bc_geomdir = get_geomdir(out_bc_base, out_bc_version, agrid=agrid, ogrid=ogrid, omodel=omodel, stretch=stretch, grid=EASE_grid) out_tilefile = glob.glob(bc_geomdir+ '/*.til')[0] - out_bc_landdir = get_landdir(out_bc_base, out_bc_version, agrid, ogrid, omodel, stretch) + out_bc_landdir = get_landdir(out_bc_base, out_bc_version, agrid=agrid, ogrid=ogrid, omodel=omodel, stretch=stretch, grid=EASE_grid) # determine NPE based on *approximate* number of input and output tile @@ -225,6 +227,92 @@ def copy_merra2(self): print("Copy file "+f +" to " + rst_dir) shutil.copy(f, dest) +def ask_catch_questions(): + questions =[ + { + "type": "path", + "name": "input:shared:rst_dir", + "message": "Enter input directory with 'rs' and 'rc_out' as subdirectory:\n", + }, + + { + "type": "text", + "name": "input:shared:yyyymmddhh", + "message": "Enter restart date/time: (Must be 10 digits: yyyymmddhh.)\n", + "validate": lambda text: len(text)==10 , + }, + + { + "type": "path", + "name": "output:shared:out_dir", + "message": "Enter output directory for new restarts:\n" + }, + + { + "type": "text", + "name": "output:shared:expid", + "message": "Enter experiment ID for new restarts: (Added as prefix to new restart file names; can leave blank.)\n", + "default": "", + }, + + { + "type": "select", + "name": "output:shared:bc_base", + "message": "\nSelect BCs base directory for output restarts: \n", + "choices": choices_bc_base, + "default": get_default_bc_base(), + }, + + { + "type": "select", + "name": "output:shared:bc_version", + "message": message_bc_ops_new, + "choices": choices_bc_ops, + "default": "NL3", + }, + { + "type": "select", + "name": "output:shared:bc_version", + "message": message_bc_other_new, + "choices": choices_bc_other, + "when": lambda x: x["output:shared:bc_version"] == 'Other', + }, + + { + "type": "select", + "name": "output:surface::EASE_grid", + "message": "Please select EASE grid for the new restart", + "choices": ['EASEv2_M03', 'EASEv2_M09', 'EASEv2_M25', 'EASEv2_M36'] + }, + ] + + answers = questionary.prompt(questions) + yyyy = answers['input:shared:yyyymmddhh'][0:4] + mm = answers['input:shared:yyyymmddhh'][4:6] + dd = answers['input:shared:yyyymmddhh'][6:8] + hh = answers['input:shared:yyyymmddhh'][8:10] + + rst_dir = answers['input:shared:rst_dir']+'/rs/ens0000/Y'+yyyy +'/M'+mm+'/' + rst_file = glob.glob(rst_dir+'*catch*_internal_rst.'+yyyy+mm+dd+'_'+hh+'00')[0] + idx1 = rst_file.find('catch') + idx2 = rst_file.find('_internal_rst') + catch_model = rst_file[idx1:idx2] + + tile_dir = answers['input:shared:rst_dir']+'/rc_out/' + in_tilefiles = glob.glob(tile_dir+'*.til') + for file in in_tilefiles: + answers['input:surface:catch_tilefile'] = file + if 'MAPL_' in file: + answers['input:surface:catch_tilefile'] = file + + answers['input:shared:rst_dir'] = rst_dir + answers['input:surface:catch_model'] = catch_model + answers['input:surface:wemin'] = 13 + answers['output:surface:wemin'] = 13 + + return answers + if __name__ == '__main__' : + catch = catchANDcn(params_file='remap_params.yaml') catch.remap() diff --git a/pre/remap_restart/remap_lake_landice_saltwater.py b/pre/remap_restart/remap_lake_landice_saltwater.py index 486c4218..709e56b2 100755 --- a/pre/remap_restart/remap_lake_landice_saltwater.py +++ b/pre/remap_restart/remap_lake_landice_saltwater.py @@ -91,14 +91,14 @@ def remap(self): ogrid = config['input']['shared']['ogrid'] omodel = config['input']['shared']['omodel'] stretch = config['input']['shared']['stretch'] - in_geomdir = get_geomdir(in_bc_base, in_bc_version, agrid, ogrid, omodel, stretch) + 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] agrid = config['output']['shared']['agrid'] ogrid = config['output']['shared']['ogrid'] omodel = config['output']['shared']['omodel'] stretch = config['output']['shared']['stretch'] - out_geomdir = get_geomdir(out_bc_base, out_bc_version, agrid, ogrid, omodel, stretch) + 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] in_til = InData_dir+'/' + os.path.basename(in_tile_file) diff --git a/pre/remap_restart/remap_params.tpl b/pre/remap_restart/remap_params.tpl index 3a78a200..34691433 100644 --- a/pre/remap_restart/remap_params.tpl +++ b/pre/remap_restart/remap_params.tpl @@ -54,6 +54,8 @@ output: remap_catch: true # if catch_tilefile is null, it searches bc_dir catch_tilefile: null + # the name of ease grid + EASE_grid: null analysis: bkg: true aqua: False diff --git a/pre/remap_restart/remap_questions.py b/pre/remap_restart/remap_questions.py index b3839005..502e36f3 100755 --- a/pre/remap_restart/remap_questions.py +++ b/pre/remap_restart/remap_questions.py @@ -46,10 +46,10 @@ def echo_bcs(x,opt): bcv = x.get(opt+':shared:bc_version') agrid = x.get(opt+':shared:agrid') ogrid = x.get(opt+':shared:ogrid') - model = x.get(opt+':shared:omodel') + omodel = x.get(opt+':shared:omodel') stretch = x.get(opt+':shared:stretch') x[opt+':shared:bc_base'] = base - land_dir = get_landdir(base, bcv, agrid, ogrid, model, stretch) + land_dir = get_landdir(base, bcv, agrid=agrid, ogrid=ogrid, omodel=omodel, stretch=stretch) if not os.path.isdir(land_dir): exit("cannot find grid subdirectory for agrid=" + agrid + " and ogrid=" + ogrid + " under " + base+'/'+bcv+'/land/') print("\n Land BCs for " + opt + " restarts: " + land_dir ) @@ -286,7 +286,7 @@ def ask_questions(): { "type": "select", "name": "output:shared:bc_version", - "message": "\nSelect BCs version of input restarts:\n", + "message": "\nSelect BCs version for new restarts:\n", "choices": choices_bc_other, "when": lambda x: x["output:shared:bc_version"] == 'Other' and x["input:shared:bc_version"] in ['v06','v11'], }, diff --git a/pre/remap_restart/remap_upper.py b/pre/remap_restart/remap_upper.py index 30ceacb7..d52f3de5 100755 --- a/pre/remap_restart/remap_upper.py +++ b/pre/remap_restart/remap_upper.py @@ -94,7 +94,7 @@ def remap(self): ogrid = config['input']['shared']['ogrid'] omodel = config['input']['shared']['omodel'] stretch = config['input']['shared']['stretch'] - topo_bcsdir = get_topodir(in_bc_base, in_bc_version, agrid, ogrid, omodel, stretch) + topo_bcsdir = get_topodir(in_bc_base, in_bc_version, agrid=agrid, ogrid=ogrid, omodel=omodel, stretch=stretch) topoin = glob.glob(topo_bcsdir+'/topo_DYN_ave*.data')[0] # link topo file @@ -109,7 +109,7 @@ def remap(self): ogrid = config['output']['shared']['ogrid'] omodel = config['output']['shared']['omodel'] stretch = config['output']['shared']['stretch'] - topo_bcsdir = get_topodir(out_bc_base, out_bc_version, agrid, ogrid, omodel, stretch) + topo_bcsdir = get_topodir(out_bc_base, out_bc_version, agrid=agrid, ogrid=ogrid, omodel=omodel, stretch=stretch) topoout = glob.glob(topo_bcsdir+'/topo_DYN_ave*.data')[0] cmd = '/bin/ln -s ' + topoout + ' topo_dynave.data' diff --git a/pre/remap_restart/remap_utils.py b/pre/remap_restart/remap_utils.py index 68b838ec..e0cd32f2 100755 --- a/pre/remap_restart/remap_utils.py +++ b/pre/remap_restart/remap_utils.py @@ -225,15 +225,19 @@ def get_label(config): if config['output']['shared']['label']: agrid = config['output']['shared']['agrid'] ogrid = config['output']['shared']['ogrid'] - model = config['output']['shared']['omodel'] + omodel = config['output']['shared']['omodel'] stretch = config['output']['shared']['stretch'] - out_resolution = get_resolutions(agrid, ogrid, model, stretch) + EASE_grid = config['output']['surface'].get('EASE_grid', None) + + out_resolution = get_resolutions(agrid=agrid, ogrid=ogrid, omodel=omodel, stretch=stretch, grid=EASE_grid) agrid = config['input']['shared']['agrid'] ogrid = config['input']['shared']['ogrid'] - model = config['input']['shared']['omodel'] + omodel = config['input']['shared']['omodel'] stretch = config['input']['shared']['stretch'] - in_resolution = get_resolutions(agrid, ogrid, model, stretch) + EASE_grid = config['input']['surface'].get('EASE_grid', None) + + in_resolution = get_resolutions(agrid=agrid, ogrid=ogrid, omodel=omodel, stretch=stretch, grid=EASE_grid) in_bcv = config['input']['shared']['bc_version'] out_bcv = config['output']['shared']['bc_version'] @@ -453,7 +457,8 @@ def get_config_from_answers(answers): return config -def get_resolutions(agrid, ogrid, model, stretch): +def get_resolutions(agrid=None, ogrid=None, omodel=None, stretch=None, grid=None): + if grid is not None : return grid aname = '' oname = '' if (agrid[0].upper() == 'C'): @@ -466,11 +471,11 @@ def get_resolutions(agrid, ogrid, model, stretch): xy = ogrid.upper().split('X') s0 = int(xy[0]) s1 = int(xy[1]) - if model == 'data': + if omodel == 'data': oname = 'DE{:04d}xPE{:04d}'.format(s0,s1) - if model == 'MOM5': + if omodel == 'MOM5': oname = 'M5TP{:04d}x{:04d}'.format(s0,s1) - if model == 'MOM6': + if omodel == 'MOM6': oname = 'M6TP{:04d}x{:04d}'.format(s0,s1) if stretch: aname = aname + '-' + stretch @@ -492,8 +497,8 @@ def get_default_bc_base(): return choices_bc_base[0] return choices_bc_base[1] -def get_topodir(bc_base, bc_version, agrid, ogrid, model, stretch): - gridStr = get_resolutions(agrid, ogrid, model,stretch) +def get_topodir(bc_base, bc_version, agrid=None, ogrid=None, omodel=None, stretch=None): + gridStr = get_resolutions(agrid=afrid, ogrid=ogrid, omodel=omodel,stretch=stretch) agrid_name = gridStr.split('_')[0] bc_topo = '' if 'GM4' == bc_version: @@ -503,13 +508,13 @@ def get_topodir(bc_base, bc_version, agrid, ogrid, model, stretch): return bc_topo -def get_landdir(bc_base, bc_version, agrid, ogrid, model, stretch): - gridStr = get_resolutions(agrid, ogrid, model,stretch) +def get_landdir(bc_base, bc_version, agrid=None, ogrid=None, omodel=None, stretch=None, grid=None): + gridStr = get_resolutions(agrid=agrid, ogrid=ogrid, omodel=omodel,stretch=stretch, grid=grid) bc_land = bc_base+'/'+ bc_version+'/land/'+gridStr return bc_land -def get_geomdir(bc_base, bc_version, agrid, ogrid, model, stretch): - bc_geom = get_landdir(bc_base, bc_version, agrid, ogrid, model, stretch). replace('/land/', '/geometry/') +def get_geomdir(bc_base, bc_version, agrid=None, ogrid=None, omodel=None, stretch=None, grid=None): + bc_geom = get_landdir(bc_base, bc_version, agrid=agrid, ogrid=ogrid, omodel=omodel, stretch=stretch, grid=grid). replace('/land/', '/geometry/') return bc_geom if __name__ == '__main__' : From c0c3456ee6a32b2cab3e0c18a74d9a5ede1e6fdb Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Mon, 4 Dec 2023 11:06:19 -0500 Subject: [PATCH 02/26] correct typo --- pre/remap_restart/remap_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pre/remap_restart/remap_utils.py b/pre/remap_restart/remap_utils.py index e0cd32f2..d66ec9fe 100755 --- a/pre/remap_restart/remap_utils.py +++ b/pre/remap_restart/remap_utils.py @@ -498,7 +498,7 @@ def get_default_bc_base(): return choices_bc_base[1] def get_topodir(bc_base, bc_version, agrid=None, ogrid=None, omodel=None, stretch=None): - gridStr = get_resolutions(agrid=afrid, ogrid=ogrid, omodel=omodel,stretch=stretch) + gridStr = get_resolutions(agrid=agrid, ogrid=ogrid, omodel=omodel,stretch=stretch) agrid_name = gridStr.split('_')[0] bc_topo = '' if 'GM4' == bc_version: From f7c532d5258d0612c9b77ec116b55049fabb9d01 Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Wed, 13 Dec 2023 11:01:14 -0500 Subject: [PATCH 03/26] 1)default partiton is '' 2) work with SLES15 3)add log for remap_lake_landice --- pre/CMakeLists.txt | 13 ++++-- pre/remap_restart/remap_catchANDcn.py | 14 ++++-- pre/remap_restart/remap_command_line.py | 2 +- .../remap_lake_landice_saltwater.py | 45 ++++++++++++------- pre/remap_restart/remap_params.tpl | 2 +- pre/remap_restart/remap_questions.py | 5 +-- pre/remap_restart/remap_upper.py | 16 ++++--- pre/remap_restart/remap_utils.py | 14 +++++- 8 files changed, 75 insertions(+), 36 deletions(-) diff --git a/pre/CMakeLists.txt b/pre/CMakeLists.txt index 4653c7c6..4b310bd7 100644 --- a/pre/CMakeLists.txt +++ b/pre/CMakeLists.txt @@ -2,9 +2,16 @@ add_subdirectory(NSIDC-OSTIA_SST-ICE_blend) add_subdirectory(prepare_ocnExtData) file(GLOB pythonscripts CONFIGURE_DEPENDS ./remap_restart/remap* ./remap_restart/bin2nc_merra2* ./remap_restart/tests/*.*) -install( - PROGRAMS ${pythonscripts} - DESTINATION bin) + +foreach (file ${pythonscripts}) + if ( NOT ${file} MATCHES "./remap_restart/remap_utils.py") + install(PROGRAMS ${file} DESTINATION bin) + endif() +endforeach() + +set(file ./remap_restart/remap_utils.py) +configure_file(${file} ${file} @ONLY) +install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${file} DESTINATION bin) install( PROGRAMS regrid.pl diff --git a/pre/remap_restart/remap_catchANDcn.py b/pre/remap_restart/remap_catchANDcn.py index fe4d5420..32a7d967 100755 --- a/pre/remap_restart/remap_catchANDcn.py +++ b/pre/remap_restart/remap_catchANDcn.py @@ -111,8 +111,15 @@ def remap(self): if NPE >= 160: assert config['slurm']['qos'] != 'debug', "qos should be allnccs" TIME = "#SBATCH --time=12:00:00" - PARTITION = "#SBATCH --partition=" + config['slurm']['partition'] - + PARTITION ='' + partition = config['slurm']['partition'] + if (partition != ''): + PARTITION = "#SBATCH --partition=" + partition + + CONSTRAINT = '#SBATCH --constraint="[cas|sky]"' + if BUILT_ON_SLES15: + CONSTRAINT = '#SBATCH --constraint=mil' + account = config['slurm']['account'] # even if the (MERRA-2) input restarts are binary, the output restarts will always be nc4 (remap_bin2nc.py) label = get_label(config) @@ -149,6 +156,7 @@ def remap(self): #SBATCH --output={log_name} {TIME} {QOS} +{CONSTRAINT} {PARTITION} # @@ -169,7 +177,7 @@ def remap(self): catch1script = mk_catch_j_template.format(Bin = bindir, account = account, out_bcs = out_bc_landdir, \ model = model, out_dir = out_dir, surflay = surflay, log_name = log_name, NPE = NPE, \ in_wemin = in_wemin, out_wemin = out_wemin, out_tilefile = out_tilefile, in_tilefile = in_tilefile, \ - in_rstfile = in_rstfile, out_rstfile = out_rstfile, time = yyyymmddhh_, TIME = TIME, PARTITION = PARTITION, QOS=QOS ) + in_rstfile = in_rstfile, out_rstfile = out_rstfile, time = yyyymmddhh_, TIME = TIME, QOS=QOS, CONSTRAINT=CONSTRAINT, PARTITION=PARTITION ) script_name = './mk_catchANDcn.j' diff --git a/pre/remap_restart/remap_command_line.py b/pre/remap_restart/remap_command_line.py index 2a7693ff..05efd693 100755 --- a/pre/remap_restart/remap_command_line.py +++ b/pre/remap_restart/remap_command_line.py @@ -75,7 +75,7 @@ def parse_args(program_description): p_command.add_argument('-qos', default="debug", help="SLURM quality-of-service", choices=['debug', 'allnccs']) account = get_account() p_command.add_argument('-account', default=account, help="SLURM account") - p_command.add_argument('-partition', default='compute', help="SLURM partition") + p_command.add_argument('-partition', default='', help="SLURM partition") p_command.add_argument('-rs', default='3', help="Flag indicating which restarts to regrid: 1 (upper air); 2 (surface); 3 (both)", choices=['1','2','3']) # Parse using parse_known_args so we can pass the rest to the remap scripts diff --git a/pre/remap_restart/remap_lake_landice_saltwater.py b/pre/remap_restart/remap_lake_landice_saltwater.py index 709e56b2..7c7e2c29 100755 --- a/pre/remap_restart/remap_lake_landice_saltwater.py +++ b/pre/remap_restart/remap_lake_landice_saltwater.py @@ -10,7 +10,7 @@ # source g5_modules [csh] # import os -import subprocess +import subprocess as sp import shutil import glob import ruamel.yaml @@ -49,17 +49,17 @@ def remap(self): os.chdir(out_dir) InData_dir = out_dir+'/InData/' - if os.path.exists(InData_dir) : subprocess.call(['rm', '-rf',InData_dir]) + if os.path.exists(InData_dir) : sp.call(['rm', '-rf',InData_dir]) print ("mkdir " + InData_dir) os.makedirs(InData_dir) OutData_dir = out_dir+'/OutData/' - if os.path.exists(OutData_dir) : subprocess.call(['rm', '-rf',OutData_dir]) + if os.path.exists(OutData_dir) : sp.call(['rm', '-rf',OutData_dir]) print ("mkdir " + OutData_dir) os.makedirs(OutData_dir) types = '.bin' - type_str = subprocess.check_output(['file','-b', restarts_in[0]]) + type_str = sp.check_output(['file','-b', restarts_in[0]]) type_str = str(type_str) if 'Hierarchical' in type_str: types = '.nc4' @@ -113,46 +113,44 @@ def remap(self): exe = bindir + '/mk_LakeLandiceSaltRestarts.x ' zoom = config['input']['surface']['zoom'] + log_name = out_dir+'/remap_lake_landice_saltwater_log' + if os.path.exists(log_name): + os.remove(log_name) if (saltwater): cmd = exe + out_til + ' ' + in_til + ' InData/'+ saltwater + ' 0 ' + str(zoom) - print('\n'+cmd) - subprocess.call(shlex.split(cmd)) + self.run_and_log(cmd, log_name) # split Saltwater if config['output']['surface']['split_saltwater']: print("\nSplitting Saltwater...\n") cmd = bindir+'/SaltIntSplitter.x ' + out_til + ' ' + 'OutData/' + saltwater - print('\n'+cmd) - subprocess.call(shlex.split(cmd)) +# subprocess.call(shlex.split(cmd)) openwater = '' seaice = '' + self.run_and_log(cmd, log_name) if (openwater): cmd = exe + out_til + ' ' + in_til + ' InData/' + openwater + ' 0 ' + str(zoom) - print('\n'+cmd) - subprocess.call(shlex.split(cmd)) + self.run_and_log(cmd, log_name) if (seaice): cmd = exe + out_til + ' ' + in_til + ' InData/' + seaice + ' 0 ' + str(zoom) print('\n'+cmd) - subprocess.call(shlex.split(cmd)) + self.run_and_log(cmd, log_name) if (lake): cmd = exe + out_til + ' ' + in_til + ' InData/' + lake + ' 19 ' + str(zoom) - print('\n'+cmd) - subprocess.call(shlex.split(cmd)) + self.run_and_log(cmd, log_name) if (landice): cmd = exe + out_til + ' ' + in_til + ' InData/' + landice + ' 20 ' + str(zoom) - print('\n'+cmd) - subprocess.call(shlex.split(cmd)) + self.run_and_log(cmd, log_name) if (route): route = bindir + '/mk_RouteRestarts.x ' cmd = route + out_til + ' ' + yyyymmddhh_[0:6] - print('\n'+cmd) - subprocess.call(shlex.split(cmd)) + self.run_and_log(cmd, log_name) expid = config['output']['shared']['expid'] if (expid) : @@ -169,6 +167,19 @@ def remap(self): self.remove_merra2() + def run_and_log(self, cmd, log_name): + print('\n'+cmd) + process =sp.Popen(shlex.split(cmd), stdout=sp.PIPE, stderr=sp.PIPE) + stdout, stderr = process.communicate() + stdout = stdout.decode() + stderr = stderr.decode() + print('\n'+ stdout) + print('\n'+ stderr) + with open(log_name, "a") as log_: + log_.write(cmd) + log_.write(stdout) + log_.write(stderr) + def find_rst(self): surf_restarts =[ "route_internal_rst" , diff --git a/pre/remap_restart/remap_params.tpl b/pre/remap_restart/remap_params.tpl index 34691433..b5f124ce 100644 --- a/pre/remap_restart/remap_params.tpl +++ b/pre/remap_restart/remap_params.tpl @@ -63,4 +63,4 @@ output: slurm: account: qos: - partition: + partition: '' diff --git a/pre/remap_restart/remap_questions.py b/pre/remap_restart/remap_questions.py index 502e36f3..0b5e3d73 100755 --- a/pre/remap_restart/remap_questions.py +++ b/pre/remap_restart/remap_questions.py @@ -424,9 +424,8 @@ def ask_questions(): { "type": "text", "name": "slurm:partition", - "message": "SLURM partition?", - "default": "compute", - "when": lambda x : default_partition(x), + "message": "Enter the SLURM partition only if you want particular partiton, otherwise keep empty as default: ", + "default": '', }, ] answers = questionary.prompt(questions) diff --git a/pre/remap_restart/remap_upper.py b/pre/remap_restart/remap_upper.py index d52f3de5..7387059c 100755 --- a/pre/remap_restart/remap_upper.py +++ b/pre/remap_restart/remap_upper.py @@ -15,9 +15,7 @@ import shutil import glob from remap_base import remap_base -from remap_utils import get_label -from remap_utils import STRETCH_GRID -from remap_utils import get_topodir +from remap_utils import * from remap_bin2nc import bin2nc class upperair(remap_base): @@ -148,8 +146,14 @@ def remap(self): if NPE > 532: assert config['slurm']['qos'] != 'debug', "qos should be allnccs" TIME = "#SBATCH --time=12:00:00" + PARTITION ='' + partition = config['slurm']['partition'] + if (partition != ''): + PARTITION = "#SBATCH --partition=" + partition - PARTITION = "#SBATCH --partition=" + config['slurm']['partition'] + CONSTRAINT = '#SBATCH --constraint="[cas|sky]"' + if BUILT_ON_SLES15: + CONSTRAINT = '#SBATCH --constraint=mil' log_name = out_dir+'/remap_upper_log' @@ -196,8 +200,8 @@ def remap(self): #SBATCH --output={log_name} {TIME} {QOS} +{CONSTRAINT} {PARTITION} - unlimit cd {out_dir}/upper_data @@ -260,7 +264,7 @@ def remap(self): remap_upper_script = remap_template.format(Bin=bindir, account = account, \ out_dir = out_dir, log_name = log_name, drymassFLG = drymassFLG, \ imout = imout, nwrit = nwrit, NPE = NPE, \ - QOS = QOS, TIME = TIME, PARTITION = PARTITION, nlevel = nlevel, hydrostatic = hydrostatic, + QOS = QOS, TIME = TIME, CONSTRAINT = CONSTRAINT, PARTITION = PARTITION, nlevel = nlevel, hydrostatic = hydrostatic, stretch_str = stretch_str) script_name = './remap_upper.j' diff --git a/pre/remap_restart/remap_utils.py b/pre/remap_restart/remap_utils.py index d66ec9fe..6b17ebcd 100755 --- a/pre/remap_restart/remap_utils.py +++ b/pre/remap_restart/remap_utils.py @@ -15,6 +15,15 @@ # shared global variables +#During cmake step, the string will be changed according to the system + +BUILT_ON_SLES15 = "NO@BUILT_ON_SLES15@" + +if BUILT_ON_SLES15== "NO": + BUILT_ON_SLES15 = False +else: + BUILT_ON_SLES15 = True + # top-level directory for BCs (machine-dependent) choices_bc_base =[ "NCCS/Discover : /discover/nobackup/projects/gmao/bcs_shared/fvInput/ExtData/esm/tiles", @@ -400,8 +409,9 @@ def get_command_line_from_answers(answers): account = " -account " + answers["slurm:account"] qos = " -qos " + answers["slurm:qos"] - partition = " -partition " + answers["slurm:partition"] - + partition = '' + if answers["slurm:partition"] != '': + partition = " -partition " + answers["slurm:partition"] cmdl = "remap_restarts.py command_line " + merra2 + \ ymdh + \ From dbd869f61cb94778951e204936eebf396d135e33 Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Fri, 15 Dec 2023 17:37:27 -0500 Subject: [PATCH 04/26] add support of PBS on NAS --- pre/remap_restart/remap_catchANDcn.py | 84 +++++++++++++------------ pre/remap_restart/remap_command_line.py | 12 ++-- pre/remap_restart/remap_params.py | 24 +++---- pre/remap_restart/remap_params.tpl | 2 +- pre/remap_restart/remap_questions.py | 16 ++--- pre/remap_restart/remap_upper.py | 84 +++++++++++++------------ pre/remap_restart/remap_utils.py | 32 ++++++++-- 7 files changed, 144 insertions(+), 110 deletions(-) diff --git a/pre/remap_restart/remap_catchANDcn.py b/pre/remap_restart/remap_catchANDcn.py index 32a7d967..111d99c0 100755 --- a/pre/remap_restart/remap_catchANDcn.py +++ b/pre/remap_restart/remap_catchANDcn.py @@ -59,6 +59,9 @@ def remap(self): surflay = config['output']['surface']['surflay'] in_tilefile = config['input']['surface']['catch_tilefile'] + job = 'SLURM' + if "gmao_SIteam/ModelData" in out_bc_base: job='PBS' + if not in_tilefile : agrid = config['input']['shared']['agrid'] ogrid = config['input']['shared']['ogrid'] @@ -106,21 +109,25 @@ def remap(self): else: NPE = 160 - QOS = "#SBATCH --qos="+config['slurm']['qos'] - TIME ="#SBATCH --time=1:00:00" - if NPE >= 160: - assert config['slurm']['qos'] != 'debug', "qos should be allnccs" - TIME = "#SBATCH --time=12:00:00" PARTITION ='' - partition = config['slurm']['partition'] - if (partition != ''): - PARTITION = "#SBATCH --partition=" + partition - - CONSTRAINT = '#SBATCH --constraint="[cas|sky]"' - if BUILT_ON_SLES15: - CONSTRAINT = '#SBATCH --constraint=mil' - - account = config['slurm']['account'] + QOS = config['slurm_pbs']['qos'] + TIME = "1:00:00" + if QOS != "debug": TIME="12:00:00" + + NNODE = '' + if job == 'SLURM': + partition = config['slurm_pbs']['partition'] + if (partition != ''): + PARTITION = "#SBATCH --partition=" + partition + + CONSTRAINT = '"[cas|sky]"' + if BUILT_ON_SLES15: + CONSTRAINT = 'mil' + elif job == "PBS": + CONSTRAINT = 'cas_ait' + NNODE = (NPE-1)//40 + 1 + + account = config['slurm_pbs']['account'] # even if the (MERRA-2) input restarts are binary, the output restarts will always be nc4 (remap_bin2nc.py) label = get_label(config) @@ -149,19 +156,10 @@ def remap(self): in_rstfile = dest log_name = out_dir+'/'+'mk_catchANDcn_log' - mk_catch_j_template = """#!/bin/csh -f -#SBATCH --account={account} -#SBATCH --ntasks={NPE} -#SBATCH --job-name=mk_catchANDcn -#SBATCH --output={log_name} -{TIME} -{QOS} -{CONSTRAINT} -{PARTITION} -# - + job_name = "mk_catchANDcn" + mk_catch_j_template = job_directive[job]+ \ +""" source {Bin}/g5_modules - limit stacksize unlimited set esma_mpirun_X = ( {Bin}/esma_mpirun -np {NPE} ) @@ -175,7 +173,8 @@ def remap(self): """ catch1script = mk_catch_j_template.format(Bin = bindir, account = account, out_bcs = out_bc_landdir, \ - model = model, out_dir = out_dir, surflay = surflay, log_name = log_name, NPE = NPE, \ + model = model, out_dir = out_dir, surflay = surflay, log_name = log_name, job_name = job_name, \ + NPE = NPE, NNODE=NNODE, \ in_wemin = in_wemin, out_wemin = out_wemin, out_tilefile = out_tilefile, in_tilefile = in_tilefile, \ in_rstfile = in_rstfile, out_rstfile = out_rstfile, time = yyyymmddhh_, TIME = TIME, QOS=QOS, CONSTRAINT=CONSTRAINT, PARTITION=PARTITION ) @@ -184,27 +183,34 @@ def remap(self): catch_scrpt = open(script_name,'wt') catch_scrpt.write(catch1script) catch_scrpt.close() - + + interactive = None + if job == "SLURM": interactive = os.getenv('SLURM_JOB_ID', default = None) + if job == 'PBS': interactive = os.getenv('PBS_JOBID', default = None) + interactive = os.getenv('SLURM_JOB_ID', default = None) if ( interactive ) : print('interactive mode\n') - ntasks = os.getenv('SLURM_NTASKS', default = None) - if ( not ntasks): - nnodes = int(os.getenv('SLURM_NNODES', default = '1')) - ncpus = int(os.getenv('SLURM_CPUS_ON_NODE', default = '40')) - ntasks = nnodes * ncpus - ntasks = int(ntasks) + if job == "SLURM": + ntasks = os.getenv('SLURM_NTASKS', default = None) + if ( not ntasks): + nnodes = int(os.getenv('SLURM_NNODES', default = '1')) + ncpus = int(os.getenv('SLURM_CPUS_ON_NODE', default = '40')) + ntasks = nnodes * ncpus + ntasks = int(ntasks) - if (ntasks < NPE): - print("\nYou should have at least {NPE} cores. Now you only have {ntasks} cores ".format(NPE=NPE, ntasks=ntasks)) + if (ntasks < NPE): + print("\nYou should have at least {NPE} cores. Now you only have {ntasks} cores ".format(NPE=NPE, ntasks=ntasks)) subprocess.call(['chmod', '755', script_name]) print(script_name+ ' 1>' + log_name + ' 2>&1') os.system(script_name + ' 1>' + log_name+ ' 2>&1') - + elif job == "SLURM" : + print('sbatch -W '+ script_name +'\n') + subprocess.call(['sbatch', '-W', script_name]) else: - print("sbatch -W " + script_name +"\n") - subprocess.call(['sbatch','-W', script_name]) + print('qsub -W block=true '+ script_name +'\n') + subprocess.call(['qsub', '-W','block=true', script_name]) print( "cd " + cwdir) os.chdir(cwdir) diff --git a/pre/remap_restart/remap_command_line.py b/pre/remap_restart/remap_command_line.py index 05efd693..489eebf2 100755 --- a/pre/remap_restart/remap_command_line.py +++ b/pre/remap_restart/remap_command_line.py @@ -72,10 +72,10 @@ def parse_args(program_description): p_command.add_argument('-out_bc_base',default="", help="Boundary conditions base dir (w/o bc_version and resolution info) for new restarts") p_command.add_argument('-zoom', help= "Zoom parameter (search radius) for input surface restarts") - p_command.add_argument('-qos', default="debug", help="SLURM quality-of-service", choices=['debug', 'allnccs']) + p_command.add_argument('-qos', default="debug", help="slurm_pbs quality-of-service", choices=['debug', 'allnccs', 'normal']) account = get_account() - p_command.add_argument('-account', default=account, help="SLURM account") - p_command.add_argument('-partition', default='', help="SLURM partition") + p_command.add_argument('-account', default=account, help="slurm_pbs account") + p_command.add_argument('-partition', default='', help="slurm_pbs partition") p_command.add_argument('-rs', default='3', help="Flag indicating which restarts to regrid: 1 (upper air); 2 (surface); 3 (both)", choices=['1','2','3']) # Parse using parse_known_args so we can pass the rest to the remap scripts @@ -146,9 +146,9 @@ def get_answers_from_command_line(cml): else: answers["output:surface:wemin"] = wemin_default(answers['output:shared:bc_version']) - answers["slurm:account"] = cml.account - answers["slurm:qos"] = cml.qos - answers["slurm:partition"] = cml.partition + answers["slurm_pbs:account"] = cml.account + answers["slurm_pbs:qos"] = cml.qos + answers["slurm_pbs:partition"] = cml.partition return answers diff --git a/pre/remap_restart/remap_params.py b/pre/remap_restart/remap_params.py index 045edc17..ff336505 100755 --- a/pre/remap_restart/remap_params.py +++ b/pre/remap_restart/remap_params.py @@ -17,13 +17,13 @@ class remap_params(object): def __init__(self, config_from_question): - self.common_in = config_from_question['input']['shared'] - self.common_out = config_from_question['output']['shared'] - self.upper_out = config_from_question['output']['air'] - self.slurm_options = config_from_question['slurm'] - self.surf_in = config_from_question['input']['surface'] - self.surf_out = config_from_question['output']['surface'] - self.ana_out = config_from_question['output']['analysis'] + self.common_in = config_from_question['input']['shared'] + self.common_out = config_from_question['output']['shared'] + self.upper_out = config_from_question['output']['air'] + self.slurm_pbs_options = config_from_question['slurm_pbs'] + self.surf_in = config_from_question['input']['surface'] + self.surf_out = config_from_question['output']['surface'] + self.ana_out = config_from_question['output']['analysis'] # load input yaml yaml = ruamel.yaml.YAML() @@ -65,7 +65,7 @@ def __init__(self, config_from_question): config_tpl = self.params_for_air(config_tpl) config_tpl = self.params_for_surface(config_tpl) config_tpl = self.params_for_analysis(config_tpl) - config_tpl = self.options_for_slurm(config_tpl) + config_tpl = self.options_for_slurm_pbs(config_tpl) self.config = config_tpl @@ -77,10 +77,10 @@ def params_for_air(self, config_tpl): return config_tpl - def options_for_slurm(self, config_tpl): - config_tpl['slurm']['account'] = self.slurm_options['account'] - config_tpl['slurm']['qos'] = self.slurm_options['qos'] - config_tpl['slurm']['partition'] = self.slurm_options['partition'] + def options_for_slurm_pbs(self, config_tpl): + config_tpl['slurm_pbs']['account'] = self.slurm_pbs_options['account'] + config_tpl['slurm_pbs']['qos'] = self.slurm_pbs_options['qos'] + config_tpl['slurm_pbs']['partition'] = self.slurm_pbs_options['partition'] return config_tpl def params_for_surface(self, config_tpl): diff --git a/pre/remap_restart/remap_params.tpl b/pre/remap_restart/remap_params.tpl index b5f124ce..1df2b7f9 100644 --- a/pre/remap_restart/remap_params.tpl +++ b/pre/remap_restart/remap_params.tpl @@ -60,7 +60,7 @@ output: bkg: true aqua: False lcv: false -slurm: +slurm_pbs: account: qos: partition: '' diff --git a/pre/remap_restart/remap_questions.py b/pre/remap_restart/remap_questions.py index 0b5e3d73..6bc65bd4 100755 --- a/pre/remap_restart/remap_questions.py +++ b/pre/remap_restart/remap_questions.py @@ -56,8 +56,8 @@ def echo_bcs(x,opt): return False def default_partition(x): - if x['slurm:qos'] == 'debug': - x['slurm:partition'] = 'compute' + if x['slurm_pbs:qos'] == 'debug': + x['slurm_pbs:partition'] = 'compute' return False return True @@ -410,21 +410,21 @@ def ask_questions(): { "type": "text", - "name": "slurm:qos", - "message": "SLURM quality-of-service (qos)? (If on NCCS and atm resolution is c1440 or higher, enter allnccs.) ", + "name": "slurm_pbs:qos", + "message": "slurm or pbs quality-of-service (qos)? (If resolution is c1440 or higher, enter allnccs on NCCS or normal on NAS.) ", "default": "debug", }, { "type": "text", - "name": "slurm:account", - "message": "SLURM account?", + "name": "slurm_pbs:account", + "message": "slurm_pbs account?", "default": get_account(), }, { "type": "text", - "name": "slurm:partition", - "message": "Enter the SLURM partition only if you want particular partiton, otherwise keep empty as default: ", + "name": "slurm_pbs:partition", + "message": "Enter the slurm or pbs partition only if you want particular partiton, otherwise keep empty as default: ", "default": '', }, ] diff --git a/pre/remap_restart/remap_upper.py b/pre/remap_restart/remap_upper.py index 7387059c..646b3bcb 100755 --- a/pre/remap_restart/remap_upper.py +++ b/pre/remap_restart/remap_upper.py @@ -94,6 +94,9 @@ def remap(self): stretch = config['input']['shared']['stretch'] topo_bcsdir = get_topodir(in_bc_base, in_bc_version, agrid=agrid, ogrid=ogrid, omodel=omodel, stretch=stretch) + job = 'SLURM' + if "gmao_SIteam/ModelData" in in_bc_base: job='PBS' + topoin = glob.glob(topo_bcsdir+'/topo_DYN_ave*.data')[0] # link topo file @@ -141,21 +144,24 @@ def remap(self): elif (imout>=2880): NPE = 5400; nwrit = 6 - QOS = "#SBATCH --qos="+config['slurm']['qos'] - TIME ="#SBATCH --time=1:00:00" - if NPE > 532: - assert config['slurm']['qos'] != 'debug', "qos should be allnccs" - TIME = "#SBATCH --time=12:00:00" PARTITION ='' - partition = config['slurm']['partition'] - if (partition != ''): - PARTITION = "#SBATCH --partition=" + partition - - CONSTRAINT = '#SBATCH --constraint="[cas|sky]"' - if BUILT_ON_SLES15: - CONSTRAINT = '#SBATCH --constraint=mil' - - log_name = out_dir+'/remap_upper_log' + QOS = config['slurm_pbs']['qos'] + TIME = "1:00:00" + if NPE > 532: + assert config['slurm_pbs']['qos'] != 'debug', "qos should be allnccs or normal on NAS" + TIME = "12:00:00" + NNODE = '' + if job == 'SLURM': + partition = config['slurm_pbs']['partition'] + if (partition != ''): + PARTITION = "#SBATCH --partition=" + partition + + CONSTRAINT = '"[cas|sky]"' + if BUILT_ON_SLES15: + CONSTRAINT = 'mil' + else: + CONSTRAINT = 'cas_ait' + NNODE = (NPE-1)//40 + 1 # We need to create an input.nml file which is different if we are running stretched grid # If we are running stretched grid, we need to pass in the target lon+lat and stretch factor @@ -193,19 +199,12 @@ def remap(self): with open('input.nml', 'w') as f: f.write(nml_file) - remap_template="""#!/bin/csh -xf -#SBATCH --account={account} -#SBATCH --ntasks={NPE} -#SBATCH --job-name=remap_upper -#SBATCH --output={log_name} -{TIME} -{QOS} -{CONSTRAINT} -{PARTITION} -unlimit + remap_template = job_directive[job] + \ +""" +source {Bin}/g5_modules +limit stacksize unlimited cd {out_dir}/upper_data -source {Bin}/g5_modules /bin/touch input.nml # The MERRA fvcore_internal_restarts don't include W or DZ, but we can add them by setting @@ -256,14 +255,15 @@ def remap(self): -do_hydro {hydrostatic} $ioflag $dmflag -nwriter {nwrit} {stretch_str} """ - account = config['slurm']['account'] + account = config['slurm_pbs']['account'] drymassFLG = config['input']['air']['drymass'] hydrostatic = config['input']['air']['hydrostatic'] nlevel = config['output']['air']['nlevel'] - + log_name = out_dir+'/remap_upper_log' + job_name = 'remap_upper' remap_upper_script = remap_template.format(Bin=bindir, account = account, \ - out_dir = out_dir, log_name = log_name, drymassFLG = drymassFLG, \ - imout = imout, nwrit = nwrit, NPE = NPE, \ + out_dir = out_dir, log_name = log_name, job_name= job_name, drymassFLG = drymassFLG, \ + imout = imout, nwrit = nwrit, NPE = NPE, NNODE = NNODE, \ QOS = QOS, TIME = TIME, CONSTRAINT = CONSTRAINT, PARTITION = PARTITION, nlevel = nlevel, hydrostatic = hydrostatic, stretch_str = stretch_str) @@ -273,25 +273,31 @@ def remap(self): upper.write(remap_upper_script) upper.close() - interactive = os.getenv('SLURM_JOB_ID', default = None) + interactive = None + if job == "SLURM": interactive = os.getenv('SLURM_JOB_ID', default = None) + if job == 'PBS': interactive = os.getenv('PBS_JOBID', default = None) if (interactive) : print('interactive mode\n') - ntasks = os.getenv('SLURM_NTASKS', default = None) - if ( not ntasks): - nnodes = int(os.getenv('SLURM_NNODES', default = '1')) - ncpus = int(os.getenv('SLURM_CPUS_ON_NODE', default = '28')) - ntasks = nnodes * ncpus - ntasks = int(ntasks) - if (ntasks < NPE ): - print("\nYou should have at least {NPE} cores. Now you only have {ntasks} cores ".format(NPE=NPE, ntasks=ntasks)) + if job == 'SLURM': + ntasks = os.getenv('SLURM_NTASKS', default = None) + if ( not ntasks): + nnodes = int(os.getenv('SLURM_NNODES', default = '1')) + ncpus = int(os.getenv('SLURM_CPUS_ON_NODE', default = '28')) + ntasks = nnodes * ncpus + ntasks = int(ntasks) + if (ntasks < NPE ): + print("\nYou should have at least {NPE} cores. Now you only have {ntasks} cores ".format(NPE=NPE, ntasks=ntasks)) subprocess.call(['chmod', '755', script_name]) print(script_name+ ' 1>' + log_name + ' 2>&1') os.system(script_name + ' 1>' + log_name+ ' 2>&1') - else : + elif job == "SLURM" : print('sbatch -W '+ script_name +'\n') subprocess.call(['sbatch', '-W', script_name]) + else: + print('qsub -W block=true '+ script_name +'\n') + subprocess.call(['qsub', '-W','block=true', script_name]) # # post process diff --git a/pre/remap_restart/remap_utils.py b/pre/remap_restart/remap_utils.py index 6b17ebcd..6b16fb0a 100755 --- a/pre/remap_restart/remap_utils.py +++ b/pre/remap_restart/remap_utils.py @@ -104,6 +104,28 @@ validate_agrid = ['C12','C24','C48','C90','C180','C360','C720','C1000','C1440','C2880','C5760'] +job_directive = {"SLURM": """#!/bin/csh -f +#SBATCH --account={account} +#SBATCH --ntasks={NPE} +#SBATCH --job-name={job_name} +#SBATCH --output={log_name} +#SBATCH --qos={QOS} +#SBATCH --time={TIME} +#SBATCH --constraint={CONSTRAINT} +{PARTITION} +""", +"PBS": """#!/bin/csh -f +#PBS -l walltime={TIME} +#PBS -l select={NNODE}:ncpus=40:mpiprocs=40:model={CONSTRAINT} +#PBS -N {job_name} +#PBS -q {QOS} +#PBS -W group_list={account} +#PBS -o {log_name} +#PBS -j oe +{PARTITION} +""" +} + # -------------------------------------------------------------------------------- def init_merra2(x): @@ -407,11 +429,11 @@ def get_command_line_from_answers(answers): noagcm_import_rst = '' if answers["output:air:agcm_import_rst"] else " -noagcm_import_rst " - account = " -account " + answers["slurm:account"] - qos = " -qos " + answers["slurm:qos"] + account = " -account " + answers["slurm_pbs:account"] + qos = " -qos " + answers["slurm_pbs:qos"] partition = '' - if answers["slurm:partition"] != '': - partition = " -partition " + answers["slurm:partition"] + if answers["slurm_pbs:partition"] != '': + partition = " -partition " + answers["slurm_pbs:partition"] cmdl = "remap_restarts.py command_line " + merra2 + \ ymdh + \ @@ -457,7 +479,7 @@ def get_config_from_answers(answers): config['output']['air'] = {} config['output']['surface'] = {} config['output']['analysis'] = {} - config['slurm'] = {} + config['slurm_pbs'] = {} for key, value in answers.items(): keys = key.split(":") if len(keys) == 2: From c756188a22b6f1adf931cbb3a3d4e16d0a87409c Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Tue, 19 Dec 2023 13:23:35 -0500 Subject: [PATCH 05/26] remove an extra wrong line --- pre/remap_restart/remap_catchANDcn.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pre/remap_restart/remap_catchANDcn.py b/pre/remap_restart/remap_catchANDcn.py index 111d99c0..5ddcda2e 100755 --- a/pre/remap_restart/remap_catchANDcn.py +++ b/pre/remap_restart/remap_catchANDcn.py @@ -188,7 +188,6 @@ def remap(self): if job == "SLURM": interactive = os.getenv('SLURM_JOB_ID', default = None) if job == 'PBS': interactive = os.getenv('PBS_JOBID', default = None) - interactive = os.getenv('SLURM_JOB_ID', default = None) if ( interactive ) : print('interactive mode\n') if job == "SLURM": From 16010dda05c09f36f5b143850b55973858e87ffe Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Wed, 20 Dec 2023 06:28:25 -0800 Subject: [PATCH 06/26] added site detection by cmake --- pre/remap_restart/remap_questions.py | 6 ++++++ pre/remap_restart/remap_utils.py | 1 + 2 files changed, 7 insertions(+) diff --git a/pre/remap_restart/remap_questions.py b/pre/remap_restart/remap_questions.py index 6bc65bd4..d4e06c8f 100755 --- a/pre/remap_restart/remap_questions.py +++ b/pre/remap_restart/remap_questions.py @@ -70,6 +70,11 @@ def validate_merra2_time(text): return False else: return False +def SITE_MERRA2(x): + if SITE == "NAS": + x['input:shared:MERRA-2']= False + return False + return True def ask_questions(): @@ -82,6 +87,7 @@ def ask_questions(): "name": "input:shared:MERRA-2", "message": "Remap archived MERRA-2 restarts? (NCCS/Discover only; elsewhere, select 'N' and complete full config; requires nc4 restarts.)\n", "default": False, + "when": lambda x: SITE_MERRA2(x), }, { "type": "path", diff --git a/pre/remap_restart/remap_utils.py b/pre/remap_restart/remap_utils.py index 6b16fb0a..a2d2e808 100755 --- a/pre/remap_restart/remap_utils.py +++ b/pre/remap_restart/remap_utils.py @@ -18,6 +18,7 @@ #During cmake step, the string will be changed according to the system BUILT_ON_SLES15 = "NO@BUILT_ON_SLES15@" +SITE = "@GEOS_SITE@" if BUILT_ON_SLES15== "NO": BUILT_ON_SLES15 = False From 1f810a896c2e7f72bbd28b0643dcc01c1ef30e58 Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Wed, 20 Dec 2023 06:33:22 -0800 Subject: [PATCH 07/26] change log --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cec8d6f7..b0d39edd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +1)Add EASE grid option to remapping of surface restarts in remap_restarts.py package +2)Added support for SLES15, NAS site and log for remap_lake_landice_saltwater in remap_restarts.py package + + ### Changed ### Fixed From 64c66c5294b3e9cc178b54d503d6eb5e3908af62 Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Wed, 20 Dec 2023 12:23:46 -0500 Subject: [PATCH 08/26] use GEOS_SITE --- pre/remap_restart/remap_catchANDcn.py | 41 +++++++++++++++------------ pre/remap_restart/remap_questions.py | 2 +- pre/remap_restart/remap_upper.py | 41 +++++++++++++++------------ pre/remap_restart/remap_utils.py | 2 +- 4 files changed, 48 insertions(+), 38 deletions(-) diff --git a/pre/remap_restart/remap_catchANDcn.py b/pre/remap_restart/remap_catchANDcn.py index 5ddcda2e..1d8665fe 100755 --- a/pre/remap_restart/remap_catchANDcn.py +++ b/pre/remap_restart/remap_catchANDcn.py @@ -59,8 +59,8 @@ def remap(self): surflay = config['output']['surface']['surflay'] in_tilefile = config['input']['surface']['catch_tilefile'] - job = 'SLURM' - if "gmao_SIteam/ModelData" in out_bc_base: job='PBS' + if "gmao_SIteam/ModelData" in out_bc_base: + assert GEOS_SITE == "NAS", "wrong site to run the package" if not in_tilefile : agrid = config['input']['shared']['agrid'] @@ -115,17 +115,20 @@ def remap(self): if QOS != "debug": TIME="12:00:00" NNODE = '' - if job == 'SLURM': - partition = config['slurm_pbs']['partition'] - if (partition != ''): - PARTITION = "#SBATCH --partition=" + partition - - CONSTRAINT = '"[cas|sky]"' - if BUILT_ON_SLES15: - CONSTRAINT = 'mil' - elif job == "PBS": + job = '' + if GEOS_SITE == 'NAS': + job = "PBS" CONSTRAINT = 'cas_ait' NNODE = (NPE-1)//40 + 1 + else: + job = "SLURM" + partition = config['slurm_pbs']['partition'] + if (partition != ''): + PARTITION = "#SBATCH --partition=" + partition + + CONSTRAINT = '"[cas|sky]"' + if BUILT_ON_SLES15: + CONSTRAINT = 'mil' account = config['slurm_pbs']['account'] # even if the (MERRA-2) input restarts are binary, the output restarts will always be nc4 (remap_bin2nc.py) @@ -185,12 +188,14 @@ def remap(self): catch_scrpt.close() interactive = None - if job == "SLURM": interactive = os.getenv('SLURM_JOB_ID', default = None) - if job == 'PBS': interactive = os.getenv('PBS_JOBID', default = None) + if GEOS_SITE == 'NAS': + interactive = os.getenv('PBS_JOBID', default = None) + else: + interactive = os.getenv('SLURM_JOB_ID', default = None) if ( interactive ) : print('interactive mode\n') - if job == "SLURM": + if GEOS_SITE != "NAS": ntasks = os.getenv('SLURM_NTASKS', default = None) if ( not ntasks): nnodes = int(os.getenv('SLURM_NNODES', default = '1')) @@ -204,12 +209,12 @@ def remap(self): subprocess.call(['chmod', '755', script_name]) print(script_name+ ' 1>' + log_name + ' 2>&1') os.system(script_name + ' 1>' + log_name+ ' 2>&1') - elif job == "SLURM" : - print('sbatch -W '+ script_name +'\n') - subprocess.call(['sbatch', '-W', script_name]) - else: + elif GEOS_SITE == "NAS" : print('qsub -W block=true '+ script_name +'\n') subprocess.call(['qsub', '-W','block=true', script_name]) + else: + print('sbatch -W '+ script_name +'\n') + subprocess.call(['sbatch', '-W', script_name]) print( "cd " + cwdir) os.chdir(cwdir) diff --git a/pre/remap_restart/remap_questions.py b/pre/remap_restart/remap_questions.py index d4e06c8f..762aa0ef 100755 --- a/pre/remap_restart/remap_questions.py +++ b/pre/remap_restart/remap_questions.py @@ -71,7 +71,7 @@ def validate_merra2_time(text): else: return False def SITE_MERRA2(x): - if SITE == "NAS": + if GEOS_SITE == "NAS": x['input:shared:MERRA-2']= False return False return True diff --git a/pre/remap_restart/remap_upper.py b/pre/remap_restart/remap_upper.py index 646b3bcb..6ea13bf1 100755 --- a/pre/remap_restart/remap_upper.py +++ b/pre/remap_restart/remap_upper.py @@ -94,8 +94,8 @@ def remap(self): stretch = config['input']['shared']['stretch'] topo_bcsdir = get_topodir(in_bc_base, in_bc_version, agrid=agrid, ogrid=ogrid, omodel=omodel, stretch=stretch) - job = 'SLURM' - if "gmao_SIteam/ModelData" in in_bc_base: job='PBS' + if "gmao_SIteam/ModelData" in in_bc_base: + assert GEOS_SITE == "NAS", "wrong site to run the package" topoin = glob.glob(topo_bcsdir+'/topo_DYN_ave*.data')[0] # link topo file @@ -151,17 +151,20 @@ def remap(self): assert config['slurm_pbs']['qos'] != 'debug', "qos should be allnccs or normal on NAS" TIME = "12:00:00" NNODE = '' - if job == 'SLURM': - partition = config['slurm_pbs']['partition'] - if (partition != ''): - PARTITION = "#SBATCH --partition=" + partition - - CONSTRAINT = '"[cas|sky]"' - if BUILT_ON_SLES15: - CONSTRAINT = 'mil' - else: + job='' + if GEOS_SITE == "NAS": CONSTRAINT = 'cas_ait' NNODE = (NPE-1)//40 + 1 + job='PBS' + else: + job='SLURM' + partition = config['slurm_pbs']['partition'] + if (partition != ''): + PARTITION = "#SBATCH --partition=" + partition + + CONSTRAINT = '"[cas|sky]"' + if BUILT_ON_SLES15: + CONSTRAINT = 'mil' # We need to create an input.nml file which is different if we are running stretched grid # If we are running stretched grid, we need to pass in the target lon+lat and stretch factor @@ -274,12 +277,14 @@ def remap(self): upper.close() interactive = None - if job == "SLURM": interactive = os.getenv('SLURM_JOB_ID', default = None) - if job == 'PBS': interactive = os.getenv('PBS_JOBID', default = None) + if GEOS_SITE == 'NAS': + interactive = os.getenv('PBS_JOBID', default = None) + else: + interactive = os.getenv('SLURM_JOB_ID', default = None) if (interactive) : print('interactive mode\n') - if job == 'SLURM': + if GEOS_SITE != 'NAS': ntasks = os.getenv('SLURM_NTASKS', default = None) if ( not ntasks): nnodes = int(os.getenv('SLURM_NNODES', default = '1')) @@ -292,12 +297,12 @@ def remap(self): subprocess.call(['chmod', '755', script_name]) print(script_name+ ' 1>' + log_name + ' 2>&1') os.system(script_name + ' 1>' + log_name+ ' 2>&1') - elif job == "SLURM" : - print('sbatch -W '+ script_name +'\n') - subprocess.call(['sbatch', '-W', script_name]) - else: + elif GEOS_SITE == "NAS" : print('qsub -W block=true '+ script_name +'\n') subprocess.call(['qsub', '-W','block=true', script_name]) + else: + print('sbatch -W '+ script_name +'\n') + subprocess.call(['sbatch', '-W', script_name]) # # post process diff --git a/pre/remap_restart/remap_utils.py b/pre/remap_restart/remap_utils.py index a2d2e808..c75cd58a 100755 --- a/pre/remap_restart/remap_utils.py +++ b/pre/remap_restart/remap_utils.py @@ -18,7 +18,7 @@ #During cmake step, the string will be changed according to the system BUILT_ON_SLES15 = "NO@BUILT_ON_SLES15@" -SITE = "@GEOS_SITE@" +GEOS_SITE = "@GEOS_SITE@" if BUILT_ON_SLES15== "NO": BUILT_ON_SLES15 = False From 8117072d5cf5ebb6f792ba78063959cdf8fb1b5d Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Wed, 20 Dec 2023 13:40:23 -0500 Subject: [PATCH 09/26] cmake change --- pre/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pre/CMakeLists.txt b/pre/CMakeLists.txt index 4b310bd7..6605e1ee 100644 --- a/pre/CMakeLists.txt +++ b/pre/CMakeLists.txt @@ -3,10 +3,10 @@ add_subdirectory(prepare_ocnExtData) file(GLOB pythonscripts CONFIGURE_DEPENDS ./remap_restart/remap* ./remap_restart/bin2nc_merra2* ./remap_restart/tests/*.*) +list(FILTER pythonscripts EXCLUDE REGEX "remap_utils.py") + foreach (file ${pythonscripts}) - if ( NOT ${file} MATCHES "./remap_restart/remap_utils.py") - install(PROGRAMS ${file} DESTINATION bin) - endif() + install(PROGRAMS ${file} DESTINATION bin) endforeach() set(file ./remap_restart/remap_utils.py) From 3a814e16115f6536dbd1742bb5cd9a926cacd5e1 Mon Sep 17 00:00:00 2001 From: Rolf Reichle <54944691+gmao-rreichle@users.noreply.github.com> Date: Wed, 20 Dec 2023 17:10:52 -0500 Subject: [PATCH 10/26] Updated CHANGELOG.md --- CHANGELOG.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b0d39edd..6392f4fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,9 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -1)Add EASE grid option to remapping of surface restarts in remap_restarts.py package -2)Added support for SLES15, NAS site and log for remap_lake_landice_saltwater in remap_restarts.py package - +- Added EASE grid option for remapping of land restarts in remap_restarts.py package (facilitates use of package in GEOSldas setup script) +- Added support for SLES15, NAS site and log for remap_lake_landice_saltwater in remap_restarts.py package ### Changed From 8e4a9d167ac340dfc8d73a1fe36bd90cca709b63 Mon Sep 17 00:00:00 2001 From: Rolf Reichle Date: Wed, 20 Dec 2023 18:27:51 -0500 Subject: [PATCH 11/26] unified messages for common questions in remap_restarts package (remap_catchANDcn.py, remap_questions.py, remap_utils.py) --- pre/remap_restart/remap_catchANDcn.py | 12 ++++++------ pre/remap_restart/remap_questions.py | 16 ++++++++-------- pre/remap_restart/remap_utils.py | 9 +++++++++ 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/pre/remap_restart/remap_catchANDcn.py b/pre/remap_restart/remap_catchANDcn.py index 1d8665fe..4cebc707 100755 --- a/pre/remap_restart/remap_catchANDcn.py +++ b/pre/remap_restart/remap_catchANDcn.py @@ -256,27 +256,27 @@ def ask_catch_questions(): { "type": "text", "name": "input:shared:yyyymmddhh", - "message": "Enter restart date/time: (Must be 10 digits: yyyymmddhh.)\n", + "message": (message_datetime + ".)\n"), "validate": lambda text: len(text)==10 , }, { "type": "path", "name": "output:shared:out_dir", - "message": "Enter output directory for new restarts:\n" + "message": message_out_dir, }, { "type": "text", "name": "output:shared:expid", - "message": "Enter experiment ID for new restarts: (Added as prefix to new restart file names; can leave blank.)\n", + "message": message_expid, "default": "", }, { "type": "select", "name": "output:shared:bc_base", - "message": "\nSelect BCs base directory for output restarts: \n", + "message": ("\nSelect " + message_bc_base_new), "choices": choices_bc_base, "default": get_default_bc_base(), }, @@ -298,8 +298,8 @@ def ask_catch_questions(): { "type": "select", - "name": "output:surface::EASE_grid", - "message": "Please select EASE grid for the new restart", + "name": "output:surface:EASE_grid", + "message": "Select EASE grid for new restarts", "choices": ['EASEv2_M03', 'EASEv2_M09', 'EASEv2_M25', 'EASEv2_M36'] }, ] diff --git a/pre/remap_restart/remap_questions.py b/pre/remap_restart/remap_questions.py index 762aa0ef..7e9d606c 100755 --- a/pre/remap_restart/remap_questions.py +++ b/pre/remap_restart/remap_questions.py @@ -98,21 +98,21 @@ def ask_questions(): { "type": "text", "name": "input:shared:yyyymmddhh", - "message": "Enter restart date/time: (Must be 10 digits: yyyymmddhh.)\n", + "message": (message_datetime + ".)\n"), "validate": lambda text: len(text)==10 , "when": lambda x: not x['input:shared:MERRA-2'] and not fvcore_info(x), }, { "type": "text", "name": "input:shared:yyyymmddhh", - "message": "Enter restart date: (Must be 10 digits: yyyymmddhh; hour = 03, 09, 15, or 21 [z].)\n", + "message": (message_datetime + "; hour = 03, 09, 15, or 21 [z].)\n"), "validate": lambda text: validate_merra2_time(text) , "when": lambda x: x['input:shared:MERRA-2'], }, { "type": "path", "name": "output:shared:out_dir", - "message": "Enter output directory for new restarts:\n" + "message": message_out_dir, }, # dummy (invisible) question to run function that initializes MERRA-2 config @@ -300,7 +300,7 @@ def ask_questions(): { "type": "select", "name": "input:shared:bc_base", - "message": "\nSelect BCs base directory for input restarts: \n", + "message": ("\nSelect " + message_bc_base_in), "choices": choices_bc_base, "default": get_default_bc_base(), "when": lambda x: not x.get('input:shared:bc_base'), @@ -309,7 +309,7 @@ def ask_questions(): { "type": "path", "name": "input:shared:bc_base", - "message": "\nEnter BCs base directory for input restarts: \n", + "message": ("\nEnter " + message_bc_base_in), "when": lambda x: 'Custom ' in x.get('input:shared:bc_base'), }, # dummy (invisible) question to retrieve input:shared:bc_base @@ -324,7 +324,7 @@ def ask_questions(): { "type": "select", "name": "output:shared:bc_base", - "message": "\nSelect BCs base directory for new restarts: \n", + "message": ("\nSelect " + message_bc_base_new), "choices": choices_bc_base, "default": get_default_bc_base(), }, @@ -332,7 +332,7 @@ def ask_questions(): { "type": "path", "name": "output:shared:bc_base", - "message": "\nEnter BCs base directory for new restarts: \n", + "message": ("\nEnter " + message_bc_base_new), "when": lambda x: 'Custom ' in x.get('output:shared:bc_base'), }, # dummy (invisible) question to retrieve output:shared:bc_base @@ -404,7 +404,7 @@ def ask_questions(): { "type": "text", "name": "output:shared:expid", - "message": "Enter experiment ID for new restarts: (Added as prefix to new restart file names; can leave blank.)\n", + "message": message_expid, "default": "", }, { diff --git a/pre/remap_restart/remap_utils.py b/pre/remap_restart/remap_utils.py index c75cd58a..f1b5f614 100755 --- a/pre/remap_restart/remap_utils.py +++ b/pre/remap_restart/remap_utils.py @@ -72,6 +72,15 @@ choices_res_SG002 = ['C1536'] +message_datetime = "Enter restart date/time: (Must be 10 digits: yyyymmddhh" + +message_out_dir = "Enter output directory for new restarts:\n" + +message_expid = "Enter experiment ID for new restarts: (Added as prefix to new restart file names; can leave blank.)\n" + +message_bc_base_in = "BCs base directory for input restarts: \n" +message_bc_base_new = "BCs base directory for new restarts: \n" + message_bc_ops = f'''\n BCs version | ADAS tags | GCM tags typically used with BCs version -----------------|----------------------|----------------------------------------- From e4aa27ba9d9a7b491c74dbfe3f57f065e1c99d3c Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Thu, 21 Dec 2023 13:59:09 -0500 Subject: [PATCH 12/26] questions for land --- pre/remap_restart/remap_catchANDcn.py | 60 +++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 4 deletions(-) diff --git a/pre/remap_restart/remap_catchANDcn.py b/pre/remap_restart/remap_catchANDcn.py index 4cebc707..da8ae798 100755 --- a/pre/remap_restart/remap_catchANDcn.py +++ b/pre/remap_restart/remap_catchANDcn.py @@ -246,18 +246,43 @@ def copy_merra2(self): shutil.copy(f, dest) def ask_catch_questions(): + catch_input_shared_rst_dir = '' + def has_rs_rc_out(path): + if os.path.exists(path): + dirs = os.listdir(path) + if 'rs' in dirs and 'rc_out' in dirs: + nonlocal catch_input_shared_rst_dir + catch_input_shared_rst_dir = path + return True + return False + + def has_catch_rst(text): + if len(text) !=10: return False + yyyy = text[0:4] + mm = text[4:6] + dd = text[6:8] + hh = text[8:10] + nonlocal catch_input_shared_rst_dir + rst_dir = catch_input_shared_rst_dir + '/rs/ens0000/Y'+yyyy +'/M'+mm+'/' + rst_files = glob.glob(rst_dir+'*catch*_internal_rst.'+yyyy+mm+dd+'_'+hh+'00') + if len(rst_files) !=1 : + return False + return True + questions =[ { "type": "path", "name": "input:shared:rst_dir", - "message": "Enter input directory with 'rs' and 'rc_out' as subdirectory:\n", + "message": "Enter input directory with both 'rs' and 'rc_out' subdirectories:\n", + "validate": lambda path : has_rs_rc_out(path) }, { "type": "text", "name": "input:shared:yyyymmddhh", - "message": (message_datetime + ".)\n"), - "validate": lambda text: len(text)==10 , + "message": (message_datetime + " and the rst file exists.)\n"), + #"validate": lambda x, text: has_catch_rst(x, text), + "validate": lambda text: has_catch_rst(text) }, { @@ -302,6 +327,27 @@ def ask_catch_questions(): "message": "Select EASE grid for new restarts", "choices": ['EASEv2_M03', 'EASEv2_M09', 'EASEv2_M25', 'EASEv2_M36'] }, + + { + "type": "text", + "name": "slurm_pbs:qos", + "message": "slurm or pbs quality-of-service (qos)? (If resolution is c1440 or higher, enter allnccs on NCCS or normal on NAS.) ", + "default": "debug", + }, + + { + "type": "text", + "name": "slurm_pbs:account", + "message": "slurm_pbs account?", + "default": get_account(), + }, + { + "type": "text", + "name": "slurm_pbs:partition", + "message": "Enter the slurm or pbs partition only if you want particular partiton, otherwise keep empty as default: ", + "default": '', + }, + ] answers = questionary.prompt(questions) @@ -332,5 +378,11 @@ def ask_catch_questions(): if __name__ == '__main__' : - catch = catchANDcn(params_file='remap_params.yaml') + answers = ask_catch_questions() + raw_config = get_config_from_answers(answers) + params = remap_params(raw_config) + config = params.config + config_yaml = answers['output:shared:out_dir']+'/remap_params.yaml' + config_to_yaml(config, config_yaml) + catch = catchANDcn(params_file=config_yaml) catch.remap() From 4ba8e845872a4df3e0f092b2796a05eca342d637 Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Thu, 21 Dec 2023 14:02:11 -0500 Subject: [PATCH 13/26] correct tests --- pre/remap_restart/tests/amip_c180Toc90.yaml | 2 +- pre/remap_restart/tests/c180Toc360.yaml | 2 +- pre/remap_restart/tests/c24Toc12.yaml | 2 +- pre/remap_restart/tests/c360Toc24.yaml | 2 +- pre/remap_restart/tests/f522Toc360.yaml | 2 +- pre/remap_restart/tests/test_remap_restarts.py | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pre/remap_restart/tests/amip_c180Toc90.yaml b/pre/remap_restart/tests/amip_c180Toc90.yaml index b3b7096c..60f50025 100644 --- a/pre/remap_restart/tests/amip_c180Toc90.yaml +++ b/pre/remap_restart/tests/amip_c180Toc90.yaml @@ -55,7 +55,7 @@ output: aqua: true lcv: false -slurm: +slurm_pbs: # account will be set to user's primary account automatically by test_remap_restarts.py account: qos: debug diff --git a/pre/remap_restart/tests/c180Toc360.yaml b/pre/remap_restart/tests/c180Toc360.yaml index 10b4c325..97b33565 100644 --- a/pre/remap_restart/tests/c180Toc360.yaml +++ b/pre/remap_restart/tests/c180Toc360.yaml @@ -55,7 +55,7 @@ output: aqua: true lcv: false -slurm: +slurm_pbs: # account will be set to user's primary account automatically by test_remap_restarts.py account: qos: debug diff --git a/pre/remap_restart/tests/c24Toc12.yaml b/pre/remap_restart/tests/c24Toc12.yaml index ed9ec246..0b19d805 100644 --- a/pre/remap_restart/tests/c24Toc12.yaml +++ b/pre/remap_restart/tests/c24Toc12.yaml @@ -55,7 +55,7 @@ output: aqua: true lcv: false -slurm: +slurm_pbs: # account will be set to user's primary account automatically by test_remap_restarts.py account: qos: debug diff --git a/pre/remap_restart/tests/c360Toc24.yaml b/pre/remap_restart/tests/c360Toc24.yaml index e566fc90..5085269c 100644 --- a/pre/remap_restart/tests/c360Toc24.yaml +++ b/pre/remap_restart/tests/c360Toc24.yaml @@ -55,7 +55,7 @@ output: aqua: true lcv: false -slurm: +slurm_pbs: # account will be set to user's primary account automatically by test_remap_restarts.py account: qos: debug diff --git a/pre/remap_restart/tests/f522Toc360.yaml b/pre/remap_restart/tests/f522Toc360.yaml index 4c58aaba..ff108749 100644 --- a/pre/remap_restart/tests/f522Toc360.yaml +++ b/pre/remap_restart/tests/f522Toc360.yaml @@ -51,7 +51,7 @@ output: aqua: true lcv: true -slurm: +slurm_pbs: # account will be set to user's primary account automatically by test_remap_restarts.py account: qos: debug diff --git a/pre/remap_restart/tests/test_remap_restarts.py b/pre/remap_restart/tests/test_remap_restarts.py index 0fcb0752..efff6345 100755 --- a/pre/remap_restart/tests/test_remap_restarts.py +++ b/pre/remap_restart/tests/test_remap_restarts.py @@ -84,7 +84,7 @@ def test_remap(config): out_dir = '/discover/nobackup/'+user+'/REMAP_TESTS/'+case+'/' config['output']['shared']['out_dir'] = out_dir - config['slurm']['account'] = get_account() + config['slurm_pbs']['account'] = get_account() test_remap(config) From f1b2f672b80a3de60421671b584b1f3048ed13a0 Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Fri, 22 Dec 2023 06:50:07 -0800 Subject: [PATCH 14/26] print information when test_remap_resartar is run on NAS --- pre/remap_restart/tests/amip_c180Toc90.yaml | 2 +- pre/remap_restart/tests/c180Toc360.yaml | 2 +- pre/remap_restart/tests/c24Toc12.yaml | 2 +- pre/remap_restart/tests/c360Toc24.yaml | 2 +- pre/remap_restart/tests/f522Toc360.yaml | 2 +- pre/remap_restart/tests/test_remap_restarts.py | 5 ++++- 6 files changed, 9 insertions(+), 6 deletions(-) diff --git a/pre/remap_restart/tests/amip_c180Toc90.yaml b/pre/remap_restart/tests/amip_c180Toc90.yaml index 60f50025..fbd55647 100644 --- a/pre/remap_restart/tests/amip_c180Toc90.yaml +++ b/pre/remap_restart/tests/amip_c180Toc90.yaml @@ -59,4 +59,4 @@ slurm_pbs: # account will be set to user's primary account automatically by test_remap_restarts.py account: qos: debug - partition: compute + partition: '' diff --git a/pre/remap_restart/tests/c180Toc360.yaml b/pre/remap_restart/tests/c180Toc360.yaml index 97b33565..e9e1c094 100644 --- a/pre/remap_restart/tests/c180Toc360.yaml +++ b/pre/remap_restart/tests/c180Toc360.yaml @@ -59,4 +59,4 @@ slurm_pbs: # account will be set to user's primary account automatically by test_remap_restarts.py account: qos: debug - partition: compute + partition: '' diff --git a/pre/remap_restart/tests/c24Toc12.yaml b/pre/remap_restart/tests/c24Toc12.yaml index 0b19d805..fb7d67db 100644 --- a/pre/remap_restart/tests/c24Toc12.yaml +++ b/pre/remap_restart/tests/c24Toc12.yaml @@ -59,4 +59,4 @@ slurm_pbs: # account will be set to user's primary account automatically by test_remap_restarts.py account: qos: debug - partition: compute + partition: '' diff --git a/pre/remap_restart/tests/c360Toc24.yaml b/pre/remap_restart/tests/c360Toc24.yaml index 5085269c..de7a55ab 100644 --- a/pre/remap_restart/tests/c360Toc24.yaml +++ b/pre/remap_restart/tests/c360Toc24.yaml @@ -59,4 +59,4 @@ slurm_pbs: # account will be set to user's primary account automatically by test_remap_restarts.py account: qos: debug - partition: compute + partition: '' diff --git a/pre/remap_restart/tests/f522Toc360.yaml b/pre/remap_restart/tests/f522Toc360.yaml index ff108749..2d2975f6 100644 --- a/pre/remap_restart/tests/f522Toc360.yaml +++ b/pre/remap_restart/tests/f522Toc360.yaml @@ -55,4 +55,4 @@ slurm_pbs: # account will be set to user's primary account automatically by test_remap_restarts.py account: qos: debug - partition: compute + partition: '' diff --git a/pre/remap_restart/tests/test_remap_restarts.py b/pre/remap_restart/tests/test_remap_restarts.py index efff6345..c3924343 100755 --- a/pre/remap_restart/tests/test_remap_restarts.py +++ b/pre/remap_restart/tests/test_remap_restarts.py @@ -12,7 +12,7 @@ import glob import subprocess as sp import remap_restarts -import remap_utils +from remap_utils import * from remap_params import * from remap_upper import * from remap_lake_landice_saltwater import * @@ -59,6 +59,9 @@ def test_remap(config): if __name__ == '__main__' : + if GEOS_SITE == "NAS" : + print("It should be run on NCCS/discoer") + exit() yaml = ruamel.yaml.YAML() stream ='' cases_yaml = 'test_remap_cases.yaml' From 917e72c9bdfaf51a3604201963d85085c0ccddff Mon Sep 17 00:00:00 2001 From: Rolf Reichle <54944691+gmao-rreichle@users.noreply.github.com> Date: Fri, 22 Dec 2023 10:09:15 -0500 Subject: [PATCH 15/26] minimal edit of exit message (test_remap_restarts.py) --- pre/remap_restart/tests/test_remap_restarts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pre/remap_restart/tests/test_remap_restarts.py b/pre/remap_restart/tests/test_remap_restarts.py index c3924343..f1e738a9 100755 --- a/pre/remap_restart/tests/test_remap_restarts.py +++ b/pre/remap_restart/tests/test_remap_restarts.py @@ -60,7 +60,7 @@ def test_remap(config): if __name__ == '__main__' : if GEOS_SITE == "NAS" : - print("It should be run on NCCS/discoer") + print("Test baseline data are not available at NAS. Please run tests on NCCS/Discover.") exit() yaml = ruamel.yaml.YAML() stream ='' From 2d5bbc58b2468ff704f1ce7667ea36f4258e3969 Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Fri, 22 Dec 2023 11:37:21 -0500 Subject: [PATCH 16/26] first step to run remap_catch --- pre/remap_restart/remap_catchANDcn.py | 15 +++++---- pre/remap_restart/remap_params.py | 32 +++++++++---------- pre/remap_restart/remap_utils.py | 44 ++++++++++++++++----------- 3 files changed, 51 insertions(+), 40 deletions(-) diff --git a/pre/remap_restart/remap_catchANDcn.py b/pre/remap_restart/remap_catchANDcn.py index da8ae798..98dd43ee 100755 --- a/pre/remap_restart/remap_catchANDcn.py +++ b/pre/remap_restart/remap_catchANDcn.py @@ -371,18 +371,21 @@ def has_catch_rst(text): answers['input:shared:rst_dir'] = rst_dir answers['input:surface:catch_model'] = catch_model - answers['input:surface:wemin'] = 13 - answers['output:surface:wemin'] = 13 + answers['input:surface:wemin'] = "13" + answers['output:surface:wemin'] = "13" + answers['output:surface:remap_catch'] = True + bc_base= answers['output:shared:bc_base'].split(": ")[-1] + answers['output:shared:bc_base'] = bc_base + answers['output:shared:out_dir'] = os.path.abspath(answers['output:shared:out_dir']) return answers if __name__ == '__main__' : answers = ask_catch_questions() - raw_config = get_config_from_answers(answers) - params = remap_params(raw_config) - config = params.config - config_yaml = answers['output:shared:out_dir']+'/remap_params.yaml' + config = get_config_from_answers(answers, config_tpl = True) + print_config(config) + config_yaml = config['output']['shared']['out_dir']+'/remap_params.yaml' config_to_yaml(config, config_yaml) catch = catchANDcn(params_file=config_yaml) catch.remap() diff --git a/pre/remap_restart/remap_params.py b/pre/remap_restart/remap_params.py index ff336505..26dda003 100755 --- a/pre/remap_restart/remap_params.py +++ b/pre/remap_restart/remap_params.py @@ -38,12 +38,12 @@ def __init__(self, config_from_question): config_tpl['input']['shared']['agrid'] = self.common_in.get('agrid') config_tpl['input']['shared']['ogrid'] = self.common_in.get('ogrid') config_tpl['input']['shared']['omodel'] = self.common_in.get('omodel') - config_tpl['input']['shared']['rst_dir'] = self.common_in['rst_dir']+'/' + config_tpl['input']['shared']['rst_dir'] = self.common_in.get('rst_dir')+'/' config_tpl['input']['shared']['expid'] = self.common_in.get('expid') - config_tpl['input']['shared']['yyyymmddhh'] = self.common_in['yyyymmddhh'] + config_tpl['input']['shared']['yyyymmddhh'] = self.common_in.get('yyyymmddhh') config_tpl['input']['shared']['bc_version'] = self.common_in.get('bc_version') config_tpl['input']['shared']['stretch'] = self.common_in.get('stretch') - config_tpl['input']['shared']['bc_base'] = self.common_in['bc_base'] + config_tpl['input']['shared']['bc_base'] = self.common_in.get('bc_base') config_tpl['input']['surface']['catch_model'] = self.surf_in.get('catch_model') config_tpl['output']['air']['nlevel'] = self.upper_out.get('nlevel') @@ -51,15 +51,15 @@ def __init__(self, config_from_question): config_tpl['output']['air']['remap'] = self.upper_out.get('remap') config_tpl['output']['surface']['remap_water'] = self.surf_out.get('remap') config_tpl['output']['surface']['remap_catch'] = self.surf_out.get('remap') - config_tpl['output']['shared']['agrid'] = self.common_out['agrid'] - config_tpl['output']['shared']['ogrid'] = self.common_out['ogrid'] - config_tpl['output']['shared']['omodel'] = self.common_out['omodel'] - config_tpl['output']['shared']['out_dir'] = self.common_out['out_dir'] + '/' - config_tpl['output']['shared']['expid'] = self.common_out['expid'] + config_tpl['output']['shared']['agrid'] = self.common_out.get('agrid') + config_tpl['output']['shared']['ogrid'] = self.common_out.get('ogrid') + config_tpl['output']['shared']['omodel'] = self.common_out.get('omodel') + config_tpl['output']['shared']['out_dir'] = self.common_out.get('out_dir') + '/' + config_tpl['output']['shared']['expid'] = self.common_out.get('expid') config_tpl['output']['shared']['bc_version'] = self.common_out.get('bc_version') config_tpl['output']['shared']['label'] = self.common_out.get('label') config_tpl['output']['shared']['stretch'] = self.common_out.get('stretch') - config_tpl['output']['shared']['bc_base'] = self.common_out['bc_base'] + config_tpl['output']['shared']['bc_base'] = self.common_out.get('bc_base') # params for upper air config_tpl = self.params_for_air(config_tpl) @@ -70,9 +70,9 @@ def __init__(self, config_from_question): self.config = config_tpl def params_for_air(self, config_tpl): - if self.common_in['MERRA-2']: + if self.common_in.get('MERRA-2'): return config_tpl - if ( not config_tpl['input']['air']['drymass']) : + if ( not config_tpl['input']['air'].get('drymass') ) : config_tpl['input']['air']['drymass'] = 1 return config_tpl @@ -85,14 +85,14 @@ def options_for_slurm_pbs(self, config_tpl): def params_for_surface(self, config_tpl): config_tpl['output']['surface']['surflay'] = 50. - bc_version = self.common_out['bc_version'] - ogrid = self.common_out['ogrid'] + bc_version = self.common_out.get('bc_version') + ogrid = self.common_out.get('ogrid') config_tpl['output']['surface']['split_saltwater'] = True if 'Ganymed' in bc_version : config_tpl['output']['surface']['split_saltwater'] = False - config_tpl['input']['surface']['zoom'] = self.surf_in['zoom'] - config_tpl['input']['surface']['wemin'] = self.surf_in['wemin'] - config_tpl['output']['surface']['wemin'] = self.surf_out['wemin'] + config_tpl['input']['surface']['zoom'] = self.surf_in.get('zoom') + config_tpl['input']['surface']['wemin'] = self.surf_in.get('wemin') + config_tpl['output']['surface']['wemin'] = self.surf_out.get('wemin') config_tpl['input']['surface']['catch_model'] = self.surf_in.get('catch_model') return config_tpl diff --git a/pre/remap_restart/remap_utils.py b/pre/remap_restart/remap_utils.py index f1b5f614..a5d6e90b 100755 --- a/pre/remap_restart/remap_utils.py +++ b/pre/remap_restart/remap_utils.py @@ -241,13 +241,9 @@ def catch_model(x): files = glob.glob(rst_dir+'/*catch*') if len (files) == 0 : return False - fname= '' - if len(files) == 1: - fname = os.path.basename(files[0]) + fname = '' + fname = os.path.basename(files[0]) - if len(files) > 1 : - files = glob.glob(rst_dir+'/*fvcore_*'+time+'*') - fname = os.path.basename(files[0]) model = 'catch' if 'cnclm40' in fname.lower(): model = 'catchcnclm40' @@ -336,6 +332,8 @@ def config_to_yaml(config, yaml_file, noprompt = False): shutil.move(yaml_file, new_name) break yaml = ruamel.yaml.YAML() + out_dir = os.path.dirname(yaml_file) + if not os.path.exists(out_dir) : os.mkdir(out_dir) with open(yaml_file, "w") as f: yaml.dump(config, f) @@ -478,25 +476,35 @@ def get_command_line_from_answers(answers): return cmdl -def get_config_from_answers(answers): +def get_config_from_answers(answers, config_tpl = False): + config = {} - config['input'] = {} - config['input']['air'] = {} - config['input']['shared'] = {} - config['input']['surface'] = {} - config['output'] = {} - config['output']['shared'] = {} - config['output']['air'] = {} - config['output']['surface'] = {} - config['output']['analysis'] = {} - config['slurm_pbs'] = {} + if config_tpl: + # load input yaml + yaml = ruamel.yaml.YAML() + stream = '' + remap_tpl = os.path.dirname(os.path.realpath(__file__)) + '/remap_params.tpl' + with open(remap_tpl, 'r') as f: + stream = f.read() + config = yaml.load(stream) + else: + config['input'] = {} + config['input']['air'] = {} + config['input']['shared'] = {} + config['input']['surface'] = {} + config['output'] = {} + config['output']['shared'] = {} + config['output']['air'] = {} + config['output']['surface'] = {} + config['output']['analysis'] = {} + config['slurm_pbs'] = {} + for key, value in answers.items(): keys = key.split(":") if len(keys) == 2: config[keys[0]][keys[1]] = value if len(keys) == 3: config[keys[0]][keys[1]][keys[2]] = value - return config def get_resolutions(agrid=None, ogrid=None, omodel=None, stretch=None, grid=None): From 8de3c13e1c60da60701e91656a1a22e88850c177 Mon Sep 17 00:00:00 2001 From: biljanaorescanin Date: Wed, 27 Dec 2023 09:47:04 -0500 Subject: [PATCH 17/26] change exit logic --- pre/remap_restart/tests/test_remap_restarts.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pre/remap_restart/tests/test_remap_restarts.py b/pre/remap_restart/tests/test_remap_restarts.py index f1e738a9..77c89b88 100755 --- a/pre/remap_restart/tests/test_remap_restarts.py +++ b/pre/remap_restart/tests/test_remap_restarts.py @@ -59,8 +59,8 @@ def test_remap(config): if __name__ == '__main__' : - if GEOS_SITE == "NAS" : - print("Test baseline data are not available at NAS. Please run tests on NCCS/Discover.") + if GEOS_SITE != "NCCS" : + print("Test baseline data are only available at NCCS. Please run tests on Discover.") exit() yaml = ruamel.yaml.YAML() stream ='' From a5e99147718d62947e4a25756cf0e2ddadab6833 Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Wed, 3 Jan 2024 11:36:45 -0500 Subject: [PATCH 18/26] more refactoring on 'remap' and 'params' --- pre/remap_restart/remap_command_line.py | 13 ++-- pre/remap_restart/remap_params.py | 93 +++---------------------- pre/remap_restart/remap_params.tpl | 2 +- pre/remap_restart/remap_questions.py | 3 + pre/remap_restart/remap_restarts.py | 3 +- pre/remap_restart/remap_utils.py | 15 +++- 6 files changed, 38 insertions(+), 91 deletions(-) diff --git a/pre/remap_restart/remap_command_line.py b/pre/remap_restart/remap_command_line.py index 489eebf2..1d848d78 100755 --- a/pre/remap_restart/remap_command_line.py +++ b/pre/remap_restart/remap_command_line.py @@ -121,12 +121,17 @@ def get_answers_from_command_line(cml): answers["output:analysis:bkg"] = not cml.nobkg answers["output:analysis:lcv"] = not cml.nolcv if cml.rs == '1': - answers["output:air:remap"] = True + answers["output:air:remap"] = True + answers["output:surface:remap_water"] = False + answers["output:surface:remap_catch"] = False if cml.rs == '2': - answers["output:surface:remap"] = True + answers["output:air:remap"] = False + answers["output:surface:remap_water"] = True + answers["output:surface:remap_catch"] = True if cml.rs == '3': - answers["output:surface:remap"] = True - answers["output:air:remap"] = True + answers["output:air:remap"] = True + answers["output:surface:remap_water"] = True + answers["output:surface:remap_catch"] = True answers["output:air:agcm_import_rst"] = not cml.noagcm_import_rst diff --git a/pre/remap_restart/remap_params.py b/pre/remap_restart/remap_params.py index 26dda003..95d9c650 100755 --- a/pre/remap_restart/remap_params.py +++ b/pre/remap_restart/remap_params.py @@ -16,92 +16,18 @@ from remap_utils import * class remap_params(object): - def __init__(self, config_from_question): - self.common_in = config_from_question['input']['shared'] - self.common_out = config_from_question['output']['shared'] - self.upper_out = config_from_question['output']['air'] - self.slurm_pbs_options = config_from_question['slurm_pbs'] - self.surf_in = config_from_question['input']['surface'] - self.surf_out = config_from_question['output']['surface'] - self.ana_out = config_from_question['output']['analysis'] + def __init__(self, config = None, answers = None): - # load input yaml - yaml = ruamel.yaml.YAML() - stream = '' - remap_tpl = os.path.dirname(os.path.realpath(__file__)) + '/remap_params.tpl' - with open(remap_tpl, 'r') as f: - stream = f.read() - config_tpl = yaml.load(stream) + # load template and fill in answers + if answers : + config_tpl = get_config_from_answer(answers, config_tpl = True) - # params for shared - config_tpl['input']['shared']['MERRA-2'] = self.common_in.get('MERRA-2') - config_tpl['input']['shared']['agrid'] = self.common_in.get('agrid') - config_tpl['input']['shared']['ogrid'] = self.common_in.get('ogrid') - config_tpl['input']['shared']['omodel'] = self.common_in.get('omodel') - config_tpl['input']['shared']['rst_dir'] = self.common_in.get('rst_dir')+'/' - config_tpl['input']['shared']['expid'] = self.common_in.get('expid') - config_tpl['input']['shared']['yyyymmddhh'] = self.common_in.get('yyyymmddhh') - config_tpl['input']['shared']['bc_version'] = self.common_in.get('bc_version') - config_tpl['input']['shared']['stretch'] = self.common_in.get('stretch') - config_tpl['input']['shared']['bc_base'] = self.common_in.get('bc_base') - config_tpl['input']['surface']['catch_model'] = self.surf_in.get('catch_model') - - config_tpl['output']['air']['nlevel'] = self.upper_out.get('nlevel') - config_tpl['output']['air']['agcm_import_rst'] = self.upper_out.get('agcm_import_rst') - config_tpl['output']['air']['remap'] = self.upper_out.get('remap') - config_tpl['output']['surface']['remap_water'] = self.surf_out.get('remap') - config_tpl['output']['surface']['remap_catch'] = self.surf_out.get('remap') - config_tpl['output']['shared']['agrid'] = self.common_out.get('agrid') - config_tpl['output']['shared']['ogrid'] = self.common_out.get('ogrid') - config_tpl['output']['shared']['omodel'] = self.common_out.get('omodel') - config_tpl['output']['shared']['out_dir'] = self.common_out.get('out_dir') + '/' - config_tpl['output']['shared']['expid'] = self.common_out.get('expid') - config_tpl['output']['shared']['bc_version'] = self.common_out.get('bc_version') - config_tpl['output']['shared']['label'] = self.common_out.get('label') - config_tpl['output']['shared']['stretch'] = self.common_out.get('stretch') - config_tpl['output']['shared']['bc_base'] = self.common_out.get('bc_base') - - # params for upper air - config_tpl = self.params_for_air(config_tpl) - config_tpl = self.params_for_surface(config_tpl) - config_tpl = self.params_for_analysis(config_tpl) - config_tpl = self.options_for_slurm_pbs(config_tpl) - - self.config = config_tpl - - def params_for_air(self, config_tpl): - if self.common_in.get('MERRA-2'): - return config_tpl - if ( not config_tpl['input']['air'].get('drymass') ) : - config_tpl['input']['air']['drymass'] = 1 - - return config_tpl - - def options_for_slurm_pbs(self, config_tpl): - config_tpl['slurm_pbs']['account'] = self.slurm_pbs_options['account'] - config_tpl['slurm_pbs']['qos'] = self.slurm_pbs_options['qos'] - config_tpl['slurm_pbs']['partition'] = self.slurm_pbs_options['partition'] - return config_tpl - - def params_for_surface(self, config_tpl): - config_tpl['output']['surface']['surflay'] = 50. - bc_version = self.common_out.get('bc_version') - ogrid = self.common_out.get('ogrid') - config_tpl['output']['surface']['split_saltwater'] = True - if 'Ganymed' in bc_version : + bc_version = config_tpl['output']['shared'].get('bc_version') + config_tpl['output']['surface']['split_saltwater'] = True + if 'Ganymed' in bc_version : config_tpl['output']['surface']['split_saltwater'] = False - config_tpl['input']['surface']['zoom'] = self.surf_in.get('zoom') - config_tpl['input']['surface']['wemin'] = self.surf_in.get('wemin') - config_tpl['output']['surface']['wemin'] = self.surf_out.get('wemin') - config_tpl['input']['surface']['catch_model'] = self.surf_in.get('catch_model') - return config_tpl - def params_for_analysis(self, config_tpl): - config_tpl['output']['analysis']['lcv'] = self.ana_out.get('lcv') - config_tpl['output']['analysis']['bkg'] = self.ana_out.get('bkg') - config_tpl['output']['analysis']['aqua'] = True - - return config_tpl + self.config = config_tpl if __name__ == "__main__": yaml = ruamel.yaml.YAML() @@ -109,5 +35,6 @@ def params_for_analysis(self, config_tpl): with open("raw_answers.yaml", "r") as f: stream = f.read() config = yaml.load(stream) - param = remap_params(config) + answers = flatten_nested(config) + param = remap_params(answers, config_tpl = True) config_to_yaml(param.config, 'remap_params.yaml') diff --git a/pre/remap_restart/remap_params.tpl b/pre/remap_restart/remap_params.tpl index 1df2b7f9..1e7f6552 100644 --- a/pre/remap_restart/remap_params.tpl +++ b/pre/remap_restart/remap_params.tpl @@ -58,7 +58,7 @@ output: EASE_grid: null analysis: bkg: true - aqua: False + aqua: true lcv: false slurm_pbs: account: diff --git a/pre/remap_restart/remap_questions.py b/pre/remap_restart/remap_questions.py index 7e9d606c..1659e8a3 100755 --- a/pre/remap_restart/remap_questions.py +++ b/pre/remap_restart/remap_questions.py @@ -441,6 +441,9 @@ def ask_questions(): if answers.get('input:air:nlevel') : del answers['input:air:nlevel'] if answers["output:surface:remap"] and not answers["input:shared:MERRA-2"]: answers["input:surface:catch_model"] = catch_model(answers) + answers["output:surface:remap_water"] = answers["output:surface:remap"] + answers["output:surface:remap_catch"] = answers["output:surface:remap"] + del answers["output:surface:remap"] return answers diff --git a/pre/remap_restart/remap_restarts.py b/pre/remap_restart/remap_restarts.py index 4f1124c0..0d5356f8 100755 --- a/pre/remap_restart/remap_restarts.py +++ b/pre/remap_restart/remap_restarts.py @@ -74,9 +74,10 @@ def main(): cmd = get_command_line_from_answers(answers) write_cmd(answers['output:shared:out_dir'], cmd) # just for debugging + # raw_config = get_config_from_answers(answers) # with open("raw_answers.yaml", "w") as f: # yaml.dump(raw_config, f) - params = remap_params(raw_config) + params = remap_params(answers) config = params.config config_yaml = answers['output:shared:out_dir']+'/remap_params.yaml' diff --git a/pre/remap_restart/remap_utils.py b/pre/remap_restart/remap_utils.py index a5d6e90b..61eae08d 100755 --- a/pre/remap_restart/remap_utils.py +++ b/pre/remap_restart/remap_utils.py @@ -429,9 +429,9 @@ def get_command_line_from_answers(answers): out_rs = " -rs " rs = 3 - if answers['output:air:remap'] and not answers['output:surface:remap']: + if answers['output:air:remap'] and not answers['output:surface:remap_catch']: rs = 1 - if answers['output:surface:remap'] and not answers['output:air:remap']: + if answers['output:surface:remap_catch'] and not answers['output:air:remap']: rs = 2 out_rs = out_rs + str(rs) @@ -476,6 +476,17 @@ def get_command_line_from_answers(answers): return cmdl +def flatten_nested(nested_dict, result=None, prefix=''): + if result is None: + result = dict() + for k, v in nested_dict.items(): + new_k = ':'.join((prefix, k)) if prefix else k + if not (isinstance(v, dict) or isinstance(v, OrderedDict)): + result.update({new_k: v}) + else: + flatten_nested(v, result, new_k) + return result + def get_config_from_answers(answers, config_tpl = False): config = {} From 47b707c968a70b15921968592eb21956356b99da Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Fri, 5 Jan 2024 10:31:05 -0500 Subject: [PATCH 19/26] add "land_only" and remove remap_params.py --- pre/remap_restart/remap_base.py | 7 ++--- pre/remap_restart/remap_catchANDcn.py | 8 +++-- pre/remap_restart/remap_command_line.py | 10 +++++-- pre/remap_restart/remap_params.py | 40 ------------------------- pre/remap_restart/remap_restarts.py | 13 +++++--- pre/remap_restart/remap_utils.py | 22 +++++++++----- 6 files changed, 38 insertions(+), 62 deletions(-) delete mode 100755 pre/remap_restart/remap_params.py diff --git a/pre/remap_restart/remap_base.py b/pre/remap_restart/remap_base.py index 990456bc..f9ee8814 100755 --- a/pre/remap_restart/remap_base.py +++ b/pre/remap_restart/remap_base.py @@ -7,17 +7,14 @@ import ruamel.yaml import shutil import subprocess +from remap_utils import * class remap_base(object): def __init__(self, **configs): for key, value in configs.items(): if (key == 'params_file'): print( "use Config yaml file: " + value) - yaml = ruamel.yaml.YAML() - stream ='' - with open(value, 'r') as f: - stream = f.read() - self.config = yaml.load(stream) + self.config = get_config_from_file(value) out_dir = self.config['output']['shared']['out_dir'] if not os.path.exists(out_dir) : os.makedirs(out_dir) f = os.path.basename(value) diff --git a/pre/remap_restart/remap_catchANDcn.py b/pre/remap_restart/remap_catchANDcn.py index 98dd43ee..ec24ce4f 100755 --- a/pre/remap_restart/remap_catchANDcn.py +++ b/pre/remap_restart/remap_catchANDcn.py @@ -18,7 +18,6 @@ import mimetypes import netCDF4 as nc from remap_base import remap_base -from remap_params import * from remap_utils import * class catchANDcn(remap_base): @@ -380,8 +379,7 @@ def has_catch_rst(text): return answers -if __name__ == '__main__' : - +def remap_land_only(): answers = ask_catch_questions() config = get_config_from_answers(answers, config_tpl = True) print_config(config) @@ -389,3 +387,7 @@ def has_catch_rst(text): config_to_yaml(config, config_yaml) catch = catchANDcn(params_file=config_yaml) catch.remap() + +if __name__ == '__main__' : + + remap_land_only() diff --git a/pre/remap_restart/remap_command_line.py b/pre/remap_restart/remap_command_line.py index 1d848d78..79cc1012 100755 --- a/pre/remap_restart/remap_command_line.py +++ b/pre/remap_restart/remap_command_line.py @@ -13,7 +13,6 @@ import glob import argparse from remap_utils import * -from remap_params import * def parse_args(program_description): @@ -30,6 +29,11 @@ def parse_args(program_description): p_config.add_argument('-c', '--config_file', help='YAML config file') + p_landonly = p_sub.add_parser( + 'land_only', + help = "remap catchxxx only", + ) + p_command = p_sub.add_parser( 'command_line', help = "Use command line as input", @@ -167,7 +171,7 @@ def get_answers_from_command_line(cml): with open("raw_command.yaml", "w") as f: yaml.dump(config, f) - params = remap_params(config) + config = get_config_from_answers(answers, config_tpl= True) with open("params_from_command.yaml", "w") as f: - yaml.dump(params.config, f) + yaml.dump(config, f) diff --git a/pre/remap_restart/remap_params.py b/pre/remap_restart/remap_params.py deleted file mode 100755 index 95d9c650..00000000 --- a/pre/remap_restart/remap_params.py +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env python3 -# -# remap_restarts package: -# remap_params.py uses the dictionary `answers` (from remap_questions.py) as inputs and -# generates a yaml config file named `remap_params.yaml`. -# -import os,sys -import ruamel.yaml -import shutil -import glob -import time -import shlex -import subprocess -from datetime import datetime -from datetime import timedelta -from remap_utils import * - -class remap_params(object): - def __init__(self, config = None, answers = None): - - # load template and fill in answers - if answers : - config_tpl = get_config_from_answer(answers, config_tpl = True) - - bc_version = config_tpl['output']['shared'].get('bc_version') - config_tpl['output']['surface']['split_saltwater'] = True - if 'Ganymed' in bc_version : - config_tpl['output']['surface']['split_saltwater'] = False - - self.config = config_tpl - -if __name__ == "__main__": - yaml = ruamel.yaml.YAML() - stream ='' - with open("raw_answers.yaml", "r") as f: - stream = f.read() - config = yaml.load(stream) - answers = flatten_nested(config) - param = remap_params(answers, config_tpl = True) - config_to_yaml(param.config, 'remap_params.yaml') diff --git a/pre/remap_restart/remap_restarts.py b/pre/remap_restart/remap_restarts.py index 0d5356f8..0ebb1bd2 100755 --- a/pre/remap_restart/remap_restarts.py +++ b/pre/remap_restart/remap_restarts.py @@ -17,7 +17,6 @@ from remap_utils import * from remap_questions import * from remap_command_line import * -from remap_params import * from remap_upper import * from remap_lake_landice_saltwater import * from remap_analysis import * @@ -42,6 +41,11 @@ 3. Use command line arguments: ./remap_restarts.py command_line -ymdh 2004041421 .... + 3. Remap land (catchxxx) only: + ./remap_restarts.py land_only + + Help commands: + Help commands: ./remap_restarts.py -h ./remap_restarts.py config_file -h @@ -66,19 +70,20 @@ def main(): if sys.argv[1] == 'command_line': answers = get_answers_from_command_line(cmdl) noprompt = cmdl.np + if sys.argv[1] == 'land_only': + remap_land_only() + sys.exit(0) if (len(sys.argv) == 1 or answers) : if not answers: answers = ask_questions() question_flag = True - raw_config = get_config_from_answers(answers) cmd = get_command_line_from_answers(answers) write_cmd(answers['output:shared:out_dir'], cmd) # just for debugging # raw_config = get_config_from_answers(answers) # with open("raw_answers.yaml", "w") as f: # yaml.dump(raw_config, f) - params = remap_params(answers) - config = params.config + config = get_config_from_answers(answers, config_tpl = True) config_yaml = answers['output:shared:out_dir']+'/remap_params.yaml' print('\n') diff --git a/pre/remap_restart/remap_utils.py b/pre/remap_restart/remap_utils.py index 61eae08d..c62cfc3c 100755 --- a/pre/remap_restart/remap_utils.py +++ b/pre/remap_restart/remap_utils.py @@ -487,17 +487,19 @@ def flatten_nested(nested_dict, result=None, prefix=''): flatten_nested(v, result, new_k) return result -def get_config_from_answers(answers, config_tpl = False): +def get_config_from_file(file): + yaml = ruamel.yaml.YAML() + stream = '' + with open(file, 'r') as f: + stream = f.read() + config = yaml.load(stream) + return config +def get_config_from_answers(answers, config_tpl = False): config = {} if config_tpl: - # load input yaml - yaml = ruamel.yaml.YAML() - stream = '' remap_tpl = os.path.dirname(os.path.realpath(__file__)) + '/remap_params.tpl' - with open(remap_tpl, 'r') as f: - stream = f.read() - config = yaml.load(stream) + config = get_config_from_file(remap_tpl) else: config['input'] = {} config['input']['air'] = {} @@ -516,6 +518,12 @@ def get_config_from_answers(answers, config_tpl = False): config[keys[0]][keys[1]] = value if len(keys) == 3: config[keys[0]][keys[1]][keys[2]] = value + + bc_version = config['output']['shared'].get('bc_version') + config['output']['surface']['split_saltwater'] = True + if 'Ganymed' in bc_version : + config['output']['surface']['split_saltwater'] = False + return config def get_resolutions(agrid=None, ogrid=None, omodel=None, stretch=None, grid=None): From 0daef391079900b2b4c213191d7cdaf387e3a5ac Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Fri, 5 Jan 2024 12:37:44 -0500 Subject: [PATCH 20/26] remove deleted mod --- pre/remap_restart/tests/test_remap_restarts.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pre/remap_restart/tests/test_remap_restarts.py b/pre/remap_restart/tests/test_remap_restarts.py index 77c89b88..6d64a746 100755 --- a/pre/remap_restart/tests/test_remap_restarts.py +++ b/pre/remap_restart/tests/test_remap_restarts.py @@ -13,7 +13,6 @@ import subprocess as sp import remap_restarts from remap_utils import * -from remap_params import * from remap_upper import * from remap_lake_landice_saltwater import * from remap_analysis import * From 1bd5dc1da8f13ff730fa56c63cd8f6d07f6a492d Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Mon, 8 Jan 2024 12:20:21 -0500 Subject: [PATCH 21/26] add questions to remap to CS grid for land_only option --- pre/remap_restart/remap_catchANDcn.py | 51 +++++++++++++++++++++++++-- pre/remap_restart/remap_questions.py | 20 ----------- pre/remap_restart/remap_utils.py | 20 +++++++++++ 3 files changed, 68 insertions(+), 23 deletions(-) diff --git a/pre/remap_restart/remap_catchANDcn.py b/pre/remap_restart/remap_catchANDcn.py index ec24ce4f..d9b15ac9 100755 --- a/pre/remap_restart/remap_catchANDcn.py +++ b/pre/remap_restart/remap_catchANDcn.py @@ -324,9 +324,37 @@ def has_catch_rst(text): "type": "select", "name": "output:surface:EASE_grid", "message": "Select EASE grid for new restarts", - "choices": ['EASEv2_M03', 'EASEv2_M09', 'EASEv2_M25', 'EASEv2_M36'] + "choices": ['EASEv2_M03', 'EASEv2_M09', 'EASEv2_M25', 'EASEv2_M36', 'Cubed-Sphere'] }, + { + "type": "text", + "name": "output:shared:agrid", + "message": message_agrid_new, + "default": 'C360', + "validate": lambda text : text in validate_agrid, + "when": lambda x : x['output:surface:EASE_grid'] == 'Cubed-Sphere', + }, + + { + "type": "select", + "name": "output:shared:ogrid", + "message": "Select data ocean grid/resolution for new restarts:\n", + "choices": choices_ogrid_data, + "default": lambda x: data_ocean_default(x.get('output:shared:agrid')), + "when": lambda x : x['output:surface:EASE_grid'] == 'Cubed-Sphere', + }, + + # dummy (invisible) question to remove parenthetical comments from selected output:shared:ogrid + { + "type": "text", + "name": "output:shared:ogrid", + "message": "remove the comment of ogrid", + # always return false, so questions never shows but changes ogrid + "when": lambda x: remove_ogrid_comment(x, 'OUT') + }, + + { "type": "text", "name": "slurm_pbs:qos", @@ -377,14 +405,31 @@ def has_catch_rst(text): answers['output:shared:bc_base'] = bc_base answers['output:shared:out_dir'] = os.path.abspath(answers['output:shared:out_dir']) + if answers['output:surface:EASE_grid'] == 'Cubed-Sphere' : + remove_ogrid_comment(answers, 'OUT') + del answers['output:surface:EASE_grid'] return answers def remap_land_only(): answers = ask_catch_questions() config = get_config_from_answers(answers, config_tpl = True) - print_config(config) config_yaml = config['output']['shared']['out_dir']+'/remap_params.yaml' - config_to_yaml(config, config_yaml) + config_to_yaml(config, config_yaml) + print_config(config) + + question = [ + { + "type": "confirm", + "name": "Continue", + "message": "Above is the YAML config file, would you like to continue?", + "default": True + },] + answer = questionary.prompt(question) + + if not answer['Continue'] : + print("\nYou answered not to continue, exiting.\n") + sys.exit(0) + catch = catchANDcn(params_file=config_yaml) catch.remap() diff --git a/pre/remap_restart/remap_questions.py b/pre/remap_restart/remap_questions.py index 1659e8a3..7b88cfd4 100755 --- a/pre/remap_restart/remap_questions.py +++ b/pre/remap_restart/remap_questions.py @@ -14,26 +14,6 @@ import glob from remap_utils import * -def remove_ogrid_comment(x, opt): - ogrid = '' - if opt == "IN": - ogrid = x.get('input:shared:ogrid') - else: - ogrid = x.get('output:shared:ogrid') - if not ogrid: return False - - ogrid = ogrid.split()[0] - if opt == "IN": - if ogrid == 'CS': - ogrid = x['input:shared:agrid'] - x['input:shared:ogrid'] = ogrid - else: - if ogrid == 'CS': - ogrid = x['output:shared:agrid'] - x['output:shared:ogrid'] = ogrid - - return False - def echo_level(x): if x["output:air:nlevel"] != str(x.get("input:air:nlevel")) : print("NOTE: Different # atm levels in input and new restarts. Cannot remap agcm_import_rst (a.k.a. IAU) file.") diff --git a/pre/remap_restart/remap_utils.py b/pre/remap_restart/remap_utils.py index c62cfc3c..7cd43bab 100755 --- a/pre/remap_restart/remap_utils.py +++ b/pre/remap_restart/remap_utils.py @@ -586,6 +586,26 @@ def get_geomdir(bc_base, bc_version, agrid=None, ogrid=None, omodel=None, stretc bc_geom = get_landdir(bc_base, bc_version, agrid=agrid, ogrid=ogrid, omodel=omodel, stretch=stretch, grid=grid). replace('/land/', '/geometry/') return bc_geom +def remove_ogrid_comment(x, opt): + ogrid = '' + if opt == "IN": + ogrid = x.get('input:shared:ogrid') + else: + ogrid = x.get('output:shared:ogrid') + if not ogrid: return False + + ogrid = ogrid.split()[0] + if opt == "IN": + if ogrid == 'CS': + ogrid = x['input:shared:agrid'] + x['input:shared:ogrid'] = ogrid + else: + if ogrid == 'CS': + ogrid = x['output:shared:agrid'] + x['output:shared:ogrid'] = ogrid + + return False + if __name__ == '__main__' : config = yaml_to_config('c24Toc12.yaml') print_config(config) From caab8bce2d7a69b1f8455cd4f983e078499a8d54 Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Wed, 10 Jan 2024 11:16:04 -0500 Subject: [PATCH 22/26] minor changes on message --- pre/remap_restart/remap_catchANDcn.py | 3 ++- pre/remap_restart/remap_command_line.py | 2 +- pre/remap_restart/remap_restarts.py | 4 +--- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/pre/remap_restart/remap_catchANDcn.py b/pre/remap_restart/remap_catchANDcn.py index d9b15ac9..1f983341 100755 --- a/pre/remap_restart/remap_catchANDcn.py +++ b/pre/remap_restart/remap_catchANDcn.py @@ -323,7 +323,7 @@ def has_catch_rst(text): { "type": "select", "name": "output:surface:EASE_grid", - "message": "Select EASE grid for new restarts", + "message": "Select a grid for new restarts", "choices": ['EASEv2_M03', 'EASEv2_M09', 'EASEv2_M25', 'EASEv2_M36', 'Cubed-Sphere'] }, @@ -411,6 +411,7 @@ def has_catch_rst(text): return answers def remap_land_only(): + print("\n It remaps catcment(cn) restarts with GLOBAL domain only. \n") answers = ask_catch_questions() config = get_config_from_answers(answers, config_tpl = True) config_yaml = config['output']['shared']['out_dir']+'/remap_params.yaml' diff --git a/pre/remap_restart/remap_command_line.py b/pre/remap_restart/remap_command_line.py index 79cc1012..3a466bf3 100755 --- a/pre/remap_restart/remap_command_line.py +++ b/pre/remap_restart/remap_command_line.py @@ -31,7 +31,7 @@ def parse_args(program_description): p_landonly = p_sub.add_parser( 'land_only', - help = "remap catchxxx only", + help = "remap catchxxx global domain only", ) p_command = p_sub.add_parser( diff --git a/pre/remap_restart/remap_restarts.py b/pre/remap_restart/remap_restarts.py index 0ebb1bd2..5b055709 100755 --- a/pre/remap_restart/remap_restarts.py +++ b/pre/remap_restart/remap_restarts.py @@ -41,11 +41,9 @@ 3. Use command line arguments: ./remap_restarts.py command_line -ymdh 2004041421 .... - 3. Remap land (catchxxx) only: + 4. Remap land (catchxxx) global domain only: ./remap_restarts.py land_only - Help commands: - Help commands: ./remap_restarts.py -h ./remap_restarts.py config_file -h From 961c8b23622672bb08b5160bd10605d1858849de Mon Sep 17 00:00:00 2001 From: Rolf Reichle Date: Thu, 11 Jan 2024 16:47:15 -0500 Subject: [PATCH 23/26] edited and unified more messages for common questions in remap_restarts package --- pre/remap_restart/remap_catchANDcn.py | 17 ++++++++--------- pre/remap_restart/remap_command_line.py | 2 +- pre/remap_restart/remap_questions.py | 8 ++++---- pre/remap_restart/remap_restarts.py | 2 +- pre/remap_restart/remap_utils.py | 9 +++++++++ 5 files changed, 23 insertions(+), 15 deletions(-) diff --git a/pre/remap_restart/remap_catchANDcn.py b/pre/remap_restart/remap_catchANDcn.py index 1f983341..215ef492 100755 --- a/pre/remap_restart/remap_catchANDcn.py +++ b/pre/remap_restart/remap_catchANDcn.py @@ -37,7 +37,7 @@ def remap(self): time = yyyymmddhh_[0:8]+'_'+yyyymmddhh_[8:10] in_rstfiles = glob.glob(rst_dir+'/*'+model+'_*'+time+'*') if len(in_rstfiles) == 0: - print('\n try catchXX file without time stamp') + print('\n try catch[cn] restart file without time stamp') in_rstfiles = glob.glob(rst_dir+'/*'+model+'_*') if len(in_rstfiles) == 0: return @@ -272,15 +272,14 @@ def has_catch_rst(text): { "type": "path", "name": "input:shared:rst_dir", - "message": "Enter input directory with both 'rs' and 'rc_out' subdirectories:\n", + "message": "Enter input directory that contains './rs' and './rc_out' subdirectories:\n", "validate": lambda path : has_rs_rc_out(path) }, { "type": "text", "name": "input:shared:yyyymmddhh", - "message": (message_datetime + " and the rst file exists.)\n"), - #"validate": lambda x, text: has_catch_rst(x, text), + "message": (message_datetime + " and rst file must exist.)\n"), "validate": lambda text: has_catch_rst(text) }, @@ -323,7 +322,7 @@ def has_catch_rst(text): { "type": "select", "name": "output:surface:EASE_grid", - "message": "Select a grid for new restarts", + "message": "Select grid for new restart:\n", "choices": ['EASEv2_M03', 'EASEv2_M09', 'EASEv2_M25', 'EASEv2_M36', 'Cubed-Sphere'] }, @@ -339,7 +338,7 @@ def has_catch_rst(text): { "type": "select", "name": "output:shared:ogrid", - "message": "Select data ocean grid/resolution for new restarts:\n", + "message": message_ogrid_in, "choices": choices_ogrid_data, "default": lambda x: data_ocean_default(x.get('output:shared:agrid')), "when": lambda x : x['output:surface:EASE_grid'] == 'Cubed-Sphere', @@ -358,20 +357,20 @@ def has_catch_rst(text): { "type": "text", "name": "slurm_pbs:qos", - "message": "slurm or pbs quality-of-service (qos)? (If resolution is c1440 or higher, enter allnccs on NCCS or normal on NAS.) ", + "message": message_qos, "default": "debug", }, { "type": "text", "name": "slurm_pbs:account", - "message": "slurm_pbs account?", + "message": message_account, "default": get_account(), }, { "type": "text", "name": "slurm_pbs:partition", - "message": "Enter the slurm or pbs partition only if you want particular partiton, otherwise keep empty as default: ", + "message": message_partition, "default": '', }, diff --git a/pre/remap_restart/remap_command_line.py b/pre/remap_restart/remap_command_line.py index 3a466bf3..9b59632b 100755 --- a/pre/remap_restart/remap_command_line.py +++ b/pre/remap_restart/remap_command_line.py @@ -31,7 +31,7 @@ def parse_args(program_description): p_landonly = p_sub.add_parser( 'land_only', - help = "remap catchxxx global domain only", + help = "Remap land (catch[cn]) restart only; global domain only; ens0000 only.\n", ) p_command = p_sub.add_parser( diff --git a/pre/remap_restart/remap_questions.py b/pre/remap_restart/remap_questions.py index 7b88cfd4..a98688d5 100755 --- a/pre/remap_restart/remap_questions.py +++ b/pre/remap_restart/remap_questions.py @@ -125,7 +125,7 @@ def ask_questions(): { "type": "select", "name": "input:shared:ogrid", - "message": "Select data ocean grid/resolution of input restarts:\n", + "message": message_ogrid_in, "choices": choices_ogrid_data, "default": lambda x: data_ocean_default(x.get('input:shared:agrid')), "when": lambda x: x.get('input:shared:omodel') == 'data' and not x['input:shared:MERRA-2'], @@ -397,20 +397,20 @@ def ask_questions(): { "type": "text", "name": "slurm_pbs:qos", - "message": "slurm or pbs quality-of-service (qos)? (If resolution is c1440 or higher, enter allnccs on NCCS or normal on NAS.) ", + "message": message_qos, "default": "debug", }, { "type": "text", "name": "slurm_pbs:account", - "message": "slurm_pbs account?", + "message": message_account, "default": get_account(), }, { "type": "text", "name": "slurm_pbs:partition", - "message": "Enter the slurm or pbs partition only if you want particular partiton, otherwise keep empty as default: ", + "message": message_partition, "default": '', }, ] diff --git a/pre/remap_restart/remap_restarts.py b/pre/remap_restart/remap_restarts.py index 5b055709..78ae59fc 100755 --- a/pre/remap_restart/remap_restarts.py +++ b/pre/remap_restart/remap_restarts.py @@ -41,7 +41,7 @@ 3. Use command line arguments: ./remap_restarts.py command_line -ymdh 2004041421 .... - 4. Remap land (catchxxx) global domain only: + 4. For GEOSldas: Remap land (catch[cn]) restart only; global domain only; ens0000 only: ./remap_restarts.py land_only Help commands: diff --git a/pre/remap_restart/remap_utils.py b/pre/remap_restart/remap_utils.py index 7cd43bab..50c28f68 100755 --- a/pre/remap_restart/remap_utils.py +++ b/pre/remap_restart/remap_utils.py @@ -114,6 +114,15 @@ validate_agrid = ['C12','C24','C48','C90','C180','C360','C720','C1000','C1440','C2880','C5760'] +message_ogrid_in = "Select data ocean grid/resolution of input restarts:\n" + +message_qos = "SLURM or PBS quality-of-service (qos)? (If resolution is c1440 or higher, enter 'allnccs' for NCCS or 'normal' for NAS.)\n" + +message_account = "Select/enter SLURM or PBS account:\n", + +message_partition = "Enter SLURM or PBS partition (can leave blank):\n", + + job_directive = {"SLURM": """#!/bin/csh -f #SBATCH --account={account} #SBATCH --ntasks={NPE} From 06aeabd6f487e60cc0dcbdbcb3962fc23b03c4fc Mon Sep 17 00:00:00 2001 From: Rolf Reichle Date: Thu, 11 Jan 2024 17:06:39 -0500 Subject: [PATCH 24/26] clarified "land_only" option for remap_restarts.py package (remap_catchANDcn.py) --- pre/remap_restart/remap_catchANDcn.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pre/remap_restart/remap_catchANDcn.py b/pre/remap_restart/remap_catchANDcn.py index 215ef492..59af8629 100755 --- a/pre/remap_restart/remap_catchANDcn.py +++ b/pre/remap_restart/remap_catchANDcn.py @@ -410,7 +410,7 @@ def has_catch_rst(text): return answers def remap_land_only(): - print("\n It remaps catcment(cn) restarts with GLOBAL domain only. \n") + print("\n Remap land (catch[cn]) restart only; global domain only; ens0000 only. \n") answers = ask_catch_questions() config = get_config_from_answers(answers, config_tpl = True) config_yaml = config['output']['shared']['out_dir']+'/remap_params.yaml' From 7f2c916908ba3db9c950893bf4b20c920e320436 Mon Sep 17 00:00:00 2001 From: Rolf Reichle Date: Thu, 11 Jan 2024 17:18:19 -0500 Subject: [PATCH 25/26] updated CHANGELOG.md; minimal edits of messages in remap_restarts.py package (remap_upper.py, remap_utils.py) --- CHANGELOG.md | 1 + pre/remap_restart/remap_upper.py | 2 +- pre/remap_restart/remap_utils.py | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6392f4fe..daa19ef4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added EASE grid option for remapping of land restarts in remap_restarts.py package (facilitates use of package in GEOSldas setup script) - Added support for SLES15, NAS site and log for remap_lake_landice_saltwater in remap_restarts.py package +- Added "land_only" option for remapping of restarts ### Changed diff --git a/pre/remap_restart/remap_upper.py b/pre/remap_restart/remap_upper.py index 6ea13bf1..ea920779 100755 --- a/pre/remap_restart/remap_upper.py +++ b/pre/remap_restart/remap_upper.py @@ -148,7 +148,7 @@ def remap(self): QOS = config['slurm_pbs']['qos'] TIME = "1:00:00" if NPE > 532: - assert config['slurm_pbs']['qos'] != 'debug', "qos should be allnccs or normal on NAS" + assert config['slurm_pbs']['qos'] != 'debug', "qos should be 'allnccs' for NCCS or 'normal' for NAS" TIME = "12:00:00" NNODE = '' job='' diff --git a/pre/remap_restart/remap_utils.py b/pre/remap_restart/remap_utils.py index 50c28f68..05068a6e 100755 --- a/pre/remap_restart/remap_utils.py +++ b/pre/remap_restart/remap_utils.py @@ -120,7 +120,7 @@ message_account = "Select/enter SLURM or PBS account:\n", -message_partition = "Enter SLURM or PBS partition (can leave blank):\n", +message_partition = "Enter SLURM or PBS partition: (If desired; can leave blank.)\n", job_directive = {"SLURM": """#!/bin/csh -f From 8757894d4d29af7e8ae97c8b6db8e32df156a90c Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Tue, 23 Jan 2024 16:02:37 -0500 Subject: [PATCH 26/26] correct label and constraint fvcore name --- pre/remap_restart/remap_lake_landice_saltwater.py | 2 +- pre/remap_restart/remap_upper.py | 2 +- pre/remap_restart/remap_utils.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pre/remap_restart/remap_lake_landice_saltwater.py b/pre/remap_restart/remap_lake_landice_saltwater.py index 7c7e2c29..5603e1c0 100755 --- a/pre/remap_restart/remap_lake_landice_saltwater.py +++ b/pre/remap_restart/remap_lake_landice_saltwater.py @@ -59,7 +59,7 @@ def remap(self): os.makedirs(OutData_dir) types = '.bin' - type_str = sp.check_output(['file','-b', restarts_in[0]]) + type_str = sp.check_output(['file','-b', os.path.realpath(restarts_in[0])]) type_str = str(type_str) if 'Hierarchical' in type_str: types = '.nc4' diff --git a/pre/remap_restart/remap_upper.py b/pre/remap_restart/remap_upper.py index ea920779..1f28c8a1 100755 --- a/pre/remap_restart/remap_upper.py +++ b/pre/remap_restart/remap_upper.py @@ -72,7 +72,7 @@ def remap(self): print('\nUpper air restart file names link from "_rst" to "_restart_in" \n') types = '.bin' - type_str = subprocess.check_output(['file','-b', restarts_in[0]]) + type_str = subprocess.check_output(['file','-b', os.path.realpath(restarts_in[0])]) type_str = str(type_str) if type_str.find('Hierarchical') >=0: types = '.nc4' diff --git a/pre/remap_restart/remap_utils.py b/pre/remap_restart/remap_utils.py index 05068a6e..345a18bd 100755 --- a/pre/remap_restart/remap_utils.py +++ b/pre/remap_restart/remap_utils.py @@ -187,7 +187,7 @@ def fvcore_info(x): if not rst_dir : return False x['input:shared:rst_dir'] = rst_dir.strip() # remove extra space - files = glob.glob(rst_dir+'/*fvcore_*') + files = glob.glob(rst_dir+'/*fvcore_internal*') if len (files) == 0 : return False fname ='' @@ -197,7 +197,7 @@ def fvcore_info(x): ymdh = x.get('input:shared:yyyymmddhh') if (not ymdh): return False time = ymdh[0:8] + '_'+ymdh[8:10] - files = glob.glob(rst_dir+'/*fvcore_*'+time+'*') + files = glob.glob(rst_dir+'/*fvcore_internal*'+time+'*') fname = files[0] if len(files) == 1: