From 58586d3c0a712a855525c022e1f84bd565d03920 Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Fri, 15 Oct 2021 14:33:18 -0400 Subject: [PATCH 01/70] initial check in --- GEOS_Util/post/CMakeLists.txt | 5 ++ GEOS_Util/post/regrid.py | 27 ++++++++ GEOS_Util/post/regrid.yaml | 52 ++++++++++++++ GEOS_Util/post/regriders.py | 125 ++++++++++++++++++++++++++++++++++ 4 files changed, 209 insertions(+) create mode 100644 GEOS_Util/post/regrid.py create mode 100644 GEOS_Util/post/regrid.yaml create mode 100644 GEOS_Util/post/regriders.py diff --git a/GEOS_Util/post/CMakeLists.txt b/GEOS_Util/post/CMakeLists.txt index 9675e374..122ad63c 100644 --- a/GEOS_Util/post/CMakeLists.txt +++ b/GEOS_Util/post/CMakeLists.txt @@ -43,6 +43,11 @@ install( PROGRAMS ${perlscripts} ec2grd.csh DESTINATION bin) +file(GLOB pythonscripts CONFIGURE_DEPENDS regrid*.py) +install( + PROGRAMS ${pythonscripts} regrid.yaml + DESTINATION bin) + set_property(SOURCE rsg3_vinterp.F APPEND_STRING PROPERTY COMPILE_FLAGS "${FREAL8} ${BYTERECLEN} ${EXTENDED_SOURCE}") set_property(SOURCE rs_vinterp.F90 APPEND_STRING PROPERTY COMPILE_FLAGS "${FREAL8} ${BYTERECLEN}") set_property(SOURCE rs_vinterp_scm.F90 APPEND_STRING PROPERTY COMPILE_FLAGS "${FREAL8} ${BYTERECLEN}") diff --git a/GEOS_Util/post/regrid.py b/GEOS_Util/post/regrid.py new file mode 100644 index 00000000..654d7a00 --- /dev/null +++ b/GEOS_Util/post/regrid.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python +# +# module load python/GEOSpyD/Min4.9.2_py3.9 +# + +import yaml +from regriders import * + +if __name__ == '__main__' : + + # load input yaml + stream = open("regrid.yaml", 'r') + config = yaml.full_load(stream) + + # upper air +# upper = upperair(config) +# upper.regrid() + + # surface + surf = surface(config) + surf.regrid() + + # what ever +# forcing = force(config) +# forcing.regrid() + + diff --git a/GEOS_Util/post/regrid.yaml b/GEOS_Util/post/regrid.yaml new file mode 100644 index 00000000..467553a0 --- /dev/null +++ b/GEOS_Util/post/regrid.yaml @@ -0,0 +1,52 @@ +restarts_in: + UPPERAIR: + fvcore: fvcore_internal_rst + moist: moist_internal_rst + agcm: agcm_import_rst + SURFACE: + lake: lake_internal_rst + salwater: saltwater_internal_rst + seaice: seaicethermo_internal_rst + catchcnclm40: + catch: catch_internal_rst + +options_in: + COMMON: + yyyymmddhh: 2000041421 + expid: + agrid: C48 + ogrid: 360x180 + tag: Icarus_Reynolds + #rstdir: /gpfsm/dnb44/mathomp4/Restarts-J10/nc4/Reynolds/c48 + rst_src: MERR-2 + UPPERAIR: + aaa: + SURFACE: + wemin: 26 + surflay: 50 + zoom: 1 + rescale: 1 + CS: + bbb: + ccc: + +options_out: + COMMON: + yyyymmddhh: 2000041421 + expid: c90e + tag: Icarus-NLv3_MERRA-2 + agrid: 90x540 + ogrid: 1440x720 + outdir: /discover/nobackup/wjiang/test_regridpy/ + UPPERAIR: + bbb: + SURFACE: + wemout: 13 + surflay: 50 + CS: + dyn2dyn.x: + interp_restarts.x: +slurm_options: + account: s1873 + qos: debug + partition: diff --git a/GEOS_Util/post/regriders.py b/GEOS_Util/post/regriders.py new file mode 100644 index 00000000..aef2550b --- /dev/null +++ b/GEOS_Util/post/regriders.py @@ -0,0 +1,125 @@ +#!/usr/bin/env python +# +import os +import subprocess + +tags_to_bcs ={"Icarus_Reynolds": "/discover/nobackup/projects/gmao/share/gmao_ops/fvInput/g5gcm/bcs/Icarus_Updated/Icarus_Reynolds/", + "Icarus-NLv3_MERRA-2": "/discover/nobackup/projects/gmao/share/gmao_ops/fvInput/g5gcm/bcs/Icarus-NLv3/Icarus-NLv3_MERRA-2/"} + +def grid_to_string(grid): + if(grid[0] == 'C'): + n = int(grid[1:]) + return f'CF{n:04d}x6C' + else: + xy = grid.upper().split('X') + x = int(xy[0]) + y = int(xy[1]) + if (y/x == 6) : + return f'CF{x:04d}x6C' + else: + return f'DE{x:04d}xPE{y:04d}' + +class regrider: + def __init__(self, config): + self.common_in = config['options_in']['COMMON'] + self.common_out = config['options_out']['COMMON'] + self.restarts_in = config['restarts_in'] + self.slurm_options = config['slurm_options'] + + # deduce the options + agrid_str = grid_to_string(self.common_in['agrid']) + ogrid_str = grid_to_string(self.common_in['ogrid']) + ao_str = agrid_str + '_' + ogrid_str + self.in_bcsdir = tags_to_bcs[self.common_in['tag']] + ao_str + self.in_til = self.in_bcsdir + '/'+ao_str + '-Pfafstetter.til' + + agrid_str = grid_to_string(self.common_out['agrid']) + ogrid_str = grid_to_string(self.common_out['ogrid']) + ao_str = agrid_str + '_' + ogrid_str + self.out_bcsdir = tags_to_bcs[self.common_out['tag']] + ao_str + self.out_til = self.out_bcsdir + '/'+ao_str + '-Pfafstetter.til' + +class upperair(regrider): + def __init__(self, config): + super().__init__(config) + def regrid(self): + ... + +class surface(regrider): + def __init__(self, config): + super().__init__(config) + self.restarts_in = self.restarts_in['SURFACE'] + self.surf_in = config['options_in']['SURFACE'] + self.surf_out = config['options_out']['SURFACE'] + + self.lake = self.restarts_in.get('lake') + self.catch = self.restarts_in.get('catch') + self.catchcnclm40 = self.restarts_in.get('catchcnclm40') + self.catchcnclm45 = self.restarts_in.get('catchcnclm45') + + def regrid(self): + bindir = os.getcwd() + if (self.lake): + cmd = bindir + 'OutData/*.til Indata/*.til Indata/' + self.lake + '19 ' + str(self.surf_in['zoom']) + outdir = self.common_out['outdir'] + if not os.path.exists(outdir) : os.makedirs(outdir) + os.chdir(self.common_out['outdir']) + print(cmd) + #subprocess.run([cmd]) + + mk_catch_j_1_template = """ +#!/bin/csh -f +#SBATCH --account={account} +#SBATCH --ntasks={numtasks} +#SBATCH --time=1:00:00 +#SBATCH --job-name=catchj +#SBATCH --output={outdir}/{mk_catch_log} +#SBATCH --qos={qos} + +source {Bin}/g5_modules +set echo + +#limit stacksize unlimited +unlimit + +set esma_mpirun_X = ( {Bin}/esma_mpirun -np {numtasks} ) +set mk_CatchRestarts_X = ( $esma_mpirun_X {Bin}/mk_CatchRestarts ) +set Scale_Catch_X = {Bin}/Scale_Catch +set OUT_til = OutData/*.til +set IN_til = InData/*.til +set catchIN = InData/*catch_internal_rst* +set params = ( $OUT_til $IN_til $catchIN {surflay} ) +$mk_CatchRestarts_X $params + +if ({rescale}) then + set catch_regrid = OutData/$catchIN:t + set catch_scaled = $catch_regrid.scaled + set params = ( $catchIN $catch_regrid $catch_scaled {surflay} ) + set params = ( $params {weminIN} {weminOUT} ) + $Scale_Catch_X $params + + mv $catch_regrid $catch_regrid.1 + mv $catch_scaled $catch_regrid +endif +exit +""" + mk_catch_j_1 = """ +#!/bin/csh -f +#SBATCH --account={account} +#SBATCH --ntasks={numtasks} +#SBATCH --time=1:00:00 +#SBATCH --job-name=catchj +#SBATCH --output={outdir}/{mk_catch_log} +#SBATCH --qos={qos} + +source {Bin}/g5_modules +set echo +set esma_mpirun_X = ( {Bin}/esma_mpirun -np {numtasks} ) +""" + catch1script = mk_catch_j_1_template.format(Bin = bindir, account = self.slurm_options['account'], \ + outdir = outdir, mk_catch_log = 'mk_catch_log.1', surflay = self.surf_in['surflay'], \ + weminIN = self.surf_in['wemin'], weminOUT = self.surf_out['wemout'] , qos = self.slurm_options['qos'], \ + numtasks = '84', rescale = '1' ) + catch1 = open('mk_catch.j.1','wt') + catch1.write(catch1script) + catch1.close() From 356a641f78746ebd91dfc1bbd7c42635a90b4c6c Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Wed, 20 Oct 2021 19:22:50 -0400 Subject: [PATCH 02/70] first working version for a simple surface rst --- GEOS_Util/post/regrid.py | 4 +- GEOS_Util/post/regrid.yaml | 15 ++- GEOS_Util/post/regrider_base.py | 43 +++++++ GEOS_Util/post/regrider_surf.py | 212 +++++++++++++++++++++++++++++++ GEOS_Util/post/regrider_upper.py | 13 ++ GEOS_Util/post/regriders.py | 210 ++++++++++++++++++++++++------ 6 files changed, 451 insertions(+), 46 deletions(-) create mode 100644 GEOS_Util/post/regrider_base.py create mode 100644 GEOS_Util/post/regrider_surf.py create mode 100644 GEOS_Util/post/regrider_upper.py diff --git a/GEOS_Util/post/regrid.py b/GEOS_Util/post/regrid.py index 654d7a00..94534f51 100644 --- a/GEOS_Util/post/regrid.py +++ b/GEOS_Util/post/regrid.py @@ -4,7 +4,9 @@ # import yaml -from regriders import * +from regrider_base import * +from regrider_upper import * +from regrider_surf import * if __name__ == '__main__' : diff --git a/GEOS_Util/post/regrid.yaml b/GEOS_Util/post/regrid.yaml index 467553a0..33293b9d 100644 --- a/GEOS_Util/post/regrid.yaml +++ b/GEOS_Util/post/regrid.yaml @@ -4,8 +4,10 @@ restarts_in: moist: moist_internal_rst agcm: agcm_import_rst SURFACE: + openwater: openwater_internal_rst lake: lake_internal_rst - salwater: saltwater_internal_rst + landice: landice_internal_rst + #salwater: saltwater_internal_rst seaice: seaicethermo_internal_rst catchcnclm40: catch: catch_internal_rst @@ -17,15 +19,20 @@ options_in: agrid: C48 ogrid: 360x180 tag: Icarus_Reynolds - #rstdir: /gpfsm/dnb44/mathomp4/Restarts-J10/nc4/Reynolds/c48 + rstdir: /gpfsm/dnb44/mathomp4/Restarts-J10/nc4/Reynolds/c48 rst_src: MERR-2 UPPERAIR: - aaa: + nlevel: 72 SURFACE: wemin: 26 surflay: 50 zoom: 1 rescale: 1 + catchcnFLG: 1 + restart_path: + restart_id: + restart_domain: + cn_version: CS: bbb: ccc: @@ -39,7 +46,7 @@ options_out: ogrid: 1440x720 outdir: /discover/nobackup/wjiang/test_regridpy/ UPPERAIR: - bbb: + nlevel: 72 SURFACE: wemout: 13 surflay: 50 diff --git a/GEOS_Util/post/regrider_base.py b/GEOS_Util/post/regrider_base.py new file mode 100644 index 00000000..6d85a602 --- /dev/null +++ b/GEOS_Util/post/regrider_base.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python +# +import os +import subprocess +import shutil +import glob + +tags_to_bcs ={"Icarus_Reynolds": "/discover/nobackup/projects/gmao/share/gmao_ops/fvInput/g5gcm/bcs/Icarus_Updated/Icarus_Reynolds/", + "Icarus-NLv3_MERRA-2": "/discover/nobackup/projects/gmao/share/gmao_ops/fvInput/g5gcm/bcs/Icarus-NLv3/Icarus-NLv3_MERRA-2/"} + +def grid_to_string(grid): + if(grid[0] == 'C'): + n = int(grid[1:]) + return f'CF{n:04d}x6C' + else: + xy = grid.upper().split('X') + x = int(xy[0]) + y = int(xy[1]) + if (y/x == 6) : + return f'CF{x:04d}x6C' + else: + return f'DE{x:04d}xPE{y:04d}' + +class regrider: + def __init__(self, config): + self.common_in = config['options_in']['COMMON'] + self.common_out = config['options_out']['COMMON'] + self.restarts_in = config['restarts_in'] + self.slurm_options = config['slurm_options'] + + # deduce the options + agrid_str = grid_to_string(self.common_in['agrid']) + ogrid_str = grid_to_string(self.common_in['ogrid']) + ao_str = agrid_str + '_' + ogrid_str + self.in_bcsdir = tags_to_bcs[self.common_in['tag']] + ao_str + self.in_til = self.in_bcsdir + '/'+ao_str + '-Pfafstetter.til' + + agrid_str = grid_to_string(self.common_out['agrid']) + ogrid_str = grid_to_string(self.common_out['ogrid']) + ao_str = agrid_str + '_' + ogrid_str + self.out_bcsdir = tags_to_bcs[self.common_out['tag']] + ao_str + self.out_til = self.out_bcsdir + '/'+ao_str + '-Pfafstetter.til' + diff --git a/GEOS_Util/post/regrider_surf.py b/GEOS_Util/post/regrider_surf.py new file mode 100644 index 00000000..97de38ab --- /dev/null +++ b/GEOS_Util/post/regrider_surf.py @@ -0,0 +1,212 @@ +#!/usr/bin/env python +# +import os +import subprocess +import shutil +import glob +from regrider_base import * + +class surface(regrider): + def __init__(self, config): + super().__init__(config) + self.restarts_in = self.restarts_in['SURFACE'] + self.surf_in = config['options_in']['SURFACE'] + self.surf_out = config['options_out']['SURFACE'] + + print("--ToDO--\n") + print("split saltwater after some tags(need to rank tag)") + print("if split, set self.saltwater None") + print("\n") + self.saltwater = self.restarts_in.get('saltwater') + self.openwater = self.restarts_in.get('openwater') + self.seaice = self.restarts_in.get('seaice') + self.landice = self.restarts_in.get('landice') + self.lake = self.restarts_in.get('lake') + self.route = self.restarts_in.get('route') + self.catch = self.restarts_in.get('catch') + self.catchcnclm40 = self.restarts_in.get('catchcnclm40') + self.catchcnclm45 = self.restarts_in.get('catchcnclm45') + + def regrid(self): + bindir = os.getcwd() + outdir = self.common_out['outdir'] + if not os.path.exists(outdir) : os.makedirs(outdir) + os.chdir(self.common_out['outdir']) + InData_dir = outdir+'/InData/' + OutData_dir = outdir+'/OutData/' + if os.path.exists(InData_dir) : subprocess.call('rm -rf '+ InData_dir, shell = True) + os.makedirs(InData_dir) + if os.path.exists(OutData_dir) : subprocess.call('rm -rf '+ OutData_dir, shell = True) + os.makedirs(OutData_dir) + + for key, value in self.restarts_in.items(): + if not value : continue + src = self.common_in['rstdir']+'/'+value + if not os.path.exists(src) : + print( "Could not find " + src + "--remove it from yaml config file add to restart dir") + exit() + dest = InData_dir+'/'+value + if os.path.exists(dest) : os.unlink(dest) + os.symlink(src, dest) + in_til = InData_dir+'/' + self.in_til.split('/')[-1] + out_til = OutData_dir+'/'+self.out_til.split('/')[-1] + if os.path.exists(in_til) : os.unlink(in_til) + if os.path.exists(out_til) : os.unlink(out_til) + os.symlink(self.in_til, in_til) + os.symlink(self.out_til, out_til) + + exe = bindir + '/mk_LakeLandiceSaltRestarts ' + if (self.saltwater): + cmd = exe + 'OutData/*.til InData/*.til InData/'+self.saltwater + ' 0 ' + str(self.surf_in['zoom']) + print(cmd) + subprocess.call(cmd, shell= True) + + if (self.openwater): + exe = bindir + '/mk_LakeLandiceSaltRestarts ' + cmd = exe + 'OutData/*.til InData/*.til InData/'+self.openwater + ' 0 ' + str(self.surf_in['zoom']) + print(cmd) + subprocess.call(cmd, shell= True) + + if (self.seaice): + exe = bindir + '/mk_LakeLandiceSaltRestarts ' + cmd = exe + 'OutData/*.til InData/*.til InData/'+self.seaice + ' 0 ' + str(self.surf_in['zoom']) + print(cmd) + subprocess.call(cmd, shell= True) + + if (self.lake): + exe = bindir + '/mk_LakeLandiceSaltRestarts ' + cmd = exe + 'OutData/*.til InData/*.til InData/'+self.lake + ' 19 ' + str(self.surf_in['zoom']) + print(cmd) + subprocess.call(cmd, shell= True) + + if (self.landice): + exe = bindir + '/mk_LakeLandiceSaltRestarts ' + cmd = exe + 'OutData/*.til InData/*.til InData/'+self.landice + ' 20 ' + str(self.surf_in['zoom']) + print(cmd) + subprocess.call(cmd, shell= True) + + if (self.route): + route = bindir + '/mk_RouteRestarts ' + cmd = route + 'OutData/*.til '+ self.common_in["yyyymmddhh"][0:6] + print(cmd) + subprocess.call(cmd, shell= True) + if ( self.catchcnclm40 or self.catchcnclm45) : + dirname = os.path.dirname(self.out_til) + clsm = dirname+'/clsm' + os.symlink(clsm, 'OutData/clsm') + + mk_catch_j_template = """#!/bin/csh -f +#SBATCH --account={account} +#SBATCH --ntasks=84 +#SBATCH --time=1:00:00 +#SBATCH --job-name=mk_catch +#SBATCH --qos=debug +#SBATCH --output={outdir}/{mk_catch_log} +# + +source {Bin}/g5_modules +set echo + +#limit stacksize unlimited +unlimit + +set esma_mpirun_X = ( {Bin}/esma_mpirun -np 84 ) +set mk_CatchRestarts_X = ( $esma_mpirun_X {Bin}/mk_CatchRestarts ) +set mk_CatchCNRestarts_X = ( $esma_mpirun_X {Bin}/mk_CatchCNRestarts ) +set Scale_Catch_X = {Bin}/Scale_Catch +set Scale_CatchCN_X = {Bin}/Scale_CatchCN + +set OUT_til = OutData/*.til +set IN_til = InData/*.til + +if ({catchFLG}) then + set catchIN = InData/*catch_internal_rst* + set params = ( $OUT_til $IN_til $catchIN {surflay} ) + $mk_CatchRestarts_X $params + + if ({rescale}) then + set catch_regrid = OutData/$catchIN:t + set catch_scaled = $catch_regrid.scaled + set params = ( $catchIN $catch_regrid $catch_scaled {surflay} ) + set params = ( $params {wemin} {wemout} ) + $Scale_Catch_X $params + + mv $catch_regrid $catch_regrid.1 + mv $catch_scaled $catch_regrid + endif +endif + +if ({catchcnFLG}) then + # WY notes: it was never used in gcm + if ({fromGCM} ) then + set catchcnIN = InData/*catchcn_internal_rst* + set params = ( $OUT_til $IN_til $catchcnIN {surflay} {rsttime} ) + $mk_CatchCNRestarts_X $params + else # from GEOSldas + set OUT_til = `ls OutData/*.til | cut -d '/' -f2` + /bin/cp OutData/*.til OutData/OutTileFile + /bin/cp OutData/*.til InData/OutTileFile + set RESTART_short = {RESTART_PATH}/{RESTART_ID}/output/{RESTART_DOMAIN}/ + set YYYY = `echo {rsttime} | cut -c1-4` + set MM = `echo {rsttime} | cut -c5-6` + echo $MM, $YYYY + set PARAM_FILE = `ls $RESTART_short/rc_out/Y$YYYY/M$MM/*ldas_catparam* | head -1` + set params = ( -b OutData/ -d {rsttime} -e {RESTART_ID} -m catchcn{CN_VERSION} -s {surflay} -j Y -r R -p $PARAM_FILE -l $RESTART_short) + $mk_GEOSldasRestarts_X $params + endif + + if ({rescale}) then + set catchcn_regrid = OutData/$catchcnIN:t + set catchcn_scaled = $catchcn_regrid.scaled + set params = ( $catchcnIN $catchcn_regrid $catchcn_scaled {surflay} ) + set params = ( $params {wemin} {wemout} ) + $Scale_CatchCN_X $params + + mv $catchcn_regrid $catchcn_regrid.1 + mv $catchcn_scaled $catchcn_regrid + endif +endif +exit +""" + catchFLG = '1' if self.catch else '0' + catchcnFLG = '1' if (self.catchcnclm40 or self.catchcnclm45) else '0' + + catch1script = mk_catch_j_template.format(Bin = bindir, account = self.slurm_options['account'], \ + outdir = outdir, mk_catch_log = 'mk_catch_log.1', surflay = self.surf_in['surflay'], \ + wemin = self.surf_in['wemin'], wemout = self.surf_out['wemout'] , \ + fromGCM = '0', catchFLG = catchFLG, catchcnFLG = catchcnFLG, rescale = '0', rsttime = self.common_in['yyyymmddhh'], \ + RESTART_ID = self.surf_in['restart_id'], RESTART_PATH = self.surf_in['restart_path'], \ + RESTART_DOMAIN = self.surf_in['restart_domain'], CN_VERSION = self.surf_in['cn_version'] ) + print(os.getcwd()) + catch1 = open('mk_catch.j.1','wt') + catch1.write(catch1script) + catch1.close() + + subprocess.call('sbatch -W mk_catch.j.1', shell= True) + # step 2 + if (self.surf_in['rescale'] and ( self.catch or self.catchcnclm40 or self.catchcnclm45)) : + if os.path.exists('InData.step1') : subprocess.call('rm -rf InData.step1', shell = True) + shutil.move('InData', 'InData.step1') + os.makedirs('InData') + for catchfile in glob.glob("OutData/*catch*"): + shutil.move(catchfile,"InData/") + os.symlink(self.out_til, in_til) + + if ( (not (self.catchcnclm40 or self.catchcnclm45)) and self.catch) : + dirname = os.path.dirname(self.out_til) + clsm = dirname+'/clsm' + os.symlink(clsm, 'OutData/clsm') + + catch2script = mk_catch_j_template.format(Bin = bindir, account = self.slurm_options['account'], \ + outdir = outdir, mk_catch_log = 'mk_catch_log.2', surflay = self.surf_in['surflay'], \ + wemin = self.surf_in['wemin'], wemout = self.surf_out['wemout'] , \ + fromGCM = '0', catchFLG = catchFLG, catchcnFLG = catchcnFLG, rescale = '1', rsttime = self.common_in['yyyymmddhh'], \ + RESTART_ID = self.surf_in['restart_id'], RESTART_PATH = self.surf_in['restart_path'], \ + RESTART_DOMAIN = self.surf_in['restart_domain'], CN_VERSION = self.surf_in['cn_version'] ) + print(os.getcwd()) + catch2 = open('mk_catch.j.2','wt') + catch2.write(catch2script) + catch2.close() + + subprocess.call('sbatch -W mk_catch.j.2', shell= True) + diff --git a/GEOS_Util/post/regrider_upper.py b/GEOS_Util/post/regrider_upper.py new file mode 100644 index 00000000..18b2398d --- /dev/null +++ b/GEOS_Util/post/regrider_upper.py @@ -0,0 +1,13 @@ +#!/usr/bin/env python +# +import os +import subprocess +import shutil +import glob +from regrider_base import * + +class upperair(regrider): + def __init__(self, config): + super().__init__(config) + def regrid(self): + ... diff --git a/GEOS_Util/post/regriders.py b/GEOS_Util/post/regriders.py index aef2550b..0058e281 100644 --- a/GEOS_Util/post/regriders.py +++ b/GEOS_Util/post/regriders.py @@ -2,6 +2,8 @@ # import os import subprocess +import shutil +import glob tags_to_bcs ={"Icarus_Reynolds": "/discover/nobackup/projects/gmao/share/gmao_ops/fvInput/g5gcm/bcs/Icarus_Updated/Icarus_Reynolds/", "Icarus-NLv3_MERRA-2": "/discover/nobackup/projects/gmao/share/gmao_ops/fvInput/g5gcm/bcs/Icarus-NLv3/Icarus-NLv3_MERRA-2/"} @@ -52,29 +54,96 @@ def __init__(self, config): self.surf_in = config['options_in']['SURFACE'] self.surf_out = config['options_out']['SURFACE'] - self.lake = self.restarts_in.get('lake') + print("--ToDO--\n") + print("split saltwater after some tags(need to rank tag)") + print("if split, set self.saltwater None") + print("\n") + self.saltwater = self.restarts_in.get('saltwater') + self.openwater = self.restarts_in.get('openwater') + self.seaice = self.restarts_in.get('seaice') + self.landice = self.restarts_in.get('landice') + self.lake = self.restarts_in.get('lake') + self.route = self.restarts_in.get('route') self.catch = self.restarts_in.get('catch') self.catchcnclm40 = self.restarts_in.get('catchcnclm40') self.catchcnclm45 = self.restarts_in.get('catchcnclm45') def regrid(self): bindir = os.getcwd() + outdir = self.common_out['outdir'] + if not os.path.exists(outdir) : os.makedirs(outdir) + os.chdir(self.common_out['outdir']) + InData_dir = outdir+'/InData/' + OutData_dir = outdir+'/OutData/' + if os.path.exists(InData_dir) : subprocess.call('rm -rf '+ InData_dir, shell = True) + os.makedirs(InData_dir) + if os.path.exists(OutData_dir) : subprocess.call('rm -rf '+ OutData_dir, shell = True) + os.makedirs(OutData_dir) + + for key, value in self.restarts_in.items(): + if not value : continue + src = self.common_in['rstdir']+'/'+value + if not os.path.exists(src) : + print( "Could not find " + src + "--remove it from yaml config file add to restart dir") + exit() + dest = InData_dir+'/'+value + if os.path.exists(dest) : os.unlink(dest) + os.symlink(src, dest) + in_til = InData_dir+'/' + self.in_til.split('/')[-1] + out_til = OutData_dir+'/'+self.out_til.split('/')[-1] + if os.path.exists(in_til) : os.unlink(in_til) + if os.path.exists(out_til) : os.unlink(out_til) + os.symlink(self.in_til, in_til) + os.symlink(self.out_til, out_til) + + exe = bindir + '/mk_LakeLandiceSaltRestarts ' + if (self.saltwater): + cmd = exe + 'OutData/*.til InData/*.til InData/'+self.saltwater + ' 0 ' + str(self.surf_in['zoom']) + print(cmd) + subprocess.call(cmd, shell= True) + + if (self.openwater): + exe = bindir + '/mk_LakeLandiceSaltRestarts ' + cmd = exe + 'OutData/*.til InData/*.til InData/'+self.openwater + ' 0 ' + str(self.surf_in['zoom']) + print(cmd) + subprocess.call(cmd, shell= True) + + if (self.seaice): + exe = bindir + '/mk_LakeLandiceSaltRestarts ' + cmd = exe + 'OutData/*.til InData/*.til InData/'+self.seaice + ' 0 ' + str(self.surf_in['zoom']) + print(cmd) + subprocess.call(cmd, shell= True) + if (self.lake): - cmd = bindir + 'OutData/*.til Indata/*.til Indata/' + self.lake + '19 ' + str(self.surf_in['zoom']) - outdir = self.common_out['outdir'] - if not os.path.exists(outdir) : os.makedirs(outdir) - os.chdir(self.common_out['outdir']) + exe = bindir + '/mk_LakeLandiceSaltRestarts ' + cmd = exe + 'OutData/*.til InData/*.til InData/'+self.lake + ' 19 ' + str(self.surf_in['zoom']) print(cmd) - #subprocess.run([cmd]) + subprocess.call(cmd, shell= True) - mk_catch_j_1_template = """ -#!/bin/csh -f + if (self.landice): + exe = bindir + '/mk_LakeLandiceSaltRestarts ' + cmd = exe + 'OutData/*.til InData/*.til InData/'+self.landice + ' 20 ' + str(self.surf_in['zoom']) + print(cmd) + subprocess.call(cmd, shell= True) + + if (self.route): + route = bindir + '/mk_RouteRestarts ' + cmd = route + 'OutData/*.til '+ self.common_in["yyyymmddhh"][0:6] + print(cmd) + subprocess.call(cmd, shell= True) + if ( self.catchcnclm40 or self.catchcnclm45) : + dirname = os.path.dirname(self.out_til) + clsm = dirname+'/clsm' + os.symlink(clsm, 'OutData/clsm') + + mk_catch_j_template = """#!/bin/csh -f #SBATCH --account={account} -#SBATCH --ntasks={numtasks} +#SBATCH --ntasks=84 #SBATCH --time=1:00:00 -#SBATCH --job-name=catchj +#SBATCH --job-name=mk_catch +#SBATCH --qos=debug #SBATCH --output={outdir}/{mk_catch_log} -#SBATCH --qos={qos} +# source {Bin}/g5_modules set echo @@ -82,44 +151,103 @@ def regrid(self): #limit stacksize unlimited unlimit -set esma_mpirun_X = ( {Bin}/esma_mpirun -np {numtasks} ) +set esma_mpirun_X = ( {Bin}/esma_mpirun -np 84 ) set mk_CatchRestarts_X = ( $esma_mpirun_X {Bin}/mk_CatchRestarts ) +set mk_CatchCNRestarts_X = ( $esma_mpirun_X {Bin}/mk_CatchCNRestarts ) set Scale_Catch_X = {Bin}/Scale_Catch +set Scale_CatchCN_X = {Bin}/Scale_CatchCN + set OUT_til = OutData/*.til set IN_til = InData/*.til -set catchIN = InData/*catch_internal_rst* -set params = ( $OUT_til $IN_til $catchIN {surflay} ) -$mk_CatchRestarts_X $params - -if ({rescale}) then - set catch_regrid = OutData/$catchIN:t - set catch_scaled = $catch_regrid.scaled - set params = ( $catchIN $catch_regrid $catch_scaled {surflay} ) - set params = ( $params {weminIN} {weminOUT} ) - $Scale_Catch_X $params - - mv $catch_regrid $catch_regrid.1 - mv $catch_scaled $catch_regrid -endif + +if ({catchFLG}) then + set catchIN = InData/*catch_internal_rst* + set params = ( $OUT_til $IN_til $catchIN {surflay} ) + $mk_CatchRestarts_X $params + + if ({rescale}) then + set catch_regrid = OutData/$catchIN:t + set catch_scaled = $catch_regrid.scaled + set params = ( $catchIN $catch_regrid $catch_scaled {surflay} ) + set params = ( $params {wemin} {wemout} ) + $Scale_Catch_X $params + + mv $catch_regrid $catch_regrid.1 + mv $catch_scaled $catch_regrid + endif +endif + +if ({catchcnFLG}) then + # WY notes: it was never used in gcm + if ({fromGCM} ) then + set catchcnIN = InData/*catchcn_internal_rst* + set params = ( $OUT_til $IN_til $catchcnIN {surflay} {rsttime} ) + $mk_CatchCNRestarts_X $params + else # from GEOSldas + set OUT_til = `ls OutData/*.til | cut -d '/' -f2` + /bin/cp OutData/*.til OutData/OutTileFile + /bin/cp OutData/*.til InData/OutTileFile + set RESTART_short = {RESTART_PATH}/{RESTART_ID}/output/{RESTART_DOMAIN}/ + set YYYY = `echo {rsttime} | cut -c1-4` + set MM = `echo {rsttime} | cut -c5-6` + echo $MM, $YYYY + set PARAM_FILE = `ls $RESTART_short/rc_out/Y$YYYY/M$MM/*ldas_catparam* | head -1` + set params = ( -b OutData/ -d {rsttime} -e {RESTART_ID} -m catchcn{CN_VERSION} -s {surflay} -j Y -r R -p $PARAM_FILE -l $RESTART_short) + $mk_GEOSldasRestarts_X $params + endif + + if ({rescale}) then + set catchcn_regrid = OutData/$catchcnIN:t + set catchcn_scaled = $catchcn_regrid.scaled + set params = ( $catchcnIN $catchcn_regrid $catchcn_scaled {surflay} ) + set params = ( $params {wemin} {wemout} ) + $Scale_CatchCN_X $params + + mv $catchcn_regrid $catchcn_regrid.1 + mv $catchcn_scaled $catchcn_regrid + endif +endif exit """ - mk_catch_j_1 = """ -#!/bin/csh -f -#SBATCH --account={account} -#SBATCH --ntasks={numtasks} -#SBATCH --time=1:00:00 -#SBATCH --job-name=catchj -#SBATCH --output={outdir}/{mk_catch_log} -#SBATCH --qos={qos} + catchFLG = '1' if self.catch else '0' + catchcnFLG = '1' if (self.catchcnclm40 or self.catchcnclm45) else '0' -source {Bin}/g5_modules -set echo -set esma_mpirun_X = ( {Bin}/esma_mpirun -np {numtasks} ) -""" - catch1script = mk_catch_j_1_template.format(Bin = bindir, account = self.slurm_options['account'], \ + catch1script = mk_catch_j_template.format(Bin = bindir, account = self.slurm_options['account'], \ outdir = outdir, mk_catch_log = 'mk_catch_log.1', surflay = self.surf_in['surflay'], \ - weminIN = self.surf_in['wemin'], weminOUT = self.surf_out['wemout'] , qos = self.slurm_options['qos'], \ - numtasks = '84', rescale = '1' ) + wemin = self.surf_in['wemin'], wemout = self.surf_out['wemout'] , \ + fromGCM = '0', catchFLG = catchFLG, catchcnFLG = catchcnFLG, rescale = '0', rsttime = self.common_in['yyyymmddhh'], \ + RESTART_ID = self.surf_in['restart_id'], RESTART_PATH = self.surf_in['restart_path'], \ + RESTART_DOMAIN = self.surf_in['restart_domain'], CN_VERSION = self.surf_in['cn_version'] ) + print(os.getcwd()) catch1 = open('mk_catch.j.1','wt') catch1.write(catch1script) catch1.close() + + subprocess.call('sbatch -W mk_catch.j.1', shell= True) + # step 2 + if (self.surf_in['rescale'] and ( self.catch or self.catchcnclm40 or self.catchcnclm45)) : + if os.path.exists('InData.step1') : subprocess.call('rm -rf InData.step1', shell = True) + shutil.move('InData', 'InData.step1') + os.makedirs('InData') + for catchfile in glob.glob("OutData/*catch*"): + shutil.move(catchfile,"InData/") + os.symlink(self.out_til, in_til) + + if ( (not (self.catchcnclm40 or self.catchcnclm45)) and self.catch) : + dirname = os.path.dirname(self.out_til) + clsm = dirname+'/clsm' + os.symlink(clsm, 'OutData/clsm') + + catch2script = mk_catch_j_template.format(Bin = bindir, account = self.slurm_options['account'], \ + outdir = outdir, mk_catch_log = 'mk_catch_log.2', surflay = self.surf_in['surflay'], \ + wemin = self.surf_in['wemin'], wemout = self.surf_out['wemout'] , \ + fromGCM = '0', catchFLG = catchFLG, catchcnFLG = catchcnFLG, rescale = '1', rsttime = self.common_in['yyyymmddhh'], \ + RESTART_ID = self.surf_in['restart_id'], RESTART_PATH = self.surf_in['restart_path'], \ + RESTART_DOMAIN = self.surf_in['restart_domain'], CN_VERSION = self.surf_in['cn_version'] ) + print(os.getcwd()) + catch2 = open('mk_catch.j.2','wt') + catch2.write(catch2script) + catch2.close() + + subprocess.call('sbatch -W mk_catch.j.2', shell= True) + From 8d75d01ec7789571130cc817f4ab9983744ed720 Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Wed, 20 Oct 2021 19:25:02 -0400 Subject: [PATCH 03/70] remove unused file --- GEOS_Util/post/regriders.py | 253 ------------------------------------ 1 file changed, 253 deletions(-) delete mode 100644 GEOS_Util/post/regriders.py diff --git a/GEOS_Util/post/regriders.py b/GEOS_Util/post/regriders.py deleted file mode 100644 index 0058e281..00000000 --- a/GEOS_Util/post/regriders.py +++ /dev/null @@ -1,253 +0,0 @@ -#!/usr/bin/env python -# -import os -import subprocess -import shutil -import glob - -tags_to_bcs ={"Icarus_Reynolds": "/discover/nobackup/projects/gmao/share/gmao_ops/fvInput/g5gcm/bcs/Icarus_Updated/Icarus_Reynolds/", - "Icarus-NLv3_MERRA-2": "/discover/nobackup/projects/gmao/share/gmao_ops/fvInput/g5gcm/bcs/Icarus-NLv3/Icarus-NLv3_MERRA-2/"} - -def grid_to_string(grid): - if(grid[0] == 'C'): - n = int(grid[1:]) - return f'CF{n:04d}x6C' - else: - xy = grid.upper().split('X') - x = int(xy[0]) - y = int(xy[1]) - if (y/x == 6) : - return f'CF{x:04d}x6C' - else: - return f'DE{x:04d}xPE{y:04d}' - -class regrider: - def __init__(self, config): - self.common_in = config['options_in']['COMMON'] - self.common_out = config['options_out']['COMMON'] - self.restarts_in = config['restarts_in'] - self.slurm_options = config['slurm_options'] - - # deduce the options - agrid_str = grid_to_string(self.common_in['agrid']) - ogrid_str = grid_to_string(self.common_in['ogrid']) - ao_str = agrid_str + '_' + ogrid_str - self.in_bcsdir = tags_to_bcs[self.common_in['tag']] + ao_str - self.in_til = self.in_bcsdir + '/'+ao_str + '-Pfafstetter.til' - - agrid_str = grid_to_string(self.common_out['agrid']) - ogrid_str = grid_to_string(self.common_out['ogrid']) - ao_str = agrid_str + '_' + ogrid_str - self.out_bcsdir = tags_to_bcs[self.common_out['tag']] + ao_str - self.out_til = self.out_bcsdir + '/'+ao_str + '-Pfafstetter.til' - -class upperair(regrider): - def __init__(self, config): - super().__init__(config) - def regrid(self): - ... - -class surface(regrider): - def __init__(self, config): - super().__init__(config) - self.restarts_in = self.restarts_in['SURFACE'] - self.surf_in = config['options_in']['SURFACE'] - self.surf_out = config['options_out']['SURFACE'] - - print("--ToDO--\n") - print("split saltwater after some tags(need to rank tag)") - print("if split, set self.saltwater None") - print("\n") - self.saltwater = self.restarts_in.get('saltwater') - self.openwater = self.restarts_in.get('openwater') - self.seaice = self.restarts_in.get('seaice') - self.landice = self.restarts_in.get('landice') - self.lake = self.restarts_in.get('lake') - self.route = self.restarts_in.get('route') - self.catch = self.restarts_in.get('catch') - self.catchcnclm40 = self.restarts_in.get('catchcnclm40') - self.catchcnclm45 = self.restarts_in.get('catchcnclm45') - - def regrid(self): - bindir = os.getcwd() - outdir = self.common_out['outdir'] - if not os.path.exists(outdir) : os.makedirs(outdir) - os.chdir(self.common_out['outdir']) - InData_dir = outdir+'/InData/' - OutData_dir = outdir+'/OutData/' - if os.path.exists(InData_dir) : subprocess.call('rm -rf '+ InData_dir, shell = True) - os.makedirs(InData_dir) - if os.path.exists(OutData_dir) : subprocess.call('rm -rf '+ OutData_dir, shell = True) - os.makedirs(OutData_dir) - - for key, value in self.restarts_in.items(): - if not value : continue - src = self.common_in['rstdir']+'/'+value - if not os.path.exists(src) : - print( "Could not find " + src + "--remove it from yaml config file add to restart dir") - exit() - dest = InData_dir+'/'+value - if os.path.exists(dest) : os.unlink(dest) - os.symlink(src, dest) - in_til = InData_dir+'/' + self.in_til.split('/')[-1] - out_til = OutData_dir+'/'+self.out_til.split('/')[-1] - if os.path.exists(in_til) : os.unlink(in_til) - if os.path.exists(out_til) : os.unlink(out_til) - os.symlink(self.in_til, in_til) - os.symlink(self.out_til, out_til) - - exe = bindir + '/mk_LakeLandiceSaltRestarts ' - if (self.saltwater): - cmd = exe + 'OutData/*.til InData/*.til InData/'+self.saltwater + ' 0 ' + str(self.surf_in['zoom']) - print(cmd) - subprocess.call(cmd, shell= True) - - if (self.openwater): - exe = bindir + '/mk_LakeLandiceSaltRestarts ' - cmd = exe + 'OutData/*.til InData/*.til InData/'+self.openwater + ' 0 ' + str(self.surf_in['zoom']) - print(cmd) - subprocess.call(cmd, shell= True) - - if (self.seaice): - exe = bindir + '/mk_LakeLandiceSaltRestarts ' - cmd = exe + 'OutData/*.til InData/*.til InData/'+self.seaice + ' 0 ' + str(self.surf_in['zoom']) - print(cmd) - subprocess.call(cmd, shell= True) - - if (self.lake): - exe = bindir + '/mk_LakeLandiceSaltRestarts ' - cmd = exe + 'OutData/*.til InData/*.til InData/'+self.lake + ' 19 ' + str(self.surf_in['zoom']) - print(cmd) - subprocess.call(cmd, shell= True) - - if (self.landice): - exe = bindir + '/mk_LakeLandiceSaltRestarts ' - cmd = exe + 'OutData/*.til InData/*.til InData/'+self.landice + ' 20 ' + str(self.surf_in['zoom']) - print(cmd) - subprocess.call(cmd, shell= True) - - if (self.route): - route = bindir + '/mk_RouteRestarts ' - cmd = route + 'OutData/*.til '+ self.common_in["yyyymmddhh"][0:6] - print(cmd) - subprocess.call(cmd, shell= True) - if ( self.catchcnclm40 or self.catchcnclm45) : - dirname = os.path.dirname(self.out_til) - clsm = dirname+'/clsm' - os.symlink(clsm, 'OutData/clsm') - - mk_catch_j_template = """#!/bin/csh -f -#SBATCH --account={account} -#SBATCH --ntasks=84 -#SBATCH --time=1:00:00 -#SBATCH --job-name=mk_catch -#SBATCH --qos=debug -#SBATCH --output={outdir}/{mk_catch_log} -# - -source {Bin}/g5_modules -set echo - -#limit stacksize unlimited -unlimit - -set esma_mpirun_X = ( {Bin}/esma_mpirun -np 84 ) -set mk_CatchRestarts_X = ( $esma_mpirun_X {Bin}/mk_CatchRestarts ) -set mk_CatchCNRestarts_X = ( $esma_mpirun_X {Bin}/mk_CatchCNRestarts ) -set Scale_Catch_X = {Bin}/Scale_Catch -set Scale_CatchCN_X = {Bin}/Scale_CatchCN - -set OUT_til = OutData/*.til -set IN_til = InData/*.til - -if ({catchFLG}) then - set catchIN = InData/*catch_internal_rst* - set params = ( $OUT_til $IN_til $catchIN {surflay} ) - $mk_CatchRestarts_X $params - - if ({rescale}) then - set catch_regrid = OutData/$catchIN:t - set catch_scaled = $catch_regrid.scaled - set params = ( $catchIN $catch_regrid $catch_scaled {surflay} ) - set params = ( $params {wemin} {wemout} ) - $Scale_Catch_X $params - - mv $catch_regrid $catch_regrid.1 - mv $catch_scaled $catch_regrid - endif -endif - -if ({catchcnFLG}) then - # WY notes: it was never used in gcm - if ({fromGCM} ) then - set catchcnIN = InData/*catchcn_internal_rst* - set params = ( $OUT_til $IN_til $catchcnIN {surflay} {rsttime} ) - $mk_CatchCNRestarts_X $params - else # from GEOSldas - set OUT_til = `ls OutData/*.til | cut -d '/' -f2` - /bin/cp OutData/*.til OutData/OutTileFile - /bin/cp OutData/*.til InData/OutTileFile - set RESTART_short = {RESTART_PATH}/{RESTART_ID}/output/{RESTART_DOMAIN}/ - set YYYY = `echo {rsttime} | cut -c1-4` - set MM = `echo {rsttime} | cut -c5-6` - echo $MM, $YYYY - set PARAM_FILE = `ls $RESTART_short/rc_out/Y$YYYY/M$MM/*ldas_catparam* | head -1` - set params = ( -b OutData/ -d {rsttime} -e {RESTART_ID} -m catchcn{CN_VERSION} -s {surflay} -j Y -r R -p $PARAM_FILE -l $RESTART_short) - $mk_GEOSldasRestarts_X $params - endif - - if ({rescale}) then - set catchcn_regrid = OutData/$catchcnIN:t - set catchcn_scaled = $catchcn_regrid.scaled - set params = ( $catchcnIN $catchcn_regrid $catchcn_scaled {surflay} ) - set params = ( $params {wemin} {wemout} ) - $Scale_CatchCN_X $params - - mv $catchcn_regrid $catchcn_regrid.1 - mv $catchcn_scaled $catchcn_regrid - endif -endif -exit -""" - catchFLG = '1' if self.catch else '0' - catchcnFLG = '1' if (self.catchcnclm40 or self.catchcnclm45) else '0' - - catch1script = mk_catch_j_template.format(Bin = bindir, account = self.slurm_options['account'], \ - outdir = outdir, mk_catch_log = 'mk_catch_log.1', surflay = self.surf_in['surflay'], \ - wemin = self.surf_in['wemin'], wemout = self.surf_out['wemout'] , \ - fromGCM = '0', catchFLG = catchFLG, catchcnFLG = catchcnFLG, rescale = '0', rsttime = self.common_in['yyyymmddhh'], \ - RESTART_ID = self.surf_in['restart_id'], RESTART_PATH = self.surf_in['restart_path'], \ - RESTART_DOMAIN = self.surf_in['restart_domain'], CN_VERSION = self.surf_in['cn_version'] ) - print(os.getcwd()) - catch1 = open('mk_catch.j.1','wt') - catch1.write(catch1script) - catch1.close() - - subprocess.call('sbatch -W mk_catch.j.1', shell= True) - # step 2 - if (self.surf_in['rescale'] and ( self.catch or self.catchcnclm40 or self.catchcnclm45)) : - if os.path.exists('InData.step1') : subprocess.call('rm -rf InData.step1', shell = True) - shutil.move('InData', 'InData.step1') - os.makedirs('InData') - for catchfile in glob.glob("OutData/*catch*"): - shutil.move(catchfile,"InData/") - os.symlink(self.out_til, in_til) - - if ( (not (self.catchcnclm40 or self.catchcnclm45)) and self.catch) : - dirname = os.path.dirname(self.out_til) - clsm = dirname+'/clsm' - os.symlink(clsm, 'OutData/clsm') - - catch2script = mk_catch_j_template.format(Bin = bindir, account = self.slurm_options['account'], \ - outdir = outdir, mk_catch_log = 'mk_catch_log.2', surflay = self.surf_in['surflay'], \ - wemin = self.surf_in['wemin'], wemout = self.surf_out['wemout'] , \ - fromGCM = '0', catchFLG = catchFLG, catchcnFLG = catchcnFLG, rescale = '1', rsttime = self.common_in['yyyymmddhh'], \ - RESTART_ID = self.surf_in['restart_id'], RESTART_PATH = self.surf_in['restart_path'], \ - RESTART_DOMAIN = self.surf_in['restart_domain'], CN_VERSION = self.surf_in['cn_version'] ) - print(os.getcwd()) - catch2 = open('mk_catch.j.2','wt') - catch2.write(catch2script) - catch2.close() - - subprocess.call('sbatch -W mk_catch.j.2', shell= True) - From 9b240d1e8fe8d4406964bbcb84ca3e98b289be1d Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Tue, 26 Oct 2021 08:29:25 -0400 Subject: [PATCH 04/70] first working version for upperair and surface --- GEOS_Util/post/regrid.py | 4 +- GEOS_Util/post/regrid.yaml | 18 ++- GEOS_Util/post/regrider_base.py | 260 +++++++++++++++++++++++++++---- GEOS_Util/post/regrider_surf.py | 88 +++++++++-- GEOS_Util/post/regrider_upper.py | 166 +++++++++++++++++++- 5 files changed, 489 insertions(+), 47 deletions(-) diff --git a/GEOS_Util/post/regrid.py b/GEOS_Util/post/regrid.py index 94534f51..f86d0c42 100644 --- a/GEOS_Util/post/regrid.py +++ b/GEOS_Util/post/regrid.py @@ -15,8 +15,8 @@ config = yaml.full_load(stream) # upper air -# upper = upperair(config) -# upper.regrid() + upper = upperair(config) + upper.regrid() # surface surf = surface(config) diff --git a/GEOS_Util/post/regrid.yaml b/GEOS_Util/post/regrid.yaml index 33293b9d..475c4d89 100644 --- a/GEOS_Util/post/regrid.yaml +++ b/GEOS_Util/post/regrid.yaml @@ -7,7 +7,7 @@ restarts_in: openwater: openwater_internal_rst lake: lake_internal_rst landice: landice_internal_rst - #salwater: saltwater_internal_rst + #saltwater: saltwater_internal_rst seaice: seaicethermo_internal_rst catchcnclm40: catch: catch_internal_rst @@ -18,16 +18,18 @@ options_in: expid: agrid: C48 ogrid: 360x180 - tag: Icarus_Reynolds + tag: ICA rstdir: /gpfsm/dnb44/mathomp4/Restarts-J10/nc4/Reynolds/c48 rst_src: MERR-2 + #bc_base: /discover/nobackup/ltakacs/bcs + bc_base: /discover/nobackup/projects/gmao/share/gmao_ops/fvInput/g5gcm/bcs + UPPERAIR: nlevel: 72 SURFACE: wemin: 26 - surflay: 50 - zoom: 1 - rescale: 1 + surflayd: 50 + zoom: 8 catchcnFLG: 1 restart_path: restart_id: @@ -41,15 +43,15 @@ options_out: COMMON: yyyymmddhh: 2000041421 expid: c90e - tag: Icarus-NLv3_MERRA-2 - agrid: 90x540 + tag: INL + agrid: C90 ogrid: 1440x720 outdir: /discover/nobackup/wjiang/test_regridpy/ + bc_base: /discover/nobackup/projects/gmao/share/gmao_ops/fvInput/g5gcm/bcs UPPERAIR: nlevel: 72 SURFACE: wemout: 13 - surflay: 50 CS: dyn2dyn.x: interp_restarts.x: diff --git a/GEOS_Util/post/regrider_base.py b/GEOS_Util/post/regrider_base.py index 6d85a602..5c5a18b4 100644 --- a/GEOS_Util/post/regrider_base.py +++ b/GEOS_Util/post/regrider_base.py @@ -4,22 +4,7 @@ import subprocess import shutil import glob - -tags_to_bcs ={"Icarus_Reynolds": "/discover/nobackup/projects/gmao/share/gmao_ops/fvInput/g5gcm/bcs/Icarus_Updated/Icarus_Reynolds/", - "Icarus-NLv3_MERRA-2": "/discover/nobackup/projects/gmao/share/gmao_ops/fvInput/g5gcm/bcs/Icarus-NLv3/Icarus-NLv3_MERRA-2/"} - -def grid_to_string(grid): - if(grid[0] == 'C'): - n = int(grid[1:]) - return f'CF{n:04d}x6C' - else: - xy = grid.upper().split('X') - x = int(xy[0]) - y = int(xy[1]) - if (y/x == 6) : - return f'CF{x:04d}x6C' - else: - return f'DE{x:04d}xPE{y:04d}' +import time class regrider: def __init__(self, config): @@ -27,17 +12,238 @@ def __init__(self, config): self.common_out = config['options_out']['COMMON'] self.restarts_in = config['restarts_in'] self.slurm_options = config['slurm_options'] + # check input grid from fvcore + #fvrstX = .... ToDo + + self.init_tags_to_bctags() + self.in_bcsdir = self.get_bcdir("IN") + self.in_til = glob.glob(self.in_bcsdir+ '/*-Pfafstetter.til')[0] + self.out_bcsdir = self.get_bcdir("OUT") + self.out_til = glob.glob(self.out_bcsdir+ '/*-Pfafstetter.til')[0] + + def init_tags_to_bctags(self): + # copy and paste from regrid.pl + # minor change. Add "D" to the number for each group + # BCS Tag: Fortuna-1_4 + F14 = ( 'F14', 'Fortuna-1_4', 'Fortuna-1_4_p1' ) + D214 = ( 'D214', 'GEOSdas-2_1_4', 'GEOSdas-2_1_4-m1', + 'GEOSdas-2_1_4-m2', 'GEOSdas-2_1_4-m3', 'GEOSdas-2_1_4-m4' ) + D540 = ( 'D540', 'GEOSadas-5_4_0', 'GEOSadas-5_4_0_p1', + 'GEOSadas-5_4_0_p2', 'GEOSadas-5_4_0_p3', 'GEOSadas-5_4_0_p4', + 'GEOSadas-5_4_1', 'GEOSadas-5_4_1_p1', 'GEOSadas-5_4_2', + 'GEOSadas-5_4_3', 'GEOSadas-5_4_4', 'GEOSadas-5_5_0', + 'GEOSadas-5_5_1', 'GEOSadas-5_5_2', 'GEOSadas-5_5_3' ) + + # BCS Tag: Fortuna-2_0 + #--------------------- + F20 = ( 'F20', 'Fortuna-2_0') + + # BCS Tag: Fortuna-2_1 + #--------------------- + F21 = ( 'F21', 'Fortuna-2_1', 'Fortuna-2_1_p1', + 'Fortuna-2_1_p2', 'Fortuna-2_1_p3', 'Fortuna-2_2', + 'Fortuna-2_2_p1', 'Fortuna-2_2_p2', 'Fortuna-2_3', + 'Fortuna-2_3_p1', 'Fortuna-2_4', 'Fortuna-2_4_p1', + 'Fortuna-2_4_p2', 'Fortuna-2_5', 'Fortuna-2_5_BETA0', + 'Fortuna-2_5_p1', 'Fortuna-2_5_p2', 'Fortuna-2_5_p3', + 'Fortuna-2_5_p4', 'Fortuna-2_5_p5', 'Fortuna-2_5_p6', + 'Fortuna-2_5_pp2' ) + D561 = ( 'D561', 'GEOSadas-5_6_1', 'GEOSadas-5_6_1_p1', + 'GEOSadas-5_6_1_p2', 'GEOSadas-5_6_1_p3', 'GEOSadas-5_6_1_p4', + 'GEOSadas-5_6_2', 'GEOSadas-5_6_2_p1', 'GEOSadas-5_6_2_p2', + 'GEOSadas-5_6_2_p3', 'GEOSadas-5_6_2_p4', 'GEOSadas-5_6_2_p5', + 'GEOSadas-5_6_2_p6', 'GEOSadas-5_7_1', 'GEOSadas-5_7_1_p1', + 'GEOSadas-5_7_1_p2', 'GEOSadas-5_7_2', 'GEOSadas-5_7_2_p1', + 'GEOSadas-5_7_2_p2', 'GEOSadas-5_7_2_p2_m1','GEOSadas-5_7_2_p3', + 'GEOSadas-5_7_2_p3_m1', 'GEOSadas-5_7_2_p3_m2','GEOSadas-5_7_2_p4', + 'GEOSadas-5_7_2_p5', 'GEOSadas-5_7_2_p5_m1','GEOSadas-5_7_3', + 'GEOSadas-5_7_3_p1', 'GEOSadas-5_7_3_p2', 'GEOSadas-5_7_3_p2' ) + + # BCS Tag: Ganymed-1_0 + #--------------------- + G10 = ( 'G10', 'Ganymed-1_0', 'Ganymed-1_0_BETA', + 'Ganymed-1_0_BETA1', 'Ganymed-1_0_BETA2', 'Ganymed-1_0_BETA3', + 'Ganymed-1_0_BETA4' ) + + D580 = ( 'D580', 'GEOSadas-5_8_0', 'GEOSadas-5_9_0', + 'GEOSadas-5_9_1' ) + + # BCS Tags: Ganymed-1_0_M and Ganymed-1_0_D + #------------------------------------------ + G10p = ( 'G10p', 'Ganymed-1_0_p1', 'Ganymed-1_0_p2', + 'Ganymed-1_0_p3', 'Ganymed-1_0_p4', 'Ganymed-1_0_p5', + 'Ganymed-1_0_p6' ) + + D591p= ( 'D591p', 'GEOSadas-5_9_1_p1', 'GEOSadas-5_9_1_p2', + 'GEOSadas-5_9_1_p3', 'GEOSadas-5_9_1_p4', 'GEOSadas-5_9_1_p5', + 'GEOSadas-5_9_1_p6', 'GEOSadas-5_9_1_p7', 'GEOSadas-5_9_1_p8', + 'GEOSadas-5_9_1_p9' ) + + # BCS Tags: Ganymed-1_0_M and Ganymed-1_0_D w/ new landice rst + #------------------------------------------------------------------------ + G20 = ( 'G20', 'Ganymed-2_0', 'Ganymed-2_1', + 'Ganymed-2_1_p1', 'Ganymed-2_1_p2', 'Ganymed-2_1_p3', + 'Ganymed-2_1_p4', 'Ganymed-2_1_p5', 'Ganymed-2_1_p6' ) + D5A0 = ( 'D5A0', 'GEOSadas-5_10_0', 'GEOSadas-5_10_0_p1' ) + + + # BCS Tags: Ganymed-1_0_Reynolds and Ganymed-1_0_Ostia + #----------------------------------------------------- + G30 = ( 'G30', 'Ganymed-3_0', 'Ganymed-3_0_p1' ) + D5B0 = ( 'D5B0', 'GEOSadas-5_10_0_p2', 'GEOSadas-5_11_0' ) + + # BCS Tags: Ganymed-4_0_Reynolds, Ganymed-4_0_MERRA-2, and Ganymed-4_0_Ostia + #--------------------------------------------------------------------------- + G40 = ( 'G40', 'Ganymed-4_0', 'Ganymed-4_0_p1', + 'Ganymed-4_1', 'Heracles-1_0', 'Heracles-1_1', + 'Heracles-2_0', 'Heracles-2_1', 'Heracles-3_0', + 'Heracles-4_0', 'Heracles-5_4_p3' ) + D512 = ( 'D512', 'GEOSadas-5_12_2', 'GEOSadas-5_12_4', + 'GEOSadas-5_12_4_p1', 'GEOSadas-5_12_4_p2', 'GEOSadas-5_12_4_p3', + 'GEOSadas-5_12_5', 'GEOSadas-5_13_0_p1', 'GEOSadas-5_13_0_p2', + 'GEOSadas-5_13_1', 'GEOSadas-5_16_5' ) + + # BCS Tags: Icarus (New Land Parameters, New Topography) + #--------------------------------------------------------------------------- + ICA = ( 'ICA', 'Icarus', 'Jason' ) + D517 = ( 'D517', 'GEOSadas-5_17_0', 'GEOSadas-5_17_1', 'GEOSadas-5_18_0', + 'GEOSadas-5_18_1', 'GEOSadas-5_18_2', 'GEOSadas-5_18_3', + 'GEOSadas-5_18_3_p1', 'GEOSadas-5_19_0', 'GEOSadas-5_20_0', + 'GEOSadas-5_20_0_p1', 'GEOSadas-5_20_0_p2', 'GEOSadas-5_21_0', + 'GEOSadas-5_21_2', 'GEOSadas-5_21_3_p1', 'GEOSadas-5_22_0', + 'GEOSadas-5_22_0_p1', 'GEOSadas-5_22_0_p2', 'GEOSadas-5_23_0', + 'GEOSadas-5_23_0_p1', 'GEOSadas-5_24_0', 'GEOSadas-5_24_0_p1' ) + + # BCS Tags: Icarus-NLv3 (New Land Parameters) + #--------------------------------------------------------------------------- + INL = ( 'INL', 'Icarus-NL', 'Icarus-NLv3', 'Jason-NL' ) + + self.bcsTag={} + for tag in F14: self.bcsTag[tag]= "Fortuna-1_4" + for tag in F20: self.bcsTag[tag]= "Fortuna-2_0" + for tag in F21: self.bcsTag[tag]= "Fortuna-2_1" + for tag in G10: self.bcsTag[tag]= "Ganymed-1_0" + for tag in G10p: self.bcsTag[tag]= "Ganymed-1_0_M" + for tag in G20: self.bcsTag[tag]= "Ganymed-1_0_M" + for tag in G30: self.bcsTag[tag]= "Ganymed-1_0_Reynolds" + for tag in G40: self.bcsTag[tag]= "Ganymed-4_0_Reynolds" + for tag in ICA: self.bcsTag[tag]= "Icarus_Reynolds" + for tag in INL: self.bcsTag[tag]= "Icarus-NLv3_Reynolds" - # deduce the options - agrid_str = grid_to_string(self.common_in['agrid']) - ogrid_str = grid_to_string(self.common_in['ogrid']) - ao_str = agrid_str + '_' + ogrid_str - self.in_bcsdir = tags_to_bcs[self.common_in['tag']] + ao_str - self.in_til = self.in_bcsdir + '/'+ao_str + '-Pfafstetter.til' - agrid_str = grid_to_string(self.common_out['agrid']) - ogrid_str = grid_to_string(self.common_out['ogrid']) - ao_str = agrid_str + '_' + ogrid_str - self.out_bcsdir = tags_to_bcs[self.common_out['tag']] + ao_str - self.out_til = self.out_bcsdir + '/'+ao_str + '-Pfafstetter.til' + for tag in D214: self.bcsTag[tag]= "Fortuna-1_4" + for tag in D540: self.bcsTag[tag]= "Fortuna-1_4" + for tag in D561: self.bcsTag[tag]= "Fortuna-2_1" + for tag in D580: self.bcsTag[tag]= "Ganymed-1_0" + for tag in D591p: self.bcsTag[tag]= "Ganymed-1_0_M" + for tag in D5A0: self.bcsTag[tag]= "Ganymed-1_0_M" + for tag in D5B0: self.bcsTag[tag]= "Ganymed-1_0_Reynolds" + for tag in D512: self.bcsTag[tag]= "Ganymed-4_0_Reynolds" + for tag in D517: self.bcsTag[tag]= "Icarus_Reynolds" + + self.tagsRank ={} + self.tagsRank['Fortuna-1_4'] = 1 + self.tagsRank['Fortuna-1_5'] = 2 + self.tagsRank['Fortuna-2_0'] = 3 + self.tagsRank['Fortuna-2_1'] = 4 + self.tagsRank['Ganymed-1_0'] = 5 + self.tagsRank['Ganymed-1_0_m1'] = 6 + self.tagsRank['Ganymed-1_0_m2'] = 7 + self.tagsRank['Ganymed-1_0_M'] = 8 + self.tagsRank['Ganymed-1_0_D'] = 9 + self.tagsRank['Ganymed-1_0_Reynolds'] = 10 + self.tagsRank['Ganymed-1_0_Ostia'] = 11 + self.tagsRank['Ganymed-4_0_Reynolds'] = 12 + self.tagsRank['Ganymed-4_0_Ostia'] = 13 + self.tagsRank['Ganymed-4_0_MERRA-2'] = 14 + self.tagsRank['Icarus_Reynolds'] = 15 + self.tagsRank['Icarus_MERRA-2'] = 16 + self.tagsRank['Icarus_Ostia'] = 17 + self.tagsRank['Icarus-NLv3_Reynolds'] = 18 + self.tagsRank['Icarus-NLv3_MERRA-2'] = 19 + self.tagsRank['Icarus-NLv3_Ostia'] = 20 + + def get_bcdir(self, opt): + tag = self.common_in['tag'] + bc_base = self.common_in['bc_base'] + ogrid = self.common_in['ogrid'] + if opt.upper() == "OUT": + tag = self.common_out['tag'] + bc_base = self.common_out['bc_base'] + ogrid = self.common_out['ogrid'] + bctag = self.get_bcTag(tag,ogrid) + + tagrank = self.tagsRank[bctag] + if (tagrank >= self.tagsRank['Icarus-NLv3_Reynolds']) : + bcdir = bc_base+'/Icarus-NLv3/'+bctag+'/' + elif (tagrank >= self.tagsRank['Icarus_Reynolds']): + if bc_base == '/discover/nobackup/projects/gmao/share/gmao_ops/fvInput/g5gcm/bcs' : + bcdir = bc_base+'/Icarus_Updated/'+bctag+'/' + else: + bcdir = bc_base+'/Icarus/'+bctag+'/' + elif(tagrank >= self.tagsRank["Ganymed-4_0_Reynolds"]): + bcdir = bc_base + '/Ganymed-4_0/'+bctag+'/' + else: + bcdir = bc_base + '/' + bctag + if not os.path.exists(bcdir): + print( "Cannot find bc dir " + bcdir) + exit() + + gridStr = self.get_grid_subdir(bcdir,opt) + bcdir = bcdir + '/' + gridStr + + return bcdir + + def get_grid_subdir(self, bcdir, opt): + + def get_name_with_grid( grid, names): + if not grid : + return names + namex = [] + if (grid[0].upper() == 'C'): + n = int(grid[1:]) + s1 =f'{n}x6C' + j=n*6 + s2 =str(n) + s3 =str(j) + # first try + for name in names: + if (name.find(s1) != -1): + namex.append(name) + if len(namex) ==0: + for name in names: + if (name.find(s2) != -1 and name.find(s3) != -1): namex.append(name) + else: + xy = grid.upper().split('X') + s2 = xy[0] + s3 = xy[1] + for name in names: + if (name.find(s2) != -1 and name.find(s3) != -1): namex.append(name) + return namex + + dirnames = [ f.name for f in os.scandir(bcdir) if f.is_dir()] + agrid_ = self.common_in['agrid'] + ogrid_ = self.common_in['ogrid'] + if opt.upper() == "OUT" : + agrid_ = self.common_out['agrid'] + ogrid_ = self.common_out['ogrid'] + + anames = get_name_with_grid(agrid_, dirnames) + gridID = get_name_with_grid(ogrid_, anames) + if len(gridID) ==0 or len(gridID) >=2 : + print(" cannot find the grid string: " + bcdir) + return gridID[0] + + def get_bcTag(self, tag, ogrid): + bctag = self.bcsTag[tag] + if ogrid[0].upper() == "C": + bctag=bctag.replace('_Reynolds','_Ostia') + else: + xy = ogrid.upper().split('X') + x = int(xy[0]) + if x == 1440: bctag=bctag.replace('_Reynolds','_MERRA-2') + if x == 2800: + bctag=bctag.replace('_Reynolds','_Ostia') + bctag=bctag.replace('_M','_D') + return bctag diff --git a/GEOS_Util/post/regrider_surf.py b/GEOS_Util/post/regrider_surf.py index 97de38ab..36e7dee3 100644 --- a/GEOS_Util/post/regrider_surf.py +++ b/GEOS_Util/post/regrider_surf.py @@ -26,6 +26,17 @@ def __init__(self, config): self.catch = self.restarts_in.get('catch') self.catchcnclm40 = self.restarts_in.get('catchcnclm40') self.catchcnclm45 = self.restarts_in.get('catchcnclm45') + tagout = config['options_out']['COMMON']['tag'] + ogrid = config['options_out']['COMMON']['ogrid'] + bctag = self.get_bcTag(tagout, ogrid) + tagrank = self.tagsRank[bctag] + + self.surf_out['surflay'] = 20. + if tagrank >=12 : + self.surf_out['surflay'] = 50. + self.surf_in['rescale'] = 0 + if tagrank > self.tagsRank["Fortuna-2_0"]: + self.surf_in['rescale'] = 1 def regrid(self): bindir = os.getcwd() @@ -93,6 +104,7 @@ def regrid(self): if ( self.catchcnclm40 or self.catchcnclm45) : dirname = os.path.dirname(self.out_til) clsm = dirname+'/clsm' + print( "symbolic link clsm to OutData/clsm") os.symlink(clsm, 'OutData/clsm') mk_catch_j_template = """#!/bin/csh -f @@ -110,6 +122,8 @@ def regrid(self): #limit stacksize unlimited unlimit +set lakelandRestartX = ( {Bin}/mk_LakeLandiceSaltRestarts ) +set routRestartX = ( {Bin}/mk_RouteRestarts ) set esma_mpirun_X = ( {Bin}/esma_mpirun -np 84 ) set mk_CatchRestarts_X = ( $esma_mpirun_X {Bin}/mk_CatchRestarts ) set mk_CatchCNRestarts_X = ( $esma_mpirun_X {Bin}/mk_CatchCNRestarts ) @@ -119,6 +133,31 @@ def regrid(self): set OUT_til = OutData/*.til set IN_til = InData/*.til + +if ( {saltwaterFLG}) then + $lakelandRestartX $OUT_til $IN_til InData/{saltwater} 0 {zoom} +endif + +if ( {openwaterFLG}) then + $lakelandRestartX $OUT_til $IN_til InData/{openwater} 0 {zoom} +endif + +if ( {seaiceFLG}) then + $lakelandRestartX $OUT_til $IN_til InData/{seaice} 0 {zoom} +endif + +if ( {lakeFLG}) then + $lakelandRestartX $OUT_til $IN_til InData/{lake} 19 {zoom} +endif + +if ( {landiceFLG}) then + $lakelandRestartX $OUT_til $IN_til InData/{landice} 20 {zoom} +endif + +if ( {routeFLG}) then + $routeRestartX $OUT_til {yyyymm} +endif + if ({catchFLG}) then set catchIN = InData/*catch_internal_rst* set params = ( $OUT_til $IN_til $catchIN {surflay} ) @@ -166,24 +205,39 @@ def regrid(self): mv $catchcn_scaled $catchcn_regrid endif endif -exit """ + saltwaterFLG = '1' if self.saltwater else '0' + openwaterFLG = '1' if self.openwater else '0' + seaiceFLG = '1' if self.seaice else '0' + landiceFLG = '1' if self.landice else '0' + lakeFLG = '1' if self.lake else '0' + routeFLG = '1' if self.route else '0' + + catchFLG = '1' if self.catch else '0' catchcnFLG = '1' if (self.catchcnclm40 or self.catchcnclm45) else '0' catch1script = mk_catch_j_template.format(Bin = bindir, account = self.slurm_options['account'], \ - outdir = outdir, mk_catch_log = 'mk_catch_log.1', surflay = self.surf_in['surflay'], \ + outdir = outdir, mk_catch_log = 'mk_catch_log.1', surflay = self.surf_out['surflay'], \ wemin = self.surf_in['wemin'], wemout = self.surf_out['wemout'] , \ fromGCM = '0', catchFLG = catchFLG, catchcnFLG = catchcnFLG, rescale = '0', rsttime = self.common_in['yyyymmddhh'], \ RESTART_ID = self.surf_in['restart_id'], RESTART_PATH = self.surf_in['restart_path'], \ - RESTART_DOMAIN = self.surf_in['restart_domain'], CN_VERSION = self.surf_in['cn_version'] ) - print(os.getcwd()) + RESTART_DOMAIN = self.surf_in['restart_domain'], CN_VERSION = self.surf_in['cn_version'], \ + saltwaterFLG = saltwaterFLG, saltwater = self.saltwater, \ + openwaterFLG = openwaterFLG, openwater = self.openwater, \ + seaiceFLG = seaiceFLG, seaice = self.seaice, \ + landiceFLG = landiceFLG, landice = self.landice, \ + lakeFLG = lakeFLG, lake = self.lake, \ + routeFLG = routeFLG, route = self.route, yyyymm = str(self.common_in['yyyymmddhh'])[0:6], \ + zoom = self.surf_in['zoom'] ) catch1 = open('mk_catch.j.1','wt') catch1.write(catch1script) catch1.close() + print("step 1: sbatch -W mk_catch.j.1") subprocess.call('sbatch -W mk_catch.j.1', shell= True) # step 2 + if (self.surf_in['rescale'] and ( self.catch or self.catchcnclm40 or self.catchcnclm45)) : if os.path.exists('InData.step1') : subprocess.call('rm -rf InData.step1', shell = True) shutil.move('InData', 'InData.step1') @@ -197,16 +251,32 @@ def regrid(self): clsm = dirname+'/clsm' os.symlink(clsm, 'OutData/clsm') + saltwaterFLG = '0' + openwaterFLG = '0' + seaiceFLG = '0' + landiceFLG = '0' + lakeFLG = '0' + routeFLG = '0' catch2script = mk_catch_j_template.format(Bin = bindir, account = self.slurm_options['account'], \ - outdir = outdir, mk_catch_log = 'mk_catch_log.2', surflay = self.surf_in['surflay'], \ + outdir = outdir, mk_catch_log = 'mk_catch_log.2', surflay = self.surf_out['surflay'], \ wemin = self.surf_in['wemin'], wemout = self.surf_out['wemout'] , \ fromGCM = '0', catchFLG = catchFLG, catchcnFLG = catchcnFLG, rescale = '1', rsttime = self.common_in['yyyymmddhh'], \ RESTART_ID = self.surf_in['restart_id'], RESTART_PATH = self.surf_in['restart_path'], \ - RESTART_DOMAIN = self.surf_in['restart_domain'], CN_VERSION = self.surf_in['cn_version'] ) - print(os.getcwd()) + RESTART_DOMAIN = self.surf_in['restart_domain'], CN_VERSION = self.surf_in['cn_version'], \ + saltwaterFLG = saltwaterFLG, saltwater = self.saltwater, \ + openwaterFLG = openwaterFLG, openwater = self.openwater, \ + seaiceFLG = seaiceFLG, seaice = self.seaice, \ + landiceFLG = landiceFLG, landice = self.landice, \ + lakeFLG = lakeFLG, lake = self.lake, \ + routeFLG = routeFLG, route = self.route, yyyymm = str(self.common_in['yyyymmddhh'])[0:6], \ + zoom = self.surf_in['zoom'] ) catch2 = open('mk_catch.j.2','wt') catch2.write(catch2script) catch2.close() - + print("step 2: sbatch -W mk_catch.j.2") subprocess.call('sbatch -W mk_catch.j.2', shell= True) - + cwd = os.getcwd() + for out_rst in glob.glob("OutData/*_rst*"): + filename = os.path.basename(out_rst) + shutil.move(out_rst, cwd+"/"+filename) + os.chdir(bindir) diff --git a/GEOS_Util/post/regrider_upper.py b/GEOS_Util/post/regrider_upper.py index 18b2398d..fe1db172 100644 --- a/GEOS_Util/post/regrider_upper.py +++ b/GEOS_Util/post/regrider_upper.py @@ -9,5 +9,169 @@ class upperair(regrider): def __init__(self, config): super().__init__(config) + self.upper_out = config['options_out']['UPPERAIR'] + self.common_out = config['options_out']['COMMON'] + tagout = self.common_out['tag'] + ogrid = self.common_out['ogrid'] + bctag = self.get_bcTag(tagout, ogrid) + tagrank = self.tagsRank[bctag] + + self.upper_out['drymassFLG'] = 0 + if tagrank >=12 : + self.upper_out['drymassFLG'] = 1 + + agrid = self.common_out['agrid'] + if agrid[0].upper() == 'C': + self.upper_out['imout']= int(agrid[1:]) + else: + print("Only support cs grid so far") + exit() + + imout = self.upper_out['imout'] + if (imout <=90): + self.upper_out['NPE'] = 12; self.upper_out['nwrit'] = 1 + elif (imout==180): + self.upper_out['NPE'] = 24; self.upper_out['nwrit'] = 1 + elif (imout<=500): + self.upper_out['NPE'] = 96; self.upper_out['nwrit'] = 1 + elif (imout==720): + self.upper_out['NPE'] = 192; self.upper_out['nwrit'] = 2 + elif (imout==1000): + self.upper_out['NPE'] = 384; self.upper_out['nwrit'] = 2 + elif (imout==1440): + self.upper_out['NPE'] = 576; self.upper_out['nwrit'] = 2 + elif (imout==2000): + self.upper_out['NPE'] = 768; self.upper_out['nwrit'] = 2 + elif (imout>=2880): + self.upper_out['NPE'] = 5400; self.upper_out['nwrit'] = 6 + + self.upper_out['QOS'] = "#" + if self.upper_out['NPE'] <= 532: self.upper_out['QOS'] = "#SBATCH --qos=debug" + def regrid(self): - ... + print( "Regridding upper air......\n") + bindir = os.getcwd() + outdir = self.common_out['outdir'] + if not os.path.exists(outdir) : os.makedirs(outdir) + print( "cd " + self.common_out['outdir']) + os.chdir(self.common_out['outdir']) + tmpdir = outdir+'/upper_data/' + if os.path.exists(tmpdir) : subprocess.call('rm -rf '+ tmpdir, shell = True) + print ("mkdir " + tmpdir) + os.makedirs(tmpdir) + + print( "cd " + tmpdir) + os.chdir(tmpdir) + rst_dir = self.common_in['rstdir'] + for key, rst in self.restarts_in['UPPERAIR'].items(): + if (rst): + rst_in = "_internal_restart_in" + if rst.find('import') != -1 : + rst_in = "_import_restart_in" + cmd = '/bin/ln -s '+rst_dir+'/'+rst+' '+key+rst_in + print(cmd) + subprocess.call(cmd, shell = True) + # link topo file + topoin = glob.glob(self.in_bcsdir+'/topo_DYN_ave*')[0] + cmd = '/bin/ln -s ' + topoin + print(cmd) + subprocess.call(cmd, shell = True) + + topoout = glob.glob(self.out_bcsdir+'/topo_DYN_ave*')[0] + cmd = '/bin/ln -s ' + topoout + print(cmd) + subprocess.call(cmd, shell = True) + cmd = '/bin/ln -s ' + topoout + ' topo_dynave.data' + print(cmd) + subprocess.call(cmd, shell = True) + + regrid_template="""#!/bin/csh -xf +#!/bin/csh -xf +#SBATCH --account={account} +#SBATCH --time=1:00:00 +#SBATCH --ntasks={NPE} +#SBATCH --job-name=regrid_upper +#SBATCH --output={outdir}/{out_log} +{QOS} + +unlimit + +cd {outdir}/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 +# HYDROSTATIC = 0 which means HYDROSTATIC = FALSE +set HYDROSTATIC = 0 + +if ($?I_MPI_ROOT) then + # intel scaling suggestions + #-------------------------- + + setenv I_MPI_DAPL_UD on + + setenv DAPL_UCM_CQ_SIZE 4096 + setenv DAPL_UCM_QP_SIZE 4096 + + setenv I_MPI_DAPL_UD_SEND_BUFFER_NUM 4096 + setenv I_MPI_DAPL_UD_RECV_BUFFER_NUM 4096 + setenv I_MPI_DAPL_UD_ACK_SEND_POOL_SIZE 4096 + setenv I_MPI_DAPL_UD_ACK_RECV_POOL_SIZE 4096 + setenv I_MPI_DAPL_UD_RNDV_EP_NUM 2 + setenv I_MPI_DAPL_UD_REQ_EVD_SIZE 2000 + + setenv DAPL_UCM_REP_TIME 2000 + setenv DAPL_UCM_RTU_TIME 2000 + setenv DAPL_UCM_RETRY 7 + setenv DAPL_ACK_RETRY 7 + setenv DAPL_ACK_TIMER 20 + setenv DAPL_UCM_RETRY 10 + setenv DAPL_ACK_RETRY 10 + +else if ($?MVAPICH2) then + setenv MV2_ENABLE_AFFINITY 0 + +endif +set infiles = () +set outfils = () +foreach infile ( *_restart_in ) + if ( $infile == fvcore_internal_restart_in ) continue + if ( $infile == moist_internal_restart_in ) continue + + set infiles = ( $infiles $infile ) + set outfil = `echo $infile | sed "s/restart_in/rst_out/"` + set outfils = ($outfils $outfil) +end + +if ( $#infiles ) then + set ioflag = "-input_files $infiles -output_files $outfils" +else + set ioflag = "" +endif + +set drymassFLG = {drymassFLG} +if ($drymassFLG) then + set dmflag = "" +else + set dmflag = "-scalers F" +endif + +set interp_restartsX = {Bin}/interp_restarts.x + +{Bin}/esma_mpirun -np {NPE} $interp_restartsX -im {imout} -lm {nlevel} \\ + -do_hydro $HYDROSTATIC $ioflag $dmflag -nwriter {nwrit} + +""" + regrid_upper_script = regrid_template.format(Bin=bindir, account = self.slurm_options['account'], \ + outdir = outdir, out_log = 'regrid_upper_log', drymassFLG = self.upper_out['drymassFLG'], \ + imout = self.upper_out['imout'], nwrit = self.upper_out['nwrit'], NPE = self.upper_out['NPE'], \ + QOS = self.upper_out['QOS'], nlevel = self.upper_out['nlevel']) + upper = open('regrider_upper.j','wt') + upper.write(regrid_upper_script) + upper.close() + print('sbatch -W regrider_upper.j\n') + subprocess.call('sbatch -W regrider_upper.j', shell= True) + for out_rst in glob.glob("*_rst*"): + shutil.move(out_rst, "../") + print('cd '+bindir) + os.chdir(bindir) From a2049e2cc6e1295325508bd5c79c5c76d33fd83d Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Wed, 3 Nov 2021 15:10:00 -0400 Subject: [PATCH 05/70] change config yaml --- GEOS_Util/post/regrid.yaml | 87 +++++++++++++++----------------- GEOS_Util/post/regrider_base.py | 42 ++++++++++----- GEOS_Util/post/regrider_surf.py | 8 +-- GEOS_Util/post/regrider_upper.py | 24 +++++++-- 4 files changed, 95 insertions(+), 66 deletions(-) diff --git a/GEOS_Util/post/regrid.yaml b/GEOS_Util/post/regrid.yaml index 475c4d89..cab40eec 100644 --- a/GEOS_Util/post/regrid.yaml +++ b/GEOS_Util/post/regrid.yaml @@ -1,4 +1,5 @@ -restarts_in: +input: + restarts: UPPERAIR: fvcore: fvcore_internal_rst moist: moist_internal_rst @@ -11,51 +12,45 @@ restarts_in: seaice: seaicethermo_internal_rst catchcnclm40: catch: catch_internal_rst + parameters: + COMMON: + yyyymmddhh: 2000041421 + expid: + agrid: C48 + ogrid: 360x180 + tag: ICA + rstdir: /gpfsm/dnb44/mathomp4/Restarts-J10/nc4/Reynolds/c48 + #rst_src: MERRA-2 + tarfile: + bc_base: discover_ops + #bc_base: discover_lt -options_in: - COMMON: - yyyymmddhh: 2000041421 - expid: - agrid: C48 - ogrid: 360x180 - tag: ICA - rstdir: /gpfsm/dnb44/mathomp4/Restarts-J10/nc4/Reynolds/c48 - rst_src: MERR-2 - #bc_base: /discover/nobackup/ltakacs/bcs - bc_base: /discover/nobackup/projects/gmao/share/gmao_ops/fvInput/g5gcm/bcs + UPPERAIR: + nlevel: 72 + SURFACE: + wemin: 26 + zoom: 8 + catchcnFLG: 1 + restart_path: + restart_id: + restart_domain: + cn_version: - UPPERAIR: - nlevel: 72 - SURFACE: - wemin: 26 - surflayd: 50 - zoom: 8 - catchcnFLG: 1 - restart_path: - restart_id: - restart_domain: - cn_version: - CS: - bbb: - ccc: - -options_out: - COMMON: - yyyymmddhh: 2000041421 - expid: c90e - tag: INL - agrid: C90 - ogrid: 1440x720 - outdir: /discover/nobackup/wjiang/test_regridpy/ - bc_base: /discover/nobackup/projects/gmao/share/gmao_ops/fvInput/g5gcm/bcs - UPPERAIR: - nlevel: 72 - SURFACE: - wemout: 13 - CS: - dyn2dyn.x: - interp_restarts.x: +output: + parameters: + COMMON: + expid: c90e + tag: INL + agrid: C90 + ogrid: 1440x720 + outdir: /discover/nobackup/wjiang/test_regridpy/ + bc_base: discover_ops + UPPERAIR: + #ak, bk + nlevel: 72 + SURFACE: + wemout: 13 slurm_options: - account: s1873 - qos: debug - partition: + account: s1873 + qos: debug + partition: diff --git a/GEOS_Util/post/regrider_base.py b/GEOS_Util/post/regrider_base.py index 5c5a18b4..6447c2a3 100644 --- a/GEOS_Util/post/regrider_base.py +++ b/GEOS_Util/post/regrider_base.py @@ -8,20 +8,23 @@ class regrider: def __init__(self, config): - self.common_in = config['options_in']['COMMON'] - self.common_out = config['options_out']['COMMON'] - self.restarts_in = config['restarts_in'] + self.common_in = config['input']['parameters']['COMMON'] + self.restarts_in = config['input']['restarts'] + self.common_out = config['output']['parameters']['COMMON'] self.slurm_options = config['slurm_options'] - # check input grid from fvcore - #fvrstX = .... ToDo - self.init_tags_to_bctags() + self.init_tags() + + # get bc directory and tile file self.in_bcsdir = self.get_bcdir("IN") self.in_til = glob.glob(self.in_bcsdir+ '/*-Pfafstetter.til')[0] self.out_bcsdir = self.get_bcdir("OUT") self.out_til = glob.glob(self.out_bcsdir+ '/*-Pfafstetter.til')[0] - def init_tags_to_bctags(self): + #ToDo + # 1) get rst source + + def init_tags(self): # copy and paste from regrid.pl # minor change. Add "D" to the number for each group # BCS Tag: Fortuna-1_4 @@ -163,13 +166,28 @@ def init_tags_to_bctags(self): self.tagsRank['Icarus-NLv3_MERRA-2'] = 19 self.tagsRank['Icarus-NLv3_Ostia'] = 20 + self.bcbase={} + self.bcbase['discover_ops'] = "/discover/nobackup/projects/gmao/share/gmao_ops/fvInput/g5gcm/bcs" + self.bcbase['discover_lt'] = "/discover/nobackup/ltakacs/bcs" + + def get_bcbase(self, opt): + base = '' + if opt.upper() == 'IN': + base = self.common_in.get('bc_base') + if opt.upper() == 'OUT': + base = self.common_out.get('bc_base') + assert base, 'please specify bc_base: discover_ops, discover_lt or an absolute path' + if base == 'discover_ops' or base == 'discover_lt': + return self.bcbase[base] + else: + return base + def get_bcdir(self, opt): + bc_base = self.get_bcbase(opt) tag = self.common_in['tag'] - bc_base = self.common_in['bc_base'] ogrid = self.common_in['ogrid'] if opt.upper() == "OUT": tag = self.common_out['tag'] - bc_base = self.common_out['bc_base'] ogrid = self.common_out['ogrid'] bctag = self.get_bcTag(tag,ogrid) @@ -177,10 +195,10 @@ def get_bcdir(self, opt): if (tagrank >= self.tagsRank['Icarus-NLv3_Reynolds']) : bcdir = bc_base+'/Icarus-NLv3/'+bctag+'/' elif (tagrank >= self.tagsRank['Icarus_Reynolds']): - if bc_base == '/discover/nobackup/projects/gmao/share/gmao_ops/fvInput/g5gcm/bcs' : - bcdir = bc_base+'/Icarus_Updated/'+bctag+'/' + if bc_base == self.bcbase['discover_ops']: + bcdir = bc_base+'/Icarus_Updated/'+bctag+'/' else: - bcdir = bc_base+'/Icarus/'+bctag+'/' + bcdir = bc_base+'/Icarus/'+bctag+'/' elif(tagrank >= self.tagsRank["Ganymed-4_0_Reynolds"]): bcdir = bc_base + '/Ganymed-4_0/'+bctag+'/' else: diff --git a/GEOS_Util/post/regrider_surf.py b/GEOS_Util/post/regrider_surf.py index 36e7dee3..07fcd834 100644 --- a/GEOS_Util/post/regrider_surf.py +++ b/GEOS_Util/post/regrider_surf.py @@ -10,8 +10,8 @@ class surface(regrider): def __init__(self, config): super().__init__(config) self.restarts_in = self.restarts_in['SURFACE'] - self.surf_in = config['options_in']['SURFACE'] - self.surf_out = config['options_out']['SURFACE'] + self.surf_in = config['input']['parameters']['SURFACE'] + self.surf_out = config['output']['parameters']['SURFACE'] print("--ToDO--\n") print("split saltwater after some tags(need to rank tag)") @@ -26,8 +26,8 @@ def __init__(self, config): self.catch = self.restarts_in.get('catch') self.catchcnclm40 = self.restarts_in.get('catchcnclm40') self.catchcnclm45 = self.restarts_in.get('catchcnclm45') - tagout = config['options_out']['COMMON']['tag'] - ogrid = config['options_out']['COMMON']['ogrid'] + tagout = self.common_out['tag'] + ogrid = self.common_out['ogrid'] bctag = self.get_bcTag(tagout, ogrid) tagrank = self.tagsRank[bctag] diff --git a/GEOS_Util/post/regrider_upper.py b/GEOS_Util/post/regrider_upper.py index fe1db172..f4015b60 100644 --- a/GEOS_Util/post/regrider_upper.py +++ b/GEOS_Util/post/regrider_upper.py @@ -9,8 +9,23 @@ class upperair(regrider): def __init__(self, config): super().__init__(config) - self.upper_out = config['options_out']['UPPERAIR'] - self.common_out = config['options_out']['COMMON'] + self.upper_out = config['input']['parameters']['UPPERAIR'] + + # verify agrid + cmd = './fvrst.x -h /gpfsm/dnb44/mathomp4/Restarts-J10/nc4/Reynolds/c48/fvcore_internal_rst' + p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) + (output, err) = p.communicate() + p_status = p.wait() + ss = output.decode().split() + agrid = self.common_in['agrid'] + if (agrid): + if agrid[0].upper() == "C": + n=int(agrid[1:]) + o=int(ss[0]) + assert n==o, "input agrid is not consistent with fvcore restart" + else: + self.common_in['agrid'] = "C"+ss[0] + tagout = self.common_out['tag'] ogrid = self.common_out['ogrid'] bctag = self.get_bcTag(tagout, ogrid) @@ -171,7 +186,8 @@ def regrid(self): upper.close() print('sbatch -W regrider_upper.j\n') subprocess.call('sbatch -W regrider_upper.j', shell= True) + cwd = os.getcwd() for out_rst in glob.glob("*_rst*"): - shutil.move(out_rst, "../") - print('cd '+bindir) + filename = os.path.basename(out_rst) + shutil.move(out_rst, cwd+"/"+filename) os.chdir(bindir) From 7f627f18fb2f8ed34ef35575a4cc71e8a1bc02af Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Mon, 8 Nov 2021 14:10:20 -0500 Subject: [PATCH 06/70] add MERRA-2 support --- GEOS_Util/post/regrid.yaml | 11 ++++--- GEOS_Util/post/regrider_base.py | 53 ++++++++++++++++++++++++++++++-- GEOS_Util/post/regrider_surf.py | 2 +- GEOS_Util/post/regrider_upper.py | 37 ++++++++++++---------- 4 files changed, 80 insertions(+), 23 deletions(-) diff --git a/GEOS_Util/post/regrid.yaml b/GEOS_Util/post/regrid.yaml index cab40eec..2901a998 100644 --- a/GEOS_Util/post/regrid.yaml +++ b/GEOS_Util/post/regrid.yaml @@ -9,18 +9,18 @@ input: lake: lake_internal_rst landice: landice_internal_rst #saltwater: saltwater_internal_rst - seaice: seaicethermo_internal_rst + #seaice: seaicethermo_internal_rst catchcnclm40: catch: catch_internal_rst parameters: COMMON: yyyymmddhh: 2000041421 + tag: ICA + rst_src: MERRA-2 expid: agrid: C48 ogrid: 360x180 - tag: ICA - rstdir: /gpfsm/dnb44/mathomp4/Restarts-J10/nc4/Reynolds/c48 - #rst_src: MERRA-2 + rst_dir: /gpfsm/dnb44/mathomp4/Restarts-J10/nc4/Reynolds/c48 tarfile: bc_base: discover_ops #bc_base: discover_lt @@ -40,6 +40,9 @@ output: parameters: COMMON: expid: c90e + #model_config: + #tag: + #couple: tag: INL agrid: C90 ogrid: 1440x720 diff --git a/GEOS_Util/post/regrider_base.py b/GEOS_Util/post/regrider_base.py index 6447c2a3..a129ce25 100644 --- a/GEOS_Util/post/regrider_base.py +++ b/GEOS_Util/post/regrider_base.py @@ -11,18 +11,22 @@ def __init__(self, config): self.common_in = config['input']['parameters']['COMMON'] self.restarts_in = config['input']['restarts'] self.common_out = config['output']['parameters']['COMMON'] + self.upper_in = config['input']['parameters']['UPPERAIR'] + self.upper_out = config['output']['parameters']['UPPERAIR'] self.slurm_options = config['slurm_options'] self.init_tags() + self.init_merra2() + # get bc directory and tile file self.in_bcsdir = self.get_bcdir("IN") self.in_til = glob.glob(self.in_bcsdir+ '/*-Pfafstetter.til')[0] + print("input tile file: " + self.in_til self.out_bcsdir = self.get_bcdir("OUT") self.out_til = glob.glob(self.out_bcsdir+ '/*-Pfafstetter.til')[0] + print("output tile file: " + self.out_til - #ToDo - # 1) get rst source def init_tags(self): # copy and paste from regrid.pl @@ -170,6 +174,51 @@ def init_tags(self): self.bcbase['discover_ops'] = "/discover/nobackup/projects/gmao/share/gmao_ops/fvInput/g5gcm/bcs" self.bcbase['discover_lt'] = "/discover/nobackup/ltakacs/bcs" + def init_merra2(self): + merra2 = self.common_in.get('rst_src') + if merra2 != 'MERRA-2': + return + print("merra-2 source") + yyyymmddhh = str(self.common_in['yyyymmddhh']) + print(type(yyyymmddhh)) + yyyymm = int(yyyymmddhh[0:6]) + if yyyymm < 197901 : + print("Error. MERRA-2 data < 1979 not available\n") + exit() + elif (yyyymm < 199201): + self.common_in['expid'] = "d5124_m2_jan79" + elif (yyyymm < 200106): + self.common_in['expid'] = "d5124_m2_jan91" + elif (yyyymm < 201101): + self.common_in['expid'] = "d5124_m2_jan00" + else: + self.common_in['expid'] = "d5124_m2_jan10" + + self.common_in['agrid'] = 'C180' + self.common_in['ogrid'] = '1440x720' + self.common_in['bc_base']= 'discover_ops' + self.upper_in['nlevel'] = 72 + expid = self.common_in['expid'] + yyyy = yyyymmddhh[0:4] + mm = yyyymmddhh[4:6] + dd = yyyymmddhh[6:8] + hh = yyyymmddhh[8:10] + surfix = yyyymmddhh[0:8]+'_'+hh+'z.bin' + self.common_in['rst_dir'] = '/archive/users/gmao_ops/MERRA2/gmao_ops/GEOSadas-5_12_4/'+expid +'/rs/Y'+yyyy +'/M'+mm + + self.restarts_in['UPPERAIR'] = {} + self.restarts_in['UPPERAIR']['fvcore'] = expid+'.fvcore_internal_rst.' + surfix + self.restarts_in['UPPERAIR']['moist'] = expid+'.moist_internal_rst.' + surfix + self.restarts_in['UPPERAIR']['agcm'] = expid+'.agcm_import_rst.' + surfix + self.restarts_in['UPPERAIR']['gocart'] = expid+'.gocart_internal_rst.' + surfix + self.restarts_in['UPPERAIR']['pchem'] = expid+'.pchem_internal_rst.' + surfix + + self.restarts_in['SURFACE'] = {} + self.restarts_in['SURFACE']['catch'] = expid+'.catch_internal_rst.' + surfix + self.restarts_in['SURFACE']['lake'] = expid+'.lake_internal_rst.' + surfix + self.restarts_in['SURFACE']['landice'] = expid+'.landice_internal_rst.' + surfix + self.restarts_in['SURFACE']['saltwater']= expid+'.saltwater_internal_rst.'+ surfix + def get_bcbase(self, opt): base = '' if opt.upper() == 'IN': diff --git a/GEOS_Util/post/regrider_surf.py b/GEOS_Util/post/regrider_surf.py index 07fcd834..b1ffb633 100644 --- a/GEOS_Util/post/regrider_surf.py +++ b/GEOS_Util/post/regrider_surf.py @@ -52,7 +52,7 @@ def regrid(self): for key, value in self.restarts_in.items(): if not value : continue - src = self.common_in['rstdir']+'/'+value + src = self.common_in['rst_dir']+'/'+value if not os.path.exists(src) : print( "Could not find " + src + "--remove it from yaml config file add to restart dir") exit() diff --git a/GEOS_Util/post/regrider_upper.py b/GEOS_Util/post/regrider_upper.py index f4015b60..cfebb399 100644 --- a/GEOS_Util/post/regrider_upper.py +++ b/GEOS_Util/post/regrider_upper.py @@ -10,24 +10,29 @@ class upperair(regrider): def __init__(self, config): super().__init__(config) self.upper_out = config['input']['parameters']['UPPERAIR'] - + self.restarts_in = self.restarts_in['UPPERAIR'] + # verify agrid - cmd = './fvrst.x -h /gpfsm/dnb44/mathomp4/Restarts-J10/nc4/Reynolds/c48/fvcore_internal_rst' - p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) - (output, err) = p.communicate() - p_status = p.wait() - ss = output.decode().split() agrid = self.common_in['agrid'] - if (agrid): - if agrid[0].upper() == "C": - n=int(agrid[1:]) - o=int(ss[0]) - assert n==o, "input agrid is not consistent with fvcore restart" - else: - self.common_in['agrid'] = "C"+ss[0] + ogrid = self.common_out['ogrid'] + merra_2 = self.common_in.get('rst_src') + if not (merra_2 == 'MERRA-2') : + fvcore = self.common_in['rst_dir']+'/'+self.restarts_in['fvcore'] + cmd = './fvrst.x -h ' + fvcore + print(cmd +'\n') + p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) + (output, err) = p.communicate() + p_status = p.wait() + ss = output.decode().split() + if (agrid): + if agrid[0].upper() == "C": + n=int(agrid[1:]) + o=int(ss[0]) + assert n==o, "input agrid is not consistent with fvcore restart" + else: + self.common_in['agrid'] = "C"+ss[0] tagout = self.common_out['tag'] - ogrid = self.common_out['ogrid'] bctag = self.get_bcTag(tagout, ogrid) tagrank = self.tagsRank[bctag] @@ -77,8 +82,8 @@ def regrid(self): print( "cd " + tmpdir) os.chdir(tmpdir) - rst_dir = self.common_in['rstdir'] - for key, rst in self.restarts_in['UPPERAIR'].items(): + rst_dir = self.common_in['rst_dir'] + for key, rst in self.restarts_in.items(): if (rst): rst_in = "_internal_restart_in" if rst.find('import') != -1 : From b3211fc88082b238b4980cdd92d3f1b3f3e3f462 Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Mon, 8 Nov 2021 15:20:15 -0500 Subject: [PATCH 07/70] add analysis regrid --- GEOS_Util/post/regrid.py | 7 +- GEOS_Util/post/regrider_ana.py | 169 +++++++++++++++++++++++++++++++ GEOS_Util/post/regrider_base.py | 50 +++++---- GEOS_Util/post/regrider_surf.py | 25 +++-- GEOS_Util/post/regrider_upper.py | 21 ++-- 5 files changed, 228 insertions(+), 44 deletions(-) create mode 100644 GEOS_Util/post/regrider_ana.py diff --git a/GEOS_Util/post/regrid.py b/GEOS_Util/post/regrid.py index f86d0c42..a5e5ba80 100644 --- a/GEOS_Util/post/regrid.py +++ b/GEOS_Util/post/regrid.py @@ -7,6 +7,7 @@ from regrider_base import * from regrider_upper import * from regrider_surf import * +from regrider_ana import * if __name__ == '__main__' : @@ -22,8 +23,8 @@ surf = surface(config) surf.regrid() - # what ever -# forcing = force(config) -# forcing.regrid() + # analysis + ana = analysis(config) + ana.regrid() diff --git a/GEOS_Util/post/regrider_ana.py b/GEOS_Util/post/regrider_ana.py new file mode 100644 index 00000000..c0f6b110 --- /dev/null +++ b/GEOS_Util/post/regrider_ana.py @@ -0,0 +1,169 @@ +#!/usr/bin/env python +# +import os +import subprocess +import shutil +import glob +import fileinput +from regrider_base import * + +class analysis(regrider): + def __init__(self, config): + # v3.0 + #super().__init__(config) + # v2.7 + super(analysis, self).__init__(config) + self.ana_in = config['input']['parameters']['ANALYSIS'] + self.bkg = self.ana_in.get('bkg') + if not self.bkg: + return + #ana bkg_eta grid mapping from input atmosphere grid + self.hgrd = {} + self.hgrd['C12'] = 'a' + self.hgrd['C24'] = 'a' + self.hgrd['C48'] = 'b' + self.hgrd['C90'] = 'c' + self.hgrd['C180'] = 'd' + self.hgrd['C360'] = 'd' + self.hgrd['C500'] = 'd' + self.hgrd['C720'] = 'e' + self.hgrd['C1000'] = 'e' + self.hgrd['C1440'] = 'e' + self.hgrd['C2000'] = 'e' + self.hgrd['C2880'] = 'e' + self.hgrd['C5760'] = 'e' + + rst_time = datetime(year=int(self.yyyy), month=int(self.mm), day=int(self.dd), hour = int(self.hh)) + rst_dir_orig = self.common_in['rst_dir'] + expid = self.common_in['expid'] + self.anafiles=[] + for h in [3,4,5,6,7,8,9]: + delt = timedelta(hours = h-3) + new_time = rst_time + delt + yyyy = "Y"+str(new_time.year) + mm = 'M%02d'%new_time.month + ymd = '%04d%02d%02d'%(new_time.year,new_time.month, new_time.day) + hh = '%02d'%h + newhh= '%02d'%new_time.hour + rst_dir = rst_dir_orig.replace('Y'+self.yyyy,yyyy).replace('M'+self.mm,mm) + # bkg files + for ftype in ['sfc', 'eta']: + fname = expid+'.bkg'+hh+'_'+ftype+'_rst.'+ymd+'_'+newhh+'z.nc4' + f = rst_dir+'/'+fname + if(os.path.isfile(f)): + self.anafiles.append(f) + else: + print('Warning: Cannot find '+f) + + # cbkg file + fname = expid + '.cbkg' + hh + '_eta_rst.' + ymd + '_' + newhh + 'z.nc4' + f = rst_dir+'/'+fname + if(os.path.isfile(f)): + self.anafiles.append(f) + else: + print('Warning: Cannot find '+f) + # gaas_bkg_sfc files + if (h==6 or h==9): + fname = expid+'.gaas_bkg_sfc_rst.'+ymd+'_'+newhh+'z.nc4' + f = rst_dir+'/'+fname + if (os.path.isfile(f)): + self.anafiles.append(f) + else: + print('Warning: Cannot find '+f) + # satbang and satbias + ymd = '%04d%02d%02d'%(rst_time.year,rst_time.month, rst_time.day) + hr ='%02d'%rst_time.hour + for ftype in ["ana_satbang_rst", "ana_satbias_rst", "ana_satbiaspc_rst"]: + fname = expid+'.'+ftype+'.'+ymd+'_'+hr+'z.txt' + f = rst_dir_orig+'/'+fname + if(os.path.isfile(f)): + self.anafiles.append(f) + else: + print('Warning: Cannot find '+f) + + # trak.GDA.rst file + delt = timedelta(hours = 3) + new_time = rst_time - delt + yyyy = "Y"+str(new_time.year) + mm = 'M%02d'%new_time.month + ymdh = '%04d%02d%02d%02d'%(new_time.year, new_time.month, new_time.day, new_time.hour) + rst_dir = rst_dir_orig.replace('Y'+self.yyyy,yyyy).replace('M'+self.mm,mm) + fname = expid+'.trak.GDA.rst.'+ymdh+'z.txt' + f = rst_dir+'/'+fname + if (os.path.isfile(f)): self.anafiles.append(f) + + agrid_in = self.common_in['agrid'] + agrid_out = self.common_out['agrid'] + + self.ana_regrid = True + if (self.hgrd[agrid_in] == self.hgrd[agrid_out]): + self.ana_regrid = False + + def regrid(self): + if not self.bkg: + return + expid_in = self.common_in.get('expid')+'.' + expid_out = self.common_out.get('expid') + if not expid_out: + expid = '' + else: + expid_out = expid_out+'.' + bindir = os.getcwd() + out_dir = self.common_out.get('out_dir') + + if not os.path.exists(out_dir) : os.makedirs(out_dir) + print( "cd " + self.common_out['out_dir']) + os.chdir(self.common_out['out_dir']) + tmp_dir = out_dir+'/ana_data/' + if os.path.exists(tmp_dir) : subprocess.call('rm -rf '+ tmp_dir, shell = True) + print ("mkdir " + tmp_dir) + os.makedirs(tmp_dir) + print( "cd " + tmp_dir) + os.chdir(tmp_dir) + + ogrid = self.common_out['ogrid'] + tagout = self.common_out['tag'] + bctag = self.get_bcTag(tagout, ogrid) + tagrank = self.tagsRank[bctag] + local_fs=[] + for f in self.anafiles: + fname = os.path.basename(f) + out_name = fname.replace(expid_in, expid_out) + f_tmp = tmp_dir+'/'+out_name + local_fs.append(f_tmp) + shutil.copy(f,f_tmp) + if (out_name.find('satbias') != -1): + if (tagrank >= self.tagsRank["Ganymed-4_0_Reynolds"]): + f_orig = f_tmp+'.orig' + shutil.move(f_tmp, f_orig) + f_ = open(f_tmp, 'w') + for line in fileinput.input(f_orig): + f_.write(line.replace('airs281SUBSET_aqua', 'airs281_aqua ')) + f_.close() + + if self.ana_regrid: + agrid_out = self.common_out['agrid'] + nlevel = self.upper_out['nlevel'] + flags = "-g5 -res " + self.hgrd[agrid_out] + " -nlevs " + str(nlevel) + bkg_files = glob.glob(tmp_dir+'/*.bkg??_eta_rst*') + print(bkg_files) + for f in bkg_files: + f_orig = f + ".orig" + shutil.move(f,f_orig) + cmd = bindir + '/dyn2dyn.x ' + flags + ' -o ' + f + ' ' + f_orig + print(cmd) + subprocess.call(cmd, shell = True) + for f in local_fs: + fname = os.path.basename(f) + shutil.move(f, out_dir+'/'+fname) + # write lcv + lcv = self.ana_in.get('lcv') + if lcv : + ymd = self.ymd + hh = self.hh + hms = hh+'0000' + rstlcvOut = out_dir+'/'+expid_out+'rst.lcv.'+ymd+'_'+hh+'z.bin' + cmd = bindir+'/mkdrstdate.x ' + ymd + ' ' + hms +' ' + rstlcvOut + print(cmd) + subprocess.call(cmd, shell = True) + os.chdir(bindir) diff --git a/GEOS_Util/post/regrider_base.py b/GEOS_Util/post/regrider_base.py index a129ce25..8b47a733 100644 --- a/GEOS_Util/post/regrider_base.py +++ b/GEOS_Util/post/regrider_base.py @@ -5,27 +5,33 @@ import shutil import glob import time +from datetime import datetime +from datetime import timedelta -class regrider: +class regrider(object): def __init__(self, config): - self.common_in = config['input']['parameters']['COMMON'] self.restarts_in = config['input']['restarts'] + self.common_in = config['input']['parameters']['COMMON'] self.common_out = config['output']['parameters']['COMMON'] self.upper_in = config['input']['parameters']['UPPERAIR'] - self.upper_out = config['output']['parameters']['UPPERAIR'] + self.upper_out = config['output']['parameters']['UPPERAIR'] self.slurm_options = config['slurm_options'] + self.init_time() self.init_tags() - + merra = self.common_in.get('rst_src') + if merra == 'MERRA-1': + print("Not yet implmented") + exit() self.init_merra2() # get bc directory and tile file self.in_bcsdir = self.get_bcdir("IN") self.in_til = glob.glob(self.in_bcsdir+ '/*-Pfafstetter.til')[0] - print("input tile file: " + self.in_til + print("input tile file: " + self.in_til) self.out_bcsdir = self.get_bcdir("OUT") self.out_til = glob.glob(self.out_bcsdir+ '/*-Pfafstetter.til')[0] - print("output tile file: " + self.out_til + print("output tile file: " + self.out_til) def init_tags(self): @@ -174,14 +180,21 @@ def init_tags(self): self.bcbase['discover_ops'] = "/discover/nobackup/projects/gmao/share/gmao_ops/fvInput/g5gcm/bcs" self.bcbase['discover_lt'] = "/discover/nobackup/ltakacs/bcs" + def init_time(self): + yyyymmddhh = str(self.common_in['yyyymmddhh']) + self.yyyymm = yyyymmddhh[0:6] + self.yyyy = yyyymmddhh[0:4] + self.mm = yyyymmddhh[4:6] + self.dd = yyyymmddhh[6:8] + self.hh = yyyymmddhh[8:10] + self.ymd = yyyymmddhh[0:8] + def init_merra2(self): merra2 = self.common_in.get('rst_src') if merra2 != 'MERRA-2': return print("merra-2 source") - yyyymmddhh = str(self.common_in['yyyymmddhh']) - print(type(yyyymmddhh)) - yyyymm = int(yyyymmddhh[0:6]) + yyyymm = int(self.yyyymm) if yyyymm < 197901 : print("Error. MERRA-2 data < 1979 not available\n") exit() @@ -199,12 +212,9 @@ def init_merra2(self): self.common_in['bc_base']= 'discover_ops' self.upper_in['nlevel'] = 72 expid = self.common_in['expid'] - yyyy = yyyymmddhh[0:4] - mm = yyyymmddhh[4:6] - dd = yyyymmddhh[6:8] - hh = yyyymmddhh[8:10] - surfix = yyyymmddhh[0:8]+'_'+hh+'z.bin' - self.common_in['rst_dir'] = '/archive/users/gmao_ops/MERRA2/gmao_ops/GEOSadas-5_12_4/'+expid +'/rs/Y'+yyyy +'/M'+mm + yyyymmddhh = str(self.common_in['yyyymmddhh']) + surfix = yyyymmddhh[0:8]+'_'+self.hh+'z.bin' + self.common_in['rst_dir'] = '/archive/users/gmao_ops/MERRA2/gmao_ops/GEOSadas-5_12_4/'+expid +'/rs/Y'+self.yyyy +'/M'+self.mm self.restarts_in['UPPERAIR'] = {} self.restarts_in['UPPERAIR']['fvcore'] = expid+'.fvcore_internal_rst.' + surfix @@ -218,7 +228,7 @@ def init_merra2(self): self.restarts_in['SURFACE']['lake'] = expid+'.lake_internal_rst.' + surfix self.restarts_in['SURFACE']['landice'] = expid+'.landice_internal_rst.' + surfix self.restarts_in['SURFACE']['saltwater']= expid+'.saltwater_internal_rst.'+ surfix - + def get_bcbase(self, opt): base = '' if opt.upper() == 'IN': @@ -270,7 +280,7 @@ def get_name_with_grid( grid, names): namex = [] if (grid[0].upper() == 'C'): n = int(grid[1:]) - s1 =f'{n}x6C' + s1 ='{n}x6C'.format(n=n) j=n*6 s2 =str(n) s3 =str(j) @@ -288,8 +298,10 @@ def get_name_with_grid( grid, names): for name in names: if (name.find(s2) != -1 and name.find(s3) != -1): namex.append(name) return namex - - dirnames = [ f.name for f in os.scandir(bcdir) if f.is_dir()] + #v3.5 + #dirnames = [ f.name for f in os.scandir(bcdir) if f.is_dir()] + #v2.7 + dirnames = [f for f in os.listdir(bcdir) if os.path.isdir(os.path.join(bcdir,f))] agrid_ = self.common_in['agrid'] ogrid_ = self.common_in['ogrid'] if opt.upper() == "OUT" : diff --git a/GEOS_Util/post/regrider_surf.py b/GEOS_Util/post/regrider_surf.py index b1ffb633..35c3396c 100644 --- a/GEOS_Util/post/regrider_surf.py +++ b/GEOS_Util/post/regrider_surf.py @@ -8,15 +8,14 @@ class surface(regrider): def __init__(self, config): - super().__init__(config) + #v3.0 + #super().__init__(config) + #v2.7 + super(surface, self).__init__(config) self.restarts_in = self.restarts_in['SURFACE'] self.surf_in = config['input']['parameters']['SURFACE'] self.surf_out = config['output']['parameters']['SURFACE'] - print("--ToDO--\n") - print("split saltwater after some tags(need to rank tag)") - print("if split, set self.saltwater None") - print("\n") self.saltwater = self.restarts_in.get('saltwater') self.openwater = self.restarts_in.get('openwater') self.seaice = self.restarts_in.get('seaice') @@ -40,11 +39,11 @@ def __init__(self, config): def regrid(self): bindir = os.getcwd() - outdir = self.common_out['outdir'] - if not os.path.exists(outdir) : os.makedirs(outdir) - os.chdir(self.common_out['outdir']) - InData_dir = outdir+'/InData/' - OutData_dir = outdir+'/OutData/' + out_dir = self.common_out['out_dir'] + if not os.path.exists(out_dir) : os.makedirs(out_dir) + os.chdir(self.common_out['out_dir']) + InData_dir = out_dir+'/InData/' + OutData_dir = out_dir+'/OutData/' if os.path.exists(InData_dir) : subprocess.call('rm -rf '+ InData_dir, shell = True) os.makedirs(InData_dir) if os.path.exists(OutData_dir) : subprocess.call('rm -rf '+ OutData_dir, shell = True) @@ -113,7 +112,7 @@ def regrid(self): #SBATCH --time=1:00:00 #SBATCH --job-name=mk_catch #SBATCH --qos=debug -#SBATCH --output={outdir}/{mk_catch_log} +#SBATCH --output={out_dir}/{mk_catch_log} # source {Bin}/g5_modules @@ -218,7 +217,7 @@ def regrid(self): catchcnFLG = '1' if (self.catchcnclm40 or self.catchcnclm45) else '0' catch1script = mk_catch_j_template.format(Bin = bindir, account = self.slurm_options['account'], \ - outdir = outdir, mk_catch_log = 'mk_catch_log.1', surflay = self.surf_out['surflay'], \ + out_dir = out_dir, mk_catch_log = 'mk_catch_log.1', surflay = self.surf_out['surflay'], \ wemin = self.surf_in['wemin'], wemout = self.surf_out['wemout'] , \ fromGCM = '0', catchFLG = catchFLG, catchcnFLG = catchcnFLG, rescale = '0', rsttime = self.common_in['yyyymmddhh'], \ RESTART_ID = self.surf_in['restart_id'], RESTART_PATH = self.surf_in['restart_path'], \ @@ -258,7 +257,7 @@ def regrid(self): lakeFLG = '0' routeFLG = '0' catch2script = mk_catch_j_template.format(Bin = bindir, account = self.slurm_options['account'], \ - outdir = outdir, mk_catch_log = 'mk_catch_log.2', surflay = self.surf_out['surflay'], \ + out_dir = out_dir, mk_catch_log = 'mk_catch_log.2', surflay = self.surf_out['surflay'], \ wemin = self.surf_in['wemin'], wemout = self.surf_out['wemout'] , \ fromGCM = '0', catchFLG = catchFLG, catchcnFLG = catchcnFLG, rescale = '1', rsttime = self.common_in['yyyymmddhh'], \ RESTART_ID = self.surf_in['restart_id'], RESTART_PATH = self.surf_in['restart_path'], \ diff --git a/GEOS_Util/post/regrider_upper.py b/GEOS_Util/post/regrider_upper.py index cfebb399..f51bb240 100644 --- a/GEOS_Util/post/regrider_upper.py +++ b/GEOS_Util/post/regrider_upper.py @@ -8,7 +8,10 @@ class upperair(regrider): def __init__(self, config): - super().__init__(config) + # v3.0 + #super().__init__(config) + # v2.7 + super(upperair, self).__init__(config) self.upper_out = config['input']['parameters']['UPPERAIR'] self.restarts_in = self.restarts_in['UPPERAIR'] @@ -71,11 +74,11 @@ def __init__(self, config): def regrid(self): print( "Regridding upper air......\n") bindir = os.getcwd() - outdir = self.common_out['outdir'] - if not os.path.exists(outdir) : os.makedirs(outdir) - print( "cd " + self.common_out['outdir']) - os.chdir(self.common_out['outdir']) - tmpdir = outdir+'/upper_data/' + out_dir = self.common_out['out_dir'] + if not os.path.exists(out_dir) : os.makedirs(out_dir) + print( "cd " + self.common_out['out_dir']) + os.chdir(self.common_out['out_dir']) + tmpdir = out_dir+'/upper_data/' if os.path.exists(tmpdir) : subprocess.call('rm -rf '+ tmpdir, shell = True) print ("mkdir " + tmpdir) os.makedirs(tmpdir) @@ -111,12 +114,12 @@ def regrid(self): #SBATCH --time=1:00:00 #SBATCH --ntasks={NPE} #SBATCH --job-name=regrid_upper -#SBATCH --output={outdir}/{out_log} +#SBATCH --output={out_dir}/{out_log} {QOS} unlimit -cd {outdir}/upper_data +cd {out_dir}/upper_data source {Bin}/g5_modules /bin/touch input.nml @@ -183,7 +186,7 @@ def regrid(self): """ regrid_upper_script = regrid_template.format(Bin=bindir, account = self.slurm_options['account'], \ - outdir = outdir, out_log = 'regrid_upper_log', drymassFLG = self.upper_out['drymassFLG'], \ + out_dir = out_dir, out_log = 'regrid_upper_log', drymassFLG = self.upper_out['drymassFLG'], \ imout = self.upper_out['imout'], nwrit = self.upper_out['nwrit'], NPE = self.upper_out['NPE'], \ QOS = self.upper_out['QOS'], nlevel = self.upper_out['nlevel']) upper = open('regrider_upper.j','wt') From f6f708f0453ae5b3087036e4d10220932fdabd0c Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Mon, 15 Nov 2021 11:30:58 -0500 Subject: [PATCH 08/70] 1)add split saltwater 2) change link to cp for restarts ( my change back for storage purpose) --- GEOS_Util/post/regrid.py | 2 +- GEOS_Util/post/regrid.yaml | 8 +- GEOS_Util/post/regrider_ana.py | 1 - GEOS_Util/post/regrider_base.py | 2 +- GEOS_Util/post/regrider_surf.py | 128 +++++++++++++++++++------------ GEOS_Util/post/regrider_upper.py | 23 +++--- 6 files changed, 100 insertions(+), 64 deletions(-) diff --git a/GEOS_Util/post/regrid.py b/GEOS_Util/post/regrid.py index a5e5ba80..be19e2f9 100644 --- a/GEOS_Util/post/regrid.py +++ b/GEOS_Util/post/regrid.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# module load python/GEOSpyD/Min4.9.2_py3.9 +# source g5_modules # import yaml diff --git a/GEOS_Util/post/regrid.yaml b/GEOS_Util/post/regrid.yaml index 2901a998..dad254df 100644 --- a/GEOS_Util/post/regrid.yaml +++ b/GEOS_Util/post/regrid.yaml @@ -17,7 +17,7 @@ input: yyyymmddhh: 2000041421 tag: ICA rst_src: MERRA-2 - expid: + expid: agrid: C48 ogrid: 360x180 rst_dir: /gpfsm/dnb44/mathomp4/Restarts-J10/nc4/Reynolds/c48 @@ -35,7 +35,9 @@ input: restart_id: restart_domain: cn_version: - + ANALYSIS: + bkg: Yes + lcv: Yes output: parameters: COMMON: @@ -46,7 +48,7 @@ output: tag: INL agrid: C90 ogrid: 1440x720 - outdir: /discover/nobackup/wjiang/test_regridpy/ + out_dir: /discover/nobackup/wjiang/test_all/ bc_base: discover_ops UPPERAIR: #ak, bk diff --git a/GEOS_Util/post/regrider_ana.py b/GEOS_Util/post/regrider_ana.py index c0f6b110..e2eaf39b 100644 --- a/GEOS_Util/post/regrider_ana.py +++ b/GEOS_Util/post/regrider_ana.py @@ -146,7 +146,6 @@ def regrid(self): nlevel = self.upper_out['nlevel'] flags = "-g5 -res " + self.hgrd[agrid_out] + " -nlevs " + str(nlevel) bkg_files = glob.glob(tmp_dir+'/*.bkg??_eta_rst*') - print(bkg_files) for f in bkg_files: f_orig = f + ".orig" shutil.move(f,f_orig) diff --git a/GEOS_Util/post/regrider_base.py b/GEOS_Util/post/regrider_base.py index 8b47a733..4b8d7358 100644 --- a/GEOS_Util/post/regrider_base.py +++ b/GEOS_Util/post/regrider_base.py @@ -215,7 +215,7 @@ def init_merra2(self): yyyymmddhh = str(self.common_in['yyyymmddhh']) surfix = yyyymmddhh[0:8]+'_'+self.hh+'z.bin' self.common_in['rst_dir'] = '/archive/users/gmao_ops/MERRA2/gmao_ops/GEOSadas-5_12_4/'+expid +'/rs/Y'+self.yyyy +'/M'+self.mm - + print('\nMERRA-2 Restart dir: ' + self.common_in['rst_dir']) self.restarts_in['UPPERAIR'] = {} self.restarts_in['UPPERAIR']['fvcore'] = expid+'.fvcore_internal_rst.' + surfix self.restarts_in['UPPERAIR']['moist'] = expid+'.moist_internal_rst.' + surfix diff --git a/GEOS_Util/post/regrider_surf.py b/GEOS_Util/post/regrider_surf.py index 35c3396c..72e36e2d 100644 --- a/GEOS_Util/post/regrider_surf.py +++ b/GEOS_Util/post/regrider_surf.py @@ -56,54 +56,76 @@ def regrid(self): print( "Could not find " + src + "--remove it from yaml config file add to restart dir") exit() dest = InData_dir+'/'+value - if os.path.exists(dest) : os.unlink(dest) - os.symlink(src, dest) + if os.path.exists(dest) : shutil.remove(dest) + print('\nCopy ' + src + ' to ' +dest) + shutil.copy(src,dest) + in_til = InData_dir+'/' + self.in_til.split('/')[-1] out_til = OutData_dir+'/'+self.out_til.split('/')[-1] - if os.path.exists(in_til) : os.unlink(in_til) - if os.path.exists(out_til) : os.unlink(out_til) - os.symlink(self.in_til, in_til) - os.symlink(self.out_til, out_til) + if os.path.exists(in_til) : shutil.remove(in_til) + if os.path.exists(out_til) : shutil.remove(out_til) + print('\n Copy ' + self.in_til + ' to ' + in_til) + shutil.copy(self.in_til, in_til) + print('\n Copy ' + self.out_til + ' to ' + out_til) + shutil.copy(self.out_til, out_til) + ogrid = self.common_out['ogrid'] + tagout = self.common_out['tag'] + bctag = self.get_bcTag(tagout, ogrid) + tagrank = self.tagsRank[bctag] + split_saltwaterFLG = '0' + if tagrank >= self.tagsRank["Icarus_Reynolds"] and self.saltwater: + split_saltwaterFLG = '1' + exe = bindir + '/mk_LakeLandiceSaltRestarts ' if (self.saltwater): cmd = exe + 'OutData/*.til InData/*.til InData/'+self.saltwater + ' 0 ' + str(self.surf_in['zoom']) - print(cmd) + print('\n'+cmd) subprocess.call(cmd, shell= True) + + # split Saltwater + ogrid = self.common_out['ogrid'] + tagout = self.common_out['tag'] + bctag = self.get_bcTag(tagout, ogrid) + tagrank = self.tagsRank[bctag] + if split_saltwaterFLG == '1': + print("\nSplitting Saltwater...\n") + cmd = bindir+'/SaltIntSplitter ' + out_til + ' ' + 'OutData/'+self.saltwater + print('\n'+cmd) + subprocess.call(cmd, shell= True) + self.openwater = None + self.seaice = None if (self.openwater): - exe = bindir + '/mk_LakeLandiceSaltRestarts ' cmd = exe + 'OutData/*.til InData/*.til InData/'+self.openwater + ' 0 ' + str(self.surf_in['zoom']) - print(cmd) + print('\n'+cmd) subprocess.call(cmd, shell= True) if (self.seaice): - exe = bindir + '/mk_LakeLandiceSaltRestarts ' cmd = exe + 'OutData/*.til InData/*.til InData/'+self.seaice + ' 0 ' + str(self.surf_in['zoom']) - print(cmd) + print('\n'+cmd) subprocess.call(cmd, shell= True) if (self.lake): - exe = bindir + '/mk_LakeLandiceSaltRestarts ' cmd = exe + 'OutData/*.til InData/*.til InData/'+self.lake + ' 19 ' + str(self.surf_in['zoom']) - print(cmd) + print('\n'+cmd) subprocess.call(cmd, shell= True) if (self.landice): - exe = bindir + '/mk_LakeLandiceSaltRestarts ' cmd = exe + 'OutData/*.til InData/*.til InData/'+self.landice + ' 20 ' + str(self.surf_in['zoom']) - print(cmd) + print('\n'+cmd) subprocess.call(cmd, shell= True) if (self.route): route = bindir + '/mk_RouteRestarts ' cmd = route + 'OutData/*.til '+ self.common_in["yyyymmddhh"][0:6] - print(cmd) + print('\n'+cmd) subprocess.call(cmd, shell= True) + if ( self.catchcnclm40 or self.catchcnclm45) : dirname = os.path.dirname(self.out_til) clsm = dirname+'/clsm' - print( "symbolic link clsm to OutData/clsm") + print( "\nsymbolic link clsm to OutData/clsm") os.symlink(clsm, 'OutData/clsm') mk_catch_j_template = """#!/bin/csh -f @@ -121,8 +143,9 @@ def regrid(self): #limit stacksize unlimited unlimit -set lakelandRestartX = ( {Bin}/mk_LakeLandiceSaltRestarts ) -set routRestartX = ( {Bin}/mk_RouteRestarts ) +#set lakelandRestartX = ( {Bin}/mk_LakeLandiceSaltRestarts ) +#set split_saltwaterX = ({Bin}/SaltIntSplitter ) +#set routRestartX = ( {Bin}/mk_RouteRestarts ) set esma_mpirun_X = ( {Bin}/esma_mpirun -np 84 ) set mk_CatchRestarts_X = ( $esma_mpirun_X {Bin}/mk_CatchRestarts ) set mk_CatchCNRestarts_X = ( $esma_mpirun_X {Bin}/mk_CatchCNRestarts ) @@ -132,30 +155,32 @@ def regrid(self): set OUT_til = OutData/*.til set IN_til = InData/*.til +#if ( {saltwaterFLG}) then +# $lakelandRestartX $OUT_til $IN_til InData/{saltwater} 0 {zoom} +# if ({split_saltwaterFLG}) then +# $split_saltwaterX $OUT_til OutData/{saltwater} +# endif +#endif -if ( {saltwaterFLG}) then - $lakelandRestartX $OUT_til $IN_til InData/{saltwater} 0 {zoom} -endif - -if ( {openwaterFLG}) then - $lakelandRestartX $OUT_til $IN_til InData/{openwater} 0 {zoom} -endif - -if ( {seaiceFLG}) then - $lakelandRestartX $OUT_til $IN_til InData/{seaice} 0 {zoom} -endif - -if ( {lakeFLG}) then - $lakelandRestartX $OUT_til $IN_til InData/{lake} 19 {zoom} -endif - -if ( {landiceFLG}) then - $lakelandRestartX $OUT_til $IN_til InData/{landice} 20 {zoom} -endif - -if ( {routeFLG}) then - $routeRestartX $OUT_til {yyyymm} -endif +#if ( {openwaterFLG}) then +# $lakelandRestartX $OUT_til $IN_til InData/{openwater} 0 {zoom} +#endif +# +#if ( {seaiceFLG}) then +# $lakelandRestartX $OUT_til $IN_til InData/{seaice} 0 {zoom} +#endif +# +#if ( {lakeFLG}) then +# $lakelandRestartX $OUT_til $IN_til InData/{lake} 19 {zoom} +#endif +# +#if ( {landiceFLG}) then +# $lakelandRestartX $OUT_til $IN_til InData/{landice} 20 {zoom} +#endif +# +#if ( {routeFLG}) then +# $routeRestartX $OUT_til {yyyymm} +#endif if ({catchFLG}) then set catchIN = InData/*catch_internal_rst* @@ -169,7 +194,8 @@ def regrid(self): set params = ( $params {wemin} {wemout} ) $Scale_Catch_X $params - mv $catch_regrid $catch_regrid.1 + rm $catch_regrid + #mv $catch_regrid $catch_regrid.1 mv $catch_scaled $catch_regrid endif endif @@ -200,7 +226,8 @@ def regrid(self): set params = ( $params {wemin} {wemout} ) $Scale_CatchCN_X $params - mv $catchcn_regrid $catchcn_regrid.1 + rm $catchcn_regrid + #mv $catchcn_regrid $catchcn_regrid.1 mv $catchcn_scaled $catchcn_regrid endif endif @@ -211,7 +238,9 @@ def regrid(self): landiceFLG = '1' if self.landice else '0' lakeFLG = '1' if self.lake else '0' routeFLG = '1' if self.route else '0' - + if (split_saltwaterFLG == '1' ): + openwaterFLG = '0' + seaiceFLG = '0' catchFLG = '1' if self.catch else '0' catchcnFLG = '1' if (self.catchcnclm40 or self.catchcnclm45) else '0' @@ -227,27 +256,30 @@ def regrid(self): seaiceFLG = seaiceFLG, seaice = self.seaice, \ landiceFLG = landiceFLG, landice = self.landice, \ lakeFLG = lakeFLG, lake = self.lake, \ + split_saltwaterFLG = split_saltwaterFLG, \ routeFLG = routeFLG, route = self.route, yyyymm = str(self.common_in['yyyymmddhh'])[0:6], \ zoom = self.surf_in['zoom'] ) catch1 = open('mk_catch.j.1','wt') catch1.write(catch1script) catch1.close() print("step 1: sbatch -W mk_catch.j.1") - subprocess.call('sbatch -W mk_catch.j.1', shell= True) # step 2 - if (self.surf_in['rescale'] and ( self.catch or self.catchcnclm40 or self.catchcnclm45)) : if os.path.exists('InData.step1') : subprocess.call('rm -rf InData.step1', shell = True) + print("\n Move Indata to InData.step1") shutil.move('InData', 'InData.step1') os.makedirs('InData') for catchfile in glob.glob("OutData/*catch*"): + print('\n Move ' + catchfile + ' to InData/') shutil.move(catchfile,"InData/") + print('\n Link ' + self.out_til + ' to ' + in_til) os.symlink(self.out_til, in_til) if ( (not (self.catchcnclm40 or self.catchcnclm45)) and self.catch) : dirname = os.path.dirname(self.out_til) clsm = dirname+'/clsm' + print('\n Link ' + clsm + ' to ' + 'OutData/clsm') os.symlink(clsm, 'OutData/clsm') saltwaterFLG = '0' @@ -267,6 +299,7 @@ def regrid(self): seaiceFLG = seaiceFLG, seaice = self.seaice, \ landiceFLG = landiceFLG, landice = self.landice, \ lakeFLG = lakeFLG, lake = self.lake, \ + split_saltwaterFLG = split_saltwaterFLG, \ routeFLG = routeFLG, route = self.route, yyyymm = str(self.common_in['yyyymmddhh'])[0:6], \ zoom = self.surf_in['zoom'] ) catch2 = open('mk_catch.j.2','wt') @@ -277,5 +310,6 @@ def regrid(self): cwd = os.getcwd() for out_rst in glob.glob("OutData/*_rst*"): filename = os.path.basename(out_rst) + print( "\nmove " + out_rst + " to " + cwd+"/"+filename) shutil.move(out_rst, cwd+"/"+filename) os.chdir(bindir) diff --git a/GEOS_Util/post/regrider_upper.py b/GEOS_Util/post/regrider_upper.py index f51bb240..3b82347f 100644 --- a/GEOS_Util/post/regrider_upper.py +++ b/GEOS_Util/post/regrider_upper.py @@ -72,7 +72,7 @@ def __init__(self, config): if self.upper_out['NPE'] <= 532: self.upper_out['QOS'] = "#SBATCH --qos=debug" def regrid(self): - print( "Regridding upper air......\n") + print( "\nRegridding upper air......\n") bindir = os.getcwd() out_dir = self.common_out['out_dir'] if not os.path.exists(out_dir) : os.makedirs(out_dir) @@ -91,21 +91,22 @@ def regrid(self): rst_in = "_internal_restart_in" if rst.find('import') != -1 : rst_in = "_import_restart_in" - cmd = '/bin/ln -s '+rst_dir+'/'+rst+' '+key+rst_in - print(cmd) + cmd = '/bin/cp '+rst_dir+'/'+rst+' '+key+rst_in + print('\n'+cmd) subprocess.call(cmd, shell = True) # link topo file topoin = glob.glob(self.in_bcsdir+'/topo_DYN_ave*')[0] - cmd = '/bin/ln -s ' + topoin - print(cmd) + cmd = '/bin/cp ' + topoin + ' .' + print('\n'+cmd) subprocess.call(cmd, shell = True) topoout = glob.glob(self.out_bcsdir+'/topo_DYN_ave*')[0] - cmd = '/bin/ln -s ' + topoout - print(cmd) + cmd = '/bin/cp ' + topoout + ' .' + print('\n'+cmd) subprocess.call(cmd, shell = True) - cmd = '/bin/ln -s ' + topoout + ' topo_dynave.data' - print(cmd) + fname = os.path.basename(topoout) + cmd = '/bin/ln -s ' + fname + ' topo_dynave.data' + print('\n'+cmd) subprocess.call(cmd, shell = True) regrid_template="""#!/bin/csh -xf @@ -194,8 +195,8 @@ def regrid(self): upper.close() print('sbatch -W regrider_upper.j\n') subprocess.call('sbatch -W regrider_upper.j', shell= True) - cwd = os.getcwd() for out_rst in glob.glob("*_rst*"): filename = os.path.basename(out_rst) - shutil.move(out_rst, cwd+"/"+filename) + print('\n Move ' + out_rst + ' to ' + out_dir+"/"+filename) + shutil.move(out_rst, out_dir+"/"+filename) os.chdir(bindir) From aacb47fdec31718096541803ef243837ddb75ac2 Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Tue, 16 Nov 2021 10:19:22 -0500 Subject: [PATCH 09/70] add coupled model restart support --- GEOS_Util/post/regrid.yaml | 18 +++++++++--------- GEOS_Util/post/regrider_base.py | 24 ++++++++++++++++++++---- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/GEOS_Util/post/regrid.yaml b/GEOS_Util/post/regrid.yaml index dad254df..cd41671b 100644 --- a/GEOS_Util/post/regrid.yaml +++ b/GEOS_Util/post/regrid.yaml @@ -20,6 +20,7 @@ input: expid: agrid: C48 ogrid: 360x180 + model: data rst_dir: /gpfsm/dnb44/mathomp4/Restarts-J10/nc4/Reynolds/c48 tarfile: bc_base: discover_ops @@ -29,7 +30,7 @@ input: nlevel: 72 SURFACE: wemin: 26 - zoom: 8 + zoom: 2 catchcnFLG: 1 restart_path: restart_id: @@ -41,20 +42,19 @@ input: output: parameters: COMMON: - expid: c90e - #model_config: - #tag: - #couple: + expid: c24 + model: MOM6 tag: INL - agrid: C90 - ogrid: 1440x720 - out_dir: /discover/nobackup/wjiang/test_all/ - bc_base: discover_ops + agrid: C24 + ogrid: 72x36 + out_dir: /discover/nobackup/wjiang/test_mycouple/ + bc_base: discover_couple UPPERAIR: #ak, bk nlevel: 72 SURFACE: wemout: 13 + slurm_options: account: s1873 qos: debug diff --git a/GEOS_Util/post/regrider_base.py b/GEOS_Util/post/regrider_base.py index 4b8d7358..56a78217 100644 --- a/GEOS_Util/post/regrider_base.py +++ b/GEOS_Util/post/regrider_base.py @@ -179,6 +179,7 @@ def init_tags(self): self.bcbase={} self.bcbase['discover_ops'] = "/discover/nobackup/projects/gmao/share/gmao_ops/fvInput/g5gcm/bcs" self.bcbase['discover_lt'] = "/discover/nobackup/ltakacs/bcs" + self.bcbase['discover_couple'] = "/discover/nobackup/projects/gmao/ssd/aogcm/atmosphere_bcs" def init_time(self): yyyymmddhh = str(self.common_in['yyyymmddhh']) @@ -231,12 +232,17 @@ def init_merra2(self): def get_bcbase(self, opt): base = '' + model = '' if opt.upper() == 'IN': - base = self.common_in.get('bc_base') + base = self.common_in.get('bc_base') + model = self.common_in.get('model') if opt.upper() == 'OUT': base = self.common_out.get('bc_base') - assert base, 'please specify bc_base: discover_ops, discover_lt or an absolute path' - if base == 'discover_ops' or base == 'discover_lt': + model = self.common_out.get('model') + assert base, 'please specify bc_base: discover_ops, discover_lt, discover_couple or an absolute path' + if model == 'MOM5' or model == 'MOM6': + assert base == 'discover_couple', "couples model's bc base should be discover_couple" + if base == 'discover_ops' or base == 'discover_lt' or base=='discover_couple': return self.bcbase[base] else: return base @@ -245,23 +251,33 @@ def get_bcdir(self, opt): bc_base = self.get_bcbase(opt) tag = self.common_in['tag'] ogrid = self.common_in['ogrid'] + model = self.common_in['model'] if opt.upper() == "OUT": tag = self.common_out['tag'] ogrid = self.common_out['ogrid'] + model = self.common_out['model'] bctag = self.get_bcTag(tag,ogrid) tagrank = self.tagsRank[bctag] if (tagrank >= self.tagsRank['Icarus-NLv3_Reynolds']) : bcdir = bc_base+'/Icarus-NLv3/'+bctag+'/' + if model == 'MOM6' or model == 'MOM5': + bcdir = bc_base+'/Icarus-NLv3/'+model+'/' elif (tagrank >= self.tagsRank['Icarus_Reynolds']): if bc_base == self.bcbase['discover_ops']: bcdir = bc_base+'/Icarus_Updated/'+bctag+'/' else: bcdir = bc_base+'/Icarus/'+bctag+'/' + if model == 'MOM6' or model == 'MOM5': + bcdir = bc_base+'/Icarus/'+model+'/' elif(tagrank >= self.tagsRank["Ganymed-4_0_Reynolds"]): bcdir = bc_base + '/Ganymed-4_0/'+bctag+'/' + if model == 'MOM6' or model == 'MOM5': + bcdir = bc_base+'/Ganymed/'+model+'/' else: - bcdir = bc_base + '/' + bctag + bcdir = bc_base + '/' + bctag + '/' + if model == 'MOM6' or model == 'MOM5': + bcdir = bc_base+'/Ganymed/'+model+'/' if not os.path.exists(bcdir): print( "Cannot find bc dir " + bcdir) From bf1b6bd4afde1990d21b89683676e6dac933ed08 Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Thu, 2 Dec 2021 13:16:42 -0500 Subject: [PATCH 10/70] add questionary --- GEOS_Util/post/CMakeLists.txt | 2 +- GEOS_Util/post/regrid.py | 62 +++-- GEOS_Util/post/regrid.yaml | 61 ----- GEOS_Util/post/regrid_questions.py | 370 +++++++++++++++++++++++++++++ GEOS_Util/post/regrider_ana.py | 112 ++++----- GEOS_Util/post/regrider_base.py | 120 ++++++---- GEOS_Util/post/regrider_surf.py | 70 ++++-- GEOS_Util/post/regrider_upper.py | 30 +-- 8 files changed, 604 insertions(+), 223 deletions(-) delete mode 100644 GEOS_Util/post/regrid.yaml create mode 100755 GEOS_Util/post/regrid_questions.py diff --git a/GEOS_Util/post/CMakeLists.txt b/GEOS_Util/post/CMakeLists.txt index 122ad63c..92ec92e5 100644 --- a/GEOS_Util/post/CMakeLists.txt +++ b/GEOS_Util/post/CMakeLists.txt @@ -45,7 +45,7 @@ install( file(GLOB pythonscripts CONFIGURE_DEPENDS regrid*.py) install( - PROGRAMS ${pythonscripts} regrid.yaml + PROGRAMS ${pythonscripts} DESTINATION bin) set_property(SOURCE rsg3_vinterp.F APPEND_STRING PROPERTY COMPILE_FLAGS "${FREAL8} ${BYTERECLEN} ${EXTENDED_SOURCE}") diff --git a/GEOS_Util/post/regrid.py b/GEOS_Util/post/regrid.py index be19e2f9..38b5764f 100644 --- a/GEOS_Util/post/regrid.py +++ b/GEOS_Util/post/regrid.py @@ -1,30 +1,56 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # # source g5_modules +# module load python/GEOSpyD/Min4.9.2_py3.9 # +import sys, getopt import yaml +from regrid_questions import get_config_from_questionary from regrider_base import * from regrider_upper import * from regrider_surf import * from regrider_ana import * -if __name__ == '__main__' : +def main(argv): + config_yaml = '' + try: + opts, args = getopt.getopt(argv,"hc:", ['config_file=']) + except getopt.GetoptError: + print('Usage: regrid.py -c regrid.yaml or ./regrid.py ') + sys.exit(2) + for opt, arg in opts: + if opt == '-h': + print('Command line: \n \ + ./regrid.py -c regrid.yaml ( the config file regrid.yaml is used) \n \ + ./regrid.py ( without arguments, the questionary will generate a regrid.yaml file) \n \ + Help message: \n \ + 1) .... \n \ + 2) .... ') + sys.exit() + if opt in("-c", "--config_file"): + config_yaml = arg + + if config_yaml == '': + get_config_from_questionary() + config_yaml = 'regrid.yaml' + + # load input yaml + stream = open(config_yaml, 'r') + config = yaml.full_load(stream) - # load input yaml - stream = open("regrid.yaml", 'r') - config = yaml.full_load(stream) - - # upper air - upper = upperair(config) - upper.regrid() - - # surface - surf = surface(config) - surf.regrid() - - # analysis - ana = analysis(config) - ana.regrid() - + # upper air + upper = upperair(config) + upper.regrid() + + # surface + surf = surface(config) + surf.regrid() + + # analysis + ana = analysis(config) + ana.regrid() + +if __name__ == '__main__' : + main(sys.argv[1:]) diff --git a/GEOS_Util/post/regrid.yaml b/GEOS_Util/post/regrid.yaml deleted file mode 100644 index cd41671b..00000000 --- a/GEOS_Util/post/regrid.yaml +++ /dev/null @@ -1,61 +0,0 @@ -input: - restarts: - UPPERAIR: - fvcore: fvcore_internal_rst - moist: moist_internal_rst - agcm: agcm_import_rst - SURFACE: - openwater: openwater_internal_rst - lake: lake_internal_rst - landice: landice_internal_rst - #saltwater: saltwater_internal_rst - #seaice: seaicethermo_internal_rst - catchcnclm40: - catch: catch_internal_rst - parameters: - COMMON: - yyyymmddhh: 2000041421 - tag: ICA - rst_src: MERRA-2 - expid: - agrid: C48 - ogrid: 360x180 - model: data - rst_dir: /gpfsm/dnb44/mathomp4/Restarts-J10/nc4/Reynolds/c48 - tarfile: - bc_base: discover_ops - #bc_base: discover_lt - - UPPERAIR: - nlevel: 72 - SURFACE: - wemin: 26 - zoom: 2 - catchcnFLG: 1 - restart_path: - restart_id: - restart_domain: - cn_version: - ANALYSIS: - bkg: Yes - lcv: Yes -output: - parameters: - COMMON: - expid: c24 - model: MOM6 - tag: INL - agrid: C24 - ogrid: 72x36 - out_dir: /discover/nobackup/wjiang/test_mycouple/ - bc_base: discover_couple - UPPERAIR: - #ak, bk - nlevel: 72 - SURFACE: - wemout: 13 - -slurm_options: - account: s1873 - qos: debug - partition: diff --git a/GEOS_Util/post/regrid_questions.py b/GEOS_Util/post/regrid_questions.py new file mode 100755 index 00000000..228530b7 --- /dev/null +++ b/GEOS_Util/post/regrid_questions.py @@ -0,0 +1,370 @@ +#!/usr/bin/env python3 +# +# source python/GEOSpyD/Min4.9.2_py3.9 +# + +import os +import subprocess +import yaml +import shutil +import questionary + +def ask_common_in(): + questions = [ + { + "type": "confirm", + "name": "MERRA-2", + "message": "Would you like to get restarts from MERRA-2 archive?", + "default": False + }, + { + "type": "path", + "name": "rst_dir", + "message": "Enter the directory with restart files to be regrided: \n \ + restart files should be distributed under subdirectories \n \ + upperair, surface, analysis", + "when": lambda x: not x["MERRA-2"], + }, + { + "type": "text", + "name": "yyyymmddhh", + "message": "What time would you like to regrid from?(yyyymmddhh)", + "default": "2000041421" + }, + { + "type": "text", + "name": "expid", + "message": "Enter input restarts expid:", + "default": "", + "when": lambda x: not x["MERRA-2"], + }, + { + "type": "select", + "name": "model", + "message": "Select ocean model:", + "choices": ["data", "MOM5", "MOM6"], + "default": "data", + }, + { + "type": "text", + "name": "agrid", + "message": "Enter input atmospheric grid, format(Cxxx):", + "default": 'C360', + "when": lambda x: not x['MERRA-2'], + }, + { + "type": "select", + "name": "ogrid", + "message": "Input Ocean grid: \n \ + Data Ocean Grids \n \ + ------------------- \n \ + 360X180 (Reynolds) \n \ + 1440X720 (MERRA-2) \n \ + 2880X1440 (OSTIA) \n \ + CS = same as atmospere grid (OSTIA cubed-sphere) \n", + "choices": ['360X180','1440X720','2880X1440','CS'], + "when": lambda x: x['model'] == 'data' and not x['MERRA-2'], + }, + { + "type": "select", + "name": "ogrid", + "message": "Input Ocean grid: \n \ + Coupled Ocean Grids \n \ + ------------------- \n \ + 72X36 \n \ + 360X200 \n \ + 720X410 \n \ + 1440X1080 \n ", + "choices": ['72X36','360X200','720X410','1440X1080'], + "when": lambda x: x['model'] != 'data', + }, + { + "type": "text", + "name": "tag", + "message": "Enter GCM or DAS tag for input: \n \ +Sample GCM tags \n \ +--------------- \n \ +F14 : Fortuna-1_4 ......... Fortuna-1_4_p1 \n \ +F20 : Fortuna-2_0 ......... Fortuna-2_0 \n \ +F21 : Fortuna-2_1 ......... Fortuna-2_5_pp2 \n \ +G10 : Ganymed-1_0 ......... Ganymed-1_0_BETA4 \n \ +G10p : Ganymed-1_0_p1 ...... Ganymed-1_0_p6 \n \ +G20 : Ganymed-2_0 ......... Ganymed-2_1_p6 \n \ +G30 : Ganymed-3_0 ......... Ganymed-3_0_p1 \n \ +G40 : Ganymed-4_0 ......... Heracles-5_4_p3 \n \ +INL : Icarus-NL ........... Jason-NL \n \ +ICA : Icarus .............. Jason \n \ +\n \ +Sample DAS tags \n \ +--------------- \n \ +214 : GEOSdas-2_1_4 ....... GEOSdas-2_1_4-m4 \n \ +540 : GEOSadas-5_4_0 ...... GEOSadas-5_5_3 \n \ +561 : GEOSadas-5_6_1 ...... GEOSadas-5_7_3_p2 \n \ +580 : GEOSadas-5_8_0 ...... GEOSadas-5_9_1 \n \ +591p : GEOSadas-5_9_1_p1 ... GEOSadas-5_9_1_p9 \n \ +5A0 : GEOSadas-5_10_0 ..... GEOSadas-5_10_0_p1 \n \ +5B0 : GEOSadas-5_10_0_p2 .. GEOSadas-5_11_0 \n \ +512 : GEOSadas-5_12_2 ..... GEOSadas-5_16_5\n", + "default": "ICA", + "when": lambda x: not x["MERRA-2"], + }, + { + "type": "select", + "name": "bc_base", + "message": "Select bcs base \n \ + discover_ops: /discover/nobackup/projects/gmao/share/gmao_ops/fvInput/g5gcm/bcs \n \ + discover_lt: /discover/nobackup/ltakacs/bcs \n", + "choices": ["discover_ops", "discover_lt"], + "when": lambda x: x.get("model")=="data" and not x['MERRA-2'], + }, + ] + common_in = questionary.prompt(questions) + if common_in.get('ogrid') == 'CS': + common_in['ogrid'] = common_in['agrid'] + return common_in + +def ask_common_out(): + questions = [ + { + "type": "path", + "name": "out_dir", + "message": "Enter the directory for new restarts:\n" + }, + { + "type": "text", + "name": "expid", + "message": "Enter new restarts expid:", + "default": "", + }, + { + "type": "text", + "name": "agrid", + "message": "Enter new atmospheric grid, format(Cxxx):", + "default": 'C360', + }, + { + "type": "text", + "name": "tag", + "message": "Enter GCM or DAS tag for new restarts: \n \ +Sample GCM tags \n \ +--------------- \n \ +F14 : Fortuna-1_4 ......... Fortuna-1_4_p1 \n \ +F20 : Fortuna-2_0 ......... Fortuna-2_0 \n \ +F21 : Fortuna-2_1 ......... Fortuna-2_5_pp2 \n \ +G10 : Ganymed-1_0 ......... Ganymed-1_0_BETA4 \n \ +G10p : Ganymed-1_0_p1 ...... Ganymed-1_0_p6 \n \ +G20 : Ganymed-2_0 ......... Ganymed-2_1_p6 \n \ +G30 : Ganymed-3_0 ......... Ganymed-3_0_p1 \n \ +G40 : Ganymed-4_0 ......... Heracles-5_4_p3 \n \ +ICA : Icarus .............. Jason \n \ +INL : Icarus-NL ........... Jason-NL \n \ +\n \ +Sample DAS tags \n \ +--------------- \n \ +214 : GEOSdas-2_1_4 ....... GEOSdas-2_1_4-m4 \n \ +540 : GEOSadas-5_4_0 ...... GEOSadas-5_5_3 \n \ +561 : GEOSadas-5_6_1 ...... GEOSadas-5_7_3_p2 \n \ +580 : GEOSadas-5_8_0 ...... GEOSadas-5_9_1 \n \ +591p : GEOSadas-5_9_1_p1 ... GEOSadas-5_9_1_p9 \n \ +5A0 : GEOSadas-5_10_0 ..... GEOSadas-5_10_0_p1 \n \ +5B0 : GEOSadas-5_10_0_p2 .. GEOSadas-5_11_0 \n \ +512 : GEOSadas-5_12_2 ..... GEOSadas-5_16_5\n", + "default": "ICA", + }, + { + "type": "select", + "name": "model", + "message": "Select ocean model for new restarts:", + "choices": ["data", "MOM5", "MOM6"], + "default": "data", + }, + { + "type": "select", + "name": "ogrid", + "message": "Select new Ocean grid: \n \ + Data Ocean Grids \n \ + ------------------- \n \ + 360X180 (Reynolds) \n \ + 1440X720 (MERRA-2) \n \ + 2880X1440 (OSTIA) \n \ + CS = same as atmospere grid (OSTIA cubed-sphere) \n", + "choices": ['360X180','1440X720','2880X1440','CS'], + "when": lambda x: x['model'] == 'data', + }, + { + "type": "select", + "name": "ogrid", + "message": "Select new Ocean grid: \n \ + Coupled Ocean Grids \n \ + ------------------- \n \ + 72X36 \n \ + 360X200 \n \ + 720X410 \n \ + 1440X1080 \n ", + "choices": ['72X36','360X200','720X410','1440X1080'], + "when": lambda x: x['model'] != 'data', + }, + { + "type": "select", + "name": "bc_base", + "message": "Select bcs base for new restarts: \n \ + discover_ops: /discover/nobackup/projects/gmao/share/gmao_ops/fvInput/g5gcm/bcs \n \ + discover_lt: /discover/nobackup/ltakacs/bcs \n", + "choices": ["discover_ops", "discover_lt","other"], + "when": lambda x: x.get("model")=="data", + }, + { + "type": "path", + "name": "alt_bcs", + "message": "Specify your own bcs path for new restarts: \n ", + "when": lambda x: x.get("bc_base")=="other", + }, + + ] + common_out = questionary.prompt(questions) + if common_out.get('ogrid') == 'CS': + common_out['ogrid'] = common_out['agrid'] + + return common_out +def ask_upper_out(): + questions = [ + { + "type": "text", + "name": "nlevel", + "message": "Enter new atmospheric levels:", + "default": "72", + }, + ] + return questionary.prompt(questions) +def ask_surface_in(common_in): + wemin_default = '26' + if common_in.get('tag') == 'INL': wemin_default = '13' + questions = [ + { + "type": "text", + "name": "wemin", + "message": "What is value of Wemin?", + "default": wemin_default + }, + { + "type": "text", + "name": "zoom", + "message": "What is value of zoom [1-8]?", + "default": '1' + }, + ] + return questionary.prompt(questions) + +def ask_surface_out(common_out): + wemout_default = '26' + if common_out.get('tag') == 'INL': wemout_default = '13' + questions = [ + { + "type": "text", + "name": "wemout", + "message": "What is value of Wemout?", + "default": wemout_default + }, + ] + return questionary.prompt(questions) + +def ask_analysis_in(): + questions = [ + { + "type": "confirm", + "name": "bkg", + "message": "Regrid bkg files?", + "default": False, + }, + { + "type": "confirm", + "name": "lcv", + "message": "Write lcv?", + "default": False, + }, + ] + return questionary.prompt(questions) + +def ask_slurm_options(): + cmd = 'id -gn' + p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) + (accounts, err) = p.communicate() + p_status = p.wait() + accounts = accounts.decode().split() + + questions = [ + { + "type": "text", + "name": "debug", + "message": "qos?", + "default": "debug", + }, + { + "type": "text", + "name": "account", + "message": "account?", + "default": accounts[0], + }, + { + "type": "select", + "name": "partition", + "message": "partition?", + "choices": ['hasw', 'sky'], + }, + ] + return questionary.prompt(questions) + +def get_config_from_questionary(): + print("\nCommon parameters INPUT: \n") + common_in = ask_common_in() + print("\nSurface parameters INPUT: \n") + surface_in = ask_surface_in(common_in) + print("\nAnalysis parameters INPUT: \n") + analysis_in = ask_analysis_in() + print("\nCommon parameters OUTPUT: \n") + common_out = ask_common_out() + print("\nUPPER parameters OUTPUT: \n") + upper_out = ask_upper_out() + print("\nSurface parameters OUTPUT: \n") + surface_out = ask_surface_out(common_out) + print("\nSlurm parameters OUTPUT: \n") + slurm = ask_slurm_options() + + config={} + inputs={} + outputs={} + parameters_in={} + parameters_in['COMMON'] = common_in + parameters_in['SURFACE'] = surface_in + parameters_in['ANALYSIS'] = analysis_in + inputs['parameters'] = parameters_in + + config['input']= inputs + + parameters_out={} + parameters_out['COMMON'] = common_out + parameters_out['UPPERAIR'] = upper_out + parameters_out['SURFACE'] = surface_out + outputs['parameters'] = parameters_out + + config['output']= outputs + + config['slurm_options'] = slurm + + if os.path.exists('regrid.yaml') : + overwrite = questionary.confirm("Do you want to overwrite regrid.yaml file?", default=False).ask() + if not overwrite : + while True: + new_name = questionary.text("What's the backup name for existing regrid.yaml?", default='regrid.yaml.1').ask() + if os.path.exists(new_name): + print('\n'+ new_name + ' exists, please enter a new one. \n') + else: + shutil.move('regrid.yaml', new_name) + break + + f = open("regrid.yaml", "w") + yaml.dump(config, f, allow_unicode=True, default_flow_style=False) + f.close() + +if __name__ == "__main__": + get_config_from_questionary() diff --git a/GEOS_Util/post/regrider_ana.py b/GEOS_Util/post/regrider_ana.py index e2eaf39b..a0aa98d8 100644 --- a/GEOS_Util/post/regrider_ana.py +++ b/GEOS_Util/post/regrider_ana.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # import os import subprocess @@ -36,61 +36,65 @@ def __init__(self, config): rst_time = datetime(year=int(self.yyyy), month=int(self.mm), day=int(self.dd), hour = int(self.hh)) rst_dir_orig = self.common_in['rst_dir'] expid = self.common_in['expid'] - self.anafiles=[] - for h in [3,4,5,6,7,8,9]: - delt = timedelta(hours = h-3) - new_time = rst_time + delt - yyyy = "Y"+str(new_time.year) - mm = 'M%02d'%new_time.month - ymd = '%04d%02d%02d'%(new_time.year,new_time.month, new_time.day) - hh = '%02d'%h - newhh= '%02d'%new_time.hour - rst_dir = rst_dir_orig.replace('Y'+self.yyyy,yyyy).replace('M'+self.mm,mm) - # bkg files - for ftype in ['sfc', 'eta']: - fname = expid+'.bkg'+hh+'_'+ftype+'_rst.'+ymd+'_'+newhh+'z.nc4' - f = rst_dir+'/'+fname - if(os.path.isfile(f)): - self.anafiles.append(f) - else: - print('Warning: Cannot find '+f) + anafiles = self.restarts_in['ANALYSIS'] + if len(anafiles) == 0 and self.common_in.get('MERRA-2'): + self.anafiles=[] + for h in [3,4,5,6,7,8,9]: + delt = timedelta(hours = h-3) + new_time = rst_time + delt + yyyy = "Y"+str(new_time.year) + mm = 'M%02d'%new_time.month + ymd = '%04d%02d%02d'%(new_time.year,new_time.month, new_time.day) + hh = '%02d'%h + newhh= '%02d'%new_time.hour + rst_dir = rst_dir_orig.replace('Y'+self.yyyy,yyyy).replace('M'+self.mm,mm) + # bkg files + for ftype in ['sfc', 'eta']: + fname = expid+'.bkg'+hh+'_'+ftype+'_rst.'+ymd+'_'+newhh+'z.nc4' + f = rst_dir+'/'+fname + if(os.path.isfile(f)): + self.anafiles.append(f) + else: + print('Warning: Cannot find '+f) - # cbkg file - fname = expid + '.cbkg' + hh + '_eta_rst.' + ymd + '_' + newhh + 'z.nc4' - f = rst_dir+'/'+fname - if(os.path.isfile(f)): - self.anafiles.append(f) - else: - print('Warning: Cannot find '+f) - # gaas_bkg_sfc files - if (h==6 or h==9): - fname = expid+'.gaas_bkg_sfc_rst.'+ymd+'_'+newhh+'z.nc4' - f = rst_dir+'/'+fname - if (os.path.isfile(f)): - self.anafiles.append(f) - else: - print('Warning: Cannot find '+f) - # satbang and satbias - ymd = '%04d%02d%02d'%(rst_time.year,rst_time.month, rst_time.day) - hr ='%02d'%rst_time.hour - for ftype in ["ana_satbang_rst", "ana_satbias_rst", "ana_satbiaspc_rst"]: - fname = expid+'.'+ftype+'.'+ymd+'_'+hr+'z.txt' - f = rst_dir_orig+'/'+fname - if(os.path.isfile(f)): - self.anafiles.append(f) - else: - print('Warning: Cannot find '+f) + # cbkg file + fname = expid + '.cbkg' + hh + '_eta_rst.' + ymd + '_' + newhh + 'z.nc4' + f = rst_dir+'/'+fname + if(os.path.isfile(f)): + self.anafiles.append(f) + else: + print('Warning: Cannot find '+f) + # gaas_bkg_sfc files + if (h==6 or h==9): + fname = expid+'.gaas_bkg_sfc_rst.'+ymd+'_'+newhh+'z.nc4' + f = rst_dir+'/'+fname + if (os.path.isfile(f)): + self.anafiles.append(f) + else: + print('Warning: Cannot find '+f) + # satbang and satbias + ymd = '%04d%02d%02d'%(rst_time.year,rst_time.month, rst_time.day) + hr ='%02d'%rst_time.hour + for ftype in ["ana_satbang_rst", "ana_satbias_rst", "ana_satbiaspc_rst"]: + fname = expid+'.'+ftype+'.'+ymd+'_'+hr+'z.txt' + f = rst_dir_orig+'/'+fname + if(os.path.isfile(f)): + self.anafiles.append(f) + else: + print('Warning: Cannot find '+f) - # trak.GDA.rst file - delt = timedelta(hours = 3) - new_time = rst_time - delt - yyyy = "Y"+str(new_time.year) - mm = 'M%02d'%new_time.month - ymdh = '%04d%02d%02d%02d'%(new_time.year, new_time.month, new_time.day, new_time.hour) - rst_dir = rst_dir_orig.replace('Y'+self.yyyy,yyyy).replace('M'+self.mm,mm) - fname = expid+'.trak.GDA.rst.'+ymdh+'z.txt' - f = rst_dir+'/'+fname - if (os.path.isfile(f)): self.anafiles.append(f) + # trak.GDA.rst file + delt = timedelta(hours = 3) + new_time = rst_time - delt + yyyy = "Y"+str(new_time.year) + mm = 'M%02d'%new_time.month + ymdh = '%04d%02d%02d%02d'%(new_time.year, new_time.month, new_time.day, new_time.hour) + rst_dir = rst_dir_orig.replace('Y'+self.yyyy,yyyy).replace('M'+self.mm,mm) + fname = expid+'.trak.GDA.rst.'+ymdh+'z.txt' + f = rst_dir+'/'+fname + if (os.path.isfile(f)): self.anafiles.append(f) + else: + self.anafiles = anafiles agrid_in = self.common_in['agrid'] agrid_out = self.common_out['agrid'] diff --git a/GEOS_Util/post/regrider_base.py b/GEOS_Util/post/regrider_base.py index 56a78217..2c03dea2 100644 --- a/GEOS_Util/post/regrider_base.py +++ b/GEOS_Util/post/regrider_base.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # import os import subprocess @@ -10,20 +10,15 @@ class regrider(object): def __init__(self, config): - self.restarts_in = config['input']['restarts'] self.common_in = config['input']['parameters']['COMMON'] self.common_out = config['output']['parameters']['COMMON'] - self.upper_in = config['input']['parameters']['UPPERAIR'] self.upper_out = config['output']['parameters']['UPPERAIR'] self.slurm_options = config['slurm_options'] self.init_time() self.init_tags() - merra = self.common_in.get('rst_src') - if merra == 'MERRA-1': - print("Not yet implmented") - exit() self.init_merra2() + self.init_restarts_in() # get bc directory and tile file self.in_bcsdir = self.get_bcdir("IN") @@ -190,58 +185,76 @@ def init_time(self): self.hh = yyyymmddhh[8:10] self.ymd = yyyymmddhh[0:8] + def init_restarts_in(self): + if self.common_in['MERRA-2']: + return + + rst_dir = self.common_in.get('rst_dir')+'/' + self.restarts_in={} + self.restarts_in['UPPERAIR'] = glob.glob(rst_dir +'upperair/*') + self.restarts_in['SURFACE'] = glob.glob(rst_dir +'surface/*') + self.restarts_in['ANALYSIS'] = glob.glob(rst_dir +'analysis/*') + def init_merra2(self): - merra2 = self.common_in.get('rst_src') - if merra2 != 'MERRA-2': - return - print("merra-2 source") - yyyymm = int(self.yyyymm) - if yyyymm < 197901 : - print("Error. MERRA-2 data < 1979 not available\n") - exit() - elif (yyyymm < 199201): - self.common_in['expid'] = "d5124_m2_jan79" - elif (yyyymm < 200106): - self.common_in['expid'] = "d5124_m2_jan91" - elif (yyyymm < 201101): - self.common_in['expid'] = "d5124_m2_jan00" - else: - self.common_in['expid'] = "d5124_m2_jan10" - - self.common_in['agrid'] = 'C180' - self.common_in['ogrid'] = '1440x720' - self.common_in['bc_base']= 'discover_ops' - self.upper_in['nlevel'] = 72 - expid = self.common_in['expid'] - yyyymmddhh = str(self.common_in['yyyymmddhh']) - surfix = yyyymmddhh[0:8]+'_'+self.hh+'z.bin' - self.common_in['rst_dir'] = '/archive/users/gmao_ops/MERRA2/gmao_ops/GEOSadas-5_12_4/'+expid +'/rs/Y'+self.yyyy +'/M'+self.mm - print('\nMERRA-2 Restart dir: ' + self.common_in['rst_dir']) - self.restarts_in['UPPERAIR'] = {} - self.restarts_in['UPPERAIR']['fvcore'] = expid+'.fvcore_internal_rst.' + surfix - self.restarts_in['UPPERAIR']['moist'] = expid+'.moist_internal_rst.' + surfix - self.restarts_in['UPPERAIR']['agcm'] = expid+'.agcm_import_rst.' + surfix - self.restarts_in['UPPERAIR']['gocart'] = expid+'.gocart_internal_rst.' + surfix - self.restarts_in['UPPERAIR']['pchem'] = expid+'.pchem_internal_rst.' + surfix - - self.restarts_in['SURFACE'] = {} - self.restarts_in['SURFACE']['catch'] = expid+'.catch_internal_rst.' + surfix - self.restarts_in['SURFACE']['lake'] = expid+'.lake_internal_rst.' + surfix - self.restarts_in['SURFACE']['landice'] = expid+'.landice_internal_rst.' + surfix - self.restarts_in['SURFACE']['saltwater']= expid+'.saltwater_internal_rst.'+ surfix + if not self.common_in['MERRA-2']: + return + print("\nMERRA-2 sources:\n") + yyyymm = int(self.yyyymm) + if yyyymm < 197901 : + print("Error. MERRA-2 data < 1979 not available\n") + exit() + elif (yyyymm < 199201): + self.common_in['expid'] = "d5124_m2_jan79" + elif (yyyymm < 200106): + self.common_in['expid'] = "d5124_m2_jan91" + elif (yyyymm < 201101): + self.common_in['expid'] = "d5124_m2_jan00" + else: + self.common_in['expid'] = "d5124_m2_jan10" + + self.common_in['agrid'] = 'C180' + self.common_in['ogrid'] = '1440x720' + self.common_in['bc_base']= 'discover_ops' + self.common_in['tag']= 'Ganymed-4_0' + expid = self.common_in['expid'] + yyyymmddhh = str(self.common_in['yyyymmddhh']) + surfix = yyyymmddhh[0:8]+'_'+self.hh+'z.bin' + self.common_in['rst_dir'] = '/archive/users/gmao_ops/MERRA2/gmao_ops/GEOSadas-5_12_4/'+expid +'/rs/Y'+self.yyyy +'/M'+self.mm+'/' + print('\nMERRA-2 Restart dir: ' + self.common_in['rst_dir']) + + self.restarts_in = {} + upperin =[self.common_in['rst_dir']+ expid+'.fvcore_internal_rst.' + surfix, + self.common_in['rst_dir']+ expid+'.moist_internal_rst.' + surfix, + self.common_in['rst_dir']+ expid+'.agcm_import_rst.' + surfix, + self.common_in['rst_dir']+ expid+'.gocart_internal_rst.' + surfix, + self.common_in['rst_dir']+ expid+'.pchem_internal_rst.' + surfix ] + self.restarts_in['UPPERAIR'] = upperin + + surfin = [self.common_in['rst_dir']+ expid+'.catch_internal_rst.' + surfix, + self.common_in['rst_dir']+ expid+'.lake_internal_rst.' + surfix, + self.common_in['rst_dir']+ expid+'.landice_internal_rst.' + surfix, + self.common_in['rst_dir']+ expid+'.saltwater_internal_rst.'+ surfix] + self.restarts_in['SURFACE'] = surfin + self.restarts_in['ANALYSIS'] = [] def get_bcbase(self, opt): base = '' model = '' + if opt.upper() == 'IN': - base = self.common_in.get('bc_base') model = self.common_in.get('model') + if model == 'MOM6' or model == 'MOM5': + base = 'discover_couple' + else: + base = self.common_in.get('bc_base') + if opt.upper() == 'OUT': - base = self.common_out.get('bc_base') model = self.common_out.get('model') + if model == 'MOM6' or model == 'MOM5': + base = 'discover_couple' + else: + base = self.common_out.get('bc_base') assert base, 'please specify bc_base: discover_ops, discover_lt, discover_couple or an absolute path' - if model == 'MOM5' or model == 'MOM6': - assert base == 'discover_couple', "couples model's bc base should be discover_couple" if base == 'discover_ops' or base == 'discover_lt' or base=='discover_couple': return self.bcbase[base] else: @@ -326,8 +339,13 @@ def get_name_with_grid( grid, names): anames = get_name_with_grid(agrid_, dirnames) gridID = get_name_with_grid(ogrid_, anames) - if len(gridID) ==0 or len(gridID) >=2 : - print(" cannot find the grid string: " + bcdir) + if len(gridID) == 0 : + print("cannot find the grid string: " + bcdir) + exit() + if len(gridID) >=2 : + print("find too may grid strings in " + bcdir) + print(" gridIDs found", gridID) + print(" pick the first one " + gridID[0]) return gridID[0] def get_bcTag(self, tag, ogrid): diff --git a/GEOS_Util/post/regrider_surf.py b/GEOS_Util/post/regrider_surf.py index 72e36e2d..5014566c 100644 --- a/GEOS_Util/post/regrider_surf.py +++ b/GEOS_Util/post/regrider_surf.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # import os import subprocess @@ -16,15 +16,41 @@ def __init__(self, config): self.surf_in = config['input']['parameters']['SURFACE'] self.surf_out = config['output']['parameters']['SURFACE'] - self.saltwater = self.restarts_in.get('saltwater') - self.openwater = self.restarts_in.get('openwater') - self.seaice = self.restarts_in.get('seaice') - self.landice = self.restarts_in.get('landice') - self.lake = self.restarts_in.get('lake') - self.route = self.restarts_in.get('route') - self.catch = self.restarts_in.get('catch') - self.catchcnclm40 = self.restarts_in.get('catchcnclm40') - self.catchcnclm45 = self.restarts_in.get('catchcnclm45') + self.saltwater = None + self.openwater = None + self.seaice = None + self.landice = None + self.lake = None + self.route = None + self.catch = None + self.catchcnclm40 = None + self.catchcnclm45 = None + for rst in self.restarts_in : + f = os.path.basename(rst) + if (f.find('saltwater') != -1): + self.saltwater = f + continue + if (f.find('seaice') != -1): + self.seaice = f + continue + if (f.find('landice') != -1): + self.landice = f + continue + if (f.find('lake') != -1): + self.lake = f + continue + if (f.find('route') != -1): + self.route = f + continue + if (f.find('catch_') != -1): + self.catch = f + continue + if (f.find('catchcnclm40') != -1): + self.catchcnclm40 = f + continue + if (f.find('catchcnclm45') != -1): + self.catchcnclm45 = f + continue tagout = self.common_out['tag'] ogrid = self.common_out['ogrid'] bctag = self.get_bcTag(tagout, ogrid) @@ -48,17 +74,13 @@ def regrid(self): os.makedirs(InData_dir) if os.path.exists(OutData_dir) : subprocess.call('rm -rf '+ OutData_dir, shell = True) os.makedirs(OutData_dir) - - for key, value in self.restarts_in.items(): - if not value : continue - src = self.common_in['rst_dir']+'/'+value - if not os.path.exists(src) : - print( "Could not find " + src + "--remove it from yaml config file add to restart dir") - exit() - dest = InData_dir+'/'+value + + for rst in self.restarts_in: + f = os.path.basename(rst) + dest = InData_dir+'/'+f if os.path.exists(dest) : shutil.remove(dest) - print('\nCopy ' + src + ' to ' +dest) - shutil.copy(src,dest) + print('\nCopy ' + rst + ' to ' +dest) + shutil.copy(rst,dest) in_til = InData_dir+'/' + self.in_til.split('/')[-1] out_til = OutData_dir+'/'+self.out_til.split('/')[-1] @@ -249,8 +271,8 @@ def regrid(self): out_dir = out_dir, mk_catch_log = 'mk_catch_log.1', surflay = self.surf_out['surflay'], \ wemin = self.surf_in['wemin'], wemout = self.surf_out['wemout'] , \ fromGCM = '0', catchFLG = catchFLG, catchcnFLG = catchcnFLG, rescale = '0', rsttime = self.common_in['yyyymmddhh'], \ - RESTART_ID = self.surf_in['restart_id'], RESTART_PATH = self.surf_in['restart_path'], \ - RESTART_DOMAIN = self.surf_in['restart_domain'], CN_VERSION = self.surf_in['cn_version'], \ + RESTART_ID = self.surf_in.get('restart_id'), RESTART_PATH = self.surf_in.get('restart_path'), \ + RESTART_DOMAIN = self.surf_in.get('restart_domain'), CN_VERSION = self.surf_in.get('cn_version'), \ saltwaterFLG = saltwaterFLG, saltwater = self.saltwater, \ openwaterFLG = openwaterFLG, openwater = self.openwater, \ seaiceFLG = seaiceFLG, seaice = self.seaice, \ @@ -292,8 +314,8 @@ def regrid(self): out_dir = out_dir, mk_catch_log = 'mk_catch_log.2', surflay = self.surf_out['surflay'], \ wemin = self.surf_in['wemin'], wemout = self.surf_out['wemout'] , \ fromGCM = '0', catchFLG = catchFLG, catchcnFLG = catchcnFLG, rescale = '1', rsttime = self.common_in['yyyymmddhh'], \ - RESTART_ID = self.surf_in['restart_id'], RESTART_PATH = self.surf_in['restart_path'], \ - RESTART_DOMAIN = self.surf_in['restart_domain'], CN_VERSION = self.surf_in['cn_version'], \ + RESTART_ID = self.surf_in.get('restart_id'), RESTART_PATH = self.surf_in.get('restart_path'), \ + RESTART_DOMAIN = self.surf_in.get('restart_domain'), CN_VERSION = self.surf_in.get('cn_version'), \ saltwaterFLG = saltwaterFLG, saltwater = self.saltwater, \ openwaterFLG = openwaterFLG, openwater = self.openwater, \ seaiceFLG = seaiceFLG, seaice = self.seaice, \ diff --git a/GEOS_Util/post/regrider_upper.py b/GEOS_Util/post/regrider_upper.py index 3b82347f..7968199c 100644 --- a/GEOS_Util/post/regrider_upper.py +++ b/GEOS_Util/post/regrider_upper.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # import os import subprocess @@ -12,15 +12,18 @@ def __init__(self, config): #super().__init__(config) # v2.7 super(upperair, self).__init__(config) - self.upper_out = config['input']['parameters']['UPPERAIR'] + self.upper_out = config['output']['parameters']['UPPERAIR'] self.restarts_in = self.restarts_in['UPPERAIR'] # verify agrid agrid = self.common_in['agrid'] ogrid = self.common_out['ogrid'] - merra_2 = self.common_in.get('rst_src') - if not (merra_2 == 'MERRA-2') : - fvcore = self.common_in['rst_dir']+'/'+self.restarts_in['fvcore'] + if not self.common_in.get('MERRA-2'): + fvcore = '' + for f in self.restarts_in: + if 'fvcore' in f: + fvcore = f + break cmd = './fvrst.x -h ' + fvcore print(cmd +'\n') p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) @@ -85,15 +88,14 @@ def regrid(self): print( "cd " + tmpdir) os.chdir(tmpdir) - rst_dir = self.common_in['rst_dir'] - for key, rst in self.restarts_in.items(): - if (rst): - rst_in = "_internal_restart_in" - if rst.find('import') != -1 : - rst_in = "_import_restart_in" - cmd = '/bin/cp '+rst_dir+'/'+rst+' '+key+rst_in - print('\n'+cmd) - subprocess.call(cmd, shell = True) + print('\nUpper air restart files should end with "_rst" \n' + for rst in self.restarts_in: + f = os.path.basename(rst) + f = f.replace('_rst','_restart_in') + cmd = '/bin/cp '+rst+' '+f + print('\n'+cmd) + subprocess.call(cmd, shell = True) + # link topo file topoin = glob.glob(self.in_bcsdir+'/topo_DYN_ave*')[0] cmd = '/bin/cp ' + topoin + ' .' From 6dbc893184d799e83c51dea4fd693ff09c6e27fe Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Thu, 2 Dec 2021 14:04:46 -0500 Subject: [PATCH 11/70] fix a typo --- GEOS_Util/post/regrider_upper.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/GEOS_Util/post/regrider_upper.py b/GEOS_Util/post/regrider_upper.py index 7968199c..0172324a 100644 --- a/GEOS_Util/post/regrider_upper.py +++ b/GEOS_Util/post/regrider_upper.py @@ -88,8 +88,8 @@ def regrid(self): print( "cd " + tmpdir) os.chdir(tmpdir) - print('\nUpper air restart files should end with "_rst" \n' - for rst in self.restarts_in: + print('\nUpper air restart files should end with "_rst" \n') + for rst in self.restarts_in : f = os.path.basename(rst) f = f.replace('_rst','_restart_in') cmd = '/bin/cp '+rst+' '+f From f1afc26e6b6ac75dcd8cf2aacdf4dd21abeb8734 Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Tue, 18 Jan 2022 11:43:44 -0500 Subject: [PATCH 12/70] get absolute path for fvrst.x --- GEOS_Util/post/regrider_upper.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/GEOS_Util/post/regrider_upper.py b/GEOS_Util/post/regrider_upper.py index 0172324a..c3954958 100644 --- a/GEOS_Util/post/regrider_upper.py +++ b/GEOS_Util/post/regrider_upper.py @@ -24,7 +24,8 @@ def __init__(self, config): if 'fvcore' in f: fvcore = f break - cmd = './fvrst.x -h ' + fvcore + path_ = os.path.dirname(os.path.realpath(__file__)) + cmd = path_ + '/fvrst.x -h ' + fvcore print(cmd +'\n') p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) (output, err) = p.communicate() From bc23d4c85257ce6e08e56e0f7aaf6b204030c16e Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Tue, 18 Jan 2022 12:17:35 -0500 Subject: [PATCH 13/70] change log --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 36d98c15..689f81fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- series of regrid*.py are added to GEOS_Util/post + ### Changed ### Fixed From b2d87dafabcbd8a3f3965bfe55c2077624994a68 Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Sun, 13 Feb 2022 15:21:51 -0500 Subject: [PATCH 14/70] add alt_bcs and fvrst.x path --- GEOS_Util/post/regrid.py | 13 +++++---- GEOS_Util/post/regrid_questions.py | 21 ++++++++----- GEOS_Util/post/regrider_base.py | 47 ++++++++++++++++-------------- GEOS_Util/post/regrider_upper.py | 4 +-- 4 files changed, 48 insertions(+), 37 deletions(-) diff --git a/GEOS_Util/post/regrid.py b/GEOS_Util/post/regrid.py index 38b5764f..59e81a72 100644 --- a/GEOS_Util/post/regrid.py +++ b/GEOS_Util/post/regrid.py @@ -21,12 +21,13 @@ def main(argv): sys.exit(2) for opt, arg in opts: if opt == '-h': - print('Command line: \n \ - ./regrid.py -c regrid.yaml ( the config file regrid.yaml is used) \n \ - ./regrid.py ( without arguments, the questionary will generate a regrid.yaml file) \n \ - Help message: \n \ - 1) .... \n \ - 2) .... ') + print('\nUse a config file to regrid: \n' + './regrid.py -c my_config.yaml \n \n' + 'Use questionary to generate regrid.yaml and regrid \n' + './regrid.py \n' + '\nHelp message: \n' + '1) .... \n' + '2) .... ') sys.exit() if opt in("-c", "--config_file"): config_yaml = arg diff --git a/GEOS_Util/post/regrid_questions.py b/GEOS_Util/post/regrid_questions.py index 228530b7..070ef795 100755 --- a/GEOS_Util/post/regrid_questions.py +++ b/GEOS_Util/post/regrid_questions.py @@ -113,9 +113,16 @@ def ask_common_in(): "name": "bc_base", "message": "Select bcs base \n \ discover_ops: /discover/nobackup/projects/gmao/share/gmao_ops/fvInput/g5gcm/bcs \n \ - discover_lt: /discover/nobackup/ltakacs/bcs \n", - "choices": ["discover_ops", "discover_lt"], - "when": lambda x: x.get("model")=="data" and not x['MERRA-2'], + discover_lt: /discover/nobackup/ltakacs/bcs \n \ + discover_couple: /discover/nobackup/projects/gmao/ssd/aogcm/atmosphere_bcs \n", + "choices": ["discover_ops", "discover_lt", "discover_couple", "other"], + "when": lambda x: not x['MERRA-2'], + }, + { + "type": "path", + "name": "alt_bcs", + "message": "Specify your own bcs path (do not contain grid info) for restarts: \n ", + "when": lambda x: x.get("bc_base")=="other", }, ] common_in = questionary.prompt(questions) @@ -209,14 +216,14 @@ def ask_common_out(): "name": "bc_base", "message": "Select bcs base for new restarts: \n \ discover_ops: /discover/nobackup/projects/gmao/share/gmao_ops/fvInput/g5gcm/bcs \n \ - discover_lt: /discover/nobackup/ltakacs/bcs \n", - "choices": ["discover_ops", "discover_lt","other"], - "when": lambda x: x.get("model")=="data", + discover_lt: /discover/nobackup/ltakacs/bcs \n \ + discover_couple: /discover/nobackup/projects/gmao/ssd/aogcm/atmosphere_bcs \n", + "choices": ["discover_ops", "discover_lt", "discover_couple", "other"], }, { "type": "path", "name": "alt_bcs", - "message": "Specify your own bcs path for new restarts: \n ", + "message": "Specify your own bcs path (do not contain grid info) for new restarts: \n ", "when": lambda x: x.get("bc_base")=="other", }, diff --git a/GEOS_Util/post/regrider_base.py b/GEOS_Util/post/regrider_base.py index 2c03dea2..35820413 100644 --- a/GEOS_Util/post/regrider_base.py +++ b/GEOS_Util/post/regrider_base.py @@ -261,36 +261,39 @@ def get_bcbase(self, opt): return base def get_bcdir(self, opt): - bc_base = self.get_bcbase(opt) tag = self.common_in['tag'] ogrid = self.common_in['ogrid'] model = self.common_in['model'] + bcdir = self.common_in.get('alt_bcs', None) if opt.upper() == "OUT": tag = self.common_out['tag'] ogrid = self.common_out['ogrid'] model = self.common_out['model'] - bctag = self.get_bcTag(tag,ogrid) - - tagrank = self.tagsRank[bctag] - if (tagrank >= self.tagsRank['Icarus-NLv3_Reynolds']) : - bcdir = bc_base+'/Icarus-NLv3/'+bctag+'/' - if model == 'MOM6' or model == 'MOM5': - bcdir = bc_base+'/Icarus-NLv3/'+model+'/' - elif (tagrank >= self.tagsRank['Icarus_Reynolds']): - if bc_base == self.bcbase['discover_ops']: - bcdir = bc_base+'/Icarus_Updated/'+bctag+'/' + bcdir = self.common_in.get('alt_bcs', None) + + if bcdir is None : + bc_base = self.get_bcbase(opt) + bctag = self.get_bcTag(tag,ogrid) + tagrank = self.tagsRank[bctag] + if (tagrank >= self.tagsRank['Icarus-NLv3_Reynolds']) : + bcdir = bc_base+'/Icarus-NLv3/'+bctag+'/' + if model == 'MOM6' or model == 'MOM5': + bcdir = bc_base+'/Icarus-NLv3/'+model+'/' + elif (tagrank >= self.tagsRank['Icarus_Reynolds']): + if bc_base == self.bcbase['discover_ops']: + bcdir = bc_base+'/Icarus_Updated/'+bctag+'/' + else: + bcdir = bc_base+'/Icarus/'+bctag+'/' + if model == 'MOM6' or model == 'MOM5': + bcdir = bc_base+'/Icarus/'+model+'/' + elif(tagrank >= self.tagsRank["Ganymed-4_0_Reynolds"]): + bcdir = bc_base + '/Ganymed-4_0/'+bctag+'/' + if model == 'MOM6' or model == 'MOM5': + bcdir = bc_base+'/Ganymed/'+model+'/' else: - bcdir = bc_base+'/Icarus/'+bctag+'/' - if model == 'MOM6' or model == 'MOM5': - bcdir = bc_base+'/Icarus/'+model+'/' - elif(tagrank >= self.tagsRank["Ganymed-4_0_Reynolds"]): - bcdir = bc_base + '/Ganymed-4_0/'+bctag+'/' - if model == 'MOM6' or model == 'MOM5': - bcdir = bc_base+'/Ganymed/'+model+'/' - else: - bcdir = bc_base + '/' + bctag + '/' - if model == 'MOM6' or model == 'MOM5': - bcdir = bc_base+'/Ganymed/'+model+'/' + bcdir = bc_base + '/' + bctag + '/' + if model == 'MOM6' or model == 'MOM5': + bcdir = bc_base+'/Ganymed/'+model+'/' if not os.path.exists(bcdir): print( "Cannot find bc dir " + bcdir) diff --git a/GEOS_Util/post/regrider_upper.py b/GEOS_Util/post/regrider_upper.py index c3954958..3e088508 100644 --- a/GEOS_Util/post/regrider_upper.py +++ b/GEOS_Util/post/regrider_upper.py @@ -18,14 +18,14 @@ def __init__(self, config): # verify agrid agrid = self.common_in['agrid'] ogrid = self.common_out['ogrid'] + fvrst = os.path.dirname(os.path.realpath(__file__)) + '/fvrst.x -h ' if not self.common_in.get('MERRA-2'): fvcore = '' for f in self.restarts_in: if 'fvcore' in f: fvcore = f break - path_ = os.path.dirname(os.path.realpath(__file__)) - cmd = path_ + '/fvrst.x -h ' + fvcore + cmd = fvrst + fvcore print(cmd +'\n') p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) (output, err) = p.communicate() From bc579c66cc395ab6e95e5f286bec5f6b8841687e Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Wed, 16 Feb 2022 09:49:52 -0500 Subject: [PATCH 15/70] remove shell in subprocess call --- GEOS_Util/post/regrid_questions.py | 3 ++- GEOS_Util/post/regrider_ana.py | 7 ++++--- GEOS_Util/post/regrider_base.py | 1 - GEOS_Util/post/regrider_surf.py | 24 ++++++++++++------------ GEOS_Util/post/regrider_upper.py | 15 ++++++++------- 5 files changed, 26 insertions(+), 24 deletions(-) diff --git a/GEOS_Util/post/regrid_questions.py b/GEOS_Util/post/regrid_questions.py index 070ef795..b074816b 100755 --- a/GEOS_Util/post/regrid_questions.py +++ b/GEOS_Util/post/regrid_questions.py @@ -5,6 +5,7 @@ import os import subprocess +import shlex import yaml import shutil import questionary @@ -294,7 +295,7 @@ def ask_analysis_in(): def ask_slurm_options(): cmd = 'id -gn' - p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) + p = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE) (accounts, err) = p.communicate() p_status = p.wait() accounts = accounts.decode().split() diff --git a/GEOS_Util/post/regrider_ana.py b/GEOS_Util/post/regrider_ana.py index a0aa98d8..855567df 100644 --- a/GEOS_Util/post/regrider_ana.py +++ b/GEOS_Util/post/regrider_ana.py @@ -2,6 +2,7 @@ # import os import subprocess +import shlex import shutil import glob import fileinput @@ -119,7 +120,7 @@ def regrid(self): print( "cd " + self.common_out['out_dir']) os.chdir(self.common_out['out_dir']) tmp_dir = out_dir+'/ana_data/' - if os.path.exists(tmp_dir) : subprocess.call('rm -rf '+ tmp_dir, shell = True) + if os.path.exists(tmp_dir) : subprocess.call(['rm', '-rf', tmp_dir]) print ("mkdir " + tmp_dir) os.makedirs(tmp_dir) print( "cd " + tmp_dir) @@ -155,7 +156,7 @@ def regrid(self): shutil.move(f,f_orig) cmd = bindir + '/dyn2dyn.x ' + flags + ' -o ' + f + ' ' + f_orig print(cmd) - subprocess.call(cmd, shell = True) + subprocess.call(shlex.split(cmd)) for f in local_fs: fname = os.path.basename(f) shutil.move(f, out_dir+'/'+fname) @@ -168,5 +169,5 @@ def regrid(self): rstlcvOut = out_dir+'/'+expid_out+'rst.lcv.'+ymd+'_'+hh+'z.bin' cmd = bindir+'/mkdrstdate.x ' + ymd + ' ' + hms +' ' + rstlcvOut print(cmd) - subprocess.call(cmd, shell = True) + subprocess.call(shlex.split(cmd)) os.chdir(bindir) diff --git a/GEOS_Util/post/regrider_base.py b/GEOS_Util/post/regrider_base.py index 35820413..62e70aad 100644 --- a/GEOS_Util/post/regrider_base.py +++ b/GEOS_Util/post/regrider_base.py @@ -1,7 +1,6 @@ #!/usr/bin/env python3 # import os -import subprocess import shutil import glob import time diff --git a/GEOS_Util/post/regrider_surf.py b/GEOS_Util/post/regrider_surf.py index 5014566c..79f1d95a 100644 --- a/GEOS_Util/post/regrider_surf.py +++ b/GEOS_Util/post/regrider_surf.py @@ -70,9 +70,9 @@ def regrid(self): os.chdir(self.common_out['out_dir']) InData_dir = out_dir+'/InData/' OutData_dir = out_dir+'/OutData/' - if os.path.exists(InData_dir) : subprocess.call('rm -rf '+ InData_dir, shell = True) + if os.path.exists(InData_dir) : subprocess.call(['rm','-rf', InData_dir]) os.makedirs(InData_dir) - if os.path.exists(OutData_dir) : subprocess.call('rm -rf '+ OutData_dir, shell = True) + if os.path.exists(OutData_dir) : subprocess.call(['rm','-rf', OutData_dir]) os.makedirs(OutData_dir) for rst in self.restarts_in: @@ -103,7 +103,7 @@ def regrid(self): if (self.saltwater): cmd = exe + 'OutData/*.til InData/*.til InData/'+self.saltwater + ' 0 ' + str(self.surf_in['zoom']) print('\n'+cmd) - subprocess.call(cmd, shell= True) + subprocess.call(shlex.split(cmd)) # split Saltwater ogrid = self.common_out['ogrid'] @@ -114,35 +114,35 @@ def regrid(self): print("\nSplitting Saltwater...\n") cmd = bindir+'/SaltIntSplitter ' + out_til + ' ' + 'OutData/'+self.saltwater print('\n'+cmd) - subprocess.call(cmd, shell= True) + subprocess.call(shlex.split(cmd)) self.openwater = None self.seaice = None if (self.openwater): cmd = exe + 'OutData/*.til InData/*.til InData/'+self.openwater + ' 0 ' + str(self.surf_in['zoom']) print('\n'+cmd) - subprocess.call(cmd, shell= True) + subprocess.call(shlex.split(cmd)) if (self.seaice): cmd = exe + 'OutData/*.til InData/*.til InData/'+self.seaice + ' 0 ' + str(self.surf_in['zoom']) print('\n'+cmd) - subprocess.call(cmd, shell= True) + subprocess.call(shlex.split(cmd)) if (self.lake): cmd = exe + 'OutData/*.til InData/*.til InData/'+self.lake + ' 19 ' + str(self.surf_in['zoom']) print('\n'+cmd) - subprocess.call(cmd, shell= True) + subprocess.call(shlex.split(cmd)) if (self.landice): cmd = exe + 'OutData/*.til InData/*.til InData/'+self.landice + ' 20 ' + str(self.surf_in['zoom']) print('\n'+cmd) - subprocess.call(cmd, shell= True) + subprocess.call(shlex.split(cmd)) if (self.route): route = bindir + '/mk_RouteRestarts ' cmd = route + 'OutData/*.til '+ self.common_in["yyyymmddhh"][0:6] print('\n'+cmd) - subprocess.call(cmd, shell= True) + subprocess.call(shlex.split(cmd)) if ( self.catchcnclm40 or self.catchcnclm45) : dirname = os.path.dirname(self.out_til) @@ -285,10 +285,10 @@ def regrid(self): catch1.write(catch1script) catch1.close() print("step 1: sbatch -W mk_catch.j.1") - subprocess.call('sbatch -W mk_catch.j.1', shell= True) + subprocess.call(['sbatch','-W', 'mk_catch.j.1']) # step 2 if (self.surf_in['rescale'] and ( self.catch or self.catchcnclm40 or self.catchcnclm45)) : - if os.path.exists('InData.step1') : subprocess.call('rm -rf InData.step1', shell = True) + if os.path.exists('InData.step1') : subprocess.call(['rm','-rf', 'InData.step1']) print("\n Move Indata to InData.step1") shutil.move('InData', 'InData.step1') os.makedirs('InData') @@ -328,7 +328,7 @@ def regrid(self): catch2.write(catch2script) catch2.close() print("step 2: sbatch -W mk_catch.j.2") - subprocess.call('sbatch -W mk_catch.j.2', shell= True) + subprocess.call(['sbatch','-W', 'mk_catch.j.2']) cwd = os.getcwd() for out_rst in glob.glob("OutData/*_rst*"): filename = os.path.basename(out_rst) diff --git a/GEOS_Util/post/regrider_upper.py b/GEOS_Util/post/regrider_upper.py index 3e088508..e5715a14 100644 --- a/GEOS_Util/post/regrider_upper.py +++ b/GEOS_Util/post/regrider_upper.py @@ -2,6 +2,7 @@ # import os import subprocess +import shlex import shutil import glob from regrider_base import * @@ -27,7 +28,7 @@ def __init__(self, config): break cmd = fvrst + fvcore print(cmd +'\n') - p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) + p = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE) (output, err) = p.communicate() p_status = p.wait() ss = output.decode().split() @@ -83,7 +84,7 @@ def regrid(self): print( "cd " + self.common_out['out_dir']) os.chdir(self.common_out['out_dir']) tmpdir = out_dir+'/upper_data/' - if os.path.exists(tmpdir) : subprocess.call('rm -rf '+ tmpdir, shell = True) + if os.path.exists(tmpdir) : subprocess.call(['rm', '-rf',tmpdir]) print ("mkdir " + tmpdir) os.makedirs(tmpdir) @@ -95,22 +96,22 @@ def regrid(self): f = f.replace('_rst','_restart_in') cmd = '/bin/cp '+rst+' '+f print('\n'+cmd) - subprocess.call(cmd, shell = True) + subprocess.call(shlex.split(cmd)) # link topo file topoin = glob.glob(self.in_bcsdir+'/topo_DYN_ave*')[0] cmd = '/bin/cp ' + topoin + ' .' print('\n'+cmd) - subprocess.call(cmd, shell = True) + subprocess.call(shlex.split(cmd)) topoout = glob.glob(self.out_bcsdir+'/topo_DYN_ave*')[0] cmd = '/bin/cp ' + topoout + ' .' print('\n'+cmd) - subprocess.call(cmd, shell = True) + subprocess.call(shlex.split(cmd)) fname = os.path.basename(topoout) cmd = '/bin/ln -s ' + fname + ' topo_dynave.data' print('\n'+cmd) - subprocess.call(cmd, shell = True) + subprocess.call(shlex.split(cmd)) regrid_template="""#!/bin/csh -xf #!/bin/csh -xf @@ -197,7 +198,7 @@ def regrid(self): upper.write(regrid_upper_script) upper.close() print('sbatch -W regrider_upper.j\n') - subprocess.call('sbatch -W regrider_upper.j', shell= True) + subprocess.call(['sbatch', '-W', 'regrider_upper.j']) for out_rst in glob.glob("*_rst*"): filename = os.path.basename(out_rst) print('\n Move ' + out_rst + ' to ' + out_dir+"/"+filename) From 3f1b545fb1209ad21e53cc6f0eb7547e91cbdcb8 Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Tue, 15 Mar 2022 10:28:50 -0400 Subject: [PATCH 16/70] add import --- GEOS_Util/post/regrider_surf.py | 1 + 1 file changed, 1 insertion(+) diff --git a/GEOS_Util/post/regrider_surf.py b/GEOS_Util/post/regrider_surf.py index 79f1d95a..c143cf57 100644 --- a/GEOS_Util/post/regrider_surf.py +++ b/GEOS_Util/post/regrider_surf.py @@ -3,6 +3,7 @@ import os import subprocess import shutil +import shlex import glob from regrider_base import * From f4bbf5e2af126d497c8a2adeaba549e09153a582 Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Thu, 24 Mar 2022 09:02:14 -0400 Subject: [PATCH 17/70] change the structure of regrid_* --- GEOS_Util/post/CMakeLists.txt | 2 +- GEOS_Util/post/regrid_analysis.py | 173 ++++++++++ GEOS_Util/post/regrid_catchment.py | 172 ++++++++++ GEOS_Util/post/regrid_lakelandice.py | 143 ++++++++ GEOS_Util/post/regrid_params.py | 485 +++++++++++++++++++++++++++ GEOS_Util/post/regrid_params.tpl | 55 +++ GEOS_Util/post/regrid_questions.py | 19 +- GEOS_Util/post/regrid_upper.py | 209 ++++++++++++ 8 files changed, 1241 insertions(+), 17 deletions(-) create mode 100755 GEOS_Util/post/regrid_analysis.py create mode 100755 GEOS_Util/post/regrid_catchment.py create mode 100755 GEOS_Util/post/regrid_lakelandice.py create mode 100755 GEOS_Util/post/regrid_params.py create mode 100644 GEOS_Util/post/regrid_params.tpl create mode 100755 GEOS_Util/post/regrid_upper.py diff --git a/GEOS_Util/post/CMakeLists.txt b/GEOS_Util/post/CMakeLists.txt index 103c76b9..58a0efa5 100644 --- a/GEOS_Util/post/CMakeLists.txt +++ b/GEOS_Util/post/CMakeLists.txt @@ -49,7 +49,7 @@ install( PROGRAMS ${perlscripts} ec2grd.csh DESTINATION bin) -file(GLOB pythonscripts CONFIGURE_DEPENDS regrid*.py) +file(GLOB pythonscripts CONFIGURE_DEPENDS regrid*.py regrid_params.tpl) install( PROGRAMS ${pythonscripts} DESTINATION bin) diff --git a/GEOS_Util/post/regrid_analysis.py b/GEOS_Util/post/regrid_analysis.py new file mode 100755 index 00000000..a18a046a --- /dev/null +++ b/GEOS_Util/post/regrid_analysis.py @@ -0,0 +1,173 @@ +#!/usr/bin/env python3 +# +# source g5_modules +# module load python/GEOSpyD/Min4.9.2_py3.9 +# + +import os +from datetime import datetime, timedelta +import subprocess +import shlex +import shutil +import glob +import fileinput +import yaml + +class analysis(object): + def __init__(self, params_file): + stream = open(params_file, 'r') + self.config = yaml.full_load(stream) + stream.close() + + def regrid(self): + config = self.config + bkg = config['output']['analysis']['bkg'] + if ( not bkg ): return + + agrid_in = config['input']['shared']['agrid'] + agrid_out = config['output']['shared']['agrid'] + + if (self.get_grid_kind(agrid_in.upper()) == self.get_grid_kind(agrid_out.upper())): + print(" No need to regrid anaylysis file") + return + + bindir = os.getcwd() + in_bcsdir = config['input']['shared']['bcs_dir'] + out_bcsdir = config['output']['shared']['bcs_dir'] + out_dir = config['output']['shared']['out_dir'] + if not os.path.exists(out_dir) : os.makedirs(out_dir) + print( "cd " + out_dir) + os.chdir(out_dir) + + tmpdir = out_dir+'/ana_data/' + if os.path.exists(tmpdir) : subprocess.call(['rm', '-rf',tmpdir]) + print ("mkdir " + tmpdir) + os.makedirs(tmpdir) + + print( "cd " + tmpdir) + os.chdir(tmpdir) + + rst_dir_orig = config['input']['analysis']['rst_dir'] + if (not rst_dir_orig): rst_dir_orig = config['input']['shared']['rst_dir'] + anafiles = glob.glob(rst_dir_orig +'/analysis/*') + yyyymmddhh_ = str(config['input']['shared']['yyyymmddhh']) + yyyy_ = yyyymmddhh_[0:4] + mm_ = yyyymmddhh_[4:6] + dd_ = yyyymmddhh_[6:8] + hh_ = yyyymmddhh_[8:10] + rst_time = datetime(year=int(yyyy_), month=int(mm_), day=int(dd_), hour = int(hh_)) + expid_in = config['input']['shared']['expid'] + expid_out = config['output']['shared']['expid'] + if (expid_out) : + expid_out = expid_out + '.' + else: + expid_out = '' + + if len(anafiles) == 0 : + anafiles=[] + for h in [3,4,5,6,7,8,9]: + delt = timedelta(hours = h-3) + new_time = rst_time + delt + yyyy = "Y"+str(new_time.year) + mm = 'M%02d'%new_time.month + ymd = '%04d%02d%02d'%(new_time.year,new_time.month, new_time.day) + hh = '%02d'%h + newhh= '%02d'%new_time.hour + rst_dir = rst_dir_orig.replace('Y'+yyyy_,yyyy).replace('M'+mm_,mm) + # bkg files + for ftype in ['sfc', 'eta']: + fname = expid_in+'.bkg'+hh+'_'+ftype+'_rst.'+ymd+'_'+newhh+'z.nc4' + f = rst_dir+'/'+fname + if(os.path.isfile(f)): + anafiles.append(f) + else: + print('Warning: Cannot find '+f) + + # cbkg file + fname = expid_in + '.cbkg' + hh + '_eta_rst.' + ymd + '_' + newhh + 'z.nc4' + f = rst_dir+'/'+fname + if(os.path.isfile(f)): + anafiles.append(f) + else: + print('Warning: Cannot find '+f) + # gaas_bkg_sfc files + if (h==6 or h==9): + fname = expid_in+'.gaas_bkg_sfc_rst.'+ymd+'_'+newhh+'z.nc4' + f = rst_dir+'/'+fname + if (os.path.isfile(f)): + anafiles.append(f) + else: + print('Warning: Cannot find '+f) + # trak.GDA.rst file + delt = timedelta(hours = 3) + new_time = rst_time - delt + yyyy = "Y"+str(new_time.year) + mm = 'M%02d'%new_time.month + ymdh = '%04d%02d%02d%02d'%(new_time.year, new_time.month, new_time.day, new_time.hour) + rst_dir = rst_dir_orig.replace('Y'+yyyy_,yyyy).replace('M'+mm_,mm) + fname = expid_in+'.trak.GDA.rst.'+ymdh+'z.txt' + f = rst_dir+'/'+fname + if (os.path.isfile(f)): anafiles.append(f) + + aqua = config['output']['analysis']['aqua'] + local_fs=[] + for f in anafiles: + fname = os.path.basename(f) + out_name = fname.replace(expid_in, expid_out) + f_tmp = tmpdir+'/'+out_name + local_fs.append(f_tmp) + shutil.copy(f,f_tmp) + if out_name.find('satbias') != -1 : + if (aqua): + f_orig = f_tmp+'.orig' + shutil.move(f_tmp, f_orig) + f_ = open(f_tmp, 'w') + for line in fileinput.input(f_orig): + f_.write(line.replace('airs281SUBSET_aqua', 'airs281_aqua ')) + f_.close() + + + nlevel = config['output']['air']['nlevel'] + flags = "-g5 -res " + self.get_grid_kind(agrid_out.upper()) + " -nlevs " + str(nlevel) + bkg_files = glob.glob(tmpdir+'/*.bkg??_eta_rst*') + for f in bkg_files: + f_orig = f + ".orig" + shutil.move(f,f_orig) + cmd = bindir + '/dyn2dyn.x ' + flags + ' -o ' + f + ' ' + f_orig + print(cmd) + subprocess.call(shlex.split(cmd)) + for f in local_fs: + fname = os.path.basename(f) + shutil.move(f, out_dir+'/'+fname) + # write lcv + lcv = config['output']['analysis']['lcv'] + if lcv : + ymd_ = yyyymmddhh_[0:8] + hh_ = yyyymmddhh_[8:10] + hms_ = hh_+'0000' + rstlcvOut = out_dir+'/'+expid_out+'rst.lcv.'+ymd_+'_'+hh_+'z.bin' + cmd = bindir+'/mkdrstdate.x ' + ymd_ + ' ' + hms_ +' ' + rstlcvOut + print(cmd) + subprocess.call(shlex.split(cmd)) + os.chdir(bindir) + + def get_grid_kind(this, grid): + hgrd = {} + hgrd['C12'] = 'a' + hgrd['C24'] = 'a' + hgrd['C48'] = 'b' + hgrd['C90'] = 'c' + hgrd['C180'] = 'd' + hgrd['C360'] = 'd' + hgrd['C500'] = 'd' + hgrd['C720'] = 'e' + hgrd['C1000'] = 'e' + hgrd['C1440'] = 'e' + hgrd['C2000'] = 'e' + hgrd['C2880'] = 'e' + hgrd['C5760'] = 'e' + return hgrd[grid] + +if __name__ == '__main__' : + ana = analysis('regrid_params.yaml') + ana.regrid() diff --git a/GEOS_Util/post/regrid_catchment.py b/GEOS_Util/post/regrid_catchment.py new file mode 100755 index 00000000..da4aea15 --- /dev/null +++ b/GEOS_Util/post/regrid_catchment.py @@ -0,0 +1,172 @@ +#!/usr/bin/env python3 +# +import os +import subprocess +import shutil +import glob +import yaml +import shlex + +class catchment(object): + def __init__(self, params_file): + stream = open(params_file, 'r') + self.config = yaml.full_load(stream) + stream.close() + + def regrid(self): + print("\nRegridding land, landice, saltwater.....\n") + config = self.config + bindir = os.getcwd() + in_bcsdir = config['input']['shared']['bcs_dir'] + out_bcsdir = config['output']['shared']['bcs_dir'] + out_dir = config['output']['shared']['out_dir'] + if not os.path.exists(out_dir) : os.makedirs(out_dir) + print( "cd " + out_dir) + os.chdir(out_dir) + + InData_dir = out_dir+'/InData/' + if os.path.exists(InData_dir) : subprocess.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]) + print ("mkdir " + OutData_dir) + os.makedirs(OutData_dir) + + rst_dir = config['input']['surface']['rst_dir'] + if (not rst_dir): rst_dir = config['input']['shared']['rst_dir'] + restarts_in = glob.glob(rst_dir +'surface/*') + yyyymmddhh_ = str(config['input']['shared']['yyyymmddhh']) + suffix = yyyymmddhh_[0:8]+'_'+yyyymmddhh_[8:10]+'z.nc4' + if (not restarts_in) : + # from merra-2 + restarts_in = glob.glob(rst_dir +'/*catch*') + if restarts_in[0].find('z.bin') != -1 : suffix = yyyymmddhh_[0:8]+'_'+yyyymmddhh_[8:10]+'z.bin' + + def find_rst(rsts,rst_name): + for rst in rsts: + f = os.path.basename(rst) + if (f.find(rst_name) != -1): + return rst + return None + catch = find_rst(restarts_in,'catch_') + if (not catch) : + print(" No catchment restart") + return + + catch_f = os.path.basename(catch) + dest = InData_dir+'/'+ catch_f + if os.path.exists(dest) : shutil.remove(dest) + print('\nCopy ' + catch + ' to ' +dest) + shutil.copy(catch , dest) + + in_tile_file = glob.glob(in_bcsdir+ '/*-Pfafstetter.til')[0] + out_tile_file = glob.glob(out_bcsdir+ '/*-Pfafstetter.til')[0] + + in_til = InData_dir+'/' + in_tile_file.split('/')[-1] + out_til = OutData_dir+'/'+ out_tile_file.split('/')[-1] + + if os.path.exists(in_til) : shutil.remove(in_til) + if os.path.exists(out_til) : shutil.remove(out_til) + print('\n Copy ' + in_tile_file + ' to ' + in_til) + shutil.copy(in_tile_file, in_til) + print('\n Copy ' + out_tile_file + ' to ' + out_til) + shutil.copy(out_tile_file, out_til) + + mk_catch_j_template = """#!/bin/csh -f +#SBATCH --account={account} +#SBATCH --ntasks=84 +#SBATCH --time=1:00:00 +#SBATCH --job-name=mk_catch +#SBATCH --qos=debug +#SBATCH --output={out_dir}/{mk_catch_log} +# + +source {Bin}/g5_modules +set echo + +#limit stacksize unlimited +unlimit + +set esma_mpirun_X = ( {Bin}/esma_mpirun -np 84 ) +set mk_CatchRestarts_X = ( $esma_mpirun_X {Bin}/mk_CatchRestarts ) +set Scale_Catch_X = {Bin}/Scale_Catch + +set catchIN = InData/{catch_f} +set params = ( {out_til} {in_til} $catchIN {surflay} ) +$mk_CatchRestarts_X $params + +if ({rescale}) then + + set catch_regrid = OutData/{catch_f} + set catch_scaled = $catch_regrid.scaled + set params = ( $catchIN $catch_regrid $catch_scaled {surflay} ) + set params = ( $params {wemin} {wemout} ) + $Scale_Catch_X $params + + rm $catch_regrid + #mv $catch_regrid $catch_regrid.1 + mv $catch_scaled $catch_regrid +endif +""" + # step 1 + expid = config['output']['shared']['expid'] + wemin = config['input']['surface']['wemin'] + wemout = config['output']['surface']['wemout'] + surflay= config['output']['surface']['surflay'] + account = config['slurm']['account'] + + catch1script = mk_catch_j_template.format(Bin = bindir, account = account, \ + out_dir = out_dir, mk_catch_log = 'mk_catch_log.1', surflay = surflay, \ + wemin = wemin, wemout = wemout, out_til = out_til, in_til = in_til, catch_f = catch_f, rescale = '0') + catch1 = open('mk_catch.j.1','wt') + catch1.write(catch1script) + catch1.close() + print("step 1: sbatch -W mk_catch.j.1") + subprocess.call(['sbatch','-W', 'mk_catch.j.1']) + + # step 2 + if os.path.exists('InData.step1') : subprocess.call(['rm','-rf', 'InData.step1']) + print("\n Move Indata to InData.step1") + shutil.move('InData', 'InData.step1') + os.makedirs('InData') + for catchfile in glob.glob("OutData/*catch*"): + print('\n Move ' + catchfile + ' to InData/') + shutil.move(catchfile,"InData/") + print('\n Link ' + out_til + ' to ' + in_til) + os.symlink(out_til, in_til) + + dirname = os.path.dirname(out_til) + clsm = dirname+'/clsm' + print('\n Link ' + clsm + ' to ' + 'OutData/clsm') + os.symlink(clsm, 'OutData/clsm') + + catch2script = mk_catch_j_template.format(Bin = bindir, account = account, \ + out_dir = out_dir, mk_catch_log = 'mk_catch_log.1', surflay = surflay, \ + wemin = wemin, wemout = wemout, out_til = out_til, in_til = in_til, catch_f = catch_f, rescale = '1') + + catch2 = open('mk_catch.j.2','wt') + catch2.write(catch2script) + catch2.close() + print("step 2: sbatch -W mk_catch.j.2") + subprocess.call(['sbatch','-W', 'mk_catch.j.2']) +# +# post process +# + if (expid) : + expid = expid + '.' + else: + expid = '' + suffix = '_rst.' + suffix + for out_rst in glob.glob("OutData/*_rst*"): + filename = expid + os.path.basename(out_rst).split('_rst')[0].split('.')[-1]+suffix + print('\n Move ' + out_rst + ' to ' + out_dir+"/"+filename) + shutil.move(out_rst, out_dir+"/"+filename) + os.chdir(bindir) + +if __name__ == '__main__' : + catch = catchment('regrid_params.yaml') + catch.regrid() + + diff --git a/GEOS_Util/post/regrid_lakelandice.py b/GEOS_Util/post/regrid_lakelandice.py new file mode 100755 index 00000000..792d57ae --- /dev/null +++ b/GEOS_Util/post/regrid_lakelandice.py @@ -0,0 +1,143 @@ +#!/usr/bin/env python3 +# +import os +import subprocess +import shutil +import glob +import yaml +import shlex + +class lakelandice(object): + def __init__(self, params_file): + stream = open(params_file, 'r') + self.config = yaml.full_load(stream) + stream.close() + + def regrid(self): + print("\nRegridding land, landice, saltwater.....\n") + config = self.config + bindir = os.getcwd() + in_bcsdir = config['input']['shared']['bcs_dir'] + out_bcsdir = config['output']['shared']['bcs_dir'] + out_dir = config['output']['shared']['out_dir'] + if not os.path.exists(out_dir) : os.makedirs(out_dir) + print( "cd " + out_dir) + os.chdir(out_dir) + + InData_dir = out_dir+'/InData/' + if os.path.exists(InData_dir) : subprocess.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]) + print ("mkdir " + OutData_dir) + os.makedirs(OutData_dir) + + rst_dir = config['input']['surface']['rst_dir'] + if (not rst_dir): rst_dir = config['input']['shared']['rst_dir'] + restarts_in = glob.glob(rst_dir +'surface/*') + yyyymmddhh_ = str(config['input']['shared']['yyyymmddhh']) + suffix = yyyymmddhh_[0:8]+'_'+yyyymmddhh_[8:10]+'z.nc4' + if (not restarts_in) : + expid = config['input']['shared']['expid'] + suffix = yyyymmddhh_[0:8]+'_'+yyyymmddhh_[8:10]+'z.bin' + # from merra-2 + restarts_in = [rst_dir + expid + '.catch_internal_rst.' + suffix, + rst_dir + expid + '.lake_internal_rst.' + suffix, + rst_dir + expid + '.landice_internal_rst.' + suffix, + rst_dir + expid + '.saltwater_internal_rst.'+ suffix] + + def find_rst(rsts,rst_name): + for rst in rsts: + f = os.path.basename(rst) + if (f.find(rst_name) != -1): + return f + return None + + saltwater = find_rst(restarts_in,'saltwater') + openwater = find_rst(restarts_in,'openwater') + seaice = find_rst(restarts_in,'seaice') + landice = find_rst(restarts_in,'landice') + lake = find_rst(restarts_in,'lake') + route = find_rst(restarts_in,'route') + + for rst in restarts_in: + f = os.path.basename(rst) + dest = InData_dir+'/'+f + if os.path.exists(dest) : shutil.remove(dest) + print('\nCopy ' + rst + ' to ' +dest) + shutil.copy(rst,dest) + + in_tile_file = glob.glob(in_bcsdir+ '/*-Pfafstetter.til')[0] + out_tile_file = glob.glob(out_bcsdir+ '/*-Pfafstetter.til')[0] + + in_til = InData_dir+'/' + in_tile_file.split('/')[-1] + out_til = OutData_dir+'/'+ out_tile_file.split('/')[-1] + + if os.path.exists(in_til) : shutil.remove(in_til) + if os.path.exists(out_til) : shutil.remove(out_til) + print('\n Copy ' + in_tile_file + ' to ' + in_til) + shutil.copy(in_tile_file, in_til) + print('\n Copy ' + out_tile_file + ' to ' + out_til) + shutil.copy(out_tile_file, out_til) + + exe = bindir + '/mk_LakeLandiceSaltRestarts ' + zoom = config['output']['surface']['zoom'] + + if (saltwater): + cmd = exe + out_til + ' ' + in_til + ' InData/'+ saltwater + ' 0 ' + str(zoom) + print('\n'+cmd) + subprocess.call(shlex.split(cmd)) + + # split Saltwater + if config['output']['surface']['split_saltwater']: + print("\nSplitting Saltwater...\n") + cmd = bindir+'/SaltIntSplitter ' + out_til + ' ' + 'OutData/' + saltwater + print('\n'+cmd) + subprocess.call(shlex.split(cmd)) + openwater = None + seaice = None + + if (openwater): + cmd = exe + out_til + ' ' + in_til + ' InData/' + openwater + ' 0 ' + str(zoom) + print('\n'+cmd) + subprocess.call(shlex.split(cmd)) + + if (seaice): + cmd = exe + out_til + ' ' + in_til + ' InData/' + seaice + ' 0 ' + str(zoom) + print('\n'+cmd) + subprocess.call(shlex.split(cmd)) + + if (lake): + cmd = exe + out_til + ' ' + in_til + ' InData/' + lake + ' 19 ' + str(zoom) + print('\n'+cmd) + subprocess.call(shlex.split(cmd)) + + if (landice): + cmd = exe + out_til + ' ' + in_til + ' InData/' + landice + ' 20 ' + str(zoom) + print('\n'+cmd) + subprocess.call(shlex.split(cmd)) + + if (route): + route = bindir + '/mk_RouteRestarts ' + cmd = route + out_til + ' ' + yyyymmddhh_[0:6] + print('\n'+cmd) + subprocess.call(shlex.split(cmd)) + + expid = config['output']['shared']['expid'] + if (expid) : + expid = expid + '.' + else: + expid = '' + suffix = '_rst.' + suffix + for out_rst in glob.glob("OutData/*_rst*"): + filename = expid + os.path.basename(out_rst).split('_rst')[0].split('.')[-1]+suffix + print('\n Move ' + out_rst + ' to ' + out_dir+"/"+filename) + shutil.move(out_rst, out_dir+"/"+filename) + os.chdir(bindir) + +if __name__ == '__main__' : + lli = lakelandice('regrid_params.yaml') + lli.regrid() + diff --git a/GEOS_Util/post/regrid_params.py b/GEOS_Util/post/regrid_params.py new file mode 100755 index 00000000..edcac6a5 --- /dev/null +++ b/GEOS_Util/post/regrid_params.py @@ -0,0 +1,485 @@ +#!/usr/bin/env python3 +# +import os +import yaml +import shutil +import glob +import time +import questionary +from datetime import datetime +from datetime import timedelta + +class regrid_params(object): + def __init__(self, config_from_question): + self.common_in = config_from_question['input']['parameters']['COMMON'] + self.common_out = config_from_question['output']['parameters']['COMMON'] + self.upper_out = config_from_question['output']['parameters']['UPPERAIR'] + self.slurm_options = config_from_question['slurm_options'] + self.surf_in = config_from_question['input']['parameters']['SURFACE'] + self.surf_out = config_from_question['output']['parameters']['SURFACE'] + #self.ana_in = config_from_question['input']['parameters']['ANALYSIS'] + self.ana_out = config_from_question['output']['parameters']['ANALYSIS'] + + self.init_time() + self.init_tags() + self.init_merra2() + self.init_restarts_in() + + # get bc directory and tile file + self.in_bcsdir = self.get_bcdir("IN") + self.in_til = glob.glob(self.in_bcsdir+ '/*-Pfafstetter.til')[0] + print("\ninput tile file: " + self.in_til) + self.out_bcsdir = self.get_bcdir("OUT") + self.out_til = glob.glob(self.out_bcsdir+ '/*-Pfafstetter.til')[0] + print("\noutput tile file: " + self.out_til) + + # load input yaml + stream = open('regrid_params.tpl', 'r') + config_tpl = yaml.full_load(stream) + + # params for shared + + config_tpl['input']['shared']['agrid'] = self.common_in['agrid'] + config_tpl['input']['shared']['ogrid'] = self.common_in['ogrid'] + config_tpl['input']['shared']['bcs_dir'] = self.in_bcsdir + config_tpl['input']['shared']['rst_dir'] = self.common_in['rst_dir'] + config_tpl['input']['shared']['expid'] = self.common_in['expid'] + config_tpl['input']['shared']['yyyymmddhh'] = self.common_in['yyyymmddhh'] + + config_tpl['output']['shared']['agrid'] = self.common_out['agrid'] + config_tpl['output']['shared']['ogrid'] = self.common_out['ogrid'] + config_tpl['output']['shared']['bcs_dir'] = self.out_bcsdir + config_tpl['output']['shared']['out_dir'] = self.common_out['out_dir'] + config_tpl['output']['shared']['expid'] = self.common_out['expid'] + + # 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(config_tpl) + + self.config = config_tpl + + def convert_to_yaml(self) : + if os.path.exists('regrid_params.yaml') : + overwrite = questionary.confirm("Do you want to overwrite regrid_params.yaml file?", default=False).ask() + if not overwrite : + while True: + new_name = questionary.text("What's the backup name for existing regrid_params.yaml?", default='regrid_params.yaml.1').ask() + if os.path.exists(new_name): + print('\n'+ new_name + ' exists, please enter a new one. \n') + else: + shutil.move('regrid_params.yaml', new_name) + break + f = open("regrid_params.yaml", "w") + yaml.dump(self.config, f, allow_unicode=True, default_flow_style=False) + f.close() + + def init_tags(self): + # copy and paste from regrid.pl + # minor change. Add "D" to the number for each group + # BCS Tag: Fortuna-1_4 + F14 = ( 'F14', 'Fortuna-1_4', 'Fortuna-1_4_p1' ) + D214 = ( 'D214', 'GEOSdas-2_1_4', 'GEOSdas-2_1_4-m1', + 'GEOSdas-2_1_4-m2', 'GEOSdas-2_1_4-m3', 'GEOSdas-2_1_4-m4' ) + D540 = ( 'D540', 'GEOSadas-5_4_0', 'GEOSadas-5_4_0_p1', + 'GEOSadas-5_4_0_p2', 'GEOSadas-5_4_0_p3', 'GEOSadas-5_4_0_p4', + 'GEOSadas-5_4_1', 'GEOSadas-5_4_1_p1', 'GEOSadas-5_4_2', + 'GEOSadas-5_4_3', 'GEOSadas-5_4_4', 'GEOSadas-5_5_0', + 'GEOSadas-5_5_1', 'GEOSadas-5_5_2', 'GEOSadas-5_5_3' ) + + # BCS Tag: Fortuna-2_0 + #--------------------- + F20 = ( 'F20', 'Fortuna-2_0') + + # BCS Tag: Fortuna-2_1 + #--------------------- + F21 = ( 'F21', 'Fortuna-2_1', 'Fortuna-2_1_p1', + 'Fortuna-2_1_p2', 'Fortuna-2_1_p3', 'Fortuna-2_2', + 'Fortuna-2_2_p1', 'Fortuna-2_2_p2', 'Fortuna-2_3', + 'Fortuna-2_3_p1', 'Fortuna-2_4', 'Fortuna-2_4_p1', + 'Fortuna-2_4_p2', 'Fortuna-2_5', 'Fortuna-2_5_BETA0', + 'Fortuna-2_5_p1', 'Fortuna-2_5_p2', 'Fortuna-2_5_p3', + 'Fortuna-2_5_p4', 'Fortuna-2_5_p5', 'Fortuna-2_5_p6', + 'Fortuna-2_5_pp2' ) + D561 = ( 'D561', 'GEOSadas-5_6_1', 'GEOSadas-5_6_1_p1', + 'GEOSadas-5_6_1_p2', 'GEOSadas-5_6_1_p3', 'GEOSadas-5_6_1_p4', + 'GEOSadas-5_6_2', 'GEOSadas-5_6_2_p1', 'GEOSadas-5_6_2_p2', + 'GEOSadas-5_6_2_p3', 'GEOSadas-5_6_2_p4', 'GEOSadas-5_6_2_p5', + 'GEOSadas-5_6_2_p6', 'GEOSadas-5_7_1', 'GEOSadas-5_7_1_p1', + 'GEOSadas-5_7_1_p2', 'GEOSadas-5_7_2', 'GEOSadas-5_7_2_p1', + 'GEOSadas-5_7_2_p2', 'GEOSadas-5_7_2_p2_m1','GEOSadas-5_7_2_p3', + 'GEOSadas-5_7_2_p3_m1', 'GEOSadas-5_7_2_p3_m2','GEOSadas-5_7_2_p4', + 'GEOSadas-5_7_2_p5', 'GEOSadas-5_7_2_p5_m1','GEOSadas-5_7_3', + 'GEOSadas-5_7_3_p1', 'GEOSadas-5_7_3_p2', 'GEOSadas-5_7_3_p2' ) + + # BCS Tag: Ganymed-1_0 + #--------------------- + G10 = ( 'G10', 'Ganymed-1_0', 'Ganymed-1_0_BETA', + 'Ganymed-1_0_BETA1', 'Ganymed-1_0_BETA2', 'Ganymed-1_0_BETA3', + 'Ganymed-1_0_BETA4' ) + + D580 = ( 'D580', 'GEOSadas-5_8_0', 'GEOSadas-5_9_0', + 'GEOSadas-5_9_1' ) + + # BCS Tags: Ganymed-1_0_M and Ganymed-1_0_D + #------------------------------------------ + G10p = ( 'G10p', 'Ganymed-1_0_p1', 'Ganymed-1_0_p2', + 'Ganymed-1_0_p3', 'Ganymed-1_0_p4', 'Ganymed-1_0_p5', + 'Ganymed-1_0_p6' ) + + D591p= ( 'D591p', 'GEOSadas-5_9_1_p1', 'GEOSadas-5_9_1_p2', + 'GEOSadas-5_9_1_p3', 'GEOSadas-5_9_1_p4', 'GEOSadas-5_9_1_p5', + 'GEOSadas-5_9_1_p6', 'GEOSadas-5_9_1_p7', 'GEOSadas-5_9_1_p8', + 'GEOSadas-5_9_1_p9' ) + + # BCS Tags: Ganymed-1_0_M and Ganymed-1_0_D w/ new landice rst + #------------------------------------------------------------------------ + G20 = ( 'G20', 'Ganymed-2_0', 'Ganymed-2_1', + 'Ganymed-2_1_p1', 'Ganymed-2_1_p2', 'Ganymed-2_1_p3', + 'Ganymed-2_1_p4', 'Ganymed-2_1_p5', 'Ganymed-2_1_p6' ) + D5A0 = ( 'D5A0', 'GEOSadas-5_10_0', 'GEOSadas-5_10_0_p1' ) + + + # BCS Tags: Ganymed-1_0_Reynolds and Ganymed-1_0_Ostia + #----------------------------------------------------- + G30 = ( 'G30', 'Ganymed-3_0', 'Ganymed-3_0_p1' ) + D5B0 = ( 'D5B0', 'GEOSadas-5_10_0_p2', 'GEOSadas-5_11_0' ) + + # BCS Tags: Ganymed-4_0_Reynolds, Ganymed-4_0_MERRA-2, and Ganymed-4_0_Ostia + #--------------------------------------------------------------------------- + G40 = ( 'G40', 'Ganymed-4_0', 'Ganymed-4_0_p1', + 'Ganymed-4_1', 'Heracles-1_0', 'Heracles-1_1', + 'Heracles-2_0', 'Heracles-2_1', 'Heracles-3_0', + 'Heracles-4_0', 'Heracles-5_4_p3' ) + D512 = ( 'D512', 'GEOSadas-5_12_2', 'GEOSadas-5_12_4', + 'GEOSadas-5_12_4_p1', 'GEOSadas-5_12_4_p2', 'GEOSadas-5_12_4_p3', + 'GEOSadas-5_12_5', 'GEOSadas-5_13_0_p1', 'GEOSadas-5_13_0_p2', + 'GEOSadas-5_13_1', 'GEOSadas-5_16_5' ) + + # BCS Tags: Icarus (New Land Parameters, New Topography) + #--------------------------------------------------------------------------- + ICA = ( 'ICA', 'Icarus', 'Jason' ) + D517 = ( 'D517', 'GEOSadas-5_17_0', 'GEOSadas-5_17_1', 'GEOSadas-5_18_0', + 'GEOSadas-5_18_1', 'GEOSadas-5_18_2', 'GEOSadas-5_18_3', + 'GEOSadas-5_18_3_p1', 'GEOSadas-5_19_0', 'GEOSadas-5_20_0', + 'GEOSadas-5_20_0_p1', 'GEOSadas-5_20_0_p2', 'GEOSadas-5_21_0', + 'GEOSadas-5_21_2', 'GEOSadas-5_21_3_p1', 'GEOSadas-5_22_0', + 'GEOSadas-5_22_0_p1', 'GEOSadas-5_22_0_p2', 'GEOSadas-5_23_0', + 'GEOSadas-5_23_0_p1', 'GEOSadas-5_24_0', 'GEOSadas-5_24_0_p1' ) + + # BCS Tags: Icarus-NLv3 (New Land Parameters) + #--------------------------------------------------------------------------- + INL = ( 'INL', 'Icarus-NL', 'Icarus-NLv3', 'Jason-NL' ) + + self.bcsTag={} + for tag in F14: self.bcsTag[tag]= "Fortuna-1_4" + for tag in F20: self.bcsTag[tag]= "Fortuna-2_0" + for tag in F21: self.bcsTag[tag]= "Fortuna-2_1" + for tag in G10: self.bcsTag[tag]= "Ganymed-1_0" + for tag in G10p: self.bcsTag[tag]= "Ganymed-1_0_M" + for tag in G20: self.bcsTag[tag]= "Ganymed-1_0_M" + for tag in G30: self.bcsTag[tag]= "Ganymed-1_0_Reynolds" + for tag in G40: self.bcsTag[tag]= "Ganymed-4_0_Reynolds" + for tag in ICA: self.bcsTag[tag]= "Icarus_Reynolds" + for tag in INL: self.bcsTag[tag]= "Icarus-NLv3_Reynolds" + + + for tag in D214: self.bcsTag[tag]= "Fortuna-1_4" + for tag in D540: self.bcsTag[tag]= "Fortuna-1_4" + for tag in D561: self.bcsTag[tag]= "Fortuna-2_1" + for tag in D580: self.bcsTag[tag]= "Ganymed-1_0" + for tag in D591p: self.bcsTag[tag]= "Ganymed-1_0_M" + for tag in D5A0: self.bcsTag[tag]= "Ganymed-1_0_M" + for tag in D5B0: self.bcsTag[tag]= "Ganymed-1_0_Reynolds" + for tag in D512: self.bcsTag[tag]= "Ganymed-4_0_Reynolds" + for tag in D517: self.bcsTag[tag]= "Icarus_Reynolds" + + self.tagsRank ={} + self.tagsRank['Fortuna-1_4'] = 1 + self.tagsRank['Fortuna-1_5'] = 2 + self.tagsRank['Fortuna-2_0'] = 3 + self.tagsRank['Fortuna-2_1'] = 4 + self.tagsRank['Ganymed-1_0'] = 5 + self.tagsRank['Ganymed-1_0_m1'] = 6 + self.tagsRank['Ganymed-1_0_m2'] = 7 + self.tagsRank['Ganymed-1_0_M'] = 8 + self.tagsRank['Ganymed-1_0_D'] = 9 + self.tagsRank['Ganymed-1_0_Reynolds'] = 10 + self.tagsRank['Ganymed-1_0_Ostia'] = 11 + self.tagsRank['Ganymed-4_0_Reynolds'] = 12 + self.tagsRank['Ganymed-4_0_Ostia'] = 13 + self.tagsRank['Ganymed-4_0_MERRA-2'] = 14 + self.tagsRank['Icarus_Reynolds'] = 15 + self.tagsRank['Icarus_MERRA-2'] = 16 + self.tagsRank['Icarus_Ostia'] = 17 + self.tagsRank['Icarus-NLv3_Reynolds'] = 18 + self.tagsRank['Icarus-NLv3_MERRA-2'] = 19 + self.tagsRank['Icarus-NLv3_Ostia'] = 20 + + self.bcbase={} + self.bcbase['discover_ops'] = "/discover/nobackup/projects/gmao/share/gmao_ops/fvInput/g5gcm/bcs" + self.bcbase['discover_lt'] = "/discover/nobackup/ltakacs/bcs" + self.bcbase['discover_couple'] = "/discover/nobackup/projects/gmao/ssd/aogcm/atmosphere_bcs" + + def init_time(self): + yyyymmddhh = str(self.common_in['yyyymmddhh']) + self.yyyymm = yyyymmddhh[0:6] + self.yyyy = yyyymmddhh[0:4] + self.mm = yyyymmddhh[4:6] + self.dd = yyyymmddhh[6:8] + self.hh = yyyymmddhh[8:10] + self.ymd = yyyymmddhh[0:8] + + def init_restarts_in(self): + if self.common_in['MERRA-2']: + return + + rst_dir = self.common_in.get('rst_dir')+'/' + self.restarts_in={} + self.restarts_in['UPPERAIR'] = glob.glob(rst_dir +'upperair/*') + self.restarts_in['SURFACE'] = glob.glob(rst_dir +'surface/*') + self.restarts_in['ANALYSIS'] = glob.glob(rst_dir +'analysis/*') + + def init_merra2(self): + if not self.common_in['MERRA-2']: + return + print("\nMERRA-2 sources:\n") + yyyymm = int(self.yyyymm) + if yyyymm < 197901 : + print("Error. MERRA-2 data < 1979 not available\n") + exit() + elif (yyyymm < 199201): + self.common_in['expid'] = "d5124_m2_jan79" + elif (yyyymm < 200106): + self.common_in['expid'] = "d5124_m2_jan91" + elif (yyyymm < 201101): + self.common_in['expid'] = "d5124_m2_jan00" + else: + self.common_in['expid'] = "d5124_m2_jan10" + + self.common_in['agrid'] = 'C180' + self.common_in['ogrid'] = '1440x720' + self.common_in['bc_base']= 'discover_ops' + self.common_in['tag']= 'Ganymed-4_0' + expid = self.common_in['expid'] + yyyymmddhh = str(self.common_in['yyyymmddhh']) + surfix = yyyymmddhh[0:8]+'_'+self.hh+'z.bin' + self.common_in['rst_dir'] = '/archive/users/gmao_ops/MERRA2/gmao_ops/GEOSadas-5_12_4/'+expid +'/rs/Y'+self.yyyy +'/M'+self.mm+'/' + print('\nMERRA-2 Restart dir: ' + self.common_in['rst_dir'] +'\n') + + self.restarts_in = {} + upperin =[self.common_in['rst_dir']+ expid+'.fvcore_internal_rst.' + surfix, + self.common_in['rst_dir']+ expid+'.moist_internal_rst.' + surfix, + self.common_in['rst_dir']+ expid+'.agcm_import_rst.' + surfix, + self.common_in['rst_dir']+ expid+'.gocart_internal_rst.' + surfix, + self.common_in['rst_dir']+ expid+'.pchem_internal_rst.' + surfix ] + self.restarts_in['UPPERAIR'] = upperin + + surfin = [self.common_in['rst_dir']+ expid+'.catch_internal_rst.' + surfix, + self.common_in['rst_dir']+ expid+'.lake_internal_rst.' + surfix, + self.common_in['rst_dir']+ expid+'.landice_internal_rst.' + surfix, + self.common_in['rst_dir']+ expid+'.saltwater_internal_rst.'+ surfix] + self.restarts_in['SURFACE'] = surfin + self.restarts_in['ANALYSIS'] = [] + + def get_bcbase(self, opt): + base = '' + model = '' + + if opt.upper() == 'IN': + model = self.common_in.get('model') + if model == 'MOM6' or model == 'MOM5': + base = 'discover_couple' + else: + base = self.common_in.get('bc_base') + + if opt.upper() == 'OUT': + model = self.common_out.get('model') + if model == 'MOM6' or model == 'MOM5': + base = 'discover_couple' + else: + base = self.common_out.get('bc_base') + assert base, 'please specify bc_base: discover_ops, discover_lt, discover_couple or an absolute path' + if base == 'discover_ops' or base == 'discover_lt' or base=='discover_couple': + return self.bcbase[base] + else: + return base + + def get_bcdir(self, opt): + tag = self.common_in['tag'] + ogrid = self.common_in['ogrid'] + model = self.common_in['model'] + bcdir = self.common_in.get('alt_bcs', None) + if opt.upper() == "OUT": + tag = self.common_out['tag'] + ogrid = self.common_out['ogrid'] + model = self.common_out['model'] + bcdir = self.common_in.get('alt_bcs', None) + + if bcdir is None : + bc_base = self.get_bcbase(opt) + bctag = self.get_bcTag(tag,ogrid) + tagrank = self.tagsRank[bctag] + if (tagrank >= self.tagsRank['Icarus-NLv3_Reynolds']) : + bcdir = bc_base+'/Icarus-NLv3/'+bctag+'/' + if model == 'MOM6' or model == 'MOM5': + bcdir = bc_base+'/Icarus-NLv3/'+model+'/' + elif (tagrank >= self.tagsRank['Icarus_Reynolds']): + if bc_base == self.bcbase['discover_ops']: + bcdir = bc_base+'/Icarus_Updated/'+bctag+'/' + else: + bcdir = bc_base+'/Icarus/'+bctag+'/' + if model == 'MOM6' or model == 'MOM5': + bcdir = bc_base+'/Icarus/'+model+'/' + elif(tagrank >= self.tagsRank["Ganymed-4_0_Reynolds"]): + bcdir = bc_base + '/Ganymed-4_0/'+bctag+'/' + if model == 'MOM6' or model == 'MOM5': + bcdir = bc_base+'/Ganymed/'+model+'/' + else: + bcdir = bc_base + '/' + bctag + '/' + if model == 'MOM6' or model == 'MOM5': + bcdir = bc_base+'/Ganymed/'+model+'/' + + if not os.path.exists(bcdir): + print( "Cannot find bc dir " + bcdir) + exit() + + gridStr = self.get_grid_subdir(bcdir,opt) + bcdir = bcdir + '/' + gridStr + + return bcdir + + def get_grid_subdir(self, bcdir, opt): + + def get_name_with_grid( grid, names): + if not grid : + return names + namex = [] + if (grid[0].upper() == 'C'): + n = int(grid[1:]) + s1 ='{n}x6C'.format(n=n) + j=n*6 + s2 =str(n) + s3 =str(j) + # first try + for name in names: + if (name.find(s1) != -1): + namex.append(name) + if len(namex) ==0: + for name in names: + if (name.find(s2) != -1 and name.find(s3) != -1): namex.append(name) + else: + xy = grid.upper().split('X') + s2 = xy[0] + s3 = xy[1] + for name in names: + if (name.find(s2) != -1 and name.find(s3) != -1): namex.append(name) + return namex + #v3.5 + #dirnames = [ f.name for f in os.scandir(bcdir) if f.is_dir()] + #v2.7 + dirnames = [f for f in os.listdir(bcdir) if os.path.isdir(os.path.join(bcdir,f))] + agrid_ = self.common_in['agrid'] + ogrid_ = self.common_in['ogrid'] + if opt.upper() == "OUT" : + agrid_ = self.common_out['agrid'] + ogrid_ = self.common_out['ogrid'] + + anames = get_name_with_grid(agrid_, dirnames) + gridID = get_name_with_grid(ogrid_, anames) + if len(gridID) == 0 : + print("cannot find the grid string: " + bcdir) + exit() + if len(gridID) >=2 : + print("find too may grid strings in " + bcdir) + print(" gridIDs found", gridID) + print(" pick the first one " + gridID[0]) + return gridID[0] + + def get_bcTag(self, tag, ogrid): + bctag = self.bcsTag[tag] + if ogrid[0].upper() == "C": + bctag=bctag.replace('_Reynolds','_Ostia') + else: + xy = ogrid.upper().split('X') + x = int(xy[0]) + if x == 1440: bctag=bctag.replace('_Reynolds','_MERRA-2') + if x == 2800: + bctag=bctag.replace('_Reynolds','_Ostia') + bctag=bctag.replace('_M','_D') + return bctag + + def params_for_air(self, config_tpl): + # verify agrid + agrid = config_tpl['input']['shared']['agrid'] + fvrst = os.path.dirname(os.path.realpath(__file__)) + '/fvrst.x -h ' + if not self.common_in.get('MERRA-2'): + fvcore = '' + for f in self.restarts_in: + if 'fvcore' in f: + fvcore = f + break + cmd = fvrst + fvcore + print(cmd +'\n') + p = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE) + (output, err) = p.communicate() + p_status = p.wait() + ss = output.decode().split() + if (agrid): + if agrid[0].upper() == "C": + n=int(agrid[1:]) + o=int(ss[0]) + assert n==o, "input agrid is not consistent with fvcore restart" + else: + config_tpl['input']['shared']['agrid'] = "C"+ss[0] + + ogrid = config_tpl['input']['shared']['ogrid'] + tagout = self.common_out['tag'] + bctag = self.get_bcTag(tagout, ogrid) + tagrank = self.tagsRank[bctag] + if ( not config_tpl['input']['air']['drymass']) : + config_tpl['input']['air']['drymass'] = 0 + if tagrank >=12 : + config_tpl['input']['air']['drymass'] = 1 + + config_tpl['output']['air']['nlevel'] = self.upper_out['nlevel'] + + return config_tpl + + def options_for_slurm(self, config_tpl): + config_tpl['slurm']['account'] = self.slurm_options['account'] + config_tpl['slurm']['debug'] = self.slurm_options['debug'] + config_tpl['slurm']['partition'] = self.slurm_options['partition'] + return config_tpl + + def params_for_surface(self, config_tpl): + config_tpl['output']['surface']['surflay'] = 20. + config_tpl['output']['surface']['rescale'] = False + tagout = self.common_out['tag'] + ogrid = self.common_out['ogrid'] + bctag = self.get_bcTag(tagout, ogrid) + tagrank = self.tagsRank[bctag] + if tagrank >=12 : + config_tpl['output']['surface']['surflay'] = 50. + if tagrank > self.tagsRank["Fortuna-2_0"]: + config_tpl['output']['surface']['rescale'] = True + if tagrank >= self.tagsRank["Icarus_Reynolds"]: + config_tpl['output']['surface']['split_saltwater'] = True + config_tpl['output']['surface']['zoom']= self.surf_in['zoom'] + config_tpl['output']['surface']['wemin']= self.surf_in['wemin'] + config_tpl['output']['surface']['wemout']= self.surf_out['wemout'] + 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') + + ogrid = self.common_out['ogrid'] + tagout = self.common_out['tag'] + bctag = self.get_bcTag(tagout, ogrid) + tagrank = self.tagsRank[bctag] + if tagrank >= self.tagsRank["Ganymed-4_0_Reynolds"] : + config_tpl['output']['analysis']['aqua'] = True + return config_tpl + diff --git a/GEOS_Util/post/regrid_params.tpl b/GEOS_Util/post/regrid_params.tpl new file mode 100644 index 00000000..94306efe --- /dev/null +++ b/GEOS_Util/post/regrid_params.tpl @@ -0,0 +1,55 @@ +input: + air: + drymass: 1 + hydrostatic: 0 + nlevel: + rst_dir: null + analysis: + rst_dir: null + shared: + agrid: + bcs_dir: + expid: + ogrid: + rst_dir: + yyyymmddhh: + surface: + wemin: + rst_dir: null + catchCNclm40: + regrid: false + rst_dir: null + catchCNclm45: + regrid: false + rst_dir: null + catchment: + regrid: false + rst_dir: null + lakelandice: + regrid: false + rst_dir: null + +output: + shared: + agrid: + bcs_dir: + expid: + ogrid: + out_dir: + air: + nlevel: + surface: + zoom: + split_saltwater: false + rescale: true + surflay: 20. + wemout: + analysis: + bkg: true + aqua: False + lcv: false + +slurm: + account: + debug: + partition: diff --git a/GEOS_Util/post/regrid_questions.py b/GEOS_Util/post/regrid_questions.py index b074816b..4dcd3ff4 100755 --- a/GEOS_Util/post/regrid_questions.py +++ b/GEOS_Util/post/regrid_questions.py @@ -344,7 +344,6 @@ def get_config_from_questionary(): parameters_in={} parameters_in['COMMON'] = common_in parameters_in['SURFACE'] = surface_in - parameters_in['ANALYSIS'] = analysis_in inputs['parameters'] = parameters_in config['input']= inputs @@ -353,26 +352,14 @@ def get_config_from_questionary(): parameters_out['COMMON'] = common_out parameters_out['UPPERAIR'] = upper_out parameters_out['SURFACE'] = surface_out + parameters_out['ANALYSIS'] = analysis_in outputs['parameters'] = parameters_out config['output']= outputs config['slurm_options'] = slurm - if os.path.exists('regrid.yaml') : - overwrite = questionary.confirm("Do you want to overwrite regrid.yaml file?", default=False).ask() - if not overwrite : - while True: - new_name = questionary.text("What's the backup name for existing regrid.yaml?", default='regrid.yaml.1').ask() - if os.path.exists(new_name): - print('\n'+ new_name + ' exists, please enter a new one. \n') - else: - shutil.move('regrid.yaml', new_name) - break - - f = open("regrid.yaml", "w") - yaml.dump(config, f, allow_unicode=True, default_flow_style=False) - f.close() + return config if __name__ == "__main__": - get_config_from_questionary() + config = get_config_from_questionary() diff --git a/GEOS_Util/post/regrid_upper.py b/GEOS_Util/post/regrid_upper.py new file mode 100755 index 00000000..736a4a1b --- /dev/null +++ b/GEOS_Util/post/regrid_upper.py @@ -0,0 +1,209 @@ +#!/usr/bin/env python3 +# +import os +import yaml +import subprocess +import shlex +import shutil +import glob + +class upperair(object): + def __init__(self, params_file): + stream = open(params_file, 'r') + self.config = yaml.full_load(stream) + stream.close() + + def regrid(self): + print( "\nRegridding upper air......\n") + config = self.config + bindir = os.getcwd() + in_bcsdir = config['input']['shared']['bcs_dir'] + out_bcsdir = config['output']['shared']['bcs_dir'] + out_dir = config['output']['shared']['out_dir'] + if not os.path.exists(out_dir) : os.makedirs(out_dir) + print( "cd " + out_dir) + os.chdir(out_dir) + + tmpdir = out_dir+'/upper_data/' + if os.path.exists(tmpdir) : subprocess.call(['rm', '-rf',tmpdir]) + print ("mkdir " + tmpdir) + os.makedirs(tmpdir) + + print( "cd " + tmpdir) + os.chdir(tmpdir) + print('\nUpper air restart files should end with "_rst" \n') + + rst_dir = config['input']['air']['rst_dir'] + if (not rst_dir): rst_dir = config['input']['shared']['rst_dir'] + restarts_in = glob.glob(rst_dir +'upperair/*') + yyyymmddhh_ = str(config['input']['shared']['yyyymmddhh']) + suffix = yyyymmddhh_[0:8]+'_'+yyyymmddhh_[8:10]+'z.nc4' + if (not restarts_in) : + expid = config['input']['shared']['expid'] + suffix = yyyymmddhh_[0:8]+'_'+yyyymmddhh_[8:10]+'z.bin' + # from merra-2 + restarts_in =[rst_dir + expid+'.fvcore_internal_rst.' + suffix, + rst_dir + expid+'.moist_internal_rst.' + suffix, + rst_dir + expid+'.agcm_import_rst.' + suffix, + rst_dir + expid+'.gocart_internal_rst.' + suffix, + rst_dir + expid+'.pchem_internal_rst.' + suffix ] + + for rst in restarts_in : + fs = os.path.basename(rst).split('.') + f = fs[0] + if (len(fs) >=2): f = fs[1] + f = f.replace('_rst','_restart_in') + cmd = '/bin/cp ' + rst + ' ' + f + print('\n'+cmd) + subprocess.call(shlex.split(cmd)) + + # link topo file + topoin = glob.glob(in_bcsdir+'/topo_DYN_ave*')[0] + cmd = '/bin/cp ' + topoin + ' .' + print('\n'+cmd) + subprocess.call(shlex.split(cmd)) + + topoout = glob.glob(out_bcsdir+'/topo_DYN_ave*')[0] + cmd = '/bin/cp ' + topoout + ' .' + print('\n'+cmd) + subprocess.call(shlex.split(cmd)) + fname = os.path.basename(topoout) + cmd = '/bin/ln -s ' + fname + ' topo_dynave.data' + print('\n'+cmd) + subprocess.call(shlex.split(cmd)) + + agrid = config['output']['shared']['agrid'] + if agrid[0].upper() == 'C': + imout = int(agrid[1:]) + else: + print("Only support cs grid so far") + exit() + + if (imout <=90): + NPE = 12; nwrit = 1 + elif (imout==180): + NPE = 24; nwrit = 1 + elif (imout<=500): + NPE = 96; nwrit = 1 + elif (imout==720): + NPE = 192; nwrit = 2 + elif (imout==1000): + NPE = 384; nwrit = 2 + elif (imout==1440): + NPE = 576; nwrit = 2 + elif (imout==2000): + NPE = 768; nwrit = 2 + elif (imout>=2880): + NPE = 5400; nwrit= 6 + + QOS = "#" + if NPE <= 532: QOS = "#SBATCH --qos=debug" + + regrid_template="""#!/bin/csh -xf +#!/bin/csh -xf +#SBATCH --account={account} +#SBATCH --time=1:00:00 +#SBATCH --ntasks={NPE} +#SBATCH --job-name=regrid_upper +#SBATCH --output={out_dir}/{out_log} +{QOS} + +unlimit + +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 +# HYDROSTATIC = 0 which means HYDROSTATIC = FALSE + +if ($?I_MPI_ROOT) then + # intel scaling suggestions + #-------------------------- + + setenv I_MPI_DAPL_UD on + + setenv DAPL_UCM_CQ_SIZE 4096 + setenv DAPL_UCM_QP_SIZE 4096 + + setenv I_MPI_DAPL_UD_SEND_BUFFER_NUM 4096 + setenv I_MPI_DAPL_UD_RECV_BUFFER_NUM 4096 + setenv I_MPI_DAPL_UD_ACK_SEND_POOL_SIZE 4096 + setenv I_MPI_DAPL_UD_ACK_RECV_POOL_SIZE 4096 + setenv I_MPI_DAPL_UD_RNDV_EP_NUM 2 + setenv I_MPI_DAPL_UD_REQ_EVD_SIZE 2000 + + setenv DAPL_UCM_REP_TIME 2000 + setenv DAPL_UCM_RTU_TIME 2000 + setenv DAPL_UCM_RETRY 7 + setenv DAPL_ACK_RETRY 7 + setenv DAPL_ACK_TIMER 20 + setenv DAPL_UCM_RETRY 10 + setenv DAPL_ACK_RETRY 10 + +else if ($?MVAPICH2) then + setenv MV2_ENABLE_AFFINITY 0 + +endif +set infiles = () +set outfils = () +foreach infile ( *_restart_in ) + if ( $infile == fvcore_internal_restart_in ) continue + if ( $infile == moist_internal_restart_in ) continue + + set infiles = ( $infiles $infile ) + set outfil = `echo $infile | sed "s/restart_in/rst_out/"` + set outfils = ($outfils $outfil) +end + +set interp_restartsX = {Bin}/interp_restarts.x +if ( $#infiles ) then + set ioflag = "-input_files $infiles -output_files $outfils" + set ftype = `file -b --mime-type fvcore_internal_restart_in` + if ($ftype =~ *stream*) then + set interp_restartsX = {Bin}/interp_restarts_bin.x + endif +else + set ioflag = "" +endif + +set drymassFLG = {drymassFLG} +if ($drymassFLG) then + set dmflag = "" +else + set dmflag = "-scalers F" +endif + +{Bin}/esma_mpirun -np {NPE} $interp_restartsX -im {imout} -lm {nlevel} \\ + -do_hydro {hydrostatic} $ioflag $dmflag -nwriter {nwrit} + +""" + account = config['slurm']['account'] + drymassFLG = config['input']['air']['drymass'] + hydrostatic = config['input']['air']['hydrostatic'] + nlevel = config['output']['air']['nlevel'] + + regrid_upper_script = regrid_template.format(Bin=bindir, account = account, \ + out_dir = out_dir, out_log = 'regrid_upper_log', drymassFLG = drymassFLG, \ + imout = imout, nwrit = nwrit, NPE = NPE, \ + QOS = QOS, nlevel = nlevel, hydrostatic = hydrostatic) + upper = open('regrider_upper.j','wt') + upper.write(regrid_upper_script) + upper.close() + print('sbatch -W regrider_upper.j\n') + subprocess.call(['sbatch', '-W', 'regrider_upper.j']) +# +# post process +# + + expid = config['output']['shared']['expid'] + if (expid) : + expid = expid + '.' + else: + expid = '' + suffix = '_rst.' + suffix + for out_rst in glob.glob("*_rst*"): + filename = expid + os.path.basename(out_rst).split('_rst')[0].split('.')[-1]+suffix + print('\n Move ' + out_rst + ' to ' + out_dir+"/"+filename) + shutil.move(out_rst, out_dir+"/"+filename) + os.chdir(bindir) From 2457cec15dcb8957b16152750f6c0f5ccea4f0ba Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Thu, 24 Mar 2022 09:29:14 -0400 Subject: [PATCH 18/70] add help message to regrid.py --- GEOS_Util/post/regrid.py | 51 ++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/GEOS_Util/post/regrid.py b/GEOS_Util/post/regrid.py index 59e81a72..ab65211e 100644 --- a/GEOS_Util/post/regrid.py +++ b/GEOS_Util/post/regrid.py @@ -7,10 +7,11 @@ import sys, getopt import yaml from regrid_questions import get_config_from_questionary -from regrider_base import * -from regrider_upper import * -from regrider_surf import * -from regrider_ana import * +from regrid_params import * +from regrid_upper import * +from regrid_lakelandice import * +from regrid_analysis import * +from regrid_catchment import * def main(argv): config_yaml = '' @@ -21,35 +22,39 @@ def main(argv): sys.exit(2) for opt, arg in opts: if opt == '-h': - print('\nUse a config file to regrid: \n' - './regrid.py -c my_config.yaml \n \n' - 'Use questionary to generate regrid.yaml and regrid \n' - './regrid.py \n' - '\nHelp message: \n' - '1) .... \n' - '2) .... ') + print('''\nThere are two ways to use this script to regrid restarts. \n + 1) Use a config file to regrid: \n + ./regrid.py -c my_config.yaml \n \n + 2) Use questionary to convert template regrid_params.tpl to \n + regrid_params.yaml and regrid. \n + ./regrid.py \n + \nHelp message: \n + 1) The rst_dir directory should have three sub-directories: \n + upperair, surface and analysis which contain restart files respectively. \n''') sys.exit() if opt in("-c", "--config_file"): config_yaml = arg if config_yaml == '': - get_config_from_questionary() - config_yaml = 'regrid.yaml' - - # load input yaml - stream = open(config_yaml, 'r') - config = yaml.full_load(stream) + config = get_config_from_questionary() + params = regrid_params(config) + params.convert_to_yaml() + config_yaml = 'regrid_params.yaml' # upper air - upper = upperair(config) + upper = upperair(config_yaml) upper.regrid() - - # surface - surf = surface(config) - surf.regrid() + + # land and water + land = lakelandice(config_yaml) + land.regrid() + + # catchment + catch = catchment(config_yaml) + catch.regrid() # analysis - ana = analysis(config) + ana = analysis(config_yaml) ana.regrid() if __name__ == '__main__' : From 6e2e3913bf6b1a9bc80119eac74a1fb0a90c1096 Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Thu, 24 Mar 2022 09:58:07 -0400 Subject: [PATCH 19/70] rm some misleading info --- GEOS_Util/post/regrid_catchment.py | 2 +- GEOS_Util/post/regrid_lakelandice.py | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/GEOS_Util/post/regrid_catchment.py b/GEOS_Util/post/regrid_catchment.py index da4aea15..dee16e49 100755 --- a/GEOS_Util/post/regrid_catchment.py +++ b/GEOS_Util/post/regrid_catchment.py @@ -14,7 +14,7 @@ def __init__(self, params_file): stream.close() def regrid(self): - print("\nRegridding land, landice, saltwater.....\n") + print("\nRegridding catchment.....\n") config = self.config bindir = os.getcwd() in_bcsdir = config['input']['shared']['bcs_dir'] diff --git a/GEOS_Util/post/regrid_lakelandice.py b/GEOS_Util/post/regrid_lakelandice.py index 792d57ae..b68ed0ed 100755 --- a/GEOS_Util/post/regrid_lakelandice.py +++ b/GEOS_Util/post/regrid_lakelandice.py @@ -43,8 +43,7 @@ def regrid(self): expid = config['input']['shared']['expid'] suffix = yyyymmddhh_[0:8]+'_'+yyyymmddhh_[8:10]+'z.bin' # from merra-2 - restarts_in = [rst_dir + expid + '.catch_internal_rst.' + suffix, - rst_dir + expid + '.lake_internal_rst.' + suffix, + restarts_in = [rst_dir + expid + '.lake_internal_rst.' + suffix, rst_dir + expid + '.landice_internal_rst.' + suffix, rst_dir + expid + '.saltwater_internal_rst.'+ suffix] From c780d70aa128213b039ee7e6f3e410765aa42cda Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Mon, 4 Apr 2022 10:26:04 -0400 Subject: [PATCH 20/70] rename lakelandice --- GEOS_Util/post/regrid.py | 8 ++++---- ...id_lakelandice.py => regrid_lake_landice_saltwater.py} | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) rename GEOS_Util/post/{regrid_lakelandice.py => regrid_lake_landice_saltwater.py} (97%) diff --git a/GEOS_Util/post/regrid.py b/GEOS_Util/post/regrid.py index ab65211e..e087598a 100644 --- a/GEOS_Util/post/regrid.py +++ b/GEOS_Util/post/regrid.py @@ -9,7 +9,7 @@ from regrid_questions import get_config_from_questionary from regrid_params import * from regrid_upper import * -from regrid_lakelandice import * +from regrid_lake_landice_saltwater import * from regrid_analysis import * from regrid_catchment import * @@ -45,9 +45,9 @@ def main(argv): upper = upperair(config_yaml) upper.regrid() - # land and water - land = lakelandice(config_yaml) - land.regrid() + # lake, landice and saltwater + lls = lake_landice_saltwater(config_yaml) + lls.regrid() # catchment catch = catchment(config_yaml) diff --git a/GEOS_Util/post/regrid_lakelandice.py b/GEOS_Util/post/regrid_lake_landice_saltwater.py similarity index 97% rename from GEOS_Util/post/regrid_lakelandice.py rename to GEOS_Util/post/regrid_lake_landice_saltwater.py index b68ed0ed..a6f909b0 100755 --- a/GEOS_Util/post/regrid_lakelandice.py +++ b/GEOS_Util/post/regrid_lake_landice_saltwater.py @@ -7,7 +7,7 @@ import yaml import shlex -class lakelandice(object): +class lake_landice_saltwater(object): def __init__(self, params_file): stream = open(params_file, 'r') self.config = yaml.full_load(stream) @@ -137,6 +137,6 @@ def find_rst(rsts,rst_name): os.chdir(bindir) if __name__ == '__main__' : - lli = lakelandice('regrid_params.yaml') - lli.regrid() + lls = lake_landice_saltwater('regrid_params.yaml') + lls.regrid() From f8b2bb945f8b8c425e3b800f67593ae71f2cdbc2 Mon Sep 17 00:00:00 2001 From: Matthew Thompson Date: Thu, 28 Apr 2022 09:34:01 -0400 Subject: [PATCH 21/70] Rename regrider to regridder --- GEOS_Util/post/regrid_upper.py | 6 +++--- GEOS_Util/post/{regrider_ana.py => regridder_ana.py} | 4 ++-- GEOS_Util/post/{regrider_base.py => regridder_base.py} | 2 +- GEOS_Util/post/{regrider_surf.py => regridder_surf.py} | 4 ++-- .../post/{regrider_upper.py => regridder_upper.py} | 10 +++++----- 5 files changed, 13 insertions(+), 13 deletions(-) rename GEOS_Util/post/{regrider_ana.py => regridder_ana.py} (99%) rename GEOS_Util/post/{regrider_base.py => regridder_base.py} (99%) rename GEOS_Util/post/{regrider_surf.py => regridder_surf.py} (99%) rename GEOS_Util/post/{regrider_upper.py => regridder_upper.py} (96%) diff --git a/GEOS_Util/post/regrid_upper.py b/GEOS_Util/post/regrid_upper.py index 736a4a1b..6d16e4c4 100755 --- a/GEOS_Util/post/regrid_upper.py +++ b/GEOS_Util/post/regrid_upper.py @@ -187,11 +187,11 @@ def regrid(self): out_dir = out_dir, out_log = 'regrid_upper_log', drymassFLG = drymassFLG, \ imout = imout, nwrit = nwrit, NPE = NPE, \ QOS = QOS, nlevel = nlevel, hydrostatic = hydrostatic) - upper = open('regrider_upper.j','wt') + upper = open('regridder_upper.j','wt') upper.write(regrid_upper_script) upper.close() - print('sbatch -W regrider_upper.j\n') - subprocess.call(['sbatch', '-W', 'regrider_upper.j']) + print('sbatch -W regridder_upper.j\n') + subprocess.call(['sbatch', '-W', 'regridder_upper.j']) # # post process # diff --git a/GEOS_Util/post/regrider_ana.py b/GEOS_Util/post/regridder_ana.py similarity index 99% rename from GEOS_Util/post/regrider_ana.py rename to GEOS_Util/post/regridder_ana.py index 855567df..831b1afc 100644 --- a/GEOS_Util/post/regrider_ana.py +++ b/GEOS_Util/post/regridder_ana.py @@ -6,9 +6,9 @@ import shutil import glob import fileinput -from regrider_base import * +from regridder_base import * -class analysis(regrider): +class analysis(regridder): def __init__(self, config): # v3.0 #super().__init__(config) diff --git a/GEOS_Util/post/regrider_base.py b/GEOS_Util/post/regridder_base.py similarity index 99% rename from GEOS_Util/post/regrider_base.py rename to GEOS_Util/post/regridder_base.py index 62e70aad..33542bcc 100644 --- a/GEOS_Util/post/regrider_base.py +++ b/GEOS_Util/post/regridder_base.py @@ -7,7 +7,7 @@ from datetime import datetime from datetime import timedelta -class regrider(object): +class regridder(object): def __init__(self, config): self.common_in = config['input']['parameters']['COMMON'] self.common_out = config['output']['parameters']['COMMON'] diff --git a/GEOS_Util/post/regrider_surf.py b/GEOS_Util/post/regridder_surf.py similarity index 99% rename from GEOS_Util/post/regrider_surf.py rename to GEOS_Util/post/regridder_surf.py index c143cf57..141e8d14 100644 --- a/GEOS_Util/post/regrider_surf.py +++ b/GEOS_Util/post/regridder_surf.py @@ -5,9 +5,9 @@ import shutil import shlex import glob -from regrider_base import * +from regridder_base import * -class surface(regrider): +class surface(regridder): def __init__(self, config): #v3.0 #super().__init__(config) diff --git a/GEOS_Util/post/regrider_upper.py b/GEOS_Util/post/regridder_upper.py similarity index 96% rename from GEOS_Util/post/regrider_upper.py rename to GEOS_Util/post/regridder_upper.py index e5715a14..fd524b9a 100644 --- a/GEOS_Util/post/regrider_upper.py +++ b/GEOS_Util/post/regridder_upper.py @@ -5,9 +5,9 @@ import shlex import shutil import glob -from regrider_base import * +from regridder_base import * -class upperair(regrider): +class upperair(regridder): def __init__(self, config): # v3.0 #super().__init__(config) @@ -194,11 +194,11 @@ def regrid(self): out_dir = out_dir, out_log = 'regrid_upper_log', drymassFLG = self.upper_out['drymassFLG'], \ imout = self.upper_out['imout'], nwrit = self.upper_out['nwrit'], NPE = self.upper_out['NPE'], \ QOS = self.upper_out['QOS'], nlevel = self.upper_out['nlevel']) - upper = open('regrider_upper.j','wt') + upper = open('regridder_upper.j','wt') upper.write(regrid_upper_script) upper.close() - print('sbatch -W regrider_upper.j\n') - subprocess.call(['sbatch', '-W', 'regrider_upper.j']) + print('sbatch -W regridder_upper.j\n') + subprocess.call(['sbatch', '-W', 'regridder_upper.j']) for out_rst in glob.glob("*_rst*"): filename = os.path.basename(out_rst) print('\n Move ' + out_rst + ' to ' + out_dir+"/"+filename) From ca7b763947ee8f15447cbfe76512a83bf3f4d2ae Mon Sep 17 00:00:00 2001 From: Matthew Thompson Date: Thu, 28 Apr 2022 10:15:17 -0400 Subject: [PATCH 22/70] Add gitol, gitnl, 525 --- GEOS_Util/post/regrid_params.py | 32 +++++++++++------ GEOS_Util/post/regrid_questions.py | 56 +++++++++++++++++------------- GEOS_Util/post/regridder_base.py | 37 +++++++++++++------- 3 files changed, 79 insertions(+), 46 deletions(-) diff --git a/GEOS_Util/post/regrid_params.py b/GEOS_Util/post/regrid_params.py index edcac6a5..0e5fc449 100755 --- a/GEOS_Util/post/regrid_params.py +++ b/GEOS_Util/post/regrid_params.py @@ -167,22 +167,33 @@ def init_tags(self): 'GEOSadas-5_21_2', 'GEOSadas-5_21_3_p1', 'GEOSadas-5_22_0', 'GEOSadas-5_22_0_p1', 'GEOSadas-5_22_0_p2', 'GEOSadas-5_23_0', 'GEOSadas-5_23_0_p1', 'GEOSadas-5_24_0', 'GEOSadas-5_24_0_p1' ) + GITOL = ( 'GITOL', '10.3', '10.4', '10.5', + '10.6', '10.7', '10.8', + '10.9', '10.10', '10.11', + '10.12', '10.13', '10.14', + '10.15', '10.16', '10.17', + '10.18' ) # BCS Tags: Icarus-NLv3 (New Land Parameters) #--------------------------------------------------------------------------- INL = ( 'INL', 'Icarus-NL', 'Icarus-NLv3', 'Jason-NL' ) + GITNL = ( 'GITNL', '10.19', '10.20', '10.21', '10.22', '10.23' ) + D525 = ( '525', 'GEOSadas-5_25_1', 'GEOSadas-5_25_1_p5', 'GEOSadas-5_25_p7', + 'GEOSadas-5_27_1', 'GEOSadas-5_29_3', 'GEOSadas-5_29_4' ) self.bcsTag={} - for tag in F14: self.bcsTag[tag]= "Fortuna-1_4" - for tag in F20: self.bcsTag[tag]= "Fortuna-2_0" - for tag in F21: self.bcsTag[tag]= "Fortuna-2_1" - for tag in G10: self.bcsTag[tag]= "Ganymed-1_0" - for tag in G10p: self.bcsTag[tag]= "Ganymed-1_0_M" - for tag in G20: self.bcsTag[tag]= "Ganymed-1_0_M" - for tag in G30: self.bcsTag[tag]= "Ganymed-1_0_Reynolds" - for tag in G40: self.bcsTag[tag]= "Ganymed-4_0_Reynolds" - for tag in ICA: self.bcsTag[tag]= "Icarus_Reynolds" - for tag in INL: self.bcsTag[tag]= "Icarus-NLv3_Reynolds" + for tag in F14: self.bcsTag[tag]= "Fortuna-1_4" + for tag in F20: self.bcsTag[tag]= "Fortuna-2_0" + for tag in F21: self.bcsTag[tag]= "Fortuna-2_1" + for tag in G10: self.bcsTag[tag]= "Ganymed-1_0" + for tag in G10p: self.bcsTag[tag]= "Ganymed-1_0_M" + for tag in G20: self.bcsTag[tag]= "Ganymed-1_0_M" + for tag in G30: self.bcsTag[tag]= "Ganymed-1_0_Reynolds" + for tag in G40: self.bcsTag[tag]= "Ganymed-4_0_Reynolds" + for tag in ICA: self.bcsTag[tag]= "Icarus_Reynolds" + for tag in GITOL: self.bcsTag[tag]= "Icarus_Reynolds" + for tag in INL: self.bcsTag[tag]= "Icarus-NLv3_Reynolds" + for tag in GITNL: self.bcsTag[tag]= "Icarus-NLv3_Reynolds" for tag in D214: self.bcsTag[tag]= "Fortuna-1_4" @@ -194,6 +205,7 @@ def init_tags(self): for tag in D5B0: self.bcsTag[tag]= "Ganymed-1_0_Reynolds" for tag in D512: self.bcsTag[tag]= "Ganymed-4_0_Reynolds" for tag in D517: self.bcsTag[tag]= "Icarus_Reynolds" + for tag in D525: self.bcsTag[tag]= "Icarus-NLv3_Reynolds" self.tagsRank ={} self.tagsRank['Fortuna-1_4'] = 1 diff --git a/GEOS_Util/post/regrid_questions.py b/GEOS_Util/post/regrid_questions.py index 4dcd3ff4..bba1bef9 100755 --- a/GEOS_Util/post/regrid_questions.py +++ b/GEOS_Util/post/regrid_questions.py @@ -85,16 +85,18 @@ def ask_common_in(): "message": "Enter GCM or DAS tag for input: \n \ Sample GCM tags \n \ --------------- \n \ -F14 : Fortuna-1_4 ......... Fortuna-1_4_p1 \n \ -F20 : Fortuna-2_0 ......... Fortuna-2_0 \n \ -F21 : Fortuna-2_1 ......... Fortuna-2_5_pp2 \n \ -G10 : Ganymed-1_0 ......... Ganymed-1_0_BETA4 \n \ -G10p : Ganymed-1_0_p1 ...... Ganymed-1_0_p6 \n \ -G20 : Ganymed-2_0 ......... Ganymed-2_1_p6 \n \ -G30 : Ganymed-3_0 ......... Ganymed-3_0_p1 \n \ -G40 : Ganymed-4_0 ......... Heracles-5_4_p3 \n \ -INL : Icarus-NL ........... Jason-NL \n \ -ICA : Icarus .............. Jason \n \ +F14 : Fortuna-1_4 ......... Fortuna-1_4_p1 \n \ +F20 : Fortuna-2_0 ......... Fortuna-2_0 \n \ +F21 : Fortuna-2_1 ......... Fortuna-2_5_pp2 \n \ +G10 : Ganymed-1_0 ......... Ganymed-1_0_BETA4 \n \ +G10p : Ganymed-1_0_p1 ...... Ganymed-1_0_p6 \n \ +G20 : Ganymed-2_0 ......... Ganymed-2_1_p6 \n \ +G30 : Ganymed-3_0 ......... Ganymed-3_0_p1 \n \ +G40 : Ganymed-4_0 ......... Heracles-5_4_p3 \n \ +ICA : Icarus .............. Jason \n \ +GITOL : 10.3 ................ 10.18 \n \ +INL : Icarus-NL ........... Jason-NL \n \ +GITNL : 10.19 ............... 10.23 \n \ \n \ Sample DAS tags \n \ --------------- \n \ @@ -105,8 +107,10 @@ def ask_common_in(): 591p : GEOSadas-5_9_1_p1 ... GEOSadas-5_9_1_p9 \n \ 5A0 : GEOSadas-5_10_0 ..... GEOSadas-5_10_0_p1 \n \ 5B0 : GEOSadas-5_10_0_p2 .. GEOSadas-5_11_0 \n \ -512 : GEOSadas-5_12_2 ..... GEOSadas-5_16_5\n", - "default": "ICA", +512 : GEOSadas-5_12_2 ..... GEOSadas-5_16_5\n \ +517 : GEOSadas-5_17_0 ..... GEOSadas-5_24_0_p1\n \ +525 : GEOSadas-5_25_1 ..... GEOSadas-5_29_4\n", + "default": "INL", "when": lambda x: not x["MERRA-2"], }, { @@ -156,16 +160,18 @@ def ask_common_out(): "message": "Enter GCM or DAS tag for new restarts: \n \ Sample GCM tags \n \ --------------- \n \ -F14 : Fortuna-1_4 ......... Fortuna-1_4_p1 \n \ -F20 : Fortuna-2_0 ......... Fortuna-2_0 \n \ -F21 : Fortuna-2_1 ......... Fortuna-2_5_pp2 \n \ -G10 : Ganymed-1_0 ......... Ganymed-1_0_BETA4 \n \ -G10p : Ganymed-1_0_p1 ...... Ganymed-1_0_p6 \n \ -G20 : Ganymed-2_0 ......... Ganymed-2_1_p6 \n \ -G30 : Ganymed-3_0 ......... Ganymed-3_0_p1 \n \ -G40 : Ganymed-4_0 ......... Heracles-5_4_p3 \n \ -ICA : Icarus .............. Jason \n \ -INL : Icarus-NL ........... Jason-NL \n \ +F14 : Fortuna-1_4 ......... Fortuna-1_4_p1 \n \ +F20 : Fortuna-2_0 ......... Fortuna-2_0 \n \ +F21 : Fortuna-2_1 ......... Fortuna-2_5_pp2 \n \ +G10 : Ganymed-1_0 ......... Ganymed-1_0_BETA4 \n \ +G10p : Ganymed-1_0_p1 ...... Ganymed-1_0_p6 \n \ +G20 : Ganymed-2_0 ......... Ganymed-2_1_p6 \n \ +G30 : Ganymed-3_0 ......... Ganymed-3_0_p1 \n \ +G40 : Ganymed-4_0 ......... Heracles-5_4_p3 \n \ +ICA : Icarus .............. Jason \n \ +GITOL : 10.3 ................ 10.18 \n \ +INL : Icarus-NL ........... Jason-NL \n \ +GITNL : 10.19 ............... 10.23 \n \ \n \ Sample DAS tags \n \ --------------- \n \ @@ -176,8 +182,10 @@ def ask_common_out(): 591p : GEOSadas-5_9_1_p1 ... GEOSadas-5_9_1_p9 \n \ 5A0 : GEOSadas-5_10_0 ..... GEOSadas-5_10_0_p1 \n \ 5B0 : GEOSadas-5_10_0_p2 .. GEOSadas-5_11_0 \n \ -512 : GEOSadas-5_12_2 ..... GEOSadas-5_16_5\n", - "default": "ICA", +512 : GEOSadas-5_12_2 ..... GEOSadas-5_16_5\n \ +517 : GEOSadas-5_17_0 ..... GEOSadas-5_24_0_p1\n \ +525 : GEOSadas-5_25_1 ..... GEOSadas-5_29_4\n", + "default": "INL", }, { "type": "select", diff --git a/GEOS_Util/post/regridder_base.py b/GEOS_Util/post/regridder_base.py index 33542bcc..744da047 100644 --- a/GEOS_Util/post/regridder_base.py +++ b/GEOS_Util/post/regridder_base.py @@ -113,29 +113,41 @@ def init_tags(self): # BCS Tags: Icarus (New Land Parameters, New Topography) #--------------------------------------------------------------------------- ICA = ( 'ICA', 'Icarus', 'Jason' ) - D517 = ( 'D517', 'GEOSadas-5_17_0', 'GEOSadas-5_17_1', 'GEOSadas-5_18_0', + D517 = ( 'D517', + 'GEOSadas-5_17_0', 'GEOSadas-5_17_1', 'GEOSadas-5_18_0', 'GEOSadas-5_18_1', 'GEOSadas-5_18_2', 'GEOSadas-5_18_3', 'GEOSadas-5_18_3_p1', 'GEOSadas-5_19_0', 'GEOSadas-5_20_0', 'GEOSadas-5_20_0_p1', 'GEOSadas-5_20_0_p2', 'GEOSadas-5_21_0', 'GEOSadas-5_21_2', 'GEOSadas-5_21_3_p1', 'GEOSadas-5_22_0', 'GEOSadas-5_22_0_p1', 'GEOSadas-5_22_0_p2', 'GEOSadas-5_23_0', 'GEOSadas-5_23_0_p1', 'GEOSadas-5_24_0', 'GEOSadas-5_24_0_p1' ) + GITOL = ( 'GITOL', '10.3', '10.4', '10.5', + '10.6', '10.7', '10.8', + '10.9', '10.10', '10.11', + '10.12', '10.13', '10.14', + '10.15', '10.16', '10.17', + '10.18' ) # BCS Tags: Icarus-NLv3 (New Land Parameters) #--------------------------------------------------------------------------- - INL = ( 'INL', 'Icarus-NL', 'Icarus-NLv3', 'Jason-NL' ) + INL = ( 'INL', 'Icarus-NL', 'Icarus-NLv3', 'Jason-NL' ) + GITNL = ( 'GITNL', '10.19', '10.20', '10.21', '10.22', '10.23' ) + D525 = ( '525', 'GEOSadas-5_25_1', 'GEOSadas-5_25_1_p5', 'GEOSadas-5_25_p7', + 'GEOSadas-5_27_1', 'GEOSadas-5_29_3', 'GEOSadas-5_29_4' ) self.bcsTag={} - for tag in F14: self.bcsTag[tag]= "Fortuna-1_4" - for tag in F20: self.bcsTag[tag]= "Fortuna-2_0" - for tag in F21: self.bcsTag[tag]= "Fortuna-2_1" - for tag in G10: self.bcsTag[tag]= "Ganymed-1_0" - for tag in G10p: self.bcsTag[tag]= "Ganymed-1_0_M" - for tag in G20: self.bcsTag[tag]= "Ganymed-1_0_M" - for tag in G30: self.bcsTag[tag]= "Ganymed-1_0_Reynolds" - for tag in G40: self.bcsTag[tag]= "Ganymed-4_0_Reynolds" - for tag in ICA: self.bcsTag[tag]= "Icarus_Reynolds" - for tag in INL: self.bcsTag[tag]= "Icarus-NLv3_Reynolds" + for tag in F14: self.bcsTag[tag]= "Fortuna-1_4" + for tag in F20: self.bcsTag[tag]= "Fortuna-2_0" + for tag in F21: self.bcsTag[tag]= "Fortuna-2_1" + for tag in G10: self.bcsTag[tag]= "Ganymed-1_0" + for tag in G10p: self.bcsTag[tag]= "Ganymed-1_0_M" + for tag in G20: self.bcsTag[tag]= "Ganymed-1_0_M" + for tag in G30: self.bcsTag[tag]= "Ganymed-1_0_Reynolds" + for tag in G40: self.bcsTag[tag]= "Ganymed-4_0_Reynolds" + for tag in ICA: self.bcsTag[tag]= "Icarus_Reynolds" + for tag in GITOL: self.bcsTag[tag]= "Icarus_Reynolds" + for tag in INL: self.bcsTag[tag]= "Icarus-NLv3_Reynolds" + for tag in GITNL: self.bcsTag[tag]= "Icarus-NLv3_Reynolds" for tag in D214: self.bcsTag[tag]= "Fortuna-1_4" @@ -147,6 +159,7 @@ def init_tags(self): for tag in D5B0: self.bcsTag[tag]= "Ganymed-1_0_Reynolds" for tag in D512: self.bcsTag[tag]= "Ganymed-4_0_Reynolds" for tag in D517: self.bcsTag[tag]= "Icarus_Reynolds" + for tag in D525: self.bcsTag[tag]= "Icarus-NLv3_Reynolds" self.tagsRank ={} self.tagsRank['Fortuna-1_4'] = 1 From 5eda2eaa796199a1dae2bc4fa11fcfa246163585 Mon Sep 17 00:00:00 2001 From: Matthew Thompson Date: Thu, 28 Apr 2022 10:19:09 -0400 Subject: [PATCH 23/70] Remove old regridder_ files. --- GEOS_Util/post/regridder_ana.py | 173 -------------- GEOS_Util/post/regridder_base.py | 377 ------------------------------ GEOS_Util/post/regridder_surf.py | 338 --------------------------- GEOS_Util/post/regridder_upper.py | 206 ---------------- 4 files changed, 1094 deletions(-) delete mode 100644 GEOS_Util/post/regridder_ana.py delete mode 100644 GEOS_Util/post/regridder_base.py delete mode 100644 GEOS_Util/post/regridder_surf.py delete mode 100644 GEOS_Util/post/regridder_upper.py diff --git a/GEOS_Util/post/regridder_ana.py b/GEOS_Util/post/regridder_ana.py deleted file mode 100644 index 831b1afc..00000000 --- a/GEOS_Util/post/regridder_ana.py +++ /dev/null @@ -1,173 +0,0 @@ -#!/usr/bin/env python3 -# -import os -import subprocess -import shlex -import shutil -import glob -import fileinput -from regridder_base import * - -class analysis(regridder): - def __init__(self, config): - # v3.0 - #super().__init__(config) - # v2.7 - super(analysis, self).__init__(config) - self.ana_in = config['input']['parameters']['ANALYSIS'] - self.bkg = self.ana_in.get('bkg') - if not self.bkg: - return - #ana bkg_eta grid mapping from input atmosphere grid - self.hgrd = {} - self.hgrd['C12'] = 'a' - self.hgrd['C24'] = 'a' - self.hgrd['C48'] = 'b' - self.hgrd['C90'] = 'c' - self.hgrd['C180'] = 'd' - self.hgrd['C360'] = 'd' - self.hgrd['C500'] = 'd' - self.hgrd['C720'] = 'e' - self.hgrd['C1000'] = 'e' - self.hgrd['C1440'] = 'e' - self.hgrd['C2000'] = 'e' - self.hgrd['C2880'] = 'e' - self.hgrd['C5760'] = 'e' - - rst_time = datetime(year=int(self.yyyy), month=int(self.mm), day=int(self.dd), hour = int(self.hh)) - rst_dir_orig = self.common_in['rst_dir'] - expid = self.common_in['expid'] - anafiles = self.restarts_in['ANALYSIS'] - if len(anafiles) == 0 and self.common_in.get('MERRA-2'): - self.anafiles=[] - for h in [3,4,5,6,7,8,9]: - delt = timedelta(hours = h-3) - new_time = rst_time + delt - yyyy = "Y"+str(new_time.year) - mm = 'M%02d'%new_time.month - ymd = '%04d%02d%02d'%(new_time.year,new_time.month, new_time.day) - hh = '%02d'%h - newhh= '%02d'%new_time.hour - rst_dir = rst_dir_orig.replace('Y'+self.yyyy,yyyy).replace('M'+self.mm,mm) - # bkg files - for ftype in ['sfc', 'eta']: - fname = expid+'.bkg'+hh+'_'+ftype+'_rst.'+ymd+'_'+newhh+'z.nc4' - f = rst_dir+'/'+fname - if(os.path.isfile(f)): - self.anafiles.append(f) - else: - print('Warning: Cannot find '+f) - - # cbkg file - fname = expid + '.cbkg' + hh + '_eta_rst.' + ymd + '_' + newhh + 'z.nc4' - f = rst_dir+'/'+fname - if(os.path.isfile(f)): - self.anafiles.append(f) - else: - print('Warning: Cannot find '+f) - # gaas_bkg_sfc files - if (h==6 or h==9): - fname = expid+'.gaas_bkg_sfc_rst.'+ymd+'_'+newhh+'z.nc4' - f = rst_dir+'/'+fname - if (os.path.isfile(f)): - self.anafiles.append(f) - else: - print('Warning: Cannot find '+f) - # satbang and satbias - ymd = '%04d%02d%02d'%(rst_time.year,rst_time.month, rst_time.day) - hr ='%02d'%rst_time.hour - for ftype in ["ana_satbang_rst", "ana_satbias_rst", "ana_satbiaspc_rst"]: - fname = expid+'.'+ftype+'.'+ymd+'_'+hr+'z.txt' - f = rst_dir_orig+'/'+fname - if(os.path.isfile(f)): - self.anafiles.append(f) - else: - print('Warning: Cannot find '+f) - - # trak.GDA.rst file - delt = timedelta(hours = 3) - new_time = rst_time - delt - yyyy = "Y"+str(new_time.year) - mm = 'M%02d'%new_time.month - ymdh = '%04d%02d%02d%02d'%(new_time.year, new_time.month, new_time.day, new_time.hour) - rst_dir = rst_dir_orig.replace('Y'+self.yyyy,yyyy).replace('M'+self.mm,mm) - fname = expid+'.trak.GDA.rst.'+ymdh+'z.txt' - f = rst_dir+'/'+fname - if (os.path.isfile(f)): self.anafiles.append(f) - else: - self.anafiles = anafiles - - agrid_in = self.common_in['agrid'] - agrid_out = self.common_out['agrid'] - - self.ana_regrid = True - if (self.hgrd[agrid_in] == self.hgrd[agrid_out]): - self.ana_regrid = False - - def regrid(self): - if not self.bkg: - return - expid_in = self.common_in.get('expid')+'.' - expid_out = self.common_out.get('expid') - if not expid_out: - expid = '' - else: - expid_out = expid_out+'.' - bindir = os.getcwd() - out_dir = self.common_out.get('out_dir') - - if not os.path.exists(out_dir) : os.makedirs(out_dir) - print( "cd " + self.common_out['out_dir']) - os.chdir(self.common_out['out_dir']) - tmp_dir = out_dir+'/ana_data/' - if os.path.exists(tmp_dir) : subprocess.call(['rm', '-rf', tmp_dir]) - print ("mkdir " + tmp_dir) - os.makedirs(tmp_dir) - print( "cd " + tmp_dir) - os.chdir(tmp_dir) - - ogrid = self.common_out['ogrid'] - tagout = self.common_out['tag'] - bctag = self.get_bcTag(tagout, ogrid) - tagrank = self.tagsRank[bctag] - local_fs=[] - for f in self.anafiles: - fname = os.path.basename(f) - out_name = fname.replace(expid_in, expid_out) - f_tmp = tmp_dir+'/'+out_name - local_fs.append(f_tmp) - shutil.copy(f,f_tmp) - if (out_name.find('satbias') != -1): - if (tagrank >= self.tagsRank["Ganymed-4_0_Reynolds"]): - f_orig = f_tmp+'.orig' - shutil.move(f_tmp, f_orig) - f_ = open(f_tmp, 'w') - for line in fileinput.input(f_orig): - f_.write(line.replace('airs281SUBSET_aqua', 'airs281_aqua ')) - f_.close() - - if self.ana_regrid: - agrid_out = self.common_out['agrid'] - nlevel = self.upper_out['nlevel'] - flags = "-g5 -res " + self.hgrd[agrid_out] + " -nlevs " + str(nlevel) - bkg_files = glob.glob(tmp_dir+'/*.bkg??_eta_rst*') - for f in bkg_files: - f_orig = f + ".orig" - shutil.move(f,f_orig) - cmd = bindir + '/dyn2dyn.x ' + flags + ' -o ' + f + ' ' + f_orig - print(cmd) - subprocess.call(shlex.split(cmd)) - for f in local_fs: - fname = os.path.basename(f) - shutil.move(f, out_dir+'/'+fname) - # write lcv - lcv = self.ana_in.get('lcv') - if lcv : - ymd = self.ymd - hh = self.hh - hms = hh+'0000' - rstlcvOut = out_dir+'/'+expid_out+'rst.lcv.'+ymd+'_'+hh+'z.bin' - cmd = bindir+'/mkdrstdate.x ' + ymd + ' ' + hms +' ' + rstlcvOut - print(cmd) - subprocess.call(shlex.split(cmd)) - os.chdir(bindir) diff --git a/GEOS_Util/post/regridder_base.py b/GEOS_Util/post/regridder_base.py deleted file mode 100644 index 744da047..00000000 --- a/GEOS_Util/post/regridder_base.py +++ /dev/null @@ -1,377 +0,0 @@ -#!/usr/bin/env python3 -# -import os -import shutil -import glob -import time -from datetime import datetime -from datetime import timedelta - -class regridder(object): - def __init__(self, config): - self.common_in = config['input']['parameters']['COMMON'] - self.common_out = config['output']['parameters']['COMMON'] - self.upper_out = config['output']['parameters']['UPPERAIR'] - self.slurm_options = config['slurm_options'] - - self.init_time() - self.init_tags() - self.init_merra2() - self.init_restarts_in() - - # get bc directory and tile file - self.in_bcsdir = self.get_bcdir("IN") - self.in_til = glob.glob(self.in_bcsdir+ '/*-Pfafstetter.til')[0] - print("input tile file: " + self.in_til) - self.out_bcsdir = self.get_bcdir("OUT") - self.out_til = glob.glob(self.out_bcsdir+ '/*-Pfafstetter.til')[0] - print("output tile file: " + self.out_til) - - - def init_tags(self): - # copy and paste from regrid.pl - # minor change. Add "D" to the number for each group - # BCS Tag: Fortuna-1_4 - F14 = ( 'F14', 'Fortuna-1_4', 'Fortuna-1_4_p1' ) - D214 = ( 'D214', 'GEOSdas-2_1_4', 'GEOSdas-2_1_4-m1', - 'GEOSdas-2_1_4-m2', 'GEOSdas-2_1_4-m3', 'GEOSdas-2_1_4-m4' ) - D540 = ( 'D540', 'GEOSadas-5_4_0', 'GEOSadas-5_4_0_p1', - 'GEOSadas-5_4_0_p2', 'GEOSadas-5_4_0_p3', 'GEOSadas-5_4_0_p4', - 'GEOSadas-5_4_1', 'GEOSadas-5_4_1_p1', 'GEOSadas-5_4_2', - 'GEOSadas-5_4_3', 'GEOSadas-5_4_4', 'GEOSadas-5_5_0', - 'GEOSadas-5_5_1', 'GEOSadas-5_5_2', 'GEOSadas-5_5_3' ) - - # BCS Tag: Fortuna-2_0 - #--------------------- - F20 = ( 'F20', 'Fortuna-2_0') - - # BCS Tag: Fortuna-2_1 - #--------------------- - F21 = ( 'F21', 'Fortuna-2_1', 'Fortuna-2_1_p1', - 'Fortuna-2_1_p2', 'Fortuna-2_1_p3', 'Fortuna-2_2', - 'Fortuna-2_2_p1', 'Fortuna-2_2_p2', 'Fortuna-2_3', - 'Fortuna-2_3_p1', 'Fortuna-2_4', 'Fortuna-2_4_p1', - 'Fortuna-2_4_p2', 'Fortuna-2_5', 'Fortuna-2_5_BETA0', - 'Fortuna-2_5_p1', 'Fortuna-2_5_p2', 'Fortuna-2_5_p3', - 'Fortuna-2_5_p4', 'Fortuna-2_5_p5', 'Fortuna-2_5_p6', - 'Fortuna-2_5_pp2' ) - D561 = ( 'D561', 'GEOSadas-5_6_1', 'GEOSadas-5_6_1_p1', - 'GEOSadas-5_6_1_p2', 'GEOSadas-5_6_1_p3', 'GEOSadas-5_6_1_p4', - 'GEOSadas-5_6_2', 'GEOSadas-5_6_2_p1', 'GEOSadas-5_6_2_p2', - 'GEOSadas-5_6_2_p3', 'GEOSadas-5_6_2_p4', 'GEOSadas-5_6_2_p5', - 'GEOSadas-5_6_2_p6', 'GEOSadas-5_7_1', 'GEOSadas-5_7_1_p1', - 'GEOSadas-5_7_1_p2', 'GEOSadas-5_7_2', 'GEOSadas-5_7_2_p1', - 'GEOSadas-5_7_2_p2', 'GEOSadas-5_7_2_p2_m1','GEOSadas-5_7_2_p3', - 'GEOSadas-5_7_2_p3_m1', 'GEOSadas-5_7_2_p3_m2','GEOSadas-5_7_2_p4', - 'GEOSadas-5_7_2_p5', 'GEOSadas-5_7_2_p5_m1','GEOSadas-5_7_3', - 'GEOSadas-5_7_3_p1', 'GEOSadas-5_7_3_p2', 'GEOSadas-5_7_3_p2' ) - - # BCS Tag: Ganymed-1_0 - #--------------------- - G10 = ( 'G10', 'Ganymed-1_0', 'Ganymed-1_0_BETA', - 'Ganymed-1_0_BETA1', 'Ganymed-1_0_BETA2', 'Ganymed-1_0_BETA3', - 'Ganymed-1_0_BETA4' ) - - D580 = ( 'D580', 'GEOSadas-5_8_0', 'GEOSadas-5_9_0', - 'GEOSadas-5_9_1' ) - - # BCS Tags: Ganymed-1_0_M and Ganymed-1_0_D - #------------------------------------------ - G10p = ( 'G10p', 'Ganymed-1_0_p1', 'Ganymed-1_0_p2', - 'Ganymed-1_0_p3', 'Ganymed-1_0_p4', 'Ganymed-1_0_p5', - 'Ganymed-1_0_p6' ) - - D591p= ( 'D591p', 'GEOSadas-5_9_1_p1', 'GEOSadas-5_9_1_p2', - 'GEOSadas-5_9_1_p3', 'GEOSadas-5_9_1_p4', 'GEOSadas-5_9_1_p5', - 'GEOSadas-5_9_1_p6', 'GEOSadas-5_9_1_p7', 'GEOSadas-5_9_1_p8', - 'GEOSadas-5_9_1_p9' ) - - # BCS Tags: Ganymed-1_0_M and Ganymed-1_0_D w/ new landice rst - #------------------------------------------------------------------------ - G20 = ( 'G20', 'Ganymed-2_0', 'Ganymed-2_1', - 'Ganymed-2_1_p1', 'Ganymed-2_1_p2', 'Ganymed-2_1_p3', - 'Ganymed-2_1_p4', 'Ganymed-2_1_p5', 'Ganymed-2_1_p6' ) - D5A0 = ( 'D5A0', 'GEOSadas-5_10_0', 'GEOSadas-5_10_0_p1' ) - - - # BCS Tags: Ganymed-1_0_Reynolds and Ganymed-1_0_Ostia - #----------------------------------------------------- - G30 = ( 'G30', 'Ganymed-3_0', 'Ganymed-3_0_p1' ) - D5B0 = ( 'D5B0', 'GEOSadas-5_10_0_p2', 'GEOSadas-5_11_0' ) - - # BCS Tags: Ganymed-4_0_Reynolds, Ganymed-4_0_MERRA-2, and Ganymed-4_0_Ostia - #--------------------------------------------------------------------------- - G40 = ( 'G40', 'Ganymed-4_0', 'Ganymed-4_0_p1', - 'Ganymed-4_1', 'Heracles-1_0', 'Heracles-1_1', - 'Heracles-2_0', 'Heracles-2_1', 'Heracles-3_0', - 'Heracles-4_0', 'Heracles-5_4_p3' ) - D512 = ( 'D512', 'GEOSadas-5_12_2', 'GEOSadas-5_12_4', - 'GEOSadas-5_12_4_p1', 'GEOSadas-5_12_4_p2', 'GEOSadas-5_12_4_p3', - 'GEOSadas-5_12_5', 'GEOSadas-5_13_0_p1', 'GEOSadas-5_13_0_p2', - 'GEOSadas-5_13_1', 'GEOSadas-5_16_5' ) - - # BCS Tags: Icarus (New Land Parameters, New Topography) - #--------------------------------------------------------------------------- - ICA = ( 'ICA', 'Icarus', 'Jason' ) - D517 = ( 'D517', - 'GEOSadas-5_17_0', 'GEOSadas-5_17_1', 'GEOSadas-5_18_0', - 'GEOSadas-5_18_1', 'GEOSadas-5_18_2', 'GEOSadas-5_18_3', - 'GEOSadas-5_18_3_p1', 'GEOSadas-5_19_0', 'GEOSadas-5_20_0', - 'GEOSadas-5_20_0_p1', 'GEOSadas-5_20_0_p2', 'GEOSadas-5_21_0', - 'GEOSadas-5_21_2', 'GEOSadas-5_21_3_p1', 'GEOSadas-5_22_0', - 'GEOSadas-5_22_0_p1', 'GEOSadas-5_22_0_p2', 'GEOSadas-5_23_0', - 'GEOSadas-5_23_0_p1', 'GEOSadas-5_24_0', 'GEOSadas-5_24_0_p1' ) - GITOL = ( 'GITOL', '10.3', '10.4', '10.5', - '10.6', '10.7', '10.8', - '10.9', '10.10', '10.11', - '10.12', '10.13', '10.14', - '10.15', '10.16', '10.17', - '10.18' ) - - # BCS Tags: Icarus-NLv3 (New Land Parameters) - #--------------------------------------------------------------------------- - INL = ( 'INL', 'Icarus-NL', 'Icarus-NLv3', 'Jason-NL' ) - GITNL = ( 'GITNL', '10.19', '10.20', '10.21', '10.22', '10.23' ) - D525 = ( '525', 'GEOSadas-5_25_1', 'GEOSadas-5_25_1_p5', 'GEOSadas-5_25_p7', - 'GEOSadas-5_27_1', 'GEOSadas-5_29_3', 'GEOSadas-5_29_4' ) - - self.bcsTag={} - for tag in F14: self.bcsTag[tag]= "Fortuna-1_4" - for tag in F20: self.bcsTag[tag]= "Fortuna-2_0" - for tag in F21: self.bcsTag[tag]= "Fortuna-2_1" - for tag in G10: self.bcsTag[tag]= "Ganymed-1_0" - for tag in G10p: self.bcsTag[tag]= "Ganymed-1_0_M" - for tag in G20: self.bcsTag[tag]= "Ganymed-1_0_M" - for tag in G30: self.bcsTag[tag]= "Ganymed-1_0_Reynolds" - for tag in G40: self.bcsTag[tag]= "Ganymed-4_0_Reynolds" - for tag in ICA: self.bcsTag[tag]= "Icarus_Reynolds" - for tag in GITOL: self.bcsTag[tag]= "Icarus_Reynolds" - for tag in INL: self.bcsTag[tag]= "Icarus-NLv3_Reynolds" - for tag in GITNL: self.bcsTag[tag]= "Icarus-NLv3_Reynolds" - - - for tag in D214: self.bcsTag[tag]= "Fortuna-1_4" - for tag in D540: self.bcsTag[tag]= "Fortuna-1_4" - for tag in D561: self.bcsTag[tag]= "Fortuna-2_1" - for tag in D580: self.bcsTag[tag]= "Ganymed-1_0" - for tag in D591p: self.bcsTag[tag]= "Ganymed-1_0_M" - for tag in D5A0: self.bcsTag[tag]= "Ganymed-1_0_M" - for tag in D5B0: self.bcsTag[tag]= "Ganymed-1_0_Reynolds" - for tag in D512: self.bcsTag[tag]= "Ganymed-4_0_Reynolds" - for tag in D517: self.bcsTag[tag]= "Icarus_Reynolds" - for tag in D525: self.bcsTag[tag]= "Icarus-NLv3_Reynolds" - - self.tagsRank ={} - self.tagsRank['Fortuna-1_4'] = 1 - self.tagsRank['Fortuna-1_5'] = 2 - self.tagsRank['Fortuna-2_0'] = 3 - self.tagsRank['Fortuna-2_1'] = 4 - self.tagsRank['Ganymed-1_0'] = 5 - self.tagsRank['Ganymed-1_0_m1'] = 6 - self.tagsRank['Ganymed-1_0_m2'] = 7 - self.tagsRank['Ganymed-1_0_M'] = 8 - self.tagsRank['Ganymed-1_0_D'] = 9 - self.tagsRank['Ganymed-1_0_Reynolds'] = 10 - self.tagsRank['Ganymed-1_0_Ostia'] = 11 - self.tagsRank['Ganymed-4_0_Reynolds'] = 12 - self.tagsRank['Ganymed-4_0_Ostia'] = 13 - self.tagsRank['Ganymed-4_0_MERRA-2'] = 14 - self.tagsRank['Icarus_Reynolds'] = 15 - self.tagsRank['Icarus_MERRA-2'] = 16 - self.tagsRank['Icarus_Ostia'] = 17 - self.tagsRank['Icarus-NLv3_Reynolds'] = 18 - self.tagsRank['Icarus-NLv3_MERRA-2'] = 19 - self.tagsRank['Icarus-NLv3_Ostia'] = 20 - - self.bcbase={} - self.bcbase['discover_ops'] = "/discover/nobackup/projects/gmao/share/gmao_ops/fvInput/g5gcm/bcs" - self.bcbase['discover_lt'] = "/discover/nobackup/ltakacs/bcs" - self.bcbase['discover_couple'] = "/discover/nobackup/projects/gmao/ssd/aogcm/atmosphere_bcs" - - def init_time(self): - yyyymmddhh = str(self.common_in['yyyymmddhh']) - self.yyyymm = yyyymmddhh[0:6] - self.yyyy = yyyymmddhh[0:4] - self.mm = yyyymmddhh[4:6] - self.dd = yyyymmddhh[6:8] - self.hh = yyyymmddhh[8:10] - self.ymd = yyyymmddhh[0:8] - - def init_restarts_in(self): - if self.common_in['MERRA-2']: - return - - rst_dir = self.common_in.get('rst_dir')+'/' - self.restarts_in={} - self.restarts_in['UPPERAIR'] = glob.glob(rst_dir +'upperair/*') - self.restarts_in['SURFACE'] = glob.glob(rst_dir +'surface/*') - self.restarts_in['ANALYSIS'] = glob.glob(rst_dir +'analysis/*') - - def init_merra2(self): - if not self.common_in['MERRA-2']: - return - print("\nMERRA-2 sources:\n") - yyyymm = int(self.yyyymm) - if yyyymm < 197901 : - print("Error. MERRA-2 data < 1979 not available\n") - exit() - elif (yyyymm < 199201): - self.common_in['expid'] = "d5124_m2_jan79" - elif (yyyymm < 200106): - self.common_in['expid'] = "d5124_m2_jan91" - elif (yyyymm < 201101): - self.common_in['expid'] = "d5124_m2_jan00" - else: - self.common_in['expid'] = "d5124_m2_jan10" - - self.common_in['agrid'] = 'C180' - self.common_in['ogrid'] = '1440x720' - self.common_in['bc_base']= 'discover_ops' - self.common_in['tag']= 'Ganymed-4_0' - expid = self.common_in['expid'] - yyyymmddhh = str(self.common_in['yyyymmddhh']) - surfix = yyyymmddhh[0:8]+'_'+self.hh+'z.bin' - self.common_in['rst_dir'] = '/archive/users/gmao_ops/MERRA2/gmao_ops/GEOSadas-5_12_4/'+expid +'/rs/Y'+self.yyyy +'/M'+self.mm+'/' - print('\nMERRA-2 Restart dir: ' + self.common_in['rst_dir']) - - self.restarts_in = {} - upperin =[self.common_in['rst_dir']+ expid+'.fvcore_internal_rst.' + surfix, - self.common_in['rst_dir']+ expid+'.moist_internal_rst.' + surfix, - self.common_in['rst_dir']+ expid+'.agcm_import_rst.' + surfix, - self.common_in['rst_dir']+ expid+'.gocart_internal_rst.' + surfix, - self.common_in['rst_dir']+ expid+'.pchem_internal_rst.' + surfix ] - self.restarts_in['UPPERAIR'] = upperin - - surfin = [self.common_in['rst_dir']+ expid+'.catch_internal_rst.' + surfix, - self.common_in['rst_dir']+ expid+'.lake_internal_rst.' + surfix, - self.common_in['rst_dir']+ expid+'.landice_internal_rst.' + surfix, - self.common_in['rst_dir']+ expid+'.saltwater_internal_rst.'+ surfix] - self.restarts_in['SURFACE'] = surfin - self.restarts_in['ANALYSIS'] = [] - - def get_bcbase(self, opt): - base = '' - model = '' - - if opt.upper() == 'IN': - model = self.common_in.get('model') - if model == 'MOM6' or model == 'MOM5': - base = 'discover_couple' - else: - base = self.common_in.get('bc_base') - - if opt.upper() == 'OUT': - model = self.common_out.get('model') - if model == 'MOM6' or model == 'MOM5': - base = 'discover_couple' - else: - base = self.common_out.get('bc_base') - assert base, 'please specify bc_base: discover_ops, discover_lt, discover_couple or an absolute path' - if base == 'discover_ops' or base == 'discover_lt' or base=='discover_couple': - return self.bcbase[base] - else: - return base - - def get_bcdir(self, opt): - tag = self.common_in['tag'] - ogrid = self.common_in['ogrid'] - model = self.common_in['model'] - bcdir = self.common_in.get('alt_bcs', None) - if opt.upper() == "OUT": - tag = self.common_out['tag'] - ogrid = self.common_out['ogrid'] - model = self.common_out['model'] - bcdir = self.common_in.get('alt_bcs', None) - - if bcdir is None : - bc_base = self.get_bcbase(opt) - bctag = self.get_bcTag(tag,ogrid) - tagrank = self.tagsRank[bctag] - if (tagrank >= self.tagsRank['Icarus-NLv3_Reynolds']) : - bcdir = bc_base+'/Icarus-NLv3/'+bctag+'/' - if model == 'MOM6' or model == 'MOM5': - bcdir = bc_base+'/Icarus-NLv3/'+model+'/' - elif (tagrank >= self.tagsRank['Icarus_Reynolds']): - if bc_base == self.bcbase['discover_ops']: - bcdir = bc_base+'/Icarus_Updated/'+bctag+'/' - else: - bcdir = bc_base+'/Icarus/'+bctag+'/' - if model == 'MOM6' or model == 'MOM5': - bcdir = bc_base+'/Icarus/'+model+'/' - elif(tagrank >= self.tagsRank["Ganymed-4_0_Reynolds"]): - bcdir = bc_base + '/Ganymed-4_0/'+bctag+'/' - if model == 'MOM6' or model == 'MOM5': - bcdir = bc_base+'/Ganymed/'+model+'/' - else: - bcdir = bc_base + '/' + bctag + '/' - if model == 'MOM6' or model == 'MOM5': - bcdir = bc_base+'/Ganymed/'+model+'/' - - if not os.path.exists(bcdir): - print( "Cannot find bc dir " + bcdir) - exit() - - gridStr = self.get_grid_subdir(bcdir,opt) - bcdir = bcdir + '/' + gridStr - - return bcdir - - def get_grid_subdir(self, bcdir, opt): - - def get_name_with_grid( grid, names): - if not grid : - return names - namex = [] - if (grid[0].upper() == 'C'): - n = int(grid[1:]) - s1 ='{n}x6C'.format(n=n) - j=n*6 - s2 =str(n) - s3 =str(j) - # first try - for name in names: - if (name.find(s1) != -1): - namex.append(name) - if len(namex) ==0: - for name in names: - if (name.find(s2) != -1 and name.find(s3) != -1): namex.append(name) - else: - xy = grid.upper().split('X') - s2 = xy[0] - s3 = xy[1] - for name in names: - if (name.find(s2) != -1 and name.find(s3) != -1): namex.append(name) - return namex - #v3.5 - #dirnames = [ f.name for f in os.scandir(bcdir) if f.is_dir()] - #v2.7 - dirnames = [f for f in os.listdir(bcdir) if os.path.isdir(os.path.join(bcdir,f))] - agrid_ = self.common_in['agrid'] - ogrid_ = self.common_in['ogrid'] - if opt.upper() == "OUT" : - agrid_ = self.common_out['agrid'] - ogrid_ = self.common_out['ogrid'] - - anames = get_name_with_grid(agrid_, dirnames) - gridID = get_name_with_grid(ogrid_, anames) - if len(gridID) == 0 : - print("cannot find the grid string: " + bcdir) - exit() - if len(gridID) >=2 : - print("find too may grid strings in " + bcdir) - print(" gridIDs found", gridID) - print(" pick the first one " + gridID[0]) - return gridID[0] - - def get_bcTag(self, tag, ogrid): - bctag = self.bcsTag[tag] - if ogrid[0].upper() == "C": - bctag=bctag.replace('_Reynolds','_Ostia') - else: - xy = ogrid.upper().split('X') - x = int(xy[0]) - if x == 1440: bctag=bctag.replace('_Reynolds','_MERRA-2') - if x == 2800: - bctag=bctag.replace('_Reynolds','_Ostia') - bctag=bctag.replace('_M','_D') - return bctag diff --git a/GEOS_Util/post/regridder_surf.py b/GEOS_Util/post/regridder_surf.py deleted file mode 100644 index 141e8d14..00000000 --- a/GEOS_Util/post/regridder_surf.py +++ /dev/null @@ -1,338 +0,0 @@ -#!/usr/bin/env python3 -# -import os -import subprocess -import shutil -import shlex -import glob -from regridder_base import * - -class surface(regridder): - def __init__(self, config): - #v3.0 - #super().__init__(config) - #v2.7 - super(surface, self).__init__(config) - self.restarts_in = self.restarts_in['SURFACE'] - self.surf_in = config['input']['parameters']['SURFACE'] - self.surf_out = config['output']['parameters']['SURFACE'] - - self.saltwater = None - self.openwater = None - self.seaice = None - self.landice = None - self.lake = None - self.route = None - self.catch = None - self.catchcnclm40 = None - self.catchcnclm45 = None - for rst in self.restarts_in : - f = os.path.basename(rst) - if (f.find('saltwater') != -1): - self.saltwater = f - continue - if (f.find('seaice') != -1): - self.seaice = f - continue - if (f.find('landice') != -1): - self.landice = f - continue - if (f.find('lake') != -1): - self.lake = f - continue - if (f.find('route') != -1): - self.route = f - continue - if (f.find('catch_') != -1): - self.catch = f - continue - if (f.find('catchcnclm40') != -1): - self.catchcnclm40 = f - continue - if (f.find('catchcnclm45') != -1): - self.catchcnclm45 = f - continue - tagout = self.common_out['tag'] - ogrid = self.common_out['ogrid'] - bctag = self.get_bcTag(tagout, ogrid) - tagrank = self.tagsRank[bctag] - - self.surf_out['surflay'] = 20. - if tagrank >=12 : - self.surf_out['surflay'] = 50. - self.surf_in['rescale'] = 0 - if tagrank > self.tagsRank["Fortuna-2_0"]: - self.surf_in['rescale'] = 1 - - def regrid(self): - bindir = os.getcwd() - out_dir = self.common_out['out_dir'] - if not os.path.exists(out_dir) : os.makedirs(out_dir) - os.chdir(self.common_out['out_dir']) - InData_dir = out_dir+'/InData/' - OutData_dir = out_dir+'/OutData/' - if os.path.exists(InData_dir) : subprocess.call(['rm','-rf', InData_dir]) - os.makedirs(InData_dir) - if os.path.exists(OutData_dir) : subprocess.call(['rm','-rf', OutData_dir]) - os.makedirs(OutData_dir) - - for rst in self.restarts_in: - f = os.path.basename(rst) - dest = InData_dir+'/'+f - if os.path.exists(dest) : shutil.remove(dest) - print('\nCopy ' + rst + ' to ' +dest) - shutil.copy(rst,dest) - - in_til = InData_dir+'/' + self.in_til.split('/')[-1] - out_til = OutData_dir+'/'+self.out_til.split('/')[-1] - if os.path.exists(in_til) : shutil.remove(in_til) - if os.path.exists(out_til) : shutil.remove(out_til) - print('\n Copy ' + self.in_til + ' to ' + in_til) - shutil.copy(self.in_til, in_til) - print('\n Copy ' + self.out_til + ' to ' + out_til) - shutil.copy(self.out_til, out_til) - - ogrid = self.common_out['ogrid'] - tagout = self.common_out['tag'] - bctag = self.get_bcTag(tagout, ogrid) - tagrank = self.tagsRank[bctag] - split_saltwaterFLG = '0' - if tagrank >= self.tagsRank["Icarus_Reynolds"] and self.saltwater: - split_saltwaterFLG = '1' - - exe = bindir + '/mk_LakeLandiceSaltRestarts ' - if (self.saltwater): - cmd = exe + 'OutData/*.til InData/*.til InData/'+self.saltwater + ' 0 ' + str(self.surf_in['zoom']) - print('\n'+cmd) - subprocess.call(shlex.split(cmd)) - - # split Saltwater - ogrid = self.common_out['ogrid'] - tagout = self.common_out['tag'] - bctag = self.get_bcTag(tagout, ogrid) - tagrank = self.tagsRank[bctag] - if split_saltwaterFLG == '1': - print("\nSplitting Saltwater...\n") - cmd = bindir+'/SaltIntSplitter ' + out_til + ' ' + 'OutData/'+self.saltwater - print('\n'+cmd) - subprocess.call(shlex.split(cmd)) - self.openwater = None - self.seaice = None - - if (self.openwater): - cmd = exe + 'OutData/*.til InData/*.til InData/'+self.openwater + ' 0 ' + str(self.surf_in['zoom']) - print('\n'+cmd) - subprocess.call(shlex.split(cmd)) - - if (self.seaice): - cmd = exe + 'OutData/*.til InData/*.til InData/'+self.seaice + ' 0 ' + str(self.surf_in['zoom']) - print('\n'+cmd) - subprocess.call(shlex.split(cmd)) - - if (self.lake): - cmd = exe + 'OutData/*.til InData/*.til InData/'+self.lake + ' 19 ' + str(self.surf_in['zoom']) - print('\n'+cmd) - subprocess.call(shlex.split(cmd)) - - if (self.landice): - cmd = exe + 'OutData/*.til InData/*.til InData/'+self.landice + ' 20 ' + str(self.surf_in['zoom']) - print('\n'+cmd) - subprocess.call(shlex.split(cmd)) - - if (self.route): - route = bindir + '/mk_RouteRestarts ' - cmd = route + 'OutData/*.til '+ self.common_in["yyyymmddhh"][0:6] - print('\n'+cmd) - subprocess.call(shlex.split(cmd)) - - if ( self.catchcnclm40 or self.catchcnclm45) : - dirname = os.path.dirname(self.out_til) - clsm = dirname+'/clsm' - print( "\nsymbolic link clsm to OutData/clsm") - os.symlink(clsm, 'OutData/clsm') - - mk_catch_j_template = """#!/bin/csh -f -#SBATCH --account={account} -#SBATCH --ntasks=84 -#SBATCH --time=1:00:00 -#SBATCH --job-name=mk_catch -#SBATCH --qos=debug -#SBATCH --output={out_dir}/{mk_catch_log} -# - -source {Bin}/g5_modules -set echo - -#limit stacksize unlimited -unlimit - -#set lakelandRestartX = ( {Bin}/mk_LakeLandiceSaltRestarts ) -#set split_saltwaterX = ({Bin}/SaltIntSplitter ) -#set routRestartX = ( {Bin}/mk_RouteRestarts ) -set esma_mpirun_X = ( {Bin}/esma_mpirun -np 84 ) -set mk_CatchRestarts_X = ( $esma_mpirun_X {Bin}/mk_CatchRestarts ) -set mk_CatchCNRestarts_X = ( $esma_mpirun_X {Bin}/mk_CatchCNRestarts ) -set Scale_Catch_X = {Bin}/Scale_Catch -set Scale_CatchCN_X = {Bin}/Scale_CatchCN - -set OUT_til = OutData/*.til -set IN_til = InData/*.til - -#if ( {saltwaterFLG}) then -# $lakelandRestartX $OUT_til $IN_til InData/{saltwater} 0 {zoom} -# if ({split_saltwaterFLG}) then -# $split_saltwaterX $OUT_til OutData/{saltwater} -# endif -#endif - -#if ( {openwaterFLG}) then -# $lakelandRestartX $OUT_til $IN_til InData/{openwater} 0 {zoom} -#endif -# -#if ( {seaiceFLG}) then -# $lakelandRestartX $OUT_til $IN_til InData/{seaice} 0 {zoom} -#endif -# -#if ( {lakeFLG}) then -# $lakelandRestartX $OUT_til $IN_til InData/{lake} 19 {zoom} -#endif -# -#if ( {landiceFLG}) then -# $lakelandRestartX $OUT_til $IN_til InData/{landice} 20 {zoom} -#endif -# -#if ( {routeFLG}) then -# $routeRestartX $OUT_til {yyyymm} -#endif - -if ({catchFLG}) then - set catchIN = InData/*catch_internal_rst* - set params = ( $OUT_til $IN_til $catchIN {surflay} ) - $mk_CatchRestarts_X $params - - if ({rescale}) then - set catch_regrid = OutData/$catchIN:t - set catch_scaled = $catch_regrid.scaled - set params = ( $catchIN $catch_regrid $catch_scaled {surflay} ) - set params = ( $params {wemin} {wemout} ) - $Scale_Catch_X $params - - rm $catch_regrid - #mv $catch_regrid $catch_regrid.1 - mv $catch_scaled $catch_regrid - endif -endif - -if ({catchcnFLG}) then - # WY notes: it was never used in gcm - if ({fromGCM} ) then - set catchcnIN = InData/*catchcn_internal_rst* - set params = ( $OUT_til $IN_til $catchcnIN {surflay} {rsttime} ) - $mk_CatchCNRestarts_X $params - else # from GEOSldas - set OUT_til = `ls OutData/*.til | cut -d '/' -f2` - /bin/cp OutData/*.til OutData/OutTileFile - /bin/cp OutData/*.til InData/OutTileFile - set RESTART_short = {RESTART_PATH}/{RESTART_ID}/output/{RESTART_DOMAIN}/ - set YYYY = `echo {rsttime} | cut -c1-4` - set MM = `echo {rsttime} | cut -c5-6` - echo $MM, $YYYY - set PARAM_FILE = `ls $RESTART_short/rc_out/Y$YYYY/M$MM/*ldas_catparam* | head -1` - set params = ( -b OutData/ -d {rsttime} -e {RESTART_ID} -m catchcn{CN_VERSION} -s {surflay} -j Y -r R -p $PARAM_FILE -l $RESTART_short) - $mk_GEOSldasRestarts_X $params - endif - - if ({rescale}) then - set catchcn_regrid = OutData/$catchcnIN:t - set catchcn_scaled = $catchcn_regrid.scaled - set params = ( $catchcnIN $catchcn_regrid $catchcn_scaled {surflay} ) - set params = ( $params {wemin} {wemout} ) - $Scale_CatchCN_X $params - - rm $catchcn_regrid - #mv $catchcn_regrid $catchcn_regrid.1 - mv $catchcn_scaled $catchcn_regrid - endif -endif -""" - saltwaterFLG = '1' if self.saltwater else '0' - openwaterFLG = '1' if self.openwater else '0' - seaiceFLG = '1' if self.seaice else '0' - landiceFLG = '1' if self.landice else '0' - lakeFLG = '1' if self.lake else '0' - routeFLG = '1' if self.route else '0' - if (split_saltwaterFLG == '1' ): - openwaterFLG = '0' - seaiceFLG = '0' - - catchFLG = '1' if self.catch else '0' - catchcnFLG = '1' if (self.catchcnclm40 or self.catchcnclm45) else '0' - - catch1script = mk_catch_j_template.format(Bin = bindir, account = self.slurm_options['account'], \ - out_dir = out_dir, mk_catch_log = 'mk_catch_log.1', surflay = self.surf_out['surflay'], \ - wemin = self.surf_in['wemin'], wemout = self.surf_out['wemout'] , \ - fromGCM = '0', catchFLG = catchFLG, catchcnFLG = catchcnFLG, rescale = '0', rsttime = self.common_in['yyyymmddhh'], \ - RESTART_ID = self.surf_in.get('restart_id'), RESTART_PATH = self.surf_in.get('restart_path'), \ - RESTART_DOMAIN = self.surf_in.get('restart_domain'), CN_VERSION = self.surf_in.get('cn_version'), \ - saltwaterFLG = saltwaterFLG, saltwater = self.saltwater, \ - openwaterFLG = openwaterFLG, openwater = self.openwater, \ - seaiceFLG = seaiceFLG, seaice = self.seaice, \ - landiceFLG = landiceFLG, landice = self.landice, \ - lakeFLG = lakeFLG, lake = self.lake, \ - split_saltwaterFLG = split_saltwaterFLG, \ - routeFLG = routeFLG, route = self.route, yyyymm = str(self.common_in['yyyymmddhh'])[0:6], \ - zoom = self.surf_in['zoom'] ) - catch1 = open('mk_catch.j.1','wt') - catch1.write(catch1script) - catch1.close() - print("step 1: sbatch -W mk_catch.j.1") - subprocess.call(['sbatch','-W', 'mk_catch.j.1']) - # step 2 - if (self.surf_in['rescale'] and ( self.catch or self.catchcnclm40 or self.catchcnclm45)) : - if os.path.exists('InData.step1') : subprocess.call(['rm','-rf', 'InData.step1']) - print("\n Move Indata to InData.step1") - shutil.move('InData', 'InData.step1') - os.makedirs('InData') - for catchfile in glob.glob("OutData/*catch*"): - print('\n Move ' + catchfile + ' to InData/') - shutil.move(catchfile,"InData/") - print('\n Link ' + self.out_til + ' to ' + in_til) - os.symlink(self.out_til, in_til) - - if ( (not (self.catchcnclm40 or self.catchcnclm45)) and self.catch) : - dirname = os.path.dirname(self.out_til) - clsm = dirname+'/clsm' - print('\n Link ' + clsm + ' to ' + 'OutData/clsm') - os.symlink(clsm, 'OutData/clsm') - - saltwaterFLG = '0' - openwaterFLG = '0' - seaiceFLG = '0' - landiceFLG = '0' - lakeFLG = '0' - routeFLG = '0' - catch2script = mk_catch_j_template.format(Bin = bindir, account = self.slurm_options['account'], \ - out_dir = out_dir, mk_catch_log = 'mk_catch_log.2', surflay = self.surf_out['surflay'], \ - wemin = self.surf_in['wemin'], wemout = self.surf_out['wemout'] , \ - fromGCM = '0', catchFLG = catchFLG, catchcnFLG = catchcnFLG, rescale = '1', rsttime = self.common_in['yyyymmddhh'], \ - RESTART_ID = self.surf_in.get('restart_id'), RESTART_PATH = self.surf_in.get('restart_path'), \ - RESTART_DOMAIN = self.surf_in.get('restart_domain'), CN_VERSION = self.surf_in.get('cn_version'), \ - saltwaterFLG = saltwaterFLG, saltwater = self.saltwater, \ - openwaterFLG = openwaterFLG, openwater = self.openwater, \ - seaiceFLG = seaiceFLG, seaice = self.seaice, \ - landiceFLG = landiceFLG, landice = self.landice, \ - lakeFLG = lakeFLG, lake = self.lake, \ - split_saltwaterFLG = split_saltwaterFLG, \ - routeFLG = routeFLG, route = self.route, yyyymm = str(self.common_in['yyyymmddhh'])[0:6], \ - zoom = self.surf_in['zoom'] ) - catch2 = open('mk_catch.j.2','wt') - catch2.write(catch2script) - catch2.close() - print("step 2: sbatch -W mk_catch.j.2") - subprocess.call(['sbatch','-W', 'mk_catch.j.2']) - cwd = os.getcwd() - for out_rst in glob.glob("OutData/*_rst*"): - filename = os.path.basename(out_rst) - print( "\nmove " + out_rst + " to " + cwd+"/"+filename) - shutil.move(out_rst, cwd+"/"+filename) - os.chdir(bindir) diff --git a/GEOS_Util/post/regridder_upper.py b/GEOS_Util/post/regridder_upper.py deleted file mode 100644 index fd524b9a..00000000 --- a/GEOS_Util/post/regridder_upper.py +++ /dev/null @@ -1,206 +0,0 @@ -#!/usr/bin/env python3 -# -import os -import subprocess -import shlex -import shutil -import glob -from regridder_base import * - -class upperair(regridder): - def __init__(self, config): - # v3.0 - #super().__init__(config) - # v2.7 - super(upperair, self).__init__(config) - self.upper_out = config['output']['parameters']['UPPERAIR'] - self.restarts_in = self.restarts_in['UPPERAIR'] - - # verify agrid - agrid = self.common_in['agrid'] - ogrid = self.common_out['ogrid'] - fvrst = os.path.dirname(os.path.realpath(__file__)) + '/fvrst.x -h ' - if not self.common_in.get('MERRA-2'): - fvcore = '' - for f in self.restarts_in: - if 'fvcore' in f: - fvcore = f - break - cmd = fvrst + fvcore - print(cmd +'\n') - p = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE) - (output, err) = p.communicate() - p_status = p.wait() - ss = output.decode().split() - if (agrid): - if agrid[0].upper() == "C": - n=int(agrid[1:]) - o=int(ss[0]) - assert n==o, "input agrid is not consistent with fvcore restart" - else: - self.common_in['agrid'] = "C"+ss[0] - - tagout = self.common_out['tag'] - bctag = self.get_bcTag(tagout, ogrid) - tagrank = self.tagsRank[bctag] - - self.upper_out['drymassFLG'] = 0 - if tagrank >=12 : - self.upper_out['drymassFLG'] = 1 - - agrid = self.common_out['agrid'] - if agrid[0].upper() == 'C': - self.upper_out['imout']= int(agrid[1:]) - else: - print("Only support cs grid so far") - exit() - - imout = self.upper_out['imout'] - if (imout <=90): - self.upper_out['NPE'] = 12; self.upper_out['nwrit'] = 1 - elif (imout==180): - self.upper_out['NPE'] = 24; self.upper_out['nwrit'] = 1 - elif (imout<=500): - self.upper_out['NPE'] = 96; self.upper_out['nwrit'] = 1 - elif (imout==720): - self.upper_out['NPE'] = 192; self.upper_out['nwrit'] = 2 - elif (imout==1000): - self.upper_out['NPE'] = 384; self.upper_out['nwrit'] = 2 - elif (imout==1440): - self.upper_out['NPE'] = 576; self.upper_out['nwrit'] = 2 - elif (imout==2000): - self.upper_out['NPE'] = 768; self.upper_out['nwrit'] = 2 - elif (imout>=2880): - self.upper_out['NPE'] = 5400; self.upper_out['nwrit'] = 6 - - self.upper_out['QOS'] = "#" - if self.upper_out['NPE'] <= 532: self.upper_out['QOS'] = "#SBATCH --qos=debug" - - def regrid(self): - print( "\nRegridding upper air......\n") - bindir = os.getcwd() - out_dir = self.common_out['out_dir'] - if not os.path.exists(out_dir) : os.makedirs(out_dir) - print( "cd " + self.common_out['out_dir']) - os.chdir(self.common_out['out_dir']) - tmpdir = out_dir+'/upper_data/' - if os.path.exists(tmpdir) : subprocess.call(['rm', '-rf',tmpdir]) - print ("mkdir " + tmpdir) - os.makedirs(tmpdir) - - print( "cd " + tmpdir) - os.chdir(tmpdir) - print('\nUpper air restart files should end with "_rst" \n') - for rst in self.restarts_in : - f = os.path.basename(rst) - f = f.replace('_rst','_restart_in') - cmd = '/bin/cp '+rst+' '+f - print('\n'+cmd) - subprocess.call(shlex.split(cmd)) - - # link topo file - topoin = glob.glob(self.in_bcsdir+'/topo_DYN_ave*')[0] - cmd = '/bin/cp ' + topoin + ' .' - print('\n'+cmd) - subprocess.call(shlex.split(cmd)) - - topoout = glob.glob(self.out_bcsdir+'/topo_DYN_ave*')[0] - cmd = '/bin/cp ' + topoout + ' .' - print('\n'+cmd) - subprocess.call(shlex.split(cmd)) - fname = os.path.basename(topoout) - cmd = '/bin/ln -s ' + fname + ' topo_dynave.data' - print('\n'+cmd) - subprocess.call(shlex.split(cmd)) - - regrid_template="""#!/bin/csh -xf -#!/bin/csh -xf -#SBATCH --account={account} -#SBATCH --time=1:00:00 -#SBATCH --ntasks={NPE} -#SBATCH --job-name=regrid_upper -#SBATCH --output={out_dir}/{out_log} -{QOS} - -unlimit - -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 -# HYDROSTATIC = 0 which means HYDROSTATIC = FALSE -set HYDROSTATIC = 0 - -if ($?I_MPI_ROOT) then - # intel scaling suggestions - #-------------------------- - - setenv I_MPI_DAPL_UD on - - setenv DAPL_UCM_CQ_SIZE 4096 - setenv DAPL_UCM_QP_SIZE 4096 - - setenv I_MPI_DAPL_UD_SEND_BUFFER_NUM 4096 - setenv I_MPI_DAPL_UD_RECV_BUFFER_NUM 4096 - setenv I_MPI_DAPL_UD_ACK_SEND_POOL_SIZE 4096 - setenv I_MPI_DAPL_UD_ACK_RECV_POOL_SIZE 4096 - setenv I_MPI_DAPL_UD_RNDV_EP_NUM 2 - setenv I_MPI_DAPL_UD_REQ_EVD_SIZE 2000 - - setenv DAPL_UCM_REP_TIME 2000 - setenv DAPL_UCM_RTU_TIME 2000 - setenv DAPL_UCM_RETRY 7 - setenv DAPL_ACK_RETRY 7 - setenv DAPL_ACK_TIMER 20 - setenv DAPL_UCM_RETRY 10 - setenv DAPL_ACK_RETRY 10 - -else if ($?MVAPICH2) then - setenv MV2_ENABLE_AFFINITY 0 - -endif -set infiles = () -set outfils = () -foreach infile ( *_restart_in ) - if ( $infile == fvcore_internal_restart_in ) continue - if ( $infile == moist_internal_restart_in ) continue - - set infiles = ( $infiles $infile ) - set outfil = `echo $infile | sed "s/restart_in/rst_out/"` - set outfils = ($outfils $outfil) -end - -if ( $#infiles ) then - set ioflag = "-input_files $infiles -output_files $outfils" -else - set ioflag = "" -endif - -set drymassFLG = {drymassFLG} -if ($drymassFLG) then - set dmflag = "" -else - set dmflag = "-scalers F" -endif - -set interp_restartsX = {Bin}/interp_restarts.x - -{Bin}/esma_mpirun -np {NPE} $interp_restartsX -im {imout} -lm {nlevel} \\ - -do_hydro $HYDROSTATIC $ioflag $dmflag -nwriter {nwrit} - -""" - regrid_upper_script = regrid_template.format(Bin=bindir, account = self.slurm_options['account'], \ - out_dir = out_dir, out_log = 'regrid_upper_log', drymassFLG = self.upper_out['drymassFLG'], \ - imout = self.upper_out['imout'], nwrit = self.upper_out['nwrit'], NPE = self.upper_out['NPE'], \ - QOS = self.upper_out['QOS'], nlevel = self.upper_out['nlevel']) - upper = open('regridder_upper.j','wt') - upper.write(regrid_upper_script) - upper.close() - print('sbatch -W regridder_upper.j\n') - subprocess.call(['sbatch', '-W', 'regridder_upper.j']) - for out_rst in glob.glob("*_rst*"): - filename = os.path.basename(out_rst) - print('\n Move ' + out_rst + ' to ' + out_dir+"/"+filename) - shutil.move(out_rst, out_dir+"/"+filename) - os.chdir(bindir) From c4f948641c55a37505e890630153ef7d95d151dc Mon Sep 17 00:00:00 2001 From: Matthew Thompson Date: Thu, 28 Apr 2022 10:25:05 -0400 Subject: [PATCH 24/70] Update comments --- GEOS_Util/post/regrid.py | 6 ++++-- GEOS_Util/post/regrid_analysis.py | 6 ++++-- GEOS_Util/post/regrid_questions.py | 5 ++++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/GEOS_Util/post/regrid.py b/GEOS_Util/post/regrid.py index e087598a..47266e91 100644 --- a/GEOS_Util/post/regrid.py +++ b/GEOS_Util/post/regrid.py @@ -1,7 +1,9 @@ #!/usr/bin/env python3 # -# source g5_modules -# module load python/GEOSpyD/Min4.9.2_py3.9 +# source install/bin/g5_modules +# +# Newer GEOS code should load a module with GEOSpyD Python3 if not run: +# module load python/GEOSpyD/Min4.10.3_py3.9 # import sys, getopt diff --git a/GEOS_Util/post/regrid_analysis.py b/GEOS_Util/post/regrid_analysis.py index a18a046a..03d11cec 100755 --- a/GEOS_Util/post/regrid_analysis.py +++ b/GEOS_Util/post/regrid_analysis.py @@ -1,7 +1,9 @@ #!/usr/bin/env python3 # -# source g5_modules -# module load python/GEOSpyD/Min4.9.2_py3.9 +# source install/bin/g5_modules +# +# Newer GEOS code should load a module with GEOSpyD Python3 if not run: +# module load python/GEOSpyD/Min4.10.3_py3.9 # import os diff --git a/GEOS_Util/post/regrid_questions.py b/GEOS_Util/post/regrid_questions.py index bba1bef9..66d3321d 100755 --- a/GEOS_Util/post/regrid_questions.py +++ b/GEOS_Util/post/regrid_questions.py @@ -1,6 +1,9 @@ #!/usr/bin/env python3 # -# source python/GEOSpyD/Min4.9.2_py3.9 +# source install/bin/g5_modules +# +# Newer GEOS code should load a module with GEOSpyD Python3 if not run: +# module load python/GEOSpyD/Min4.10.3_py3.9 # import os From 4361441b72aa786f40486c396f853d5f9c602c19 Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Thu, 28 Apr 2022 14:24:03 -0400 Subject: [PATCH 25/70] relocate regrid*.py to regrid_py --- GEOS_Util/post/CMakeLists.txt | 2 +- GEOS_Util/post/{ => regrid_py}/regrid.py | 0 GEOS_Util/post/{ => regrid_py}/regrid_analysis.py | 0 GEOS_Util/post/{ => regrid_py}/regrid_catchment.py | 0 GEOS_Util/post/{ => regrid_py}/regrid_lake_landice_saltwater.py | 0 GEOS_Util/post/{ => regrid_py}/regrid_params.py | 0 GEOS_Util/post/{ => regrid_py}/regrid_params.tpl | 0 GEOS_Util/post/{ => regrid_py}/regrid_questions.py | 0 GEOS_Util/post/{ => regrid_py}/regrid_upper.py | 0 9 files changed, 1 insertion(+), 1 deletion(-) rename GEOS_Util/post/{ => regrid_py}/regrid.py (100%) rename GEOS_Util/post/{ => regrid_py}/regrid_analysis.py (100%) rename GEOS_Util/post/{ => regrid_py}/regrid_catchment.py (100%) rename GEOS_Util/post/{ => regrid_py}/regrid_lake_landice_saltwater.py (100%) rename GEOS_Util/post/{ => regrid_py}/regrid_params.py (100%) rename GEOS_Util/post/{ => regrid_py}/regrid_params.tpl (100%) rename GEOS_Util/post/{ => regrid_py}/regrid_questions.py (100%) rename GEOS_Util/post/{ => regrid_py}/regrid_upper.py (100%) diff --git a/GEOS_Util/post/CMakeLists.txt b/GEOS_Util/post/CMakeLists.txt index 7c058d6a..21503ff9 100644 --- a/GEOS_Util/post/CMakeLists.txt +++ b/GEOS_Util/post/CMakeLists.txt @@ -50,7 +50,7 @@ install( PROGRAMS ${perlscripts} ec2grd.csh DESTINATION bin) -file(GLOB pythonscripts CONFIGURE_DEPENDS regrid*.py regrid_params.tpl) +file(GLOB pythonscripts CONFIGURE_DEPENDS ./regrid_py/regrid*) install( PROGRAMS ${pythonscripts} DESTINATION bin) diff --git a/GEOS_Util/post/regrid.py b/GEOS_Util/post/regrid_py/regrid.py similarity index 100% rename from GEOS_Util/post/regrid.py rename to GEOS_Util/post/regrid_py/regrid.py diff --git a/GEOS_Util/post/regrid_analysis.py b/GEOS_Util/post/regrid_py/regrid_analysis.py similarity index 100% rename from GEOS_Util/post/regrid_analysis.py rename to GEOS_Util/post/regrid_py/regrid_analysis.py diff --git a/GEOS_Util/post/regrid_catchment.py b/GEOS_Util/post/regrid_py/regrid_catchment.py similarity index 100% rename from GEOS_Util/post/regrid_catchment.py rename to GEOS_Util/post/regrid_py/regrid_catchment.py diff --git a/GEOS_Util/post/regrid_lake_landice_saltwater.py b/GEOS_Util/post/regrid_py/regrid_lake_landice_saltwater.py similarity index 100% rename from GEOS_Util/post/regrid_lake_landice_saltwater.py rename to GEOS_Util/post/regrid_py/regrid_lake_landice_saltwater.py diff --git a/GEOS_Util/post/regrid_params.py b/GEOS_Util/post/regrid_py/regrid_params.py similarity index 100% rename from GEOS_Util/post/regrid_params.py rename to GEOS_Util/post/regrid_py/regrid_params.py diff --git a/GEOS_Util/post/regrid_params.tpl b/GEOS_Util/post/regrid_py/regrid_params.tpl similarity index 100% rename from GEOS_Util/post/regrid_params.tpl rename to GEOS_Util/post/regrid_py/regrid_params.tpl diff --git a/GEOS_Util/post/regrid_questions.py b/GEOS_Util/post/regrid_py/regrid_questions.py similarity index 100% rename from GEOS_Util/post/regrid_questions.py rename to GEOS_Util/post/regrid_py/regrid_questions.py diff --git a/GEOS_Util/post/regrid_upper.py b/GEOS_Util/post/regrid_py/regrid_upper.py similarity index 100% rename from GEOS_Util/post/regrid_upper.py rename to GEOS_Util/post/regrid_py/regrid_upper.py From 64ebdfedb2d937538efa28bf858d1a542d6f8eb9 Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Thu, 28 Apr 2022 17:11:36 -0400 Subject: [PATCH 26/70] read and write yaml file with comments --- GEOS_Util/post/regrid_py/regrid.py | 2 +- GEOS_Util/post/regrid_py/regrid_analysis.py | 10 ++++++---- GEOS_Util/post/regrid_py/regrid_catchment.py | 10 ++++++---- .../regrid_py/regrid_lake_landice_saltwater.py | 10 ++++++---- GEOS_Util/post/regrid_py/regrid_params.py | 18 ++++++++++-------- GEOS_Util/post/regrid_py/regrid_params.tpl | 9 +++++++++ GEOS_Util/post/regrid_py/regrid_upper.py | 10 ++++++---- 7 files changed, 44 insertions(+), 25 deletions(-) diff --git a/GEOS_Util/post/regrid_py/regrid.py b/GEOS_Util/post/regrid_py/regrid.py index 47266e91..fa39bda0 100644 --- a/GEOS_Util/post/regrid_py/regrid.py +++ b/GEOS_Util/post/regrid_py/regrid.py @@ -7,7 +7,6 @@ # import sys, getopt -import yaml from regrid_questions import get_config_from_questionary from regrid_params import * from regrid_upper import * @@ -43,6 +42,7 @@ def main(argv): params.convert_to_yaml() config_yaml = 'regrid_params.yaml' + sys.exit() # upper air upper = upperair(config_yaml) upper.regrid() diff --git a/GEOS_Util/post/regrid_py/regrid_analysis.py b/GEOS_Util/post/regrid_py/regrid_analysis.py index 03d11cec..775353fb 100755 --- a/GEOS_Util/post/regrid_py/regrid_analysis.py +++ b/GEOS_Util/post/regrid_py/regrid_analysis.py @@ -13,13 +13,15 @@ import shutil import glob import fileinput -import yaml +import ruamel.yaml class analysis(object): def __init__(self, params_file): - stream = open(params_file, 'r') - self.config = yaml.full_load(stream) - stream.close() + yaml = ruamel.yaml.YAML() + stream ='' + with open(params_file, 'r') as f: + stream = f.read() + self.config = yaml.load(stream) def regrid(self): config = self.config diff --git a/GEOS_Util/post/regrid_py/regrid_catchment.py b/GEOS_Util/post/regrid_py/regrid_catchment.py index dee16e49..d119403e 100755 --- a/GEOS_Util/post/regrid_py/regrid_catchment.py +++ b/GEOS_Util/post/regrid_py/regrid_catchment.py @@ -4,14 +4,16 @@ import subprocess import shutil import glob -import yaml +import ruamel.yaml import shlex class catchment(object): def __init__(self, params_file): - stream = open(params_file, 'r') - self.config = yaml.full_load(stream) - stream.close() + yaml = ruamel.yaml.YAML() + stream ='' + with open(params_file, 'r') as f: + stream = f.read() + self.config = yaml.load(stream) def regrid(self): print("\nRegridding catchment.....\n") diff --git a/GEOS_Util/post/regrid_py/regrid_lake_landice_saltwater.py b/GEOS_Util/post/regrid_py/regrid_lake_landice_saltwater.py index a6f909b0..875c0521 100755 --- a/GEOS_Util/post/regrid_py/regrid_lake_landice_saltwater.py +++ b/GEOS_Util/post/regrid_py/regrid_lake_landice_saltwater.py @@ -4,14 +4,16 @@ import subprocess import shutil import glob -import yaml +import ruamel.yaml import shlex class lake_landice_saltwater(object): def __init__(self, params_file): - stream = open(params_file, 'r') - self.config = yaml.full_load(stream) - stream.close() + yaml = ruamel.yaml.YAML() + stream ='' + with open(params_file, 'r') as f: + stream = f.read() + self.config = yaml.load(stream) def regrid(self): print("\nRegridding land, landice, saltwater.....\n") diff --git a/GEOS_Util/post/regrid_py/regrid_params.py b/GEOS_Util/post/regrid_py/regrid_params.py index 0e5fc449..6462ca0b 100755 --- a/GEOS_Util/post/regrid_py/regrid_params.py +++ b/GEOS_Util/post/regrid_py/regrid_params.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 # import os -import yaml +import ruamel.yaml import shutil import glob import time @@ -34,11 +34,13 @@ def __init__(self, config_from_question): print("\noutput tile file: " + self.out_til) # load input yaml - stream = open('regrid_params.tpl', 'r') - config_tpl = yaml.full_load(stream) - - # params for shared + yaml = ruamel.yaml.YAML() + stream = '' + with open('regrid_params.tpl', 'r') as f: + stream = f.read() + config_tpl = yaml.load(stream) + # params for shared config_tpl['input']['shared']['agrid'] = self.common_in['agrid'] config_tpl['input']['shared']['ogrid'] = self.common_in['ogrid'] config_tpl['input']['shared']['bcs_dir'] = self.in_bcsdir @@ -71,9 +73,9 @@ def convert_to_yaml(self) : else: shutil.move('regrid_params.yaml', new_name) break - f = open("regrid_params.yaml", "w") - yaml.dump(self.config, f, allow_unicode=True, default_flow_style=False) - f.close() + yaml = ruamel.yaml.YAML() + with open("regrid_params.yaml", "w") as f: + yaml.dump(self.config, f) def init_tags(self): # copy and paste from regrid.pl diff --git a/GEOS_Util/post/regrid_py/regrid_params.tpl b/GEOS_Util/post/regrid_py/regrid_params.tpl index 94306efe..45f318fa 100644 --- a/GEOS_Util/post/regrid_py/regrid_params.tpl +++ b/GEOS_Util/post/regrid_py/regrid_params.tpl @@ -1,3 +1,12 @@ +# +# This template file can be filled with questionary or manually +# +# By default, the values in child dictionary overwrites the values +# in parent dictionary. For example, rst_dir in input is the location with +# restart files to be regrrided. The surface restart files can be in +# surfface:rst_dir if it has value +# + input: air: drymass: 1 diff --git a/GEOS_Util/post/regrid_py/regrid_upper.py b/GEOS_Util/post/regrid_py/regrid_upper.py index 6d16e4c4..0fedee48 100755 --- a/GEOS_Util/post/regrid_py/regrid_upper.py +++ b/GEOS_Util/post/regrid_py/regrid_upper.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 # import os -import yaml +import ruamel.yaml import subprocess import shlex import shutil @@ -9,9 +9,11 @@ class upperair(object): def __init__(self, params_file): - stream = open(params_file, 'r') - self.config = yaml.full_load(stream) - stream.close() + yaml = ruamel.yaml.YAML() + stream ='' + with open(params_file, 'r') as f: + stream = f.read() + self.config = yaml.load(stream) def regrid(self): print( "\nRegridding upper air......\n") From bb075f7e33bbb9b1636d8358cc46d4c29377d950 Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Tue, 3 May 2022 21:35:46 -0400 Subject: [PATCH 27/70] clean up regrid_catchment.py and others --- GEOS_Util/post/regrid_py/regrid.py | 5 +- GEOS_Util/post/regrid_py/regrid_catchment.py | 186 ++++++------------ .../regrid_lake_landice_saltwater.py | 6 +- GEOS_Util/post/regrid_py/regrid_params.py | 33 ++-- GEOS_Util/post/regrid_py/regrid_params.tpl | 17 +- GEOS_Util/post/regrid_py/regrid_questions.py | 4 +- GEOS_Util/post/regrid_py/regrid_upper.py | 3 +- 7 files changed, 100 insertions(+), 154 deletions(-) diff --git a/GEOS_Util/post/regrid_py/regrid.py b/GEOS_Util/post/regrid_py/regrid.py index fa39bda0..9bb97cec 100644 --- a/GEOS_Util/post/regrid_py/regrid.py +++ b/GEOS_Util/post/regrid_py/regrid.py @@ -20,7 +20,7 @@ def main(argv): opts, args = getopt.getopt(argv,"hc:", ['config_file=']) except getopt.GetoptError: print('Usage: regrid.py -c regrid.yaml or ./regrid.py ') - sys.exit(2) + sys.exit('command line error') for opt, arg in opts: if opt == '-h': print('''\nThere are two ways to use this script to regrid restarts. \n @@ -32,7 +32,7 @@ def main(argv): \nHelp message: \n 1) The rst_dir directory should have three sub-directories: \n upperair, surface and analysis which contain restart files respectively. \n''') - sys.exit() + sys.exit(0) if opt in("-c", "--config_file"): config_yaml = arg @@ -42,7 +42,6 @@ def main(argv): params.convert_to_yaml() config_yaml = 'regrid_params.yaml' - sys.exit() # upper air upper = upperair(config_yaml) upper.regrid() diff --git a/GEOS_Util/post/regrid_py/regrid_catchment.py b/GEOS_Util/post/regrid_py/regrid_catchment.py index d119403e..8151de69 100755 --- a/GEOS_Util/post/regrid_py/regrid_catchment.py +++ b/GEOS_Util/post/regrid_py/regrid_catchment.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 # import os +import sys import subprocess import shutil import glob @@ -18,67 +19,62 @@ def __init__(self, params_file): def regrid(self): print("\nRegridding catchment.....\n") config = self.config + model = '' + in_rstfile ='' + if (config['input']['surface']['catchment']['regrid']): + model = 'catch' + in_rstfile = config['input']['surface']['catchment']['rst_file'] + elif (config['input']['surface']['catchcnclm40']['regrid']): + model = 'catchcnclm40' + in_rstfile = config['input']['surface']['catchcnclm40']['rst_file'] + elif (config['input']['surface']['catchcnclm45']['regrid']): + model = 'catchcnclm45' + in_rstfile = config['input']['surface']['catchcnclm45']['rst_file'] + if model == '': + return + + bindir = os.getcwd() + in_bcsdir = config['input']['shared']['bcs_dir'] out_bcsdir = config['output']['shared']['bcs_dir'] out_dir = config['output']['shared']['out_dir'] + expid = config['output']['shared']['expid'] + in_wemin = config['input']['surface']['wemin'] + out_wemin = config['output']['surface']['wemin'] + surflay = config['output']['surface']['surflay'] + in_tilefile = config['input']['surface']['tile_file'] + out_tilefile = config['output']['surface']['tile_file'] + account = config['slurm']['account'] + yyyymmddhh_= str(config['input']['shared']['yyyymmddhh']) + suffix = yyyymmddhh_[0:8]+'_'+yyyymmddhh_[8:10]+'z.nc4' + + if (expid) : + expid = expid + '.' + else: + expid = '' + suffix = '_rst.' + suffix + out_rstfile = expid + os.path.basename(in_rstfile).split('_rst')[0].split('.')[-1]+suffix + if not os.path.exists(out_dir) : os.makedirs(out_dir) print( "cd " + out_dir) os.chdir(out_dir) - InData_dir = out_dir+'/InData/' - if os.path.exists(InData_dir) : subprocess.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]) - print ("mkdir " + OutData_dir) - os.makedirs(OutData_dir) - - rst_dir = config['input']['surface']['rst_dir'] - if (not rst_dir): rst_dir = config['input']['shared']['rst_dir'] - restarts_in = glob.glob(rst_dir +'surface/*') - yyyymmddhh_ = str(config['input']['shared']['yyyymmddhh']) - suffix = yyyymmddhh_[0:8]+'_'+yyyymmddhh_[8:10]+'z.nc4' - if (not restarts_in) : - # from merra-2 - restarts_in = glob.glob(rst_dir +'/*catch*') - if restarts_in[0].find('z.bin') != -1 : suffix = yyyymmddhh_[0:8]+'_'+yyyymmddhh_[8:10]+'z.bin' - - def find_rst(rsts,rst_name): - for rst in rsts: - f = os.path.basename(rst) - if (f.find(rst_name) != -1): - return rst - return None - catch = find_rst(restarts_in,'catch_') - if (not catch) : - print(" No catchment restart") - return - - catch_f = os.path.basename(catch) - dest = InData_dir+'/'+ catch_f + if not os.path.exists(InData_dir) : + print ("mkdir " + InData_dir) + os.makedirs(InData_dir) + + f = os.path.basename(in_rstfile) + dest = InData_dir+'/'+f if os.path.exists(dest) : shutil.remove(dest) - print('\nCopy ' + catch + ' to ' +dest) - shutil.copy(catch , dest) - - in_tile_file = glob.glob(in_bcsdir+ '/*-Pfafstetter.til')[0] - out_tile_file = glob.glob(out_bcsdir+ '/*-Pfafstetter.til')[0] - - in_til = InData_dir+'/' + in_tile_file.split('/')[-1] - out_til = OutData_dir+'/'+ out_tile_file.split('/')[-1] - - if os.path.exists(in_til) : shutil.remove(in_til) - if os.path.exists(out_til) : shutil.remove(out_til) - print('\n Copy ' + in_tile_file + ' to ' + in_til) - shutil.copy(in_tile_file, in_til) - print('\n Copy ' + out_tile_file + ' to ' + out_til) - shutil.copy(out_tile_file, out_til) - + # file got copy because the computing node cannot access archive + print('\nCopy ' + rst + ' to ' +dest) + shutil.copy(rst,dest) + in_rstfile = dest + mk_catch_j_template = """#!/bin/csh -f #SBATCH --account={account} -#SBATCH --ntasks=84 +#SBATCH --ntasks=56 #SBATCH --time=1:00:00 #SBATCH --job-name=mk_catch #SBATCH --qos=debug @@ -88,87 +84,31 @@ def find_rst(rsts,rst_name): source {Bin}/g5_modules set echo -#limit stacksize unlimited -unlimit +limit stacksize unlimited -set esma_mpirun_X = ( {Bin}/esma_mpirun -np 84 ) -set mk_CatchRestarts_X = ( $esma_mpirun_X {Bin}/mk_CatchRestarts ) -set Scale_Catch_X = {Bin}/Scale_Catch +set esma_mpirun_X = ( {Bin}/esma_mpirun -np 56 ) +set mk_CatchmentRestarts_X = ( {Bin}/mk_CatchmentRestarts.x ) -set catchIN = InData/{catch_f} -set params = ( {out_til} {in_til} $catchIN {surflay} ) -$mk_CatchRestarts_X $params +set params = ( -model {model} -time {time} -in_tilefile {in_tilefile} ) +set params = ( $params -out_bcs {out_bcs} -out_tilefile {out_tilefile} -out_dir {out_dir} ) +set params = ( $params -surflay {surflay} -in_wemin {in_wemin} -out_wemin {out_wemin} ) +set params = ( $params -in_rst {in_rstfile} -out_rst {out_rstfile} ) +$esma_mpirun_X $mk_CatchmentRestarts_X $params -if ({rescale}) then - - set catch_regrid = OutData/{catch_f} - set catch_scaled = $catch_regrid.scaled - set params = ( $catchIN $catch_regrid $catch_scaled {surflay} ) - set params = ( $params {wemin} {wemout} ) - $Scale_Catch_X $params - - rm $catch_regrid - #mv $catch_regrid $catch_regrid.1 - mv $catch_scaled $catch_regrid -endif """ - # step 1 - expid = config['output']['shared']['expid'] - wemin = config['input']['surface']['wemin'] - wemout = config['output']['surface']['wemout'] - surflay= config['output']['surface']['surflay'] - account = config['slurm']['account'] - - catch1script = mk_catch_j_template.format(Bin = bindir, account = account, \ - out_dir = out_dir, mk_catch_log = 'mk_catch_log.1', surflay = surflay, \ - wemin = wemin, wemout = wemout, out_til = out_til, in_til = in_til, catch_f = catch_f, rescale = '0') - catch1 = open('mk_catch.j.1','wt') - catch1.write(catch1script) - catch1.close() - print("step 1: sbatch -W mk_catch.j.1") - subprocess.call(['sbatch','-W', 'mk_catch.j.1']) - - # step 2 - if os.path.exists('InData.step1') : subprocess.call(['rm','-rf', 'InData.step1']) - print("\n Move Indata to InData.step1") - shutil.move('InData', 'InData.step1') - os.makedirs('InData') - for catchfile in glob.glob("OutData/*catch*"): - print('\n Move ' + catchfile + ' to InData/') - shutil.move(catchfile,"InData/") - print('\n Link ' + out_til + ' to ' + in_til) - os.symlink(out_til, in_til) - - dirname = os.path.dirname(out_til) - clsm = dirname+'/clsm' - print('\n Link ' + clsm + ' to ' + 'OutData/clsm') - os.symlink(clsm, 'OutData/clsm') + catch1script = mk_catch_j_template.format(Bin = bindir, account = account, out_bcs = out_bcsdir, \ + model = model, out_dir = out_dir, mk_catch_log = 'mk_catch_log', surflay = surflay, \ + 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_ ) - catch2script = mk_catch_j_template.format(Bin = bindir, account = account, \ - out_dir = out_dir, mk_catch_log = 'mk_catch_log.1', surflay = surflay, \ - wemin = wemin, wemout = wemout, out_til = out_til, in_til = in_til, catch_f = catch_f, rescale = '1') + catch_scrpt = open('mk_catchment.j','wt') + catch_scrpt.write(catch1script) + catch_scrpt.close() + print("sbatch -W mk_catchment.j") + subprocess.call(['sbatch','-W', 'mk_catchment.j']) - catch2 = open('mk_catch.j.2','wt') - catch2.write(catch2script) - catch2.close() - print("step 2: sbatch -W mk_catch.j.2") - subprocess.call(['sbatch','-W', 'mk_catch.j.2']) -# -# post process -# - if (expid) : - expid = expid + '.' - else: - expid = '' - suffix = '_rst.' + suffix - for out_rst in glob.glob("OutData/*_rst*"): - filename = expid + os.path.basename(out_rst).split('_rst')[0].split('.')[-1]+suffix - print('\n Move ' + out_rst + ' to ' + out_dir+"/"+filename) - shutil.move(out_rst, out_dir+"/"+filename) os.chdir(bindir) if __name__ == '__main__' : catch = catchment('regrid_params.yaml') catch.regrid() - - diff --git a/GEOS_Util/post/regrid_py/regrid_lake_landice_saltwater.py b/GEOS_Util/post/regrid_py/regrid_lake_landice_saltwater.py index 875c0521..940cf835 100755 --- a/GEOS_Util/post/regrid_py/regrid_lake_landice_saltwater.py +++ b/GEOS_Util/post/regrid_py/regrid_lake_landice_saltwater.py @@ -83,7 +83,7 @@ def find_rst(rsts,rst_name): print('\n Copy ' + out_tile_file + ' to ' + out_til) shutil.copy(out_tile_file, out_til) - exe = bindir + '/mk_LakeLandiceSaltRestarts ' + exe = bindir + '/mk_LakeLandiceSaltRestarts.x ' zoom = config['output']['surface']['zoom'] if (saltwater): @@ -94,7 +94,7 @@ def find_rst(rsts,rst_name): # split Saltwater if config['output']['surface']['split_saltwater']: print("\nSplitting Saltwater...\n") - cmd = bindir+'/SaltIntSplitter ' + out_til + ' ' + 'OutData/' + saltwater + cmd = bindir+'/SaltIntSplitter.x ' + out_til + ' ' + 'OutData/' + saltwater print('\n'+cmd) subprocess.call(shlex.split(cmd)) openwater = None @@ -121,7 +121,7 @@ def find_rst(rsts,rst_name): subprocess.call(shlex.split(cmd)) if (route): - route = bindir + '/mk_RouteRestarts ' + route = bindir + '/mk_RouteRestarts.x ' cmd = route + out_til + ' ' + yyyymmddhh_[0:6] print('\n'+cmd) subprocess.call(shlex.split(cmd)) diff --git a/GEOS_Util/post/regrid_py/regrid_params.py b/GEOS_Util/post/regrid_py/regrid_params.py index 6462ca0b..4513bc98 100755 --- a/GEOS_Util/post/regrid_py/regrid_params.py +++ b/GEOS_Util/post/regrid_py/regrid_params.py @@ -261,8 +261,7 @@ def init_merra2(self): print("\nMERRA-2 sources:\n") yyyymm = int(self.yyyymm) if yyyymm < 197901 : - print("Error. MERRA-2 data < 1979 not available\n") - exit() + exit("Error. MERRA-2 data < 1979 not available\n") elif (yyyymm < 199201): self.common_in['expid'] = "d5124_m2_jan79" elif (yyyymm < 200106): @@ -356,8 +355,7 @@ def get_bcdir(self, opt): bcdir = bc_base+'/Ganymed/'+model+'/' if not os.path.exists(bcdir): - print( "Cannot find bc dir " + bcdir) - exit() + exit("Cannot find bc dir " + bcdir) gridStr = self.get_grid_subdir(bcdir,opt) bcdir = bcdir + '/' + gridStr @@ -403,8 +401,7 @@ def get_name_with_grid( grid, names): anames = get_name_with_grid(agrid_, dirnames) gridID = get_name_with_grid(ogrid_, anames) if len(gridID) == 0 : - print("cannot find the grid string: " + bcdir) - exit() + exit("cannot find the grid string: " + bcdir) if len(gridID) >=2 : print("find too may grid strings in " + bcdir) print(" gridIDs found", gridID) @@ -430,7 +427,7 @@ def params_for_air(self, config_tpl): fvrst = os.path.dirname(os.path.realpath(__file__)) + '/fvrst.x -h ' if not self.common_in.get('MERRA-2'): fvcore = '' - for f in self.restarts_in: + for f in self.restarts_in['UPPERAIR']: if 'fvcore' in f: fvcore = f break @@ -469,20 +466,32 @@ def options_for_slurm(self, config_tpl): def params_for_surface(self, config_tpl): config_tpl['output']['surface']['surflay'] = 20. - config_tpl['output']['surface']['rescale'] = False tagout = self.common_out['tag'] ogrid = self.common_out['ogrid'] bctag = self.get_bcTag(tagout, ogrid) tagrank = self.tagsRank[bctag] if tagrank >=12 : config_tpl['output']['surface']['surflay'] = 50. - if tagrank > self.tagsRank["Fortuna-2_0"]: - config_tpl['output']['surface']['rescale'] = True if tagrank >= self.tagsRank["Icarus_Reynolds"]: config_tpl['output']['surface']['split_saltwater'] = True config_tpl['output']['surface']['zoom']= self.surf_in['zoom'] - config_tpl['output']['surface']['wemin']= self.surf_in['wemin'] - config_tpl['output']['surface']['wemout']= self.surf_out['wemout'] + config_tpl['input']['surface']['wemin']= self.surf_in['wemin'] + config_tpl['output']['surface']['wemin']= self.surf_out['wemout'] + config_tpl['output']['surface']['tile_file']= self.out_til + config_tpl['input']['surface']['tile_file']= self.in_til + + for f in self.restarts_in['SURFACE'] : + fname = os.path.basename(f) + if fname.find('catch_') != -1 : + config_tpl['input']['surface']['catchment']['regrid'] = True + config_tpl['input']['surface']['catchment']['rst_file'] = f + elif fname.find('catchcnclm40_') != -1 : + config_tpl['input']['surface']['catchcnclm40']['regrid'] = True + config_tpl['input']['surface']['catchcnclm40']['rst_file'] = f + elif fname.find('catchcnclm45_') != -1 : + config_tpl['input']['surface']['catchcnclm45']['regrid'] = True + config_tpl['input']['surface']['catchcnclm45']['rst_file'] = f + return config_tpl def params_for_analysis(self, config_tpl): diff --git a/GEOS_Util/post/regrid_py/regrid_params.tpl b/GEOS_Util/post/regrid_py/regrid_params.tpl index 45f318fa..916b87dd 100644 --- a/GEOS_Util/post/regrid_py/regrid_params.tpl +++ b/GEOS_Util/post/regrid_py/regrid_params.tpl @@ -25,18 +25,19 @@ input: surface: wemin: rst_dir: null - catchCNclm40: + tile_file: null + catchcnclm40: regrid: false - rst_dir: null - catchCNclm45: + rst_file: null + catchcnclm45: regrid: false - rst_dir: null + rst_file: null catchment: regrid: false - rst_dir: null + rst_file: null lakelandice: regrid: false - rst_dir: null + rst_file: null output: shared: @@ -50,9 +51,9 @@ output: surface: zoom: split_saltwater: false - rescale: true surflay: 20. - wemout: + wemin: + tile_file: none analysis: bkg: true aqua: False diff --git a/GEOS_Util/post/regrid_py/regrid_questions.py b/GEOS_Util/post/regrid_py/regrid_questions.py index 66d3321d..5fa6037c 100755 --- a/GEOS_Util/post/regrid_py/regrid_questions.py +++ b/GEOS_Util/post/regrid_py/regrid_questions.py @@ -24,9 +24,7 @@ def ask_common_in(): { "type": "path", "name": "rst_dir", - "message": "Enter the directory with restart files to be regrided: \n \ - restart files should be distributed under subdirectories \n \ - upperair, surface, analysis", + "message": "Enter the directory with restart files to be regrided: \n restart files should be distributed under subdirectories \n upperair, surface, analysis", "when": lambda x: not x["MERRA-2"], }, { diff --git a/GEOS_Util/post/regrid_py/regrid_upper.py b/GEOS_Util/post/regrid_py/regrid_upper.py index 0fedee48..b449238e 100755 --- a/GEOS_Util/post/regrid_py/regrid_upper.py +++ b/GEOS_Util/post/regrid_py/regrid_upper.py @@ -78,8 +78,7 @@ def regrid(self): if agrid[0].upper() == 'C': imout = int(agrid[1:]) else: - print("Only support cs grid so far") - exit() + exit("Only support cs grid so far") if (imout <=90): NPE = 12; nwrit = 1 From 8951d1929bbd5ce7935a80e13bbe49674b790d5f Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Wed, 4 May 2022 09:02:36 -0400 Subject: [PATCH 28/70] refactor copyfile and mkdir --- GEOS_Util/post/regrid_py/regrid_catchment.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/GEOS_Util/post/regrid_py/regrid_catchment.py b/GEOS_Util/post/regrid_py/regrid_catchment.py index 8151de69..0de6c517 100755 --- a/GEOS_Util/post/regrid_py/regrid_catchment.py +++ b/GEOS_Util/post/regrid_py/regrid_catchment.py @@ -59,18 +59,17 @@ def regrid(self): if not os.path.exists(out_dir) : os.makedirs(out_dir) print( "cd " + out_dir) os.chdir(out_dir) + InData_dir = out_dir+'/InData/' - if not os.path.exists(InData_dir) : - print ("mkdir " + InData_dir) - os.makedirs(InData_dir) + print ("mkdir -p" + InData_dir) + os.makedirs(InData_dir, exist_ok = True) f = os.path.basename(in_rstfile) dest = InData_dir+'/'+f - if os.path.exists(dest) : shutil.remove(dest) - # file got copy because the computing node cannot access archive - print('\nCopy ' + rst + ' to ' +dest) - shutil.copy(rst,dest) - in_rstfile = dest + # file got copy because the computing node cannot access archive + print('\nCopy ' + rst + ' to ' +dest) + shutil.copyfile(rst,dest) + in_rstfile = dest mk_catch_j_template = """#!/bin/csh -f #SBATCH --account={account} From 0c67623ca6d6dd0fd8d0dd45040d7a1a541ba843 Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Fri, 6 May 2022 16:38:19 -0400 Subject: [PATCH 29/70] rename catchment --- GEOS_Util/post/regrid_py/regrid.py | 6 +++--- ...{regrid_catchment.py => regrid_catchANDcn.py} | 16 ++++++++-------- 2 files changed, 11 insertions(+), 11 deletions(-) rename GEOS_Util/post/regrid_py/{regrid_catchment.py => regrid_catchANDcn.py} (90%) diff --git a/GEOS_Util/post/regrid_py/regrid.py b/GEOS_Util/post/regrid_py/regrid.py index 9bb97cec..6739bc9b 100644 --- a/GEOS_Util/post/regrid_py/regrid.py +++ b/GEOS_Util/post/regrid_py/regrid.py @@ -12,7 +12,7 @@ from regrid_upper import * from regrid_lake_landice_saltwater import * from regrid_analysis import * -from regrid_catchment import * +from regrid_catchANDcn import * def main(argv): config_yaml = '' @@ -50,8 +50,8 @@ def main(argv): lls = lake_landice_saltwater(config_yaml) lls.regrid() - # catchment - catch = catchment(config_yaml) + # catchANDcn + catch = catchANDcn(config_yaml) catch.regrid() # analysis diff --git a/GEOS_Util/post/regrid_py/regrid_catchment.py b/GEOS_Util/post/regrid_py/regrid_catchANDcn.py similarity index 90% rename from GEOS_Util/post/regrid_py/regrid_catchment.py rename to GEOS_Util/post/regrid_py/regrid_catchANDcn.py index 0de6c517..af67e1dd 100755 --- a/GEOS_Util/post/regrid_py/regrid_catchment.py +++ b/GEOS_Util/post/regrid_py/regrid_catchANDcn.py @@ -8,7 +8,7 @@ import ruamel.yaml import shlex -class catchment(object): +class catchANDcn(object): def __init__(self, params_file): yaml = ruamel.yaml.YAML() stream ='' @@ -17,7 +17,7 @@ def __init__(self, params_file): self.config = yaml.load(stream) def regrid(self): - print("\nRegridding catchment.....\n") + print("\nRegridding catchment or catchmentCN.....\n") config = self.config model = '' in_rstfile ='' @@ -86,13 +86,13 @@ def regrid(self): limit stacksize unlimited set esma_mpirun_X = ( {Bin}/esma_mpirun -np 56 ) -set mk_CatchmentRestarts_X = ( {Bin}/mk_CatchmentRestarts.x ) +set mk_catchANDcnRestarts_X = ( {Bin}/mk_catchANDcnRestarts.x ) set params = ( -model {model} -time {time} -in_tilefile {in_tilefile} ) set params = ( $params -out_bcs {out_bcs} -out_tilefile {out_tilefile} -out_dir {out_dir} ) set params = ( $params -surflay {surflay} -in_wemin {in_wemin} -out_wemin {out_wemin} ) set params = ( $params -in_rst {in_rstfile} -out_rst {out_rstfile} ) -$esma_mpirun_X $mk_CatchmentRestarts_X $params +$esma_mpirun_X $mk_catchANDcnRestarts_X $params """ catch1script = mk_catch_j_template.format(Bin = bindir, account = account, out_bcs = out_bcsdir, \ @@ -100,14 +100,14 @@ def regrid(self): 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_ ) - catch_scrpt = open('mk_catchment.j','wt') + catch_scrpt = open('mk_catchANDcn.j','wt') catch_scrpt.write(catch1script) catch_scrpt.close() - print("sbatch -W mk_catchment.j") - subprocess.call(['sbatch','-W', 'mk_catchment.j']) + print("sbatch -W mk_catchANDcn.j") + subprocess.call(['sbatch','-W', 'mk_catchANDcn.j']) os.chdir(bindir) if __name__ == '__main__' : - catch = catchment('regrid_params.yaml') + catch = catchANDcn('regrid_params.yaml') catch.regrid() From 81fddbe1545e2420a0fdc062ed9512e1b7c14d72 Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Tue, 17 May 2022 09:14:01 -0400 Subject: [PATCH 30/70] add import --- GEOS_Util/post/regrid_py/regrid_params.py | 1 + 1 file changed, 1 insertion(+) diff --git a/GEOS_Util/post/regrid_py/regrid_params.py b/GEOS_Util/post/regrid_py/regrid_params.py index 4513bc98..a3bd728f 100755 --- a/GEOS_Util/post/regrid_py/regrid_params.py +++ b/GEOS_Util/post/regrid_py/regrid_params.py @@ -5,6 +5,7 @@ import shutil import glob import time +import subprocess import questionary from datetime import datetime from datetime import timedelta From b46bff8a7f736334662fa32bfc9b4db60b0666c9 Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Tue, 17 May 2022 10:32:15 -0400 Subject: [PATCH 31/70] import shlex --- GEOS_Util/post/regrid_py/regrid_params.py | 1 + 1 file changed, 1 insertion(+) diff --git a/GEOS_Util/post/regrid_py/regrid_params.py b/GEOS_Util/post/regrid_py/regrid_params.py index a3bd728f..fb61a400 100755 --- a/GEOS_Util/post/regrid_py/regrid_params.py +++ b/GEOS_Util/post/regrid_py/regrid_params.py @@ -5,6 +5,7 @@ import shutil import glob import time +import shlex import subprocess import questionary from datetime import datetime From f5a5c807afa7e0223fc69ce1df7196ab1400841a Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Tue, 17 May 2022 20:58:38 -0400 Subject: [PATCH 32/70] add '/' to dir --- GEOS_Util/post/regrid_py/regrid_params.py | 27 ++++++++++++----------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/GEOS_Util/post/regrid_py/regrid_params.py b/GEOS_Util/post/regrid_py/regrid_params.py index fb61a400..26e4daca 100755 --- a/GEOS_Util/post/regrid_py/regrid_params.py +++ b/GEOS_Util/post/regrid_py/regrid_params.py @@ -45,15 +45,15 @@ def __init__(self, config_from_question): # params for shared config_tpl['input']['shared']['agrid'] = self.common_in['agrid'] config_tpl['input']['shared']['ogrid'] = self.common_in['ogrid'] - config_tpl['input']['shared']['bcs_dir'] = self.in_bcsdir - config_tpl['input']['shared']['rst_dir'] = self.common_in['rst_dir'] + config_tpl['input']['shared']['bcs_dir'] = self.in_bcsdir+ '/' + config_tpl['input']['shared']['rst_dir'] = self.common_in['rst_dir']+'/' config_tpl['input']['shared']['expid'] = self.common_in['expid'] config_tpl['input']['shared']['yyyymmddhh'] = self.common_in['yyyymmddhh'] config_tpl['output']['shared']['agrid'] = self.common_out['agrid'] config_tpl['output']['shared']['ogrid'] = self.common_out['ogrid'] - config_tpl['output']['shared']['bcs_dir'] = self.out_bcsdir - config_tpl['output']['shared']['out_dir'] = self.common_out['out_dir'] + config_tpl['output']['shared']['bcs_dir'] = self.out_bcsdir + '/' + config_tpl['output']['shared']['out_dir'] = self.common_out['out_dir'] + '/' config_tpl['output']['shared']['expid'] = self.common_out['expid'] # params for upper air @@ -284,17 +284,18 @@ def init_merra2(self): print('\nMERRA-2 Restart dir: ' + self.common_in['rst_dir'] +'\n') self.restarts_in = {} - upperin =[self.common_in['rst_dir']+ expid+'.fvcore_internal_rst.' + surfix, - self.common_in['rst_dir']+ expid+'.moist_internal_rst.' + surfix, - self.common_in['rst_dir']+ expid+'.agcm_import_rst.' + surfix, - self.common_in['rst_dir']+ expid+'.gocart_internal_rst.' + surfix, - self.common_in['rst_dir']+ expid+'.pchem_internal_rst.' + surfix ] + rst_dir = self.common_in['rst_dir'] + upperin =[rst_dir + expid+'.fvcore_internal_rst.' + surfix, + rst_dir + expid+'.moist_internal_rst.' + surfix, + rst_dir + expid+'.agcm_import_rst.' + surfix, + rst_dir + expid+'.gocart_internal_rst.' + surfix, + rst_dir + expid+'.pchem_internal_rst.' + surfix ] self.restarts_in['UPPERAIR'] = upperin - surfin = [self.common_in['rst_dir']+ expid+'.catch_internal_rst.' + surfix, - self.common_in['rst_dir']+ expid+'.lake_internal_rst.' + surfix, - self.common_in['rst_dir']+ expid+'.landice_internal_rst.' + surfix, - self.common_in['rst_dir']+ expid+'.saltwater_internal_rst.'+ surfix] + surfin = [ rst_dir + expid+'.catch_internal_rst.' + surfix, + rst_dir + expid+'.lake_internal_rst.' + surfix, + rst_dir + expid+'.landice_internal_rst.' + surfix, + rst_dir + expid+'.saltwater_internal_rst.'+ surfix] self.restarts_in['SURFACE'] = surfin self.restarts_in['ANALYSIS'] = [] From cf4adba75a7732966c869ab5207c3c32d15ed28a Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Wed, 18 May 2022 12:53:05 -0400 Subject: [PATCH 33/70] fix bug searching bc sub directories --- GEOS_Util/post/regrid_py/regrid_catchANDcn.py | 4 +-- GEOS_Util/post/regrid_py/regrid_params.py | 31 ++++++++++++------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/GEOS_Util/post/regrid_py/regrid_catchANDcn.py b/GEOS_Util/post/regrid_py/regrid_catchANDcn.py index af67e1dd..44e0fa18 100755 --- a/GEOS_Util/post/regrid_py/regrid_catchANDcn.py +++ b/GEOS_Util/post/regrid_py/regrid_catchANDcn.py @@ -67,8 +67,8 @@ def regrid(self): f = os.path.basename(in_rstfile) dest = InData_dir+'/'+f # file got copy because the computing node cannot access archive - print('\nCopy ' + rst + ' to ' +dest) - shutil.copyfile(rst,dest) + print('\nCopy ' + in_rstfile + ' to ' +dest) + shutil.copyfile(in_rstfile,dest) in_rstfile = dest mk_catch_j_template = """#!/bin/csh -f diff --git a/GEOS_Util/post/regrid_py/regrid_params.py b/GEOS_Util/post/regrid_py/regrid_params.py index 26e4daca..a913988c 100755 --- a/GEOS_Util/post/regrid_py/regrid_params.py +++ b/GEOS_Util/post/regrid_py/regrid_params.py @@ -367,7 +367,7 @@ def get_bcdir(self, opt): def get_grid_subdir(self, bcdir, opt): - def get_name_with_grid( grid, names): + def get_name_with_grid( grid, names, a_o): if not grid : return names namex = [] @@ -378,18 +378,25 @@ def get_name_with_grid( grid, names): s2 =str(n) s3 =str(j) # first try - for name in names: - if (name.find(s1) != -1): - namex.append(name) - if len(namex) ==0: - for name in names: - if (name.find(s2) != -1 and name.find(s3) != -1): namex.append(name) + for aoname in names: + name = '' + if(a_o == 'a'): + name = aoname.split('_')[0] + else: + name = aoname.split('_')[1] + if (name.find(s1) != -1 or (name.find(s2) != -1 and name.find(s3) != -1 )): + namex.append(aoname) else: xy = grid.upper().split('X') s2 = xy[0] s3 = xy[1] - for name in names: - if (name.find(s2) != -1 and name.find(s3) != -1): namex.append(name) + for aoname in names: + name = '' + if(a_o == 'a'): + name = aoname.split('_')[0] + else + name = aoname.split('_')[1] + if (name.find(s2) != -1 and name.find(s3) != -1): namex.append(aoname) return namex #v3.5 #dirnames = [ f.name for f in os.scandir(bcdir) if f.is_dir()] @@ -401,12 +408,12 @@ def get_name_with_grid( grid, names): agrid_ = self.common_out['agrid'] ogrid_ = self.common_out['ogrid'] - anames = get_name_with_grid(agrid_, dirnames) - gridID = get_name_with_grid(ogrid_, anames) + anames = get_name_with_grid(agrid_, dirnames, 'a') + gridID = get_name_with_grid(ogrid_, anames, 'o') if len(gridID) == 0 : exit("cannot find the grid string: " + bcdir) if len(gridID) >=2 : - print("find too may grid strings in " + bcdir) + print("find too many grid strings in " + bcdir) print(" gridIDs found", gridID) print(" pick the first one " + gridID[0]) return gridID[0] From cd59b6c094d321245bbe86611e1914ef2bf1fa76 Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Wed, 18 May 2022 14:17:06 -0400 Subject: [PATCH 34/70] typo fix --- GEOS_Util/post/regrid_py/regrid_params.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GEOS_Util/post/regrid_py/regrid_params.py b/GEOS_Util/post/regrid_py/regrid_params.py index a913988c..b091c635 100755 --- a/GEOS_Util/post/regrid_py/regrid_params.py +++ b/GEOS_Util/post/regrid_py/regrid_params.py @@ -394,7 +394,7 @@ def get_name_with_grid( grid, names, a_o): name = '' if(a_o == 'a'): name = aoname.split('_')[0] - else + else: name = aoname.split('_')[1] if (name.find(s2) != -1 and name.find(s3) != -1): namex.append(aoname) return namex From f98c4444849a4ce90899dde5e725dc992cb6d02a Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Wed, 18 May 2022 14:51:49 -0400 Subject: [PATCH 35/70] fine tpl from differnt directory --- GEOS_Util/post/regrid_py/regrid_params.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/GEOS_Util/post/regrid_py/regrid_params.py b/GEOS_Util/post/regrid_py/regrid_params.py index b091c635..f39c391c 100755 --- a/GEOS_Util/post/regrid_py/regrid_params.py +++ b/GEOS_Util/post/regrid_py/regrid_params.py @@ -38,7 +38,8 @@ def __init__(self, config_from_question): # load input yaml yaml = ruamel.yaml.YAML() stream = '' - with open('regrid_params.tpl', 'r') as f: + regrid_tpl = os.path.dirname(os.path.realpath(__file__)) + '/regrid_params.tpl' + with open(regrid_tpl, 'r') as f: stream = f.read() config_tpl = yaml.load(stream) From 2369fed81f8c42f66f6c8beec67c14ac189a4190 Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Wed, 18 May 2022 23:15:40 -0400 Subject: [PATCH 36/70] remove extra '.' --- GEOS_Util/post/regrid_py/regrid_analysis.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GEOS_Util/post/regrid_py/regrid_analysis.py b/GEOS_Util/post/regrid_py/regrid_analysis.py index 775353fb..fb9356b8 100755 --- a/GEOS_Util/post/regrid_py/regrid_analysis.py +++ b/GEOS_Util/post/regrid_py/regrid_analysis.py @@ -117,7 +117,7 @@ def regrid(self): local_fs=[] for f in anafiles: fname = os.path.basename(f) - out_name = fname.replace(expid_in, expid_out) + out_name = fname.replace(expid_in + '.', expid_out) f_tmp = tmpdir+'/'+out_name local_fs.append(f_tmp) shutil.copy(f,f_tmp) From 334717b5c5b1c1687a18169015d210e6de4d218c Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Tue, 24 May 2022 23:48:35 -0400 Subject: [PATCH 37/70] all restart files are in one directory. meera2 passes --- GEOS_Util/post/regrid_py/regrid_analysis.py | 79 ++---- GEOS_Util/post/regrid_py/regrid_catchANDcn.py | 13 +- .../regrid_lake_landice_saltwater.py | 70 +++--- GEOS_Util/post/regrid_py/regrid_params.py | 230 +++++++++++++----- GEOS_Util/post/regrid_py/regrid_questions.py | 47 ++-- GEOS_Util/post/regrid_py/regrid_upper.py | 72 ++++-- 6 files changed, 323 insertions(+), 188 deletions(-) diff --git a/GEOS_Util/post/regrid_py/regrid_analysis.py b/GEOS_Util/post/regrid_py/regrid_analysis.py index fb9356b8..8f3eea23 100755 --- a/GEOS_Util/post/regrid_py/regrid_analysis.py +++ b/GEOS_Util/post/regrid_py/regrid_analysis.py @@ -28,13 +28,13 @@ def regrid(self): bkg = config['output']['analysis']['bkg'] if ( not bkg ): return - agrid_in = config['input']['shared']['agrid'] - agrid_out = config['output']['shared']['agrid'] - - if (self.get_grid_kind(agrid_in.upper()) == self.get_grid_kind(agrid_out.upper())): - print(" No need to regrid anaylysis file") + analysis_in = self.find_analysis() + if len(analysis_in) ==0 : + print("\n There are no analysis files. \n") return + print("\n Regrid or copy analysis files...\n") + bindir = os.getcwd() in_bcsdir = config['input']['shared']['bcs_dir'] out_bcsdir = config['output']['shared']['bcs_dir'] @@ -51,9 +51,6 @@ def regrid(self): print( "cd " + tmpdir) os.chdir(tmpdir) - rst_dir_orig = config['input']['analysis']['rst_dir'] - if (not rst_dir_orig): rst_dir_orig = config['input']['shared']['rst_dir'] - anafiles = glob.glob(rst_dir_orig +'/analysis/*') yyyymmddhh_ = str(config['input']['shared']['yyyymmddhh']) yyyy_ = yyyymmddhh_[0:4] mm_ = yyyymmddhh_[4:6] @@ -67,55 +64,10 @@ def regrid(self): else: expid_out = '' - if len(anafiles) == 0 : - anafiles=[] - for h in [3,4,5,6,7,8,9]: - delt = timedelta(hours = h-3) - new_time = rst_time + delt - yyyy = "Y"+str(new_time.year) - mm = 'M%02d'%new_time.month - ymd = '%04d%02d%02d'%(new_time.year,new_time.month, new_time.day) - hh = '%02d'%h - newhh= '%02d'%new_time.hour - rst_dir = rst_dir_orig.replace('Y'+yyyy_,yyyy).replace('M'+mm_,mm) - # bkg files - for ftype in ['sfc', 'eta']: - fname = expid_in+'.bkg'+hh+'_'+ftype+'_rst.'+ymd+'_'+newhh+'z.nc4' - f = rst_dir+'/'+fname - if(os.path.isfile(f)): - anafiles.append(f) - else: - print('Warning: Cannot find '+f) - - # cbkg file - fname = expid_in + '.cbkg' + hh + '_eta_rst.' + ymd + '_' + newhh + 'z.nc4' - f = rst_dir+'/'+fname - if(os.path.isfile(f)): - anafiles.append(f) - else: - print('Warning: Cannot find '+f) - # gaas_bkg_sfc files - if (h==6 or h==9): - fname = expid_in+'.gaas_bkg_sfc_rst.'+ymd+'_'+newhh+'z.nc4' - f = rst_dir+'/'+fname - if (os.path.isfile(f)): - anafiles.append(f) - else: - print('Warning: Cannot find '+f) - # trak.GDA.rst file - delt = timedelta(hours = 3) - new_time = rst_time - delt - yyyy = "Y"+str(new_time.year) - mm = 'M%02d'%new_time.month - ymdh = '%04d%02d%02d%02d'%(new_time.year, new_time.month, new_time.day, new_time.hour) - rst_dir = rst_dir_orig.replace('Y'+yyyy_,yyyy).replace('M'+mm_,mm) - fname = expid_in+'.trak.GDA.rst.'+ymdh+'z.txt' - f = rst_dir+'/'+fname - if (os.path.isfile(f)): anafiles.append(f) - aqua = config['output']['analysis']['aqua'] local_fs=[] - for f in anafiles: + for f in analysis_in: + print(f) fname = os.path.basename(f) out_name = fname.replace(expid_in + '.', expid_out) f_tmp = tmpdir+'/'+out_name @@ -123,14 +75,11 @@ def regrid(self): shutil.copy(f,f_tmp) if out_name.find('satbias') != -1 : if (aqua): - f_orig = f_tmp+'.orig' - shutil.move(f_tmp, f_orig) f_ = open(f_tmp, 'w') - for line in fileinput.input(f_orig): + for line in fileinput.input(f): f_.write(line.replace('airs281SUBSET_aqua', 'airs281_aqua ')) f_.close() - nlevel = config['output']['air']['nlevel'] flags = "-g5 -res " + self.get_grid_kind(agrid_out.upper()) + " -nlevs " + str(nlevel) bkg_files = glob.glob(tmpdir+'/*.bkg??_eta_rst*') @@ -140,6 +89,7 @@ def regrid(self): cmd = bindir + '/dyn2dyn.x ' + flags + ' -o ' + f + ' ' + f_orig print(cmd) subprocess.call(shlex.split(cmd)) + for f in local_fs: fname = os.path.basename(f) shutil.move(f, out_dir+'/'+fname) @@ -153,6 +103,7 @@ def regrid(self): cmd = bindir+'/mkdrstdate.x ' + ymd_ + ' ' + hms_ +' ' + rstlcvOut print(cmd) subprocess.call(shlex.split(cmd)) + print( "cd " + bindir) os.chdir(bindir) def get_grid_kind(this, grid): @@ -172,6 +123,16 @@ def get_grid_kind(this, grid): hgrd['C5760'] = 'e' return hgrd[grid] + def find_analysis(self): + analysis_in = [] + rst_dir = self.config['input']['analysis']['rst_dir'] + if (not rst_dir): rst_dir = self.config['input']['shared']['rst_dir'] + bkgs = glob.glob(rst_dir + '/*_eta_rst*') + sfcs = glob.glob(rst_dir + '/*_sfc_rst*') + traks= glob.glob(rst_dir + '/*.trak.GDA.rst*') + analysis_in = bkgs + sfcs + traks + return analysis_in + if __name__ == '__main__' : ana = analysis('regrid_params.yaml') ana.regrid() diff --git a/GEOS_Util/post/regrid_py/regrid_catchANDcn.py b/GEOS_Util/post/regrid_py/regrid_catchANDcn.py index 44e0fa18..d401060d 100755 --- a/GEOS_Util/post/regrid_py/regrid_catchANDcn.py +++ b/GEOS_Util/post/regrid_py/regrid_catchANDcn.py @@ -17,7 +17,6 @@ def __init__(self, params_file): self.config = yaml.load(stream) def regrid(self): - print("\nRegridding catchment or catchmentCN.....\n") config = self.config model = '' in_rstfile ='' @@ -33,6 +32,7 @@ def regrid(self): if model == '': return + print("\nRegridding " + model + ".....\n") bindir = os.getcwd() @@ -47,6 +47,7 @@ def regrid(self): out_tilefile = config['output']['surface']['tile_file'] account = config['slurm']['account'] yyyymmddhh_= str(config['input']['shared']['yyyymmddhh']) + # even the input is binary, the output si nc4 suffix = yyyymmddhh_[0:8]+'_'+yyyymmddhh_[8:10]+'z.nc4' if (expid) : @@ -70,14 +71,15 @@ def regrid(self): print('\nCopy ' + in_rstfile + ' to ' +dest) shutil.copyfile(in_rstfile,dest) in_rstfile = dest - + model_log = 'mk_'+model+'_log' + mk_catch_j_template = """#!/bin/csh -f #SBATCH --account={account} #SBATCH --ntasks=56 #SBATCH --time=1:00:00 -#SBATCH --job-name=mk_catch +#SBATCH --job-name=mk_{model} #SBATCH --qos=debug -#SBATCH --output={out_dir}/{mk_catch_log} +#SBATCH --output={out_dir}/{mk_log} # source {Bin}/g5_modules @@ -96,7 +98,7 @@ def regrid(self): """ catch1script = mk_catch_j_template.format(Bin = bindir, account = account, out_bcs = out_bcsdir, \ - model = model, out_dir = out_dir, mk_catch_log = 'mk_catch_log', surflay = surflay, \ + model = model, out_dir = out_dir, mk_log = model_log, surflay = surflay, \ 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_ ) @@ -106,6 +108,7 @@ def regrid(self): print("sbatch -W mk_catchANDcn.j") subprocess.call(['sbatch','-W', 'mk_catchANDcn.j']) + print( "cd " + bindir) os.chdir(bindir) if __name__ == '__main__' : diff --git a/GEOS_Util/post/regrid_py/regrid_lake_landice_saltwater.py b/GEOS_Util/post/regrid_py/regrid_lake_landice_saltwater.py index 940cf835..b2fec6d3 100755 --- a/GEOS_Util/post/regrid_py/regrid_lake_landice_saltwater.py +++ b/GEOS_Util/post/regrid_py/regrid_lake_landice_saltwater.py @@ -16,12 +16,17 @@ def __init__(self, params_file): self.config = yaml.load(stream) def regrid(self): + restarts_in = self.find_rst() + if len(restarts_in) == 0: + return + print("\nRegridding land, landice, saltwater.....\n") config = self.config bindir = os.getcwd() in_bcsdir = config['input']['shared']['bcs_dir'] out_bcsdir = config['output']['shared']['bcs_dir'] out_dir = config['output']['shared']['out_dir'] + if not os.path.exists(out_dir) : os.makedirs(out_dir) print( "cd " + out_dir) os.chdir(out_dir) @@ -36,45 +41,36 @@ def regrid(self): print ("mkdir " + OutData_dir) os.makedirs(OutData_dir) - rst_dir = config['input']['surface']['rst_dir'] - if (not rst_dir): rst_dir = config['input']['shared']['rst_dir'] - restarts_in = glob.glob(rst_dir +'surface/*') + types = 'z.bin' + type_str = subprocess.check_output(['file','-b', restarts_in[0]]) + type_str = str(type_str) + if 'Hierarchical' in type_str: + types = 'z.nc4' yyyymmddhh_ = str(config['input']['shared']['yyyymmddhh']) - suffix = yyyymmddhh_[0:8]+'_'+yyyymmddhh_[8:10]+'z.nc4' - if (not restarts_in) : - expid = config['input']['shared']['expid'] - suffix = yyyymmddhh_[0:8]+'_'+yyyymmddhh_[8:10]+'z.bin' - # from merra-2 - restarts_in = [rst_dir + expid + '.lake_internal_rst.' + suffix, - rst_dir + expid + '.landice_internal_rst.' + suffix, - rst_dir + expid + '.saltwater_internal_rst.'+ suffix] - - def find_rst(rsts,rst_name): - for rst in rsts: - f = os.path.basename(rst) - if (f.find(rst_name) != -1): - return f - return None - - saltwater = find_rst(restarts_in,'saltwater') - openwater = find_rst(restarts_in,'openwater') - seaice = find_rst(restarts_in,'seaice') - landice = find_rst(restarts_in,'landice') - lake = find_rst(restarts_in,'lake') - route = find_rst(restarts_in,'route') + suffix = yyyymmddhh_[0:8]+'_'+yyyymmddhh_[8:10]+ types + saltwater = '' + seaice = '' + landice = '' + lake = '' + route = '' for rst in restarts_in: f = os.path.basename(rst) dest = InData_dir+'/'+f if os.path.exists(dest) : shutil.remove(dest) print('\nCopy ' + rst + ' to ' +dest) shutil.copy(rst,dest) + if 'saltwater' in f : saltwater = f + if 'seaice' in f : seaice = f + if 'landice' in f : landice = f + if 'lake' in f : lake = f + if 'roue' in f : route = f in_tile_file = glob.glob(in_bcsdir+ '/*-Pfafstetter.til')[0] out_tile_file = glob.glob(out_bcsdir+ '/*-Pfafstetter.til')[0] - in_til = InData_dir+'/' + in_tile_file.split('/')[-1] - out_til = OutData_dir+'/'+ out_tile_file.split('/')[-1] + in_til = InData_dir+'/' + os.path.basename(in_tile_file) + out_til = OutData_dir+'/'+ os.path.basename(out_tile_file) if os.path.exists(in_til) : shutil.remove(in_til) if os.path.exists(out_til) : shutil.remove(out_til) @@ -136,9 +132,27 @@ def find_rst(rsts,rst_name): filename = expid + os.path.basename(out_rst).split('_rst')[0].split('.')[-1]+suffix print('\n Move ' + out_rst + ' to ' + out_dir+"/"+filename) shutil.move(out_rst, out_dir+"/"+filename) + print('cd ' + bindir) os.chdir(bindir) + def find_rst(self): + surf_restarts =[ + "route_internal_rst" , + "lake_internal_rst" , + "landice_internal_rst" , + "openwater_internal_rst" , + "saltwater_internal_rst" , + "seaicethermo_internal_rst"] + + rst_dir = self.config['input']['air']['rst_dir'] + if (not rst_dir): rst_dir = self.config['input']['shared']['rst_dir'] + restarts_in=[] + for f in surf_restarts : + files = glob.glob(rst_dir+ '/*'+f+'*') + if len(files) >0: + restarts_in.append(files[0]) + return restarts_in + if __name__ == '__main__' : lls = lake_landice_saltwater('regrid_params.yaml') lls.regrid() - diff --git a/GEOS_Util/post/regrid_py/regrid_params.py b/GEOS_Util/post/regrid_py/regrid_params.py index f39c391c..c8573cbb 100755 --- a/GEOS_Util/post/regrid_py/regrid_params.py +++ b/GEOS_Util/post/regrid_py/regrid_params.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -import os +import os,sys import ruamel.yaml import shutil import glob @@ -25,7 +25,6 @@ def __init__(self, config_from_question): self.init_time() self.init_tags() self.init_merra2() - self.init_restarts_in() # get bc directory and tile file self.in_bcsdir = self.get_bcdir("IN") @@ -44,11 +43,11 @@ def __init__(self, config_from_question): config_tpl = yaml.load(stream) # params for shared - config_tpl['input']['shared']['agrid'] = self.common_in['agrid'] - config_tpl['input']['shared']['ogrid'] = self.common_in['ogrid'] + config_tpl['input']['shared']['agrid'] = self.common_in.get('agrid') + config_tpl['input']['shared']['ogrid'] = self.common_in.get('ogrid') config_tpl['input']['shared']['bcs_dir'] = self.in_bcsdir+ '/' config_tpl['input']['shared']['rst_dir'] = self.common_in['rst_dir']+'/' - config_tpl['input']['shared']['expid'] = self.common_in['expid'] + config_tpl['input']['shared']['expid'] = self.common_in.get('expid') config_tpl['input']['shared']['yyyymmddhh'] = self.common_in['yyyymmddhh'] config_tpl['output']['shared']['agrid'] = self.common_out['agrid'] @@ -248,17 +247,24 @@ def init_time(self): self.hh = yyyymmddhh[8:10] self.ymd = yyyymmddhh[0:8] - def init_restarts_in(self): - if self.common_in['MERRA-2']: - return - - rst_dir = self.common_in.get('rst_dir')+'/' - self.restarts_in={} - self.restarts_in['UPPERAIR'] = glob.glob(rst_dir +'upperair/*') - self.restarts_in['SURFACE'] = glob.glob(rst_dir +'surface/*') - self.restarts_in['ANALYSIS'] = glob.glob(rst_dir +'analysis/*') - def init_merra2(self): + def get_grid_kind(grid): + hgrd = {} + hgrd['C12'] = 'a' + hgrd['C24'] = 'a' + hgrd['C48'] = 'b' + hgrd['C90'] = 'c' + hgrd['C180'] = 'd' + hgrd['C360'] = 'd' + hgrd['C500'] = 'd' + hgrd['C720'] = 'e' + hgrd['C1000'] = 'e' + hgrd['C1440'] = 'e' + hgrd['C2000'] = 'e' + hgrd['C2880'] = 'e' + hgrd['C5760'] = 'e' + return hgrd[grid] + if not self.common_in['MERRA-2']: return print("\nMERRA-2 sources:\n") @@ -279,26 +285,105 @@ def init_merra2(self): self.common_in['bc_base']= 'discover_ops' self.common_in['tag']= 'Ganymed-4_0' expid = self.common_in['expid'] - yyyymmddhh = str(self.common_in['yyyymmddhh']) - surfix = yyyymmddhh[0:8]+'_'+self.hh+'z.bin' - self.common_in['rst_dir'] = '/archive/users/gmao_ops/MERRA2/gmao_ops/GEOSadas-5_12_4/'+expid +'/rs/Y'+self.yyyy +'/M'+self.mm+'/' - print('\nMERRA-2 Restart dir: ' + self.common_in['rst_dir'] +'\n') - - self.restarts_in = {} - rst_dir = self.common_in['rst_dir'] - upperin =[rst_dir + expid+'.fvcore_internal_rst.' + surfix, - rst_dir + expid+'.moist_internal_rst.' + surfix, - rst_dir + expid+'.agcm_import_rst.' + surfix, - rst_dir + expid+'.gocart_internal_rst.' + surfix, - rst_dir + expid+'.pchem_internal_rst.' + surfix ] - self.restarts_in['UPPERAIR'] = upperin - - surfin = [ rst_dir + expid+'.catch_internal_rst.' + surfix, - rst_dir + expid+'.lake_internal_rst.' + surfix, - rst_dir + expid+'.landice_internal_rst.' + surfix, - rst_dir + expid+'.saltwater_internal_rst.'+ surfix] - self.restarts_in['SURFACE'] = surfin - self.restarts_in['ANALYSIS'] = [] + yyyymmddhh_ = str(self.common_in['yyyymmddhh']) + surfix = yyyymmddhh_[0:8]+'_'+self.hh+'z.bin' + merra_2_rst_dir = '/archive/users/gmao_ops/MERRA2/gmao_ops/GEOSadas-5_12_4/'+expid +'/rs/Y'+self.yyyy +'/M'+self.mm+'/' + rst_dir = self.common_in['rst_dir'] + '/' + os.makedirs(rst_dir, exist_ok = True) + print('\n Copy MERRA-2 Restart \n from \n' + merra_2_rst_dir + '\n to \n '+ rst_dir +'\n') + + upperin =[merra_2_rst_dir + expid+'.fvcore_internal_rst.' + surfix, + merra_2_rst_dir + expid+'.moist_internal_rst.' + surfix, + merra_2_rst_dir + expid+'.agcm_import_rst.' + surfix, + merra_2_rst_dir + expid+'.gocart_internal_rst.' + surfix, + merra_2_rst_dir + expid+'.pchem_internal_rst.' + surfix ] + + surfin = [ merra_2_rst_dir + expid+'.catch_internal_rst.' + surfix, + merra_2_rst_dir + expid+'.lake_internal_rst.' + surfix, + merra_2_rst_dir + expid+'.landice_internal_rst.' + surfix, + merra_2_rst_dir + expid+'.saltwater_internal_rst.'+ surfix] + + for f in upperin : + fname = os.path.basename(f) + dest = rst_dir + '/'+fname + shutil.copy(f, dest) + + for f in surfin : + fname = os.path.basename(f) + dest = rst_dir + '/'+fname + shutil.copy(f, dest) + + # prepare analysis files + bkg = self.ana_out['bkg'] + if ( not bkg ): return + yyyy_ = yyyymmddhh_[0:4] + mm_ = yyyymmddhh_[4:6] + dd_ = yyyymmddhh_[6:8] + hh_ = yyyymmddhh_[8:10] + rst_time = datetime(year=int(yyyy_), month=int(mm_), day=int(dd_), hour = int(hh_)) + expid_in = self.common_in['expid'] + expid_out = self.common_out['expid'] + if (expid_out) : + expid_out = expid_out + '.' + else: + expid_out = '' + + agrid_in = self.common_in['agrid'] + agrid_out = self.common_out['agrid'] + + if (get_grid_kind(agrid_in.upper()) == get_grid_kind(agrid_out.upper())): + print(" No need to regrid anaylysis file according to air grid in and out") + return + + anafiles=[] + for h in [3,4,5,6,7,8,9]: + delt = timedelta(hours = h-3) + new_time = rst_time + delt + yyyy = "Y"+str(new_time.year) + mm = 'M%02d'%new_time.month + ymd = '%04d%02d%02d'%(new_time.year,new_time.month, new_time.day) + hh = '%02d'%h + newhh= '%02d'%new_time.hour + m2_rst_dir = merra_2_rst_dir.replace('Y'+yyyy_,yyyy).replace('M'+mm_,mm) + # bkg files + for ftype in ['sfc', 'eta']: + fname = expid_in+'.bkg'+hh+'_'+ftype+'_rst.'+ymd+'_'+newhh+'z.nc4' + f = m2_rst_dir+'/'+fname + if(os.path.isfile(f)): + anafiles.append(f) + else: + print('Warning: Cannot find '+f) + # cbkg file + fname = expid_in + '.cbkg' + hh + '_eta_rst.' + ymd + '_' + newhh + 'z.nc4' + f = m2_rst_dir+'/'+fname + if(os.path.isfile(f)): + anafiles.append(f) + else: + print('Warning: Cannot find '+f) + # gaas_bkg_sfc files + if (h==6 or h==9): + fname = expid_in+'.gaas_bkg_sfc_rst.'+ymd+'_'+newhh+'z.nc4' + f = m2_rst_dir+'/'+fname + if (os.path.isfile(f)): + anafiles.append(f) + else: + print('Warning: Cannot find '+f) + # trak.GDA.rst file + delt = timedelta(hours = 3) + new_time = rst_time - delt + yyyy = "Y"+str(new_time.year) + mm = 'M%02d'%new_time.month + ymdh = '%04d%02d%02d%02d'%(new_time.year, new_time.month, new_time.day, new_time.hour) + m2_rst_dir = merra_2_rst_dir.replace('Y'+yyyy_,yyyy).replace('M'+mm_,mm) + fname = expid_in+'.trak.GDA.rst.'+ymdh+'z.txt' + f = m2_rst_dir+'/'+fname + if (os.path.isfile(f)): anafiles.append(f) + + for f in anafiles: + fname = os.path.basename(f) + f_tmp = rst_dir+'/'+fname + print("Copy file "+f +" to " + rst_dir) + shutil.copy(f,f_tmp) def get_bcbase(self, opt): base = '' @@ -433,29 +518,32 @@ def get_bcTag(self, tag, ogrid): return bctag def params_for_air(self, config_tpl): + if self.common_in['MERRA-2']: + return config_tpl # verify agrid - agrid = config_tpl['input']['shared']['agrid'] - fvrst = os.path.dirname(os.path.realpath(__file__)) + '/fvrst.x -h ' - if not self.common_in.get('MERRA-2'): - fvcore = '' - for f in self.restarts_in['UPPERAIR']: - if 'fvcore' in f: - fvcore = f - break - cmd = fvrst + fvcore - print(cmd +'\n') - p = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE) - (output, err) = p.communicate() - p_status = p.wait() - ss = output.decode().split() - if (agrid): - if agrid[0].upper() == "C": - n=int(agrid[1:]) - o=int(ss[0]) - assert n==o, "input agrid is not consistent with fvcore restart" - else: - config_tpl['input']['shared']['agrid'] = "C"+ss[0] + rst_dir = self.common_in['rst_dir'] + '/' + files = glob.glob(rst_dir + '*fvcore_*') + if len(files) ==0 : + return config_tpl + # get expid + fname = os.path.basename(files[0]) + expid = fname.split('fvcore')[0] + config_tpl['input']['shared']['expid'] = expid[0:-1] #remove the last '.' + fvrst = os.path.dirname(os.path.realpath(__file__)) + '/fvrst.x -h ' + cmd = fvrst + files[0] + print(cmd +'\n') + p = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE) + (output, err) = p.communicate() + p_status = p.wait() + ss = output.decode().split() + config_tpl['input']['shared']['agrid'] = "C"+ss[0] + config_tpl['input']['shared']['nlevel'] = ss[2] + lat = int(ss[0]) + lon = int(ss[1]) + if (lon != lat*6) : + sys.exit('This is not a cubed-sphere grid fvcore restart. Please contact SI team') + ogrid = config_tpl['input']['shared']['ogrid'] tagout = self.common_out['tag'] bctag = self.get_bcTag(tagout, ogrid) @@ -491,18 +579,20 @@ def params_for_surface(self, config_tpl): config_tpl['output']['surface']['tile_file']= self.out_til config_tpl['input']['surface']['tile_file']= self.in_til - for f in self.restarts_in['SURFACE'] : - fname = os.path.basename(f) - if fname.find('catch_') != -1 : + rst_dir = self.common_in['rst_dir'] + '/' + files = glob.glob(rst_dir + '*catch_*') + if (len(files) > 0) : config_tpl['input']['surface']['catchment']['regrid'] = True - config_tpl['input']['surface']['catchment']['rst_file'] = f - elif fname.find('catchcnclm40_') != -1 : + config_tpl['input']['surface']['catchment']['rst_file'] = files[0] + files = glob.glob(rst_dir + '*catchcnclm40_*') + if (len(files) > 0) : config_tpl['input']['surface']['catchcnclm40']['regrid'] = True - config_tpl['input']['surface']['catchcnclm40']['rst_file'] = f - elif fname.find('catchcnclm45_') != -1 : + config_tpl['input']['surface']['catchcnclm40']['rst_file'] = files[0] + files = glob.glob(rst_dir + '*catchcnclm45_*') + if (len(files) > 0) : config_tpl['input']['surface']['catchcnclm45']['regrid'] = True - config_tpl['input']['surface']['catchcnclm45']['rst_file'] = f - + config_tpl['input']['surface']['catchcnclm45']['rst_file'] = files[0] + return config_tpl def params_for_analysis(self, config_tpl): @@ -516,4 +606,12 @@ def params_for_analysis(self, config_tpl): if tagrank >= self.tagsRank["Ganymed-4_0_Reynolds"] : config_tpl['output']['analysis']['aqua'] = True return 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) + param = regrid_params(config) + param.convert_to_yaml() diff --git a/GEOS_Util/post/regrid_py/regrid_questions.py b/GEOS_Util/post/regrid_py/regrid_questions.py index 5fa6037c..ee7c3e3d 100755 --- a/GEOS_Util/post/regrid_py/regrid_questions.py +++ b/GEOS_Util/post/regrid_py/regrid_questions.py @@ -9,9 +9,19 @@ import os import subprocess import shlex -import yaml +import ruamel.yaml import shutil import questionary +import glob + +def has_fvcore(x): + files = glob.glob(x['rst_dir']+'/*fvcore_*') + if len(files) ==1 : + return True + else: + print('False') + return False + def ask_common_in(): questions = [ @@ -24,21 +34,21 @@ def ask_common_in(): { "type": "path", "name": "rst_dir", - "message": "Enter the directory with restart files to be regrided: \n restart files should be distributed under subdirectories \n upperair, surface, analysis", - "when": lambda x: not x["MERRA-2"], + "message": "Enter the directory with restart files to be regrided: \n If it is MERRA-2, files from achives will be copied to this directory. \n", }, { "type": "text", "name": "yyyymmddhh", "message": "What time would you like to regrid from?(yyyymmddhh)", - "default": "2000041421" + "default": "2000041421", }, { "type": "text", - "name": "expid", - "message": "Enter input restarts expid:", - "default": "", - "when": lambda x: not x["MERRA-2"], + "name": "agrid", + "message": "Enter input atmospheric grid, format(Cxxx):", + "default": 'C360', + # if it is merra-2 or has_fvcore, agrid is deduced + "when": lambda x: not x['MERRA-2'] and not has_fvcore(x), }, { "type": "select", @@ -46,14 +56,17 @@ def ask_common_in(): "message": "Select ocean model:", "choices": ["data", "MOM5", "MOM6"], "default": "data", + "when": lambda x: not x['MERRA-2'] }, { "type": "text", - "name": "agrid", - "message": "Enter input atmospheric grid, format(Cxxx):", - "default": 'C360', - "when": lambda x: not x['MERRA-2'], + "name": "nlevel", + "message": "Enter input atmospheric grid leve:", + "default": '72', + # if it is merra-2 or has_fvcore, nlevel is deduced + "when": lambda x: not x['MERRA-2'] and not has_fvcore(x), }, + { "type": "select", "name": "ogrid", @@ -65,7 +78,7 @@ def ask_common_in(): 2880X1440 (OSTIA) \n \ CS = same as atmospere grid (OSTIA cubed-sphere) \n", "choices": ['360X180','1440X720','2880X1440','CS'], - "when": lambda x: x['model'] == 'data' and not x['MERRA-2'], + "when": lambda x: x.get('model') == 'data' and not x['MERRA-2'], }, { "type": "select", @@ -78,7 +91,7 @@ def ask_common_in(): 720X410 \n \ 1440X1080 \n ", "choices": ['72X36','360X200','720X410','1440X1080'], - "when": lambda x: x['model'] != 'data', + "when": lambda x: x.get('model') == 'MOM5' or x.get('model')== 'MOM6' }, { "type": "text", @@ -134,6 +147,8 @@ def ask_common_in(): common_in = questionary.prompt(questions) if common_in.get('ogrid') == 'CS': common_in['ogrid'] = common_in['agrid'] + if not common_in.get('model') : + common_in['model'] = 'data' return common_in def ask_common_out(): @@ -372,3 +387,7 @@ def get_config_from_questionary(): if __name__ == "__main__": config = get_config_from_questionary() + yaml = ruamel.yaml.YAML() + with open("raw_answers.yaml", "w") as f: + yaml.dump(config, f) + diff --git a/GEOS_Util/post/regrid_py/regrid_upper.py b/GEOS_Util/post/regrid_py/regrid_upper.py index b449238e..4e7a1b74 100755 --- a/GEOS_Util/post/regrid_py/regrid_upper.py +++ b/GEOS_Util/post/regrid_py/regrid_upper.py @@ -16,12 +16,17 @@ def __init__(self, params_file): self.config = yaml.load(stream) def regrid(self): + restarts_in = self.find_rst() + if len(restarts_in) == 0: + return + print( "\nRegridding upper air......\n") config = self.config bindir = os.getcwd() in_bcsdir = config['input']['shared']['bcs_dir'] out_bcsdir = config['output']['shared']['bcs_dir'] out_dir = config['output']['shared']['out_dir'] + if not os.path.exists(out_dir) : os.makedirs(out_dir) print( "cd " + out_dir) os.chdir(out_dir) @@ -33,23 +38,17 @@ def regrid(self): print( "cd " + tmpdir) os.chdir(tmpdir) - print('\nUpper air restart files should end with "_rst" \n') - rst_dir = config['input']['air']['rst_dir'] - if (not rst_dir): rst_dir = config['input']['shared']['rst_dir'] - restarts_in = glob.glob(rst_dir +'upperair/*') - yyyymmddhh_ = str(config['input']['shared']['yyyymmddhh']) - suffix = yyyymmddhh_[0:8]+'_'+yyyymmddhh_[8:10]+'z.nc4' - if (not restarts_in) : - expid = config['input']['shared']['expid'] - suffix = yyyymmddhh_[0:8]+'_'+yyyymmddhh_[8:10]+'z.bin' - # from merra-2 - restarts_in =[rst_dir + expid+'.fvcore_internal_rst.' + suffix, - rst_dir + expid+'.moist_internal_rst.' + suffix, - rst_dir + expid+'.agcm_import_rst.' + suffix, - rst_dir + expid+'.gocart_internal_rst.' + suffix, - rst_dir + expid+'.pchem_internal_rst.' + suffix ] + print('\nUpper air restart file names changed from "_rst" to "_restart_in" \n') + types = 'z.bin' + type_str = subprocess.check_output(['file','-b', restarts_in[0]]) + type_str = str(type_str) + if type_str.find('Hierarchical') >=0: + types = 'z.nc4' + yyyymmddhh_ = str(config['input']['shared']['yyyymmddhh']) + suffix = yyyymmddhh_[0:8]+'_'+yyyymmddhh_[8:10]+ types + for rst in restarts_in : fs = os.path.basename(rst).split('.') f = fs[0] @@ -193,10 +192,10 @@ def regrid(self): upper.close() print('sbatch -W regridder_upper.j\n') subprocess.call(['sbatch', '-W', 'regridder_upper.j']) + # # post process # - expid = config['output']['shared']['expid'] if (expid) : expid = expid + '.' @@ -207,4 +206,45 @@ def regrid(self): filename = expid + os.path.basename(out_rst).split('_rst')[0].split('.')[-1]+suffix print('\n Move ' + out_rst + ' to ' + out_dir+"/"+filename) shutil.move(out_rst, out_dir+"/"+filename) + + print('\n Move regridder_upper.j to ' + out_dir) + shutil.move('regridder_upper.j', out_dir+"/regridder_upper.j") + print('cd ' + bindir) os.chdir(bindir) + + def find_rst(self): + air_restarts =["fvcore_internal_rst" , + "moist_internal_rst" , + "agcm_import_rst" , + "agcm_internal_rst" , + "carma_internal_rst" , + "geosachem_internal_rst" , + "geoschemchem_internal_rst", + "gmichem_internal_rst" , + "gocart_internal_rst" , + "hemco_internal_rst" , + "mam_internal_rst" , + "matrix_internal_rst" , + "pchem_internal_rst" , + "stratchem_internal_rst" , + "ss_internal_rst" , + "du_internal_rst" , + "cabr_internal_rst" , + "cabc_internal_rst" , + "caoc_internal_rst" , + "ni_internal_rst" , + "su_internal_rst" , + "tr_internal_rst"] + + rst_dir = self.config['input']['air']['rst_dir'] + if (not rst_dir): rst_dir = self.config['input']['shared']['rst_dir'] + restarts_in=[] + for f in air_restarts : + files = glob.glob(rst_dir+ '/*'+f+'*') + if len(files) >0: + restarts_in.append(files[0]) + return restarts_in + +if __name__ == '__main__' : + air = upperair('regrid_params.yaml') + air.regrid() From 5f7f34799b8b8dafe9a1db3f384e91a1af489e66 Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Wed, 25 May 2022 13:55:33 -0400 Subject: [PATCH 38/70] test f522_fp --- GEOS_Util/post/regrid_py/regrid_analysis.py | 3 +- .../regrid_lake_landice_saltwater.py | 6 ++-- GEOS_Util/post/regrid_py/regrid_params.py | 34 +++++++++++-------- GEOS_Util/post/regrid_py/regrid_params.tpl | 1 - GEOS_Util/post/regrid_py/regrid_questions.py | 10 ------ 5 files changed, 25 insertions(+), 29 deletions(-) diff --git a/GEOS_Util/post/regrid_py/regrid_analysis.py b/GEOS_Util/post/regrid_py/regrid_analysis.py index 8f3eea23..c9b08d20 100755 --- a/GEOS_Util/post/regrid_py/regrid_analysis.py +++ b/GEOS_Util/post/regrid_py/regrid_analysis.py @@ -80,7 +80,8 @@ def regrid(self): f_.write(line.replace('airs281SUBSET_aqua', 'airs281_aqua ')) f_.close() - nlevel = config['output']['air']['nlevel'] + nlevel = config['output']['air']['nlevel'] + agrid_out = config['output']['shared']['agrid'] flags = "-g5 -res " + self.get_grid_kind(agrid_out.upper()) + " -nlevs " + str(nlevel) bkg_files = glob.glob(tmpdir+'/*.bkg??_eta_rst*') for f in bkg_files: diff --git a/GEOS_Util/post/regrid_py/regrid_lake_landice_saltwater.py b/GEOS_Util/post/regrid_py/regrid_lake_landice_saltwater.py index b2fec6d3..1bd65ccd 100755 --- a/GEOS_Util/post/regrid_py/regrid_lake_landice_saltwater.py +++ b/GEOS_Util/post/regrid_py/regrid_lake_landice_saltwater.py @@ -54,6 +54,7 @@ def regrid(self): landice = '' lake = '' route = '' + openwater = '' for rst in restarts_in: f = os.path.basename(rst) dest = InData_dir+'/'+f @@ -65,6 +66,7 @@ def regrid(self): if 'landice' in f : landice = f if 'lake' in f : lake = f if 'roue' in f : route = f + if 'openwater' in f : openwater = f in_tile_file = glob.glob(in_bcsdir+ '/*-Pfafstetter.til')[0] out_tile_file = glob.glob(out_bcsdir+ '/*-Pfafstetter.til')[0] @@ -93,8 +95,8 @@ def regrid(self): cmd = bindir+'/SaltIntSplitter.x ' + out_til + ' ' + 'OutData/' + saltwater print('\n'+cmd) subprocess.call(shlex.split(cmd)) - openwater = None - seaice = None + openwater = '' + seaice = '' if (openwater): cmd = exe + out_til + ' ' + in_til + ' InData/' + openwater + ' 0 ' + str(zoom) diff --git a/GEOS_Util/post/regrid_py/regrid_params.py b/GEOS_Util/post/regrid_py/regrid_params.py index c8573cbb..3156a020 100755 --- a/GEOS_Util/post/regrid_py/regrid_params.py +++ b/GEOS_Util/post/regrid_py/regrid_params.py @@ -22,17 +22,10 @@ def __init__(self, config_from_question): #self.ana_in = config_from_question['input']['parameters']['ANALYSIS'] self.ana_out = config_from_question['output']['parameters']['ANALYSIS'] - self.init_time() + self.init_time(str(config_from_question['input']['parameters']['COMMON']['yyyymmddhh'])) self.init_tags() self.init_merra2() - # get bc directory and tile file - self.in_bcsdir = self.get_bcdir("IN") - self.in_til = glob.glob(self.in_bcsdir+ '/*-Pfafstetter.til')[0] - print("\ninput tile file: " + self.in_til) - self.out_bcsdir = self.get_bcdir("OUT") - self.out_til = glob.glob(self.out_bcsdir+ '/*-Pfafstetter.til')[0] - print("\noutput tile file: " + self.out_til) # load input yaml yaml = ruamel.yaml.YAML() @@ -45,14 +38,12 @@ def __init__(self, config_from_question): # params for shared config_tpl['input']['shared']['agrid'] = self.common_in.get('agrid') config_tpl['input']['shared']['ogrid'] = self.common_in.get('ogrid') - config_tpl['input']['shared']['bcs_dir'] = self.in_bcsdir+ '/' config_tpl['input']['shared']['rst_dir'] = self.common_in['rst_dir']+'/' config_tpl['input']['shared']['expid'] = self.common_in.get('expid') config_tpl['input']['shared']['yyyymmddhh'] = self.common_in['yyyymmddhh'] config_tpl['output']['shared']['agrid'] = self.common_out['agrid'] config_tpl['output']['shared']['ogrid'] = self.common_out['ogrid'] - config_tpl['output']['shared']['bcs_dir'] = self.out_bcsdir + '/' config_tpl['output']['shared']['out_dir'] = self.common_out['out_dir'] + '/' config_tpl['output']['shared']['expid'] = self.common_out['expid'] @@ -62,6 +53,18 @@ def __init__(self, config_from_question): config_tpl = self.params_for_analysis(config_tpl) config_tpl = self.options_for_slurm(config_tpl) + # get bc directory and tile file + in_bcsdir = self.get_bcdir("IN") + in_til = glob.glob(in_bcsdir+ '/*-Pfafstetter.til')[0] + print("\ninput tile file: " + in_til) + out_bcsdir = self.get_bcdir("OUT") + out_til = glob.glob(out_bcsdir+ '/*-Pfafstetter.til')[0] + print("\noutput tile file: " + out_til) + config_tpl['input']['shared']['bcs_dir'] = in_bcsdir+ '/' + config_tpl['output']['shared']['bcs_dir'] = out_bcsdir + '/' + config_tpl['output']['surface']['tile_file']= out_til + config_tpl['input']['surface']['tile_file'] = in_til + self.config = config_tpl def convert_to_yaml(self) : @@ -238,8 +241,7 @@ def init_tags(self): self.bcbase['discover_lt'] = "/discover/nobackup/ltakacs/bcs" self.bcbase['discover_couple'] = "/discover/nobackup/projects/gmao/ssd/aogcm/atmosphere_bcs" - def init_time(self): - yyyymmddhh = str(self.common_in['yyyymmddhh']) + def init_time(self, yyyymmddhh): self.yyyymm = yyyymmddhh[0:6] self.yyyy = yyyymmddhh[0:4] self.mm = yyyymmddhh[4:6] @@ -538,7 +540,11 @@ def params_for_air(self, config_tpl): p_status = p.wait() ss = output.decode().split() config_tpl['input']['shared']['agrid'] = "C"+ss[0] - config_tpl['input']['shared']['nlevel'] = ss[2] + self.common_in['agrid'] = config_tpl['input']['shared']['agrid'] + if self.common_in['ogrid'] == 'CS' : + config_tpl['input']['shared']['ogrid'] = "C"+ss[0] + self.common_in['ogrid'] = config_tpl['input']['shared']['agrid'] + lat = int(ss[0]) lon = int(ss[1]) if (lon != lat*6) : @@ -576,8 +582,6 @@ def params_for_surface(self, config_tpl): config_tpl['output']['surface']['zoom']= self.surf_in['zoom'] config_tpl['input']['surface']['wemin']= self.surf_in['wemin'] config_tpl['output']['surface']['wemin']= self.surf_out['wemout'] - config_tpl['output']['surface']['tile_file']= self.out_til - config_tpl['input']['surface']['tile_file']= self.in_til rst_dir = self.common_in['rst_dir'] + '/' files = glob.glob(rst_dir + '*catch_*') diff --git a/GEOS_Util/post/regrid_py/regrid_params.tpl b/GEOS_Util/post/regrid_py/regrid_params.tpl index 916b87dd..43cb29bb 100644 --- a/GEOS_Util/post/regrid_py/regrid_params.tpl +++ b/GEOS_Util/post/regrid_py/regrid_params.tpl @@ -11,7 +11,6 @@ input: air: drymass: 1 hydrostatic: 0 - nlevel: rst_dir: null analysis: rst_dir: null diff --git a/GEOS_Util/post/regrid_py/regrid_questions.py b/GEOS_Util/post/regrid_py/regrid_questions.py index ee7c3e3d..610a7712 100755 --- a/GEOS_Util/post/regrid_py/regrid_questions.py +++ b/GEOS_Util/post/regrid_py/regrid_questions.py @@ -58,14 +58,6 @@ def ask_common_in(): "default": "data", "when": lambda x: not x['MERRA-2'] }, - { - "type": "text", - "name": "nlevel", - "message": "Enter input atmospheric grid leve:", - "default": '72', - # if it is merra-2 or has_fvcore, nlevel is deduced - "when": lambda x: not x['MERRA-2'] and not has_fvcore(x), - }, { "type": "select", @@ -145,8 +137,6 @@ def ask_common_in(): }, ] common_in = questionary.prompt(questions) - if common_in.get('ogrid') == 'CS': - common_in['ogrid'] = common_in['agrid'] if not common_in.get('model') : common_in['model'] = 'data' return common_in From 3507b7dbe40e8e29376a463fb9a8a48f863dd2c5 Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Thu, 26 May 2022 10:40:50 -0400 Subject: [PATCH 39/70] more simplification. remove unnecessary items in template --- GEOS_Util/post/regrid_py/regrid_analysis.py | 3 +-- GEOS_Util/post/regrid_py/regrid_catchANDcn.py | 26 +++++++++---------- .../regrid_lake_landice_saltwater.py | 3 +-- GEOS_Util/post/regrid_py/regrid_params.py | 17 ++++-------- GEOS_Util/post/regrid_py/regrid_params.tpl | 19 +------------- GEOS_Util/post/regrid_py/regrid_upper.py | 3 +-- 6 files changed, 21 insertions(+), 50 deletions(-) diff --git a/GEOS_Util/post/regrid_py/regrid_analysis.py b/GEOS_Util/post/regrid_py/regrid_analysis.py index c9b08d20..d9accde9 100755 --- a/GEOS_Util/post/regrid_py/regrid_analysis.py +++ b/GEOS_Util/post/regrid_py/regrid_analysis.py @@ -126,8 +126,7 @@ def get_grid_kind(this, grid): def find_analysis(self): analysis_in = [] - rst_dir = self.config['input']['analysis']['rst_dir'] - if (not rst_dir): rst_dir = self.config['input']['shared']['rst_dir'] + rst_dir = self.config['input']['shared']['rst_dir'] bkgs = glob.glob(rst_dir + '/*_eta_rst*') sfcs = glob.glob(rst_dir + '/*_sfc_rst*') traks= glob.glob(rst_dir + '/*.trak.GDA.rst*') diff --git a/GEOS_Util/post/regrid_py/regrid_catchANDcn.py b/GEOS_Util/post/regrid_py/regrid_catchANDcn.py index d401060d..5a9e29bc 100755 --- a/GEOS_Util/post/regrid_py/regrid_catchANDcn.py +++ b/GEOS_Util/post/regrid_py/regrid_catchANDcn.py @@ -18,18 +18,16 @@ def __init__(self, params_file): def regrid(self): config = self.config - model = '' - in_rstfile ='' - if (config['input']['surface']['catchment']['regrid']): - model = 'catch' - in_rstfile = config['input']['surface']['catchment']['rst_file'] - elif (config['input']['surface']['catchcnclm40']['regrid']): - model = 'catchcnclm40' - in_rstfile = config['input']['surface']['catchcnclm40']['rst_file'] - elif (config['input']['surface']['catchcnclm45']['regrid']): - model = 'catchcnclm45' - in_rstfile = config['input']['surface']['catchcnclm45']['rst_file'] - if model == '': + rst_dir = config['input']['shared']['rst_dir'] + model = config['input']['surface']['catch_model'] + in_rstfile = '' + if model == 'catch' : + in_rstfile = glob.glob(rst_dir+'/*catch_*')[0] + if model == 'catchcnclm40' : + in_rstfile = glob.glob(rst_dir+'/*catchcnclm40_*')[0] + if model == 'catchcnclm45' : + in_rstfile = glob.glob(rst_dir+'/*catchcnclm45_*')[0] + if not in_rstfile: return print("\nRegridding " + model + ".....\n") @@ -43,8 +41,8 @@ def regrid(self): in_wemin = config['input']['surface']['wemin'] out_wemin = config['output']['surface']['wemin'] surflay = config['output']['surface']['surflay'] - in_tilefile = config['input']['surface']['tile_file'] - out_tilefile = config['output']['surface']['tile_file'] + in_tilefile = glob.glob(in_bcsdir+ '/*-Pfafstetter.til')[0] + out_tilefile = glob.glob(out_bcsdir+ '/*-Pfafstetter.til')[0] account = config['slurm']['account'] yyyymmddhh_= str(config['input']['shared']['yyyymmddhh']) # even the input is binary, the output si nc4 diff --git a/GEOS_Util/post/regrid_py/regrid_lake_landice_saltwater.py b/GEOS_Util/post/regrid_py/regrid_lake_landice_saltwater.py index 1bd65ccd..39d1fff9 100755 --- a/GEOS_Util/post/regrid_py/regrid_lake_landice_saltwater.py +++ b/GEOS_Util/post/regrid_py/regrid_lake_landice_saltwater.py @@ -146,8 +146,7 @@ def find_rst(self): "saltwater_internal_rst" , "seaicethermo_internal_rst"] - rst_dir = self.config['input']['air']['rst_dir'] - if (not rst_dir): rst_dir = self.config['input']['shared']['rst_dir'] + rst_dir = self.config['input']['shared']['rst_dir'] restarts_in=[] for f in surf_restarts : files = glob.glob(rst_dir+ '/*'+f+'*') diff --git a/GEOS_Util/post/regrid_py/regrid_params.py b/GEOS_Util/post/regrid_py/regrid_params.py index 3156a020..47887b3e 100755 --- a/GEOS_Util/post/regrid_py/regrid_params.py +++ b/GEOS_Util/post/regrid_py/regrid_params.py @@ -55,15 +55,9 @@ def __init__(self, config_from_question): # get bc directory and tile file in_bcsdir = self.get_bcdir("IN") - in_til = glob.glob(in_bcsdir+ '/*-Pfafstetter.til')[0] - print("\ninput tile file: " + in_til) out_bcsdir = self.get_bcdir("OUT") - out_til = glob.glob(out_bcsdir+ '/*-Pfafstetter.til')[0] - print("\noutput tile file: " + out_til) config_tpl['input']['shared']['bcs_dir'] = in_bcsdir+ '/' config_tpl['output']['shared']['bcs_dir'] = out_bcsdir + '/' - config_tpl['output']['surface']['tile_file']= out_til - config_tpl['input']['surface']['tile_file'] = in_til self.config = config_tpl @@ -586,16 +580,15 @@ def params_for_surface(self, config_tpl): rst_dir = self.common_in['rst_dir'] + '/' files = glob.glob(rst_dir + '*catch_*') if (len(files) > 0) : - config_tpl['input']['surface']['catchment']['regrid'] = True - config_tpl['input']['surface']['catchment']['rst_file'] = files[0] + config_tpl['input']['surface']['catch_model'] = 'catch' + files = glob.glob(rst_dir + '*catchcnclm40_*') if (len(files) > 0) : - config_tpl['input']['surface']['catchcnclm40']['regrid'] = True - config_tpl['input']['surface']['catchcnclm40']['rst_file'] = files[0] + config_tpl['input']['surface']['catch_model'] = 'catchcnclm40' + files = glob.glob(rst_dir + '*catchcnclm45_*') if (len(files) > 0) : - config_tpl['input']['surface']['catchcnclm45']['regrid'] = True - config_tpl['input']['surface']['catchcnclm45']['rst_file'] = files[0] + config_tpl['input']['surface']['catch_model'] = 'catchcnclm45' return config_tpl diff --git a/GEOS_Util/post/regrid_py/regrid_params.tpl b/GEOS_Util/post/regrid_py/regrid_params.tpl index 43cb29bb..42871793 100644 --- a/GEOS_Util/post/regrid_py/regrid_params.tpl +++ b/GEOS_Util/post/regrid_py/regrid_params.tpl @@ -11,9 +11,6 @@ input: air: drymass: 1 hydrostatic: 0 - rst_dir: null - analysis: - rst_dir: null shared: agrid: bcs_dir: @@ -23,20 +20,7 @@ input: yyyymmddhh: surface: wemin: - rst_dir: null - tile_file: null - catchcnclm40: - regrid: false - rst_file: null - catchcnclm45: - regrid: false - rst_file: null - catchment: - regrid: false - rst_file: null - lakelandice: - regrid: false - rst_file: null + catch_model: null output: shared: @@ -52,7 +36,6 @@ output: split_saltwater: false surflay: 20. wemin: - tile_file: none analysis: bkg: true aqua: False diff --git a/GEOS_Util/post/regrid_py/regrid_upper.py b/GEOS_Util/post/regrid_py/regrid_upper.py index 4e7a1b74..86aa15e9 100755 --- a/GEOS_Util/post/regrid_py/regrid_upper.py +++ b/GEOS_Util/post/regrid_py/regrid_upper.py @@ -236,8 +236,7 @@ def find_rst(self): "su_internal_rst" , "tr_internal_rst"] - rst_dir = self.config['input']['air']['rst_dir'] - if (not rst_dir): rst_dir = self.config['input']['shared']['rst_dir'] + rst_dir = self.config['input']['shared']['rst_dir'] restarts_in=[] for f in air_restarts : files = glob.glob(rst_dir+ '/*'+f+'*') From d186bf5c1f97e7579f7c6320809d3d92f28636d9 Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Thu, 26 May 2022 14:16:29 -0400 Subject: [PATCH 40/70] fix some typo and info --- GEOS_Util/post/regrid_py/regrid_catchANDcn.py | 10 ++- GEOS_Util/post/regrid_py/regrid_params.py | 71 ++++++++++++------- GEOS_Util/post/regrid_py/regrid_questions.py | 3 +- GEOS_Util/post/regrid_py/regrid_upper.py | 10 +-- 4 files changed, 57 insertions(+), 37 deletions(-) diff --git a/GEOS_Util/post/regrid_py/regrid_catchANDcn.py b/GEOS_Util/post/regrid_py/regrid_catchANDcn.py index 5a9e29bc..d78f16d0 100755 --- a/GEOS_Util/post/regrid_py/regrid_catchANDcn.py +++ b/GEOS_Util/post/regrid_py/regrid_catchANDcn.py @@ -60,7 +60,7 @@ def regrid(self): os.chdir(out_dir) InData_dir = out_dir+'/InData/' - print ("mkdir -p" + InData_dir) + print ("mkdir -p " + InData_dir) os.makedirs(InData_dir, exist_ok = True) f = os.path.basename(in_rstfile) @@ -69,19 +69,17 @@ def regrid(self): print('\nCopy ' + in_rstfile + ' to ' +dest) shutil.copyfile(in_rstfile,dest) in_rstfile = dest - model_log = 'mk_'+model+'_log' mk_catch_j_template = """#!/bin/csh -f #SBATCH --account={account} #SBATCH --ntasks=56 #SBATCH --time=1:00:00 -#SBATCH --job-name=mk_{model} +#SBATCH --job-name=mk_catchANDcn #SBATCH --qos=debug -#SBATCH --output={out_dir}/{mk_log} +#SBATCH --output={out_dir}/mk_catchANDcn_log # source {Bin}/g5_modules -set echo limit stacksize unlimited @@ -96,7 +94,7 @@ def regrid(self): """ catch1script = mk_catch_j_template.format(Bin = bindir, account = account, out_bcs = out_bcsdir, \ - model = model, out_dir = out_dir, mk_log = model_log, surflay = surflay, \ + model = model, out_dir = out_dir, surflay = surflay, \ 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_ ) diff --git a/GEOS_Util/post/regrid_py/regrid_params.py b/GEOS_Util/post/regrid_py/regrid_params.py index 47887b3e..2b7e5b25 100755 --- a/GEOS_Util/post/regrid_py/regrid_params.py +++ b/GEOS_Util/post/regrid_py/regrid_params.py @@ -22,7 +22,7 @@ def __init__(self, config_from_question): #self.ana_in = config_from_question['input']['parameters']['ANALYSIS'] self.ana_out = config_from_question['output']['parameters']['ANALYSIS'] - self.init_time(str(config_from_question['input']['parameters']['COMMON']['yyyymmddhh'])) + self.init_time() self.init_tags() self.init_merra2() @@ -235,13 +235,32 @@ def init_tags(self): self.bcbase['discover_lt'] = "/discover/nobackup/ltakacs/bcs" self.bcbase['discover_couple'] = "/discover/nobackup/projects/gmao/ssd/aogcm/atmosphere_bcs" - def init_time(self, yyyymmddhh): - self.yyyymm = yyyymmddhh[0:6] - self.yyyy = yyyymmddhh[0:4] - self.mm = yyyymmddhh[4:6] - self.dd = yyyymmddhh[6:8] - self.hh = yyyymmddhh[8:10] - self.ymd = yyyymmddhh[0:8] + def init_time(self): + ymdh = self.common_in.get('yyyymmddhh') + self.agrid_ = '' + if not ymdh: + rst_dir = self.common_in['rst_dir'] + '/' + files = glob.glob(rst_dir + '*fvcore_*') + if len(files) ==0 : + sys.exit("date and time are not provided") + + fvrst = os.path.dirname(os.path.realpath(__file__)) + '/fvrst.x -h ' + cmd = fvrst + files[0] + print(cmd +'\n') + p = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE) + (output, err) = p.communicate() + p_status = p.wait() + ss = output.decode().split() + ymdh = str(ss[3]) + str(ss[4])[0:2] + self.common_in['yyyymmddhh']=ymdh + self.agrid_ = "C"+ss[0] # save for air parameter + + self.yyyymm = ymdh[0:6] + self.yyyy = ymdh[0:4] + self.mm = ymdh[4:6] + self.dd = ymdh[6:8] + self.hh = ymdh[8:10] + self.ymd = ymdh[0:8] def init_merra2(self): def get_grid_kind(grid): @@ -263,7 +282,7 @@ def get_grid_kind(grid): if not self.common_in['MERRA-2']: return - print("\nMERRA-2 sources:\n") + print("\n MERRA-2 sources:\n") yyyymm = int(self.yyyymm) if yyyymm < 197901 : exit("Error. MERRA-2 data < 1979 not available\n") @@ -286,7 +305,7 @@ def get_grid_kind(grid): merra_2_rst_dir = '/archive/users/gmao_ops/MERRA2/gmao_ops/GEOSadas-5_12_4/'+expid +'/rs/Y'+self.yyyy +'/M'+self.mm+'/' rst_dir = self.common_in['rst_dir'] + '/' os.makedirs(rst_dir, exist_ok = True) - print('\n Copy MERRA-2 Restart \n from \n' + merra_2_rst_dir + '\n to \n '+ rst_dir +'\n') + print(' Copy MERRA-2 Restart \n from \n ' + merra_2_rst_dir + '\n to\n '+ rst_dir +'\n') upperin =[merra_2_rst_dir + expid+'.fvcore_internal_rst.' + surfix, merra_2_rst_dir + expid+'.moist_internal_rst.' + surfix, @@ -526,23 +545,25 @@ def params_for_air(self, config_tpl): expid = fname.split('fvcore')[0] config_tpl['input']['shared']['expid'] = expid[0:-1] #remove the last '.' - fvrst = os.path.dirname(os.path.realpath(__file__)) + '/fvrst.x -h ' - cmd = fvrst + files[0] - print(cmd +'\n') - p = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE) - (output, err) = p.communicate() - p_status = p.wait() - ss = output.decode().split() - config_tpl['input']['shared']['agrid'] = "C"+ss[0] - self.common_in['agrid'] = config_tpl['input']['shared']['agrid'] + if not self.agrid_ : + fvrst = os.path.dirname(os.path.realpath(__file__)) + '/fvrst.x -h ' + cmd = fvrst + files[0] + print(cmd +'\n') + p = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE) + (output, err) = p.communicate() + p_status = p.wait() + ss = output.decode().split() + self.agrid_ = "C"+ss[0] + lat = int(ss[0]) + lon = int(ss[1]) + if (lon != lat*6) : + sys.exit('This is not a cubed-sphere grid fvcore restart. Please contact SI team') + config_tpl['input']['shared']['agrid'] = self.agrid_ + self.common_in['agrid'] = self.agrid_ if self.common_in['ogrid'] == 'CS' : - config_tpl['input']['shared']['ogrid'] = "C"+ss[0] - self.common_in['ogrid'] = config_tpl['input']['shared']['agrid'] + config_tpl['input']['shared']['ogrid'] = self.agrid_ + self.common_in['ogrid'] = self.agrid_ - lat = int(ss[0]) - lon = int(ss[1]) - if (lon != lat*6) : - sys.exit('This is not a cubed-sphere grid fvcore restart. Please contact SI team') ogrid = config_tpl['input']['shared']['ogrid'] tagout = self.common_out['tag'] diff --git a/GEOS_Util/post/regrid_py/regrid_questions.py b/GEOS_Util/post/regrid_py/regrid_questions.py index 610a7712..04847090 100755 --- a/GEOS_Util/post/regrid_py/regrid_questions.py +++ b/GEOS_Util/post/regrid_py/regrid_questions.py @@ -40,7 +40,8 @@ def ask_common_in(): "type": "text", "name": "yyyymmddhh", "message": "What time would you like to regrid from?(yyyymmddhh)", - "default": "2000041421", + "default": "", + "when": lambda x: not has_fvcore(x), }, { "type": "text", diff --git a/GEOS_Util/post/regrid_py/regrid_upper.py b/GEOS_Util/post/regrid_py/regrid_upper.py index 86aa15e9..26bcbe1f 100755 --- a/GEOS_Util/post/regrid_py/regrid_upper.py +++ b/GEOS_Util/post/regrid_py/regrid_upper.py @@ -187,11 +187,11 @@ def regrid(self): out_dir = out_dir, out_log = 'regrid_upper_log', drymassFLG = drymassFLG, \ imout = imout, nwrit = nwrit, NPE = NPE, \ QOS = QOS, nlevel = nlevel, hydrostatic = hydrostatic) - upper = open('regridder_upper.j','wt') + upper = open('regrid_upper.j','wt') upper.write(regrid_upper_script) upper.close() - print('sbatch -W regridder_upper.j\n') - subprocess.call(['sbatch', '-W', 'regridder_upper.j']) + print('sbatch -W regrid_upper.j\n') + subprocess.call(['sbatch', '-W', 'regrid_upper.j']) # # post process @@ -207,8 +207,8 @@ def regrid(self): print('\n Move ' + out_rst + ' to ' + out_dir+"/"+filename) shutil.move(out_rst, out_dir+"/"+filename) - print('\n Move regridder_upper.j to ' + out_dir) - shutil.move('regridder_upper.j', out_dir+"/regridder_upper.j") + print('\n Move regrid_upper.j to ' + out_dir) + shutil.move('regrid_upper.j', out_dir+"/regrid_upper.j") print('cd ' + bindir) os.chdir(bindir) From 39af95f573a3422822dd7e31b958639a9dd25b63 Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Fri, 27 May 2022 11:10:19 -0400 Subject: [PATCH 41/70] change name geosachem to achem --- GEOS_Util/post/regrid_py/regrid_upper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GEOS_Util/post/regrid_py/regrid_upper.py b/GEOS_Util/post/regrid_py/regrid_upper.py index 26bcbe1f..aa9fc071 100755 --- a/GEOS_Util/post/regrid_py/regrid_upper.py +++ b/GEOS_Util/post/regrid_py/regrid_upper.py @@ -218,7 +218,7 @@ def find_rst(self): "agcm_import_rst" , "agcm_internal_rst" , "carma_internal_rst" , - "geosachem_internal_rst" , + "achem_internal_rst" , "geoschemchem_internal_rst", "gmichem_internal_rst" , "gocart_internal_rst" , From 85a162b157985568065d9924d452ddbbc8d9a67a Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Tue, 7 Jun 2022 11:40:13 -0400 Subject: [PATCH 42/70] add *ana_satb* --- GEOS_Util/post/regrid_py/regrid_analysis.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/GEOS_Util/post/regrid_py/regrid_analysis.py b/GEOS_Util/post/regrid_py/regrid_analysis.py index d9accde9..177cce9a 100755 --- a/GEOS_Util/post/regrid_py/regrid_analysis.py +++ b/GEOS_Util/post/regrid_py/regrid_analysis.py @@ -129,8 +129,9 @@ def find_analysis(self): rst_dir = self.config['input']['shared']['rst_dir'] bkgs = glob.glob(rst_dir + '/*_eta_rst*') sfcs = glob.glob(rst_dir + '/*_sfc_rst*') + anasat = glob.glob(rst_dir + '/*ana_satb*') traks= glob.glob(rst_dir + '/*.trak.GDA.rst*') - analysis_in = bkgs + sfcs + traks + analysis_in = bkgs + sfcs + traks + anasat return analysis_in if __name__ == '__main__' : From 7388d48da1f6abbac68ee480ad4139f8cc4d26d4 Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Tue, 7 Jun 2022 11:45:00 -0400 Subject: [PATCH 43/70] default zoom to 8 --- GEOS_Util/post/regrid_py/regrid_questions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GEOS_Util/post/regrid_py/regrid_questions.py b/GEOS_Util/post/regrid_py/regrid_questions.py index 04847090..bc3d5439 100755 --- a/GEOS_Util/post/regrid_py/regrid_questions.py +++ b/GEOS_Util/post/regrid_py/regrid_questions.py @@ -273,7 +273,7 @@ def ask_surface_in(common_in): "type": "text", "name": "zoom", "message": "What is value of zoom [1-8]?", - "default": '1' + "default": '8' }, ] return questionary.prompt(questions) From 98e541745a78cbd9f7b5eee6dd99d6cdccdf62f7 Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Tue, 7 Jun 2022 16:40:19 -0400 Subject: [PATCH 44/70] convert relative path to absoulte path for rst_dir, out_dir --- GEOS_Util/post/regrid_py/regrid_questions.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/GEOS_Util/post/regrid_py/regrid_questions.py b/GEOS_Util/post/regrid_py/regrid_questions.py index bc3d5439..8452968d 100755 --- a/GEOS_Util/post/regrid_py/regrid_questions.py +++ b/GEOS_Util/post/regrid_py/regrid_questions.py @@ -133,13 +133,14 @@ def ask_common_in(): { "type": "path", "name": "alt_bcs", - "message": "Specify your own bcs path (do not contain grid info) for restarts: \n ", + "message": "Specify your own bcs absolute path (do not contain grid info) for restarts: \n ", "when": lambda x: x.get("bc_base")=="other", }, ] common_in = questionary.prompt(questions) if not common_in.get('model') : common_in['model'] = 'data' + common_in['rst_dir'] = os.path.abspath(common_in['rst_dir']) return common_in def ask_common_out(): @@ -247,6 +248,7 @@ def ask_common_out(): common_out = questionary.prompt(questions) if common_out.get('ogrid') == 'CS': common_out['ogrid'] = common_out['agrid'] + common_out['out_dir'] = os.path.abspath(common_out['out_dir']) return common_out def ask_upper_out(): From 7b7b10ed4155de4981a21bdbc7cd6444b5174256 Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Wed, 8 Jun 2022 09:57:16 -0400 Subject: [PATCH 45/70] continue polishing 1)interactive node 2) default wemin 3) display more infoR --- GEOS_Util/post/regrid_py/regrid.py | 30 ++++++++++++++-- GEOS_Util/post/regrid_py/regrid_catchANDcn.py | 26 +++++++++++--- GEOS_Util/post/regrid_py/regrid_params.py | 4 ++- GEOS_Util/post/regrid_py/regrid_params.tpl | 6 +--- GEOS_Util/post/regrid_py/regrid_questions.py | 8 +++-- GEOS_Util/post/regrid_py/regrid_upper.py | 34 +++++++++++++++---- 6 files changed, 85 insertions(+), 23 deletions(-) diff --git a/GEOS_Util/post/regrid_py/regrid.py b/GEOS_Util/post/regrid_py/regrid.py index 6739bc9b..716a6ff8 100644 --- a/GEOS_Util/post/regrid_py/regrid.py +++ b/GEOS_Util/post/regrid_py/regrid.py @@ -7,6 +7,8 @@ # import sys, getopt +import ruamel.yaml +import questionary from regrid_questions import get_config_from_questionary from regrid_params import * from regrid_upper import * @@ -30,8 +32,13 @@ def main(argv): regrid_params.yaml and regrid. \n ./regrid.py \n \nHelp message: \n - 1) The rst_dir directory should have three sub-directories: \n - upperair, surface and analysis which contain restart files respectively. \n''') + 1) Each individual script can be excuted indepently + 2) regrid_questions.py would generate raw_answer.yaml + 3) regrid_params.py uses raw_answer.yaml and regrid_params.tpl as inputs and generate regrid_params.yaml + 4) regrid_upper.py uses regrid_params.yaml as input for regriding + 5) regrid_lake_landice_saltwater.py uses regrid_params.yaml as input for regriding + 6) regrid_catchANDcn.py uses regrid_params.yaml as input for regriding + 7) regrid_analysis.py uses regrid_params.yaml as input for regriding ''') sys.exit(0) if opt in("-c", "--config_file"): config_yaml = arg @@ -42,6 +49,25 @@ def main(argv): params.convert_to_yaml() config_yaml = 'regrid_params.yaml' + with open(config_yaml, 'r') as f: + for line in f.readlines(): + trimmed_line = line.rstrip() + if trimmed_line: # Don't print blank lines + print(trimmed_line) + + print('\n') + questions = [ + { + "type": "confirm", + "name": "Continue", + "message": "Above is the YAML config file, would you like to continue?", + "default": True + },] + answer = questionary.prompt(questions) + + if not answer['Continue'] : + print("\nYou answer not to continue\n") + sys.exit(0) # upper air upper = upperair(config_yaml) upper.regrid() diff --git a/GEOS_Util/post/regrid_py/regrid_catchANDcn.py b/GEOS_Util/post/regrid_py/regrid_catchANDcn.py index d78f16d0..b19d2dd8 100755 --- a/GEOS_Util/post/regrid_py/regrid_catchANDcn.py +++ b/GEOS_Util/post/regrid_py/regrid_catchANDcn.py @@ -70,13 +70,14 @@ def regrid(self): shutil.copyfile(in_rstfile,dest) in_rstfile = dest + log_name = out_dir+'/'+'mk_catchANDcn_log' mk_catch_j_template = """#!/bin/csh -f #SBATCH --account={account} #SBATCH --ntasks=56 #SBATCH --time=1:00:00 #SBATCH --job-name=mk_catchANDcn #SBATCH --qos=debug -#SBATCH --output={out_dir}/mk_catchANDcn_log +#SBATCH --output={log_name} # source {Bin}/g5_modules @@ -94,15 +95,30 @@ def regrid(self): """ catch1script = mk_catch_j_template.format(Bin = bindir, account = account, out_bcs = out_bcsdir, \ - model = model, out_dir = out_dir, surflay = surflay, \ + model = model, out_dir = out_dir, surflay = surflay, log_name = log_name, \ 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_ ) - catch_scrpt = open('mk_catchANDcn.j','wt') + script_name = './mk_catchANDcn.j' + + catch_scrpt = open(script_name,'wt') catch_scrpt.write(catch1script) catch_scrpt.close() - print("sbatch -W mk_catchANDcn.j") - subprocess.call(['sbatch','-W', 'mk_catchANDcn.j']) + + interactive = os.getenv('SLURM_JOB_ID', default = None) + if(interactive ) : + print('interactive mode\n') + subprocess.call(['chmod', '755', script_name]) + ntasks = int(os.getenv('SLURM_NTASKS', default = 1)) + NPE = 56 + if (ntasks < NPE): + print("\nYou should have at least {NPE} cores. Now you only have {ntasks} cores ".format(NPE=NPE, ntasks=ntasks)) + print(script_name+ ' 1>' + log_name + ' 2>&1') + subprocess.call([script_name, '1>' + log_name, '2>&1']) + + else: + print("sbatch -W " + script_name +"\n") + subprocess.call(['sbatch','-W', script_name]) print( "cd " + bindir) os.chdir(bindir) diff --git a/GEOS_Util/post/regrid_py/regrid_params.py b/GEOS_Util/post/regrid_py/regrid_params.py index 2b7e5b25..5b5800b7 100755 --- a/GEOS_Util/post/regrid_py/regrid_params.py +++ b/GEOS_Util/post/regrid_py/regrid_params.py @@ -321,11 +321,13 @@ def get_grid_kind(grid): for f in upperin : fname = os.path.basename(f) dest = rst_dir + '/'+fname + print("Copy file "+f +" to " + rst_dir) shutil.copy(f, dest) for f in surfin : fname = os.path.basename(f) dest = rst_dir + '/'+fname + print("Copy file "+f +" to " + rst_dir) shutil.copy(f, dest) # prepare analysis files @@ -580,7 +582,7 @@ def params_for_air(self, config_tpl): def options_for_slurm(self, config_tpl): config_tpl['slurm']['account'] = self.slurm_options['account'] - config_tpl['slurm']['debug'] = self.slurm_options['debug'] + config_tpl['slurm']['qos'] = self.slurm_options['qos'] config_tpl['slurm']['partition'] = self.slurm_options['partition'] return config_tpl diff --git a/GEOS_Util/post/regrid_py/regrid_params.tpl b/GEOS_Util/post/regrid_py/regrid_params.tpl index 42871793..2eee1516 100644 --- a/GEOS_Util/post/regrid_py/regrid_params.tpl +++ b/GEOS_Util/post/regrid_py/regrid_params.tpl @@ -1,10 +1,6 @@ # # This template file can be filled with questionary or manually # -# By default, the values in child dictionary overwrites the values -# in parent dictionary. For example, rst_dir in input is the location with -# restart files to be regrrided. The surface restart files can be in -# surfface:rst_dir if it has value # input: @@ -43,5 +39,5 @@ output: slurm: account: - debug: + qos: partition: diff --git a/GEOS_Util/post/regrid_py/regrid_questions.py b/GEOS_Util/post/regrid_py/regrid_questions.py index 8452968d..b3af8f5b 100755 --- a/GEOS_Util/post/regrid_py/regrid_questions.py +++ b/GEOS_Util/post/regrid_py/regrid_questions.py @@ -263,7 +263,8 @@ def ask_upper_out(): return questionary.prompt(questions) def ask_surface_in(common_in): wemin_default = '26' - if common_in.get('tag') == 'INL': wemin_default = '13' + tag = common_in.get('tag') + if tag in ['INL','GITNL'] : wemin_default = '13' questions = [ { "type": "text", @@ -282,7 +283,8 @@ def ask_surface_in(common_in): def ask_surface_out(common_out): wemout_default = '26' - if common_out.get('tag') == 'INL': wemout_default = '13' + tag = common_out.get('tag') + if tag in ['INL','GITNL'] : wemout_default = '13' questions = [ { "type": "text", @@ -320,7 +322,7 @@ def ask_slurm_options(): questions = [ { "type": "text", - "name": "debug", + "name": "qos", "message": "qos?", "default": "debug", }, diff --git a/GEOS_Util/post/regrid_py/regrid_upper.py b/GEOS_Util/post/regrid_py/regrid_upper.py index aa9fc071..c466e088 100755 --- a/GEOS_Util/post/regrid_py/regrid_upper.py +++ b/GEOS_Util/post/regrid_py/regrid_upper.py @@ -96,8 +96,11 @@ def regrid(self): elif (imout>=2880): NPE = 5400; nwrit= 6 - QOS = "#" + QOS = "#SBATCH --qos="+config['slurm']['qos'] if NPE <= 532: QOS = "#SBATCH --qos=debug" + CONSTR = "#SBATCH --constrain=" + config['slurm']['partition'] + + log_name = out_dir+'/regrid_upper_log' regrid_template="""#!/bin/csh -xf #!/bin/csh -xf @@ -105,8 +108,9 @@ def regrid(self): #SBATCH --time=1:00:00 #SBATCH --ntasks={NPE} #SBATCH --job-name=regrid_upper -#SBATCH --output={out_dir}/{out_log} +#SBATCH --output={log_name} {QOS} +{CONSTR} unlimit @@ -184,14 +188,30 @@ def regrid(self): nlevel = config['output']['air']['nlevel'] regrid_upper_script = regrid_template.format(Bin=bindir, account = account, \ - out_dir = out_dir, out_log = 'regrid_upper_log', drymassFLG = drymassFLG, \ + out_dir = out_dir, log_name = log_name, drymassFLG = drymassFLG, \ imout = imout, nwrit = nwrit, NPE = NPE, \ - QOS = QOS, nlevel = nlevel, hydrostatic = hydrostatic) - upper = open('regrid_upper.j','wt') + QOS = QOS,CONSTR = CONSTR, nlevel = nlevel, hydrostatic = hydrostatic) + + script_name = './regrid_upper.j' + + upper = open(script_name,'wt') upper.write(regrid_upper_script) upper.close() - print('sbatch -W regrid_upper.j\n') - subprocess.call(['sbatch', '-W', 'regrid_upper.j']) + + interactive = os.getenv('SLURM_JOB_ID', default = None) + + if(interactive ) : + print('interactive mode\n') + ntasks = int(os.getenv('SLURM_NTASKS', default = 1)) + 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') + subprocess.call([script_name, '1>'+log_name, '2>&1']) + else : + print('sbatch -W '+ script_name +'\n') + subprocess.call(['sbatch', '-W', script_name]) # # post process From 2d21cb4199544ecf32b25d9a3b624aea3aaf624b Mon Sep 17 00:00:00 2001 From: Rolf Reichle <54944691+gmao-rreichle@users.noreply.github.com> Date: Wed, 8 Jun 2022 11:16:43 -0400 Subject: [PATCH 46/70] fixed typos in comments (regrid.py) --- GEOS_Util/post/regrid_py/regrid.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/GEOS_Util/post/regrid_py/regrid.py b/GEOS_Util/post/regrid_py/regrid.py index 716a6ff8..e291f3bb 100644 --- a/GEOS_Util/post/regrid_py/regrid.py +++ b/GEOS_Util/post/regrid_py/regrid.py @@ -29,12 +29,12 @@ def main(argv): 1) Use a config file to regrid: \n ./regrid.py -c my_config.yaml \n \n 2) Use questionary to convert template regrid_params.tpl to \n - regrid_params.yaml and regrid. \n + regrid_params.yaml and then regrid. \n ./regrid.py \n \nHelp message: \n - 1) Each individual script can be excuted indepently - 2) regrid_questions.py would generate raw_answer.yaml - 3) regrid_params.py uses raw_answer.yaml and regrid_params.tpl as inputs and generate regrid_params.yaml + 1) Each individual script can be executed independently + 2) regrid_questions.py generates raw_answer.yaml + 3) regrid_params.py uses raw_answer.yaml and regrid_params.tpl as inputs and generates regrid_params.yaml 4) regrid_upper.py uses regrid_params.yaml as input for regriding 5) regrid_lake_landice_saltwater.py uses regrid_params.yaml as input for regriding 6) regrid_catchANDcn.py uses regrid_params.yaml as input for regriding @@ -66,7 +66,7 @@ def main(argv): answer = questionary.prompt(questions) if not answer['Continue'] : - print("\nYou answer not to continue\n") + print("\nYou answered not to continue, exiting.\n") sys.exit(0) # upper air upper = upperair(config_yaml) From b25e263cc1179f243736a2b07134573532147f39 Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Wed, 8 Jun 2022 23:15:21 -0400 Subject: [PATCH 47/70] further polishing. py scripts can be run at different locations --- GEOS_Util/post/regrid_py/regrid_analysis.py | 7 +- GEOS_Util/post/regrid_py/regrid_catchANDcn.py | 22 +++--- .../regrid_lake_landice_saltwater.py | 11 +-- GEOS_Util/post/regrid_py/regrid_params.py | 70 ++++++++----------- GEOS_Util/post/regrid_py/regrid_questions.py | 23 +++--- GEOS_Util/post/regrid_py/regrid_upper.py | 16 +++-- 6 files changed, 76 insertions(+), 73 deletions(-) diff --git a/GEOS_Util/post/regrid_py/regrid_analysis.py b/GEOS_Util/post/regrid_py/regrid_analysis.py index 177cce9a..d2cb78bb 100755 --- a/GEOS_Util/post/regrid_py/regrid_analysis.py +++ b/GEOS_Util/post/regrid_py/regrid_analysis.py @@ -35,7 +35,8 @@ def regrid(self): print("\n Regrid or copy analysis files...\n") - bindir = os.getcwd() + cwdir = os.getcwd() + bindir = os.path.dirname(os.path.realpath(__file__)) in_bcsdir = config['input']['shared']['bcs_dir'] out_bcsdir = config['output']['shared']['bcs_dir'] out_dir = config['output']['shared']['out_dir'] @@ -104,8 +105,8 @@ def regrid(self): cmd = bindir+'/mkdrstdate.x ' + ymd_ + ' ' + hms_ +' ' + rstlcvOut print(cmd) subprocess.call(shlex.split(cmd)) - print( "cd " + bindir) - os.chdir(bindir) + print( "cd " + cwdir) + os.chdir(cwdir) def get_grid_kind(this, grid): hgrd = {} diff --git a/GEOS_Util/post/regrid_py/regrid_catchANDcn.py b/GEOS_Util/post/regrid_py/regrid_catchANDcn.py index b19d2dd8..500078cf 100755 --- a/GEOS_Util/post/regrid_py/regrid_catchANDcn.py +++ b/GEOS_Util/post/regrid_py/regrid_catchANDcn.py @@ -21,19 +21,21 @@ def regrid(self): rst_dir = config['input']['shared']['rst_dir'] model = config['input']['surface']['catch_model'] in_rstfile = '' + yyyymmddhh_ = str(self.config['input']['shared']['yyyymmddhh']) + time = yyyymmddhh_[0:8]+'_'+yyyymmddhh_[8:10] if model == 'catch' : - in_rstfile = glob.glob(rst_dir+'/*catch_*')[0] + in_rstfile = glob.glob(rst_dir+'/*catch_*'+time+'*')[0] if model == 'catchcnclm40' : - in_rstfile = glob.glob(rst_dir+'/*catchcnclm40_*')[0] + in_rstfile = glob.glob(rst_dir+'/*catchcnclm40_*'+time+'*')[0] if model == 'catchcnclm45' : - in_rstfile = glob.glob(rst_dir+'/*catchcnclm45_*')[0] + in_rstfile = glob.glob(rst_dir+'/*catchcnclm45_*'+time+'*')[0] if not in_rstfile: return print("\nRegridding " + model + ".....\n") - bindir = os.getcwd() - + cwdir = os.getcwd() + bindir = os.path.dirname(os.path.realpath(__file__)) in_bcsdir = config['input']['shared']['bcs_dir'] out_bcsdir = config['output']['shared']['bcs_dir'] out_dir = config['output']['shared']['out_dir'] @@ -44,9 +46,8 @@ def regrid(self): in_tilefile = glob.glob(in_bcsdir+ '/*-Pfafstetter.til')[0] out_tilefile = glob.glob(out_bcsdir+ '/*-Pfafstetter.til')[0] account = config['slurm']['account'] - yyyymmddhh_= str(config['input']['shared']['yyyymmddhh']) # even the input is binary, the output si nc4 - suffix = yyyymmddhh_[0:8]+'_'+yyyymmddhh_[8:10]+'z.nc4' + suffix = time+'z.nc4' if (expid) : expid = expid + '.' @@ -114,14 +115,15 @@ def regrid(self): if (ntasks < NPE): print("\nYou should have at least {NPE} cores. Now you only have {ntasks} cores ".format(NPE=NPE, ntasks=ntasks)) print(script_name+ ' 1>' + log_name + ' 2>&1') - subprocess.call([script_name, '1>' + log_name, '2>&1']) + #subprocess.call([script_name, '1>' + log_name, '2>&1'], shell = True) + os.system(script_name + ' 1>' + log_name+ ' 2>&1') else: print("sbatch -W " + script_name +"\n") subprocess.call(['sbatch','-W', script_name]) - print( "cd " + bindir) - os.chdir(bindir) + print( "cd " + cwdir) + os.chdir(cwdir) if __name__ == '__main__' : catch = catchANDcn('regrid_params.yaml') diff --git a/GEOS_Util/post/regrid_py/regrid_lake_landice_saltwater.py b/GEOS_Util/post/regrid_py/regrid_lake_landice_saltwater.py index 39d1fff9..0c33c34b 100755 --- a/GEOS_Util/post/regrid_py/regrid_lake_landice_saltwater.py +++ b/GEOS_Util/post/regrid_py/regrid_lake_landice_saltwater.py @@ -22,7 +22,8 @@ def regrid(self): print("\nRegridding land, landice, saltwater.....\n") config = self.config - bindir = os.getcwd() + cwdir = os.getcwd() + bindir = os.path.dirname(os.path.realpath(__file__)) in_bcsdir = config['input']['shared']['bcs_dir'] out_bcsdir = config['output']['shared']['bcs_dir'] out_dir = config['output']['shared']['out_dir'] @@ -134,8 +135,8 @@ def regrid(self): filename = expid + os.path.basename(out_rst).split('_rst')[0].split('.')[-1]+suffix print('\n Move ' + out_rst + ' to ' + out_dir+"/"+filename) shutil.move(out_rst, out_dir+"/"+filename) - print('cd ' + bindir) - os.chdir(bindir) + print('cd ' + cwdir) + os.chdir(cwdir) def find_rst(self): surf_restarts =[ @@ -147,9 +148,11 @@ def find_rst(self): "seaicethermo_internal_rst"] rst_dir = self.config['input']['shared']['rst_dir'] + yyyymmddhh_ = str(self.config['input']['shared']['yyyymmddhh']) + time = yyyymmddhh_[0:8]+'_'+yyyymmddhh_[8:10] restarts_in=[] for f in surf_restarts : - files = glob.glob(rst_dir+ '/*'+f+'*') + files = glob.glob(rst_dir+ '/*'+f+'*'+time+'*') if len(files) >0: restarts_in.append(files[0]) return restarts_in diff --git a/GEOS_Util/post/regrid_py/regrid_params.py b/GEOS_Util/post/regrid_py/regrid_params.py index 5b5800b7..e099e8b8 100755 --- a/GEOS_Util/post/regrid_py/regrid_params.py +++ b/GEOS_Util/post/regrid_py/regrid_params.py @@ -22,7 +22,7 @@ def __init__(self, config_from_question): #self.ana_in = config_from_question['input']['parameters']['ANALYSIS'] self.ana_out = config_from_question['output']['parameters']['ANALYSIS'] - self.init_time() + self.init_time_and_grid() self.init_tags() self.init_merra2() @@ -235,26 +235,8 @@ def init_tags(self): self.bcbase['discover_lt'] = "/discover/nobackup/ltakacs/bcs" self.bcbase['discover_couple'] = "/discover/nobackup/projects/gmao/ssd/aogcm/atmosphere_bcs" - def init_time(self): + def init_time_and_grid(self): ymdh = self.common_in.get('yyyymmddhh') - self.agrid_ = '' - if not ymdh: - rst_dir = self.common_in['rst_dir'] + '/' - files = glob.glob(rst_dir + '*fvcore_*') - if len(files) ==0 : - sys.exit("date and time are not provided") - - fvrst = os.path.dirname(os.path.realpath(__file__)) + '/fvrst.x -h ' - cmd = fvrst + files[0] - print(cmd +'\n') - p = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE) - (output, err) = p.communicate() - p_status = p.wait() - ss = output.decode().split() - ymdh = str(ss[3]) + str(ss[4])[0:2] - self.common_in['yyyymmddhh']=ymdh - self.agrid_ = "C"+ss[0] # save for air parameter - self.yyyymm = ymdh[0:6] self.yyyy = ymdh[0:4] self.mm = ymdh[4:6] @@ -262,6 +244,28 @@ def init_time(self): self.hh = ymdh[8:10] self.ymd = ymdh[0:8] + self.agrid_ = '' + rst_dir = self.common_in['rst_dir'] + '/' + time = self.ymd + '_'+self.hh + files = glob.glob(rst_dir +'/*fvcore_*'+time+'*') + if len(files) ==0 : + return + fvrst = os.path.dirname(os.path.realpath(__file__)) + '/fvrst.x -h ' + cmd = fvrst + files[0] + print(cmd +'\n') + p = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE) + (output, err) = p.communicate() + p_status = p.wait() + ss = output.decode().split() + self.agrid_ = "C"+ss[0] # save for air parameter + lat = int(ss[0]) + lon = int(ss[1]) + if (lon != lat*6) : + sys.exit('This is not a cubed-sphere grid fvcore restart. Please contact SI team') + ymdh_ = str(ss[3]) + str(ss[4])[0:2] + if (ymdh_ != ymdh) : + print("Warning: The date in fvcore is different from the date you input\n") + def init_merra2(self): def get_grid_kind(grid): hgrd = {} @@ -539,34 +543,21 @@ def params_for_air(self, config_tpl): return config_tpl # verify agrid rst_dir = self.common_in['rst_dir'] + '/' - files = glob.glob(rst_dir + '*fvcore_*') - if len(files) ==0 : + time = self.ymd + '_'+ self.hh + files = glob.glob(rst_dir +'/*fvcore_*'+time+'*') + if len(files) == 0 : return config_tpl # get expid fname = os.path.basename(files[0]) expid = fname.split('fvcore')[0] config_tpl['input']['shared']['expid'] = expid[0:-1] #remove the last '.' - if not self.agrid_ : - fvrst = os.path.dirname(os.path.realpath(__file__)) + '/fvrst.x -h ' - cmd = fvrst + files[0] - print(cmd +'\n') - p = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE) - (output, err) = p.communicate() - p_status = p.wait() - ss = output.decode().split() - self.agrid_ = "C"+ss[0] - lat = int(ss[0]) - lon = int(ss[1]) - if (lon != lat*6) : - sys.exit('This is not a cubed-sphere grid fvcore restart. Please contact SI team') config_tpl['input']['shared']['agrid'] = self.agrid_ self.common_in['agrid'] = self.agrid_ if self.common_in['ogrid'] == 'CS' : config_tpl['input']['shared']['ogrid'] = self.agrid_ self.common_in['ogrid'] = self.agrid_ - ogrid = config_tpl['input']['shared']['ogrid'] tagout = self.common_out['tag'] bctag = self.get_bcTag(tagout, ogrid) @@ -601,15 +592,16 @@ def params_for_surface(self, config_tpl): config_tpl['output']['surface']['wemin']= self.surf_out['wemout'] rst_dir = self.common_in['rst_dir'] + '/' - files = glob.glob(rst_dir + '*catch_*') + time = self.ymd + '_'+ self.hh + files = glob.glob(rst_dir +'/*catch_*'+time+'*') if (len(files) > 0) : config_tpl['input']['surface']['catch_model'] = 'catch' - files = glob.glob(rst_dir + '*catchcnclm40_*') + files = glob.glob(rst_dir +'/*catchcnclm40_*'+time+'*') if (len(files) > 0) : config_tpl['input']['surface']['catch_model'] = 'catchcnclm40' - files = glob.glob(rst_dir + '*catchcnclm45_*') + files = glob.glob(rst_dir +'/*catchcnclm45_*'+time+'*') if (len(files) > 0) : config_tpl['input']['surface']['catch_model'] = 'catchcnclm45' diff --git a/GEOS_Util/post/regrid_py/regrid_questions.py b/GEOS_Util/post/regrid_py/regrid_questions.py index b3af8f5b..c7d16ced 100755 --- a/GEOS_Util/post/regrid_py/regrid_questions.py +++ b/GEOS_Util/post/regrid_py/regrid_questions.py @@ -15,11 +15,13 @@ import glob def has_fvcore(x): - files = glob.glob(x['rst_dir']+'/*fvcore_*') + ymdh = x['yyyymmddhh'] + time = ymdh[0:8] + '_'+ymdh[8:10] + files = glob.glob(x['rst_dir']+'/*fvcore_*'+time+'*') if len(files) ==1 : return True else: - print('False') + print('\nDo not have fvcore for this date\n') return False @@ -34,19 +36,18 @@ def ask_common_in(): { "type": "path", "name": "rst_dir", - "message": "Enter the directory with restart files to be regrided: \n If it is MERRA-2, files from achives will be copied to this directory. \n", + "message": "Enter the directory containing restart files to be regrided: \n (If it is MERRA-2, files from achives will be copied to this directory automatically). \n", }, { "type": "text", "name": "yyyymmddhh", - "message": "What time would you like to regrid from?(yyyymmddhh)", - "default": "", - "when": lambda x: not has_fvcore(x), + "message": "What time would you like to regrid from?(must be 10 digits: yyyymmddhh)", + "validate": lambda text: len(text)==10 , }, { "type": "text", "name": "agrid", - "message": "Enter input atmospheric grid, format(Cxxx):", + "message": "Enter input atmospheric grid: \n C12 C180 C1000 \n C24 C360 C1440 \n C48 C500 C2880 \n C90 C720 C5760 \n ", "default": 'C360', # if it is merra-2 or has_fvcore, agrid is deduced "when": lambda x: not x['MERRA-2'] and not has_fvcore(x), @@ -159,7 +160,7 @@ def ask_common_out(): { "type": "text", "name": "agrid", - "message": "Enter new atmospheric grid, format(Cxxx):", + "message": "Enter new atmospheric grid: \n C12 C180 C1000 \n C24 C360 C1440 \n C48 C500 C2880 \n C90 C720 C5760 \n ", "default": 'C360', }, { @@ -256,7 +257,7 @@ def ask_upper_out(): { "type": "text", "name": "nlevel", - "message": "Enter new atmospheric levels:", + "message": "Enter new atmospheric levels: (71 72 91 127 132 137 144 181)", "default": "72", }, ] @@ -264,7 +265,7 @@ def ask_upper_out(): def ask_surface_in(common_in): wemin_default = '26' tag = common_in.get('tag') - if tag in ['INL','GITNL'] : wemin_default = '13' + if tag in ['INL','GITNL', '525'] : wemin_default = '13' questions = [ { "type": "text", @@ -284,7 +285,7 @@ def ask_surface_in(common_in): def ask_surface_out(common_out): wemout_default = '26' tag = common_out.get('tag') - if tag in ['INL','GITNL'] : wemout_default = '13' + if tag in ['INL','GITNL', '525'] : wemout_default = '13' questions = [ { "type": "text", diff --git a/GEOS_Util/post/regrid_py/regrid_upper.py b/GEOS_Util/post/regrid_py/regrid_upper.py index c466e088..03626022 100755 --- a/GEOS_Util/post/regrid_py/regrid_upper.py +++ b/GEOS_Util/post/regrid_py/regrid_upper.py @@ -22,7 +22,8 @@ def regrid(self): print( "\nRegridding upper air......\n") config = self.config - bindir = os.getcwd() + cwdir = os.getcwd() + bindir = os.path.dirname(os.path.realpath(__file__)) in_bcsdir = config['input']['shared']['bcs_dir'] out_bcsdir = config['output']['shared']['bcs_dir'] out_dir = config['output']['shared']['out_dir'] @@ -98,7 +99,7 @@ def regrid(self): QOS = "#SBATCH --qos="+config['slurm']['qos'] if NPE <= 532: QOS = "#SBATCH --qos=debug" - CONSTR = "#SBATCH --constrain=" + config['slurm']['partition'] + CONSTR = "#SBATCH --constraint=" + config['slurm']['partition'] log_name = out_dir+'/regrid_upper_log' @@ -208,7 +209,8 @@ def regrid(self): subprocess.call(['chmod', '755', script_name]) print(script_name+ ' 1>' + log_name + ' 2>&1') - subprocess.call([script_name, '1>'+log_name, '2>&1']) + #subprocess.call([script_name, '1>'+log_name, '2>&1'], shell = True) + os.system(script_name + ' 1>' + log_name+ ' 2>&1') else : print('sbatch -W '+ script_name +'\n') subprocess.call(['sbatch', '-W', script_name]) @@ -229,8 +231,8 @@ def regrid(self): print('\n Move regrid_upper.j to ' + out_dir) shutil.move('regrid_upper.j', out_dir+"/regrid_upper.j") - print('cd ' + bindir) - os.chdir(bindir) + print('cd ' + cwdir) + os.chdir(cwdir) def find_rst(self): air_restarts =["fvcore_internal_rst" , @@ -257,9 +259,11 @@ def find_rst(self): "tr_internal_rst"] rst_dir = self.config['input']['shared']['rst_dir'] + yyyymmddhh_ = str(self.config['input']['shared']['yyyymmddhh']) + time = yyyymmddhh_[0:8]+'_'+yyyymmddhh_[8:10] restarts_in=[] for f in air_restarts : - files = glob.glob(rst_dir+ '/*'+f+'*') + files = glob.glob(rst_dir+ '/*'+f+'*'+time+'*') if len(files) >0: restarts_in.append(files[0]) return restarts_in From c308ec8d33aa70c6440abe179893a0af6816da66 Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Thu, 9 Jun 2022 09:20:30 -0400 Subject: [PATCH 48/70] fix alt_bcs --- GEOS_Util/post/regrid_py/regrid_params.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GEOS_Util/post/regrid_py/regrid_params.py b/GEOS_Util/post/regrid_py/regrid_params.py index e099e8b8..95d84571 100755 --- a/GEOS_Util/post/regrid_py/regrid_params.py +++ b/GEOS_Util/post/regrid_py/regrid_params.py @@ -438,7 +438,7 @@ def get_bcdir(self, opt): tag = self.common_out['tag'] ogrid = self.common_out['ogrid'] model = self.common_out['model'] - bcdir = self.common_in.get('alt_bcs', None) + bcdir = self.common_out.get('alt_bcs', None) if bcdir is None : bc_base = self.get_bcbase(opt) From 45e096f4b0286dac695a95cd881144383fa19bf5 Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Thu, 9 Jun 2022 09:37:17 -0400 Subject: [PATCH 49/70] remove some old tags --- GEOS_Util/post/regrid_py/regrid_questions.py | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/GEOS_Util/post/regrid_py/regrid_questions.py b/GEOS_Util/post/regrid_py/regrid_questions.py index c7d16ced..5cd59f58 100755 --- a/GEOS_Util/post/regrid_py/regrid_questions.py +++ b/GEOS_Util/post/regrid_py/regrid_questions.py @@ -93,12 +93,6 @@ def ask_common_in(): "message": "Enter GCM or DAS tag for input: \n \ Sample GCM tags \n \ --------------- \n \ -F14 : Fortuna-1_4 ......... Fortuna-1_4_p1 \n \ -F20 : Fortuna-2_0 ......... Fortuna-2_0 \n \ -F21 : Fortuna-2_1 ......... Fortuna-2_5_pp2 \n \ -G10 : Ganymed-1_0 ......... Ganymed-1_0_BETA4 \n \ -G10p : Ganymed-1_0_p1 ...... Ganymed-1_0_p6 \n \ -G20 : Ganymed-2_0 ......... Ganymed-2_1_p6 \n \ G30 : Ganymed-3_0 ......... Ganymed-3_0_p1 \n \ G40 : Ganymed-4_0 ......... Heracles-5_4_p3 \n \ ICA : Icarus .............. Jason \n \ @@ -108,12 +102,6 @@ def ask_common_in(): \n \ Sample DAS tags \n \ --------------- \n \ -214 : GEOSdas-2_1_4 ....... GEOSdas-2_1_4-m4 \n \ -540 : GEOSadas-5_4_0 ...... GEOSadas-5_5_3 \n \ -561 : GEOSadas-5_6_1 ...... GEOSadas-5_7_3_p2 \n \ -580 : GEOSadas-5_8_0 ...... GEOSadas-5_9_1 \n \ -591p : GEOSadas-5_9_1_p1 ... GEOSadas-5_9_1_p9 \n \ -5A0 : GEOSadas-5_10_0 ..... GEOSadas-5_10_0_p1 \n \ 5B0 : GEOSadas-5_10_0_p2 .. GEOSadas-5_11_0 \n \ 512 : GEOSadas-5_12_2 ..... GEOSadas-5_16_5\n \ 517 : GEOSadas-5_17_0 ..... GEOSadas-5_24_0_p1\n \ From 61b02b36d57cdf9174b1c1f7d35bff893cf8e473 Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Fri, 10 Jun 2022 09:53:53 -0400 Subject: [PATCH 50/70] add another way to check ntasks when interactive --- GEOS_Util/post/regrid_py/regrid_catchANDcn.py | 13 +++++++++---- GEOS_Util/post/regrid_py/regrid_upper.py | 12 ++++++++---- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/GEOS_Util/post/regrid_py/regrid_catchANDcn.py b/GEOS_Util/post/regrid_py/regrid_catchANDcn.py index 500078cf..1ec5ff20 100755 --- a/GEOS_Util/post/regrid_py/regrid_catchANDcn.py +++ b/GEOS_Util/post/regrid_py/regrid_catchANDcn.py @@ -107,15 +107,20 @@ def regrid(self): catch_scrpt.close() interactive = os.getenv('SLURM_JOB_ID', default = None) - if(interactive ) : + if ( interactive ) : print('interactive mode\n') - subprocess.call(['chmod', '755', script_name]) - ntasks = int(os.getenv('SLURM_NTASKS', default = 1)) + 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) NPE = 56 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') - #subprocess.call([script_name, '1>' + log_name, '2>&1'], shell = True) os.system(script_name + ' 1>' + log_name+ ' 2>&1') else: diff --git a/GEOS_Util/post/regrid_py/regrid_upper.py b/GEOS_Util/post/regrid_py/regrid_upper.py index 03626022..6c983907 100755 --- a/GEOS_Util/post/regrid_py/regrid_upper.py +++ b/GEOS_Util/post/regrid_py/regrid_upper.py @@ -201,15 +201,19 @@ def regrid(self): interactive = os.getenv('SLURM_JOB_ID', default = None) - if(interactive ) : + if (interactive) : print('interactive mode\n') - ntasks = int(os.getenv('SLURM_NTASKS', default = 1)) - if (ntasks < NPE): + 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') - #subprocess.call([script_name, '1>'+log_name, '2>&1'], shell = True) os.system(script_name + ' 1>' + log_name+ ' 2>&1') else : print('sbatch -W '+ script_name +'\n') From 2be14d569bd5f6b8ddcfcc6abe2207fb02e040da Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Mon, 13 Jun 2022 08:44:47 -0400 Subject: [PATCH 51/70] rename regrid to remap --- GEOS_Util/post/CMakeLists.txt | 2 +- .../remap_analysis.py} | 8 +-- .../remap_catchANDcn.py} | 8 +-- .../remap_lake_landice_saltwater.py} | 8 +-- .../remap_params.py} | 22 ++++---- .../remap_params.tpl} | 0 .../remap_questions.py} | 4 +- .../remap_restarts.py} | 50 +++++++++---------- .../remap_upper.py} | 24 ++++----- 9 files changed, 63 insertions(+), 63 deletions(-) rename GEOS_Util/post/{regrid_py/regrid_analysis.py => remap_restart/remap_analysis.py} (96%) rename GEOS_Util/post/{regrid_py/regrid_catchANDcn.py => remap_restart/remap_catchANDcn.py} (97%) rename GEOS_Util/post/{regrid_py/regrid_lake_landice_saltwater.py => remap_restart/remap_lake_landice_saltwater.py} (97%) rename GEOS_Util/post/{regrid_py/regrid_params.py => remap_restart/remap_params.py} (97%) rename GEOS_Util/post/{regrid_py/regrid_params.tpl => remap_restart/remap_params.tpl} (100%) rename GEOS_Util/post/{regrid_py/regrid_questions.py => remap_restart/remap_questions.py} (98%) rename GEOS_Util/post/{regrid_py/regrid.py => remap_restart/remap_restarts.py} (54%) rename GEOS_Util/post/{regrid_py/regrid_upper.py => remap_restart/remap_upper.py} (94%) diff --git a/GEOS_Util/post/CMakeLists.txt b/GEOS_Util/post/CMakeLists.txt index fa817cf8..ce71bc27 100644 --- a/GEOS_Util/post/CMakeLists.txt +++ b/GEOS_Util/post/CMakeLists.txt @@ -50,7 +50,7 @@ install( PROGRAMS ${perlscripts} ec2grd.csh DESTINATION bin) -file(GLOB pythonscripts CONFIGURE_DEPENDS ./regrid_py/regrid*) +file(GLOB pythonscripts CONFIGURE_DEPENDS ./remap_restart/remap*) install( PROGRAMS ${pythonscripts} DESTINATION bin) diff --git a/GEOS_Util/post/regrid_py/regrid_analysis.py b/GEOS_Util/post/remap_restart/remap_analysis.py similarity index 96% rename from GEOS_Util/post/regrid_py/regrid_analysis.py rename to GEOS_Util/post/remap_restart/remap_analysis.py index d2cb78bb..2448088e 100755 --- a/GEOS_Util/post/regrid_py/regrid_analysis.py +++ b/GEOS_Util/post/remap_restart/remap_analysis.py @@ -23,7 +23,7 @@ def __init__(self, params_file): stream = f.read() self.config = yaml.load(stream) - def regrid(self): + def remap(self): config = self.config bkg = config['output']['analysis']['bkg'] if ( not bkg ): return @@ -33,7 +33,7 @@ def regrid(self): print("\n There are no analysis files. \n") return - print("\n Regrid or copy analysis files...\n") + print("\n Remapping or copying analysis files...\n") cwdir = os.getcwd() bindir = os.path.dirname(os.path.realpath(__file__)) @@ -136,5 +136,5 @@ def find_analysis(self): return analysis_in if __name__ == '__main__' : - ana = analysis('regrid_params.yaml') - ana.regrid() + ana = analysis('remap_params.yaml') + ana.remap() diff --git a/GEOS_Util/post/regrid_py/regrid_catchANDcn.py b/GEOS_Util/post/remap_restart/remap_catchANDcn.py similarity index 97% rename from GEOS_Util/post/regrid_py/regrid_catchANDcn.py rename to GEOS_Util/post/remap_restart/remap_catchANDcn.py index 1ec5ff20..d72ec9b7 100755 --- a/GEOS_Util/post/regrid_py/regrid_catchANDcn.py +++ b/GEOS_Util/post/remap_restart/remap_catchANDcn.py @@ -16,7 +16,7 @@ def __init__(self, params_file): stream = f.read() self.config = yaml.load(stream) - def regrid(self): + def remap(self): config = self.config rst_dir = config['input']['shared']['rst_dir'] model = config['input']['surface']['catch_model'] @@ -32,7 +32,7 @@ def regrid(self): if not in_rstfile: return - print("\nRegridding " + model + ".....\n") + print("\nRemapping " + model + ".....\n") cwdir = os.getcwd() bindir = os.path.dirname(os.path.realpath(__file__)) @@ -131,5 +131,5 @@ def regrid(self): os.chdir(cwdir) if __name__ == '__main__' : - catch = catchANDcn('regrid_params.yaml') - catch.regrid() + catch = catchANDcn('remap_params.yaml') + catch.remap() diff --git a/GEOS_Util/post/regrid_py/regrid_lake_landice_saltwater.py b/GEOS_Util/post/remap_restart/remap_lake_landice_saltwater.py similarity index 97% rename from GEOS_Util/post/regrid_py/regrid_lake_landice_saltwater.py rename to GEOS_Util/post/remap_restart/remap_lake_landice_saltwater.py index 0c33c34b..3f5bf55b 100755 --- a/GEOS_Util/post/regrid_py/regrid_lake_landice_saltwater.py +++ b/GEOS_Util/post/remap_restart/remap_lake_landice_saltwater.py @@ -15,12 +15,12 @@ def __init__(self, params_file): stream = f.read() self.config = yaml.load(stream) - def regrid(self): + def remap(self): restarts_in = self.find_rst() if len(restarts_in) == 0: return - print("\nRegridding land, landice, saltwater.....\n") + print("\nRemapping land, landice, saltwater.....\n") config = self.config cwdir = os.getcwd() bindir = os.path.dirname(os.path.realpath(__file__)) @@ -158,5 +158,5 @@ def find_rst(self): return restarts_in if __name__ == '__main__' : - lls = lake_landice_saltwater('regrid_params.yaml') - lls.regrid() + lls = lake_landice_saltwater('remap_params.yaml') + lls.remap() diff --git a/GEOS_Util/post/regrid_py/regrid_params.py b/GEOS_Util/post/remap_restart/remap_params.py similarity index 97% rename from GEOS_Util/post/regrid_py/regrid_params.py rename to GEOS_Util/post/remap_restart/remap_params.py index 95d84571..e08dd9d9 100755 --- a/GEOS_Util/post/regrid_py/regrid_params.py +++ b/GEOS_Util/post/remap_restart/remap_params.py @@ -11,7 +11,7 @@ from datetime import datetime from datetime import timedelta -class regrid_params(object): +class remap_params(object): def __init__(self, config_from_question): self.common_in = config_from_question['input']['parameters']['COMMON'] self.common_out = config_from_question['output']['parameters']['COMMON'] @@ -30,8 +30,8 @@ def __init__(self, config_from_question): # load input yaml yaml = ruamel.yaml.YAML() stream = '' - regrid_tpl = os.path.dirname(os.path.realpath(__file__)) + '/regrid_params.tpl' - with open(regrid_tpl, 'r') as f: + 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) @@ -62,22 +62,22 @@ def __init__(self, config_from_question): self.config = config_tpl def convert_to_yaml(self) : - if os.path.exists('regrid_params.yaml') : - overwrite = questionary.confirm("Do you want to overwrite regrid_params.yaml file?", default=False).ask() + if os.path.exists('remap_params.yaml') : + overwrite = questionary.confirm("Do you want to overwrite remap_params.yaml file?", default=False).ask() if not overwrite : while True: - new_name = questionary.text("What's the backup name for existing regrid_params.yaml?", default='regrid_params.yaml.1').ask() + new_name = questionary.text("What's the backup name for existing remap_params.yaml?", default='remap_params.yaml.1').ask() if os.path.exists(new_name): print('\n'+ new_name + ' exists, please enter a new one. \n') else: - shutil.move('regrid_params.yaml', new_name) + shutil.move('remap_params.yaml', new_name) break yaml = ruamel.yaml.YAML() - with open("regrid_params.yaml", "w") as f: + with open("remap_params.yaml", "w") as f: yaml.dump(self.config, f) def init_tags(self): - # copy and paste from regrid.pl + # copy and paste from remap.pl # minor change. Add "D" to the number for each group # BCS Tag: Fortuna-1_4 F14 = ( 'F14', 'Fortuna-1_4', 'Fortuna-1_4_p1' ) @@ -353,7 +353,7 @@ def get_grid_kind(grid): agrid_out = self.common_out['agrid'] if (get_grid_kind(agrid_in.upper()) == get_grid_kind(agrid_out.upper())): - print(" No need to regrid anaylysis file according to air grid in and out") + print(" No need to remap anaylysis file according to air grid in and out") return anafiles=[] @@ -625,5 +625,5 @@ def params_for_analysis(self, config_tpl): with open("raw_answers.yaml", "r") as f: stream = f.read() config = yaml.load(stream) - param = regrid_params(config) + param = remap_params(config) param.convert_to_yaml() diff --git a/GEOS_Util/post/regrid_py/regrid_params.tpl b/GEOS_Util/post/remap_restart/remap_params.tpl similarity index 100% rename from GEOS_Util/post/regrid_py/regrid_params.tpl rename to GEOS_Util/post/remap_restart/remap_params.tpl diff --git a/GEOS_Util/post/regrid_py/regrid_questions.py b/GEOS_Util/post/remap_restart/remap_questions.py similarity index 98% rename from GEOS_Util/post/regrid_py/regrid_questions.py rename to GEOS_Util/post/remap_restart/remap_questions.py index 5cd59f58..65c16631 100755 --- a/GEOS_Util/post/regrid_py/regrid_questions.py +++ b/GEOS_Util/post/remap_restart/remap_questions.py @@ -36,12 +36,12 @@ def ask_common_in(): { "type": "path", "name": "rst_dir", - "message": "Enter the directory containing restart files to be regrided: \n (If it is MERRA-2, files from achives will be copied to this directory automatically). \n", + "message": "Enter the directory containing restart files to be remapped: \n (If it is MERRA-2, files from achives will be copied to this directory automatically). \n", }, { "type": "text", "name": "yyyymmddhh", - "message": "What time would you like to regrid from?(must be 10 digits: yyyymmddhh)", + "message": "What time would you like to remap from?(must be 10 digits: yyyymmddhh)", "validate": lambda text: len(text)==10 , }, { diff --git a/GEOS_Util/post/regrid_py/regrid.py b/GEOS_Util/post/remap_restart/remap_restarts.py similarity index 54% rename from GEOS_Util/post/regrid_py/regrid.py rename to GEOS_Util/post/remap_restart/remap_restarts.py index e291f3bb..4ca6bc1a 100644 --- a/GEOS_Util/post/regrid_py/regrid.py +++ b/GEOS_Util/post/remap_restart/remap_restarts.py @@ -9,45 +9,45 @@ import sys, getopt import ruamel.yaml import questionary -from regrid_questions import get_config_from_questionary -from regrid_params import * -from regrid_upper import * -from regrid_lake_landice_saltwater import * -from regrid_analysis import * -from regrid_catchANDcn import * +from remap_questions import get_config_from_questionary +from remap_params import * +from remap_upper import * +from remap_lake_landice_saltwater import * +from remap_analysis import * +from remap_catchANDcn import * def main(argv): config_yaml = '' try: opts, args = getopt.getopt(argv,"hc:", ['config_file=']) except getopt.GetoptError: - print('Usage: regrid.py -c regrid.yaml or ./regrid.py ') + print('Usage: remap_restarts.py -c remap_params.yaml or ./remap_restarts.py ') sys.exit('command line error') for opt, arg in opts: if opt == '-h': - print('''\nThere are two ways to use this script to regrid restarts. \n - 1) Use a config file to regrid: \n - ./regrid.py -c my_config.yaml \n \n - 2) Use questionary to convert template regrid_params.tpl to \n - regrid_params.yaml and then regrid. \n - ./regrid.py \n + print('''\nThere are two ways to use this script to remap restarts. \n + 1) Use an exsiting config file to remap: \n + ./remap_restarts.py -c my_config.yaml \n \n + 2) Use questionary to convert template remap_params.tpl to \n + remap_params.yaml and then remap. \n + ./remap_restarts.py \n \nHelp message: \n 1) Each individual script can be executed independently - 2) regrid_questions.py generates raw_answer.yaml - 3) regrid_params.py uses raw_answer.yaml and regrid_params.tpl as inputs and generates regrid_params.yaml - 4) regrid_upper.py uses regrid_params.yaml as input for regriding - 5) regrid_lake_landice_saltwater.py uses regrid_params.yaml as input for regriding - 6) regrid_catchANDcn.py uses regrid_params.yaml as input for regriding - 7) regrid_analysis.py uses regrid_params.yaml as input for regriding ''') + 2) remap_questions.py generates raw_answer.yaml + 3) remap_params.py uses raw_answer.yaml and remap_params.tpl as inputs and generates remap_params.yaml + 4) remap_upper.py uses remap_params.yaml as input for remapping + 5) remap_lake_landice_saltwater.py uses remap_params.yaml as input for remapping + 6) remap_catchANDcn.py uses remap_params.yaml as input for remapping + 7) remap_analysis.py uses remap_params.yaml as input for remapping ''') sys.exit(0) if opt in("-c", "--config_file"): config_yaml = arg if config_yaml == '': config = get_config_from_questionary() - params = regrid_params(config) + params = remap_params(config) params.convert_to_yaml() - config_yaml = 'regrid_params.yaml' + config_yaml = 'remap_params.yaml' with open(config_yaml, 'r') as f: for line in f.readlines(): @@ -70,19 +70,19 @@ def main(argv): sys.exit(0) # upper air upper = upperair(config_yaml) - upper.regrid() + upper.remap() # lake, landice and saltwater lls = lake_landice_saltwater(config_yaml) - lls.regrid() + lls.remap() # catchANDcn catch = catchANDcn(config_yaml) - catch.regrid() + catch.remap() # analysis ana = analysis(config_yaml) - ana.regrid() + ana.remap() if __name__ == '__main__' : main(sys.argv[1:]) diff --git a/GEOS_Util/post/regrid_py/regrid_upper.py b/GEOS_Util/post/remap_restart/remap_upper.py similarity index 94% rename from GEOS_Util/post/regrid_py/regrid_upper.py rename to GEOS_Util/post/remap_restart/remap_upper.py index 6c983907..340bbf99 100755 --- a/GEOS_Util/post/regrid_py/regrid_upper.py +++ b/GEOS_Util/post/remap_restart/remap_upper.py @@ -15,12 +15,12 @@ def __init__(self, params_file): stream = f.read() self.config = yaml.load(stream) - def regrid(self): + def remap(self): restarts_in = self.find_rst() if len(restarts_in) == 0: return - print( "\nRegridding upper air......\n") + print( "\nRemapping upper air......\n") config = self.config cwdir = os.getcwd() bindir = os.path.dirname(os.path.realpath(__file__)) @@ -101,14 +101,14 @@ def regrid(self): if NPE <= 532: QOS = "#SBATCH --qos=debug" CONSTR = "#SBATCH --constraint=" + config['slurm']['partition'] - log_name = out_dir+'/regrid_upper_log' + log_name = out_dir+'/remap_upper_log' - regrid_template="""#!/bin/csh -xf + remap_template="""#!/bin/csh -xf #!/bin/csh -xf #SBATCH --account={account} #SBATCH --time=1:00:00 #SBATCH --ntasks={NPE} -#SBATCH --job-name=regrid_upper +#SBATCH --job-name=remap_upper #SBATCH --output={log_name} {QOS} {CONSTR} @@ -188,15 +188,15 @@ def regrid(self): hydrostatic = config['input']['air']['hydrostatic'] nlevel = config['output']['air']['nlevel'] - regrid_upper_script = regrid_template.format(Bin=bindir, account = account, \ + 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,CONSTR = CONSTR, nlevel = nlevel, hydrostatic = hydrostatic) - script_name = './regrid_upper.j' + script_name = './remap_upper.j' upper = open(script_name,'wt') - upper.write(regrid_upper_script) + upper.write(remap_upper_script) upper.close() interactive = os.getenv('SLURM_JOB_ID', default = None) @@ -233,8 +233,8 @@ def regrid(self): print('\n Move ' + out_rst + ' to ' + out_dir+"/"+filename) shutil.move(out_rst, out_dir+"/"+filename) - print('\n Move regrid_upper.j to ' + out_dir) - shutil.move('regrid_upper.j', out_dir+"/regrid_upper.j") + print('\n Move remap_upper.j to ' + out_dir) + shutil.move('remap_upper.j', out_dir+"/remap_upper.j") print('cd ' + cwdir) os.chdir(cwdir) @@ -273,5 +273,5 @@ def find_rst(self): return restarts_in if __name__ == '__main__' : - air = upperair('regrid_params.yaml') - air.regrid() + air = upperair('remap_params.yaml') + air.remap() From c114d064cb0e0d6de93c7c4268300161610b791f Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang <52509753+weiyuan-jiang@users.noreply.github.com> Date: Mon, 13 Jun 2022 16:31:08 -0400 Subject: [PATCH 52/70] fix typo from 2800 to 2880 --- GEOS_Util/post/regrid_py/regrid_params.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GEOS_Util/post/regrid_py/regrid_params.py b/GEOS_Util/post/regrid_py/regrid_params.py index 95d84571..b95e01e8 100755 --- a/GEOS_Util/post/regrid_py/regrid_params.py +++ b/GEOS_Util/post/regrid_py/regrid_params.py @@ -533,7 +533,7 @@ def get_bcTag(self, tag, ogrid): xy = ogrid.upper().split('X') x = int(xy[0]) if x == 1440: bctag=bctag.replace('_Reynolds','_MERRA-2') - if x == 2800: + if x == 2880: bctag=bctag.replace('_Reynolds','_Ostia') bctag=bctag.replace('_M','_D') return bctag From c644906703cc6fac258cced5a9baf2f4429c5d1c Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Mon, 13 Jun 2022 21:30:11 -0400 Subject: [PATCH 53/70] add support without time in restart file names --- .../post/remap_restart/remap_catchANDcn.py | 13 +++++------ .../remap_lake_landice_saltwater.py | 7 ++++++ GEOS_Util/post/remap_restart/remap_params.py | 23 ++++++++++++++++--- GEOS_Util/post/remap_restart/remap_params.tpl | 1 + .../post/remap_restart/remap_questions.py | 4 +++- GEOS_Util/post/remap_restart/remap_upper.py | 7 ++++++ 6 files changed, 44 insertions(+), 11 deletions(-) diff --git a/GEOS_Util/post/remap_restart/remap_catchANDcn.py b/GEOS_Util/post/remap_restart/remap_catchANDcn.py index d72ec9b7..37daf2dc 100755 --- a/GEOS_Util/post/remap_restart/remap_catchANDcn.py +++ b/GEOS_Util/post/remap_restart/remap_catchANDcn.py @@ -23,14 +23,13 @@ def remap(self): in_rstfile = '' yyyymmddhh_ = str(self.config['input']['shared']['yyyymmddhh']) time = yyyymmddhh_[0:8]+'_'+yyyymmddhh_[8:10] - if model == 'catch' : - in_rstfile = glob.glob(rst_dir+'/*catch_*'+time+'*')[0] - if model == 'catchcnclm40' : - in_rstfile = glob.glob(rst_dir+'/*catchcnclm40_*'+time+'*')[0] - if model == 'catchcnclm45' : - in_rstfile = glob.glob(rst_dir+'/*catchcnclm45_*'+time+'*')[0] - if not in_rstfile: + in_rstfiles = glob.glob(rst_dir+'/*'+model+'_*'+time+'*') + if len(in_rstfiles) == 0: + print('\n try catchXX file without time stamp') + in_rstfiles = glob.glob(rst_dir+'/*'+model+'_*') + if len(in_rstfiles) == 0: return + in_rstfile = in_rstfiles[0] print("\nRemapping " + model + ".....\n") diff --git a/GEOS_Util/post/remap_restart/remap_lake_landice_saltwater.py b/GEOS_Util/post/remap_restart/remap_lake_landice_saltwater.py index 3f5bf55b..501e2e72 100755 --- a/GEOS_Util/post/remap_restart/remap_lake_landice_saltwater.py +++ b/GEOS_Util/post/remap_restart/remap_lake_landice_saltwater.py @@ -155,6 +155,13 @@ def find_rst(self): files = glob.glob(rst_dir+ '/*'+f+'*'+time+'*') if len(files) >0: restarts_in.append(files[0]) + if (len(restarts_in) == 0) : + print("\n try restart file names without time stamp\n") + for f in surf_restarts : + fname = rst_dir+ '/'+f + if os.path.exists(fname): + restarts_in.append(fname) + return restarts_in if __name__ == '__main__' : diff --git a/GEOS_Util/post/remap_restart/remap_params.py b/GEOS_Util/post/remap_restart/remap_params.py index e08dd9d9..4e3626be 100755 --- a/GEOS_Util/post/remap_restart/remap_params.py +++ b/GEOS_Util/post/remap_restart/remap_params.py @@ -249,7 +249,11 @@ def init_time_and_grid(self): time = self.ymd + '_'+self.hh files = glob.glob(rst_dir +'/*fvcore_*'+time+'*') if len(files) ==0 : - return + fname = rst_dir +'/fvcore_internal_rst' + if os.path.exists(fname) : + files.append(fname) + else: + return fvrst = os.path.dirname(os.path.realpath(__file__)) + '/fvrst.x -h ' cmd = fvrst + files[0] print(cmd +'\n') @@ -533,7 +537,7 @@ def get_bcTag(self, tag, ogrid): xy = ogrid.upper().split('X') x = int(xy[0]) if x == 1440: bctag=bctag.replace('_Reynolds','_MERRA-2') - if x == 2800: + if x == 2880: bctag=bctag.replace('_Reynolds','_Ostia') bctag=bctag.replace('_M','_D') return bctag @@ -546,7 +550,11 @@ def params_for_air(self, config_tpl): time = self.ymd + '_'+ self.hh files = glob.glob(rst_dir +'/*fvcore_*'+time+'*') if len(files) == 0 : - return config_tpl + fname_ = rst_dir +'/fvcore_internal_rst' + if os.path.exists(fname_) : + files.append(fname_) + else: + return config_tpl # get expid fname = os.path.basename(files[0]) expid = fname.split('fvcore')[0] @@ -594,14 +602,23 @@ def params_for_surface(self, config_tpl): rst_dir = self.common_in['rst_dir'] + '/' time = self.ymd + '_'+ self.hh files = glob.glob(rst_dir +'/*catch_*'+time+'*') + if (len(files)== 0) : + files = glob.glob(rst_dir +'/*catch_*') + if (len(files) > 0) : config_tpl['input']['surface']['catch_model'] = 'catch' files = glob.glob(rst_dir +'/*catchcnclm40_*'+time+'*') + if (len(files)== 0) : + files = glob.glob(rst_dir +'/*catchcnclm40_*') + if (len(files) > 0) : config_tpl['input']['surface']['catch_model'] = 'catchcnclm40' files = glob.glob(rst_dir +'/*catchcnclm45_*'+time+'*') + if (len(files)== 0) : + files = glob.glob(rst_dir +'/*catchcnclm45_*') + if (len(files) > 0) : config_tpl['input']['surface']['catch_model'] = 'catchcnclm45' diff --git a/GEOS_Util/post/remap_restart/remap_params.tpl b/GEOS_Util/post/remap_restart/remap_params.tpl index 2eee1516..bc5b7bd3 100644 --- a/GEOS_Util/post/remap_restart/remap_params.tpl +++ b/GEOS_Util/post/remap_restart/remap_params.tpl @@ -16,6 +16,7 @@ input: yyyymmddhh: surface: wemin: + # it supports three models: catch, catchcnclm40, catchcnclm45 catch_model: null output: diff --git a/GEOS_Util/post/remap_restart/remap_questions.py b/GEOS_Util/post/remap_restart/remap_questions.py index 65c16631..a36cfe2f 100755 --- a/GEOS_Util/post/remap_restart/remap_questions.py +++ b/GEOS_Util/post/remap_restart/remap_questions.py @@ -21,7 +21,9 @@ def has_fvcore(x): if len(files) ==1 : return True else: - print('\nDo not have fvcore for this date\n') + print('\nDo not have fvcore for this date\n try "fvcore_internal_rst"') + if os.path.exists(x['rst_dir']+'/fvcore_internal_rst'): + return True return False diff --git a/GEOS_Util/post/remap_restart/remap_upper.py b/GEOS_Util/post/remap_restart/remap_upper.py index 340bbf99..fe2b62e2 100755 --- a/GEOS_Util/post/remap_restart/remap_upper.py +++ b/GEOS_Util/post/remap_restart/remap_upper.py @@ -270,6 +270,13 @@ def find_rst(self): files = glob.glob(rst_dir+ '/*'+f+'*'+time+'*') if len(files) >0: restarts_in.append(files[0]) + if (len(restarts_in) == 0) : + print("\n try restart file names without time stamp\n") + for f in air_restarts : + fname = rst_dir+ '/'+f + if os.path.exists(fname): + restarts_in.append(fname) + return restarts_in if __name__ == '__main__' : From 804bf397047a818c02de0bfc26b218b61d55708f Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Tue, 14 Jun 2022 08:36:44 -0400 Subject: [PATCH 54/70] 1) default zoom 2) no time in file name 3)fix some bug --- .../post/remap_restart/remap_analysis.py | 2 +- .../remap_lake_landice_saltwater.py | 2 +- GEOS_Util/post/remap_restart/remap_params.py | 52 ++++------------- GEOS_Util/post/remap_restart/remap_params.tpl | 2 +- .../post/remap_restart/remap_questions.py | 55 +++++++++++------- GEOS_Util/post/remap_restart/remap_upper.py | 58 +++++++++---------- 6 files changed, 77 insertions(+), 94 deletions(-) diff --git a/GEOS_Util/post/remap_restart/remap_analysis.py b/GEOS_Util/post/remap_restart/remap_analysis.py index 2448088e..6a78f40e 100755 --- a/GEOS_Util/post/remap_restart/remap_analysis.py +++ b/GEOS_Util/post/remap_restart/remap_analysis.py @@ -133,7 +133,7 @@ def find_analysis(self): anasat = glob.glob(rst_dir + '/*ana_satb*') traks= glob.glob(rst_dir + '/*.trak.GDA.rst*') analysis_in = bkgs + sfcs + traks + anasat - return analysis_in + return list(dict.fromkeys(analysis_in)) if __name__ == '__main__' : ana = analysis('remap_params.yaml') diff --git a/GEOS_Util/post/remap_restart/remap_lake_landice_saltwater.py b/GEOS_Util/post/remap_restart/remap_lake_landice_saltwater.py index 501e2e72..b5530112 100755 --- a/GEOS_Util/post/remap_restart/remap_lake_landice_saltwater.py +++ b/GEOS_Util/post/remap_restart/remap_lake_landice_saltwater.py @@ -83,7 +83,7 @@ def remap(self): shutil.copy(out_tile_file, out_til) exe = bindir + '/mk_LakeLandiceSaltRestarts.x ' - zoom = config['output']['surface']['zoom'] + zoom = config['input']['surface']['zoom'] if (saltwater): cmd = exe + out_til + ' ' + in_til + ' InData/'+ saltwater + ' 0 ' + str(zoom) diff --git a/GEOS_Util/post/remap_restart/remap_params.py b/GEOS_Util/post/remap_restart/remap_params.py index 4e3626be..bd52e088 100755 --- a/GEOS_Util/post/remap_restart/remap_params.py +++ b/GEOS_Util/post/remap_restart/remap_params.py @@ -22,7 +22,7 @@ def __init__(self, config_from_question): #self.ana_in = config_from_question['input']['parameters']['ANALYSIS'] self.ana_out = config_from_question['output']['parameters']['ANALYSIS'] - self.init_time_and_grid() + self.init_time() self.init_tags() self.init_merra2() @@ -42,6 +42,7 @@ def __init__(self, config_from_question): config_tpl['input']['shared']['expid'] = self.common_in.get('expid') config_tpl['input']['shared']['yyyymmddhh'] = self.common_in['yyyymmddhh'] + config_tpl['output']['air']['nlevel'] = self.upper_out.get('nlevel') config_tpl['output']['shared']['agrid'] = self.common_out['agrid'] config_tpl['output']['shared']['ogrid'] = self.common_out['ogrid'] config_tpl['output']['shared']['out_dir'] = self.common_out['out_dir'] + '/' @@ -235,7 +236,7 @@ def init_tags(self): self.bcbase['discover_lt'] = "/discover/nobackup/ltakacs/bcs" self.bcbase['discover_couple'] = "/discover/nobackup/projects/gmao/ssd/aogcm/atmosphere_bcs" - def init_time_and_grid(self): + def init_time(self): ymdh = self.common_in.get('yyyymmddhh') self.yyyymm = ymdh[0:6] self.yyyy = ymdh[0:4] @@ -244,32 +245,6 @@ def init_time_and_grid(self): self.hh = ymdh[8:10] self.ymd = ymdh[0:8] - self.agrid_ = '' - rst_dir = self.common_in['rst_dir'] + '/' - time = self.ymd + '_'+self.hh - files = glob.glob(rst_dir +'/*fvcore_*'+time+'*') - if len(files) ==0 : - fname = rst_dir +'/fvcore_internal_rst' - if os.path.exists(fname) : - files.append(fname) - else: - return - fvrst = os.path.dirname(os.path.realpath(__file__)) + '/fvrst.x -h ' - cmd = fvrst + files[0] - print(cmd +'\n') - p = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE) - (output, err) = p.communicate() - p_status = p.wait() - ss = output.decode().split() - self.agrid_ = "C"+ss[0] # save for air parameter - lat = int(ss[0]) - lon = int(ss[1]) - if (lon != lat*6) : - sys.exit('This is not a cubed-sphere grid fvcore restart. Please contact SI team') - ymdh_ = str(ss[3]) + str(ss[4])[0:2] - if (ymdh_ != ymdh) : - print("Warning: The date in fvcore is different from the date you input\n") - def init_merra2(self): def get_grid_kind(grid): hgrd = {} @@ -553,18 +528,17 @@ def params_for_air(self, config_tpl): fname_ = rst_dir +'/fvcore_internal_rst' if os.path.exists(fname_) : files.append(fname_) - else: - return config_tpl + # get expid - fname = os.path.basename(files[0]) - expid = fname.split('fvcore')[0] - config_tpl['input']['shared']['expid'] = expid[0:-1] #remove the last '.' + if (len(files) >0) : + fname = os.path.basename(files[0]) + expid = fname.split('fvcore')[0] + config_tpl['input']['shared']['expid'] = expid[0:-1] #remove the last '.' - config_tpl['input']['shared']['agrid'] = self.agrid_ - self.common_in['agrid'] = self.agrid_ + agrid_ = self.common_in['agrid'] if self.common_in['ogrid'] == 'CS' : - config_tpl['input']['shared']['ogrid'] = self.agrid_ - self.common_in['ogrid'] = self.agrid_ + config_tpl['input']['shared']['ogrid'] = agrid_ + self.common_in['ogrid'] = agrid_ ogrid = config_tpl['input']['shared']['ogrid'] tagout = self.common_out['tag'] @@ -575,8 +549,6 @@ def params_for_air(self, config_tpl): if tagrank >=12 : config_tpl['input']['air']['drymass'] = 1 - config_tpl['output']['air']['nlevel'] = self.upper_out['nlevel'] - return config_tpl def options_for_slurm(self, config_tpl): @@ -595,7 +567,7 @@ def params_for_surface(self, config_tpl): config_tpl['output']['surface']['surflay'] = 50. if tagrank >= self.tagsRank["Icarus_Reynolds"]: config_tpl['output']['surface']['split_saltwater'] = True - config_tpl['output']['surface']['zoom']= self.surf_in['zoom'] + 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['wemout'] diff --git a/GEOS_Util/post/remap_restart/remap_params.tpl b/GEOS_Util/post/remap_restart/remap_params.tpl index bc5b7bd3..c6e0806d 100644 --- a/GEOS_Util/post/remap_restart/remap_params.tpl +++ b/GEOS_Util/post/remap_restart/remap_params.tpl @@ -15,6 +15,7 @@ input: rst_dir: yyyymmddhh: surface: + zoom: wemin: # it supports three models: catch, catchcnclm40, catchcnclm45 catch_model: null @@ -29,7 +30,6 @@ output: air: nlevel: surface: - zoom: split_saltwater: false surflay: 20. wemin: diff --git a/GEOS_Util/post/remap_restart/remap_questions.py b/GEOS_Util/post/remap_restart/remap_questions.py index a36cfe2f..99998946 100755 --- a/GEOS_Util/post/remap_restart/remap_questions.py +++ b/GEOS_Util/post/remap_restart/remap_questions.py @@ -14,19 +14,21 @@ import questionary import glob -def has_fvcore(x): +def fvcore_name(x): ymdh = x['yyyymmddhh'] time = ymdh[0:8] + '_'+ymdh[8:10] files = glob.glob(x['rst_dir']+'/*fvcore_*'+time+'*') if len(files) ==1 : - return True + fname = files[0] + print('\nFound ' + fname) + return fname else: - print('\nDo not have fvcore for this date\n try "fvcore_internal_rst"') - if os.path.exists(x['rst_dir']+'/fvcore_internal_rst'): - return True + fname = x['rst_dir']+'/fvcore_internal_rst' + if os.path.exists(fname): + print('\nFound ' + fname) + return fname return False - def ask_common_in(): questions = [ { @@ -52,7 +54,7 @@ def ask_common_in(): "message": "Enter input atmospheric grid: \n C12 C180 C1000 \n C24 C360 C1440 \n C48 C500 C2880 \n C90 C720 C5760 \n ", "default": 'C360', # if it is merra-2 or has_fvcore, agrid is deduced - "when": lambda x: not x['MERRA-2'] and not has_fvcore(x), + "when": lambda x: not x['MERRA-2'] and not fvcore_name(x), }, { "type": "select", @@ -159,12 +161,6 @@ def ask_common_out(): "message": "Enter GCM or DAS tag for new restarts: \n \ Sample GCM tags \n \ --------------- \n \ -F14 : Fortuna-1_4 ......... Fortuna-1_4_p1 \n \ -F20 : Fortuna-2_0 ......... Fortuna-2_0 \n \ -F21 : Fortuna-2_1 ......... Fortuna-2_5_pp2 \n \ -G10 : Ganymed-1_0 ......... Ganymed-1_0_BETA4 \n \ -G10p : Ganymed-1_0_p1 ...... Ganymed-1_0_p6 \n \ -G20 : Ganymed-2_0 ......... Ganymed-2_1_p6 \n \ G30 : Ganymed-3_0 ......... Ganymed-3_0_p1 \n \ G40 : Ganymed-4_0 ......... Heracles-5_4_p3 \n \ ICA : Icarus .............. Jason \n \ @@ -174,12 +170,6 @@ def ask_common_out(): \n \ Sample DAS tags \n \ --------------- \n \ -214 : GEOSdas-2_1_4 ....... GEOSdas-2_1_4-m4 \n \ -540 : GEOSadas-5_4_0 ...... GEOSadas-5_5_3 \n \ -561 : GEOSadas-5_6_1 ...... GEOSadas-5_7_3_p2 \n \ -580 : GEOSadas-5_8_0 ...... GEOSadas-5_9_1 \n \ -591p : GEOSadas-5_9_1_p1 ... GEOSadas-5_9_1_p9 \n \ -5A0 : GEOSadas-5_10_0 ..... GEOSadas-5_10_0_p1 \n \ 5B0 : GEOSadas-5_10_0_p2 .. GEOSadas-5_11_0 \n \ 512 : GEOSadas-5_12_2 ..... GEOSadas-5_16_5\n \ 517 : GEOSadas-5_17_0 ..... GEOSadas-5_24_0_p1\n \ @@ -256,6 +246,31 @@ def ask_surface_in(common_in): wemin_default = '26' tag = common_in.get('tag') if tag in ['INL','GITNL', '525'] : wemin_default = '13' + + zoom_default = '8' + fvcore = fvcore_name(common_in) + if fvcore : + fvrst = os.path.dirname(os.path.realpath(__file__)) + '/fvrst.x -h ' + cmd = fvrst + fvcore + print(cmd +'\n') + p = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE) + (output, err) = p.communicate() + p_status = p.wait() + ss = output.decode().split() + common_in['agrid'] = "C"+ss[0] # save for air parameter + lat = int(ss[0]) + lon = int(ss[1]) + if (lon != lat*6) : + sys.exit('This is not a cubed-sphere grid fvcore restart. Please contact SI team') + ymdh = common_in.get('yyyymmddhh') + ymdh_ = str(ss[3]) + str(ss[4])[0:2] + if (ymdh_ != ymdh) : + print("Warning: The date in fvcore is different from the date you input\n") + zoom = lat /90.0 + zoom_default = str(int(zoom)) + if zoom < 1 : zoom_default = '1' + if zoom > 8 : zoom_default = '8' + questions = [ { "type": "text", @@ -267,7 +282,7 @@ def ask_surface_in(common_in): "type": "text", "name": "zoom", "message": "What is value of zoom [1-8]?", - "default": '8' + "default": zoom_default }, ] return questionary.prompt(questions) diff --git a/GEOS_Util/post/remap_restart/remap_upper.py b/GEOS_Util/post/remap_restart/remap_upper.py index fe2b62e2..4f305857 100755 --- a/GEOS_Util/post/remap_restart/remap_upper.py +++ b/GEOS_Util/post/remap_restart/remap_upper.py @@ -16,6 +16,28 @@ def __init__(self, params_file): self.config = yaml.load(stream) def remap(self): + self.air_restarts =["fvcore_internal_rst" , + "moist_internal_rst" , + "agcm_import_rst" , + "agcm_internal_rst" , + "carma_internal_rst" , + "achem_internal_rst" , + "geoschemchem_internal_rst", + "gmichem_internal_rst" , + "gocart_internal_rst" , + "hemco_internal_rst" , + "mam_internal_rst" , + "matrix_internal_rst" , + "pchem_internal_rst" , + "stratchem_internal_rst" , + "ss_internal_rst" , + "du_internal_rst" , + "cabr_internal_rst" , + "cabc_internal_rst" , + "caoc_internal_rst" , + "ni_internal_rst" , + "su_internal_rst" , + "tr_internal_rst"] restarts_in = self.find_rst() if len(restarts_in) == 0: return @@ -40,7 +62,7 @@ def remap(self): print( "cd " + tmpdir) os.chdir(tmpdir) - print('\nUpper air restart file names changed from "_rst" to "_restart_in" \n') + print('\nUpper air restart file names link from "_rst" to "_restart_in" \n') types = 'z.bin' type_str = subprocess.check_output(['file','-b', restarts_in[0]]) @@ -51,11 +73,8 @@ def remap(self): suffix = yyyymmddhh_[0:8]+'_'+yyyymmddhh_[8:10]+ types for rst in restarts_in : - fs = os.path.basename(rst).split('.') - f = fs[0] - if (len(fs) >=2): f = fs[1] - f = f.replace('_rst','_restart_in') - cmd = '/bin/cp ' + rst + ' ' + f + f = os.path.basename(rst).split('_rst')[0].split('.')[-1]+'_restart_in' + cmd = '/bin/ln -s ' + rst + ' ' + f print('\n'+cmd) subprocess.call(shlex.split(cmd)) @@ -239,40 +258,17 @@ def remap(self): os.chdir(cwdir) def find_rst(self): - air_restarts =["fvcore_internal_rst" , - "moist_internal_rst" , - "agcm_import_rst" , - "agcm_internal_rst" , - "carma_internal_rst" , - "achem_internal_rst" , - "geoschemchem_internal_rst", - "gmichem_internal_rst" , - "gocart_internal_rst" , - "hemco_internal_rst" , - "mam_internal_rst" , - "matrix_internal_rst" , - "pchem_internal_rst" , - "stratchem_internal_rst" , - "ss_internal_rst" , - "du_internal_rst" , - "cabr_internal_rst" , - "cabc_internal_rst" , - "caoc_internal_rst" , - "ni_internal_rst" , - "su_internal_rst" , - "tr_internal_rst"] - rst_dir = self.config['input']['shared']['rst_dir'] yyyymmddhh_ = str(self.config['input']['shared']['yyyymmddhh']) time = yyyymmddhh_[0:8]+'_'+yyyymmddhh_[8:10] restarts_in=[] - for f in air_restarts : + for f in self.air_restarts : files = glob.glob(rst_dir+ '/*'+f+'*'+time+'*') if len(files) >0: restarts_in.append(files[0]) if (len(restarts_in) == 0) : print("\n try restart file names without time stamp\n") - for f in air_restarts : + for f in self.air_restarts : fname = rst_dir+ '/'+f if os.path.exists(fname): restarts_in.append(fname) From ccd8662e74306206a3efc7a3a4f52e27fb71bf83 Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Tue, 14 Jun 2022 14:11:30 -0400 Subject: [PATCH 55/70] do not use debug qos when #core>532 --- GEOS_Util/post/remap_restart/remap_upper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GEOS_Util/post/remap_restart/remap_upper.py b/GEOS_Util/post/remap_restart/remap_upper.py index 4f305857..bb5cba87 100755 --- a/GEOS_Util/post/remap_restart/remap_upper.py +++ b/GEOS_Util/post/remap_restart/remap_upper.py @@ -117,7 +117,7 @@ def remap(self): NPE = 5400; nwrit= 6 QOS = "#SBATCH --qos="+config['slurm']['qos'] - if NPE <= 532: QOS = "#SBATCH --qos=debug" + if NPE > 532: QOS = "###" + QOS CONSTR = "#SBATCH --constraint=" + config['slurm']['partition'] log_name = out_dir+'/remap_upper_log' From 8e20e1da73198eab1e2797556a86adc17121c106 Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Tue, 14 Jun 2022 14:29:49 -0400 Subject: [PATCH 56/70] correct the name partition to constraint --- GEOS_Util/post/remap_restart/remap_params.py | 2 +- GEOS_Util/post/remap_restart/remap_params.tpl | 2 +- GEOS_Util/post/remap_restart/remap_questions.py | 6 +++--- GEOS_Util/post/remap_restart/remap_upper.py | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/GEOS_Util/post/remap_restart/remap_params.py b/GEOS_Util/post/remap_restart/remap_params.py index bd52e088..aa8726fb 100755 --- a/GEOS_Util/post/remap_restart/remap_params.py +++ b/GEOS_Util/post/remap_restart/remap_params.py @@ -554,7 +554,7 @@ def params_for_air(self, 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'] + config_tpl['slurm']['constraint'] = self.slurm_options['constraint'] return config_tpl def params_for_surface(self, config_tpl): diff --git a/GEOS_Util/post/remap_restart/remap_params.tpl b/GEOS_Util/post/remap_restart/remap_params.tpl index c6e0806d..eeb8b315 100644 --- a/GEOS_Util/post/remap_restart/remap_params.tpl +++ b/GEOS_Util/post/remap_restart/remap_params.tpl @@ -41,4 +41,4 @@ output: slurm: account: qos: - partition: + constraint: diff --git a/GEOS_Util/post/remap_restart/remap_questions.py b/GEOS_Util/post/remap_restart/remap_questions.py index 99998946..99351c6f 100755 --- a/GEOS_Util/post/remap_restart/remap_questions.py +++ b/GEOS_Util/post/remap_restart/remap_questions.py @@ -340,9 +340,9 @@ def ask_slurm_options(): }, { "type": "select", - "name": "partition", - "message": "partition?", - "choices": ['hasw', 'sky'], + "name": "constraint", + "message": "constraint?", + "choices": ['hasw', 'sky', 'cas'], }, ] return questionary.prompt(questions) diff --git a/GEOS_Util/post/remap_restart/remap_upper.py b/GEOS_Util/post/remap_restart/remap_upper.py index bb5cba87..6c12a6e3 100755 --- a/GEOS_Util/post/remap_restart/remap_upper.py +++ b/GEOS_Util/post/remap_restart/remap_upper.py @@ -118,7 +118,7 @@ def remap(self): QOS = "#SBATCH --qos="+config['slurm']['qos'] if NPE > 532: QOS = "###" + QOS - CONSTR = "#SBATCH --constraint=" + config['slurm']['partition'] + CONSTR = "#SBATCH --constraint=" + config['slurm']['constraint'] log_name = out_dir+'/remap_upper_log' From 507da9b1ad52ac568bc8641b4b4f3db3cf7e3ccc Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Wed, 22 Jun 2022 08:36:31 -0400 Subject: [PATCH 57/70] choose a directory based on "-" --- GEOS_Util/post/remap_restart/remap_params.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/GEOS_Util/post/remap_restart/remap_params.py b/GEOS_Util/post/remap_restart/remap_params.py index aa8726fb..8d5e2efd 100755 --- a/GEOS_Util/post/remap_restart/remap_params.py +++ b/GEOS_Util/post/remap_restart/remap_params.py @@ -498,11 +498,18 @@ def get_name_with_grid( grid, names, a_o): gridID = get_name_with_grid(ogrid_, anames, 'o') if len(gridID) == 0 : exit("cannot find the grid string: " + bcdir) + g = '' + if len(gridID) == 1 : g = gridID[0] if len(gridID) >=2 : print("find too many grid strings in " + bcdir) print(" gridIDs found", gridID) - print(" pick the first one " + gridID[0]) - return gridID[0] + for g_ in gridId: + if g_.count('_') == 1 : + g = g_ + #WY note, found many string in couple model + print(" pick the first directory with only one '_' " + g) + break + return g def get_bcTag(self, tag, ogrid): bctag = self.bcsTag[tag] From ee1cf0f0dce748b37a8cecf5bd051c43b4c0fa61 Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Wed, 22 Jun 2022 16:00:09 -0400 Subject: [PATCH 58/70] increase NPE for upper air --- GEOS_Util/post/remap_restart/remap_upper.py | 37 +++++++++------------ 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/GEOS_Util/post/remap_restart/remap_upper.py b/GEOS_Util/post/remap_restart/remap_upper.py index 6c12a6e3..03266150 100755 --- a/GEOS_Util/post/remap_restart/remap_upper.py +++ b/GEOS_Util/post/remap_restart/remap_upper.py @@ -99,9 +99,9 @@ def remap(self): else: exit("Only support cs grid so far") - if (imout <=90): + if (imout <90): NPE = 12; nwrit = 1 - elif (imout==180): + elif (imout<=180): NPE = 24; nwrit = 1 elif (imout<=500): NPE = 96; nwrit = 1 @@ -144,29 +144,22 @@ def remap(self): if ($?I_MPI_ROOT) then # intel scaling suggestions #-------------------------- - - setenv I_MPI_DAPL_UD on - - setenv DAPL_UCM_CQ_SIZE 4096 - setenv DAPL_UCM_QP_SIZE 4096 - - setenv I_MPI_DAPL_UD_SEND_BUFFER_NUM 4096 - setenv I_MPI_DAPL_UD_RECV_BUFFER_NUM 4096 - setenv I_MPI_DAPL_UD_ACK_SEND_POOL_SIZE 4096 - setenv I_MPI_DAPL_UD_ACK_RECV_POOL_SIZE 4096 - setenv I_MPI_DAPL_UD_RNDV_EP_NUM 2 - setenv I_MPI_DAPL_UD_REQ_EVD_SIZE 2000 - - setenv DAPL_UCM_REP_TIME 2000 - setenv DAPL_UCM_RTU_TIME 2000 - setenv DAPL_UCM_RETRY 7 - setenv DAPL_ACK_RETRY 7 - setenv DAPL_ACK_TIMER 20 - setenv DAPL_UCM_RETRY 10 - setenv DAPL_ACK_RETRY 10 + setenv I_MPI_ADJUST_ALLREDUCE 12 + setenv I_MPI_ADJUST_GATHERV 3 + + setenv I_MPI_SHM_HEAP_VSIZE 512 + setenv PSM2_MEMORY large + setenv I_MPI_EXTRA_FILESYSTEM 1 + setenv I_MPI_EXTRA_FILESYSTEM_FORCE gpfs + setenv ROMIO_FSTYPE_FORCE "gpfs:" else if ($?MVAPICH2) then + setenv MV2_ENABLE_AFFINITY 0 + setenv MV2_ENABLE_AFFINITY 0 + setenv SLURM_DISTRIBUTION block + setenv MV2_MPIRUN_TIMEOUT 100 + setenv MV2_GATHERV_SSEND_THRESHOLD 256 endif set infiles = () From 26f8a2740d99aa3779b9d865967407ffd017409e Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Fri, 24 Jun 2022 13:04:04 -0400 Subject: [PATCH 59/70] fix typo --- GEOS_Util/post/remap_restart/remap_params.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GEOS_Util/post/remap_restart/remap_params.py b/GEOS_Util/post/remap_restart/remap_params.py index 8d5e2efd..29ca6dda 100755 --- a/GEOS_Util/post/remap_restart/remap_params.py +++ b/GEOS_Util/post/remap_restart/remap_params.py @@ -503,7 +503,7 @@ def get_name_with_grid( grid, names, a_o): if len(gridID) >=2 : print("find too many grid strings in " + bcdir) print(" gridIDs found", gridID) - for g_ in gridId: + for g_ in gridID: if g_.count('_') == 1 : g = g_ #WY note, found many string in couple model From b87fdbf94f10d6c74a92ff126d0ef087e2c63725 Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Mon, 27 Jun 2022 10:45:11 -0400 Subject: [PATCH 60/70] make tag selection consistent --- GEOS_Util/post/remap_restart/remap_params.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/GEOS_Util/post/remap_restart/remap_params.py b/GEOS_Util/post/remap_restart/remap_params.py index 29ca6dda..e7f64295 100755 --- a/GEOS_Util/post/remap_restart/remap_params.py +++ b/GEOS_Util/post/remap_restart/remap_params.py @@ -146,7 +146,7 @@ def init_tags(self): # BCS Tags: Ganymed-1_0_Reynolds and Ganymed-1_0_Ostia #----------------------------------------------------- G30 = ( 'G30', 'Ganymed-3_0', 'Ganymed-3_0_p1' ) - D5B0 = ( 'D5B0', 'GEOSadas-5_10_0_p2', 'GEOSadas-5_11_0' ) + D5B0 = ( '5B0', 'GEOSadas-5_10_0_p2', 'GEOSadas-5_11_0' ) # BCS Tags: Ganymed-4_0_Reynolds, Ganymed-4_0_MERRA-2, and Ganymed-4_0_Ostia #--------------------------------------------------------------------------- @@ -154,7 +154,7 @@ def init_tags(self): 'Ganymed-4_1', 'Heracles-1_0', 'Heracles-1_1', 'Heracles-2_0', 'Heracles-2_1', 'Heracles-3_0', 'Heracles-4_0', 'Heracles-5_4_p3' ) - D512 = ( 'D512', 'GEOSadas-5_12_2', 'GEOSadas-5_12_4', + D512 = ( '512', 'GEOSadas-5_12_2', 'GEOSadas-5_12_4', 'GEOSadas-5_12_4_p1', 'GEOSadas-5_12_4_p2', 'GEOSadas-5_12_4_p3', 'GEOSadas-5_12_5', 'GEOSadas-5_13_0_p1', 'GEOSadas-5_13_0_p2', 'GEOSadas-5_13_1', 'GEOSadas-5_16_5' ) @@ -162,7 +162,7 @@ def init_tags(self): # BCS Tags: Icarus (New Land Parameters, New Topography) #--------------------------------------------------------------------------- ICA = ( 'ICA', 'Icarus', 'Jason' ) - D517 = ( 'D517', 'GEOSadas-5_17_0', 'GEOSadas-5_17_1', 'GEOSadas-5_18_0', + D517 = ( '517', 'GEOSadas-5_17_0', 'GEOSadas-5_17_1', 'GEOSadas-5_18_0', 'GEOSadas-5_18_1', 'GEOSadas-5_18_2', 'GEOSadas-5_18_3', 'GEOSadas-5_18_3_p1', 'GEOSadas-5_19_0', 'GEOSadas-5_20_0', 'GEOSadas-5_20_0_p1', 'GEOSadas-5_20_0_p2', 'GEOSadas-5_21_0', From 0353d83d1cfcf9119466227dbb9e19549ce4043b Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Tue, 28 Jun 2022 14:46:09 -0400 Subject: [PATCH 61/70] 1) type for link, 1)zoom default for merra2 --- GEOS_Util/post/remap_restart/remap_questions.py | 4 +++- GEOS_Util/post/remap_restart/remap_upper.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/GEOS_Util/post/remap_restart/remap_questions.py b/GEOS_Util/post/remap_restart/remap_questions.py index 99351c6f..77e1014d 100755 --- a/GEOS_Util/post/remap_restart/remap_questions.py +++ b/GEOS_Util/post/remap_restart/remap_questions.py @@ -270,7 +270,9 @@ def ask_surface_in(common_in): zoom_default = str(int(zoom)) if zoom < 1 : zoom_default = '1' if zoom > 8 : zoom_default = '8' - + if common_in['MERRA-2'] : + zoom_default = '2' + questions = [ { "type": "text", diff --git a/GEOS_Util/post/remap_restart/remap_upper.py b/GEOS_Util/post/remap_restart/remap_upper.py index 03266150..2dfc881e 100755 --- a/GEOS_Util/post/remap_restart/remap_upper.py +++ b/GEOS_Util/post/remap_restart/remap_upper.py @@ -176,7 +176,7 @@ def remap(self): set interp_restartsX = {Bin}/interp_restarts.x if ( $#infiles ) then set ioflag = "-input_files $infiles -output_files $outfils" - set ftype = `file -b --mime-type fvcore_internal_restart_in` + set ftype = `file -Lb --mime-type fvcore_internal_restart_in` if ($ftype =~ *stream*) then set interp_restartsX = {Bin}/interp_restarts_bin.x endif From a78fc3d25a61e0e1b5352b6f567fe37a5842c03c Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Wed, 29 Jun 2022 15:48:43 -0400 Subject: [PATCH 62/70] 1)add choice for remap 2) copy yaml to out_dir --- GEOS_Util/post/remap_restart/remap_analysis.py | 8 ++++++++ GEOS_Util/post/remap_restart/remap_catchANDcn.py | 11 +++++++++++ .../remap_restart/remap_lake_landice_saltwater.py | 11 +++++++++++ GEOS_Util/post/remap_restart/remap_params.py | 3 +++ GEOS_Util/post/remap_restart/remap_params.tpl | 6 ++++++ GEOS_Util/post/remap_restart/remap_questions.py | 14 +++++++++++++- GEOS_Util/post/remap_restart/remap_upper.py | 11 ++++++++++- 7 files changed, 62 insertions(+), 2 deletions(-) diff --git a/GEOS_Util/post/remap_restart/remap_analysis.py b/GEOS_Util/post/remap_restart/remap_analysis.py index 6a78f40e..9b5511b1 100755 --- a/GEOS_Util/post/remap_restart/remap_analysis.py +++ b/GEOS_Util/post/remap_restart/remap_analysis.py @@ -22,6 +22,14 @@ def __init__(self, params_file): with open(params_file, 'r') as f: stream = f.read() self.config = yaml.load(stream) + f = os.path.basename(params_file) + out_dir = self.config['output']['shared']['out_dir'] + if not os.path.exists(out_dir) : os.makedirs(out_dir) + dest = out_dir+'/'+f + try: + shutil.copy(params_file, dest) + except shutil.SameFileError: + pass def remap(self): config = self.config diff --git a/GEOS_Util/post/remap_restart/remap_catchANDcn.py b/GEOS_Util/post/remap_restart/remap_catchANDcn.py index 37daf2dc..03924ba7 100755 --- a/GEOS_Util/post/remap_restart/remap_catchANDcn.py +++ b/GEOS_Util/post/remap_restart/remap_catchANDcn.py @@ -15,8 +15,19 @@ def __init__(self, params_file): with open(params_file, 'r') as f: stream = f.read() self.config = yaml.load(stream) + f = os.path.basename(params_file) + out_dir = self.config['output']['shared']['out_dir'] + if not os.path.exists(out_dir) : os.makedirs(out_dir) + dest = out_dir+'/'+f + try: + shutil.copy(params_file, dest) + except shutil.SameFileError: + pass def remap(self): + if not self.config['output']['surface']['remap_catch']: + return + config = self.config rst_dir = config['input']['shared']['rst_dir'] model = config['input']['surface']['catch_model'] diff --git a/GEOS_Util/post/remap_restart/remap_lake_landice_saltwater.py b/GEOS_Util/post/remap_restart/remap_lake_landice_saltwater.py index b5530112..ee8222ec 100755 --- a/GEOS_Util/post/remap_restart/remap_lake_landice_saltwater.py +++ b/GEOS_Util/post/remap_restart/remap_lake_landice_saltwater.py @@ -14,8 +14,19 @@ def __init__(self, params_file): with open(params_file, 'r') as f: stream = f.read() self.config = yaml.load(stream) + f = os.path.basename(params_file) + out_dir = self.config['output']['shared']['out_dir'] + if not os.path.exists(out_dir) : os.makedirs(out_dir) + dest = out_dir+'/'+f + try: + shutil.copy(params_file, dest) + except shutil.SameFileError: + pass def remap(self): + if not self.config['output']['surface']['remap_water']: + return + restarts_in = self.find_rst() if len(restarts_in) == 0: return diff --git a/GEOS_Util/post/remap_restart/remap_params.py b/GEOS_Util/post/remap_restart/remap_params.py index e7f64295..ef06eddb 100755 --- a/GEOS_Util/post/remap_restart/remap_params.py +++ b/GEOS_Util/post/remap_restart/remap_params.py @@ -43,6 +43,9 @@ def __init__(self, config_from_question): config_tpl['input']['shared']['yyyymmddhh'] = self.common_in['yyyymmddhh'] config_tpl['output']['air']['nlevel'] = self.upper_out.get('nlevel') + 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']['out_dir'] = self.common_out['out_dir'] + '/' diff --git a/GEOS_Util/post/remap_restart/remap_params.tpl b/GEOS_Util/post/remap_restart/remap_params.tpl index eeb8b315..d08caee7 100644 --- a/GEOS_Util/post/remap_restart/remap_params.tpl +++ b/GEOS_Util/post/remap_restart/remap_params.tpl @@ -28,11 +28,17 @@ output: ogrid: out_dir: air: + # remap upper air or not + remap: true nlevel: surface: split_saltwater: false surflay: 20. wemin: + # remap lake, saltwater, landicet + remap_water: true + # remap catch(cn) + remap_catch: true analysis: bkg: true aqua: False diff --git a/GEOS_Util/post/remap_restart/remap_questions.py b/GEOS_Util/post/remap_restart/remap_questions.py index 77e1014d..43eca74e 100755 --- a/GEOS_Util/post/remap_restart/remap_questions.py +++ b/GEOS_Util/post/remap_restart/remap_questions.py @@ -35,7 +35,7 @@ def ask_common_in(): "type": "confirm", "name": "MERRA-2", "message": "Would you like to get restarts from MERRA-2 archive?", - "default": False + "default": False, }, { "type": "path", @@ -240,6 +240,12 @@ def ask_upper_out(): "message": "Enter new atmospheric levels: (71 72 91 127 132 137 144 181)", "default": "72", }, + { + "type": "confirm", + "name": "remap", + "message": "Would you like to remap upper air?", + "default": True, + }, ] return questionary.prompt(questions) def ask_surface_in(common_in): @@ -300,6 +306,12 @@ def ask_surface_out(common_out): "message": "What is value of Wemout?", "default": wemout_default }, + { + "type": "confirm", + "name": "remap", + "message": "Would you like to remap surface?", + "default": True, + }, ] return questionary.prompt(questions) diff --git a/GEOS_Util/post/remap_restart/remap_upper.py b/GEOS_Util/post/remap_restart/remap_upper.py index 2dfc881e..8c783366 100755 --- a/GEOS_Util/post/remap_restart/remap_upper.py +++ b/GEOS_Util/post/remap_restart/remap_upper.py @@ -14,8 +14,17 @@ def __init__(self, params_file): with open(params_file, 'r') as f: stream = f.read() self.config = yaml.load(stream) - + f = os.path.basename(params_file) + out_dir = self.config['output']['shared']['out_dir'] + if not os.path.exists(out_dir) : os.makedirs(out_dir) + dest = out_dir+'/'+f + try: + shutil.copy(params_file, dest) + except shutil.SameFileError: + pass def remap(self): + if not self.config['output']['air']['remap'] : + return self.air_restarts =["fvcore_internal_rst" , "moist_internal_rst" , "agcm_import_rst" , From d254debd0494bd221f5d8e7975d13ba9524b7e55 Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Fri, 1 Jul 2022 09:02:26 -0400 Subject: [PATCH 63/70] re-phrase question for MERRA-2 --- GEOS_Util/post/remap_restart/remap_questions.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/GEOS_Util/post/remap_restart/remap_questions.py b/GEOS_Util/post/remap_restart/remap_questions.py index 43eca74e..8f0066b0 100755 --- a/GEOS_Util/post/remap_restart/remap_questions.py +++ b/GEOS_Util/post/remap_restart/remap_questions.py @@ -34,13 +34,20 @@ def ask_common_in(): { "type": "confirm", "name": "MERRA-2", - "message": "Would you like to get restarts from MERRA-2 archive?", + "message": "Would you like to remap from MERRA-2 archive?", "default": False, }, { "type": "path", "name": "rst_dir", - "message": "Enter the directory containing restart files to be remapped: \n (If it is MERRA-2, files from achives will be copied to this directory automatically). \n", + "message": "Enter the directory containing restart files to be remapped:", + "when": lambda x: not x['MERRA-2'], + }, + { + "type": "path", + "name": "rst_dir", + "message": "Enter the directory MERRA-2 archive files to be copied to: ", + "when": lambda x: x['MERRA-2'], }, { "type": "text", From dd2c48f21b8694aa47f6138f7ea0a168e0937b4b Mon Sep 17 00:00:00 2001 From: Rolf Reichle <54944691+gmao-rreichle@users.noreply.github.com> Date: Fri, 1 Jul 2022 09:24:03 -0400 Subject: [PATCH 64/70] Minor edits of remap_questions.py message strings --- GEOS_Util/post/remap_restart/remap_questions.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/GEOS_Util/post/remap_restart/remap_questions.py b/GEOS_Util/post/remap_restart/remap_questions.py index 8f0066b0..ae487419 100755 --- a/GEOS_Util/post/remap_restart/remap_questions.py +++ b/GEOS_Util/post/remap_restart/remap_questions.py @@ -34,7 +34,7 @@ def ask_common_in(): { "type": "confirm", "name": "MERRA-2", - "message": "Would you like to remap from MERRA-2 archive?", + "message": "Would you like to remap archived MERRA-2 restarts?", "default": False, }, { @@ -46,13 +46,13 @@ def ask_common_in(): { "type": "path", "name": "rst_dir", - "message": "Enter the directory MERRA-2 archive files to be copied to: ", + "message": "Enter a directory to which the archived MERRA-2 archive files can be copied: ", "when": lambda x: x['MERRA-2'], }, { "type": "text", "name": "yyyymmddhh", - "message": "What time would you like to remap from?(must be 10 digits: yyyymmddhh)", + "message": "From what restart date/time would you like to remap? (must be 10 digits: yyyymmddhh)", "validate": lambda text: len(text)==10 , }, { From 5c33f3f7a071cb83677b1c9813c0a972c7e79640 Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Fri, 1 Jul 2022 15:50:17 -0400 Subject: [PATCH 65/70] correct topo files --- GEOS_Util/post/remap_restart/remap_params.py | 2 +- GEOS_Util/post/remap_restart/remap_upper.py | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/GEOS_Util/post/remap_restart/remap_params.py b/GEOS_Util/post/remap_restart/remap_params.py index ef06eddb..99162d7f 100755 --- a/GEOS_Util/post/remap_restart/remap_params.py +++ b/GEOS_Util/post/remap_restart/remap_params.py @@ -336,7 +336,7 @@ def get_grid_kind(grid): if (get_grid_kind(agrid_in.upper()) == get_grid_kind(agrid_out.upper())): print(" No need to remap anaylysis file according to air grid in and out") - return + #return anafiles=[] for h in [3,4,5,6,7,8,9]: diff --git a/GEOS_Util/post/remap_restart/remap_upper.py b/GEOS_Util/post/remap_restart/remap_upper.py index 8c783366..fbbc86c9 100755 --- a/GEOS_Util/post/remap_restart/remap_upper.py +++ b/GEOS_Util/post/remap_restart/remap_upper.py @@ -89,18 +89,18 @@ def remap(self): # link topo file topoin = glob.glob(in_bcsdir+'/topo_DYN_ave*')[0] - cmd = '/bin/cp ' + topoin + ' .' + cmd = '/bin/ln -s ' + topoin + ' .' print('\n'+cmd) subprocess.call(shlex.split(cmd)) topoout = glob.glob(out_bcsdir+'/topo_DYN_ave*')[0] - cmd = '/bin/cp ' + topoout + ' .' - print('\n'+cmd) - subprocess.call(shlex.split(cmd)) - fname = os.path.basename(topoout) - cmd = '/bin/ln -s ' + fname + ' topo_dynave.data' + cmd = '/bin/ln -s ' + topoout + ' topo_dynave.data' print('\n'+cmd) subprocess.call(shlex.split(cmd)) + #fname = os.path.basename(topoout) + #cmd = '/bin/ln -s ' + fname + ' topo_dynave.data' + #print('\n'+cmd) + #subprocess.call(shlex.split(cmd)) agrid = config['output']['shared']['agrid'] if agrid[0].upper() == 'C': From 085984bcd27503a79573d827a83425927af50a7a Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Wed, 6 Jul 2022 16:19:18 -0400 Subject: [PATCH 66/70] 1) add keyword for init 2)add base for init --- .../post/remap_restart/remap_analysis.py | 21 ++++--------- GEOS_Util/post/remap_restart/remap_base.py | 30 +++++++++++++++++++ .../post/remap_restart/remap_catchANDcn.py | 19 +++--------- .../remap_lake_landice_saltwater.py | 19 +++--------- .../post/remap_restart/remap_restarts.py | 8 ++--- GEOS_Util/post/remap_restart/remap_upper.py | 20 ++++--------- 6 files changed, 52 insertions(+), 65 deletions(-) create mode 100755 GEOS_Util/post/remap_restart/remap_base.py diff --git a/GEOS_Util/post/remap_restart/remap_analysis.py b/GEOS_Util/post/remap_restart/remap_analysis.py index 9b5511b1..0990f497 100755 --- a/GEOS_Util/post/remap_restart/remap_analysis.py +++ b/GEOS_Util/post/remap_restart/remap_analysis.py @@ -14,22 +14,11 @@ import glob import fileinput import ruamel.yaml +from remap_base import remap_base -class analysis(object): - def __init__(self, params_file): - yaml = ruamel.yaml.YAML() - stream ='' - with open(params_file, 'r') as f: - stream = f.read() - self.config = yaml.load(stream) - f = os.path.basename(params_file) - out_dir = self.config['output']['shared']['out_dir'] - if not os.path.exists(out_dir) : os.makedirs(out_dir) - dest = out_dir+'/'+f - try: - shutil.copy(params_file, dest) - except shutil.SameFileError: - pass +class analysis(remap_base): + def __init__(self, **configs): + super().__init__(**configs) def remap(self): config = self.config @@ -144,5 +133,5 @@ def find_analysis(self): return list(dict.fromkeys(analysis_in)) if __name__ == '__main__' : - ana = analysis('remap_params.yaml') + ana = analysis(params_file='remap_params.yaml') ana.remap() diff --git a/GEOS_Util/post/remap_restart/remap_base.py b/GEOS_Util/post/remap_restart/remap_base.py new file mode 100755 index 00000000..1194c0b6 --- /dev/null +++ b/GEOS_Util/post/remap_restart/remap_base.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 +# +import os +import ruamel.yaml +import shutil + +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) + out_dir = self.config['output']['shared']['out_dir'] + if not os.path.exists(out_dir) : os.makedirs(out_dir) + f = os.path.basename(value) + dest = out_dir+'/'+f + try: + shutil.copy(value, dest) + except shutil.SameFileError: + pass + if (key == 'config_obj'): + print( "use Config obj") + self.config = value + out_dir = self.config['output']['shared']['out_dir'] + if not os.path.exists(out_dir) : os.makedirs(out_dir) + break diff --git a/GEOS_Util/post/remap_restart/remap_catchANDcn.py b/GEOS_Util/post/remap_restart/remap_catchANDcn.py index 03924ba7..6f87c063 100755 --- a/GEOS_Util/post/remap_restart/remap_catchANDcn.py +++ b/GEOS_Util/post/remap_restart/remap_catchANDcn.py @@ -7,22 +7,11 @@ import glob import ruamel.yaml import shlex +from remap_base import remap_base class catchANDcn(object): - def __init__(self, params_file): - yaml = ruamel.yaml.YAML() - stream ='' - with open(params_file, 'r') as f: - stream = f.read() - self.config = yaml.load(stream) - f = os.path.basename(params_file) - out_dir = self.config['output']['shared']['out_dir'] - if not os.path.exists(out_dir) : os.makedirs(out_dir) - dest = out_dir+'/'+f - try: - shutil.copy(params_file, dest) - except shutil.SameFileError: - pass + def __init__(self, **configs): + super().__init__(**configs) def remap(self): if not self.config['output']['surface']['remap_catch']: @@ -141,5 +130,5 @@ def remap(self): os.chdir(cwdir) if __name__ == '__main__' : - catch = catchANDcn('remap_params.yaml') + catch = catchANDcn(params_file='remap_params.yaml') catch.remap() diff --git a/GEOS_Util/post/remap_restart/remap_lake_landice_saltwater.py b/GEOS_Util/post/remap_restart/remap_lake_landice_saltwater.py index ee8222ec..96d8a445 100755 --- a/GEOS_Util/post/remap_restart/remap_lake_landice_saltwater.py +++ b/GEOS_Util/post/remap_restart/remap_lake_landice_saltwater.py @@ -6,22 +6,11 @@ import glob import ruamel.yaml import shlex +from remap_base import remap_base class lake_landice_saltwater(object): - def __init__(self, params_file): - yaml = ruamel.yaml.YAML() - stream ='' - with open(params_file, 'r') as f: - stream = f.read() - self.config = yaml.load(stream) - f = os.path.basename(params_file) - out_dir = self.config['output']['shared']['out_dir'] - if not os.path.exists(out_dir) : os.makedirs(out_dir) - dest = out_dir+'/'+f - try: - shutil.copy(params_file, dest) - except shutil.SameFileError: - pass + def __init__(self, **configs): + super().__init__(**configs) def remap(self): if not self.config['output']['surface']['remap_water']: @@ -176,5 +165,5 @@ def find_rst(self): return restarts_in if __name__ == '__main__' : - lls = lake_landice_saltwater('remap_params.yaml') + lls = lake_landice_saltwater(params_file='remap_params.yaml') lls.remap() diff --git a/GEOS_Util/post/remap_restart/remap_restarts.py b/GEOS_Util/post/remap_restart/remap_restarts.py index 4ca6bc1a..661fe513 100644 --- a/GEOS_Util/post/remap_restart/remap_restarts.py +++ b/GEOS_Util/post/remap_restart/remap_restarts.py @@ -69,19 +69,19 @@ def main(argv): print("\nYou answered not to continue, exiting.\n") sys.exit(0) # upper air - upper = upperair(config_yaml) + upper = upperair(params_file=config_yaml) upper.remap() # lake, landice and saltwater - lls = lake_landice_saltwater(config_yaml) + lls = lake_landice_saltwater(params_file=config_yaml) lls.remap() # catchANDcn - catch = catchANDcn(config_yaml) + catch = catchANDcn(params_file=config_yaml) catch.remap() # analysis - ana = analysis(config_yaml) + ana = analysis(params_file=config_yaml) ana.remap() if __name__ == '__main__' : diff --git a/GEOS_Util/post/remap_restart/remap_upper.py b/GEOS_Util/post/remap_restart/remap_upper.py index fbbc86c9..f7aa00e4 100755 --- a/GEOS_Util/post/remap_restart/remap_upper.py +++ b/GEOS_Util/post/remap_restart/remap_upper.py @@ -6,22 +6,12 @@ import shlex import shutil import glob +from remap_base import remap_base class upperair(object): - def __init__(self, params_file): - yaml = ruamel.yaml.YAML() - stream ='' - with open(params_file, 'r') as f: - stream = f.read() - self.config = yaml.load(stream) - f = os.path.basename(params_file) - out_dir = self.config['output']['shared']['out_dir'] - if not os.path.exists(out_dir) : os.makedirs(out_dir) - dest = out_dir+'/'+f - try: - shutil.copy(params_file, dest) - except shutil.SameFileError: - pass + def __init__(self, **configs): + super().__init__(**configs) + def remap(self): if not self.config['output']['air']['remap'] : return @@ -278,5 +268,5 @@ def find_rst(self): return restarts_in if __name__ == '__main__' : - air = upperair('remap_params.yaml') + air = upperair(params_file='remap_params.yaml') air.remap() From 00f799abb76f85a5dedd7400e31509b0f1b5e217 Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Wed, 6 Jul 2022 16:28:36 -0400 Subject: [PATCH 67/70] minor inherit fix --- GEOS_Util/post/remap_restart/remap_base.py | 2 +- GEOS_Util/post/remap_restart/remap_catchANDcn.py | 2 +- GEOS_Util/post/remap_restart/remap_lake_landice_saltwater.py | 2 +- GEOS_Util/post/remap_restart/remap_upper.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/GEOS_Util/post/remap_restart/remap_base.py b/GEOS_Util/post/remap_restart/remap_base.py index 1194c0b6..2f5a9406 100755 --- a/GEOS_Util/post/remap_restart/remap_base.py +++ b/GEOS_Util/post/remap_restart/remap_base.py @@ -8,7 +8,7 @@ class remap_base(object): def __init__(self, **configs): for key, value in configs.items(): if (key == 'params_file'): - print( "use Config yaml file" + value) + print( "use Config yaml file: " + value) yaml = ruamel.yaml.YAML() stream ='' with open(value, 'r') as f: diff --git a/GEOS_Util/post/remap_restart/remap_catchANDcn.py b/GEOS_Util/post/remap_restart/remap_catchANDcn.py index 6f87c063..44337f3e 100755 --- a/GEOS_Util/post/remap_restart/remap_catchANDcn.py +++ b/GEOS_Util/post/remap_restart/remap_catchANDcn.py @@ -9,7 +9,7 @@ import shlex from remap_base import remap_base -class catchANDcn(object): +class catchANDcn(remap_base): def __init__(self, **configs): super().__init__(**configs) diff --git a/GEOS_Util/post/remap_restart/remap_lake_landice_saltwater.py b/GEOS_Util/post/remap_restart/remap_lake_landice_saltwater.py index 96d8a445..4d25ae33 100755 --- a/GEOS_Util/post/remap_restart/remap_lake_landice_saltwater.py +++ b/GEOS_Util/post/remap_restart/remap_lake_landice_saltwater.py @@ -8,7 +8,7 @@ import shlex from remap_base import remap_base -class lake_landice_saltwater(object): +class lake_landice_saltwater(remap_base): def __init__(self, **configs): super().__init__(**configs) diff --git a/GEOS_Util/post/remap_restart/remap_upper.py b/GEOS_Util/post/remap_restart/remap_upper.py index f7aa00e4..090eb7af 100755 --- a/GEOS_Util/post/remap_restart/remap_upper.py +++ b/GEOS_Util/post/remap_restart/remap_upper.py @@ -8,7 +8,7 @@ import glob from remap_base import remap_base -class upperair(object): +class upperair(remap_base): def __init__(self, **configs): super().__init__(**configs) From fbd50b99555caf0a322bdff531109318949adbe8 Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Thu, 7 Jul 2022 10:19:00 -0400 Subject: [PATCH 68/70] add default tmp directory for merra2 --- .../post/remap_restart/remap_questions.py | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/GEOS_Util/post/remap_restart/remap_questions.py b/GEOS_Util/post/remap_restart/remap_questions.py index ae487419..0dbb1f8b 100755 --- a/GEOS_Util/post/remap_restart/remap_questions.py +++ b/GEOS_Util/post/remap_restart/remap_questions.py @@ -30,6 +30,14 @@ def fvcore_name(x): return False def ask_common_in(): + cmd = 'whoami' + p = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE) + (user, err) = p.communicate() + p_status = p.wait() + print(user) + user = user.decode().split() + tmp_merra2 = '/discover/nobackup/'+user[0]+'/merra2_tmp' + questions = [ { "type": "confirm", @@ -43,18 +51,19 @@ def ask_common_in(): "message": "Enter the directory containing restart files to be remapped:", "when": lambda x: not x['MERRA-2'], }, - { - "type": "path", - "name": "rst_dir", - "message": "Enter a directory to which the archived MERRA-2 archive files can be copied: ", - "when": lambda x: x['MERRA-2'], - }, { "type": "text", "name": "yyyymmddhh", "message": "From what restart date/time would you like to remap? (must be 10 digits: yyyymmddhh)", "validate": lambda text: len(text)==10 , }, + { + "type": "path", + "name": "rst_dir", + "message": "Enter a directory to which the archived MERRA-2 archive files can be copied: ", + "default": lambda x: tmp_merra2+x['yyyymmddhh']+'/', + "when": lambda x: x['MERRA-2'], + }, { "type": "text", "name": "agrid", @@ -408,8 +417,8 @@ def get_config_from_questionary(): return config if __name__ == "__main__": - config = get_config_from_questionary() - yaml = ruamel.yaml.YAML() - with open("raw_answers.yaml", "w") as f: - yaml.dump(config, f) + config = get_config_from_questionary() + yaml = ruamel.yaml.YAML() + with open("raw_answers.yaml", "w") as f: + yaml.dump(config, f) From e656565f46a0ea9d6646187090ceac4b0b3b2486 Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Fri, 8 Jul 2022 08:33:04 -0400 Subject: [PATCH 69/70] re-order questions so it matches regrid.pl --- GEOS_Util/post/remap_restart/remap_params.py | 17 +- .../post/remap_restart/remap_questions.py | 445 ++++++++---------- 2 files changed, 203 insertions(+), 259 deletions(-) diff --git a/GEOS_Util/post/remap_restart/remap_params.py b/GEOS_Util/post/remap_restart/remap_params.py index 99162d7f..235ebbd9 100755 --- a/GEOS_Util/post/remap_restart/remap_params.py +++ b/GEOS_Util/post/remap_restart/remap_params.py @@ -13,14 +13,13 @@ class remap_params(object): def __init__(self, config_from_question): - self.common_in = config_from_question['input']['parameters']['COMMON'] - self.common_out = config_from_question['output']['parameters']['COMMON'] - self.upper_out = config_from_question['output']['parameters']['UPPERAIR'] - self.slurm_options = config_from_question['slurm_options'] - self.surf_in = config_from_question['input']['parameters']['SURFACE'] - self.surf_out = config_from_question['output']['parameters']['SURFACE'] - #self.ana_in = config_from_question['input']['parameters']['ANALYSIS'] - self.ana_out = config_from_question['output']['parameters']['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_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.init_time() self.init_tags() @@ -500,7 +499,7 @@ def get_name_with_grid( grid, names, a_o): anames = get_name_with_grid(agrid_, dirnames, 'a') gridID = get_name_with_grid(ogrid_, anames, 'o') if len(gridID) == 0 : - exit("cannot find the grid string: " + bcdir) + exit("cannot find the grid subdirctory of agrid: " +agrid_+ " and ogrid " + ogrid_ + " under "+ bcdir) g = '' if len(gridID) == 1 : g = gridID[0] if len(gridID) >=2 : diff --git a/GEOS_Util/post/remap_restart/remap_questions.py b/GEOS_Util/post/remap_restart/remap_questions.py index 0dbb1f8b..8547bfc0 100755 --- a/GEOS_Util/post/remap_restart/remap_questions.py +++ b/GEOS_Util/post/remap_restart/remap_questions.py @@ -15,75 +15,141 @@ import glob def fvcore_name(x): - ymdh = x['yyyymmddhh'] + ymdh = x['input:shared:yyyymmddhh'] time = ymdh[0:8] + '_'+ymdh[8:10] - files = glob.glob(x['rst_dir']+'/*fvcore_*'+time+'*') + files = glob.glob(x['input:shared:rst_dir']+'/*fvcore_*'+time+'*') if len(files) ==1 : fname = files[0] print('\nFound ' + fname) return fname else: - fname = x['rst_dir']+'/fvcore_internal_rst' + fname = x['input:shared:rst_dir']+'/fvcore_internal_rst' if os.path.exists(fname): print('\nFound ' + fname) return fname return False -def ask_common_in(): +def tmp_merra2_dir(x): cmd = 'whoami' p = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE) (user, err) = p.communicate() p_status = p.wait() print(user) user = user.decode().split() - tmp_merra2 = '/discover/nobackup/'+user[0]+'/merra2_tmp' + tmp_merra2 = '/discover/nobackup/'+user[0]+'/merra2_tmp'+x['input:shared:yyyymmddhh']+'/' + return tmp_merra2 + +def we_default(tag): + default_ = '26' + if tag in ['INL','GITNL', '525'] : default_ = '13' + return default_ + +def zoom_default(x): + zoom_ = '8' + fvcore = fvcore_name(x) + if fvcore : + fvrst = os.path.dirname(os.path.realpath(__file__)) + '/fvrst.x -h ' + cmd = fvrst + fvcore + print(cmd +'\n') + p = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE) + (output, err) = p.communicate() + p_status = p.wait() + ss = output.decode().split() + x['input:shared:agrid'] = "C"+ss[0] # save for air parameter + lat = int(ss[0]) + lon = int(ss[1]) + if (lon != lat*6) : + sys.exit('This is not a cubed-sphere grid fvcore restart. Please contact SI team') + ymdh = x.get('input:shared:yyyymmddhh') + ymdh_ = str(ss[3]) + str(ss[4])[0:2] + if (ymdh_ != ymdh) : + print("Warning: The date in fvcore is different from the date you input\n") + zoom = lat /90.0 + zoom_ = str(int(zoom)) + if zoom < 1 : zoom_ = '1' + if zoom > 8 : zoom_ = '8' + if x['input:shared:MERRA-2'] : + zoom_ = '2' + return zoom_ + +def get_account(): + cmd = 'id -gn' + p = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE) + (accounts, err) = p.communicate() + p_status = p.wait() + accounts = accounts.decode().split() + return accounts[0] + +def ask_questions(): questions = [ { "type": "confirm", - "name": "MERRA-2", + "name": "input:shared:MERRA-2", "message": "Would you like to remap archived MERRA-2 restarts?", "default": False, }, { "type": "path", - "name": "rst_dir", + "name": "input:shared:rst_dir", "message": "Enter the directory containing restart files to be remapped:", - "when": lambda x: not x['MERRA-2'], + "when": lambda x: not x['input:shared:MERRA-2'], }, { "type": "text", - "name": "yyyymmddhh", + "name": "input:shared:yyyymmddhh", "message": "From what restart date/time would you like to remap? (must be 10 digits: yyyymmddhh)", "validate": lambda text: len(text)==10 , }, { "type": "path", - "name": "rst_dir", + "name": "input:shared:rst_dir", "message": "Enter a directory to which the archived MERRA-2 archive files can be copied: ", - "default": lambda x: tmp_merra2+x['yyyymmddhh']+'/', - "when": lambda x: x['MERRA-2'], + "default": lambda x: tmp_merra2_dir(x), + "when": lambda x: x['input:shared:MERRA-2'], + }, + + { + "type": "path", + "name": "output:shared:out_dir", + "message": "Enter the directory for new restarts:\n" }, + { "type": "text", - "name": "agrid", + "name": "input:shared:agrid", "message": "Enter input atmospheric grid: \n C12 C180 C1000 \n C24 C360 C1440 \n C48 C500 C2880 \n C90 C720 C5760 \n ", "default": 'C360', # if it is merra-2 or has_fvcore, agrid is deduced - "when": lambda x: not x['MERRA-2'] and not fvcore_name(x), + "when": lambda x: not x['input:shared:MERRA-2'] and not fvcore_name(x), + }, + + { + "type": "text", + "name": "output:shared:agrid", + "message": "Enter new atmospheric grid: \n C12 C180 C1000 \n C24 C360 C1440 \n C48 C500 C2880 \n C90 C720 C5760 \n ", + "default": 'C360', }, + + { + "type": "text", + "name": "output:air:nlevel", + "message": "Enter new atmospheric levels: (71 72 91 127 132 137 144 181)", + "default": "72", + }, + { "type": "select", - "name": "model", - "message": "Select ocean model:", + "name": "input:shared:model", + "message": "Select input ocean model:", "choices": ["data", "MOM5", "MOM6"], "default": "data", - "when": lambda x: not x['MERRA-2'] + "when": lambda x: not x['input:shared:MERRA-2'] }, { "type": "select", - "name": "ogrid", + "name": "input:shared:ogrid", "message": "Input Ocean grid: \n \ Data Ocean Grids \n \ ------------------- \n \ @@ -92,12 +158,41 @@ def ask_common_in(): 2880X1440 (OSTIA) \n \ CS = same as atmospere grid (OSTIA cubed-sphere) \n", "choices": ['360X180','1440X720','2880X1440','CS'], - "when": lambda x: x.get('model') == 'data' and not x['MERRA-2'], + "when": lambda x: x.get('input:shared:model') == 'data' and not x['input:shared:MERRA-2'], }, + { "type": "select", - "name": "ogrid", - "message": "Input Ocean grid: \n \ + "name": "output:shared:model", + "message": "Select ocean model for new restarts:", + "choices": ["data", "MOM5", "MOM6"], + "default": "data", + }, + { + "type": "select", + "name": "output:shared:ogrid", + "message": "Select new ocean grid:", + "choices": ['360X180','1440X720','2880X1440','CS'], + "when": lambda x: x['output:shared:model'] == 'data', + }, + + { + "type": "select", + "name": "input:shared:ogrid", + "message": "Input ocean grid: \n \ + Coupled Ocean Grids \n \ + ------------------- \n \ + 72X36 \n \ + 360X200 \n \ + 720X410 \n \ + 1440X1080 \n ", + "choices": ['72X36','360X200','720X410','1440X1080'], + "when": lambda x: x.get('input:shared:model') == 'MOM5' or x.get('input:shared:model')== 'MOM6' + }, + { + "type": "select", + "name": "output:shared:ogrid", + "message": "Select new ocean grid: \n \ Coupled Ocean Grids \n \ ------------------- \n \ 72X36 \n \ @@ -105,15 +200,15 @@ def ask_common_in(): 720X410 \n \ 1440X1080 \n ", "choices": ['72X36','360X200','720X410','1440X1080'], - "when": lambda x: x.get('model') == 'MOM5' or x.get('model')== 'MOM6' + "when": lambda x: x['output:shared:model'] != 'data', }, + { "type": "text", - "name": "tag", + "name": "input:shared:tag", "message": "Enter GCM or DAS tag for input: \n \ Sample GCM tags \n \ --------------- \n \ -G30 : Ganymed-3_0 ......... Ganymed-3_0_p1 \n \ G40 : Ganymed-4_0 ......... Heracles-5_4_p3 \n \ ICA : Icarus .............. Jason \n \ GITOL : 10.3 ................ 10.18 \n \ @@ -127,294 +222,144 @@ def ask_common_in(): 517 : GEOSadas-5_17_0 ..... GEOSadas-5_24_0_p1\n \ 525 : GEOSadas-5_25_1 ..... GEOSadas-5_29_4\n", "default": "INL", - "when": lambda x: not x["MERRA-2"], + "when": lambda x: not x["input:shared:MERRA-2"], }, + { + "type": "text", + "name": "output:shared:tag", + "message": "Enter GCM or DAS tag for new restarts:", + "default": "INL", + }, + { "type": "select", - "name": "bc_base", + "name": "input:shared:bc_base", "message": "Select bcs base \n \ discover_ops: /discover/nobackup/projects/gmao/share/gmao_ops/fvInput/g5gcm/bcs \n \ discover_lt: /discover/nobackup/ltakacs/bcs \n \ discover_couple: /discover/nobackup/projects/gmao/ssd/aogcm/atmosphere_bcs \n", "choices": ["discover_ops", "discover_lt", "discover_couple", "other"], - "when": lambda x: not x['MERRA-2'], + "when": lambda x: not x['input:shared:MERRA-2'], }, { "type": "path", - "name": "alt_bcs", + "name": "input:shared:alt_bcs", "message": "Specify your own bcs absolute path (do not contain grid info) for restarts: \n ", - "when": lambda x: x.get("bc_base")=="other", + "when": lambda x: x.get("input:shared:bc_base")=="other", }, - ] - common_in = questionary.prompt(questions) - if not common_in.get('model') : - common_in['model'] = 'data' - common_in['rst_dir'] = os.path.abspath(common_in['rst_dir']) - return common_in -def ask_common_out(): - questions = [ - { - "type": "path", - "name": "out_dir", - "message": "Enter the directory for new restarts:\n" - }, - { - "type": "text", - "name": "expid", - "message": "Enter new restarts expid:", - "default": "", - }, - { - "type": "text", - "name": "agrid", - "message": "Enter new atmospheric grid: \n C12 C180 C1000 \n C24 C360 C1440 \n C48 C500 C2880 \n C90 C720 C5760 \n ", - "default": 'C360', - }, - { - "type": "text", - "name": "tag", - "message": "Enter GCM or DAS tag for new restarts: \n \ -Sample GCM tags \n \ ---------------- \n \ -G30 : Ganymed-3_0 ......... Ganymed-3_0_p1 \n \ -G40 : Ganymed-4_0 ......... Heracles-5_4_p3 \n \ -ICA : Icarus .............. Jason \n \ -GITOL : 10.3 ................ 10.18 \n \ -INL : Icarus-NL ........... Jason-NL \n \ -GITNL : 10.19 ............... 10.23 \n \ -\n \ -Sample DAS tags \n \ ---------------- \n \ -5B0 : GEOSadas-5_10_0_p2 .. GEOSadas-5_11_0 \n \ -512 : GEOSadas-5_12_2 ..... GEOSadas-5_16_5\n \ -517 : GEOSadas-5_17_0 ..... GEOSadas-5_24_0_p1\n \ -525 : GEOSadas-5_25_1 ..... GEOSadas-5_29_4\n", - "default": "INL", - }, { "type": "select", - "name": "model", - "message": "Select ocean model for new restarts:", - "choices": ["data", "MOM5", "MOM6"], - "default": "data", - }, - { - "type": "select", - "name": "ogrid", - "message": "Select new Ocean grid: \n \ - Data Ocean Grids \n \ - ------------------- \n \ - 360X180 (Reynolds) \n \ - 1440X720 (MERRA-2) \n \ - 2880X1440 (OSTIA) \n \ - CS = same as atmospere grid (OSTIA cubed-sphere) \n", - "choices": ['360X180','1440X720','2880X1440','CS'], - "when": lambda x: x['model'] == 'data', - }, - { - "type": "select", - "name": "ogrid", - "message": "Select new Ocean grid: \n \ - Coupled Ocean Grids \n \ - ------------------- \n \ - 72X36 \n \ - 360X200 \n \ - 720X410 \n \ - 1440X1080 \n ", - "choices": ['72X36','360X200','720X410','1440X1080'], - "when": lambda x: x['model'] != 'data', - }, - { - "type": "select", - "name": "bc_base", - "message": "Select bcs base for new restarts: \n \ - discover_ops: /discover/nobackup/projects/gmao/share/gmao_ops/fvInput/g5gcm/bcs \n \ - discover_lt: /discover/nobackup/ltakacs/bcs \n \ - discover_couple: /discover/nobackup/projects/gmao/ssd/aogcm/atmosphere_bcs \n", + "name": "output:shared:bc_base", + "message": "Select bcs base for new restarts:", "choices": ["discover_ops", "discover_lt", "discover_couple", "other"], }, { "type": "path", - "name": "alt_bcs", + "name": "output:shared:alt_bcs", "message": "Specify your own bcs path (do not contain grid info) for new restarts: \n ", - "when": lambda x: x.get("bc_base")=="other", + "when": lambda x: x.get("output:shared:bc_base")=="other", }, - ] - common_out = questionary.prompt(questions) - if common_out.get('ogrid') == 'CS': - common_out['ogrid'] = common_out['agrid'] - common_out['out_dir'] = os.path.abspath(common_out['out_dir']) - - return common_out -def ask_upper_out(): - questions = [ - { - "type": "text", - "name": "nlevel", - "message": "Enter new atmospheric levels: (71 72 91 127 132 137 144 181)", - "default": "72", - }, { "type": "confirm", - "name": "remap", + "name": "output:air:remap", "message": "Would you like to remap upper air?", "default": True, }, - ] - return questionary.prompt(questions) -def ask_surface_in(common_in): - wemin_default = '26' - tag = common_in.get('tag') - if tag in ['INL','GITNL', '525'] : wemin_default = '13' - - zoom_default = '8' - fvcore = fvcore_name(common_in) - if fvcore : - fvrst = os.path.dirname(os.path.realpath(__file__)) + '/fvrst.x -h ' - cmd = fvrst + fvcore - print(cmd +'\n') - p = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE) - (output, err) = p.communicate() - p_status = p.wait() - ss = output.decode().split() - common_in['agrid'] = "C"+ss[0] # save for air parameter - lat = int(ss[0]) - lon = int(ss[1]) - if (lon != lat*6) : - sys.exit('This is not a cubed-sphere grid fvcore restart. Please contact SI team') - ymdh = common_in.get('yyyymmddhh') - ymdh_ = str(ss[3]) + str(ss[4])[0:2] - if (ymdh_ != ymdh) : - print("Warning: The date in fvcore is different from the date you input\n") - zoom = lat /90.0 - zoom_default = str(int(zoom)) - if zoom < 1 : zoom_default = '1' - if zoom > 8 : zoom_default = '8' - if common_in['MERRA-2'] : - zoom_default = '2' - - questions = [ - { - "type": "text", - "name": "wemin", - "message": "What is value of Wemin?", - "default": wemin_default - }, - { - "type": "text", - "name": "zoom", - "message": "What is value of zoom [1-8]?", - "default": zoom_default - }, - ] - return questionary.prompt(questions) - -def ask_surface_out(common_out): - wemout_default = '26' - tag = common_out.get('tag') - if tag in ['INL','GITNL', '525'] : wemout_default = '13' - questions = [ - { - "type": "text", - "name": "wemout", - "message": "What is value of Wemout?", - "default": wemout_default - }, { "type": "confirm", - "name": "remap", + "name": "output:surface:remap", "message": "Would you like to remap surface?", "default": True, }, - ] - return questionary.prompt(questions) - -def ask_analysis_in(): - questions = [ { "type": "confirm", - "name": "bkg", + "name": "output:analysis:bkg", "message": "Regrid bkg files?", "default": False, }, { "type": "confirm", - "name": "lcv", + "name": "output:analysis:lcv", "message": "Write lcv?", "default": False, }, - ] - return questionary.prompt(questions) - -def ask_slurm_options(): - cmd = 'id -gn' - p = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE) - (accounts, err) = p.communicate() - p_status = p.wait() - accounts = accounts.decode().split() + { + "type": "text", + "name": "input:surface:wemin", + "message": "What is value of Wemin?", + "default": lambda x: we_default(x.get('input:shared:tag')) + }, + { + "type": "text", + "name": "output:surface:wemout", + "message": "What is value of Wemout?", + "default": lambda x: we_default(x.get('output:shared:tag')) + }, + { + "type": "text", + "name": "input:surface:zoom", + "message": "What is value of zoom [1-8]?", + "default": lambda x: zoom_default(x) + }, + { + "type": "text", + "name": "output:shared:expid", + "message": "Enter new restarts expid:", + "default": "", + }, - questions = [ { "type": "text", - "name": "qos", + "name": "slurm:qos", "message": "qos?", "default": "debug", }, + { "type": "text", - "name": "account", + "name": "slurm:account", "message": "account?", - "default": accounts[0], + "default": get_account(), }, { "type": "select", - "name": "constraint", + "name": "slurm:constraint", "message": "constraint?", "choices": ['hasw', 'sky', 'cas'], }, ] - return questionary.prompt(questions) + answers = questionary.prompt(questions) + if not answers.get('input:shared:model') : + answers['input:shared:model'] = 'data' + answers['input:shared:rst_dir'] = os.path.abspath(answers['input:shared:rst_dir']) + if answers.get('output:shared:ogrid') == 'CS': + answers['output:shared:ogrid'] = answers['output:shared:agrid'] + answers['output:shared:out_dir'] = os.path.abspath(answers['output:shared:out_dir']) -def get_config_from_questionary(): - print("\nCommon parameters INPUT: \n") - common_in = ask_common_in() - print("\nSurface parameters INPUT: \n") - surface_in = ask_surface_in(common_in) - print("\nAnalysis parameters INPUT: \n") - analysis_in = ask_analysis_in() - print("\nCommon parameters OUTPUT: \n") - common_out = ask_common_out() - print("\nUPPER parameters OUTPUT: \n") - upper_out = ask_upper_out() - print("\nSurface parameters OUTPUT: \n") - surface_out = ask_surface_out(common_out) - print("\nSlurm parameters OUTPUT: \n") - slurm = ask_slurm_options() - - config={} - inputs={} - outputs={} - parameters_in={} - parameters_in['COMMON'] = common_in - parameters_in['SURFACE'] = surface_in - inputs['parameters'] = parameters_in - - config['input']= inputs + return answers - parameters_out={} - parameters_out['COMMON'] = common_out - parameters_out['UPPERAIR'] = upper_out - parameters_out['SURFACE'] = surface_out - parameters_out['ANALYSIS'] = analysis_in - outputs['parameters'] = parameters_out - - config['output']= outputs - - config['slurm_options'] = slurm +def get_config_from_questionary(): + answers = ask_questions() + config = {} + config['input'] = {} + config['input']['shared'] = {} + config['input']['surface'] = {} + config['output'] = {} + config['output']['shared'] = {} + config['output']['air'] = {} + config['output']['surface'] = {} + config['output']['analysis'] = {} + config['slurm'] = {} + 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 + return config if __name__ == "__main__": config = get_config_from_questionary() From 29bf7b1f2b2e73032ac320756f5c12c1060a323a Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Fri, 8 Jul 2022 09:06:34 -0400 Subject: [PATCH 70/70] make a copy of merra2 files only after confirming to continue --- GEOS_Util/post/remap_restart/remap_params.py | 26 ++++--------------- .../post/remap_restart/remap_restarts.py | 6 +++++ 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/GEOS_Util/post/remap_restart/remap_params.py b/GEOS_Util/post/remap_restart/remap_params.py index 235ebbd9..cd5ec03c 100755 --- a/GEOS_Util/post/remap_restart/remap_params.py +++ b/GEOS_Util/post/remap_restart/remap_params.py @@ -248,23 +248,6 @@ def init_time(self): self.ymd = ymdh[0:8] def init_merra2(self): - def get_grid_kind(grid): - hgrd = {} - hgrd['C12'] = 'a' - hgrd['C24'] = 'a' - hgrd['C48'] = 'b' - hgrd['C90'] = 'c' - hgrd['C180'] = 'd' - hgrd['C360'] = 'd' - hgrd['C500'] = 'd' - hgrd['C720'] = 'e' - hgrd['C1000'] = 'e' - hgrd['C1440'] = 'e' - hgrd['C2000'] = 'e' - hgrd['C2880'] = 'e' - hgrd['C5760'] = 'e' - return hgrd[grid] - if not self.common_in['MERRA-2']: return print("\n MERRA-2 sources:\n") @@ -284,6 +267,11 @@ def get_grid_kind(grid): self.common_in['ogrid'] = '1440x720' self.common_in['bc_base']= 'discover_ops' self.common_in['tag']= 'Ganymed-4_0' + + def copy_merra2(self): + if not self.common_in['MERRA-2']: + return + print("\n Copy MERRA-2 :\n") expid = self.common_in['expid'] yyyymmddhh_ = str(self.common_in['yyyymmddhh']) surfix = yyyymmddhh_[0:8]+'_'+self.hh+'z.bin' @@ -333,10 +321,6 @@ def get_grid_kind(grid): agrid_in = self.common_in['agrid'] agrid_out = self.common_out['agrid'] - if (get_grid_kind(agrid_in.upper()) == get_grid_kind(agrid_out.upper())): - print(" No need to remap anaylysis file according to air grid in and out") - #return - anafiles=[] for h in [3,4,5,6,7,8,9]: delt = timedelta(hours = h-3) diff --git a/GEOS_Util/post/remap_restart/remap_restarts.py b/GEOS_Util/post/remap_restart/remap_restarts.py index 661fe513..f91e4af3 100644 --- a/GEOS_Util/post/remap_restart/remap_restarts.py +++ b/GEOS_Util/post/remap_restart/remap_restarts.py @@ -43,6 +43,7 @@ def main(argv): if opt in("-c", "--config_file"): config_yaml = arg + params = '' if config_yaml == '': config = get_config_from_questionary() params = remap_params(config) @@ -68,6 +69,11 @@ def main(argv): if not answer['Continue'] : print("\nYou answered not to continue, exiting.\n") sys.exit(0) + + # copy merra2 files from archives + if params: + params.copy_merra2() + # upper air upper = upperair(params_file=config_yaml) upper.remap()