From a730da33a518293173ebf8632bb9fa5902c7f977 Mon Sep 17 00:00:00 2001 From: biljanaorescanin Date: Wed, 3 Jul 2024 08:38:50 -0400 Subject: [PATCH 01/24] add MOM6 C90 ogrid option --- pre/remap_restart/remap_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pre/remap_restart/remap_utils.py b/pre/remap_restart/remap_utils.py index 4cc6bba..871205c 100755 --- a/pre/remap_restart/remap_utils.py +++ b/pre/remap_restart/remap_utils.py @@ -46,7 +46,7 @@ choices_ogrid_data = ['360x180 (Reynolds)','1440x720 (MERRA-2)','2880x1440 (OSTIA)','CS (same as atmosphere OSTIA cubed-sphere grid)'] -choices_ogrid_cpld = ['72x36', '360x200', '720x410', '1440x1080'] +choices_ogrid_cpld = ['72x36', '360x200', '540x458', '720x410', '1440x1080'] choices_ogrid_cmd = ['360x180', '1440x720', '2880x1440', 'CS'] + choices_ogrid_cpld From ab10fce62a6f6d4c74899f956051103cb44d30a7 Mon Sep 17 00:00:00 2001 From: Matthew Thompson Date: Fri, 26 Jul 2024 13:49:13 -0400 Subject: [PATCH 02/24] Fix time_ave.rc --- CHANGELOG.md | 2 + post/time_ave.rc | 144 +++++++++++++++++++++++------------------------ 2 files changed, 74 insertions(+), 72 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e6abdc..970d6ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- Fix quote-v-comma issue in `time_ave.rc` that ESMF 8.6.1 was triggered + ### Removed ### Deprecated diff --git a/post/time_ave.rc b/post/time_ave.rc index d3adbc6..5849be2 100644 --- a/post/time_ave.rc +++ b/post/time_ave.rc @@ -31,90 +31,90 @@ QUADRATICS: 'u' , 'v' , 'wstar' , 'qstar' , 'WSQS' , :: -ALIASES: 'u' , 'U' ' - 'u' , 'uwnd' ' - 'u' , 'UWND' ' - 'u' , 'ugrd' ' - 'u' , 'UGRD' ' - 'u' , 'ugrdprs' ' - 'u' , 'UGRDPRS' ' +ALIASES: 'u' , 'U' , + 'u' , 'uwnd' , + 'u' , 'UWND' , + 'u' , 'ugrd' , + 'u' , 'UGRD' , + 'u' , 'ugrdprs' , + 'u' , 'UGRDPRS' , - 'v' , 'V' ' - 'v' , 'vwnd' ' - 'v' , 'VWND' ' - 'v' , 'vgrd' ' - 'v' , 'VGRD' ' - 'v' , 'vgrdprs' ' - 'v' , 'VGRDPRS' ' + 'v' , 'V' , + 'v' , 'vwnd' , + 'v' , 'VWND' , + 'v' , 'vgrd' , + 'v' , 'VGRD' , + 'v' , 'vgrdprs' , + 'v' , 'VGRDPRS' , - 't' , 'T' ' - 't' , 'tmp' ' - 't' , 'TMP' ' - 't' , 'tmpu' ' - 't' , 'TMPU' ' - 't' , 'tmpprs' ' - 't' , 'TMPPRS' ' + 't' , 'T' , + 't' , 'tmp' , + 't' , 'TMP' , + 't' , 'tmpu' , + 't' , 'TMPU' , + 't' , 'tmpprs' , + 't' , 'TMPPRS' , - 'qv' , 'q' ' - 'qv' , 'Q' ' - 'qv' , 'QV' ' - 'qv' , 'sphu' ' - 'qv' , 'SPHU' ' + 'qv' , 'q' , + 'qv' , 'Q' , + 'qv' , 'QV' , + 'qv' , 'sphu' , + 'qv' , 'SPHU' , - 'ql' , 'QL' ' + 'ql' , 'QL' , - 'qi' , 'QI' ' + 'qi' , 'QI' , - 'h' , 'H' ' - 'h' , 'hgt' ' - 'h' , 'HGT' ' - 'h' , 'hght' ' - 'h' , 'HGHT' ' - 'h' , 'hgtprs' ' - 'h' , 'HGTPRS' ' - 'h' , 'z' ' - 'h' , 'Z' ' + 'h' , 'H' , + 'h' , 'hgt' , + 'h' , 'HGT' , + 'h' , 'hght' , + 'h' , 'HGHT' , + 'h' , 'hgtprs' , + 'h' , 'HGTPRS' , + 'h' , 'z' , + 'h' , 'Z' , - 'ustar' , 'U' ' - 'ustar' , 'uwnd' ' - 'ustar' , 'UWND' ' - 'ustar' , 'ugrd' ' - 'ustar' , 'UGRD' ' - 'ustar' , 'ugrdprs' ' - 'ustar' , 'UGRDPRS' ' + 'ustar' , 'U' , + 'ustar' , 'uwnd' , + 'ustar' , 'UWND' , + 'ustar' , 'ugrd' , + 'ustar' , 'UGRD' , + 'ustar' , 'ugrdprs' , + 'ustar' , 'UGRDPRS' , - 'vstar' , 'V' ' - 'vstar' , 'vwnd' ' - 'vstar' , 'VWND' ' - 'vstar' , 'vgrd' ' - 'vstar' , 'VGRD' ' - 'vstar' , 'vgrdprs' ' - 'vstar' , 'VGRDPRS' ' + 'vstar' , 'V' , + 'vstar' , 'vwnd' , + 'vstar' , 'VWND' , + 'vstar' , 'vgrd' , + 'vstar' , 'VGRD' , + 'vstar' , 'vgrdprs' , + 'vstar' , 'VGRDPRS' , - 'tstar' , 'T' ' - 'tstar' , 'tmp' ' - 'tstar' , 'TMP' ' - 'tstar' , 'tmpu' ' - 'tstar' , 'TMPU' ' - 'tstar' , 'tmpprs' ' - 'tstar' , 'TMPPRS' ' + 'tstar' , 'T' , + 'tstar' , 'tmp' , + 'tstar' , 'TMP' , + 'tstar' , 'tmpu' , + 'tstar' , 'TMPU' , + 'tstar' , 'tmpprs' , + 'tstar' , 'TMPPRS' , - 'qstar' , 'q' ' - 'qstar' , 'Q' ' - 'qstar' , 'qv' ' - 'qstar' , 'QV' ' - 'qstar' , 'sphu' ' - 'qstar' , 'SPHU' ' + 'qstar' , 'q' , + 'qstar' , 'Q' , + 'qstar' , 'qv' , + 'qstar' , 'QV' , + 'qstar' , 'sphu' , + 'qstar' , 'SPHU' , - 'wstar' , 'omega' ' - 'wstar' , 'OMEGA' ' - 'omega' , 'OMEGA' ' + 'wstar' , 'omega' , + 'wstar' , 'OMEGA' , + 'omega' , 'OMEGA' , - 'epv' , 'EPV' ' + 'epv' , 'EPV' , - 'o3' , 'O3' ' - 'o3' , 'OZ' ' - 'o3' , 'ozone' ' - 'o3' , 'OZONE' ' + 'o3' , 'O3' , + 'o3' , 'OZ' , + 'o3' , 'ozone' , + 'o3' , 'OZONE' , :: From c41a145c7167dfb15db7791e95c95d572d8a40fd Mon Sep 17 00:00:00 2001 From: Matthew Thompson Date: Fri, 26 Jul 2024 14:13:27 -0400 Subject: [PATCH 03/24] Fix up changelog --- CHANGELOG.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 970d6ad..c91e901 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,12 +13,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed -- Fix quote-v-comma issue in `time_ave.rc` that ESMF 8.6.1 was triggered - ### Removed ### Deprecated +## [2.1.1] - 2024-07-26 + +### Fixed + +- Fix quote-v-comma issue in `time_ave.rc` that ESMF 8.6.1 was triggered by. + ## [2.1.0] - 2024-06-10 ### Added From 5dec566c4f13946f06f7b403c34a97f0461bf157 Mon Sep 17 00:00:00 2001 From: Scott Rabenhorst <53346946+sdrabenh@users.noreply.github.com> Date: Tue, 30 Jul 2024 10:28:32 -0400 Subject: [PATCH 04/24] Update CHANGELOG.md --- CHANGELOG.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c91e901..1692ce9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Deprecated -## [2.1.1] - 2024-07-26 +## [2.1.2] - 2024-07-30 + +### Changed + +- Added MASKFILE for time-discontinuous data in TEM diagnostics + +## [2.1.1] - 2024-07-30 + +### Added + +- MOM6 C90 ogrid option to `remap_utils.py` ### Fixed From cf095185b8818d8b3a7b920571874a58cb4f562f Mon Sep 17 00:00:00 2001 From: Matthew Thompson Date: Mon, 12 Aug 2024 14:57:07 -0400 Subject: [PATCH 05/24] Update ESMF CMake target to ESMF::ESMF This PR updates the ESMF CMake target to `ESMF::ESMF` which is the correct canonical target name for ESMF. This is necessary for Spack compatibility. NOTE: This requires ESMF 8.6.1 or later. --- CHANGELOG.md | 2 ++ post/CMakeLists.txt | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1692ce9..2199df6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- Update ESMF CMake target to `ESMF::ESMF` + ### Fixed ### Removed diff --git a/post/CMakeLists.txt b/post/CMakeLists.txt index 370875e..54a7b09 100644 --- a/post/CMakeLists.txt +++ b/post/CMakeLists.txt @@ -89,7 +89,7 @@ target_link_libraries (eta2prs.x ${this} GMAO_gfio_r4 MAPL GEOS_Shared) target_link_libraries (ec_prs2eta.x ${this} GMAO_gfio_r4 MAPL) target_link_libraries (era5_prs2eta.x ${this} GMAO_gfio_r4 MAPL) target_link_libraries (ec_prs2fv.x ${this} GMAO_gfio_r4 MAPL) -target_link_libraries (stats.x post_nompi GMAO_gfio_r4 MAPL esmf) +target_link_libraries (stats.x post_nompi GMAO_gfio_r4 MAPL ESMF::ESMF) target_link_libraries (flat2hdf.x post_nompi GMAO_gfio_r4) target_link_libraries (gg2fv.x post) target_link_libraries (rs2hdf.x post) From 714d00dbe918bed1b21757a9e420021b89976a3d Mon Sep 17 00:00:00 2001 From: biljanaorescanin Date: Mon, 26 Aug 2024 16:02:12 -0400 Subject: [PATCH 06/24] add candidate for FP res --- pre/remap_restart/remap_utils.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pre/remap_restart/remap_utils.py b/pre/remap_restart/remap_utils.py index 871205c..ccb10a9 100755 --- a/pre/remap_restart/remap_utils.py +++ b/pre/remap_restart/remap_utils.py @@ -104,16 +104,16 @@ message_bc_other_new = ("Select BCs version for new restarts:\n" + message_bc_other) message_agrid_list = f''' - C12 C180 C1440 - C24 C360 C2880 - C48 C720 C5760 - C90 C1000 \n''' + C12 C180 C1120 + C24 C360 C1440 + C48 C720 C2880 + C90 C1000 C5760 \n''' message_agrid_in = ("Enter atmospheric grid of input restarts:\n" + message_agrid_list) message_agrid_new = ("Enter atmospheric grid for new restarts:\n" + message_agrid_list) -validate_agrid = ['C12','C24','C48','C90','C180','C360','C720','C1000','C1440','C2880','C5760'] +validate_agrid = ['C12','C24','C48','C90','C180','C360','C720','C1000','C1120','C1440','C2880','C5760'] message_ogrid_in = "Select data ocean grid/resolution of input restarts:\n" From 2b70a165b5827cd215449f75f538c22ce5b96d37 Mon Sep 17 00:00:00 2001 From: biljanaorescanin Date: Mon, 26 Aug 2024 16:05:17 -0400 Subject: [PATCH 07/24] add res --- pre/remap_restart/remap_analysis.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pre/remap_restart/remap_analysis.py b/pre/remap_restart/remap_analysis.py index 5236c66..96d3895 100755 --- a/pre/remap_restart/remap_analysis.py +++ b/pre/remap_restart/remap_analysis.py @@ -139,6 +139,7 @@ def get_grid_kind(this, grid): hgrd['C540'] = 'd' hgrd['C720'] = 'e' hgrd['C1080'] = 'e' + hgrd['C1120'] = 'e' hgrd['C1440'] = 'e' hgrd['C1536'] = 'e' hgrd['C2160'] = 'e' From 0013b8c85bd222e14d57833e60f5aceb2376b80e Mon Sep 17 00:00:00 2001 From: biljanaorescanin Date: Tue, 27 Aug 2024 09:55:19 -0400 Subject: [PATCH 08/24] add what is changed --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1692ce9..ec5bcbd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added MASKFILE for time-discontinuous data in TEM diagnostics +### Added + +- Added new res C1120 +- NOTE: If running on SLES15 remap tests will not be zero diff for GOCART RST but are zero diff for all other + ## [2.1.1] - 2024-07-30 ### Added From 8449948044c6f097139ebe2a16d23c0abf4e69bb Mon Sep 17 00:00:00 2001 From: Shayon Shakoorzadeh Date: Fri, 6 Sep 2024 13:04:45 -0400 Subject: [PATCH 09/24] slurmified --- .../remap_lake_landice_saltwater.py | 261 +++++++++++++++--- 1 file changed, 216 insertions(+), 45 deletions(-) diff --git a/pre/remap_restart/remap_lake_landice_saltwater.py b/pre/remap_restart/remap_lake_landice_saltwater.py index ca2f9cd..da72ea9 100755 --- a/pre/remap_restart/remap_lake_landice_saltwater.py +++ b/pre/remap_restart/remap_lake_landice_saltwater.py @@ -16,7 +16,7 @@ import ruamel.yaml import shlex from remap_base import remap_base -from remap_utils import get_label +from remap_utils import * from remap_utils import get_geomdir from remap_bin2nc import bin2nc @@ -47,13 +47,9 @@ def remap(self): ogrid = config['input']['shared']['ogrid'] omodel = config['input']['shared']['omodel'] stretch = config['input']['shared']['stretch'] + in_geomdir = get_geomdir(in_bc_base, in_bc_version, agrid=agrid, ogrid=ogrid, omodel=omodel, stretch=stretch) in_tile_file = glob.glob(in_geomdir+ '/*-Pfafstetter.til')[0] - - agrid = config['output']['shared']['agrid'] - ogrid = config['output']['shared']['ogrid'] - omodel = config['output']['shared']['omodel'] - stretch = config['output']['shared']['stretch'] out_geomdir = get_geomdir(out_bc_base, out_bc_version, agrid=agrid, ogrid=ogrid, omodel=omodel, stretch=stretch) out_tile_file = glob.glob(out_geomdir+ '/*-Pfafstetter.til')[0] @@ -170,6 +166,180 @@ def remap(self): print('cd ' + cwdir) os.chdir(cwdir) + + agrid = config['output']['shared']['agrid'] + if agrid[0].upper() == 'C': + imout = int(agrid[1:]) + else: + exit("Only support cs grid so far") + + if (imout <90): + NPE = 12; nwrit = 1 + elif (imout<=180): + NPE = 24; nwrit = 1 + elif (imout<=540): + NPE = 96; nwrit = 1 + elif (imout<=720): + NPE = 192; nwrit = 2 + elif (imout<=1080): + NPE = 384; nwrit = 2 + elif (imout<=1440): + NPE = 576; nwrit = 2 + elif (imout< 2880): + NPE = 768; nwrit = 2 + elif (imout>=2880): + NPE = 5400; nwrit = 6 + + PARTITION ='' + QOS = config['slurm_pbs']['qos'] + TIME = "1:00:00" + if NPE > 532: + assert config['slurm_pbs']['qos'] != 'debug', "qos should be 'allnccs' for NCCS or 'normal' for NAS" + TIME = "12:00:00" + NNODE = '' + job='' + if GEOS_SITE == "NAS": + CONSTRAINT = 'cas_ait' + NNODE = (NPE-1)//40 + 1 + job='PBS' + else: + job='SLURM' + partition = config['slurm_pbs']['partition'] + if (partition != ''): + PARTITION = "#SBATCH --partition=" + partition + + CONSTRAINT = '"[cas|sky]"' + if BUILT_ON_SLES15: + CONSTRAINT = 'mil' + + + remap_template = job_directive[job] + \ +""" +source {Bin}/g5_modules +limit stacksize unlimited + +cd {out_dir}/upper_data +/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_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:" +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 -Lb --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} {stretch_str} + +""" + account = config['slurm_pbs']['account'] + drymassFLG = config['input']['air']['drymass'] + hydrostatic = config['input']['air']['hydrostatic'] + nlevel = config['output']['air']['nlevel'] + log_name = out_dir+'/remap_lake_landice_saltwater_log' + job_name = 'remap_lake_landice_saltwater' + stretch_str = '' + remap_script = remap_template.format(Bin=bindir, account = account, \ + out_dir = out_dir, log_name = log_name, job_name= job_name, drymassFLG = drymassFLG, \ + imout = imout, nwrit = nwrit, NPE = NPE, NNODE = NNODE, \ + QOS = QOS, TIME = TIME, CONSTRAINT = CONSTRAINT, PARTITION = PARTITION, nlevel = nlevel, hydrostatic = hydrostatic, + stretch_str = stretch_str) + + script_name = './remap_lake_landice_saltwater.j' + + lake_landice_saltwater = open(script_name, 'wt') + lake_landice_saltwater.write(remap_script) + lake_landice_saltwater.close() + + in_bc_base = config['input']['shared']['bc_base'] + if "gmao_SIteam/ModelData" in in_bc_base: + assert GEOS_SITE == "NAS", "wrong site to run the package" + + interactive = None + if GEOS_SITE == 'NAS': + interactive = os.getenv('PBS_JOBID', default = None) + else: + interactive = os.getenv('SLURM_JOB_ID', default = None) + + if (interactive) : + print('interactive mode\n') + if GEOS_SITE != 'NAS': + ntasks = os.getenv('SLURM_NTASKS', default = None) + if ( not ntasks): + nnodes = int(os.getenv('SLURM_NNODES', default = '1')) + ncpus = int(os.getenv('SLURM_CPUS_ON_NODE', default = '28')) + ntasks = nnodes * ncpus + ntasks = int(ntasks) + if (ntasks < NPE ): + print("\nYou should have at least {NPE} cores. Now you only have {ntasks} cores ".format(NPE=NPE, ntasks=ntasks)) + + subprocess.call(['chmod', '755', script_name]) + print(script_name+ ' 1>' + log_name + ' 2>&1') + os.system(script_name + ' 1>' + log_name+ ' 2>&1') + elif GEOS_SITE == "NAS" : + print('qsub -W block=true '+ script_name +'\n') + subprocess.call(['qsub', '-W','block=true', script_name]) + else: + print('sbatch -W '+ script_name +'\n') + subprocess.call(['sbatch', '-W', script_name]) + +# +# post process +# + 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) + + print('\n Move remap_lake_landice_saltwater.j to ' + out_dir) + shutil.move('remap_lake_landice_saltwater.j', out_dir+"/remap_lake_landice_saltwater.j") + with open(out_dir+'/cap_restart', 'w') as f: + yyyymmddhh_ = str(config['input']['shared']['yyyymmddhh']) + time = yyyymmddhh_[0:8]+' '+yyyymmddhh_[8:10]+'0000' + print('Create cap_restart') + f.write(time) + print('cd ' + cwdir) + os.chdir(cwdir) + self.remove_merra2() def run_and_log(self, cmd, log_name): @@ -185,14 +355,15 @@ def run_and_log(self, cmd, log_name): log_.write(stdout) log_.write(stderr) + def find_rst(self): surf_restarts =[ - "route_internal_rst" , - "lake_internal_rst" , - "landice_internal_rst" , - "openwater_internal_rst" , - "saltwater_internal_rst" , - "seaicethermo_internal_rst"] + "route_internal_rst" , + "lake_internal_rst" , + "landice_internal_rst" , + "openwater_internal_rst" , + "saltwater_internal_rst" , + "seaicethermo_internal_rst"] rst_dir = self.config['input']['shared']['rst_dir'] yyyymmddhh_ = str(self.config['input']['shared']['yyyymmddhh']) @@ -201,48 +372,48 @@ def find_rst(self): for f in surf_restarts : files = glob.glob(rst_dir+ '/*'+f+'*'+time+'*') if len(files) >0: - restarts_in.append(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) + restarts_in.append(fname) return restarts_in def copy_merra2(self): - if not self.config['input']['shared']['MERRA-2']: - return - - expid = self.config['input']['shared']['expid'] - yyyymmddhh_ = str(self.config['input']['shared']['yyyymmddhh']) - yyyy_ = yyyymmddhh_[0:4] - mm_ = yyyymmddhh_[4:6] - dd_ = yyyymmddhh_[6:8] - hh_ = yyyymmddhh_[8:10] - - suffix = yyyymmddhh_[0:8]+'_'+ hh_ + 'z.bin' - merra_2_rst_dir = '/archive/users/gmao_ops/MERRA2/gmao_ops/GEOSadas-5_12_4/'+expid +'/rs/Y'+yyyy_ +'/M'+mm_+'/' - rst_dir = self.config['input']['shared']['rst_dir'] + '/' - os.makedirs(rst_dir, exist_ok = True) - print(' Copy MERRA-2 surface restarts \n from \n ' + merra_2_rst_dir + '\n to\n '+ rst_dir +'\n') - - surfin = [ merra_2_rst_dir + expid+'.lake_internal_rst.' + suffix, - merra_2_rst_dir + expid+'.landice_internal_rst.' + suffix, - merra_2_rst_dir + expid+'.saltwater_internal_rst.'+ suffix] - bin2nc_yaml = ['bin2nc_merra2_lake.yaml', 'bin2nc_merra2_landice.yaml','bin2nc_merra2_salt.yaml'] - bin_path = os.path.dirname(os.path.realpath(__file__)) - for (f,yf) in zip(surfin, bin2nc_yaml): - fname = os.path.basename(f) - dest = rst_dir + '/'+fname - print("Copy file "+f +" to " + rst_dir) - shutil.copy(f, dest) - ncdest = dest.replace('z.bin', 'z.nc4') - yaml_file = bin_path + '/'+yf - print('Convert bin to nc4:' + dest + ' to \n' + ncdest + '\n') - bin2nc(dest, ncdest, yaml_file) - os.remove(dest) + if not self.config['input']['shared']['MERRA-2']: + return + + expid = self.config['input']['shared']['expid'] + yyyymmddhh_ = str(self.config['input']['shared']['yyyymmddhh']) + yyyy_ = yyyymmddhh_[0:4] + mm_ = yyyymmddhh_[4:6] + dd_ = yyyymmddhh_[6:8] + hh_ = yyyymmddhh_[8:10] + + suffix = yyyymmddhh_[0:8]+'_'+ hh_ + 'z.bin' + merra_2_rst_dir = '/archive/users/gmao_ops/MERRA2/gmao_ops/GEOSadas-5_12_4/'+expid +'/rs/Y'+yyyy_ +'/M'+mm_+'/' + rst_dir = self.config['input']['shared']['rst_dir'] + '/' + os.makedirs(rst_dir, exist_ok = True) + print(' Copy MERRA-2 surface restarts \n from \n ' + merra_2_rst_dir + '\n to\n '+ rst_dir +'\n') + + surfin = [ merra_2_rst_dir + expid+'.lake_internal_rst.' + suffix, + merra_2_rst_dir + expid+'.landice_internal_rst.' + suffix, + merra_2_rst_dir + expid+'.saltwater_internal_rst.'+ suffix] + bin2nc_yaml = ['bin2nc_merra2_lake.yaml', 'bin2nc_merra2_landice.yaml','bin2nc_merra2_salt.yaml'] + bin_path = os.path.dirname(os.path.realpath(__file__)) + for (f,yf) in zip(surfin, bin2nc_yaml): + fname = os.path.basename(f) + dest = rst_dir + '/'+fname + print("Copy file "+f +" to " + rst_dir) + shutil.copy(f, dest) + ncdest = dest.replace('z.bin', 'z.nc4') + yaml_file = bin_path + '/'+yf + print('Convert bin to nc4:' + dest + ' to \n' + ncdest + '\n') + bin2nc(dest, ncdest, yaml_file) + os.remove(dest) if __name__ == '__main__' : lls = lake_landice_saltwater(params_file='remap_params.yaml') From ee89bd06016f6f38cc11692e4878c211cf8fe691 Mon Sep 17 00:00:00 2001 From: biljanaorescanin Date: Mon, 9 Sep 2024 14:38:04 -0400 Subject: [PATCH 10/24] add GEOS-IT option for remap restarts --- pre/remap_restart/remap_analysis.py | 51 ++++++++- pre/remap_restart/remap_base.py | 4 + pre/remap_restart/remap_catchANDcn.py | 54 ++++++++- pre/remap_restart/remap_command_line.py | 4 + .../remap_lake_landice_saltwater.py | 53 ++++++++- pre/remap_restart/remap_params.tpl | 1 + pre/remap_restart/remap_questions.py | 108 ++++++++++++------ pre/remap_restart/remap_upper.py | 52 ++++++++- pre/remap_restart/remap_utils.py | 53 +++++++-- 9 files changed, 330 insertions(+), 50 deletions(-) diff --git a/pre/remap_restart/remap_analysis.py b/pre/remap_restart/remap_analysis.py index 5236c66..2809909 100755 --- a/pre/remap_restart/remap_analysis.py +++ b/pre/remap_restart/remap_analysis.py @@ -23,7 +23,10 @@ class analysis(remap_base): def __init__(self, **configs): super().__init__(**configs) - self.copy_merra2() + if self.config['input']['shared']['MERRA-2']: + self.copy_merra2() + if self.config['input']['shared']['GEOS-IT']: + self.copy_geosit() def remap(self): config = self.config @@ -125,7 +128,10 @@ def remap(self): print( "cd " + cwdir) os.chdir(cwdir) - self.remove_merra2() + if self.config['input']['shared']['MERRA-2']: + self.remove_merra2() + if self.config['input']['shared']['GEOS-IT']: + self.remove_geosit() def get_grid_kind(this, grid): hgrd = {} @@ -156,6 +162,47 @@ def find_analysis(self): analysis_in = bkgs + sfcs + traks + anasat return list(dict.fromkeys(analysis_in)) + def copy_geosit(self): + if not self.config['input']['shared']['GEOS-IT']: + return + + expid = self.config['input']['shared']['expid'] + yyyymmddhh_ = str(self.config['input']['shared']['yyyymmddhh']) + yyyy_ = yyyymmddhh_[0:4] + mm_ = yyyymmddhh_[4:6] + day_ = yyyymmddhh_[6:8] # Extract the day from yyyymmddhh_ + + time_suffix = '_21z.tar' + + geos_it_rst_dir = '/discover/nobackup/projects/gmao/geos-it/dao_ops/archive/' + expid + '/rs/Y' + yyyy_ + '/M' + mm_ + '/' + rst_dir = self.config['input']['shared']['rst_dir'] + '/' + os.makedirs(rst_dir, exist_ok=True) + + print('Stage GEOS-IT restarts \n from \n ' + geos_it_rst_dir + '\n to\n ' + rst_dir + '\n') + + # Only use the specific day from yyyymmddhh_ + filename = f'{expid}.rst.{yyyy_}{mm_}{day_}{time_suffix}' + src_file = os.path.join(geos_it_rst_dir, filename) + dest_file = os.path.join(rst_dir, filename) + + if os.path.exists(src_file): + print(f"Copying file {src_file} to {dest_file}") + shutil.copy(src_file, dest_file) + + # Untar the .tar file using the tar command + if os.path.exists(dest_file): + print(f"Untarring {dest_file} to {rst_dir}") + try: + subprocess.run(['tar', '-xf', dest_file, '-C', rst_dir], check=True) + print(f"Untarred {dest_file} successfully.") + except subprocess.CalledProcessError as e: + print(f"Error untarring {dest_file}: {e}") + + # Optionally remove the tar file after extraction + os.remove(dest_file) + else: + print(f"File {src_file} does not exist.") + def copy_merra2(self): if not self.config['input']['shared']['MERRA-2']: return diff --git a/pre/remap_restart/remap_base.py b/pre/remap_restart/remap_base.py index d018911..93e8466 100755 --- a/pre/remap_restart/remap_base.py +++ b/pre/remap_restart/remap_base.py @@ -33,6 +33,10 @@ def remove_merra2(self): if self.config['input']['shared']['MERRA-2']: print(" remove temporary folder that contains MERRA-2 archived files ... \n") subprocess.call(['/bin/rm', '-rf', self.config['input']['shared']['rst_dir']]) + def remove_geosit(self): + if self.config['input']['shared']['GEOS-IT']: + print(" remove temporary folder that contains GEOS-IT archived files ... \n") + subprocess.call(['/bin/rm', '-rf', self.config['input']['shared']['rst_dir']]) def copy_without_remap(self, restarts_in, compared_file_in, compared_file_out, suffix, catch=False): # diff --git a/pre/remap_restart/remap_catchANDcn.py b/pre/remap_restart/remap_catchANDcn.py index 8481707..67d8e02 100755 --- a/pre/remap_restart/remap_catchANDcn.py +++ b/pre/remap_restart/remap_catchANDcn.py @@ -23,7 +23,10 @@ class catchANDcn(remap_base): def __init__(self, **configs): super().__init__(**configs) - self.copy_merra2() + if self.config['input']['shared']['MERRA-2']: + self.copy_merra2() + if self.config['input']['shared']['GEOS-IT']: + self.copy_geosit() def remap(self): if not self.config['output']['surface']['remap_catch']: @@ -222,7 +225,10 @@ def remap(self): print( "cd " + cwdir) os.chdir(cwdir) - self.remove_merra2() + if self.config['input']['shared']['MERRA-2']: + self.remove_merra2() + if self.config['input']['shared']['GEOS-IT']: + self.remove_geosit() def copy_merra2(self): if not self.config['input']['shared']['MERRA-2']: @@ -248,6 +254,48 @@ def copy_merra2(self): print("Copy file "+f +" to " + rst_dir) shutil.copy(f, dest) + def copy_geosit(self): + if not self.config['input']['shared']['GEOS-IT']: + return + + expid = self.config['input']['shared']['expid'] + yyyymmddhh_ = str(self.config['input']['shared']['yyyymmddhh']) + yyyy_ = yyyymmddhh_[0:4] + mm_ = yyyymmddhh_[4:6] + day_ = yyyymmddhh_[6:8] # Extract the day from yyyymmddhh_ + + time_suffix = '_21z.tar' + + geos_it_rst_dir = '/discover/nobackup/projects/gmao/geos-it/dao_ops/archive/' + expid + '/rs/Y' + yyyy_ + '/M' + mm_ + '/' + rst_dir = self.config['input']['shared']['rst_dir'] + '/' + os.makedirs(rst_dir, exist_ok=True) + + print('Stage GEOS-IT restarts \n from \n ' + geos_it_rst_dir + '\n to\n ' + rst_dir + '\n') + + # Only use the specific day from yyyymmddhh_ + filename = f'{expid}.rst.{yyyy_}{mm_}{day_}{time_suffix}' + src_file = os.path.join(geos_it_rst_dir, filename) + dest_file = os.path.join(rst_dir, filename) + + if os.path.exists(src_file): + print(f"Copying file {src_file} to {dest_file}") + shutil.copy(src_file, dest_file) + + # Untar the .tar file using the tar command + if os.path.exists(dest_file): + print(f"Untarring {dest_file} to {rst_dir}") + try: + subprocess.run(['tar', '-xf', dest_file, '-C', rst_dir], check=True) + print(f"Untarred {dest_file} successfully.") + except subprocess.CalledProcessError as e: + print(f"Error untarring {dest_file}: {e}") + + # Optionally remove the tar file after extraction + os.remove(dest_file) + else: + print(f"File {src_file} does not exist.") + + def ask_catch_questions(): catch_input_shared_rst_dir = '' def has_rs_rc_out(path): @@ -342,7 +390,7 @@ def has_catch_rst(text): { "type": "select", "name": "output:shared:ogrid", - "message": message_ogrid_in, + "message": message_ogrid_new, "choices": choices_ogrid_data, "default": lambda x: data_ocean_default(x.get('output:shared:agrid')), "when": lambda x : x['output:surface:EASE_grid'] == 'Cubed-Sphere', diff --git a/pre/remap_restart/remap_command_line.py b/pre/remap_restart/remap_command_line.py index 9b59632..0d1435c 100755 --- a/pre/remap_restart/remap_command_line.py +++ b/pre/remap_restart/remap_command_line.py @@ -39,6 +39,7 @@ def parse_args(program_description): help = "Use command line as input", ) p_command.add_argument('-merra2', action='store_true', default= False, help='use merra2 restarts') + p_command.add_argument('-geosit', action='store_true', default= False, help='use GEOSIT restarts') p_command.add_argument('-ymdh', help='yyyymmddhh year month date hour of input and new restarts') p_command.add_argument('-grout', help='Grid ID/resolution of new restarts, format C[xxx] (cubed-sphere only for now)') @@ -91,11 +92,14 @@ def get_answers_from_command_line(cml): answers = {} answers["input:shared:MERRA-2"] = cml.merra2 + answers["input:shared:GEOS-IT"] = cml.geosit answers["input:shared:yyyymmddhh"] = cml.ymdh answers["input:shared:omodel"] = cml.ocnmdlin answers["output:shared:out_dir"] = os.path.abspath(cml.out_dir + '/') if cml.merra2: init_merra2(answers) + if cml.geosit: + init_geosit(answers) else: answers["input:shared:bc_version"] = cml.bcvin answers["input:surface:catch_model"] = cml.catch_model diff --git a/pre/remap_restart/remap_lake_landice_saltwater.py b/pre/remap_restart/remap_lake_landice_saltwater.py index ca2f9cd..6691e04 100755 --- a/pre/remap_restart/remap_lake_landice_saltwater.py +++ b/pre/remap_restart/remap_lake_landice_saltwater.py @@ -12,6 +12,7 @@ import os import subprocess as sp import shutil +import subprocess import glob import ruamel.yaml import shlex @@ -23,7 +24,10 @@ class lake_landice_saltwater(remap_base): def __init__(self, **configs): super().__init__(**configs) - self.copy_merra2() + if self.config['input']['shared']['MERRA-2']: + self.copy_merra2() + if self.config['input']['shared']['GEOS-IT']: + self.copy_geosit() def remap(self): if not self.config['output']['surface']['remap_water']: @@ -170,7 +174,10 @@ def remap(self): print('cd ' + cwdir) os.chdir(cwdir) - self.remove_merra2() + if self.config['input']['shared']['MERRA-2']: + self.remove_merra2() + if self.config['input']['shared']['GEOS-IT']: + self.remove_geosit() def run_and_log(self, cmd, log_name): print('\n'+cmd) @@ -244,6 +251,48 @@ def copy_merra2(self): bin2nc(dest, ncdest, yaml_file) os.remove(dest) + def copy_geosit(self): + if not self.config['input']['shared']['GEOS-IT']: + return + + expid = self.config['input']['shared']['expid'] + yyyymmddhh_ = str(self.config['input']['shared']['yyyymmddhh']) + yyyy_ = yyyymmddhh_[0:4] + mm_ = yyyymmddhh_[4:6] + day_ = yyyymmddhh_[6:8] # Extract the day from yyyymmddhh_ + + time_suffix = '_21z.tar' + + geos_it_rst_dir = '/discover/nobackup/projects/gmao/geos-it/dao_ops/archive/' + expid + '/rs/Y' + yyyy_ + '/M' + mm_ + '/' + rst_dir = self.config['input']['shared']['rst_dir'] + '/' + os.makedirs(rst_dir, exist_ok=True) + + print('Stage GEOS-IT restarts \n from \n ' + geos_it_rst_dir + '\n to\n ' + rst_dir + '\n') + + # Only use the specific day from yyyymmddhh_ + filename = f'{expid}.rst.{yyyy_}{mm_}{day_}{time_suffix}' + src_file = os.path.join(geos_it_rst_dir, filename) + dest_file = os.path.join(rst_dir, filename) + + if os.path.exists(src_file): + print(f"Copying file {src_file} to {dest_file}") + shutil.copy(src_file, dest_file) + + # Untar the .tar file using the tar command + if os.path.exists(dest_file): + print(f"Untarring {dest_file} to {rst_dir}") + try: + subprocess.run(['tar', '-xf', dest_file, '-C', rst_dir], check=True) + print(f"Untarred {dest_file} successfully.") + except subprocess.CalledProcessError as e: + print(f"Error untarring {dest_file}: {e}") + + # Optionally remove the tar file after extraction + os.remove(dest_file) + else: + print(f"File {src_file} does not exist.") + +# if __name__ == '__main__' : lls = lake_landice_saltwater(params_file='remap_params.yaml') lls.remap() diff --git a/pre/remap_restart/remap_params.tpl b/pre/remap_restart/remap_params.tpl index 1e7f655..a68c1a1 100644 --- a/pre/remap_restart/remap_params.tpl +++ b/pre/remap_restart/remap_params.tpl @@ -10,6 +10,7 @@ input: hydrostatic: 0 shared: MERRA-2: false + GEOS-IT: false stretch: false # (coupled) ocean model: data, MOM5, MOM6 omodel: data diff --git a/pre/remap_restart/remap_questions.py b/pre/remap_restart/remap_questions.py index af624c0..84db949 100755 --- a/pre/remap_restart/remap_questions.py +++ b/pre/remap_restart/remap_questions.py @@ -50,12 +50,30 @@ def validate_merra2_time(text): return False else: return False + +def validate_geosit_time(text): + if len(text) == 10 : + dd = text[6:8] + hh = text[8:] + if dd in ['14','28'] and hh in ['21']: + return True + else: + return False + else: + return False + def SITE_MERRA2(x): if GEOS_SITE == "NAS": x['input:shared:MERRA-2']= False return False return True +def SITE_GEOSIT(x): + if GEOS_SITE == "NAS": + x['input:shared:GEOS-IT']= False + return False + return True + def ask_questions(): # See remap_utils.py for definitions of "choices", "message" strings, and "validate" lists @@ -69,32 +87,48 @@ def ask_questions(): "default": False, "when": lambda x: SITE_MERRA2(x), }, + { + "type": "confirm", + "name": "input:shared:GEOS-IT", + "message": "Remap archived GEOS-IT restarts? (NCCS/Discover only; elsewhere, select 'N' and complete full config; requires nc4 restarts.)\n", + "default": False, + "when": lambda x: SITE_GEOSIT(x) and not x.get("input:shared:MERRA-2", False), + }, { "type": "path", "name": "input:shared:rst_dir", "message": "Enter input directory with restart files to be remapped:\n", - "when": lambda x: not x['input:shared:MERRA-2'], + "when": lambda x: not x.get("input:shared:MERRA-2", False) and not x.get("input:shared:GEOS-IT", False), + }, + { + "type": "text", + "name": "input:shared:yyyymmddhh", + "message": "Enter the restart date and hour (YYYYMMDDHH):\n", + "validate": lambda text: len(text) == 10, + "when": lambda x: not x.get('input:shared:MERRA-2', False) and not x.get('input:shared:GEOS-IT', False) and not fvcore_info(x), }, { "type": "text", "name": "input:shared:yyyymmddhh", - "message": (message_datetime + ".)\n"), - "validate": lambda text: len(text)==10 , - "when": lambda x: not x['input:shared:MERRA-2'] and not fvcore_info(x), + "message": "Enter the restart date and hour (YYYYMMDDHH, hour = 03, 09, 15, or 21 [z]):\n", + "validate": lambda text: validate_merra2_time(text), + "when": lambda x: x.get("input:shared:MERRA-2", False), }, { "type": "text", "name": "input:shared:yyyymmddhh", - "message": (message_datetime + "; hour = 03, 09, 15, or 21 [z].)\n"), - "validate": lambda text: validate_merra2_time(text) , - "when": lambda x: x['input:shared:MERRA-2'], + "message": "Enter the restart date and hour (YYYYMMDDHH, Only days available are 14th and 28th and only hour = 21 [z]):\n", + "validate": lambda text: validate_geosit_time(text), + "when": lambda x: x.get("input:shared:GEOS-IT", False) and not x.get("input:shared:MERRA-2", False), }, + { "type": "path", "name": "output:shared:out_dir", "message": message_out_dir, }, + # dummy (invisible) question to run function that initializes MERRA-2 config { "type": "path", @@ -103,33 +137,41 @@ def ask_questions(): # always return false, so question never shows but changes x "when": lambda x: init_merra2(x), }, - + # dummy (invisible) question to run function that initializes GEOS-IT config { - "type": "text", - "name": "input:shared:agrid", - "message": message_agrid_in, - "validate": lambda text : text in validate_agrid, - # if it is merra-2 or has_fvcore, agrid is deduced - "when": lambda x: not x['input:shared:MERRA-2'] and not fvcore_info(x), + "type": "path", + "name": "output:shared:out_dir", + "message": "init GEOSIT\n", + # always return false, so question never shows but changes x + "when": lambda x: init_geosit(x), }, + # for both MERRA2 and GEOS-IT { - "type": "select", - "name": "input:shared:omodel", - "message": "Select ocean model of input restarts:\n", - "choices": choices_omodel, - "default": "data", - "when": lambda x: not x['input:shared:MERRA-2'] + "type": "text", + "name": "input:shared:agrid", + "message": message_agrid_in, + "validate": lambda text: text in validate_agrid, + "when": lambda x: not x['input:shared:MERRA-2'] and not x['input:shared:GEOS-IT'] and not fvcore_info(x), }, - { - "type": "select", - "name": "input:shared:ogrid", - "message": message_ogrid_in, - "choices": choices_ogrid_data, - "default": lambda x: data_ocean_default(x.get('input:shared:agrid')), - "when": lambda x: x.get('input:shared:omodel') == 'data' and not x['input:shared:MERRA-2'], - }, + { + "type": "select", + "name": "input:shared:omodel", + "message": "Select ocean model of input restarts:\n", + "choices": choices_omodel, + "default": "data", + "when": lambda x: not x['input:shared:MERRA-2'] and not x['input:shared:GEOS-IT'], + }, + + { + "type": "select", + "name": "input:shared:ogrid", + "message": message_ogrid_in, + "choices": choices_ogrid_data, + "default": lambda x: data_ocean_default(x.get('input:shared:agrid')), + "when": lambda x: x.get('input:shared:omodel') == 'data' and not x['input:shared:MERRA-2'] and not x['input:shared:GEOS-IT'], + }, # dummy (invisible) question to remove parenthetical comments from selected input:shared:ogrid { @@ -232,7 +274,7 @@ def ask_questions(): "name": "input:shared:bc_version", "message": message_bc_ops_in, "choices": choices_bc_ops, - "when": lambda x: not x["input:shared:MERRA-2"], + "when": lambda x: not x["input:shared:MERRA-2"] and not x["input:shared:GEOS-IT"], }, { @@ -249,7 +291,7 @@ def ask_questions(): "message": message_bc_ops_new, "choices": choices_bc_ops, "default": "NL3", - "when": lambda x: x["input:shared:MERRA-2"], + "when": lambda x: x["input:shared:MERRA-2"] or x["input:shared:GEOS-IT"], }, { @@ -258,7 +300,7 @@ def ask_questions(): "message": "Select BCs version for new restarts:\n", "choices": choices_bc_ops, "default": "NL3", - "when": lambda x: not x["input:shared:MERRA-2"], + "when": lambda x: not x["input:shared:MERRA-2"] and not x["input:shared:GEOS-IT"], }, { @@ -355,7 +397,6 @@ def ask_questions(): "message": "Remap bkg files? (Required by ADAS but not mapped onto ADAS grid; run one ADAS cycle to spin up.) ", "default": False, }, - { "type": "confirm", "name": "output:analysis:lcv", @@ -419,11 +460,12 @@ def ask_questions(): answers['output:shared:out_dir'] = os.path.abspath(answers['output:shared:out_dir']) if answers.get('input:air:nlevel') : del answers['input:air:nlevel'] - if answers["output:surface:remap"] and not answers["input:shared:MERRA-2"]: + if answers["output:surface:remap"] and not answers["input:shared:MERRA-2"] and not answers["input:shared:GEOS-IT"]: answers["input:surface:catch_model"] = catch_model(answers) answers["output:surface:remap_water"] = answers["output:surface:remap"] answers["output:surface:remap_catch"] = answers["output:surface:remap"] del answers["output:surface:remap"] + return answers diff --git a/pre/remap_restart/remap_upper.py b/pre/remap_restart/remap_upper.py index 6704d8d..899d32f 100755 --- a/pre/remap_restart/remap_upper.py +++ b/pre/remap_restart/remap_upper.py @@ -22,7 +22,10 @@ class upperair(remap_base): def __init__(self, **configs): super().__init__(**configs) - self.copy_merra2() + if self.config['input']['shared']['MERRA-2']: + self.copy_merra2() + if self.config['input']['shared']['GEOS-IT']: + self.copy_geosit() def remap(self): if not self.config['output']['air']['remap'] : @@ -332,7 +335,10 @@ def remap(self): print('cd ' + cwdir) os.chdir(cwdir) - self.remove_merra2() + if self.config['input']['shared']['MERRA-2']: + self.remove_merra2() + if self.config['input']['shared']['GEOS-IT']: + self.remove_geosit() def find_rst(self): rst_dir = self.config['input']['shared']['rst_dir'] @@ -391,6 +397,48 @@ def copy_merra2(self): bin2nc(dest, ncdest, yaml_file) os.remove(dest) + def copy_geosit(self): + if not self.config['input']['shared']['GEOS-IT']: + return + + expid = self.config['input']['shared']['expid'] + yyyymmddhh_ = str(self.config['input']['shared']['yyyymmddhh']) + yyyy_ = yyyymmddhh_[0:4] + mm_ = yyyymmddhh_[4:6] + day_ = yyyymmddhh_[6:8] # Extract the day from yyyymmddhh_ + + time_suffix = '_21z.tar' + + geos_it_rst_dir = '/discover/nobackup/projects/gmao/geos-it/dao_ops/archive/' + expid + '/rs/Y' + yyyy_ + '/M' + mm_ + '/' + rst_dir = self.config['input']['shared']['rst_dir'] + '/' + os.makedirs(rst_dir, exist_ok=True) + + print('Stage GEOS-IT restarts \n from \n ' + geos_it_rst_dir + '\n to\n ' + rst_dir + '\n') + + # Only use the specific day from yyyymmddhh_ + filename = f'{expid}.rst.{yyyy_}{mm_}{day_}{time_suffix}' + src_file = os.path.join(geos_it_rst_dir, filename) + dest_file = os.path.join(rst_dir, filename) + + if os.path.exists(src_file): + print(f"Copying file {src_file} to {dest_file}") + shutil.copy(src_file, dest_file) + + # Untar the .tar file using the tar command + if os.path.exists(dest_file): + print(f"Untarring {dest_file} to {rst_dir}") + try: + subprocess.run(['tar', '-xf', dest_file, '-C', rst_dir], check=True) + print(f"Untarred {dest_file} successfully.") + except subprocess.CalledProcessError as e: + print(f"Error untarring {dest_file}: {e}") + + # Optionally remove the tar file after extraction + os.remove(dest_file) + else: + print(f"File {src_file} does not exist.") + + if __name__ == '__main__' : air = upperair(params_file='remap_params.yaml') air.remap() diff --git a/pre/remap_restart/remap_utils.py b/pre/remap_restart/remap_utils.py index 871205c..e343165 100755 --- a/pre/remap_restart/remap_utils.py +++ b/pre/remap_restart/remap_utils.py @@ -17,8 +17,8 @@ #During cmake step, the string will be changed according to the system -BUILT_ON_SLES15 = "@BUILT_ON_SLES15@" -GEOS_SITE = "@GEOS_SITE@" +BUILT_ON_SLES15 = "TRUE" +GEOS_SITE = "NCCS" if BUILT_ON_SLES15 == "TRUE": BUILT_ON_SLES15 = True @@ -117,6 +117,8 @@ message_ogrid_in = "Select data ocean grid/resolution of input restarts:\n" +message_ogrid_new = "Select data ocean grid/resolution of output restarts:\n" + message_qos = "SLURM or PBS quality-of-service (qos)? (If resolution is c1440 or higher, enter 'allnccs' for NCCS or 'normal' for NAS.)\n" message_account = "Select/enter SLURM or PBS account:\n" @@ -181,6 +183,35 @@ def init_merra2(x): return False +def init_geosit(x): + if not x.get('input:shared:GEOS-IT') : return False + + yyyymm = int(x.get('input:shared:yyyymmddhh')[0:6]) + if yyyymm < 199701 : + exit("Error. GEOS-IT data < 1997 not available\n") + elif (yyyymm < 199701): + expid = "d5294_geosit_jan98" + elif (yyyymm < 200701): + expid = "d5294_geosit_jan08" + elif (yyyymm < 201701): + expid = "d5294_geosit_jan18" + else: + expid = "d5294_geosit_jan18" + x['input:shared:expid'] = expid + x['input:shared:omodel'] = 'data' + x['input:shared:agrid'] = 'C180' + x['input:shared:ogrid'] = 'CS' + x['input:shared:omodel'] = 'data' + x['input:shared:bc_version'] = 'NL3' + x['input:shared:bc_base'] = '/discover/nobackup/projects/gmao/bcs_shared/fvInput/ExtData/esm/tiles' + x['input:surface:catch_model'] = 'catch' + x['input:shared:stretch'] = False + x['input:shared:rst_dir'] = x['output:shared:out_dir'] + '/geosit_tmp_'+x['input:shared:yyyymmddhh']+'/' + x['input:air:nlevel'] = 72 + + return False + + def fvcore_info(x): if 'input:shared:agrid' in x.keys(): return True @@ -303,11 +334,15 @@ def wemin_default(bc_version): return default_ def show_wemin_default(x): - if not x['input:shared:MERRA-2']: - return True + if x['input:shared:MERRA-2']: + x['input:surface:wemin'] = '26' + return False + elif x['input:shared:GEOS-IT']: + x['input:surface:wemin'] = '13' + return False else: - x['input:surface:wemin'] = '26' - return False + # If neither MERRA2 or GEOS-IT is selected option will be shown on screen + return True def zoom_default(x): zoom_ = '8' @@ -318,7 +353,7 @@ def zoom_default(x): zoom_ = str(int(zoom)) if zoom < 1 : zoom_ = '1' if zoom > 8 : zoom_ = '8' - if x['input:shared:MERRA-2'] : + if x.get('input:shared:MERRA-2') or x.get('input:shared:GEOS-IT'): zoom_ = '2' return zoom_ @@ -376,7 +411,8 @@ def print_config( config, indent = 0 ): def get_command_line_from_answers(answers): - merra2 = " -merra2 " if answers["input:shared:MERRA-2"] else "" + merra2 = " -merra2 " if "input:shared:MERRA-2" in answers else "" + geosit = " -geosit " if "input:shared:GEOS-IT" in answers else "" ymdh = " -ymdh " + answers["input:shared:yyyymmddhh"] rst_dir = " -rst_dir " + answers["input:shared:rst_dir"] @@ -454,6 +490,7 @@ def get_command_line_from_answers(answers): partition = " -partition " + answers["slurm_pbs:partition"] cmdl = "remap_restarts.py command_line " + merra2 + \ + geosit + \ ymdh + \ grout + \ levsout + \ From e970d4d4f05188c649b67990a1b340f05d3b90fa Mon Sep 17 00:00:00 2001 From: Biljana Orescanin <68251545+biljanaorescanin@users.noreply.github.com> Date: Mon, 9 Sep 2024 15:07:36 -0400 Subject: [PATCH 11/24] Update CHANGELOG.md --- CHANGELOG.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ec5bcbd..56102b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- Added new res C1120 +- NOTE: If running on SLES15 remap tests will not be zero diff for GOCART RST but are zero diff for all other + ### Changed ### Fixed @@ -23,11 +26,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added MASKFILE for time-discontinuous data in TEM diagnostics -### Added - -- Added new res C1120 -- NOTE: If running on SLES15 remap tests will not be zero diff for GOCART RST but are zero diff for all other - ## [2.1.1] - 2024-07-30 ### Added From 6eb86c62f878b16f800f840d69dc4abca3dfa4b9 Mon Sep 17 00:00:00 2001 From: biljanaorescanin Date: Mon, 9 Sep 2024 15:10:10 -0400 Subject: [PATCH 12/24] update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1692ce9..3e21a87 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 +- Add remapping for GEOS-IT restarts + ### Changed ### Fixed From 5bec977ac0be453e229d0640127d7731213e5f29 Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Tue, 10 Sep 2024 15:24:47 -0400 Subject: [PATCH 13/24] consolidate copy_geosit and remove_geosit --- pre/remap_restart/remap_analysis.py | 44 +---------------- pre/remap_restart/remap_base.py | 43 +++++++++++++++++ pre/remap_restart/remap_catchANDcn.py | 47 +------------------ .../remap_lake_landice_saltwater.py | 45 +----------------- pre/remap_restart/remap_restarts.py | 2 + pre/remap_restart/remap_upper.py | 45 +----------------- 6 files changed, 49 insertions(+), 177 deletions(-) diff --git a/pre/remap_restart/remap_analysis.py b/pre/remap_restart/remap_analysis.py index 2809909..e69d215 100755 --- a/pre/remap_restart/remap_analysis.py +++ b/pre/remap_restart/remap_analysis.py @@ -130,8 +130,6 @@ def remap(self): if self.config['input']['shared']['MERRA-2']: self.remove_merra2() - if self.config['input']['shared']['GEOS-IT']: - self.remove_geosit() def get_grid_kind(this, grid): hgrd = {} @@ -162,47 +160,6 @@ def find_analysis(self): analysis_in = bkgs + sfcs + traks + anasat return list(dict.fromkeys(analysis_in)) - def copy_geosit(self): - if not self.config['input']['shared']['GEOS-IT']: - return - - expid = self.config['input']['shared']['expid'] - yyyymmddhh_ = str(self.config['input']['shared']['yyyymmddhh']) - yyyy_ = yyyymmddhh_[0:4] - mm_ = yyyymmddhh_[4:6] - day_ = yyyymmddhh_[6:8] # Extract the day from yyyymmddhh_ - - time_suffix = '_21z.tar' - - geos_it_rst_dir = '/discover/nobackup/projects/gmao/geos-it/dao_ops/archive/' + expid + '/rs/Y' + yyyy_ + '/M' + mm_ + '/' - rst_dir = self.config['input']['shared']['rst_dir'] + '/' - os.makedirs(rst_dir, exist_ok=True) - - print('Stage GEOS-IT restarts \n from \n ' + geos_it_rst_dir + '\n to\n ' + rst_dir + '\n') - - # Only use the specific day from yyyymmddhh_ - filename = f'{expid}.rst.{yyyy_}{mm_}{day_}{time_suffix}' - src_file = os.path.join(geos_it_rst_dir, filename) - dest_file = os.path.join(rst_dir, filename) - - if os.path.exists(src_file): - print(f"Copying file {src_file} to {dest_file}") - shutil.copy(src_file, dest_file) - - # Untar the .tar file using the tar command - if os.path.exists(dest_file): - print(f"Untarring {dest_file} to {rst_dir}") - try: - subprocess.run(['tar', '-xf', dest_file, '-C', rst_dir], check=True) - print(f"Untarred {dest_file} successfully.") - except subprocess.CalledProcessError as e: - print(f"Error untarring {dest_file}: {e}") - - # Optionally remove the tar file after extraction - os.remove(dest_file) - else: - print(f"File {src_file} does not exist.") - def copy_merra2(self): if not self.config['input']['shared']['MERRA-2']: return @@ -289,3 +246,4 @@ def copy_merra2(self): if __name__ == '__main__' : ana = analysis(params_file='remap_params.yaml') ana.remap() + ana.remove_geosit() diff --git a/pre/remap_restart/remap_base.py b/pre/remap_restart/remap_base.py index 93e8466..7a3e41b 100755 --- a/pre/remap_restart/remap_base.py +++ b/pre/remap_restart/remap_base.py @@ -93,3 +93,46 @@ def copy_without_remap(self, restarts_in, compared_file_in, compared_file_out, s return True return False + + def copy_geosit(self): + if not self.config['input']['shared']['GEOS-IT']: + return + + expid = self.config['input']['shared']['expid'] + yyyymmddhh_ = str(self.config['input']['shared']['yyyymmddhh']) + yyyy_ = yyyymmddhh_[0:4] + mm_ = yyyymmddhh_[4:6] + day_ = yyyymmddhh_[6:8] # Extract the day from yyyymmddhh_ + + time_suffix = '_21z.tar' + + geos_it_rst_dir = '/discover/nobackup/projects/gmao/geos-it/dao_ops/archive/' + expid + '/rs/Y' + yyyy_ + '/M' + mm_ + '/' + rst_dir = self.config['input']['shared']['rst_dir'] + '/' + os.makedirs(rst_dir, exist_ok=True) + + print('Stage GEOS-IT restarts \n from \n ' + geos_it_rst_dir + '\n to\n ' + rst_dir + '\n') + + # Only use the specific day from yyyymmddhh_ + filename = f'{expid}.rst.{yyyy_}{mm_}{day_}{time_suffix}' + src_file = os.path.join(geos_it_rst_dir, filename) + dest_file = os.path.join(rst_dir, filename) + if os.path.exists(dest_file): + print('tar file is copied and untar, no need to copy') + return + if os.path.exists(src_file): + print(f"Copying file {src_file} to {dest_file}") + shutil.copy(src_file, dest_file) + + # Untar the .tar file using the tar command + if os.path.exists(dest_file): + print(f"Untarring {dest_file} to {rst_dir}") + try: + subprocess.run(['tar', '-xf', dest_file, '-C', rst_dir], check=True) + print(f"Untarred {dest_file} successfully.") + except subprocess.CalledProcessError as e: + print(f"Error untarring {dest_file}: {e}") + + # Optionally remove the tar file after extraction + #os.remove(dest_file) + else: + print(f"File {src_file} does not exist.") diff --git a/pre/remap_restart/remap_catchANDcn.py b/pre/remap_restart/remap_catchANDcn.py index 67d8e02..c5802e2 100755 --- a/pre/remap_restart/remap_catchANDcn.py +++ b/pre/remap_restart/remap_catchANDcn.py @@ -227,8 +227,6 @@ def remap(self): if self.config['input']['shared']['MERRA-2']: self.remove_merra2() - if self.config['input']['shared']['GEOS-IT']: - self.remove_geosit() def copy_merra2(self): if not self.config['input']['shared']['MERRA-2']: @@ -254,48 +252,6 @@ def copy_merra2(self): print("Copy file "+f +" to " + rst_dir) shutil.copy(f, dest) - def copy_geosit(self): - if not self.config['input']['shared']['GEOS-IT']: - return - - expid = self.config['input']['shared']['expid'] - yyyymmddhh_ = str(self.config['input']['shared']['yyyymmddhh']) - yyyy_ = yyyymmddhh_[0:4] - mm_ = yyyymmddhh_[4:6] - day_ = yyyymmddhh_[6:8] # Extract the day from yyyymmddhh_ - - time_suffix = '_21z.tar' - - geos_it_rst_dir = '/discover/nobackup/projects/gmao/geos-it/dao_ops/archive/' + expid + '/rs/Y' + yyyy_ + '/M' + mm_ + '/' - rst_dir = self.config['input']['shared']['rst_dir'] + '/' - os.makedirs(rst_dir, exist_ok=True) - - print('Stage GEOS-IT restarts \n from \n ' + geos_it_rst_dir + '\n to\n ' + rst_dir + '\n') - - # Only use the specific day from yyyymmddhh_ - filename = f'{expid}.rst.{yyyy_}{mm_}{day_}{time_suffix}' - src_file = os.path.join(geos_it_rst_dir, filename) - dest_file = os.path.join(rst_dir, filename) - - if os.path.exists(src_file): - print(f"Copying file {src_file} to {dest_file}") - shutil.copy(src_file, dest_file) - - # Untar the .tar file using the tar command - if os.path.exists(dest_file): - print(f"Untarring {dest_file} to {rst_dir}") - try: - subprocess.run(['tar', '-xf', dest_file, '-C', rst_dir], check=True) - print(f"Untarred {dest_file} successfully.") - except subprocess.CalledProcessError as e: - print(f"Error untarring {dest_file}: {e}") - - # Optionally remove the tar file after extraction - os.remove(dest_file) - else: - print(f"File {src_file} does not exist.") - - def ask_catch_questions(): catch_input_shared_rst_dir = '' def has_rs_rc_out(path): @@ -484,8 +440,7 @@ def remap_land_only(): catch = catchANDcn(params_file=config_yaml) catch.remap() - - + catch.remove_geosit() if __name__ == '__main__' : diff --git a/pre/remap_restart/remap_lake_landice_saltwater.py b/pre/remap_restart/remap_lake_landice_saltwater.py index 6691e04..253fc3a 100755 --- a/pre/remap_restart/remap_lake_landice_saltwater.py +++ b/pre/remap_restart/remap_lake_landice_saltwater.py @@ -176,8 +176,6 @@ def remap(self): if self.config['input']['shared']['MERRA-2']: self.remove_merra2() - if self.config['input']['shared']['GEOS-IT']: - self.remove_geosit() def run_and_log(self, cmd, log_name): print('\n'+cmd) @@ -251,48 +249,7 @@ def copy_merra2(self): bin2nc(dest, ncdest, yaml_file) os.remove(dest) - def copy_geosit(self): - if not self.config['input']['shared']['GEOS-IT']: - return - - expid = self.config['input']['shared']['expid'] - yyyymmddhh_ = str(self.config['input']['shared']['yyyymmddhh']) - yyyy_ = yyyymmddhh_[0:4] - mm_ = yyyymmddhh_[4:6] - day_ = yyyymmddhh_[6:8] # Extract the day from yyyymmddhh_ - - time_suffix = '_21z.tar' - - geos_it_rst_dir = '/discover/nobackup/projects/gmao/geos-it/dao_ops/archive/' + expid + '/rs/Y' + yyyy_ + '/M' + mm_ + '/' - rst_dir = self.config['input']['shared']['rst_dir'] + '/' - os.makedirs(rst_dir, exist_ok=True) - - print('Stage GEOS-IT restarts \n from \n ' + geos_it_rst_dir + '\n to\n ' + rst_dir + '\n') - - # Only use the specific day from yyyymmddhh_ - filename = f'{expid}.rst.{yyyy_}{mm_}{day_}{time_suffix}' - src_file = os.path.join(geos_it_rst_dir, filename) - dest_file = os.path.join(rst_dir, filename) - - if os.path.exists(src_file): - print(f"Copying file {src_file} to {dest_file}") - shutil.copy(src_file, dest_file) - - # Untar the .tar file using the tar command - if os.path.exists(dest_file): - print(f"Untarring {dest_file} to {rst_dir}") - try: - subprocess.run(['tar', '-xf', dest_file, '-C', rst_dir], check=True) - print(f"Untarred {dest_file} successfully.") - except subprocess.CalledProcessError as e: - print(f"Error untarring {dest_file}: {e}") - - # Optionally remove the tar file after extraction - os.remove(dest_file) - else: - print(f"File {src_file} does not exist.") - -# if __name__ == '__main__' : lls = lake_landice_saltwater(params_file='remap_params.yaml') lls.remap() + lls.remove_geosit() diff --git a/pre/remap_restart/remap_restarts.py b/pre/remap_restart/remap_restarts.py index f2a380f..a5ade81 100755 --- a/pre/remap_restart/remap_restarts.py +++ b/pre/remap_restart/remap_restarts.py @@ -133,6 +133,8 @@ def main(): ana = analysis(params_file=config_yaml) ana.remap() + ana.remove_geosit() + if __name__ == '__main__' : main() diff --git a/pre/remap_restart/remap_upper.py b/pre/remap_restart/remap_upper.py index 899d32f..228c0ea 100755 --- a/pre/remap_restart/remap_upper.py +++ b/pre/remap_restart/remap_upper.py @@ -337,8 +337,6 @@ def remap(self): if self.config['input']['shared']['MERRA-2']: self.remove_merra2() - if self.config['input']['shared']['GEOS-IT']: - self.remove_geosit() def find_rst(self): rst_dir = self.config['input']['shared']['rst_dir'] @@ -397,48 +395,7 @@ def copy_merra2(self): bin2nc(dest, ncdest, yaml_file) os.remove(dest) - def copy_geosit(self): - if not self.config['input']['shared']['GEOS-IT']: - return - - expid = self.config['input']['shared']['expid'] - yyyymmddhh_ = str(self.config['input']['shared']['yyyymmddhh']) - yyyy_ = yyyymmddhh_[0:4] - mm_ = yyyymmddhh_[4:6] - day_ = yyyymmddhh_[6:8] # Extract the day from yyyymmddhh_ - - time_suffix = '_21z.tar' - - geos_it_rst_dir = '/discover/nobackup/projects/gmao/geos-it/dao_ops/archive/' + expid + '/rs/Y' + yyyy_ + '/M' + mm_ + '/' - rst_dir = self.config['input']['shared']['rst_dir'] + '/' - os.makedirs(rst_dir, exist_ok=True) - - print('Stage GEOS-IT restarts \n from \n ' + geos_it_rst_dir + '\n to\n ' + rst_dir + '\n') - - # Only use the specific day from yyyymmddhh_ - filename = f'{expid}.rst.{yyyy_}{mm_}{day_}{time_suffix}' - src_file = os.path.join(geos_it_rst_dir, filename) - dest_file = os.path.join(rst_dir, filename) - - if os.path.exists(src_file): - print(f"Copying file {src_file} to {dest_file}") - shutil.copy(src_file, dest_file) - - # Untar the .tar file using the tar command - if os.path.exists(dest_file): - print(f"Untarring {dest_file} to {rst_dir}") - try: - subprocess.run(['tar', '-xf', dest_file, '-C', rst_dir], check=True) - print(f"Untarred {dest_file} successfully.") - except subprocess.CalledProcessError as e: - print(f"Error untarring {dest_file}: {e}") - - # Optionally remove the tar file after extraction - os.remove(dest_file) - else: - print(f"File {src_file} does not exist.") - - if __name__ == '__main__' : air = upperair(params_file='remap_params.yaml') air.remap() + air.remove_geosit() From 786d100c9bc22f5546a3b5ffad0e980e416b948c Mon Sep 17 00:00:00 2001 From: Biljana Orescanin <68251545+biljanaorescanin@users.noreply.github.com> Date: Tue, 10 Sep 2024 15:42:35 -0400 Subject: [PATCH 14/24] this was oopsie --- pre/remap_restart/remap_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pre/remap_restart/remap_utils.py b/pre/remap_restart/remap_utils.py index e343165..63b0b0a 100755 --- a/pre/remap_restart/remap_utils.py +++ b/pre/remap_restart/remap_utils.py @@ -17,8 +17,8 @@ #During cmake step, the string will be changed according to the system -BUILT_ON_SLES15 = "TRUE" -GEOS_SITE = "NCCS" +BUILT_ON_SLES15 = "@BUILT_ON_SLES15@" +GEOS_SITE = "@GEOS_SITE@" if BUILT_ON_SLES15 == "TRUE": BUILT_ON_SLES15 = True From 4d01d6d4296cb05873851e8e21fe3aed2275a249 Mon Sep 17 00:00:00 2001 From: Matt Thompson Date: Fri, 13 Sep 2024 12:32:13 -0400 Subject: [PATCH 15/24] Revert "remap_restarts uses SLURM for lake/landice/saltwater (Resolution for issue #85)" --- .../remap_lake_landice_saltwater.py | 261 +++--------------- 1 file changed, 45 insertions(+), 216 deletions(-) diff --git a/pre/remap_restart/remap_lake_landice_saltwater.py b/pre/remap_restart/remap_lake_landice_saltwater.py index da72ea9..ca2f9cd 100755 --- a/pre/remap_restart/remap_lake_landice_saltwater.py +++ b/pre/remap_restart/remap_lake_landice_saltwater.py @@ -16,7 +16,7 @@ import ruamel.yaml import shlex from remap_base import remap_base -from remap_utils import * +from remap_utils import get_label from remap_utils import get_geomdir from remap_bin2nc import bin2nc @@ -47,9 +47,13 @@ def remap(self): ogrid = config['input']['shared']['ogrid'] omodel = config['input']['shared']['omodel'] stretch = config['input']['shared']['stretch'] - in_geomdir = get_geomdir(in_bc_base, in_bc_version, agrid=agrid, ogrid=ogrid, omodel=omodel, stretch=stretch) in_tile_file = glob.glob(in_geomdir+ '/*-Pfafstetter.til')[0] + + agrid = config['output']['shared']['agrid'] + ogrid = config['output']['shared']['ogrid'] + omodel = config['output']['shared']['omodel'] + stretch = config['output']['shared']['stretch'] out_geomdir = get_geomdir(out_bc_base, out_bc_version, agrid=agrid, ogrid=ogrid, omodel=omodel, stretch=stretch) out_tile_file = glob.glob(out_geomdir+ '/*-Pfafstetter.til')[0] @@ -166,180 +170,6 @@ def remap(self): print('cd ' + cwdir) os.chdir(cwdir) - - agrid = config['output']['shared']['agrid'] - if agrid[0].upper() == 'C': - imout = int(agrid[1:]) - else: - exit("Only support cs grid so far") - - if (imout <90): - NPE = 12; nwrit = 1 - elif (imout<=180): - NPE = 24; nwrit = 1 - elif (imout<=540): - NPE = 96; nwrit = 1 - elif (imout<=720): - NPE = 192; nwrit = 2 - elif (imout<=1080): - NPE = 384; nwrit = 2 - elif (imout<=1440): - NPE = 576; nwrit = 2 - elif (imout< 2880): - NPE = 768; nwrit = 2 - elif (imout>=2880): - NPE = 5400; nwrit = 6 - - PARTITION ='' - QOS = config['slurm_pbs']['qos'] - TIME = "1:00:00" - if NPE > 532: - assert config['slurm_pbs']['qos'] != 'debug', "qos should be 'allnccs' for NCCS or 'normal' for NAS" - TIME = "12:00:00" - NNODE = '' - job='' - if GEOS_SITE == "NAS": - CONSTRAINT = 'cas_ait' - NNODE = (NPE-1)//40 + 1 - job='PBS' - else: - job='SLURM' - partition = config['slurm_pbs']['partition'] - if (partition != ''): - PARTITION = "#SBATCH --partition=" + partition - - CONSTRAINT = '"[cas|sky]"' - if BUILT_ON_SLES15: - CONSTRAINT = 'mil' - - - remap_template = job_directive[job] + \ -""" -source {Bin}/g5_modules -limit stacksize unlimited - -cd {out_dir}/upper_data -/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_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:" -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 -Lb --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} {stretch_str} - -""" - account = config['slurm_pbs']['account'] - drymassFLG = config['input']['air']['drymass'] - hydrostatic = config['input']['air']['hydrostatic'] - nlevel = config['output']['air']['nlevel'] - log_name = out_dir+'/remap_lake_landice_saltwater_log' - job_name = 'remap_lake_landice_saltwater' - stretch_str = '' - remap_script = remap_template.format(Bin=bindir, account = account, \ - out_dir = out_dir, log_name = log_name, job_name= job_name, drymassFLG = drymassFLG, \ - imout = imout, nwrit = nwrit, NPE = NPE, NNODE = NNODE, \ - QOS = QOS, TIME = TIME, CONSTRAINT = CONSTRAINT, PARTITION = PARTITION, nlevel = nlevel, hydrostatic = hydrostatic, - stretch_str = stretch_str) - - script_name = './remap_lake_landice_saltwater.j' - - lake_landice_saltwater = open(script_name, 'wt') - lake_landice_saltwater.write(remap_script) - lake_landice_saltwater.close() - - in_bc_base = config['input']['shared']['bc_base'] - if "gmao_SIteam/ModelData" in in_bc_base: - assert GEOS_SITE == "NAS", "wrong site to run the package" - - interactive = None - if GEOS_SITE == 'NAS': - interactive = os.getenv('PBS_JOBID', default = None) - else: - interactive = os.getenv('SLURM_JOB_ID', default = None) - - if (interactive) : - print('interactive mode\n') - if GEOS_SITE != 'NAS': - ntasks = os.getenv('SLURM_NTASKS', default = None) - if ( not ntasks): - nnodes = int(os.getenv('SLURM_NNODES', default = '1')) - ncpus = int(os.getenv('SLURM_CPUS_ON_NODE', default = '28')) - ntasks = nnodes * ncpus - ntasks = int(ntasks) - if (ntasks < NPE ): - print("\nYou should have at least {NPE} cores. Now you only have {ntasks} cores ".format(NPE=NPE, ntasks=ntasks)) - - subprocess.call(['chmod', '755', script_name]) - print(script_name+ ' 1>' + log_name + ' 2>&1') - os.system(script_name + ' 1>' + log_name+ ' 2>&1') - elif GEOS_SITE == "NAS" : - print('qsub -W block=true '+ script_name +'\n') - subprocess.call(['qsub', '-W','block=true', script_name]) - else: - print('sbatch -W '+ script_name +'\n') - subprocess.call(['sbatch', '-W', script_name]) - -# -# post process -# - 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) - - print('\n Move remap_lake_landice_saltwater.j to ' + out_dir) - shutil.move('remap_lake_landice_saltwater.j', out_dir+"/remap_lake_landice_saltwater.j") - with open(out_dir+'/cap_restart', 'w') as f: - yyyymmddhh_ = str(config['input']['shared']['yyyymmddhh']) - time = yyyymmddhh_[0:8]+' '+yyyymmddhh_[8:10]+'0000' - print('Create cap_restart') - f.write(time) - print('cd ' + cwdir) - os.chdir(cwdir) - self.remove_merra2() def run_and_log(self, cmd, log_name): @@ -355,15 +185,14 @@ def run_and_log(self, cmd, log_name): log_.write(stdout) log_.write(stderr) - def find_rst(self): surf_restarts =[ - "route_internal_rst" , - "lake_internal_rst" , - "landice_internal_rst" , - "openwater_internal_rst" , - "saltwater_internal_rst" , - "seaicethermo_internal_rst"] + "route_internal_rst" , + "lake_internal_rst" , + "landice_internal_rst" , + "openwater_internal_rst" , + "saltwater_internal_rst" , + "seaicethermo_internal_rst"] rst_dir = self.config['input']['shared']['rst_dir'] yyyymmddhh_ = str(self.config['input']['shared']['yyyymmddhh']) @@ -372,48 +201,48 @@ def find_rst(self): for f in surf_restarts : files = glob.glob(rst_dir+ '/*'+f+'*'+time+'*') if len(files) >0: - restarts_in.append(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) + restarts_in.append(fname) return restarts_in def copy_merra2(self): - if not self.config['input']['shared']['MERRA-2']: - return - - expid = self.config['input']['shared']['expid'] - yyyymmddhh_ = str(self.config['input']['shared']['yyyymmddhh']) - yyyy_ = yyyymmddhh_[0:4] - mm_ = yyyymmddhh_[4:6] - dd_ = yyyymmddhh_[6:8] - hh_ = yyyymmddhh_[8:10] - - suffix = yyyymmddhh_[0:8]+'_'+ hh_ + 'z.bin' - merra_2_rst_dir = '/archive/users/gmao_ops/MERRA2/gmao_ops/GEOSadas-5_12_4/'+expid +'/rs/Y'+yyyy_ +'/M'+mm_+'/' - rst_dir = self.config['input']['shared']['rst_dir'] + '/' - os.makedirs(rst_dir, exist_ok = True) - print(' Copy MERRA-2 surface restarts \n from \n ' + merra_2_rst_dir + '\n to\n '+ rst_dir +'\n') - - surfin = [ merra_2_rst_dir + expid+'.lake_internal_rst.' + suffix, - merra_2_rst_dir + expid+'.landice_internal_rst.' + suffix, - merra_2_rst_dir + expid+'.saltwater_internal_rst.'+ suffix] - bin2nc_yaml = ['bin2nc_merra2_lake.yaml', 'bin2nc_merra2_landice.yaml','bin2nc_merra2_salt.yaml'] - bin_path = os.path.dirname(os.path.realpath(__file__)) - for (f,yf) in zip(surfin, bin2nc_yaml): - fname = os.path.basename(f) - dest = rst_dir + '/'+fname - print("Copy file "+f +" to " + rst_dir) - shutil.copy(f, dest) - ncdest = dest.replace('z.bin', 'z.nc4') - yaml_file = bin_path + '/'+yf - print('Convert bin to nc4:' + dest + ' to \n' + ncdest + '\n') - bin2nc(dest, ncdest, yaml_file) - os.remove(dest) + if not self.config['input']['shared']['MERRA-2']: + return + + expid = self.config['input']['shared']['expid'] + yyyymmddhh_ = str(self.config['input']['shared']['yyyymmddhh']) + yyyy_ = yyyymmddhh_[0:4] + mm_ = yyyymmddhh_[4:6] + dd_ = yyyymmddhh_[6:8] + hh_ = yyyymmddhh_[8:10] + + suffix = yyyymmddhh_[0:8]+'_'+ hh_ + 'z.bin' + merra_2_rst_dir = '/archive/users/gmao_ops/MERRA2/gmao_ops/GEOSadas-5_12_4/'+expid +'/rs/Y'+yyyy_ +'/M'+mm_+'/' + rst_dir = self.config['input']['shared']['rst_dir'] + '/' + os.makedirs(rst_dir, exist_ok = True) + print(' Copy MERRA-2 surface restarts \n from \n ' + merra_2_rst_dir + '\n to\n '+ rst_dir +'\n') + + surfin = [ merra_2_rst_dir + expid+'.lake_internal_rst.' + suffix, + merra_2_rst_dir + expid+'.landice_internal_rst.' + suffix, + merra_2_rst_dir + expid+'.saltwater_internal_rst.'+ suffix] + bin2nc_yaml = ['bin2nc_merra2_lake.yaml', 'bin2nc_merra2_landice.yaml','bin2nc_merra2_salt.yaml'] + bin_path = os.path.dirname(os.path.realpath(__file__)) + for (f,yf) in zip(surfin, bin2nc_yaml): + fname = os.path.basename(f) + dest = rst_dir + '/'+fname + print("Copy file "+f +" to " + rst_dir) + shutil.copy(f, dest) + ncdest = dest.replace('z.bin', 'z.nc4') + yaml_file = bin_path + '/'+yf + print('Convert bin to nc4:' + dest + ' to \n' + ncdest + '\n') + bin2nc(dest, ncdest, yaml_file) + os.remove(dest) if __name__ == '__main__' : lls = lake_landice_saltwater(params_file='remap_params.yaml') From 4859f4fe740da96bfba9d71b2d17d1053c8e5034 Mon Sep 17 00:00:00 2001 From: biljanaorescanin Date: Tue, 17 Sep 2024 09:36:54 -0400 Subject: [PATCH 16/24] add agcm import rst copy --- pre/remap_restart/remap_base.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/pre/remap_restart/remap_base.py b/pre/remap_restart/remap_base.py index 7a3e41b..f9e91b6 100755 --- a/pre/remap_restart/remap_base.py +++ b/pre/remap_restart/remap_base.py @@ -104,7 +104,8 @@ def copy_geosit(self): mm_ = yyyymmddhh_[4:6] day_ = yyyymmddhh_[6:8] # Extract the day from yyyymmddhh_ - time_suffix = '_21z.tar' + time_suffix = '_21z' + time_suffix_nc4 = '_2100z' geos_it_rst_dir = '/discover/nobackup/projects/gmao/geos-it/dao_ops/archive/' + expid + '/rs/Y' + yyyy_ + '/M' + mm_ + '/' rst_dir = self.config['input']['shared']['rst_dir'] + '/' @@ -113,7 +114,7 @@ def copy_geosit(self): print('Stage GEOS-IT restarts \n from \n ' + geos_it_rst_dir + '\n to\n ' + rst_dir + '\n') # Only use the specific day from yyyymmddhh_ - filename = f'{expid}.rst.{yyyy_}{mm_}{day_}{time_suffix}' + filename = f'{expid}.rst.{yyyy_}{mm_}{day_}{time_suffix}.tar' src_file = os.path.join(geos_it_rst_dir, filename) dest_file = os.path.join(rst_dir, filename) if os.path.exists(dest_file): @@ -135,4 +136,16 @@ def copy_geosit(self): # Optionally remove the tar file after extraction #os.remove(dest_file) else: - print(f"File {src_file} does not exist.") + print(f"Tar file {src_file} does not exist.") + + # Now handle the additional .nc4 file + nc4_filename = f'{expid}.agcm_import_rst.{yyyy_}{mm_}{day_}{time_suffix_nc4}.nc4' + src_nc4_file = os.path.join(geos_it_rst_dir, nc4_filename) + dest_nc4_file = os.path.join(rst_dir, nc4_filename) + + # Copy the .nc4 file if it exists + if os.path.exists(src_nc4_file): + print(f"Copying .nc4 file {src_nc4_file} to {dest_nc4_file}") + shutil.copy(src_nc4_file, dest_nc4_file) + else: + print(f" agcm_import_rst file {src_nc4_file} does not exist.") From 35006bb22b576172fe36a924a861fd003b065172 Mon Sep 17 00:00:00 2001 From: biljanaorescanin Date: Tue, 17 Sep 2024 09:54:19 -0400 Subject: [PATCH 17/24] add GEOS-IT flag to test yaml --- pre/remap_restart/tests/amip_c180Toc90.yaml | 1 + pre/remap_restart/tests/c180Toc360.yaml | 1 + pre/remap_restart/tests/c24Toc12.yaml | 1 + pre/remap_restart/tests/c360Toc24.yaml | 1 + pre/remap_restart/tests/f522Toc360.yaml | 1 + 5 files changed, 5 insertions(+) diff --git a/pre/remap_restart/tests/amip_c180Toc90.yaml b/pre/remap_restart/tests/amip_c180Toc90.yaml index fbd5564..872a59a 100644 --- a/pre/remap_restart/tests/amip_c180Toc90.yaml +++ b/pre/remap_restart/tests/amip_c180Toc90.yaml @@ -9,6 +9,7 @@ input: hydrostatic: 0 shared: MERRA-2: false + GEOS-IT: false stretch: false agrid: C180 # (coupled) ocean model: data, MOM5, MOM6 diff --git a/pre/remap_restart/tests/c180Toc360.yaml b/pre/remap_restart/tests/c180Toc360.yaml index e9e1c09..ad09b37 100644 --- a/pre/remap_restart/tests/c180Toc360.yaml +++ b/pre/remap_restart/tests/c180Toc360.yaml @@ -9,6 +9,7 @@ input: hydrostatic: 0 shared: MERRA-2: false + GEOS-IT: false stretch: false # (coupled) ocean model: data, MOM5, MOM6 omodel: data diff --git a/pre/remap_restart/tests/c24Toc12.yaml b/pre/remap_restart/tests/c24Toc12.yaml index fb7d67d..a8f7d9d 100644 --- a/pre/remap_restart/tests/c24Toc12.yaml +++ b/pre/remap_restart/tests/c24Toc12.yaml @@ -9,6 +9,7 @@ input: hydrostatic: 0 shared: MERRA-2: false + GEOS-IT: false stretch: false # (coupled) ocean model: data, MOM5, MOM6 omodel: data diff --git a/pre/remap_restart/tests/c360Toc24.yaml b/pre/remap_restart/tests/c360Toc24.yaml index de7a55a..eb78f5f 100644 --- a/pre/remap_restart/tests/c360Toc24.yaml +++ b/pre/remap_restart/tests/c360Toc24.yaml @@ -9,6 +9,7 @@ input: hydrostatic: 0 shared: MERRA-2: false + GEOS-IT: false agrid: C360 stretch: false # (coupled) ocean model: data, MOM5, MOM6 diff --git a/pre/remap_restart/tests/f522Toc360.yaml b/pre/remap_restart/tests/f522Toc360.yaml index 2d2975f..456d47b 100644 --- a/pre/remap_restart/tests/f522Toc360.yaml +++ b/pre/remap_restart/tests/f522Toc360.yaml @@ -9,6 +9,7 @@ input: hydrostatic: 0 shared: MERRA-2: false + GEOS-IT: false stretch: false # (coupled) ocean model: data, MOM5, MOM6 omodel: data From 060ef18d583e078fb702937a30d44942241520e1 Mon Sep 17 00:00:00 2001 From: biljanaorescanin Date: Tue, 17 Sep 2024 11:13:38 -0400 Subject: [PATCH 18/24] only copy if user said yes --- pre/remap_restart/remap_base.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/pre/remap_restart/remap_base.py b/pre/remap_restart/remap_base.py index f9e91b6..b7b52f8 100755 --- a/pre/remap_restart/remap_base.py +++ b/pre/remap_restart/remap_base.py @@ -137,15 +137,17 @@ def copy_geosit(self): #os.remove(dest_file) else: print(f"Tar file {src_file} does not exist.") - - # Now handle the additional .nc4 file - nc4_filename = f'{expid}.agcm_import_rst.{yyyy_}{mm_}{day_}{time_suffix_nc4}.nc4' - src_nc4_file = os.path.join(geos_it_rst_dir, nc4_filename) - dest_nc4_file = os.path.join(rst_dir, nc4_filename) - - # Copy the .nc4 file if it exists - if os.path.exists(src_nc4_file): - print(f"Copying .nc4 file {src_nc4_file} to {dest_nc4_file}") - shutil.copy(src_nc4_file, dest_nc4_file) + # Now handle the additional .nc4 file, only if the user has confirmed to remap agcm_import_rst + if self.config['output']['air'].get('agcm_import_rst', False): + nc4_filename = f'{expid}.agcm_import_rst.{yyyy_}{mm_}{day_}{time_suffix_nc4}.nc4' + src_nc4_file = os.path.join(geos_it_rst_dir, nc4_filename) + dest_nc4_file = os.path.join(rst_dir, nc4_filename) + + # Copy the .nc4 file if it exists + if os.path.exists(src_nc4_file): + print(f"Copying .nc4 file {src_nc4_file} to {dest_nc4_file}") + shutil.copy(src_nc4_file, dest_nc4_file) + else: + print(f" agcm_import_rst file {src_nc4_file} does not exist.") else: - print(f" agcm_import_rst file {src_nc4_file} does not exist.") + print("Skipping agcm_import_rst file copy as the user did not confirm.") From 6cc74db9e0cc0bd744909c27a10119b63e3d9fd4 Mon Sep 17 00:00:00 2001 From: biljanaorescanin Date: Tue, 17 Sep 2024 11:52:18 -0400 Subject: [PATCH 19/24] fix date options --- pre/remap_restart/remap_utils.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/pre/remap_restart/remap_utils.py b/pre/remap_restart/remap_utils.py index 53dcd07..5c6ec9d 100755 --- a/pre/remap_restart/remap_utils.py +++ b/pre/remap_restart/remap_utils.py @@ -17,8 +17,8 @@ #During cmake step, the string will be changed according to the system -BUILT_ON_SLES15 = "@BUILT_ON_SLES15@" -GEOS_SITE = "@GEOS_SITE@" +BUILT_ON_SLES15 = "TRUE" +GEOS_SITE = "NCCS" if BUILT_ON_SLES15 == "TRUE": BUILT_ON_SLES15 = True @@ -187,16 +187,18 @@ def init_geosit(x): if not x.get('input:shared:GEOS-IT') : return False yyyymm = int(x.get('input:shared:yyyymmddhh')[0:6]) - if yyyymm < 199701 : - exit("Error. GEOS-IT data < 1997 not available\n") - elif (yyyymm < 199701): - expid = "d5294_geosit_jan98" - elif (yyyymm < 200701): - expid = "d5294_geosit_jan08" - elif (yyyymm < 201701): - expid = "d5294_geosit_jan18" + + if yyyymm < 199701: + exit("Error. GEOS-IT data < 1997 not available\n") + elif 199612 <= yyyymm <= 200712: + expid = "d5294_geosit_jan98" + elif 200801 <= yyyymm < 201801: + expid = "d5294_geosit_jan08" + elif yyyymm >= 201801: + expid = "d5294_geosit_jan18" # For any date starting from 201801 and beyond else: - expid = "d5294_geosit_jan18" + exit("Error. GEOS-IT data not available for this date\n") + x['input:shared:expid'] = expid x['input:shared:omodel'] = 'data' x['input:shared:agrid'] = 'C180' From 0fca7d6f2414e71e3a1e14c36c756bda4ba2bb20 Mon Sep 17 00:00:00 2001 From: biljanaorescanin Date: Tue, 17 Sep 2024 11:55:05 -0400 Subject: [PATCH 20/24] typo --- pre/remap_restart/remap_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pre/remap_restart/remap_utils.py b/pre/remap_restart/remap_utils.py index 5c6ec9d..a881c11 100755 --- a/pre/remap_restart/remap_utils.py +++ b/pre/remap_restart/remap_utils.py @@ -17,8 +17,8 @@ #During cmake step, the string will be changed according to the system -BUILT_ON_SLES15 = "TRUE" -GEOS_SITE = "NCCS" +BUILT_ON_SLES15 = "@BUILT_ON_SLES15@" +GEOS_SITE = "@GEOS_SITE@" if BUILT_ON_SLES15 == "TRUE": BUILT_ON_SLES15 = True From 7669eff0f6bab4faac4b692178d13bea62308c3e Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Tue, 17 Sep 2024 16:20:22 -0400 Subject: [PATCH 21/24] no agcm_import_rst is remppaed if answering no --- pre/remap_restart/remap_base.py | 45 +++++++++++++++--------------- pre/remap_restart/remap_params.tpl | 1 + pre/remap_restart/remap_upper.py | 4 +++ pre/remap_restart/remap_utils.py | 4 +-- 4 files changed, 30 insertions(+), 24 deletions(-) diff --git a/pre/remap_restart/remap_base.py b/pre/remap_restart/remap_base.py index f9e91b6..70de50e 100755 --- a/pre/remap_restart/remap_base.py +++ b/pre/remap_restart/remap_base.py @@ -121,31 +121,32 @@ def copy_geosit(self): print('tar file is copied and untar, no need to copy') return if os.path.exists(src_file): - print(f"Copying file {src_file} to {dest_file}") - shutil.copy(src_file, dest_file) - - # Untar the .tar file using the tar command - if os.path.exists(dest_file): - print(f"Untarring {dest_file} to {rst_dir}") - try: - subprocess.run(['tar', '-xf', dest_file, '-C', rst_dir], check=True) - print(f"Untarred {dest_file} successfully.") - except subprocess.CalledProcessError as e: - print(f"Error untarring {dest_file}: {e}") + print(f"Copying file {src_file} to {dest_file}") + shutil.copy(src_file, dest_file) + + # Untar the .tar file using the tar command + if os.path.exists(dest_file): + print(f"Untarring {dest_file} to {rst_dir}") + try: + subprocess.run(['tar', '-xf', dest_file, '-C', rst_dir], check=True) + print(f"Untarred {dest_file} successfully.") + except subprocess.CalledProcessError as e: + print(f"Error untarring {dest_file}: {e}") # Optionally remove the tar file after extraction #os.remove(dest_file) else: - print(f"Tar file {src_file} does not exist.") + print(f"Tar file {src_file} does not exist.") # Now handle the additional .nc4 file - nc4_filename = f'{expid}.agcm_import_rst.{yyyy_}{mm_}{day_}{time_suffix_nc4}.nc4' - src_nc4_file = os.path.join(geos_it_rst_dir, nc4_filename) - dest_nc4_file = os.path.join(rst_dir, nc4_filename) - - # Copy the .nc4 file if it exists - if os.path.exists(src_nc4_file): - print(f"Copying .nc4 file {src_nc4_file} to {dest_nc4_file}") - shutil.copy(src_nc4_file, dest_nc4_file) - else: - print(f" agcm_import_rst file {src_nc4_file} does not exist.") + cp_agcm_import_rst = self.config['output']['air']['agcm_import_rst'] + if (cp_agcm_import_rst) : + nc4_filename = f'{expid}.agcm_import_rst.{yyyy_}{mm_}{day_}{time_suffix_nc4}.nc4' + src_nc4_file = os.path.join(geos_it_rst_dir, nc4_filename) + dest_nc4_file = os.path.join(rst_dir, nc4_filename) + # Copy the .nc4 file if it exists + if os.path.exists(src_nc4_file): + print(f"Copying .nc4 file {src_nc4_file} to {dest_nc4_file}") + shutil.copy(src_nc4_file, dest_nc4_file) + else: + print(f" agcm_import_rst file {src_nc4_file} does not exist.") diff --git a/pre/remap_restart/remap_params.tpl b/pre/remap_restart/remap_params.tpl index a68c1a1..7ac89ee 100644 --- a/pre/remap_restart/remap_params.tpl +++ b/pre/remap_restart/remap_params.tpl @@ -45,6 +45,7 @@ output: # remap upper air or not remap: true nlevel: + agcm_import_rst: false surface: split_saltwater: false surflay: 50. diff --git a/pre/remap_restart/remap_upper.py b/pre/remap_restart/remap_upper.py index 228c0ea..b3efe0d 100755 --- a/pre/remap_restart/remap_upper.py +++ b/pre/remap_restart/remap_upper.py @@ -52,6 +52,10 @@ def remap(self): "ni_internal_rst" , "su_internal_rst" , "tr_internal_rst"] + + cp_agcm_import_rst = self.config['output']['air']['agcm_import_rst'] + if ( not cp_agcm_import_rst) : + self.air_restarts.remove("agcm_import_rst") restarts_in = self.find_rst() if len(restarts_in) == 0: return diff --git a/pre/remap_restart/remap_utils.py b/pre/remap_restart/remap_utils.py index 53dcd07..5026f26 100755 --- a/pre/remap_restart/remap_utils.py +++ b/pre/remap_restart/remap_utils.py @@ -411,8 +411,8 @@ def print_config( config, indent = 0 ): def get_command_line_from_answers(answers): - merra2 = " -merra2 " if "input:shared:MERRA-2" in answers else "" - geosit = " -geosit " if "input:shared:GEOS-IT" in answers else "" + merra2 = " -merra2 " if answers.get("input:shared:MERRA-2", False) else "" + geosit = " -geosit " if answers.get("input:shared:GEOS-IT", False) else "" ymdh = " -ymdh " + answers["input:shared:yyyymmddhh"] rst_dir = " -rst_dir " + answers["input:shared:rst_dir"] From 9be3b1b831b0a1246b6a556ea79e196a23e7232c Mon Sep 17 00:00:00 2001 From: Biljana Orescanin <68251545+biljanaorescanin@users.noreply.github.com> Date: Tue, 17 Sep 2024 19:38:50 -0400 Subject: [PATCH 22/24] fix bug from last commit --- pre/remap_restart/remap_upper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pre/remap_restart/remap_upper.py b/pre/remap_restart/remap_upper.py index b3efe0d..4155dc3 100755 --- a/pre/remap_restart/remap_upper.py +++ b/pre/remap_restart/remap_upper.py @@ -53,7 +53,7 @@ def remap(self): "su_internal_rst" , "tr_internal_rst"] - cp_agcm_import_rst = self.config['output']['air']['agcm_import_rst'] + cp_agcm_import_rst = self.config['output']['air'].get('agcm_import_rst', False) if ( not cp_agcm_import_rst) : self.air_restarts.remove("agcm_import_rst") restarts_in = self.find_rst() From f5af5ec25519103885419e2f8e561d0a2b332cf6 Mon Sep 17 00:00:00 2001 From: biljanaorescanin Date: Wed, 18 Sep 2024 11:12:08 -0400 Subject: [PATCH 23/24] add flag to yaml tests --- pre/remap_restart/tests/amip_c180Toc90.yaml | 1 + pre/remap_restart/tests/c180Toc360.yaml | 1 + pre/remap_restart/tests/c24Toc12.yaml | 1 + pre/remap_restart/tests/c360Toc24.yaml | 1 + pre/remap_restart/tests/f522Toc360.yaml | 1 + 5 files changed, 5 insertions(+) diff --git a/pre/remap_restart/tests/amip_c180Toc90.yaml b/pre/remap_restart/tests/amip_c180Toc90.yaml index 872a59a..36278f3 100644 --- a/pre/remap_restart/tests/amip_c180Toc90.yaml +++ b/pre/remap_restart/tests/amip_c180Toc90.yaml @@ -42,6 +42,7 @@ output: # remap upper air or not remap: true nlevel: '72' + agcm_import_rst: false surface: split_saltwater: true surflay: 50.0 diff --git a/pre/remap_restart/tests/c180Toc360.yaml b/pre/remap_restart/tests/c180Toc360.yaml index ad09b37..7c3ee8b 100644 --- a/pre/remap_restart/tests/c180Toc360.yaml +++ b/pre/remap_restart/tests/c180Toc360.yaml @@ -42,6 +42,7 @@ output: # remap upper air or not remap: true nlevel: '91' + agcm_import_rst: false surface: split_saltwater: true surflay: 50.0 diff --git a/pre/remap_restart/tests/c24Toc12.yaml b/pre/remap_restart/tests/c24Toc12.yaml index a8f7d9d..6ce7a3e 100644 --- a/pre/remap_restart/tests/c24Toc12.yaml +++ b/pre/remap_restart/tests/c24Toc12.yaml @@ -42,6 +42,7 @@ output: # remap upper air or not remap: true nlevel: '72' + agcm_import_rst: true surface: split_saltwater: true surflay: 50.0 diff --git a/pre/remap_restart/tests/c360Toc24.yaml b/pre/remap_restart/tests/c360Toc24.yaml index eb78f5f..7e6eee2 100644 --- a/pre/remap_restart/tests/c360Toc24.yaml +++ b/pre/remap_restart/tests/c360Toc24.yaml @@ -42,6 +42,7 @@ output: # remap upper air or not remap: true nlevel: '181' + agcm_import_rst: false surface: split_saltwater: true surflay: 50.0 diff --git a/pre/remap_restart/tests/f522Toc360.yaml b/pre/remap_restart/tests/f522Toc360.yaml index 456d47b..6f13320 100644 --- a/pre/remap_restart/tests/f522Toc360.yaml +++ b/pre/remap_restart/tests/f522Toc360.yaml @@ -39,6 +39,7 @@ output: label: False air: nlevel: '72' + agcm_import_rst: false remap: true surface: split_saltwater: true From e608f94facc246ecb72e669a515cf145b451a6a2 Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Thu, 19 Sep 2024 15:27:20 -0400 Subject: [PATCH 24/24] bypass merra2 --- pre/remap_restart/remap_command_line.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/pre/remap_restart/remap_command_line.py b/pre/remap_restart/remap_command_line.py index 0d1435c..8a8ea85 100755 --- a/pre/remap_restart/remap_command_line.py +++ b/pre/remap_restart/remap_command_line.py @@ -94,21 +94,23 @@ def get_answers_from_command_line(cml): answers["input:shared:MERRA-2"] = cml.merra2 answers["input:shared:GEOS-IT"] = cml.geosit answers["input:shared:yyyymmddhh"] = cml.ymdh - answers["input:shared:omodel"] = cml.ocnmdlin answers["output:shared:out_dir"] = os.path.abspath(cml.out_dir + '/') if cml.merra2: init_merra2(answers) - if cml.geosit: + elif cml.geosit: init_geosit(answers) else: - answers["input:shared:bc_version"] = cml.bcvin - answers["input:surface:catch_model"] = cml.catch_model - answers["input:shared:rst_dir"] = os.path.abspath(cml.rst_dir + '/') + answers["input:shared:bc_base"] = cml.in_bc_base + answers["input:shared:omodel"] = cml.ocnmdlin + answers["input:shared:bc_version"] = cml.bcvin + answers["input:surface:catch_model"]= cml.catch_model + answers["input:shared:stretch"] = cml.in_stretch + answers["input:shared:rst_dir"] = os.path.abspath(cml.rst_dir + '/') fvcore_info(answers) - ogrid = cml.oceanin + ogrid = cml.oceanin if ogrid == "CS": ogrid = answers["input:shared:agrid"] - answers["input:shared:ogrid"] = ogrid + answers["input:shared:ogrid"] = ogrid answers["output:shared:agrid"] = cml.grout answers["output:air:nlevel"] = cml.levsout @@ -121,11 +123,9 @@ def get_answers_from_command_line(cml): ogrid = answers["output:shared:agrid"] answers["output:shared:ogrid"] = ogrid - answers["input:shared:bc_base"] = cml.in_bc_base answers["output:shared:bc_base"] = cml.out_bc_base answers["output:shared:stretch"] = cml.out_stretch - answers["input:shared:stretch"] = cml.in_stretch answers["output:analysis:bkg"] = not cml.nobkg answers["output:analysis:lcv"] = not cml.nolcv if cml.rs == '1':