From a8a8a0cdd92a4597bc2fcb30ce8bc88c9119dc7b Mon Sep 17 00:00:00 2001 From: Yonggang Yu Date: Thu, 3 Dec 2026 01:24:09 -0500 Subject: [PATCH 1/4] GEOSJEDI switch: 1 = GEOSdas_App/jedi, 2 = GEOSdas_App/swell (3, 4 reserved) - fvsetup: GEOSJEDI is read once from the environment ($geosjedi; 1-4, else 0) and written to FVDAS_Run_Config; GEOSJEDI=3/4 abort (reserved, not implemented). Tests use explicit GEOSJEDI values (eq 1 / eq 2). set_geosjedi: GEOSJEDI=1 -> set_geosjedi_1 (the original body); GEOSJEDI=2 -> nothing here (set up after the GEOS-JEDI prompts). New option -jedistatic DIR (GEOSJEDI=1: setup_aanajedi.pl -jedistatic). - write_FVDAS_Run_Config.pl: write "setenv GEOSJEDI ". - GEOSdas.csm (JEDI_AnalysisRun_): selected by GEOSJEDI from FVDAS_Run_Config instead of the existence of run/jedi; experiments with run/jedi but no GEOSJEDI abort with a request to add "setenv GEOSJEDI 1". - jedi/jedi_driver.csh, jedi/jedi_driver_atmens.csh: abort if GEOSJEDI is set to anything but 1 (unset is allowed for jedi_anasa.j/jedi_asens.j). --- src/Applications/GEOSdas_App/GEOSdas.csm | 33 ++++++++-- src/Applications/GEOSdas_App/fvsetup | 64 +++++++++++++++---- .../GEOSdas_App/jedi/jedi_driver.csh | 8 +++ .../GEOSdas_App/jedi/jedi_driver_atmens.csh | 8 +++ .../GEOSdas_App/write_FVDAS_Run_Config.pl | 8 ++- 5 files changed, 104 insertions(+), 17 deletions(-) diff --git a/src/Applications/GEOSdas_App/GEOSdas.csm b/src/Applications/GEOSdas_App/GEOSdas.csm index 8691ffe6..f558dc23 100755 --- a/src/Applications/GEOSdas_App/GEOSdas.csm +++ b/src/Applications/GEOSdas_App/GEOSdas.csm @@ -79,6 +79,8 @@ # (cost goes down with successive updates) # - Temporarily leaving test lines commented out # 8Dec2021 Sienkiewicz - add option for 'cleanup_tail' for aircraft bias correction +# 3Dec2026 Yu - JEDI_AnalysisRun_: selected by GEOSJEDI (FVDAS_Run_Config), +# 1 = GEOSdas_App/jedi (jedi_driver.csh) #----------------------------------------------------------------------------- # @@ -3318,14 +3320,32 @@ endif if ( $?ECHO___ ) set echo # - if ( ! -d $FVHOME/run/jedi ) exit (0) - if ( -e $FVHOME/run/AGCM.BOOTSTRAP.rc.tmpl ) exit (0) # only run from second cycle of experiment onwards + # GEOSJEDI (FVDAS_Run_Config): 1 = JEDI (GEOSdas_App/jedi), 2 = JEDI via swell (GEOSdas_App/swell) + if ( ! $?GEOSJEDI ) then + if ( -d $FVHOME/run/jedi ) then + echo "JEDI_AnalysisRun_: $FVHOME/run/jedi exists, but GEOSJEDI is not set:" + echo "JEDI_AnalysisRun_: experiment set up before the GEOSJEDI switch; add" + echo "JEDI_AnalysisRun_: setenv GEOSJEDI 1" + echo "JEDI_AnalysisRun_: to $FVHOME/run/FVDAS_Run_Config, aborting ..." + Call AbnormalExit_( 1 ) + endif + exit (0) + endif + if ( "$GEOSJEDI" != "1" && "$GEOSJEDI" != "2" ) exit (0) @ idummy = $VAROFFSET * 60 set ana_datetime = ( `tick $gcm_nymd0 $gcm_nhms0 $idummy` ) set this_hh0 = `echo $gcm_nhms0 | cut -c1-2` set this_hha = `echo $ana_datetime[2] | cut -c1-2` + set drvlog = $FVWORK/$EXPID.jedi_drv.log.${gcm_nymd0}_${this_hh0}z.txt + + # first cycle of the experiment: no JEDI analysis + if ( -e $FVHOME/run/AGCM.BOOTSTRAP.rc.tmpl ) then + if ( "$GEOSJEDI" == "1" ) then + exit (0) # only run from second cycle of experiment onwards + endif + endif if ( ! $SKIPGSI && ! -e $FVHOME/run/AGCM.BOOTSTRAP.rc.tmpl ) then set this_log = $EXPID.ana_jo.log.${ana_datetime[1]}_${this_hha}z.txt @@ -3333,8 +3353,13 @@ endif endif - jedi_driver.csh $gcm_nymd0 $gcm_nhms0 $ana_datetime[1] $ana_datetime[2] 0 |& tee -a $FVWORK/$EXPID.jedi_drv.log.${gcm_nymd0}_${this_hh0}z.txt - if ( $status ) then + # (endif resets $status: keep the driver's status) + set jedi_rc = 0 + if ( "$GEOSJEDI" == "1" ) then + jedi_driver.csh $gcm_nymd0 $gcm_nhms0 $ana_datetime[1] $ana_datetime[2] 0 |& tee -a $drvlog + set jedi_rc = $status + endif + if ( $jedi_rc ) then echo "JEDI analysis failed, aborting ..." Call AbnormalExit_( 1 ) endif diff --git a/src/Applications/GEOSdas_App/fvsetup b/src/Applications/GEOSdas_App/fvsetup index f793386f..17737244 100755 --- a/src/Applications/GEOSdas_App/fvsetup +++ b/src/Applications/GEOSdas_App/fvsetup @@ -342,6 +342,9 @@ # 19Jul2018 Wargan Additions for OMPS # 2022,2024 sqz Additions for LADAS # 2025 sqz integrated setup for LADAS +# 03Dec2026 Yu GEOSJEDI switch, from the environment and written to FVDAS_Run_Config: +# 1 = JEDI (GEOSdas_App/jedi), 2 = JEDI via swell (GEOSdas_App/swell), +# 3 and 4 reserved; -jedistatic option #------------------------------------------------------------------------- use Cwd qw(abs_path cwd); use English; @@ -393,6 +396,7 @@ my ($coupled, $ores, $mometc); my ($o_servers,$bckend_wrts, $xncpus, $ncpus_per_node); my ($skipgsi); my ($jedi_ensrpy, $jedi_exprpy); +my ($geosjedi, $jedistatic); my ($sysfile, $nodeflg); my (@rmTilde); @@ -482,6 +486,16 @@ $ENV{"PATH"} = $FindBin::Bin .":$ENV{PATH}"; $skipgsi = 1; } +# GEOS-JEDI, from the environment only: 1 = JEDI (GEOSdas_App/jedi), +# 2 = JEDI via swell (GEOSdas_App/swell), 3 and 4 reserved; else 0 (GSI) + $geosjedi = 0; + if ( defined($ENV{"GEOSJEDI"}) and $ENV{"GEOSJEDI"} =~ /^[1-4]$/ ) { + $geosjedi = $ENV{"GEOSJEDI"}; + } + if ( $geosjedi eq 3 or $geosjedi eq 4 ) { + die ">>> ERROR <<< GEOSJEDI=$geosjedi is reserved, not implemented\n"; + } + # Assorted defaults # ----------------- $siteID = get_siteID(); @@ -709,6 +723,9 @@ sub set_inputparams { # =3 for third-deg sensitivity test # => check: use when calling fvsetup from the checkinput script # => header=s: header for input file +# => jedistatic=s: JEDI static-files directory; GEOSJEDI=1: passed to +# setup_aanajedi.pl -jedistatic; GEOSJEDI=2: required, +# SWELL_STATIC_FILES in $FVHOME/run/swell/swell_exp.csh # => setupfile: file to copy to expid directory (set note below) # => runjob: use when calling fvsetup from the runjob script # => save: default value for $saveFLG used in write_saved_inputs() @@ -738,15 +755,16 @@ sub get_runtime_values { $fvsetupflags .= " $_"; } - GetOptions( "agcm" => \$agcm_rst_flg, - "sensdeg=i" => \$sensdeg, - "check" => \$checkFLG, - "dbqueue|dbq" => \$dbqueue, - "header=s" => \@otherheaders, - "setupfile=s" => \%setupfile, - "runjob" => \$runjobFLG, - "save=i" => \$saveFLG, - "stop" => \$stopFLG); + GetOptions( "agcm" => \$agcm_rst_flg, + "sensdeg=i" => \$sensdeg, + "check" => \$checkFLG, + "dbqueue|dbq" => \$dbqueue, + "header=s" => \@otherheaders, + "jedistatic=s" => \$jedistatic, + "setupfile=s" => \%setupfile, + "runjob" => \$runjobFLG, + "save=i" => \$saveFLG, + "stop" => \$stopFLG); $sensdeg = 1 unless ($sensdeg and $sensdeg eq "3"); $runjobFLG = 1 if $checkFLG; $saveFLG = 1 unless $saveFLG == 2; @@ -850,7 +868,7 @@ sub defaults { vtrack.rc vtx.ctl.tmpl ); - if ( $ENV{"GEOSJEDI"} ) { + if ( $geosjedi eq 1 or $geosjedi eq 2 ) { @a3dvr_files = qw ( Chem_Registry_apert.rc GSI_GridComp.rc.tmpl jedi_gsi.rc.tmpl @@ -3705,10 +3723,27 @@ EOF } +#======================================================================= +# name - set_geosjedi +# purpose - GEOSJEDI=1: install GEOSdas_App/jedi (setup_aanajedi.pl); +# GEOSJEDI=2: GEOSdas_App/swell is installed by set_swell(), +# after the GEOS-JEDI prompts at the end of fvsetup #======================================================================= sub set_geosjedi { - if ( ! $ENV{GEOSJEDI} ) { return 0 }; + if ( $geosjedi eq 1 ) { + return set_geosjedi_1(); + } elsif ( $geosjedi eq 2 ) { + return 0; + } + return 0; +} + +#======================================================================= +# name - set_geosjedi_1 +# purpose - GEOSJEDI=1: install GEOSdas_App/jedi (setup_aanajedi.pl) +#======================================================================= +sub set_geosjedi_1 { $nogsi = " "; if ( $skipgsi ) { @@ -3728,6 +3763,10 @@ sub set_geosjedi { $xtra4jedi = "-ensrpy $jedi_ensrpy -exprpy $jedi_exprpy"; } $jediopts = "-fvhome $fvhome -iodadir $iodadir -archive $acqloc -gcmres $agcm_im $nogsi $xtra4jedi"; + if ( $jedistatic ) { + die ">>> ERROR <<< JEDI static directory not found: $jedistatic\n" unless ( -d $jedistatic ); + $jediopts .= " -jedistatic $jedistatic"; + } if ( $ENV{JEDI_ATMVAR_SCHEME} ) { $jedivar = $ENV{JEDI_ATMVAR_SCHEME}; @@ -8306,7 +8345,7 @@ print SCRIPT <<"EOF"; setenv STAGE4HYBGSI /dev/null setenv RSTSTAGE4AENS /dev/null EOF - if ( $ENV{GEOSJEDI} ) { + if ( $geosjedi eq 1 or $geosjedi eq 2 ) { print SCRIPT <<"EOF"; setenv NSEGS 1 setenv NSTEP 1 @@ -9216,6 +9255,7 @@ sub write_FVDAS_Run_Config { $ENV{"OBSCLASS"} = $obClass; $ENV{"OMP_NUM_THREADS"} = $omp_num_threads; $ENV{"SKIPGSI"} = $skipgsi; + local $ENV{"GEOSJEDI"} = $geosjedi; # run time reads GEOSJEDI from FVDAS_Run_Config only $ENV{"VTRACK"} = $vtrack; $ENV{"VTXLEVS"} = $vtxlevs; $ENV{"VTXRELOC"} = $vtxreloc; diff --git a/src/Applications/GEOSdas_App/jedi/jedi_driver.csh b/src/Applications/GEOSdas_App/jedi/jedi_driver.csh index 6d2233de..ffaa166a 100755 --- a/src/Applications/GEOSdas_App/jedi/jedi_driver.csh +++ b/src/Applications/GEOSdas_App/jedi/jedi_driver.csh @@ -8,6 +8,14 @@ if ( ! $?FVHOME ) then exit (1) endif +# GEOSdas_App/jedi is GEOSJEDI=1 (GEOSJEDI=2 is GEOSdas_App/swell) +if ( $?GEOSJEDI ) then + if ( "$GEOSJEDI" != "1" ) then + echo " ${MYNAME}: GEOSJEDI=$GEOSJEDI; this driver is for GEOSJEDI=1 only, aborting" + exit (1) + endif +endif + if ( ! -d $FVHOME/run/jedi ) then echo " ${MYNAME}: Nothing to do." else diff --git a/src/Applications/GEOSdas_App/jedi/jedi_driver_atmens.csh b/src/Applications/GEOSdas_App/jedi/jedi_driver_atmens.csh index 39ec6915..ae3eee39 100755 --- a/src/Applications/GEOSdas_App/jedi/jedi_driver_atmens.csh +++ b/src/Applications/GEOSdas_App/jedi/jedi_driver_atmens.csh @@ -8,6 +8,14 @@ if ( ! $?FVHOME ) then exit (1) endif +# GEOSdas_App/jedi is GEOSJEDI=1 (GEOSJEDI=2 is GEOSdas_App/swell) +if ( $?GEOSJEDI ) then + if ( "$GEOSJEDI" != "1" ) then + echo " ${MYNAME}: GEOSJEDI=$GEOSJEDI; this driver is for GEOSJEDI=1 only, aborting" + exit (1) + endif +endif + if ( ! -d $FVHOME/run/jedi ) then echo " ${MYNAME}: Nothing to do." else diff --git a/src/Applications/GEOSdas_App/write_FVDAS_Run_Config.pl b/src/Applications/GEOSdas_App/write_FVDAS_Run_Config.pl index 8c6fa375..470f3f44 100755 --- a/src/Applications/GEOSdas_App/write_FVDAS_Run_Config.pl +++ b/src/Applications/GEOSdas_App/write_FVDAS_Run_Config.pl @@ -5,6 +5,7 @@ # revision history # 30Apr2009 Stassi initial version # 28Aug2009 Stassi Update for pleiades +# 03Dec2026 Yu Write GEOSJEDI (0: GSI, 1: GEOSdas_App/jedi, 2: GEOSdas_App/swell) #======================================================================= use strict; @@ -25,7 +26,7 @@ my ($FVROOT_PORTAL, $RC_LOC, $RTAG, $ANAID, $CASE, $ERR, $ERROR_EXP, $FCHOME, $FCSTAGE, $FERR, $FVDOLMS, $FVGROUP, $FVPLOTS, $FVSCRA, $FVSILO, $FVSPOOL, $FVSTAGE, $FVWORK, $GRADS_CONFIG, $LIBSZ, $MONTHLY_X); -my ($ACFTBIAS, $NEWRADBC); +my ($ACFTBIAS, $NEWRADBC, $GEOSJEDI); my (%vv); # main program @@ -110,6 +111,7 @@ sub init { $PYRADMON = $ENV{"PYRADMON"}; $RUN_QUADS = $ENV{"RUN_QUADS"}; $SKIPGSI = $ENV{"SKIPGSI"}; + $GEOSJEDI = $ENV{"GEOSJEDI"}; $VTRACK = $ENV{"VTRACK"}; $VTXLEVS = $ENV{"VTXLEVS"}; $VTXRELOC = $ENV{"VTXRELOC"}; @@ -351,6 +353,10 @@ sub writefile { print RUNCONF "setenv NEWRADBC \"$NEWRADBC\"\n"; print RUNCONF "setenv ANGLEBC \"$NEWRADBC\"\n"; print RUNCONF "setenv SKIPGSI $SKIPGSI\n" if $SKIPGSI; + if ( defined($GEOSJEDI) and $GEOSJEDI ne "" ) { + print RUNCONF "# JEDI analysis: 0 = none (GSI), 1 = GEOSdas_App/jedi, 2 = GEOSdas_App/swell\n"; + print RUNCONF "setenv GEOSJEDI $GEOSJEDI\n"; + } print RUNCONF "\numask 022\n"; print RUNCONF "limit stacksize unlimited\n"; From 8bdbe8632ee39d8367abc9ceddac7a84cd52f3ac Mon Sep 17 00:00:00 2001 From: Yonggang Yu Date: Thu, 3 Dec 2026 01:27:05 -0500 Subject: [PATCH 2/4] GEOSJEDI=2: add GEOSdas_App/swell (JEDI through swell) New layer, installed to $FVROOT/bin and $FVROOT/etc/swell; taken from feature/ygyu/CX_v5.45.1_nov24_wai (894a3cd), with: - no personal or site paths: swell venv, swell source, JEDI build and source, and JEDI static files have no defaults; swell_env.csh stops when one is missing - etc/swell_config.csh holds the shared defaults only and reads the experiment settings from $FVHOME/run/swell/swell_exp.csh first (environment > swell_exp.csh > swell_config.csh) - swell_setup.pl copies swell_config.csh unchanged to run/swell and writes the experiment settings (-set KEY=VALUE) to swell_exp.csh - etc/mkiau.rc.tenv renamed etc/mkiau.rc.tmpl (as the other templates) Scripts: swell_env.csh, swell_render.csh, swell_run.csh, swell_driver.csh (central analysis), swell_gsi2ioda.csh, swell_ana_central.csh (3D-FGAT), swell_mkiau.csh, swell_upd4geos.csh, swell_obs_stage.csh, swell_obs_share.csh, swell_ana_atmens.csh (EDA/GETKF), swell_setup.pl. --- src/Applications/GEOSdas_App/CMakeLists.txt | 1 + .../GEOSdas_App/swell/CMakeLists.txt | 7 + src/Applications/GEOSdas_App/swell/README.md | 180 ++++++++++++ .../GEOSdas_App/swell/etc/CMakeLists.txt | 17 ++ .../swell/etc/atmens_diffstates.yaml.tmpl | 77 +++++ .../swell/etc/atmens_eda.yaml.tmpl | 89 ++++++ .../swell/etc/atmens_getkf.yaml.tmpl | 57 ++++ .../swell/etc/atmens_getkf2.yaml.tmpl | 57 ++++ .../swell/etc/atmens_slurm.yaml.tmpl | 29 ++ .../swell/etc/central_3dfgat.yaml.tmpl | 51 ++++ .../swell/etc/central_slurm.yaml.tmpl | 15 + .../swell/etc/convert_ncdiags.yaml.tmpl | 30 ++ .../GEOSdas_App/swell/etc/mkiau.rc.tmpl | 52 ++++ .../GEOSdas_App/swell/etc/swell_config.csh | 136 +++++++++ .../GEOSdas_App/swell/swell_ana_atmens.csh | 272 ++++++++++++++++++ .../GEOSdas_App/swell/swell_ana_central.csh | 247 ++++++++++++++++ .../GEOSdas_App/swell/swell_driver.csh | 158 ++++++++++ .../GEOSdas_App/swell/swell_env.csh | 96 +++++++ .../GEOSdas_App/swell/swell_gsi2ioda.csh | 108 +++++++ .../GEOSdas_App/swell/swell_mkiau.csh | 257 +++++++++++++++++ .../GEOSdas_App/swell/swell_obs_share.csh | 55 ++++ .../GEOSdas_App/swell/swell_obs_stage.csh | 102 +++++++ .../GEOSdas_App/swell/swell_render.csh | 69 +++++ .../GEOSdas_App/swell/swell_run.csh | 180 ++++++++++++ .../GEOSdas_App/swell/swell_setup.pl | 139 +++++++++ .../GEOSdas_App/swell/swell_upd4geos.csh | 137 +++++++++ 26 files changed, 2618 insertions(+) create mode 100644 src/Applications/GEOSdas_App/swell/CMakeLists.txt create mode 100644 src/Applications/GEOSdas_App/swell/README.md create mode 100644 src/Applications/GEOSdas_App/swell/etc/CMakeLists.txt create mode 100644 src/Applications/GEOSdas_App/swell/etc/atmens_diffstates.yaml.tmpl create mode 100644 src/Applications/GEOSdas_App/swell/etc/atmens_eda.yaml.tmpl create mode 100644 src/Applications/GEOSdas_App/swell/etc/atmens_getkf.yaml.tmpl create mode 100644 src/Applications/GEOSdas_App/swell/etc/atmens_getkf2.yaml.tmpl create mode 100644 src/Applications/GEOSdas_App/swell/etc/atmens_slurm.yaml.tmpl create mode 100644 src/Applications/GEOSdas_App/swell/etc/central_3dfgat.yaml.tmpl create mode 100644 src/Applications/GEOSdas_App/swell/etc/central_slurm.yaml.tmpl create mode 100644 src/Applications/GEOSdas_App/swell/etc/convert_ncdiags.yaml.tmpl create mode 100644 src/Applications/GEOSdas_App/swell/etc/mkiau.rc.tmpl create mode 100644 src/Applications/GEOSdas_App/swell/etc/swell_config.csh create mode 100644 src/Applications/GEOSdas_App/swell/swell_ana_atmens.csh create mode 100644 src/Applications/GEOSdas_App/swell/swell_ana_central.csh create mode 100644 src/Applications/GEOSdas_App/swell/swell_driver.csh create mode 100644 src/Applications/GEOSdas_App/swell/swell_env.csh create mode 100644 src/Applications/GEOSdas_App/swell/swell_gsi2ioda.csh create mode 100644 src/Applications/GEOSdas_App/swell/swell_mkiau.csh create mode 100644 src/Applications/GEOSdas_App/swell/swell_obs_share.csh create mode 100644 src/Applications/GEOSdas_App/swell/swell_obs_stage.csh create mode 100644 src/Applications/GEOSdas_App/swell/swell_render.csh create mode 100644 src/Applications/GEOSdas_App/swell/swell_run.csh create mode 100644 src/Applications/GEOSdas_App/swell/swell_setup.pl create mode 100644 src/Applications/GEOSdas_App/swell/swell_upd4geos.csh diff --git a/src/Applications/GEOSdas_App/CMakeLists.txt b/src/Applications/GEOSdas_App/CMakeLists.txt index 0db76209..56ea5617 100644 --- a/src/Applications/GEOSdas_App/CMakeLists.txt +++ b/src/Applications/GEOSdas_App/CMakeLists.txt @@ -1,5 +1,6 @@ add_subdirectory(testsuites) add_subdirectory(jedi) +add_subdirectory(swell) set(dasscripts FixUnblocked.csh diff --git a/src/Applications/GEOSdas_App/swell/CMakeLists.txt b/src/Applications/GEOSdas_App/swell/CMakeLists.txt new file mode 100644 index 00000000..adf131da --- /dev/null +++ b/src/Applications/GEOSdas_App/swell/CMakeLists.txt @@ -0,0 +1,7 @@ +add_subdirectory(etc) + +file(GLOB cshscripts *.csh) + +install( + PROGRAMS ${cshscripts} swell_setup.pl + DESTINATION bin) diff --git a/src/Applications/GEOSdas_App/swell/README.md b/src/Applications/GEOSdas_App/swell/README.md new file mode 100644 index 00000000..a81cd20f --- /dev/null +++ b/src/Applications/GEOSdas_App/swell/README.md @@ -0,0 +1,180 @@ +# GEOSdas_App/swell — run JEDI from ADAS through swell + +ADAS owns time, data placement and model coupling; swell owns everything about +JEDI (YAML, obs operators, B, executables). ADAS ships no JEDI YAML: each role +has a small override template holding only the values ADAS knows. + +| File | Purpose | +|---|---| +| `etc/swell_config.csh` | settings shared by all experiments (defaults); reads the experiment's `run/swell/swell_exp.csh` first | +| `swell_setup.pl` | called by `fvsetup`: copies `swell_config.csh` (unchanged), writes `swell_exp.csh`, `mkiau.rc.tmpl`, the forecast IAU acquire | +| `swell_env.csh` | sourced: read `swell_config.csh`, check the required settings, activate the venv (`SWELL_ENV_OK`) | +| `swell_render.csh` | find a template, fill `$VAR`s from the environment, reject leftovers | +| `swell_run.csh` | generic: render templates → `swell create` → `swell launch -b` → check → clean | +| `swell_driver.csh` | central analysis of one cycle, called by `GEOSdas.csm`; replaces `jedi_driver.csh` | +| `swell_gsi2ioda.csh` | role: GSI ncdiag + GSI bias → IODA (suite `convert_ncdiags`) | +| `swell_ana_central.csh` | role: central 3D-FGAT analysis (suite `3dfgat_atmos`), replaces `jedi_set.csh` + `jedi_run.csh` | +| `swell_mkiau.csh` | analyses and IAU forcing from the JEDI increment(s) at each IAU time (`dyn_jediupd.x`, `mkiau.x`), replaces `jedi_mkiau.csh` | +| `swell_upd4geos.csh` | GEOS uses the JEDI IAU forcing (and, in 4D-IAU, the JEDI `agcm09`/`ana09` and central analysis of the ensemble), replaces `jedi_upd4geos.csh` | +| `swell_ana_atmens.csh` | role: ensemble analysis (EDA / GETKF); replaces `jedi_driver_atmens.csh` | +| `etc/convert_ncdiags.yaml.tmpl` | override for `swell_gsi2ioda.csh` | +| `etc/central_3dfgat.yaml.tmpl`, `etc/central_slurm.yaml.tmpl` | override and slurm settings for `swell_ana_central.csh` | +| `etc/atmens_{eda,getkf,getkf2}.yaml.tmpl`, `etc/atmens_slurm.yaml.tmpl` | overrides and slurm settings for `swell_ana_atmens.csh` | +| `etc/atmens_diffstates.yaml.tmpl` | `fv3jedi_diffstates.x` input for the EDA member increments (`swell_ana_atmens.csh`) | +| `etc/mkiau.rc.tmpl` | `mkiau.x` resource template (`@AGCM_IM`, `@AGCM_JM`, `@AGCM_LM` filled in by `swell_setup.pl`) | + +## The GEOSJEDI switch + +One value selects the JEDI analysis of an experiment. `fvsetup` takes it from +the environment and writes it into `$FVHOME/run/FVDAS_Run_Config`; at run time +the jobs read only that value. The two JEDI designs share no code: `GEOSJEDI=1` +runs only `GEOSdas_App/jedi`, `GEOSJEDI=2` only `GEOSdas_App/swell`. `GEOSJEDI=3` +and `4` are reserved (`fvsetup` stops); any other value means GSI only. + +| `GEOSJEDI` | `fvsetup` | central analysis (`GEOSdas.csm`) | +|---|---|---| +| 0 or unset | GSI only | none | +| 1 | `setup_aanajedi.pl` → `run/jedi` | `jedi_driver.csh` | +| 2 | `swell_setup.pl` → `run/swell` | `swell_driver.csh` (3D-FGAT) | + +New experiments always get `setenv GEOSJEDI ` in `FVDAS_Run_Config`, so a +`GEOSJEDI` exported in the shell that submits the job does not matter. An +experiment set up before the switch existed, with `run/jedi`, stops in +`GEOSdas.csm` until `setenv GEOSJEDI 1` is added to its `FVDAS_Run_Config`. + +## Setting up an experiment (GEOSJEDI=2) + + setenv GEOSJEDI 2 + fvsetup -jedistatic /path/to/SwellStaticFiles + +`-jedistatic DIR` is required. At the end of `fvsetup`, after all other questions: + + GEOSJEDI = 2:JEDI via swell, 1:JEDI or 0:GSI? 2 (from the environment: shown, not asked) + jedi_ens_scheme = 1:EDA or 2:GETKF? [1] + jedi_ens_member? [32] + swell venv? + swell source directory? + JEDI build directory? + +The three paths have no built-in default (`$SWELL_VENV`, `$SWELL_SRC` and +`$SWELL_JEDI_BUILD` are offered when set). `fvsetup` then runs `swell_setup.pl`: + +- `$FVHOME/run/swell/swell_config.csh`: copy of `$FVROOT/etc/swell/swell_config.csh`, + unchanged; +- `$FVHOME/run/swell/swell_exp.csh`: the settings of this experiment, e.g. + + if ( ! $?SWELL_VENV ) setenv SWELL_VENV + if ( ! $?SWELL_SRC ) setenv SWELL_SRC + if ( ! $?SWELL_JEDI_BUILD ) setenv SWELL_JEDI_BUILD + if ( ! $?SWELL_JEDI_SRC ) setenv SWELL_JEDI_SRC + if ( ! $?SWELL_STATIC_FILES ) setenv SWELL_STATIC_FILES <-jedistatic DIR> + if ( ! $?SWELL_CENTRAL_CRES ) setenv SWELL_CENTRAL_CRES 91 + if ( ! $?SWELL_SLURM_ACCOUNT ) setenv SWELL_SLURM_ACCOUNT + + `swell_config.csh` reads it ahead of its own defaults: environment > + `swell_exp.csh` > `swell_config.csh`; +- `$FVHOME/run/swell/mkiau.rc.tmpl`: `etc/swell/mkiau.rc.tmpl` with the AGCM grid filled in; +- `fcst/rst4fcst.acq` acquires the JEDI IAU (`jedi_agcmrst`) in place of the + GSI IAU (`agcm_import_rst`); the restart line stays. + +The central analysis is 3D-FGAT with climatological B, also when the ensemble +is on (`hyb_ens >= 3`; hybrid through swell is still to come). `SKIPGSI` needs +`OFFLINE_IODA_DIR` (→ `SWELL_OFFLINE_IODA_DIR`). + +Templates and an optional `slurm.yaml` placed in `$FVHOME/run/swell` take +precedence over the installed ones in `$FVROOT/etc/swell`. + +## Central analysis (swell_driver.csh) + +Each step is restartable through its `.DONE` file in `$FVWORK`. + +| step | | +|---|---| +| 1. observations | `swell_gsi2ioda.csh` → `$FVWORK/ioda.`; or links to `$SWELL_OFFLINE_IODA_DIR//geos_atmosphere` | +| 2. analysis | `swell_ana_central.csh` (below) | +| 3. IAU (`SWELL_MKIAU=1`) | `swell_mkiau.csh`: at each IAU time, `dyn_jediupd.x`(`$FVHOME/recycle` bkg.eta, increment) → `mkiau.x` | +| 4. use the IAU (`SWELL_IAU_OVERWRITE=1`, forced by `SKIPGSI`) | `swell_upd4geos.csh`: `$FVWORK/[$EXPID.]agcm_import_rst.` → the JEDI IAU | + +IAU times: with `DO4DIAU=1` every `ASYNBKG` minutes of the window (09z…15z for the +12z cycle), as the GSI 4D-IAU; with `DO4DIAU=0` the analysis time only (3D-IAU, the +file tagged with the window begin). One JEDI increment (3D-FGAT) is added to the +background of each IAU time; with several (4D, e.g. 4DEnVar) each IAU time needs +its own increment, else `swell_mkiau.csh` aborts. With one increment `mkiau.x` +runs once, at the analysis time, and the other IAU times get that file (hard +links: the GCM ignores the time stored in it); `SWELL_MKIAU_EACH_TIME=1` runs +`mkiau.x` at every IAU time from that time's background. With 4D increments +`mkiau.x` always runs at every IAU time. + +With `DO4DIAU=1` and `SWELL_IAU_OVERWRITE=1` (read from `run/swell/swell_config.csh` +by `GEOSdas.csm` too), `CoupleAnaToGcm_` runs `ana4dupd.pl` without `-iau`: GSI still +makes its `ana.eta`, but no IAU tendencies, `agcm09`/`ana09`, nor `atmens/central`. +`swell_upd4geos.csh` then provides, from JEDI: `$EXPID.agcm_import_rst.` (hard +links into `$JEDIWORK/iau`, so `$EXPID.agcmrst..tar` archives the JEDI forcing), +`$EXPID.agcm09_import_rst.` and `$EXPID.ana09.eta.` at the window end, and +`$STAGE4HYBGSI/$EXPID.ana.eta.` + `$FVHOME/.DONE_MEM001_analyzer.` (the +central analysis the ensemble recenters on). A missing JEDI file stops the cycle; +the GCM never mixes GSI and JEDI forcing. The first cycle (no JEDI analysis) keeps +the GSI IAU. + +Logs `$FVWORK/$EXPID.jedi_{drv,g2i,run,var,cfg,miau,upd}.log.z.txt` and the +tars below keep the names of the jedi layer, so the archive rules are unchanged. + +| swell_ana_central.csh | | +|---|---| +| observations | `$FVWORK/ioda.` → swell `ioda_locations_not_in_r2d2` | +| backgrounds | `$SWELL_BKG_ARCHIVE/$EXPID/rs/Y/M/$EXPID.bkgcrst..tar` (swell `GetBackgroundGeosExperiment`) | +| bias correction | previous cycle's JEDI VarBC in `$SWELL_VARBC_DIR` when `SWELL_FEEDBACK_VARBC=1`, else GSI biases | +| B | GSIBEC climatological, `gsibec/$SWELL_GSIBEC_VERSION` in `$SWELL_STATIC_FILES` | +| → `$JEDIWORK/inc` | `$EXPID.jedi_inc1.eta..nc4` (lat-lon increment, read by `swell_mkiau.csh`) | +| → `$JEDIWORK/ana` | `$EXPID.jedi_ana.ceta..nc4` (cubed analysis at the analysis time) | +| → `$FVWORK` | `$EXPID.jedi_{hofx,vbc}..tar`, `$EXPID.jedi_{var,cfg}.log..txt` | +| → `$SWELL_VARBC_DIR` | VarBC output at the window begin, input of the next cycle | +| → `$SWELL_OBS_SHARE/` | copy of the observations and biases used, read by the ensemble | + +| swell_mkiau.csh | | +|---|---| +| → `$JEDIWORK/ana`, `$FVWORK/$EXPID.jedi_ana..tar` | `$EXPID.jedi_ana.eta..nc4` (lat-lon analysis at each IAU time) | +| → `$JEDIWORK/inc`, `$FVWORK/$EXPID.jedi_inc..tar` | increments (`jedi_inc1` from JEDI, `jedi_inc` on the background grid) | +| → `$JEDIWORK/iau`, `$FVWORK/$EXPID.jedi_agcmrst..tar` | `$EXPID.agcm_import_rst..nc4` (4D-IAU: each IAU time; 3D-IAU: one file tagged with the IAU start) | + +Processor layout and GSIBEC grid follow from `SWELL_CENTRAL_CRES` (table in +`swell_ana_central.csh`; any `SWELL_CENTRAL_*` already set wins). + +## Ensemble analysis data flow (swell_ana_atmens.csh) + +| | | +|---|---| +| method | `SWELL_ENSEMBLE`: `eda` (eda_atmos), `getkf` (localensembleda), `getkf2` (localensembleda_2steps) | +| observations | `$SWELL_OBS_SHARE/`: the same observations and biases as the central analysis of the cycle | +| backgrounds | `$ATMENSLOC/ensbkgx/memNNN/*.bkg_clcv.*` read in place (swell links an unpacked `atmens_ebkgx` layout) | +| B (EDA) | GSIBEC climatological, `gsibec/$SWELL_GSIBEC_VERSION` | +| → member increments | lat-lon `analysis/memNNN/.inc.eta..nc4`: GETKF posterior member increments written by swell; EDA analysis − background, made by `swell_ana_atmens.csh` with `fv3jedi_diffstates.x` (swell writes the EDA member analyses `eda_atmos.ana.ceta` on the cubed sphere only) | +| → `$FVWORK/updated_ens/memNNN` | `$EXPID.ana.eta..nc4` = `dyn_jediupd.x`(`$ATMENSLOC/memNNN/$EXPID.bkg.eta`, increment) | +| → `$FVWORK/updated_ens` | `ensmean/`, `ensrms/` (filled by `post_eana.csh`), `$EXPID.atmens_olog..tar.gz` | + +The ensemble needs the central analysis of the same cycle to have run through +swell first (it reads `$SWELL_OBS_SHARE/`); it aborts otherwise. Layout and +GSIBEC grid follow from `SWELL_ENS_CRES` (13, 25, 91, 181). + +The EDA increments are the only JEDI executable this layer runs itself: it loads +`SWELL_JEDI_MODULES` (default `$SWELL_JEDI_BUILD/modules`) in a subshell and starts +`fv3jedi_diffstates.x` with `SWELL_JEDI_MPIRUN` (default `mpirun`) on 6 tasks. + +## swell_run.csh + + swell_run.csh suite template exproot expid nymd nhms + +- `expid` must be unique per role and cycle (e.g. `${EXPID}-ana-2026082612`). +- Templates are rendered with `vED -env`; any unresolved `$VAR` aborts. + `SWELL_SLURM_TEMPLATE` is rendered the same way and passed with `-s`. +- Success requires `swell launch -b` to return 0 and swell's `cycle_done_*` + marker in the cycle directory (`SWELL_DONE_MARKER=none` to skip). +- Each run leaves `//swell_run.info` (swell commit, JEDI build, + override) and `cylc_log.tar.gz`. The `~/cylc-run` entry is removed on success + (`SWELL_KEEP_CYLC_RUN=1` to keep) and kept on failure. + +## Debugging interactively + + setenv FVHOME /path/to/exp + source $FVROOT/bin/swell_env.csh # SWELL_ENV_OK should be 1 + swell task RunJediVariationalExecutable /-suite/experiment.yaml -d 2026-08-26T12:00:00Z -m geos_atmosphere diff --git a/src/Applications/GEOSdas_App/swell/etc/CMakeLists.txt b/src/Applications/GEOSdas_App/swell/etc/CMakeLists.txt new file mode 100644 index 00000000..f326e47d --- /dev/null +++ b/src/Applications/GEOSdas_App/swell/etc/CMakeLists.txt @@ -0,0 +1,17 @@ +set (ALLETC + swell_config.csh + convert_ncdiags.yaml.tmpl + central_3dfgat.yaml.tmpl + central_slurm.yaml.tmpl + atmens_eda.yaml.tmpl + atmens_getkf.yaml.tmpl + atmens_getkf2.yaml.tmpl + atmens_slurm.yaml.tmpl + atmens_diffstates.yaml.tmpl + mkiau.rc.tmpl + ) + +install ( + FILES ${ALLETC} + DESTINATION etc/swell + ) diff --git a/src/Applications/GEOSdas_App/swell/etc/atmens_diffstates.yaml.tmpl b/src/Applications/GEOSdas_App/swell/etc/atmens_diffstates.yaml.tmpl new file mode 100644 index 00000000..784688e3 --- /dev/null +++ b/src/Applications/GEOSdas_App/swell/etc/atmens_diffstates.yaml.tmpl @@ -0,0 +1,77 @@ +# fv3jedi_diffstates.x: lat-lon increment of one EDA member = analysis - background +# (swell writes the EDA member analyses on the cubed sphere only) +# +# Rendered by swell_ana_atmens.csh for each member and run in the member directory +# (SWELL_DIFF_FV3FILES is relative to it: FMS cuts file names at 128 characters). +# Both states are read as swell reads the EDA backgrounds (background_eda.py); the +# output holds what dyn_jediupd.x reads (ps ts t ua va q o3ppmv) and the other +# analysis variables. +# SWELL_DIFF_*, SWELL_ENS_CRES swell_ana_atmens.csh + +state geometry: + fms initialization: + namelist filename: $SWELL_DIFF_FV3FILES/fmsmpp.nml + field table filename: $SWELL_DIFF_FV3FILES/field_table_gmao + akbk: $SWELL_DIFF_FV3FILES/akbk72.nc4 + layout: [1, 1] + npx: $SWELL_ENS_CRES + npy: $SWELL_ENS_CRES + npz: 72 +increment geometry: + akbk: $SWELL_DIFF_FV3FILES/akbk72.nc4 + layout: [1, 1] + npx: $SWELL_ENS_CRES + npy: $SWELL_ENS_CRES + npz: 72 + +# increment = state1 - state2 +state1: + datetime: '$SWELL_DIFF_DATE' + filetype: cube sphere history + provider: geos + compute edge pressure from surface pressure: true + max allowable geometry difference: 1e-3 + datapath: $SWELL_DIFF_ANA_DIR + filename: $SWELL_DIFF_ANA_FILE + state variables: &variables + - eastward_wind + - northward_wind + - air_temperature + - air_pressure_at_surface + - air_pressure_levels + - water_vapor_mixing_ratio_wrt_moist_air + - cloud_liquid_ice + - cloud_liquid_water + - rain_water + - snow_water + - mole_fraction_of_ozone_in_air + - skin_temperature_at_surface + field io names: &io_names + eastward_wind: ua + northward_wind: va + air_temperature: t + air_pressure_at_surface: ps + air_pressure_levels: pe + water_vapor_mixing_ratio_wrt_moist_air: q + cloud_liquid_ice: qi + cloud_liquid_water: ql + rain_water: qr + snow_water: qs + mole_fraction_of_ozone_in_air: o3ppmv + skin_temperature_at_surface: ts +state2: + datetime: '$SWELL_DIFF_DATE' + filetype: cube sphere history + provider: geos + compute edge pressure from surface pressure: true + max allowable geometry difference: 1e-3 + datapath: $SWELL_DIFF_BKG_DIR + filename: $SWELL_DIFF_BKG_FILE + state variables: *variables + field io names: *io_names +output: + filetype: auxgrid + gridtype: latlon + datapath: . + filename: $SWELL_DIFF_OUTPUT + field io names: *io_names diff --git a/src/Applications/GEOSdas_App/swell/etc/atmens_eda.yaml.tmpl b/src/Applications/GEOSdas_App/swell/etc/atmens_eda.yaml.tmpl new file mode 100644 index 00000000..c56fccd8 --- /dev/null +++ b/src/Applications/GEOSdas_App/swell/etc/atmens_eda.yaml.tmpl @@ -0,0 +1,89 @@ +# swell override: ADAS ensemble analysis, EDA = perturbed-observation 3D-Var members +# (swell suite eda_atmos, run by swell_ana_atmens.csh) +# +# Only values ADAS has to supply are set here. Swell writes the member analyses on +# the cubed sphere (analysis/memNNN/eda_atmos.ana.ceta..nc4); swell_ana_atmens.csh +# makes the lat-lon member increments from them. Ensemble statistics are computed later +# by post_eana.csh, so swell's mean/variance tasks are skipped. +# SWELL_* swell_run.csh / swell_config.csh +# SWELL_ENS_*, SWELL_ENS_ROOT, SWELL_OBS_SHARE swell_ana_atmens.csh + +experiment_id: $SWELL_EXPERIMENT_ID +experiment_root: $SWELL_EXPERIMENT_ROOT +start_cycle_point: '$SWELL_ISO_DATE' +final_cycle_point: '$SWELL_ISO_DATE' +skip_eva: true +skip_ensemble_statistics: true + +jedi_build_method: use_existing +existing_jedi_build_directory: $SWELL_JEDI_BUILD +existing_jedi_source_directory: $SWELL_JEDI_SRC + +models: + geos_atmosphere: + cycle_times: + - $SWELL_CYCLE_TIME + window_type: 3D + window_length: PT6H + background_time_offset: PT9H # time tag of the bias files + ebkg_time_offset: PT3H + + background_experiment: $EXPID + geos_x_ensemble_directory: $SWELL_ENS_ROOT + ioda_locations_not_in_r2d2: $SWELL_OBS_SHARE + ensemble_num_members: $SWELL_ENS_NMEM + + horizontal_resolution: '$SWELL_ENS_CRES' + vertical_resolution: '72' + npx_proc: $SWELL_ENS_NPX + npy_proc: $SWELL_ENS_NPY + perhost: $SWELL_ENS_PERHOST + + gsibec_configuration: cli_gsibec_configuration + gsibec_version: '$SWELL_GSIBEC_VERSION' + gsibec_nlats: $SWELL_ENS_GSIBEC_NLATS + gsibec_nlons: $SWELL_ENS_GSIBEC_NLONS + minimizer: DRPCG + gradient_norm_reduction: 1e-3 + number_of_iterations: + - $SWELL_ENS_NITER + obs_pert_amplitude: $SWELL_ENS_OBS_PERT + obs_thinning_rej_fraction: $SWELL_ENS_THIN + + crtm_coeff_dir: $SWELL_CRTM_COEFFS + swell_static_files: $SWELL_STATIC_FILES + observing_system_records_mksi_path: $SWELL_MKSI_PATH + clean_patterns: [] + + # channel-correlated radiances (airs, cris, iasi) are left out: their obs + # errors cannot be perturbed consistently yet + observations: + - aircraft_temperature + - aircraft_wind + - amsr2_gcom-w1 + - amsua_aqua + - amsua_metop-b + - amsua_metop-c + - amsua_n15 + - amsua_n18 + - amsua_n19 + - atms_n20 + - atms_npp + - avhrr3_metop-b + - avhrr3_n18 + - avhrr3_n19 + - gmi_gpm + - gps + - mhs_metop-b + - mhs_metop-c + - mhs_n19 + - mls55_aura + - omi_aura + - ompsnm_npp + - pibal + - satwind + - scatwind + - sfcship + - sfc + - sondes + - ssmis_f17 diff --git a/src/Applications/GEOSdas_App/swell/etc/atmens_getkf.yaml.tmpl b/src/Applications/GEOSdas_App/swell/etc/atmens_getkf.yaml.tmpl new file mode 100644 index 00000000..5fd2959e --- /dev/null +++ b/src/Applications/GEOSdas_App/swell/etc/atmens_getkf.yaml.tmpl @@ -0,0 +1,57 @@ +# swell override: ADAS ensemble analysis, 1-step GETKF +# (swell suite localensembleda, run by swell_ana_atmens.csh) +# +# Only values ADAS has to supply are set here; the observation list, localization +# and inflation are the swell defaults. ADAS uses the posterior member increments +# (analysis/memNNN/localensembleda.inc.eta..nc4); ensemble statistics are +# computed later by post_eana.csh, so swell's mean/variance tasks are skipped. +# SWELL_* swell_run.csh / swell_config.csh +# SWELL_ENS_*, SWELL_ENS_ROOT, SWELL_OBS_SHARE swell_ana_atmens.csh + +experiment_id: $SWELL_EXPERIMENT_ID +experiment_root: $SWELL_EXPERIMENT_ROOT +start_cycle_point: '$SWELL_ISO_DATE' +final_cycle_point: '$SWELL_ISO_DATE' +skip_eva: true +skip_ensemble_statistics: true + +jedi_build_method: use_existing +existing_jedi_build_directory: $SWELL_JEDI_BUILD +existing_jedi_source_directory: $SWELL_JEDI_SRC + +models: + geos_atmosphere: + cycle_times: + - $SWELL_CYCLE_TIME + window_type: 3D + window_length: PT6H + background_time_offset: PT9H # time tag of the bias files + ebkg_time_offset: PT3H + + background_experiment: $EXPID + geos_x_ensemble_directory: $SWELL_ENS_ROOT + ioda_locations_not_in_r2d2: $SWELL_OBS_SHARE + ensemble_num_members: $SWELL_ENS_NMEM + + horizontal_resolution: '$SWELL_ENS_CRES' + vertical_resolution: '72' + npx_proc: $SWELL_ENS_NPX + npy_proc: $SWELL_ENS_NPY + perhost: $SWELL_ENS_PERHOST + + gsibec_configuration: cli_gsibec_configuration + gsibec_version: '$SWELL_GSIBEC_VERSION' + gsibec_nlats: $SWELL_ENS_GSIBEC_NLATS + gsibec_nlons: $SWELL_ENS_GSIBEC_NLONS + obs_thinning_rej_fraction: $SWELL_ENS_THIN + + skip_ensemble_hofx: true + local_ensemble_save_posterior_ensemble: false + local_ensemble_save_posterior_ensemble_increments: true + local_ensemble_save_posterior_mean: false + local_ensemble_save_posterior_mean_increment: false + + crtm_coeff_dir: $SWELL_CRTM_COEFFS + swell_static_files: $SWELL_STATIC_FILES + observing_system_records_mksi_path: $SWELL_MKSI_PATH + clean_patterns: [] diff --git a/src/Applications/GEOSdas_App/swell/etc/atmens_getkf2.yaml.tmpl b/src/Applications/GEOSdas_App/swell/etc/atmens_getkf2.yaml.tmpl new file mode 100644 index 00000000..5f655772 --- /dev/null +++ b/src/Applications/GEOSdas_App/swell/etc/atmens_getkf2.yaml.tmpl @@ -0,0 +1,57 @@ +# swell override: ADAS ensemble analysis, 2-step GETKF (observers per observation type, then the solver) +# (swell suite localensembleda_2steps, run by swell_ana_atmens.csh) +# +# Only values ADAS has to supply are set here; the observation list, localization +# and inflation are the swell defaults. ADAS uses the posterior member increments +# (analysis/memNNN/localensembleda_2steps.inc.eta..nc4); ensemble statistics are +# computed later by post_eana.csh. +# SWELL_* swell_run.csh / swell_config.csh +# SWELL_ENS_*, SWELL_ENS_ROOT, SWELL_OBS_SHARE swell_ana_atmens.csh + +experiment_id: $SWELL_EXPERIMENT_ID +experiment_root: $SWELL_EXPERIMENT_ROOT +start_cycle_point: '$SWELL_ISO_DATE' +final_cycle_point: '$SWELL_ISO_DATE' +skip_eva: true +skip_ensemble_statistics: true + +jedi_build_method: use_existing +existing_jedi_build_directory: $SWELL_JEDI_BUILD +existing_jedi_source_directory: $SWELL_JEDI_SRC + +models: + geos_atmosphere: + cycle_times: + - $SWELL_CYCLE_TIME + window_type: 3D + window_length: PT6H + background_time_offset: PT9H # time tag of the bias files + ebkg_time_offset: PT3H + + background_experiment: $EXPID + geos_x_ensemble_directory: $SWELL_ENS_ROOT + ioda_locations_not_in_r2d2: $SWELL_OBS_SHARE + ensemble_num_members: $SWELL_ENS_NMEM + + horizontal_resolution: '$SWELL_ENS_CRES' + vertical_resolution: '72' + npx_proc: $SWELL_ENS_NPX + npy_proc: $SWELL_ENS_NPY + perhost: $SWELL_ENS_PERHOST + + gsibec_configuration: cli_gsibec_configuration + gsibec_version: '$SWELL_GSIBEC_VERSION' + gsibec_nlats: $SWELL_ENS_GSIBEC_NLATS + gsibec_nlons: $SWELL_ENS_GSIBEC_NLONS + obs_thinning_rej_fraction: $SWELL_ENS_THIN + + skip_ensemble_hofx: true + local_ensemble_save_posterior_ensemble: false + local_ensemble_save_posterior_ensemble_increments: true + local_ensemble_save_posterior_mean: false + local_ensemble_save_posterior_mean_increment: false + + crtm_coeff_dir: $SWELL_CRTM_COEFFS + swell_static_files: $SWELL_STATIC_FILES + observing_system_records_mksi_path: $SWELL_MKSI_PATH + clean_patterns: [] diff --git a/src/Applications/GEOSdas_App/swell/etc/atmens_slurm.yaml.tmpl b/src/Applications/GEOSdas_App/swell/etc/atmens_slurm.yaml.tmpl new file mode 100644 index 00000000..68b92abf --- /dev/null +++ b/src/Applications/GEOSdas_App/swell/etc/atmens_slurm.yaml.tmpl @@ -0,0 +1,29 @@ +# swell slurm settings for the ADAS ensemble analysis (swell_ana_atmens.csh) +# SWELL_SLURM_* swell_config.csh +# SWELL_ENS_NODES, SWELL_ENS_PERHOST swell_ana_atmens.csh (from the layout) +# Entries for tasks that a suite does not have are ignored. + +slurm_directives_global: + account: $SWELL_SLURM_ACCOUNT + qos: $SWELL_SLURM_QOS + constraint: $SWELL_SLURM_CONSTRAINT + +slurm_directives_tasks: + RunJediEdaExecutable: # one job per member + geos_atmosphere: + nodes: $SWELL_ENS_NODES + ntasks-per-node: $SWELL_ENS_PERHOST + time: '$SWELL_ENS_WALLTIME' + RunJediLocalEnsembleDaExecutable: + geos_atmosphere: + nodes: $SWELL_ENS_NODES + ntasks-per-node: $SWELL_ENS_PERHOST + time: '$SWELL_ENS_WALLTIME' + RunJediEtkfSolver: + geos_atmosphere: + nodes: $SWELL_ENS_NODES + ntasks-per-node: $SWELL_ENS_PERHOST + time: '$SWELL_ENS_WALLTIME' + RunJediEtkfObserver: + geos_atmosphere: + time: '$SWELL_ENS_WALLTIME' diff --git a/src/Applications/GEOSdas_App/swell/etc/central_3dfgat.yaml.tmpl b/src/Applications/GEOSdas_App/swell/etc/central_3dfgat.yaml.tmpl new file mode 100644 index 00000000..f1c88101 --- /dev/null +++ b/src/Applications/GEOSdas_App/swell/etc/central_3dfgat.yaml.tmpl @@ -0,0 +1,51 @@ +# swell override: ADAS central analysis, 3D-FGAT with climatological GSIBEC B +# (swell suite 3dfgat_atmos, run by swell_ana_central.csh) +# +# Only values ADAS has to supply are set here; observation operators, QC, B and +# the JEDI YAML itself come from swell. The observation list is the suite +# default; observations without data in the cycle are dropped by swell. +# SWELL_* set by swell_run.csh / swell_config.csh +# SWELL_CENTRAL_*, SWELL_IODA_DIR set by swell_ana_central.csh + +experiment_id: $SWELL_EXPERIMENT_ID +experiment_root: $SWELL_EXPERIMENT_ROOT +start_cycle_point: '$SWELL_ISO_DATE' +final_cycle_point: '$SWELL_ISO_DATE' +skip_eva: true + +jedi_build_method: use_existing +existing_jedi_build_directory: $SWELL_JEDI_BUILD +existing_jedi_source_directory: $SWELL_JEDI_SRC + +models: + geos_atmosphere: + cycle_times: + - $SWELL_CYCLE_TIME + window_type: 4D # 4D-Var with PSEUDO model + Identity TLM = 3D-FGAT + window_length: PT6H + background_time_offset: PT9H + background_frequency: $SWELL_VAR_BKG_FREQ + + background_experiment: $EXPID + geos_x_background_directory: $SWELL_BKG_ARCHIVE + ioda_locations_not_in_r2d2: $SWELL_IODA_DIR + + horizontal_resolution: '$SWELL_CENTRAL_CRES' + vertical_resolution: '72' + npx_proc: $SWELL_CENTRAL_NPX + npy_proc: $SWELL_CENTRAL_NPY + perhost: $SWELL_CENTRAL_PERHOST + + gsibec_configuration: cli_gsibec_configuration + gsibec_version: '$SWELL_GSIBEC_VERSION' + gsibec_nlats: $SWELL_CENTRAL_GSIBEC_NLATS + gsibec_nlons: $SWELL_CENTRAL_GSIBEC_NLONS + minimizer: DRPCG + gradient_norm_reduction: 1e-3 + number_of_iterations: + - $SWELL_VAR_NITER + + crtm_coeff_dir: $SWELL_CRTM_COEFFS + swell_static_files: $SWELL_STATIC_FILES + observing_system_records_mksi_path: $SWELL_MKSI_PATH + clean_patterns: [] # ADAS collects the outputs after the run diff --git a/src/Applications/GEOSdas_App/swell/etc/central_slurm.yaml.tmpl b/src/Applications/GEOSdas_App/swell/etc/central_slurm.yaml.tmpl new file mode 100644 index 00000000..06dd7322 --- /dev/null +++ b/src/Applications/GEOSdas_App/swell/etc/central_slurm.yaml.tmpl @@ -0,0 +1,15 @@ +# swell slurm settings for the ADAS central analysis (swell_ana_central.csh) +# SWELL_SLURM_* swell_config.csh +# SWELL_CENTRAL_NODES, SWELL_CENTRAL_PERHOST swell_ana_central.csh (from the layout) + +slurm_directives_global: + account: $SWELL_SLURM_ACCOUNT + qos: $SWELL_SLURM_QOS + constraint: $SWELL_SLURM_CONSTRAINT + +slurm_directives_tasks: + RunJediVariationalExecutable: + geos_atmosphere: + nodes: $SWELL_CENTRAL_NODES + ntasks-per-node: $SWELL_CENTRAL_PERHOST + time: '$SWELL_CENTRAL_WALLTIME' diff --git a/src/Applications/GEOSdas_App/swell/etc/convert_ncdiags.yaml.tmpl b/src/Applications/GEOSdas_App/swell/etc/convert_ncdiags.yaml.tmpl new file mode 100644 index 00000000..a05f7117 --- /dev/null +++ b/src/Applications/GEOSdas_App/swell/etc/convert_ncdiags.yaml.tmpl @@ -0,0 +1,30 @@ +# swell override: GSI ncdiag + GSI bias text -> IODA (swell suite convert_ncdiags) +# +# Only values ADAS has to supply are set here; everything else is the swell +# default. $VARs are resolved by swell_run.csh (vED -env); an unresolved $VAR +# aborts the run. +# SWELL_* set by swell_run.csh / swell_config.csh +# SWELL_GSI_DIAG_DIR, SWELL_GSI_BIAS_DIR set by swell_gsi2ioda.csh + +experiment_id: $SWELL_EXPERIMENT_ID +experiment_root: $SWELL_EXPERIMENT_ROOT +start_cycle_point: '$SWELL_ISO_DATE' +final_cycle_point: '$SWELL_ISO_DATE' + +jedi_build_method: use_existing +existing_jedi_build_directory: $SWELL_JEDI_BUILD +existing_jedi_source_directory: $SWELL_JEDI_SRC + +models: + geos_atmosphere: + cycle_times: + - $SWELL_CYCLE_TIME + window_length: PT6H + background_time_offset: PT9H + crtm_coeff_dir: $SWELL_CRTM_COEFFS + path_to_gsi_nc_diags: $SWELL_GSI_DIAG_DIR + path_to_gsi_bc_coefficients: $SWELL_GSI_BIAS_DIR/*bias*%Y%m%d_%Hz.txt + produce_geovals: false # swell default is true; ADAS does not use GeoVaLs + observations: + - aircraft + - amsua_n19 # radiance entry needed so GsiBcToIoda writes satbias/tlapse diff --git a/src/Applications/GEOSdas_App/swell/etc/mkiau.rc.tmpl b/src/Applications/GEOSdas_App/swell/etc/mkiau.rc.tmpl new file mode 100644 index 00000000..843e1551 --- /dev/null +++ b/src/Applications/GEOSdas_App/swell/etc/mkiau.rc.tmpl @@ -0,0 +1,52 @@ +# MAPL required variables +# ----------------------- +RUN_DT: 21600 # for now, must be set to 6-hrs +MAPL_ENABLE_TIMERS: NO +PRINTSPEC: 0 # (0: OFF, 1: IMPORT & EXPORT, 2: IMPORT, 3: EXPORT) + +# request increment to (also) come out in sdf format +# -------------------------------------------------- +#SDF_FILENAME: agcm_import_rst.%y4%m2%d2_%h2z.nc4 + +# Model Resolution and Timestep Parameters +# 4x4 is usually enough for any resolution +# ---------------------------------------- +NX: 4 +NY: 24 + +#TEST_CASE: 0 +#TEST_CASE: 1 # convert cubed back to latlon +#TEST_CASE: 2 # test ad l2c (not avail yet) +#TEST_CASE: 3 # test ad c2l + +DYCORE: FV3 +AGCM.GRIDNAME: PE@AGCM_IMx@AGCM_JM-CF + +AGCM.IM_WORLD: @AGCM_IM +AGCM.JM_WORLD: @AGCM_JM +AGCM.LM: @AGCM_LM +AGCM.GRID_TYPE: Cubed-Sphere + +IAU_DATE: $ANADATE +IAU_TIME: $ANATIME + +# This is presently set the same file as the old makeiau.x did +# NOTE: the internal_rst of this program provides +# the import to GEOSgcm.x, therefore its name +# ------------------------------------------------------------ +AGCM_INTERNAL_CHECKPOINT_FILE: ${AGCMIMPRST} +AGCM_INTERNAL_CHECKPOINT_TYPE: pnc4 + +#WRITE_AGCM_INTERNAL_FILE: agcm_interal_rst + +ANALYZE_TS: 1 +REPLAY_BKG: $BKGFNAME +REPLAY_FILE: $ANAFNAME +REPLAY_DAMPBEG: 0 +REPLAY_DAMPEND: 0 +REPLAY_OFFLINE: 1 +REPLAY_REMAP: YES +REPLAY_WINDFIX: NO +# Following allows zero-out of q-tendency (careful) +#NO_DQVDT: 1 + diff --git a/src/Applications/GEOSdas_App/swell/etc/swell_config.csh b/src/Applications/GEOSdas_App/swell/etc/swell_config.csh new file mode 100644 index 00000000..7843c36a --- /dev/null +++ b/src/Applications/GEOSdas_App/swell/etc/swell_config.csh @@ -0,0 +1,136 @@ +#!/bin/csh +# +# swell_config.csh - settings of the swell layer of GEOS-ADAS (GEOSJEDI=2) +# +# Read by swell_env.csh and the swell_*.csh scripts. Search order for this file: +# $SWELL_CONFIG (if set) +# $FVHOME/run/swell/swell_config.csh (experiment copy, identical to the installed one) +# $FVROOT/etc/swell/swell_config.csh (installed) +# +# The settings of an experiment are not in this file: fvsetup writes them to +# $FVHOME/run/swell/swell_exp.csh (swell_setup.pl -set KEY=VALUE), read first below. +# Precedence: environment > swell_exp.csh > the defaults in this file. +# --------------------------------------------------------------------------- + +# experiment settings, written by fvsetup (swell_setup.pl) +if ( $?FVHOME ) then + if ( -e $FVHOME/run/swell/swell_exp.csh ) source $FVHOME/run/swell/swell_exp.csh +endif + +# Required, no defaults (swell_exp.csh; checked by swell_env.csh): +# SWELL_VENV python venv with swell installed (fvsetup prompt: swell venv) +# SWELL_SRC swell source tree (fvsetup prompt: swell source directory) +# SWELL_JEDI_BUILD JEDI build used by swell (fvsetup prompt: JEDI build directory) +# SWELL_JEDI_SRC JEDI source of that build (from the build's CMakeCache.txt) +# SWELL_STATIC_FILES JEDI static files (fvsetup -jedistatic DIR) + +# Expected swell commit (full or abbreviated hash). Empty string disables the check. +# SWELL_COMMIT_STRICT=1 aborts on mismatch; 0 only warns. +# The swell commit check is commented out here and in swell_env.csh (swell changes often). +#if ( ! $?SWELL_COMMIT ) setenv SWELL_COMMIT "" +#if ( ! $?SWELL_COMMIT_STRICT ) setenv SWELL_COMMIT_STRICT 1 + +# JEDI executables run by this layer itself (EDA member increments, fv3jedi_diffstates.x): +# run-time modules (csh, sourced in a subshell) and MPI launcher +if ( ! $?SWELL_JEDI_MODULES ) then + if ( $?SWELL_JEDI_BUILD ) then + setenv SWELL_JEDI_MODULES $SWELL_JEDI_BUILD/modules + endif +endif +if ( ! $?SWELL_JEDI_MPIRUN ) setenv SWELL_JEDI_MPIRUN mpirun + +# CRTM coefficients +if ( ! $?SWELL_CRTM_COEFFS ) then + if ( $?FVHOME ) then + setenv SWELL_CRTM_COEFFS $FVHOME/fvInput/gsi/etc/JEDI-CRTM-2.4.1j1-GMAO-1/Little_Endian/ + endif +endif + +# swell platform and workflow behavior +if ( ! $?SWELL_PLATFORM ) setenv SWELL_PLATFORM nccs_discover_sles15 +if ( ! $?SWELL_TIMEOUT ) setenv SWELL_TIMEOUT PT5M # cylc stall timeout after a task failure +if ( ! $?SWELL_KEEP_CYLC_RUN ) setenv SWELL_KEEP_CYLC_RUN 0 # 1: keep ~/cylc-run/-suite after success + +# slurm settings for swell tasks that run as batch jobs +if ( ! $?SWELL_SLURM_ACCOUNT ) then + if ( $?GID ) then + setenv SWELL_SLURM_ACCOUNT $GID + endif +endif +if ( ! $?SWELL_SLURM_QOS ) setenv SWELL_SLURM_QOS allnccs +if ( ! $?SWELL_SLURM_CONSTRAINT ) setenv SWELL_SLURM_CONSTRAINT mil + +# --------------------------------------------------------------------------- +# Central analysis (GEOSJEDI=2: GEOSdas.csm runs swell_driver.csh; suite 3dfgat_atmos) +# --------------------------------------------------------------------------- +# Observations: converted from the GSI ncdiags of the cycle (default), or taken from +# an IODA archive //geos_atmosphere (e.g. when SKIPGSI) +if ( ! $?SWELL_OFFLINE_IODA_DIR ) setenv SWELL_OFFLINE_IODA_DIR "" + +if ( ! $?SWELL_FEEDBACK_VARBC ) setenv SWELL_FEEDBACK_VARBC 1 # cycle JEDI VarBC (else GSI biases) +if ( ! $?SWELL_MKIAU ) setenv SWELL_MKIAU 1 # make the JEDI IAU forcing +# SWELL_IAU_OVERWRITE=1: the JEDI IAU forcing drives the GCM. GEOSdas.csm (CoupleAnaToGcm_) reads +# it here too: with DO4DIAU=1 GSI then makes no IAU, and swell_upd4geos.csh provides agcm09/ana09 +# and the central analysis of the ensemble. 0: JEDI runs alongside, the GCM keeps the GSI IAU. +if ( ! $?SWELL_IAU_OVERWRITE ) setenv SWELL_IAU_OVERWRITE 1 # GEOS uses it instead of the GSI IAU +if ( ! $?SWELL_MKIAU_MPIRUN ) setenv SWELL_MKIAU_MPIRUN mpirun + +# SWELL_CENTRAL_CRES (swell_exp.csh): cubed-sphere resolution of the JEDI backgrounds +# as npx (C90 -> 91, ...). Processor layout and GSIBEC grid follow from it (see +# swell_ana_central.csh). + +if ( ! $?SWELL_GSIBEC_VERSION ) setenv SWELL_GSIBEC_VERSION 1.0.2 # $SWELL_STATIC_FILES/.../gsibec/ +if ( ! $?SWELL_VAR_NITER ) setenv SWELL_VAR_NITER 100 # inner iterations +if ( ! $?SWELL_VAR_BKG_FREQ ) setenv SWELL_VAR_BKG_FREQ PT3H # FGAT background frequency +if ( ! $?SWELL_CENTRAL_WALLTIME ) setenv SWELL_CENTRAL_WALLTIME 00:40:00 + +# Where GEOS keeps /rs/Y%Y/M%m/.bkgcrst..tar: the archive of +# the experiment ($FVARCH from FVDAS_Run_Config, else $ARCHIVE) +if ( ! $?SWELL_BKG_ARCHIVE ) then + if ( $?FVARCH ) then + setenv SWELL_BKG_ARCHIVE $FVARCH + else if ( $?ARCHIVE ) then + setenv SWELL_BKG_ARCHIVE $ARCHIVE + endif +endif + +# GMAO observing system database (gmao_satinfo.db, gmao_ozinfo.db) +if ( ! $?SWELL_MKSI_PATH ) then + if ( $?FVROOT ) then + setenv SWELL_MKSI_PATH $FVROOT/etc/ + endif +endif + +# Persistent copy of the latest JEDI VarBC output, used by the next cycle +# when SWELL_FEEDBACK_VARBC=1 (bootstrap from the GSI biases when empty) +if ( ! $?SWELL_VARBC_DIR ) then + if ( $?FVHOME ) then + setenv SWELL_VARBC_DIR $FVHOME/swell/varbc + endif +endif + +# Observations and biases used by the central analysis, per cycle, read by the +# ensemble analysis of the same cycle (latest SWELL_OBS_SHARE_KEEP cycles kept) +if ( ! $?SWELL_OBS_SHARE ) then + if ( $?FVHOME ) then + setenv SWELL_OBS_SHARE $FVHOME/swell/obs + endif +endif +if ( ! $?SWELL_OBS_SHARE_KEEP ) setenv SWELL_OBS_SHARE_KEEP 4 + +# --------------------------------------------------------------------------- +# Ensemble analysis (GEOSJEDI=2: atm_ens.j runs swell_ana_atmens.csh) +# --------------------------------------------------------------------------- +# none: GSI EnKF; eda: eda_atmos; getkf: localensembleda; +# getkf2: localensembleda_2steps +if ( ! $?SWELL_ENSEMBLE ) setenv SWELL_ENSEMBLE none + +# SWELL_ENS_CRES (swell_exp.csh): cubed-sphere resolution of the ensemble backgrounds +# as npx (C90 -> 91, C180 -> 181). Layout and GSIBEC grid follow from it (see +# swell_ana_atmens.csh). SWELL_ENS_NMEM (swell_exp.csh): number of members. + +if ( ! $?SWELL_ENS_NITER ) setenv SWELL_ENS_NITER 50 # EDA inner iterations +if ( ! $?SWELL_ENS_OBS_PERT ) setenv SWELL_ENS_OBS_PERT 0.5 # EDA obs perturbation amplitude +if ( ! $?SWELL_ENS_WALLTIME ) setenv SWELL_ENS_WALLTIME 00:40:00 +# Obs thinning rejection fraction; default 0.8 (eda) / 0.75 (getkf), as in jedi_eda/getkf.yaml +#if ( ! $?SWELL_ENS_THIN ) setenv SWELL_ENS_THIN 0.8 diff --git a/src/Applications/GEOSdas_App/swell/swell_ana_atmens.csh b/src/Applications/GEOSdas_App/swell/swell_ana_atmens.csh new file mode 100644 index 00000000..21c8b9df --- /dev/null +++ b/src/Applications/GEOSdas_App/swell/swell_ana_atmens.csh @@ -0,0 +1,272 @@ +#!/bin/csh -f +# +# swell_ana_atmens.csh - ADAS ensemble analysis (EDA or GETKF) with swell +# +# usage: swell_ana_atmens.csh nymdb nhmsb nymda nhmsa +# +# nymdb nhmsb beginning of the analysis window +# nymda nhmsa analysis time (middle of the window) +# +# Replaces jedi_driver_atmens.csh. Method from SWELL_ENSEMBLE, and the lat-lon member +# increments (analysis/memNNN/.inc.eta..nc4) it gives: +# eda swell eda_atmos made here: analysis - background (fv3jedi_diffstates.x), +# since swell writes the member analyses +# (eda_atmos.ana.ceta..nc4) on the cubed sphere only +# getkf swell localensembleda written by swell (posterior member increments) +# getkf2 swell localensembleda_2steps written by swell (posterior member increments) +# +# Inputs: +# $SWELL_OBS_SHARE//geos_atmosphere observations + biases of the central analysis +# (written by swell_ana_central.csh) +# $ATMENSLOC/ensbkgx/memNNN/*.bkg_clcv.* cubed member backgrounds (read in place) +# $ATMENSLOC/memNNN/$EXPID.bkg.eta.* lat-lon member backgrounds +# Outputs (what post_eana.csh / atmos_ens2gcm.csh expect): +# $FVWORK/updated_ens/memNNN/$EXPID.ana.eta.z.nc4 (dyn_jediupd.x: bkg + inc) +# $FVWORK/updated_ens/{ensmean,ensrms}/ (filled by post_eana.csh) +# $FVWORK/updated_ens/$EXPID.atmens_olog.z.tar.gz (swell/JEDI logs) +# +# Resolution: SWELL_ENS_CRES (npx: 13, 25, 91, 181) selects the processor layout and +# GSIBEC grid; any SWELL_ENS_{NPX,NPY,PERHOST,GSIBEC_NLATS,GSIBEC_NLONS} already set wins. +# --------------------------------------------------------------------------- + +set myname = swell_ana_atmens.csh + +if ( $#argv < 4 ) then + echo "usage: $myname nymdb nhmsb nymda nhmsa" + exit 1 +endif + +set nymdb = $1 +set nhmsb = `echo $2 | awk '{printf "%06d", $1}'` +set nymda = $3 +set nhmsa = `echo $4 | awk '{printf "%06d", $1}'` +set hhb = `echo $nhmsb | cut -c1-2` +set hha = `echo $nhmsa | cut -c1-2` +set hhmma = `echo $nhmsa | cut -c1-4` +set yyyymmddhh = ${nymda}${hha} + +if ( ! $?EXPID || ! $?FVHOME || ! $?FVWORK ) then + echo "${myname}: EXPID, FVHOME and FVWORK must be defined, aborting" + exit 1 +endif +if ( ! $?ATMENSLOC ) setenv ATMENSLOC $FVHOME/atmens + +set donefile = $FVWORK/.DONE_${myname}.$yyyymmddhh +if ( -e $donefile ) then + echo "${myname}: already done" + exit 0 +endif + +set mydir = `dirname $0` +set mydir = `cd $mydir && pwd` + +# installed layout ($FVROOT/bin + $FVROOT/etc/swell) or source tree (swell/ + swell/etc) +set etcdir = $mydir/etc +if ( -d $mydir/../etc/swell ) set etcdir = `cd $mydir/../etc/swell && pwd` +setenv SWELL_ETC_FALLBACK $etcdir + +source $mydir/swell_env.csh +if ( ! $SWELL_ENV_OK ) then + echo "${myname}: swell environment setup failed, aborting" + exit 1 +endif +foreach v ( SWELL_ENS_CRES SWELL_OBS_SHARE SWELL_MKSI_PATH SWELL_SLURM_ACCOUNT ) + printenv $v >& /dev/null + if ( $status ) then + echo "${myname}: $v is not set (see swell_config.csh), aborting" + exit 1 + endif +end + +# --- method ---------------------------------------------------------------- +switch ( $SWELL_ENSEMBLE ) + case eda: + set suite = eda_atmos + set tmpl = atmens_eda.yaml.tmpl + set thin = 0.8 + breaksw + case getkf: + set suite = localensembleda + set tmpl = atmens_getkf.yaml.tmpl + set thin = 0.75 + breaksw + case getkf2: + set suite = localensembleda_2steps + set tmpl = atmens_getkf2.yaml.tmpl + set thin = 0.75 + breaksw + default: + echo "${myname}: SWELL_ENSEMBLE=$SWELL_ENSEMBLE is not one of eda, getkf, getkf2, aborting" + exit 1 +endsw +if ( ! $?SWELL_ENS_THIN ) setenv SWELL_ENS_THIN $thin + +# EDA member increments are computed here with JEDI (see "member analyses" below) +if ( $SWELL_ENSEMBLE == eda ) then + if ( ! $?SWELL_JEDI_MODULES ) setenv SWELL_JEDI_MODULES $SWELL_JEDI_BUILD/modules + if ( ! $?SWELL_JEDI_MPIRUN ) setenv SWELL_JEDI_MPIRUN mpirun + if ( ! $?MODULESHOME ) setenv MODULESHOME /usr/share/lmod/lmod + if ( ! -e $SWELL_JEDI_MODULES ) then + echo "${myname}: JEDI run-time modules SWELL_JEDI_MODULES=$SWELL_JEDI_MODULES not found, aborting" + exit 1 + endif +endif + +# --- layout from resolution (as in setup_aanajedi.pl set_ens_res) ----------- +switch ( $SWELL_ENS_CRES ) + case 13: + set lay = ( 2 2 24 46 72 ) + breaksw + case 25: + set lay = ( 4 4 96 46 72 ) + breaksw + case 91: + set lay = ( 4 5 120 91 144 ) + breaksw + case 181: + set lay = ( 6 6 108 181 288 ) + breaksw + default: + echo "${myname}: no layout for SWELL_ENS_CRES=$SWELL_ENS_CRES, aborting" + exit 1 +endsw +if ( ! $?SWELL_ENS_NPX ) setenv SWELL_ENS_NPX $lay[1] +if ( ! $?SWELL_ENS_NPY ) setenv SWELL_ENS_NPY $lay[2] +if ( ! $?SWELL_ENS_PERHOST ) setenv SWELL_ENS_PERHOST $lay[3] +if ( ! $?SWELL_ENS_GSIBEC_NLATS ) setenv SWELL_ENS_GSIBEC_NLATS $lay[4] +if ( ! $?SWELL_ENS_GSIBEC_NLONS ) setenv SWELL_ENS_GSIBEC_NLONS $lay[5] +@ ntasks = 6 * $SWELL_ENS_NPX * $SWELL_ENS_NPY +@ nodes = ( $ntasks + $SWELL_ENS_PERHOST - 1 ) / $SWELL_ENS_PERHOST +setenv SWELL_ENS_NODES $nodes + +# --- members --------------------------------------------------------------- +set members = ( `find -H $ATMENSLOC -maxdepth 1 -name "mem[0-9][0-9][0-9]" | sort | xargs -n1 basename` ) +if ( $#members == 0 ) then + echo "${myname}: no member directories in $ATMENSLOC, aborting" + exit 1 +endif +setenv SWELL_ENS_NMEM $#members +echo "${myname}: $SWELL_ENSEMBLE ($suite), $#members members, C$SWELL_ENS_CRES layout ${SWELL_ENS_NPX}x${SWELL_ENS_NPY}x6 = $ntasks tasks on $nodes node(s)" + +foreach m ( $members ) + if ( ! -e $ATMENSLOC/$m/$EXPID.bkg.eta.${nymda}_${hhmma}z.nc4 ) then + echo "${myname}: missing $ATMENSLOC/$m/$EXPID.bkg.eta.${nymda}_${hhmma}z.nc4, aborting" + exit 1 + endif + if ( ! -e $ATMENSLOC/ensbkgx/$m/$EXPID.bkg_clcv.${nymda}_${hhmma}z.nc4 ) then + echo "${myname}: missing $ATMENSLOC/ensbkgx/$m/$EXPID.bkg_clcv.${nymda}_${hhmma}z.nc4, aborting" + exit 1 + endif +end + +# --- observations: those of the central analysis of this cycle ------------- +set obsdir = $SWELL_OBS_SHARE/${nymda}T${nhmsa}Z/geos_atmosphere +set nobs = `find -H $obsdir -maxdepth 1 -type f |& grep -c "^$obsdir/"` +if ( $nobs == 0 ) then + echo "${myname}: no observations in $obsdir; the central analysis must run" + echo "${myname}: through swell (swell_ana_central.csh) before the ensemble, aborting" + exit 1 +endif + +# --- backgrounds: present $ATMENSLOC under the archive layout swell expects -- +setenv JEDIWORK $FVWORK/jedi.${nymda}.${nhmsa} +mkdir -p $JEDIWORK +setenv SWELL_ENS_ROOT $JEDIWORK/swell_ens +set yyyyb = `echo $nymdb | cut -c1-4` +set mmb = `echo $nymdb | cut -c5-6` +set ensdir = $SWELL_ENS_ROOT/$EXPID/atmens/Y$yyyyb/M$mmb +/bin/rm -rf $SWELL_ENS_ROOT +mkdir -p $ensdir +ln -s $ATMENSLOC $ensdir/$EXPID.atmens_ebkgx.${nymdb}_${hhb}z + +# --- run swell ------------------------------------------------------------- +set expid = ${EXPID}-ens-$yyyymmddhh +setenv SWELL_SLURM_TEMPLATE atmens_slurm.yaml.tmpl +$mydir/swell_run.csh $suite $tmpl $JEDIWORK $expid $nymda $nhmsa +if ( $status ) then + echo "${myname}: swell $suite failed, aborting" + exit 1 +endif +set cycdir = $JEDIWORK/$expid/run/${nymda}T${nhmsa}Z/geos_atmosphere + +# --- member analyses: lat-lon background + lat-lon increment --------------- +# EDA: increment = cubed analysis - cubed background, written on the lat-lon grid by +# fv3jedi_diffstates.x (layout 1x1: 6 tasks) in a subshell with the JEDI run-time +# modules, so the ADAS environment of dyn_jediupd.x is left untouched +if ( $SWELL_ENSEMBLE == eda ) then + set yyyya = `echo $nymda | cut -c1-4` + set mma = `echo $nymda | cut -c5-6` + set dda = `echo $nymda | cut -c7-8` + set mna = `echo $nhmsa | cut -c3-4` + set ssa = `echo $nhmsa | cut -c5-6` + setenv SWELL_DIFF_DATE "${yyyya}-${mma}-${dda}T${hha}:${mna}:${ssa}Z" + # relative to the member directory: FMS cuts file names at 128 characters + setenv SWELL_DIFF_FV3FILES ../../fv3-jedi/fv3files + setenv SWELL_DIFF_OUTPUT ${suite}.inc.eta. + if ( ! -d $cycdir/fv3-jedi/fv3files ) then + echo "${myname}: $cycdir/fv3-jedi/fv3files not found, aborting" + exit 1 + endif +endif +mkdir -p $FVWORK/updated_ens/ensmean $FVWORK/updated_ens/ensrms +foreach m ( $members ) + set mdir = $cycdir/analysis/$m + if ( $SWELL_ENSEMBLE == eda ) then + setenv SWELL_DIFF_ANA_DIR $mdir + setenv SWELL_DIFF_ANA_FILE ${suite}.ana.ceta.${nymda}_${nhmsa}z.nc4 + setenv SWELL_DIFF_BKG_DIR $ATMENSLOC/ensbkgx/$m + setenv SWELL_DIFF_BKG_FILE $EXPID.bkg_clcv.${nymda}_${hhmma}z.nc4 + if ( ! -e $mdir/$SWELL_DIFF_ANA_FILE ) then + echo "${myname}: missing $mdir/$SWELL_DIFF_ANA_FILE, aborting" + exit 1 + endif + set dtmpl = `$mydir/swell_render.csh atmens_diffstates.yaml.tmpl $mdir/diffstates.yaml` + if ( $status ) then + echo "$dtmpl" + echo "${myname}: cannot prepare $mdir/diffstates.yaml, aborting" + exit 1 + endif + cd $mdir + ( source $MODULESHOME/init/csh; source $SWELL_JEDI_MODULES; \ + $SWELL_JEDI_MPIRUN -np 6 $SWELL_JEDI_BUILD/bin/fv3jedi_diffstates.x diffstates.yaml ) >& diffstates.log + if ( $status ) then + tail -20 diffstates.log + echo "${myname}: fv3jedi_diffstates.x failed for $m (log $mdir/diffstates.log), aborting" + exit 1 + endif + endif + set incs = ( `find -H $mdir -maxdepth 1 -name "${suite}.inc.eta.*.nc4"` ) + if ( $#incs != 1 ) then + echo "${myname}: expected one increment for $m in $mdir, found $#incs, aborting" + exit 1 + endif + set inc = $incs[1] + set itag = `basename $inc .nc4 | awk -F. '{print $NF}'` + if ( "$itag" != "${nymda}_${nhmsa}z" ) then + echo "${myname}: WARNING: $m increment valid at $itag, used at ${nymda}_${nhmsa}z" + endif + + set bkg = $ATMENSLOC/$m/$EXPID.bkg.eta.${nymda}_${hhmma}z.nc4 + set outdir = $FVWORK/updated_ens/$m + set ana = $outdir/$EXPID.ana.eta.${nymda}_${hhmma}z.nc4 + mkdir -p $outdir + /bin/rm -f $ana + dyn_jediupd.x $nymda $nhmsa $bkg $inc $ana >& $cycdir/analysis/$m/dyn_jediupd.log + if ( $status || ! -e $ana ) then + cat $cycdir/analysis/$m/dyn_jediupd.log + echo "${myname}: dyn_jediupd.x failed for $m, aborting" + exit 1 + endif +end +echo "${myname}: $#members member analyses in $FVWORK/updated_ens/mem*" + +# --- logs ------------------------------------------------------------------ +cd $JEDIWORK +set logs = ( `find -H $expid -name "*log*" -type f` ) +if ( $#logs > 0 ) then + tar czf $FVWORK/updated_ens/$EXPID.atmens_olog.${nymda}_${hha}z.tar.gz $logs +endif + +touch $donefile +echo "${myname}: Complete" +exit 0 diff --git a/src/Applications/GEOSdas_App/swell/swell_ana_central.csh b/src/Applications/GEOSdas_App/swell/swell_ana_central.csh new file mode 100644 index 00000000..7c97d25a --- /dev/null +++ b/src/Applications/GEOSdas_App/swell/swell_ana_central.csh @@ -0,0 +1,247 @@ +#!/bin/csh -f +# +# swell_ana_central.csh - ADAS central analysis (3D-FGAT, climatological B) with swell +# +# usage: swell_ana_central.csh nymdb nhmsb nymda nhmsa +# +# nymdb nhmsb beginning of the analysis window +# nymda nhmsa analysis time (middle of the window) +# +# Run by swell_driver.csh. On success $JEDIWORK=$FVWORK/jedi.. +# holds what swell_mkiau.csh and the archiving expect: +# inc/$EXPID.jedi_inc1.eta.z.nc4 lat-lon increment (window begin for FGAT) +# ana/$EXPID.jedi_ana.ceta.z.nc4 cubed analysis at the analysis time +# bkg/ iau/ (filled by swell_mkiau.csh) +# and in $FVWORK: +# $EXPID.jedi_hofx..tar observation feedback, named ..nc4 +# $EXPID.jedi_vbc..tar VarBC output at the window begin (+ tlapse, acftbias_cov) +# $EXPID.jedi_var.log..txt JEDI log +# $EXPID.jedi_cfg.log..txt JEDI configuration (yaml) +# +# Inputs: +# $FVWORK/ioda._0000 IODA obs and GSI-converted biases (swell_gsi2ioda.csh) +# $SWELL_BKG_ARCHIVE/$EXPID/rs/Y%Y/M%m/$EXPID.bkgcrst..tar cubed backgrounds +# $SWELL_VARBC_DIR previous JEDI VarBC (used if SWELL_FEEDBACK_VARBC=1) +# +# Also writes $SWELL_OBS_SHARE//geos_atmosphere (copy of the observations and biases +# used here) for swell_ana_atmens.csh; the latest SWELL_OBS_SHARE_KEEP cycles are kept. +# +# Resolution: SWELL_CENTRAL_CRES (npx: 13, 25, 91, 181, 361, 721) selects the processor +# layout and GSIBEC grid; any SWELL_CENTRAL_{NPX,NPY,PERHOST,GSIBEC_NLATS,GSIBEC_NLONS} +# already in the environment wins. +# --------------------------------------------------------------------------- + +set myname = swell_ana_central.csh + +if ( $#argv < 4 ) then + echo "usage: $myname nymdb nhmsb nymda nhmsa" + exit 1 +endif + +set nymdb = $1 +set nhmsb = `echo $2 | awk '{printf "%06d", $1}'` +set nymda = $3 +set nhmsa = `echo $4 | awk '{printf "%06d", $1}'` +set hhb = `echo $nhmsb | cut -c1-2` +set hha = `echo $nhmsa | cut -c1-2` +set yyyymmddhh = ${nymda}${hha} + +if ( ! $?EXPID || ! $?FVHOME || ! $?FVWORK ) then + echo "${myname}: EXPID, FVHOME and FVWORK must be defined, aborting" + exit 1 +endif +if ( ! $?TIMEINC ) setenv TIMEINC 360 + +set donefile = $FVWORK/.DONE_${myname}.$yyyymmddhh +if ( -e $donefile ) then + echo "${myname}: already done" + exit 0 +endif + +set mydir = `dirname $0` +set mydir = `cd $mydir && pwd` + +# swell_config.csh provides the central settings (pins are re-checked by swell_run.csh) +source $mydir/swell_env.csh +if ( ! $SWELL_ENV_OK ) then + echo "${myname}: swell environment setup failed, aborting" + exit 1 +endif +foreach v ( SWELL_CENTRAL_CRES SWELL_BKG_ARCHIVE SWELL_MKSI_PATH SWELL_VARBC_DIR SWELL_SLURM_ACCOUNT ) + printenv $v >& /dev/null + if ( $status ) then + echo "${myname}: $v is not set (see swell_config.csh), aborting" + exit 1 + endif +end + +# --- layout from resolution (as in setup_aanajedi.pl for 3D schemes) ------- +switch ( $SWELL_CENTRAL_CRES ) + case 13: + set lay = ( 2 2 24 46 72 ) + breaksw + case 25: + set lay = ( 4 4 96 46 72 ) + breaksw + case 91: + set lay = ( 6 6 12 91 144 ) + breaksw + case 181: + set lay = ( 8 8 16 361 576 ) + breaksw + case 361: + set lay = ( 10 10 16 361 576 ) + breaksw + case 721: + set lay = ( 10 10 16 721 1152 ) + breaksw + default: + echo "${myname}: no layout for SWELL_CENTRAL_CRES=$SWELL_CENTRAL_CRES, aborting" + exit 1 +endsw +if ( ! $?SWELL_CENTRAL_NPX ) setenv SWELL_CENTRAL_NPX $lay[1] +if ( ! $?SWELL_CENTRAL_NPY ) setenv SWELL_CENTRAL_NPY $lay[2] +if ( ! $?SWELL_CENTRAL_PERHOST ) setenv SWELL_CENTRAL_PERHOST $lay[3] +if ( ! $?SWELL_CENTRAL_GSIBEC_NLATS ) setenv SWELL_CENTRAL_GSIBEC_NLATS $lay[4] +if ( ! $?SWELL_CENTRAL_GSIBEC_NLONS ) setenv SWELL_CENTRAL_GSIBEC_NLONS $lay[5] +@ ntasks = 6 * $SWELL_CENTRAL_NPX * $SWELL_CENTRAL_NPY +@ nodes = ( $ntasks + $SWELL_CENTRAL_PERHOST - 1 ) / $SWELL_CENTRAL_PERHOST +setenv SWELL_CENTRAL_NODES $nodes +echo "${myname}: C$SWELL_CENTRAL_CRES layout ${SWELL_CENTRAL_NPX}x${SWELL_CENTRAL_NPY}x6 = $ntasks tasks on $nodes node(s)" + +# --- time tags ------------------------------------------------------------- +# btag: window begin (VarBC output); ptag: previous window begin = background time +@ dtsec = $TIMEINC * 60 +set pdate = ( `tick $nymdb $nhmsb -$dtsec` ) +if ( $#pdate != 2 ) then + echo "${myname}: tick failed, aborting" + exit 1 +endif +set hhp = `echo $pdate[2] | awk '{printf "%06d", $1}' | cut -c1-2` +set btag = ${nymdb}T${hhb}0000Z +set ptag = $pdate[1]T${hhp}0000Z + +setenv JEDIWORK $FVWORK/jedi.${nymda}.${nhmsa} +mkdir -p $JEDIWORK +cd $JEDIWORK +foreach d ( ana bkg inc iau hofx vbc ) + if ( -d $d ) /bin/rm -rf $d + mkdir $d +end + +# --- backgrounds: fail early if the tar swell will read is missing --------- +set yyyyp = `echo $pdate[1] | cut -c1-4` +set mmp = `echo $pdate[1] | cut -c5-6` +set bkgtar = $SWELL_BKG_ARCHIVE/$EXPID/rs/Y$yyyyp/M$mmp/$EXPID.bkgcrst.$pdate[1]_${hhp}z.tar +if ( ! -e $bkgtar ) then + echo "${myname}: background archive $bkgtar not found, aborting" + exit 1 +endif + +# --- observations and bias correction (swell_obs_stage.csh) ---------------- +setenv SWELL_IODA_DIR $JEDIWORK/swell_obs +set obsdir = $SWELL_IODA_DIR/${nymda}T${nhmsa}Z/geos_atmosphere +/bin/rm -rf $SWELL_IODA_DIR +$mydir/swell_obs_stage.csh $nymdb $nhmsb $nymda $nhmsa $obsdir +if ( $status ) then + echo "${myname}: swell_obs_stage.csh failed, aborting" + exit 1 +endif +cd $JEDIWORK + +# --- run swell ------------------------------------------------------------- +set expid = ${EXPID}-ana-$yyyymmddhh +setenv SWELL_SLURM_TEMPLATE central_slurm.yaml.tmpl +$mydir/swell_run.csh 3dfgat_atmos central_3dfgat.yaml.tmpl $JEDIWORK $expid $nymda $nhmsa +if ( $status ) then + echo "${myname}: swell 3dfgat_atmos failed, aborting" + exit 1 +endif +set cycdir = $JEDIWORK/$expid/run/${nymda}T${nhmsa}Z/geos_atmosphere + +# --- JEDI log -------------------------------------------------------------- +set varlog = $cycdir/jedi_variational_log.log +if ( ! -e $varlog ) then + echo "${myname}: $varlog not found, aborting" + exit 1 +endif +/bin/cp $varlog $FVWORK/$EXPID.jedi_var.log.${nymdb}_${hhb}z.txt +set nnan = `grep -c NaN $varlog` +if ( $nnan > 0 ) then + echo "${myname}: NaNs in the JEDI log, aborting" + exit 1 +endif +grep "Quadratic cost function: J " $varlog | head -1 +grep "Quadratic cost function: J " $varlog | tail -1 + +# --- increment and analysis ------------------------------------------------ +set incs = ( `find -H $cycdir -maxdepth 1 -type f -name "${expid}.increment-iter1.*.nc4"` ) +if ( $#incs == 0 ) then + echo "${myname}: no increment ${expid}.increment-iter1.*.nc4 in $cycdir, aborting" + exit 1 +endif +foreach f ( $incs ) + set ttag = `basename $f .nc4 | sed "s/^${expid}\.increment-iter1\.//"` + /bin/mv $f inc/$EXPID.jedi_inc1.eta.${ttag}.nc4 +end + +set anafn = $cycdir/${expid}.analysis.${nymda}_${nhmsa}z.nc4 +if ( -e $anafn ) then + /bin/mv $anafn ana/$EXPID.jedi_ana.ceta.${nymda}_${hha}`echo $nhmsa | cut -c3-4`z.nc4 +else + echo "${myname}: WARNING: no cubed analysis at the analysis time in $cycdir" +endif + +# --- observation feedback -------------------------------------------------- +foreach f ( `find -H $cycdir -maxdepth 1 -type f -name "${expid}.*.${btag}.nc4"` ) + set obsname = `basename $f | sed "s/^${expid}\.//"` + /bin/mv $f hofx/$obsname +end +cd hofx +set nhofx = `find -H . -maxdepth 1 -name "*.nc4" | wc -l` +if ( $nhofx > 0 ) then + tar cf $FVWORK/$EXPID.jedi_hofx.${nymdb}_${hhb}z.tar *.nc4 +endif +cd $JEDIWORK +echo "${myname}: $nhofx observation feedback file(s)" + +# --- inputs for the ensemble analysis of this cycle ------------------------ +# The observations and bias correction this analysis used; done before the VarBC +# directory is refreshed below, since some of the inputs are links into it. +$mydir/swell_obs_share.csh $nymda $nhmsa $obsdir +if ( $status ) then + echo "${myname}: swell_obs_share.csh failed, aborting" + exit 1 +endif + +# --- VarBC output for the next cycle --------------------------------------- +foreach f ( `find -H $cycdir -maxdepth 1 -type f \( -name "*.${btag}.satbias.nc4" -o -name "*.${btag}.satbias_cov.nc4" -o -name "*.${btag}.acftbias" -o -name "*.${btag}.acftbias_cov" \)` ) + /bin/mv $f vbc/ +end +# JEDI writes no acftbias covariance and no tlapse: carry the inputs forward +if ( -e vbc/aircraft_temperature.${btag}.acftbias && ! -e vbc/aircraft_temperature.${btag}.acftbias_cov ) then + if ( -e $obsdir/aircraft_temperature.${ptag}.acftbias_cov ) then + /bin/cp -L $obsdir/aircraft_temperature.${ptag}.acftbias_cov vbc/aircraft_temperature.${btag}.acftbias_cov + endif +endif +foreach f ( `find -H $obsdir -maxdepth 1 -name "*.${ptag}.tlapse.txt"` ) + set sensor = `basename $f | cut -d. -f1` + /bin/cp -L $f vbc/$sensor.${btag}.tlapse.txt +end +cd vbc +set nvbc = `find -H . -maxdepth 1 -type f | wc -l` +if ( $nvbc > 0 ) then + tar cf $FVWORK/$EXPID.jedi_vbc.${nymdb}_${hhb}z.tar * + mkdir -p $SWELL_VARBC_DIR + find -H $SWELL_VARBC_DIR -maxdepth 1 -type f -delete + /bin/cp -p * $SWELL_VARBC_DIR/ +endif +cd $JEDIWORK +echo "${myname}: $nvbc VarBC file(s) saved for the next cycle in $SWELL_VARBC_DIR" + +# --- record of the JEDI configuration (archived with the JEDI logs) -------- +/bin/cp $cycdir/jedi_variational_config.yaml $FVWORK/$EXPID.jedi_cfg.log.${nymdb}_${hhb}z.txt + +touch $donefile +echo "${myname}: Complete" +exit 0 diff --git a/src/Applications/GEOSdas_App/swell/swell_driver.csh b/src/Applications/GEOSdas_App/swell/swell_driver.csh new file mode 100644 index 00000000..c3a85bed --- /dev/null +++ b/src/Applications/GEOSdas_App/swell/swell_driver.csh @@ -0,0 +1,158 @@ +#!/bin/csh -f +# +# swell_driver.csh - central JEDI analysis of one ADAS cycle through swell +# +# usage: swell_driver.csh nymdb nhmsb nymda nhmsa [obsonly] +# +# nymdb nhmsb beginning of the analysis window +# nymda nhmsa analysis time +# obsonly only step 1 and the observations for the ensemble analysis +# ($SWELL_OBS_SHARE, swell_obs_stage.csh + swell_obs_share.csh); used on +# the first cycle (AGCM.BOOTSTRAP), when no central JEDI analysis runs. +# Nothing is done when SWELL_ENSEMBLE=none. +# +# Called by GEOSdas.csm (JEDI_AnalysisRun_) when GEOSJEDI=2 (FVDAS_Run_Config). +# Steps (each one restartable through its .DONE file): +# 1. observations $FVWORK/ioda.: swell_gsi2ioda.csh (GSI ncdiags), or links to +# $SWELL_OFFLINE_IODA_DIR/T..Z/geos_atmosphere when that is set +# 2. analysis swell_ana_central.csh +# 3. IAU swell_mkiau.csh (SWELL_MKIAU=1) +# 4. use the IAU swell_upd4geos.csh (SWELL_IAU_OVERWRITE=1, forced when SKIPGSI; +# with DO4DIAU=1, GEOSdas.csm then makes no GSI IAU) +# Logs: $FVWORK/$EXPID.jedi_{g2i,run,miau,upd}.log.z.txt (archived as jedi/etc). +# --------------------------------------------------------------------------- + +set myname = swell_driver.csh + +if ( $#argv < 4 ) then + echo "usage: $myname nymdb nhmsb nymda nhmsa [obsonly]" + exit 1 +endif +set obsonly = 0 +if ( $#argv > 4 ) then + if ( "$5" == "obsonly" ) then + set obsonly = 1 + else + echo "${myname}: unknown option $5, aborting" + exit 1 + endif +endif + +set nymdb = $1 +set nhmsb = `echo $2 | awk '{printf "%06d", $1}'` +set nymda = $3 +set nhmsa = `echo $4 | awk '{printf "%06d", $1}'` +set hhb = `echo $nhmsb | cut -c1-2` +set hha = `echo $nhmsa | cut -c1-2` +set yyyymmddhh = ${nymda}${hha} + +if ( ! $?EXPID || ! $?FVHOME || ! $?FVWORK ) then + echo "${myname}: EXPID, FVHOME and FVWORK must be defined, aborting" + exit 1 +endif +if ( ! -e $FVHOME/run/swell/swell_config.csh ) then + echo "${myname}: $FVHOME/run/swell/swell_config.csh not found, aborting" + exit 1 +endif +source $FVHOME/run/swell/swell_config.csh + +set donefile = $FVWORK/.DONE_${myname}.$yyyymmddhh +if ( $obsonly ) then + set donefile = $FVWORK/.DONE_${myname}.obsonly.$yyyymmddhh + if ( "$SWELL_ENSEMBLE" == "none" ) then + echo "${myname}: obsonly: no swell ensemble (SWELL_ENSEMBLE=none), nothing to do" + touch $donefile + exit 0 + endif +endif +if ( -e $donefile ) then + echo "${myname}: already done" + exit 0 +endif + +set mydir = `dirname $0` +set mydir = `cd $mydir && pwd` +set logtag = ${nymdb}_${hhb}z +setenv JEDIWORK $FVWORK/jedi.${nymda}.${nhmsa} +mkdir -p $JEDIWORK + +# --- 1. observations ------------------------------------------------------- +set iodadir = $FVWORK/ioda.${nymda}_${hha}0000 +if ( "$SWELL_OFFLINE_IODA_DIR" != "" ) then + set src = $SWELL_OFFLINE_IODA_DIR/${nymda}T${nhmsa}Z/geos_atmosphere + set srcfiles = ( `find -H $src -maxdepth 1 \( -type f -o -type l \) |& grep "^$src/"` ) + if ( $#srcfiles == 0 ) then + echo "${myname}: no IODA files in $src, aborting" + exit 1 + endif + mkdir -p $iodadir + foreach f ( $srcfiles ) + ln -sf $f $iodadir/ + end + echo "${myname}: observations linked from $src" +else + $mydir/swell_gsi2ioda.csh $nymda $nhmsa $FVWORK $FVWORK $JEDIWORK |& tee -a $FVWORK/$EXPID.jedi_g2i.log.$logtag.txt + if ( $status || ! -e $FVWORK/.DONE_swell_gsi2ioda.csh.$yyyymmddhh ) then + echo "${myname}: swell_gsi2ioda.csh failed, aborting" + exit 1 + endif +endif + +# --- first cycle: only the observations for the ensemble analysis --------- +if ( $obsonly ) then + set obsdir = $JEDIWORK/swell_obs/${nymda}T${nhmsa}Z/geos_atmosphere + /bin/rm -rf $JEDIWORK/swell_obs + $mydir/swell_obs_stage.csh $nymdb $nhmsb $nymda $nhmsa $obsdir |& tee -a $FVWORK/$EXPID.jedi_g2i.log.$logtag.txt + if ( $status ) then + echo "${myname}: swell_obs_stage.csh failed, aborting" + exit 1 + endif + $mydir/swell_obs_share.csh $nymda $nhmsa $obsdir |& tee -a $FVWORK/$EXPID.jedi_g2i.log.$logtag.txt + if ( $status ) then + echo "${myname}: swell_obs_share.csh failed, aborting" + exit 1 + endif + touch $donefile + echo "${myname}: Complete (obsonly: observations for the ensemble analysis only)" + exit 0 +endif + +# --- 2. analysis ----------------------------------------------------------- +$mydir/swell_ana_central.csh $nymdb $nhmsb $nymda $nhmsa |& tee -a $FVWORK/$EXPID.jedi_run.log.$logtag.txt +if ( $status || ! -e $FVWORK/.DONE_swell_ana_central.csh.$yyyymmddhh ) then + echo "${myname}: swell_ana_central.csh failed, aborting" + exit 1 +endif + +# --- 3. IAU ---------------------------------------------------------------- +if ( $SWELL_MKIAU ) then + $mydir/swell_mkiau.csh $nymdb $nhmsb $nymda $nhmsa |& tee -a $FVWORK/$EXPID.jedi_miau.log.$logtag.txt + if ( $status || ! -e $FVWORK/.DONE_swell_mkiau.csh.$yyyymmddhh ) then + echo "${myname}: swell_mkiau.csh failed, aborting" + exit 1 + endif +endif + +# --- 4. GEOS uses the JEDI IAU --------------------------------------------- +set overwrite = $SWELL_IAU_OVERWRITE +if ( $?SKIPGSI ) then + if ( $SKIPGSI ) then + echo "${myname}: no GSI analysis (SKIPGSI): the JEDI IAU forcing is used" + set overwrite = 1 + endif +endif +if ( $overwrite ) then + if ( ! $SWELL_MKIAU ) then + echo "${myname}: SWELL_IAU_OVERWRITE requires SWELL_MKIAU=1, aborting" + exit 1 + endif + $mydir/swell_upd4geos.csh $nymdb $nhmsb $nymda $nhmsa |& tee -a $FVWORK/$EXPID.jedi_upd.log.$logtag.txt + if ( $status ) then + echo "${myname}: swell_upd4geos.csh failed, aborting" + exit 1 + endif +endif + +touch $donefile +echo "${myname}: Complete" +exit 0 diff --git a/src/Applications/GEOSdas_App/swell/swell_env.csh b/src/Applications/GEOSdas_App/swell/swell_env.csh new file mode 100644 index 00000000..2dca20af --- /dev/null +++ b/src/Applications/GEOSdas_App/swell/swell_env.csh @@ -0,0 +1,96 @@ +#!/bin/csh +# +# swell_env.csh - set up the environment for the swell command line (swell, cylc) +# +# usage (must be sourced): source swell_env.csh +# +# On return SWELL_ENV_OK is 1 on success and 0 on failure (the reason is printed). +# The calling script must check it; this file never exits, so it is also safe +# to source from an interactive shell for debugging. +# +# Notes: +# - PYTHONPATH/PYTHONHOME are cleared: the ADAS (GEOSpyD) python settings break +# the swell venv. Call this from a script (own process), not from the ADAS job +# shell itself, so the ADAS environment is left untouched. +# - HOSTNAME is exported if missing; swell uses it to detect the NCCS platform. +# - cylc tasks do not inherit this environment: each task sources the +# 'modules' file that swell writes into the suite directory. +# --------------------------------------------------------------------------- + +setenv SWELL_ENV_OK 0 + +# locate and read the pin file +if ( ! $?SWELL_CONFIG ) then + if ( $?FVHOME ) then + if ( -e $FVHOME/run/swell/swell_config.csh ) setenv SWELL_CONFIG $FVHOME/run/swell/swell_config.csh + endif +endif +if ( ! $?SWELL_CONFIG ) then + if ( $?FVROOT ) then + if ( -e $FVROOT/etc/swell/swell_config.csh ) setenv SWELL_CONFIG $FVROOT/etc/swell/swell_config.csh + endif +endif + +if ( ! $?SWELL_CONFIG ) then + if ( $?SWELL_ETC_FALLBACK ) then + if ( -e $SWELL_ETC_FALLBACK/swell_config.csh ) setenv SWELL_CONFIG $SWELL_ETC_FALLBACK/swell_config.csh + endif +endif + +if ( ! $?SWELL_CONFIG ) then + echo "swell_env.csh: cannot find swell_config.csh (set SWELL_CONFIG, or provide FVHOME/run/swell or FVROOT/etc/swell)" +else if ( ! -e $SWELL_CONFIG ) then + echo "swell_env.csh: SWELL_CONFIG=$SWELL_CONFIG does not exist" +else + source $SWELL_CONFIG + + # experiment settings without defaults (fvsetup writes them to run/swell/swell_exp.csh) + set swell_missing = "" + foreach swell_v ( SWELL_VENV SWELL_SRC SWELL_JEDI_BUILD SWELL_JEDI_SRC SWELL_STATIC_FILES ) + printenv $swell_v >& /dev/null + if ( $status ) set swell_missing = "$swell_missing $swell_v" + end + if ( $?PYTHONPATH ) unsetenv PYTHONPATH + if ( $?PYTHONHOME ) unsetenv PYTHONHOME + if ( ! $?HOSTNAME ) setenv HOSTNAME `hostname` + + if ( "$swell_missing" != "" ) then + echo "swell_env.csh: not set:$swell_missing" + echo 'swell_env.csh: (written by fvsetup to $FVHOME/run/swell/swell_exp.csh, or set them in the environment)' + else if ( ! -e $SWELL_VENV/bin/activate.csh ) then + echo "swell_env.csh: no venv at SWELL_VENV=$SWELL_VENV" + else + source $SWELL_VENV/bin/activate.csh + rehash + set swell_exe = `which swell` + if ( $status ) then + echo "swell_env.csh: swell not found in $SWELL_VENV/bin" + else + setenv SWELL_ENV_OK 1 + + # provenance and commit pin + setenv SWELL_HEAD unknown + if ( -d $SWELL_SRC/.git ) setenv SWELL_HEAD `git -C $SWELL_SRC rev-parse HEAD` + set swell_dirty = "" + if ( -d $SWELL_SRC/.git ) then + set nmod = `git -C $SWELL_SRC status --porcelain --untracked-files=no | wc -l` + if ( $nmod > 0 ) set swell_dirty = " (with $nmod uncommitted change(s))" + endif + echo "swell_env.csh: swell = $swell_exe" + echo "swell_env.csh: commit = $SWELL_HEAD$swell_dirty [$SWELL_SRC]" + echo "swell_env.csh: JEDI = $SWELL_JEDI_BUILD" + + # swell commit check: commented out (swell changes often) + #if ( "$SWELL_COMMIT" != "" ) then + # echo $SWELL_HEAD | grep -q "^$SWELL_COMMIT" + # if ( $status ) then + # echo "swell_env.csh: swell commit $SWELL_HEAD does not match pinned SWELL_COMMIT=$SWELL_COMMIT" + # if ( $SWELL_COMMIT_STRICT ) setenv SWELL_ENV_OK 0 + # endif + #endif + unset nmod + endif + unset swell_exe swell_dirty + endif + unset swell_missing swell_v +endif diff --git a/src/Applications/GEOSdas_App/swell/swell_gsi2ioda.csh b/src/Applications/GEOSdas_App/swell/swell_gsi2ioda.csh new file mode 100644 index 00000000..4f83544f --- /dev/null +++ b/src/Applications/GEOSdas_App/swell/swell_gsi2ioda.csh @@ -0,0 +1,108 @@ +#!/bin/csh -f +# +# swell_gsi2ioda.csh - convert GSI ncdiags and GSI bias files to IODA with swell +# +# usage: swell_gsi2ioda.csh nymda nhmsa inpdir outdir workdir +# +# nymda nhmsa analysis date/time +# inpdir directory holding $EXPID.diag_*_ges..nc4 (normally $FVWORK) +# outdir results go to $outdir/ioda._0000 +# workdir scratch for this conversion (swell experiment_root) +# +# Inputs: $inpdir/$EXPID.diag_*_ges.*.nc4 +# $FVHOME/recycle/$EXPID.{ana_satbias_rst,ana_satbiaspc_rst,ana_acftbias_rst}.*.txt +# Outputs: $outdir/ioda._0000/ IODA obs, satbias, tlapse, aircraft bias +# +# swell (GetGsiBc) looks for the bias files at the previous analysis time +# (analysis - TIMEINC); the single recycle file of each type is linked under that name. +# Override template: convert_ncdiags.yaml.tmpl (see swell_run.csh for the search path). +# --------------------------------------------------------------------------- + +set myname = swell_gsi2ioda.csh + +if ( $#argv < 5 ) then + echo "usage: $myname nymda nhmsa inpdir outdir workdir" + exit 1 +endif + +set nymda = $1 +set nhmsa = `echo $2 | awk '{printf "%06d", $1}'` +set inpdir = $3 +set outdir = $4 +set workdir = $5 +set hha = `echo $nhmsa | cut -c1-2` +set yyyymmddhh = ${nymda}${hha} + +if ( ! $?EXPID || ! $?FVHOME || ! $?FVWORK ) then + echo "${myname}: EXPID, FVHOME and FVWORK must be defined, aborting" + exit 1 +endif +if ( ! $?TIMEINC ) setenv TIMEINC 360 + +set donefile = $FVWORK/.DONE_${myname}.$yyyymmddhh +if ( -e $donefile ) then + echo "${myname}: already done" + exit 0 +endif + +set mydir = `dirname $0` +set mydir = `cd $mydir && pwd` + +# previous analysis time: tag swell expects on the GSI bias files +@ dtsec = $TIMEINC * 60 +set pdate = ( `tick $nymda $nhmsa -$dtsec` ) +if ( $#pdate != 2 ) then + echo "${myname}: tick failed, aborting" + exit 1 +endif +set ptag = $pdate[1]_`echo $pdate[2] | cut -c1-2`z + +# --- stage inputs ---------------------------------------------------------- +set stage = $workdir/g2i_inputs.$yyyymmddhh +/bin/rm -rf $stage +mkdir -p $stage/gsi_diags $stage/gsi_bias + +set diags = ( `find -H $inpdir -maxdepth 1 -name "${EXPID}.diag_*_ges.*nc4"` ) +if ( $#diags == 0 ) then + echo "${myname}: no $inpdir/${EXPID}.diag_*_ges.*nc4 found, aborting" + exit 1 +endif +foreach f ( $diags ) + ln -sf $f $stage/gsi_diags/ +end + +foreach ftype ( ana_acftbias_rst ana_satbias_rst ana_satbiaspc_rst ) + set fn = ( `find -H $FVHOME/recycle -maxdepth 1 -name "${EXPID}.${ftype}.*.txt"` ) + if ( $#fn != 1 ) then + echo "${myname}: expected one $FVHOME/recycle/${EXPID}.${ftype}.*.txt, found $#fn, aborting" + exit 1 + endif + ln -sf $fn[1] $stage/gsi_bias/${EXPID}.${ftype}.${ptag}.txt +end + +setenv SWELL_GSI_DIAG_DIR $stage/gsi_diags +setenv SWELL_GSI_BIAS_DIR $stage/gsi_bias + +# --- run swell ------------------------------------------------------------- +set expid = ${EXPID}-g2i-$yyyymmddhh +$mydir/swell_run.csh convert_ncdiags convert_ncdiags.yaml.tmpl $workdir $expid $nymda $nhmsa +if ( $status ) then + echo "${myname}: swell convert_ncdiags failed, aborting" + exit 1 +endif + +# --- deliver --------------------------------------------------------------- +set cycdir = $workdir/$expid/run/${nymda}T${nhmsa}Z/geos_atmosphere +set iodadir = $outdir/ioda.${nymda}_${hha}0000 +mkdir -p $iodadir +set outs = ( `find -H $cycdir -maxdepth 1 -type f \( -name "*.nc4" -o -name "*.txt" \)` ) +if ( $#outs == 0 ) then + echo "${myname}: no IODA output in $cycdir, aborting" + exit 1 +endif +/bin/mv $outs $iodadir/ +echo "${myname}: $#outs file(s) moved to $iodadir" + +touch $donefile +echo "${myname}: Complete" +exit 0 diff --git a/src/Applications/GEOSdas_App/swell/swell_mkiau.csh b/src/Applications/GEOSdas_App/swell/swell_mkiau.csh new file mode 100644 index 00000000..6bb0f0ee --- /dev/null +++ b/src/Applications/GEOSdas_App/swell/swell_mkiau.csh @@ -0,0 +1,257 @@ +#!/bin/csh -f +# +# swell_mkiau.csh - GEOS analyses and IAU forcing from the central JEDI increment(s) +# +# usage: swell_mkiau.csh nymdb nhmsb nymda nhmsa +# +# nymdb nhmsb beginning of the analysis window (IAU start) +# nymda nhmsa analysis time +# +# In $JEDIWORK=$FVWORK/jedi.. (as left by swell_ana_central.csh): +# inc/$EXPID.jedi_inc1.eta.z.nc4 lat-lon JEDI increment(s) +# one file 3D-Var/3D-FGAT: the increment holds for the whole window +# N files 4D (e.g. 4DEnVar): one increment at each IAU time +# IAU times T: +# DO4DIAU=1 every ASYNBKG minutes from the window begin to its end (TIMEINC minutes), +# as the GSI 4D-IAU (ana4dupd.pl); with one increment, the analysis at T is +# the background at T plus that increment +# DO4DIAU=0 the analysis time only (3D-IAU) +# produces, for each T: +# ana/$EXPID.jedi_ana.eta..nc4 dyn_jediupd.x: lat-lon bkg(T) + increment +# iau/$EXPID.agcm_import_rst..nc4 mkiau.x (IAU_DATE/IAU_TIME = T) +# inc/$EXPID.jedi_inc.eta..nc4 increment on the bkg grid (when grids differ) +# With one increment mkiau.x runs once, at the analysis time, and the other IAU times +# get that file (hard link; SWELL_MKIAU_EACH_TIME=1: mkiau.x at every IAU time). +# (DO4DIAU=0: the single IAU file is tagged with the window begin, as GEOSdas expects) +# and $FVWORK/$EXPID.jedi_{agcmrst,ana,inc}..tar +# +# Lat-lon backgrounds: $FVHOME/recycle/$EXPID.bkg??_eta_rst..nc4 +# mkiau resource: mkiau.rc.tmpl ($FVHOME/run/swell, else $FVROOT/etc/swell), with +# ANADATE ANATIME ANAFNAME BKGFNAME AGCMIMPRST filled at run time. +# --------------------------------------------------------------------------- + +set myname = swell_mkiau.csh + +if ( $#argv < 4 ) then + echo "usage: $myname nymdb nhmsb nymda nhmsa" + exit 1 +endif + +set nymdb = $1 +set nhmsb = `echo $2 | awk '{printf "%06d", $1}'` +set nymda = $3 +set nhmsa = `echo $4 | awk '{printf "%06d", $1}'` +set hhb = `echo $nhmsb | cut -c1-2` +set hha = `echo $nhmsa | cut -c1-2` +set hhmmb = `echo $nhmsb | cut -c1-4` +set hhmma = `echo $nhmsa | cut -c1-4` +set yyyymmddhh = ${nymda}${hha} + +if ( ! $?EXPID || ! $?FVHOME || ! $?FVWORK ) then + echo "${myname}: EXPID, FVHOME and FVWORK must be defined, aborting" + exit 1 +endif +if ( ! $?SWELL_MKIAU_MPIRUN ) setenv SWELL_MKIAU_MPIRUN mpirun +if ( ! $?SWELL_MKIAU_EACH_TIME ) setenv SWELL_MKIAU_EACH_TIME 0 +if ( ! $?DO4DIAU ) setenv DO4DIAU 0 +if ( ! $?TIMEINC ) setenv TIMEINC 360 +if ( ! $?ASYNBKG ) setenv ASYNBKG 60 + +set donefile = $FVWORK/.DONE_${myname}.$yyyymmddhh +if ( -e $donefile ) then + echo "${myname}: already done" + exit 0 +endif + +set mydir = `dirname $0` +set mydir = `cd $mydir && pwd` + +set rctmpl = "" +foreach d ( $FVHOME/run/swell $mydir/../etc/swell $mydir/etc ) + if ( "$rctmpl" == "" && -e $d/mkiau.rc.tmpl ) set rctmpl = $d/mkiau.rc.tmpl +end +if ( "$rctmpl" == "" ) then + echo "${myname}: cannot find mkiau.rc.tmpl, aborting" + exit 1 +endif + +setenv JEDIWORK $FVWORK/jedi.${nymda}.${nhmsa} +if ( ! -d $JEDIWORK/inc ) then + echo "${myname}: $JEDIWORK/inc not found, aborting" + exit 1 +endif +cd $JEDIWORK +mkdir -p ana bkg iau + +# --- lat-lon backgrounds (GEOSdas removes some from FVWORK when GSI runs) --- +# (links named like archived files: keep fvarchive out of bkg/) +touch bkg/.no_archiving +foreach fn ( `find -H $FVHOME/recycle -maxdepth 1 -name "${EXPID}.bkg*_eta_rst.*.nc4"` ) + set sfx = `basename $fn | cut -d. -f3-` + ln -sf $fn bkg/$EXPID.bkg.eta.$sfx +end + +# --- IAU times (yyyymmdd_hhmm) --------------------------------------------- +set iautags = ( ) +if ( $DO4DIAU ) then + @ winsec = $TIMEINC * 60 + @ frqsec = $ASYNBKG * 60 + if ( $frqsec <= 0 || $frqsec > $winsec ) then + echo "${myname}: ASYNBKG=$ASYNBKG does not fit TIMEINC=$TIMEINC, aborting" + exit 1 + endif + @ rem = $winsec % $frqsec + if ( $rem != 0 ) then + echo "${myname}: TIMEINC=$TIMEINC is not a multiple of ASYNBKG=$ASYNBKG, aborting" + exit 1 + endif + @ nstep = $winsec / $frqsec + @ i = 0 + while ( $i <= $nstep ) + @ dt = $i * $frqsec + set t = ( `tick $nymdb $nhmsb $dt` ) + set nhms = `echo $t[2] | awk '{printf "%06d", $1}'` + set iautags = ( $iautags $t[1]_`echo $nhms | cut -c1-4` ) + @ i++ + end +else + set iautags = ( ${nymda}_${hhmma} ) +endif + +# --- increment(s) ---------------------------------------------------------- +set incs = ( `find -H inc -maxdepth 1 -name "$EXPID.jedi_inc1.eta.*.nc4" | sort` ) +if ( $#incs == 0 ) then + echo "${myname}: no inc/$EXPID.jedi_inc1.eta.*.nc4, aborting" + exit 1 +endif +if ( $#incs == 1 ) then + # 3D-Var/3D-FGAT: one increment for the whole window (FGAT writes it at the + # window begin); tag it with the analysis time + set inc3d = inc/$EXPID.jedi_inc1.eta.${nymda}_${nhmsa}z.nc4 + if ( "$incs[1]" != "$inc3d" ) then + /bin/mv $incs[1] $inc3d + reset_time.x $inc3d $nymda $nhmsa -9 + endif + echo "${myname}: one (3D) increment, used at $#iautags IAU time(s): $iautags" +else + echo "${myname}: $#incs (4D) increments for $#iautags IAU time(s): $iautags" +endif + +# --- where mkiau.x runs ----------------------------------------------------- +# With one (3D) increment the IAU forcing is the same at every IAU time: mkiau.x +# runs once, at the analysis time, and the other IAU times get that file (hard +# link). The time stored in the file does not matter: the GCM (exact replay) +# reads it with MAPL_ESMFStateReadFromFile, which ignores it. +# SWELL_MKIAU_EACH_TIME=1: mkiau.x at every IAU time, from bkg(T) + increment. +# With 4D increments mkiau.x always runs at every IAU time. +set atag = ${nymda}_${hhmma} +set mkiau_once = 0 +if ( $#incs == 1 && ! $SWELL_MKIAU_EACH_TIME ) set mkiau_once = 1 +set mkiautags = ( $iautags ) +if ( $mkiau_once ) set mkiautags = ( $atag ) + +# analyses at every IAU time, and where mkiau.x runs +set anatags = ( $iautags ) +foreach tag ( $mkiautags ) + set found = 0 + foreach t ( $anatags ) + if ( "$t" == "$tag" ) set found = 1 + end + if ( ! $found ) set anatags = ( $anatags $tag ) +end + +# --- analysis = background + increment, at each time ------------------------ +foreach tag ( $anatags ) + set nymd = `echo $tag | cut -c1-8` + set hhmm = `echo $tag | cut -c10-13` + set nhms = ${hhmm}00 + + set bkgfn = bkg/$EXPID.bkg.eta.${tag}z.nc4 + if ( ! -e $bkgfn ) then + echo "${myname}: $bkgfn not found (from $FVHOME/recycle), aborting" + exit 1 + endif + if ( $#incs == 1 ) then + set incfn = $inc3d + set incout = NULL + if ( "$tag" == "$atag" ) set incout = inc/$EXPID.jedi_inc.eta.${tag}z.nc4 + else + set incfn = inc/$EXPID.jedi_inc1.eta.${nymd}_${nhms}z.nc4 + set incout = inc/$EXPID.jedi_inc.eta.${tag}z.nc4 + if ( ! -e $incfn ) then + echo "${myname}: no JEDI increment at ${tag}z ($incfn), aborting" + exit 1 + endif + endif + + set anafn = ana/$EXPID.jedi_ana.eta.${tag}z.nc4 + /bin/rm -f $anafn + dyn_jediupd.x $nymd $nhms -o $incout $bkgfn $incfn $anafn + if ( $status || ! -e $anafn ) then + echo "${myname}: dyn_jediupd.x failed to create $anafn, aborting" + exit 1 + endif + echo "${myname}: ${tag}z: $bkgfn + $incfn -> $anafn" +end + +# --- IAU forcing ------------------------------------------------------------ +touch input.nml +foreach tag ( $mkiautags ) + set nymd = `echo $tag | cut -c1-8` + set hhmm = `echo $tag | cut -c10-13` + set nhms = ${hhmm}00 + set bkgfn = bkg/$EXPID.bkg.eta.${tag}z.nc4 + set anafn = ana/$EXPID.jedi_ana.eta.${tag}z.nc4 + set iaufn = iau/$EXPID.agcm_import_rst.${tag}z.nc4 + /bin/rm -f $iaufn + setenv ANADATE $nymd + setenv ANATIME $nhms + setenv ANAFNAME $anafn + setenv BKGFNAME $bkgfn + setenv AGCMIMPRST $iaufn + vED -env $rctmpl -o mkiau.rc + set nx = `echorc.x -rc mkiau.rc NX` + set ny = `echorc.x -rc mkiau.rc NY` + @ ncpus = $nx * $ny + $SWELL_MKIAU_MPIRUN -np $ncpus mkiau.x + if ( $status || ! -e $iaufn ) then + echo "${myname}: mkiau.x failed to create $iaufn, aborting" + exit 1 + endif + echo "${myname}: ${tag}z: mkiau.x -> $iaufn" +end + +# --- one mkiau.x run: the same forcing at the other IAU times --------------- +if ( $mkiau_once ) then + set src = iau/$EXPID.agcm_import_rst.${atag}z.nc4 + foreach tag ( $iautags ) + if ( "$tag" == "$atag" ) continue + set dst = iau/$EXPID.agcm_import_rst.${tag}z.nc4 + /bin/rm -f $dst + /bin/ln -f $src $dst >& /dev/null + if ( $status ) /bin/cp $src $dst + if ( ! -e $dst ) then + echo "${myname}: cannot make $dst from $src, aborting" + exit 1 + endif + end + echo "${myname}: one mkiau.x run (${atag}z); the same IAU forcing at: $iautags" +endif + +# 3D-IAU: the single IAU file carries the time tag of the IAU start (as GEOSdas expects) +if ( ! $DO4DIAU ) then + /bin/mv iau/$EXPID.agcm_import_rst.${nymda}_${hhmma}z.nc4 iau/$EXPID.agcm_import_rst.${nymdb}_${hhmmb}z.nc4 +endif + +# --- archive --------------------------------------------------------------- +cd iau +tar cf $FVWORK/$EXPID.jedi_agcmrst.${nymdb}_${hhb}z.tar $EXPID.agcm_import_rst.* +cd ../ana +tar cf $FVWORK/$EXPID.jedi_ana.${nymdb}_${hhb}z.tar $EXPID.jedi_ana*.nc4 +cd ../inc +tar cf $FVWORK/$EXPID.jedi_inc.${nymdb}_${hhb}z.tar $EXPID.jedi_*.nc4 +cd $JEDIWORK + +touch $donefile +echo "${myname}: Complete" +exit 0 diff --git a/src/Applications/GEOSdas_App/swell/swell_obs_share.csh b/src/Applications/GEOSdas_App/swell/swell_obs_share.csh new file mode 100644 index 00000000..3ca5df61 --- /dev/null +++ b/src/Applications/GEOSdas_App/swell/swell_obs_share.csh @@ -0,0 +1,55 @@ +#!/bin/csh -f +# +# swell_obs_share.csh - keep the observations and bias correction of one cycle for the +# ensemble analysis (swell_ana_atmens.csh) of the same cycle +# +# usage: swell_obs_share.csh nymda nhmsa obsdir +# +# nymda nhmsa analysis time +# obsdir staged inputs (swell_obs_stage.csh); links are dereferenced +# +# Copies obsdir to $SWELL_OBS_SHARE/TZ/geos_atmosphere (swell_config.csh: +# $FVHOME/swell/obs, outside $FVWORK) and keeps the latest SWELL_OBS_SHARE_KEEP cycles. +# Used by swell_ana_central.csh and by swell_driver.csh obsonly (first cycle). +# --------------------------------------------------------------------------- + +set myname = swell_obs_share.csh + +if ( $#argv < 3 ) then + echo "usage: $myname nymda nhmsa obsdir" + exit 1 +endif + +set nymda = $1 +set nhmsa = `echo $2 | awk '{printf "%06d", $1}'` +set obsdir = $3 + +if ( ! $?SWELL_OBS_SHARE && $?FVHOME ) then + if ( -e $FVHOME/run/swell/swell_config.csh ) source $FVHOME/run/swell/swell_config.csh +endif +if ( ! $?SWELL_OBS_SHARE ) then + echo "${myname}: SWELL_OBS_SHARE not set, observations not saved for the ensemble" + exit 0 +endif + +set nobs = `find -H $obsdir -maxdepth 1 \( -type f -o -type l \) |& grep -c "^$obsdir/"` +if ( $nobs == 0 ) then + echo "${myname}: no inputs in $obsdir, aborting" + exit 1 +endif + +set share = $SWELL_OBS_SHARE/${nymda}T${nhmsa}Z/geos_atmosphere +/bin/rm -rf $share +mkdir -p $share +/bin/cp -L $obsdir/* $share/ +if ( $status ) then + echo "${myname}: failed to copy the inputs of this analysis to $share, aborting" + exit 1 +endif +if ( ! $?SWELL_OBS_SHARE_KEEP ) setenv SWELL_OBS_SHARE_KEEP 4 +@ k1 = $SWELL_OBS_SHARE_KEEP + 1 +foreach d ( `find -H $SWELL_OBS_SHARE -mindepth 1 -maxdepth 1 -type d -name "*T*Z" | sort -r | tail -n +$k1` ) + /bin/rm -rf $d +end +echo "${myname}: observations and biases for the ensemble saved in $share ($nobs files)" +exit 0 diff --git a/src/Applications/GEOSdas_App/swell/swell_obs_stage.csh b/src/Applications/GEOSdas_App/swell/swell_obs_stage.csh new file mode 100644 index 00000000..266d78e1 --- /dev/null +++ b/src/Applications/GEOSdas_App/swell/swell_obs_stage.csh @@ -0,0 +1,102 @@ +#!/bin/csh -f +# +# swell_obs_stage.csh - observations and bias correction of one cycle, as swell reads them +# +# usage: swell_obs_stage.csh nymdb nhmsb nymda nhmsa obsdir +# +# nymdb nhmsb beginning of the analysis window +# nymda nhmsa analysis time +# obsdir directory to fill (normally /T..Z/geos_atmosphere) +# +# Links $FVWORK/ioda._0000/* (swell_gsi2ioda.csh, or SWELL_OFFLINE_IODA_DIR links) +# into obsdir, then the bias correction at the background time (ptag = window begin - TIMEINC): +# GSI bootstrap: ..satbias_cov.nc4 -> satbias file, +# aircraft_abias_air..nc4 -> aircraft_temperature..acftbias{,_cov} +# cycled VarBC (SWELL_FEEDBACK_VARBC=1): files at ptag in $SWELL_VARBC_DIR replace those. +# Used by swell_ana_central.csh and by swell_driver.csh obsonly (first cycle). +# --------------------------------------------------------------------------- + +set myname = swell_obs_stage.csh + +if ( $#argv < 5 ) then + echo "usage: $myname nymdb nhmsb nymda nhmsa obsdir" + exit 1 +endif + +set nymdb = $1 +set nhmsb = `echo $2 | awk '{printf "%06d", $1}'` +set nymda = $3 +set nhmsa = `echo $4 | awk '{printf "%06d", $1}'` +set obsdir = $5 +set hhb = `echo $nhmsb | cut -c1-2` +set hha = `echo $nhmsa | cut -c1-2` + +if ( ! $?EXPID || ! $?FVHOME || ! $?FVWORK ) then + echo "${myname}: EXPID, FVHOME and FVWORK must be defined, aborting" + exit 1 +endif +if ( ! $?TIMEINC ) setenv TIMEINC 360 +if ( ! $?SWELL_FEEDBACK_VARBC || ! $?SWELL_VARBC_DIR ) then + if ( ! -e $FVHOME/run/swell/swell_config.csh ) then + echo "${myname}: $FVHOME/run/swell/swell_config.csh not found, aborting" + exit 1 + endif + source $FVHOME/run/swell/swell_config.csh +endif + +# ptag: previous window begin = background time of the bias correction +@ dtsec = $TIMEINC * 60 +set pdate = ( `tick $nymdb $nhmsb -$dtsec` ) +if ( $#pdate != 2 ) then + echo "${myname}: tick failed, aborting" + exit 1 +endif +set hhp = `echo $pdate[2] | awk '{printf "%06d", $1}' | cut -c1-2` +set ptag = $pdate[1]T${hhp}0000Z + +# --- observations ---------------------------------------------------------- +set iodasrc = $FVWORK/ioda.${nymda}_${hha}0000 +set nsrc = `find -H $iodasrc -maxdepth 1 \( -type f -o -type l \) |& grep -c "^$iodasrc/"` +if ( $nsrc == 0 ) then + echo "${myname}: no IODA input in $iodasrc, aborting" + exit 1 +endif + +mkdir -p $obsdir +foreach f ( `find -H $iodasrc -maxdepth 1 \( -type f -o -type l \)` ) + ln -sf $f $obsdir/ +end +cd $obsdir + +# bootstrap from GSI biases: satbias covariance = satbias file, aircraft bias renamed +foreach f ( `find -H . -maxdepth 1 -name "*.${ptag}.satbias.nc4"` ) + set sensor = `basename $f .${ptag}.satbias.nc4` + if ( ! -e ${sensor}.${ptag}.satbias_cov.nc4 ) then + ln -sf $f:t ${sensor}.${ptag}.satbias_cov.nc4 + endif +end +if ( -e aircraft_abias_air.${ptag}.nc4 ) then + if ( ! -e aircraft_temperature.${ptag}.acftbias ) then + ln -sf aircraft_abias_air.${ptag}.nc4 aircraft_temperature.${ptag}.acftbias + endif + if ( ! -e aircraft_temperature.${ptag}.acftbias_cov ) then + ln -sf aircraft_abias_air.${ptag}.nc4 aircraft_temperature.${ptag}.acftbias_cov + endif +endif + +# cycled VarBC: previous JEDI output at this background time replaces the GSI biases +set vbcsrc = "GSI (bootstrap)" +if ( $SWELL_FEEDBACK_VARBC ) then + set prev = () + if ( -d $SWELL_VARBC_DIR ) set prev = ( `find -H $SWELL_VARBC_DIR -maxdepth 1 -type f -name "*.${ptag}.*"` ) + if ( $#prev > 0 ) then + foreach f ( $prev ) + ln -sf $f $f:t + end + set vbcsrc = "JEDI $SWELL_VARBC_DIR ($#prev files)" + else + echo "${myname}: WARNING: no VarBC at $ptag in $SWELL_VARBC_DIR, using GSI biases" + endif +endif +echo "${myname}: $nsrc IODA input file(s) staged in $obsdir; bias correction from $vbcsrc" +exit 0 diff --git a/src/Applications/GEOSdas_App/swell/swell_render.csh b/src/Applications/GEOSdas_App/swell/swell_render.csh new file mode 100644 index 00000000..0c1c4683 --- /dev/null +++ b/src/Applications/GEOSdas_App/swell/swell_render.csh @@ -0,0 +1,69 @@ +#!/bin/csh -f +# +# swell_render.csh - locate a template, fill in $VARs from the environment, reject leftovers +# +# usage: swell_render.csh template output +# +# template path, or bare name searched for in $FVHOME/run/swell, $FVROOT/etc/swell, +# $SWELL_ETC_FALLBACK (in this order) +# output rendered file +# +# Rendering is done with vED -env; any $VAR or ${VAR} left over (outside comment +# lines) is an error. The template path actually used is printed on success. +# Exit status: 0 on success, 1 on failure. +# --------------------------------------------------------------------------- + +set myname = swell_render.csh + +if ( $#argv < 2 ) then + echo "usage: $myname template output" + exit 1 +endif +set template = $1 +set output = $2 + +which vED >& /dev/null +if ( $status ) then + echo "${myname}: vED not found in PATH, aborting" + exit 1 +endif + +set tmpl = "" +if ( -e $template ) then + set tmpl = $template +else + set search = () + if ( $?FVHOME ) then + set search = ( $search $FVHOME/run/swell ) + endif + if ( $?FVROOT ) then + set search = ( $search $FVROOT/etc/swell ) + endif + if ( $?SWELL_ETC_FALLBACK ) then + set search = ( $search $SWELL_ETC_FALLBACK ) + endif + foreach d ( $search ) + if ( "$tmpl" == "" && -e $d/$template ) set tmpl = $d/$template + end +endif +if ( "$tmpl" == "" ) then + echo "${myname}: cannot find template $template, aborting" + exit 1 +endif + +vED -env $tmpl -o $output +if ( $status || ! -e $output ) then + echo "${myname}: failed to render $tmpl, aborting" + exit 1 +endif + +# (\x24 is '$'; a literal dollar cannot be used inside csh backquotes) +set nunres = `grep -v '^[[:space:]]*#' $output | grep -cP '\x24\{?[A-Za-z_]'` +if ( $nunres > 0 ) then + echo "${myname}: unresolved variables in $output (from $tmpl):" + grep -v '^[[:space:]]*#' $output | grep -nP '\x24\{?[A-Za-z_]' + exit 1 +endif + +echo $tmpl +exit 0 diff --git a/src/Applications/GEOSdas_App/swell/swell_run.csh b/src/Applications/GEOSdas_App/swell/swell_run.csh new file mode 100644 index 00000000..ddef086b --- /dev/null +++ b/src/Applications/GEOSdas_App/swell/swell_run.csh @@ -0,0 +1,180 @@ +#!/bin/csh -f +# +# swell_run.csh - run ONE cycle of a swell suite and wait for it to finish +# +# usage: swell_run.csh suite template exproot expid nymd nhms +# +# suite swell suite/config name (e.g. convert_ncdiags, 3dfgat_atmos) +# template override template; a bare name is searched for in +# $FVHOME/run/swell, $FVROOT/etc/swell, +# exproot swell experiment_root (directory owned by this run) +# expid swell experiment_id (unique per role and cycle, e.g. x0055-g2i-2026082612) +# nymd nhms analysis date/time (middle of window) +# +# Steps: +# 1. swell_env.csh (pin file, venv, commit check) +# 2. render the override (and optional slurm) template with swell_render.csh +# 3. swell create -o -p $SWELL_PLATFORM -k [-s ] +# 4. swell launch -b -t $SWELL_TIMEOUT (blocks until done) +# 5. require the swell CleanCycle marker /cycle_done_* +# 6. save cylc logs into //cylc_log.tar.gz; remove the +# ~/cylc-run entry on success (kept on failure for 'cylc cat-log') +# +# Variables available to templates (in addition to the whole environment): +# SWELL_EXPERIMENT_ID SWELL_EXPERIMENT_ROOT SWELL_ISO_DATE SWELL_CYCLE_TIME +# SWELL_JEDI_BUILD SWELL_JEDI_SRC SWELL_STATIC_FILES SWELL_CRTM_COEFFS +# +# Optional environment: +# SWELL_SLURM_TEMPLATE slurm template rendered like the override and passed with -s +# SWELL_SLURM_FILE ready-made slurm yaml passed with -s +# (default $FVHOME/run/swell/slurm.yaml if present) +# SWELL_MODEL model component holding the done marker (default geos_atmosphere) +# SWELL_DONE_MARKER none: do not require cycle_done_* (for suites without CleanCycle) +# +# Exit status: 0 on success, 1 on failure. +# --------------------------------------------------------------------------- + +set myname = swell_run.csh + +if ( $#argv < 6 ) then + echo "usage: $myname suite template exproot expid nymd nhms" + exit 1 +endif + +set suite = $1 +set template = $2 +set exproot = $3 +set expid = $4 +set nymd = $5 +set nhms = `echo $6 | awk '{printf "%06d", $1}'` + +set mydir = `dirname $0` +set mydir = `cd $mydir && pwd` + +# installed layout ($FVROOT/bin + $FVROOT/etc/swell) or source tree (swell/ + swell/etc) +set etcdir = $mydir/etc +if ( -d $mydir/../etc/swell ) set etcdir = `cd $mydir/../etc/swell && pwd` +setenv SWELL_ETC_FALLBACK $etcdir + +# --- environment ----------------------------------------------------------- +source $mydir/swell_env.csh +if ( ! $SWELL_ENV_OK ) then + echo "${myname}: swell environment setup failed, aborting" + exit 1 +endif + +# --- dates ----------------------------------------------------------------- +set yyyy = `echo $nymd | cut -c1-4` +set mm = `echo $nymd | cut -c5-6` +set dd = `echo $nymd | cut -c7-8` +set hh = `echo $nhms | cut -c1-2` +set mn = `echo $nhms | cut -c3-4` +set ss = `echo $nhms | cut -c5-6` + +setenv SWELL_EXPERIMENT_ID $expid +setenv SWELL_EXPERIMENT_ROOT $exproot +setenv SWELL_ISO_DATE "${yyyy}-${mm}-${dd}T${hh}:${mn}:${ss}Z" +setenv SWELL_CYCLE_TIME T${hh} + +if ( ! $?SWELL_MODEL ) setenv SWELL_MODEL geos_atmosphere +set expdir = $exproot/$expid +set suitedir = $expdir/${expid}-suite +set cycdir = $expdir/run/${nymd}T${nhms}Z/$SWELL_MODEL +set cylcrun = $HOME/cylc-run/${expid}-suite + +# --- fresh experiment directory -------------------------------------------- +if ( "$exproot" == "" || "$expid" == "" ) then + echo "${myname}: empty exproot or expid, aborting" + exit 1 +endif +mkdir -p $exproot +if ( -d $expdir ) /bin/rm -rf $expdir +if ( -d $cylcrun ) /bin/rm -rf $cylcrun + +# --- render override and slurm settings ------------------------------------ +set override = $exproot/${expid}.override.yaml +set tmpl = `$mydir/swell_render.csh $template $override` +if ( $status ) then + echo "$tmpl" + echo "${myname}: cannot prepare the override from $template, aborting" + exit 1 +endif + +set slurmopt = "" +if ( $?SWELL_SLURM_TEMPLATE ) then + set slurmyaml = $exproot/${expid}.slurm.yaml + set stmpl = `$mydir/swell_render.csh $SWELL_SLURM_TEMPLATE $slurmyaml` + if ( $status ) then + echo "$stmpl" + echo "${myname}: cannot prepare slurm settings from $SWELL_SLURM_TEMPLATE, aborting" + exit 1 + endif + set slurmopt = "-s $slurmyaml" +else + if ( ! $?SWELL_SLURM_FILE ) then + if ( $?FVHOME ) then + if ( -e $FVHOME/run/swell/slurm.yaml ) setenv SWELL_SLURM_FILE $FVHOME/run/swell/slurm.yaml + endif + endif + if ( $?SWELL_SLURM_FILE ) then + set slurmopt = "-s $SWELL_SLURM_FILE" + endif +endif + +echo "${myname}: suite=$suite expid=$expid cycle=$SWELL_ISO_DATE" +echo "${myname}: template=$tmpl" +echo "${myname}: override=$override" +if ( "$slurmopt" != "" ) echo "${myname}: slurm=$slurmopt" + +# --- create ---------------------------------------------------------------- +swell create $suite -o $override -p $SWELL_PLATFORM -k $slurmopt +set rc = $status +if ( $rc || ! -e $suitedir/flow.cylc ) then + echo "${myname}: swell create $suite failed (status $rc), aborting" + exit 1 +endif + +# provenance +cat >! $expdir/swell_run.info << EOF +suite: $suite +experiment: $expid +cycle: $SWELL_ISO_DATE +override: $override +template: $tmpl +slurm: $slurmopt +swell_venv: $SWELL_VENV +swell_src: $SWELL_SRC +swell_commit: $SWELL_HEAD +jedi_build: $SWELL_JEDI_BUILD +host: `hostname` +created: `date -u +%Y-%m-%dT%H:%M:%SZ` +EOF + +# --- launch and wait ------------------------------------------------------- +swell launch $suitedir -b -t $SWELL_TIMEOUT +set rc = $status + +# keep the cylc logs with the experiment +if ( -d $cylcrun/runN/log ) then + tar -C $cylcrun/runN -czf $expdir/cylc_log.tar.gz log +endif + +if ( $rc ) then + echo "${myname}: swell launch failed (status $rc); cylc run kept in $cylcrun" + exit 1 +endif + +# --- success checks -------------------------------------------------------- +if ( ! $?SWELL_DONE_MARKER ) setenv SWELL_DONE_MARKER cycle_done +if ( "$SWELL_DONE_MARKER" != "none" ) then + set marker = `find -H $cycdir -maxdepth 1 -name "${SWELL_DONE_MARKER}_*" |& head -1` + if ( "$marker" == "" ) then + echo "${myname}: workflow ended but $cycdir/${SWELL_DONE_MARKER}_* not found, aborting" + exit 1 + endif +endif + +if ( ! $SWELL_KEEP_CYLC_RUN ) /bin/rm -rf $cylcrun + +echo "${myname}: $suite $expid completed" +exit 0 diff --git a/src/Applications/GEOSdas_App/swell/swell_setup.pl b/src/Applications/GEOSdas_App/swell/swell_setup.pl new file mode 100644 index 00000000..81119aaa --- /dev/null +++ b/src/Applications/GEOSdas_App/swell/swell_setup.pl @@ -0,0 +1,139 @@ +#!/usr/bin/env perl +# +# swell_setup.pl - install the swell layer into a GEOS-ADAS experiment (called by fvsetup) +# +# usage: swell_setup.pl -fvhome DIR -fvroot DIR [-set KEY=VALUE ...] +# [-mkiau IM,JM,LM] [-rst4fcst ARCHIVE,EXPID] +# +# (always) copy $FVROOT/etc/swell/swell_config.csh, unchanged, to $FVHOME/run/swell +# -set KEY=VALUE experiment setting written to $FVHOME/run/swell/swell_exp.csh +# (repeatable; a later call updates the same key) +# -mkiau IM,JM,LM $FVHOME/run/swell/mkiau.rc.tmpl from $FVROOT/etc/swell/mkiau.rc.tmpl, +# with @AGCM_IM, @AGCM_JM, @AGCM_LM filled in for the AGCM grid +# -rst4fcst ARCH,EXP in $FVHOME/fcst/rst4fcst.acq, replace the GSI IAU (agcm_import_rst) +# by the JEDI IAU archive (jedi_agcmrst); the restart line stays +# +# swell_exp.csh holds the experiment settings as "if ( ! $?KEY ) setenv KEY VALUE", so +# they can still be overridden from the environment at run time; swell_config.csh +# reads it ahead of its own defaults. +#========================================================================================= + +use strict; +use warnings; +use File::Compare qw(compare); +use File::Copy qw(copy); +use File::Path qw(make_path); +use Getopt::Long; + +my ($fvhome, $fvroot, @sets, $mkiau, $rst4fcst); +GetOptions( "fvhome=s" => \$fvhome, + "fvroot=s" => \$fvroot, + "set=s" => \@sets, + "mkiau=s" => \$mkiau, + "rst4fcst=s" => \$rst4fcst ) or usage(); +usage() unless ( $fvhome and $fvroot ); + +my $etc = "$fvroot/etc/swell"; +my $rundir = "$fvhome/run/swell"; +make_path($rundir); + +install_config(); +set_exp(@sets) if @sets; +install_mkiau($mkiau) if $mkiau; +add_rst4fcst($rst4fcst) if $rst4fcst; +exit 0; + +#----------------------------------------------------------------------------------------- +sub install_config { + my ($src, $dst) = ("$etc/swell_config.csh", "$rundir/swell_config.csh"); + + copy($src, $dst) or die ">>> ERROR <<< cannot copy $src to $dst: $!\n"; + die ">>> ERROR <<< $dst differs from $src\n" unless ( compare($src, $dst) == 0 ); +} + +#----------------------------------------------------------------------------------------- +sub set_exp { + my (@kv) = @_; + my $exp = "$rundir/swell_exp.csh"; + my (%val, @order); + + # current settings (if any) + if ( -e $exp ) { + open(my $in, "<", $exp) or die ">>> ERROR <<< cannot read $exp: $!\n"; + while ( my $line = <$in> ) { + next unless ( $line =~ /^\s*if\s*\(\s*!\s*\$\?(\w+)\s*\)\s*setenv\s+(\w+)\s+(.*?)\s*$/ ); + push @order, $1 unless exists $val{$1}; + $val{$1} = $3; + } + close($in); + } + + foreach my $s (@kv) { + my ($k, $v) = split(/=/, $s, 2); + die ">>> ERROR <<< bad -set '$s' (expected KEY=VALUE)\n" unless ( defined $v and $k =~ /^\w+$/ ); + $v = "\"\"" if ( $v eq "" ); + push @order, $k unless exists $val{$k}; + $val{$k} = $v; + } + + open(my $out, ">", $exp) or die ">>> ERROR <<< cannot write $exp: $!\n"; + print $out "#!/bin/csh\n" + . "#\n" + . "# swell_exp.csh - settings of this experiment for the swell layer (GEOSJEDI=2)\n" + . "#\n" + . "# Written by fvsetup (swell_setup.pl -set KEY=VALUE); read by swell_config.csh\n" + . "# ahead of its defaults. Environment variables of the same name take precedence.\n" + . "# ---------------------------------------------------------------------------\n"; + printf $out "if ( ! \$?%s ) setenv %s %s\n", $_, $_, $val{$_} foreach @order; + close($out); + print "swell_setup.pl: $exp: " . join(" ", map { "$_=$val{$_}" } @order) . "\n"; +} + +#----------------------------------------------------------------------------------------- +sub install_mkiau { + my ($grid) = @_; + my ($im, $jm, $lm) = split(/,/, $grid); + die ">>> ERROR <<< bad -mkiau '$grid' (expected IM,JM,LM)\n" unless ( $im and $jm and $lm ); + my ($src, $dst) = ("$etc/mkiau.rc.tmpl", "$rundir/mkiau.rc.tmpl"); + open(my $in, "<", $src) or die ">>> ERROR <<< cannot read $src: $!\n"; + open(my $out, ">", $dst) or die ">>> ERROR <<< cannot write $dst: $!\n"; + while ( my $line = <$in> ) { + $line =~ s/\@AGCM_IM/$im/g; + $line =~ s/\@AGCM_JM/$jm/g; + $line =~ s/\@AGCM_LM/$lm/g; + print $out $line; + } + close($in); + close($out); + print "swell_setup.pl: $dst for ${im}x${jm}x${lm}\n"; +} + +#----------------------------------------------------------------------------------------- +sub add_rst4fcst { + my ($arg) = @_; + my ($archive, $expid) = split(/,/, $arg); + die ">>> ERROR <<< bad -rst4fcst '$arg' (expected ARCHIVE,EXPID)\n" unless ( $archive and $expid ); + $archive =~ s|/+$||; + my $acq = "$fvhome/fcst/rst4fcst.acq"; + my $line = "$archive/$expid/jedi/rs/Y%y4/M%m2/$expid.jedi_agcmrst.%y4%m2%d2_%h2z.tar"; + + # the forecast restarts stay; the GSI IAU (agcm_import_rst) gives way to the JEDI one + unless ( -e $acq ) { + print "swell_setup.pl: no $acq, forecast acquire not changed\n"; + return; + } + open(my $in, "<", $acq) or die ">>> ERROR <<< cannot read $acq: $!\n"; + my @lines = grep { !/\.agcm_import_rst\./ and !/\.jedi_agcmrst\./ } <$in>; + close($in); + open(my $out, ">", $acq) or die ">>> ERROR <<< cannot write $acq: $!\n"; + print $out @lines, "$line\n"; + close($out); + print "swell_setup.pl: $acq acquires the JEDI IAU forcing\n"; +} + +#----------------------------------------------------------------------------------------- +sub usage { + print "usage: swell_setup.pl -fvhome DIR -fvroot DIR [-set KEY=VALUE ...]\n" + . " [-mkiau IM,JM,LM] [-rst4fcst ARCHIVE,EXPID]\n"; + exit 1; +} diff --git a/src/Applications/GEOSdas_App/swell/swell_upd4geos.csh b/src/Applications/GEOSdas_App/swell/swell_upd4geos.csh new file mode 100644 index 00000000..8cfd9531 --- /dev/null +++ b/src/Applications/GEOSdas_App/swell/swell_upd4geos.csh @@ -0,0 +1,137 @@ +#!/bin/csh -f +# +# swell_upd4geos.csh - make the GEOS model use the JEDI IAU forcing of this cycle +# +# usage: swell_upd4geos.csh nymdb nhmsb nymda nhmsa +# +# Sets in $FVWORK, from $FVWORK/jedi.. (swell_mkiau.csh), what GEOSdas.csm +# (CoupleAnaToGcm_) sets from the GSI analysis: +# $EXPID.agcm_import_rst..nc4 JEDI IAU forcing at each IAU time T (hard link to +# jedi.*/iau, else copy; archived in $EXPID.agcmrst..tar) +# agcm_import_rst..nc4 -> $EXPID.agcm_import_rst..nc4 (read by the GCM) +# agcm_import_rst -> $EXPID.agcm_import_rst..nc4 +# IAU times: DO4DIAU=1, every ASYNBKG minutes of the window (TIMEINC minutes), all of +# them required (no mix of GSI and JEDI forcing); DO4DIAU=0, the window begin. +# With DO4DIAU=1 CoupleAnaToGcm_ makes no GSI IAU (GEOSJEDI=2, SWELL_IAU_OVERWRITE=1), +# so this also writes, at the window end E, +# $EXPID.agcm09_import_rst..nc4 $EXPID.ana09.eta..nc4 +# and stages the JEDI analyses as the central analysis of the ensemble: +# $STAGE4HYBGSI/$EXPID.ana.eta..nc4 $FVHOME/.DONE_MEM001_analyzer. +# (when HYBRIDGSI and STAGE4HYBGSI are set, and there is no atmens_replay.acq). +# --------------------------------------------------------------------------- + +set myname = swell_upd4geos.csh + +if ( $#argv < 4 ) then + echo "usage: $myname nymdb nhmsb nymda nhmsa" + exit 1 +endif + +set nymdb = $1 +set nhmsb = `echo $2 | awk '{printf "%06d", $1}'` +set nymda = $3 +set nhmsa = `echo $4 | awk '{printf "%06d", $1}'` +set hhb = `echo $nhmsb | cut -c1-2` +set hha = `echo $nhmsa | cut -c1-2` +set hhmmb = `echo $nhmsb | cut -c1-4` +set yyyymmddhh = ${nymdb}${hhb} + +if ( ! $?EXPID || ! $?FVHOME || ! $?FVWORK ) then + echo "${myname}: EXPID, FVHOME and FVWORK must be defined, aborting" + exit 1 +endif +if ( ! $?DO4DIAU ) setenv DO4DIAU 0 +if ( ! $?TIMEINC ) setenv TIMEINC 360 +if ( ! $?ASYNBKG ) setenv ASYNBKG 60 + +set donefile = $FVWORK/.DONE_${myname}.$yyyymmddhh +if ( -e $donefile ) then + echo "${myname}: already done" + exit 0 +endif + +set iaudir = $FVWORK/jedi.${nymda}.${nhmsa}/iau +set anadir = $FVWORK/jedi.${nymda}.${nhmsa}/ana + +# --- IAU times read by the GCM (yyyymmdd_hhmm) ------------------------------- +set iautags = ( ) +if ( $DO4DIAU ) then + @ winsec = $TIMEINC * 60 + @ frqsec = $ASYNBKG * 60 + if ( $frqsec <= 0 || $frqsec > $winsec ) then + echo "${myname}: ASYNBKG=$ASYNBKG does not fit TIMEINC=$TIMEINC, aborting" + exit 1 + endif + @ nstep = $winsec / $frqsec + @ i = 0 + while ( $i <= $nstep ) + @ dt = $i * $frqsec + set t = ( `tick $nymdb $nhmsb $dt` ) + set nhms = `echo $t[2] | awk '{printf "%06d", $1}'` + set iautags = ( $iautags $t[1]_`echo $nhms | cut -c1-4` ) + @ i++ + end +else + set iautags = ( ${nymdb}_${hhmmb} ) +endif + +# --- the JEDI IAU forcing, named as GEOSdas names the GSI one ---------------- +cd $FVWORK +foreach tag ( $iautags ) + set src = $iaudir/$EXPID.agcm_import_rst.${tag}z.nc4 + if ( ! -e $src ) then + echo "${myname}: $src not found, aborting" + exit 1 + endif + set dst = $EXPID.agcm_import_rst.${tag}z.nc4 + /bin/rm -f $dst agcm_import_rst.${tag}z.nc4 + /bin/ln -f $src $dst >& /dev/null + if ( $status ) /bin/cp $src $dst + if ( ! -e $dst ) then + echo "${myname}: cannot place $src as $FVWORK/$dst, aborting" + exit 1 + endif + /bin/ln -sf $dst agcm_import_rst.${tag}z.nc4 +end +/bin/ln -sf $EXPID.agcm_import_rst.${iautags[1]}z.nc4 agcm_import_rst +echo "${myname}: GEOS will use the JEDI IAU forcing at $#iautags time(s): $iautags" + +if ( $DO4DIAU ) then + + # --- window end: kept as "09" files (the next cycle reuses the names at this time) + set etag = ${iautags[$#iautags]} + set anae = $anadir/$EXPID.jedi_ana.eta.${etag}z.nc4 + if ( ! -e $anae ) then + echo "${myname}: $anae not found, aborting" + exit 1 + endif + /bin/cp -f $EXPID.agcm_import_rst.${etag}z.nc4 $EXPID.agcm09_import_rst.${etag}z.nc4 + /bin/cp -f $anae $EXPID.ana09.eta.${etag}z.nc4 + + # --- central analysis for the ensemble (recentering), as CoupleAnaToGcm_ does for GSI + set stage = 0 + if ( $?HYBRIDGSI && $?STAGE4HYBGSI ) then + if ( "$HYBRIDGSI" != "/dev/null" && "$STAGE4HYBGSI" != "/dev/null" ) then + if ( ! -e $FVHOME/run/atmens_replay.acq ) set stage = 1 + endif + endif + if ( $stage ) then + mkdir -p $STAGE4HYBGSI + foreach tag ( $iautags ) + set ana = $anadir/$EXPID.jedi_ana.eta.${tag}z.nc4 + if ( ! -e $ana ) then + echo "${myname}: $ana not found, aborting" + exit 1 + endif + /bin/cp -f $ana $STAGE4HYBGSI/$EXPID.ana.eta.${tag}z.nc4 + end + touch $FVHOME/.DONE_MEM001_analyzer.${nymda}${hha} + echo "${myname}: JEDI analyses staged in $STAGE4HYBGSI (central analysis of the ensemble)" + endif +endif + +ls -l | grep -E "agcm_import_rst|agcm09_import_rst|ana09" + +touch $donefile +echo "${myname}: Complete" +exit 0 From 9ef4d2116000944154a723867dc0b9c4226fc86d Mon Sep 17 00:00:00 2001 From: Yonggang Yu Date: Thu, 3 Dec 2026 01:30:56 -0500 Subject: [PATCH 3/4] GEOSJEDI=2: central analysis through swell (fvsetup, GEOSdas.csm) - fvsetup: get_jedi_info (last prompts; GEOSJEDI=2 only, none for GEOSJEDI=0/1): GEOSJEDI is shown from the environment (not asked, not saved), then jedi_ens_scheme, jedi_ens_member, swell venv, swell source directory, JEDI build directory (no built-in defaults; checked; 3 tries). The JEDI source directory is read from the build's CMakeCache.txt. set_swell (after the prompts): requires -jedistatic DIR; writes run/swell/swell_exp.csh (SWELL_VENV, SWELL_SRC, SWELL_JEDI_BUILD, SWELL_JEDI_SRC, SWELL_STATIC_FILES, SWELL_CENTRAL_CRES, account, SWELL_OFFLINE_IODA_DIR with SKIPGSI), run/swell/mkiau.rc.tmpl, and the JEDI IAU in fcst/rst4fcst.acq (swell_setup.pl). - GEOSdas.csm: JEDI_AnalysisRun_: GEOSJEDI=2 runs swell_driver.csh (first cycle: obsonly, the observations for the ensemble); success requires the driver's .DONE file. CoupleAnaToGcm_: GEOSJEDI=2 with SWELL_IAU_OVERWRITE=1 and DO4DIAU=1, after the first cycle: ana4dupd.pl without -iau; the JEDI IAU, agcm09, ana09 and the central analysis of the ensemble come from swell_mkiau.csh/swell_upd4geos.csh. --- src/Applications/GEOSdas_App/GEOSdas.csm | 68 +++++++-- src/Applications/GEOSdas_App/fvsetup | 173 +++++++++++++++++++++++ 2 files changed, 230 insertions(+), 11 deletions(-) diff --git a/src/Applications/GEOSdas_App/GEOSdas.csm b/src/Applications/GEOSdas_App/GEOSdas.csm index f558dc23..a67386a9 100755 --- a/src/Applications/GEOSdas_App/GEOSdas.csm +++ b/src/Applications/GEOSdas_App/GEOSdas.csm @@ -80,7 +80,10 @@ # - Temporarily leaving test lines commented out # 8Dec2021 Sienkiewicz - add option for 'cleanup_tail' for aircraft bias correction # 3Dec2026 Yu - JEDI_AnalysisRun_: selected by GEOSJEDI (FVDAS_Run_Config), -# 1 = GEOSdas_App/jedi (jedi_driver.csh) +# 1 = GEOSdas_App/jedi (jedi_driver.csh), +# 2 = GEOSdas_App/swell (swell_driver.csh) +# - CoupleAnaToGcm_: with GEOSJEDI=2 and SWELL_IAU_OVERWRITE=1 (4D-IAU), no GSI +# IAU tendencies; the JEDI IAU (swell_mkiau.csh/swell_upd4geos.csh) drives the GCM #----------------------------------------------------------------------------- # @@ -3344,6 +3347,17 @@ endif if ( -e $FVHOME/run/AGCM.BOOTSTRAP.rc.tmpl ) then if ( "$GEOSJEDI" == "1" ) then exit (0) # only run from second cycle of experiment onwards + else if ( "$GEOSJEDI" == "2" ) then + # no central analysis (no cubed backgrounds yet), but this cycle's + # observations ($SWELL_OBS_SHARE) for the swell ensemble analysis + swell_driver.csh $gcm_nymd0 $gcm_nhms0 $ana_datetime[1] $ana_datetime[2] obsonly |& tee -a $drvlog + set jedi_rc = $status + if ( ! -e $FVWORK/.DONE_swell_driver.csh.obsonly.$ana_datetime[1]$this_hha ) set jedi_rc = 1 + if ( $jedi_rc ) then + echo "JEDI observations for the ensemble failed, aborting ..." + Call AbnormalExit_( 1 ) + endif + exit (0) # only run the analysis from second cycle of experiment onwards endif endif @@ -3358,6 +3372,10 @@ endif if ( "$GEOSJEDI" == "1" ) then jedi_driver.csh $gcm_nymd0 $gcm_nhms0 $ana_datetime[1] $ana_datetime[2] 0 |& tee -a $drvlog set jedi_rc = $status + else if ( "$GEOSJEDI" == "2" ) then + swell_driver.csh $gcm_nymd0 $gcm_nhms0 $ana_datetime[1] $ana_datetime[2] |& tee -a $drvlog + set jedi_rc = $status + if ( ! -e $FVWORK/.DONE_swell_driver.csh.$ana_datetime[1]$this_hha ) set jedi_rc = 1 endif if ( $jedi_rc ) then echo "JEDI analysis failed, aborting ..." @@ -3566,6 +3584,27 @@ endif if ( $DO4DIAU ) then # Perform 4D-analysis update (from GSI increments) & # generate 4D-GCM forcing terms (IAU tendencies) + # GEOSJEDI=2 with SWELL_IAU_OVERWRITE=1 (run/swell/swell_config.csh), after the + # first cycle: the JEDI analysis drives the GCM. GSI still makes its ana.eta, but + # no IAU tendencies; swell_mkiau.csh/swell_upd4geos.csh (JEDI_AnalysisRun_) make + # the IAU tendencies, agcm09/ana09 and the central analysis of the ensemble. + set jedi_iau = 0 + if ( $?GEOSJEDI ) then + if ( "$GEOSJEDI" == "1" ) then + # GEOSdas_App/jedi: GSI IAU tendencies as before + else if ( "$GEOSJEDI" == "2" ) then + if ( ! -e $FVHOME/run/AGCM.BOOTSTRAP.rc.tmpl && -e $FVHOME/run/swell/swell_config.csh ) then + set jedi_iau = `csh -fc 'source $FVHOME/run/swell/swell_config.csh; printenv SWELL_IAU_OVERWRITE'` + endif + endif + endif + if ( "$jedi_iau" != "1" ) set jedi_iau = 0 + set iauopt = ( -iau ) + if ( $jedi_iau ) then + set iauopt = ( ) + echo "CoupleAnaToGcm_: GEOSJEDI=2, SWELL_IAU_OVERWRITE=1: no GSI IAU, GEOS will use the JEDI IAU" + endif + #_RT if ( -e $anafile ) then #_RT # get original analysis out of the way (it will be re-created) #_RT /bin/mv $anafile $anafile.orig @@ -3580,7 +3619,7 @@ endif end endif - ana4dupd.pl -ncpus 7 -iau -iter $Viter_ -rcdir . $updrst0 \ + ana4dupd.pl -ncpus 7 $iauopt -iter $Viter_ -rcdir . $updrst0 \ $EXPID $beg_ana[1] $beg_ana[2] \ $end_ana[1] $end_ana[2] $ASYNBKG set my_status = $status @@ -3596,10 +3635,12 @@ endif end endif - set agcmfn = `echorc.x -template $EXPID $beg_ana[1] $beg_ana[2] iau_tendency_filename` - /bin/ln -sf $agcmfn agcm_import_rst + if ( ! $jedi_iau ) then + set agcmfn = `echorc.x -template $EXPID $beg_ana[1] $beg_ana[2] iau_tendency_filename` + /bin/ln -sf $agcmfn agcm_import_rst + endif - if ( ($HYBRIDGSI != "/dev/null") && (! -e $FVHOME/run/atmens_replay.acq) ) then + if ( ($HYBRIDGSI != "/dev/null") && (! -e $FVHOME/run/atmens_replay.acq) && (! $jedi_iau) ) then if ( $Final_ && ($STAGE4HYBGSI != "/dev/null") ) then rndasfiles -stage $STAGE4HYBGSI $EXPID ana.eta $beg_ana[1] $beg_ana[2] \ $end_ana[1] $end_ana[2] $ASYNBKG 99 @@ -3609,17 +3650,22 @@ endif endif # save ana/xinc files at end time-slot before these are overwritten by cycle - set ana09upa = `echorc.x -template $EXPID $end_ana[1] $end_ana[2] upper-air_ana09_filename` - set ana_upa = `echorc.x -template $EXPID $end_ana[1] $end_ana[2] upper-air_ana_filename` - /bin/cp $ana_upa $ana09upa + # (with the JEDI IAU, swell_upd4geos.csh saves the JEDI ana09 and agcm09) + if ( ! $jedi_iau ) then + set ana09upa = `echorc.x -template $EXPID $end_ana[1] $end_ana[2] upper-air_ana09_filename` + set ana_upa = `echorc.x -template $EXPID $end_ana[1] $end_ana[2] upper-air_ana_filename` + /bin/cp $ana_upa $ana09upa + endif set xinc09upa = `echorc.x -template $EXPID $end_ana[1] $end_ana[2] upper-air_xinc09_filename` set xinc_upa = `echorc.x -template $EXPID $end_ana[1] $end_ana[2] upper-air_xinc_filename` /bin/cp $xinc_upa $xinc09upa - set iau09inc = `echorc.x -template $EXPID $end_ana[1] $end_ana[2] iau09_tendency_filename` - set iau_inc = `echorc.x -template $EXPID $end_ana[1] $end_ana[2] iau_tendency_filename` - /bin/cp $iau_inc $iau09inc + if ( ! $jedi_iau ) then + set iau09inc = `echorc.x -template $EXPID $end_ana[1] $end_ana[2] iau09_tendency_filename` + set iau_inc = `echorc.x -template $EXPID $end_ana[1] $end_ana[2] iau_tendency_filename` + /bin/cp $iau_inc $iau09inc + endif else # Regular (3D) IAU diff --git a/src/Applications/GEOSdas_App/fvsetup b/src/Applications/GEOSdas_App/fvsetup index 17737244..937f9242 100755 --- a/src/Applications/GEOSdas_App/fvsetup +++ b/src/Applications/GEOSdas_App/fvsetup @@ -345,6 +345,8 @@ # 03Dec2026 Yu GEOSJEDI switch, from the environment and written to FVDAS_Run_Config: # 1 = JEDI (GEOSdas_App/jedi), 2 = JEDI via swell (GEOSdas_App/swell), # 3 and 4 reserved; -jedistatic option +# 03Dec2026 Yu GEOSJEDI=2: GEOS-JEDI prompts (get_jedi_info) and the swell layer +# (set_swell, swell_setup.pl) #------------------------------------------------------------------------- use Cwd qw(abs_path cwd); use English; @@ -397,6 +399,7 @@ my ($o_servers,$bckend_wrts, $xncpus, $ncpus_per_node); my ($skipgsi); my ($jedi_ensrpy, $jedi_exprpy); my ($geosjedi, $jedistatic); +my ($jedi_ens_scheme, $jedi_ens_member, $swell_venv, $swell_src, $jedi_build, $jedi_src); my ($sysfile, $nodeflg); my (@rmTilde); @@ -644,6 +647,16 @@ $ENV{"PATH"} = $FindBin::Bin .":$ENV{PATH}"; print "$cmd\n"; system($cmd); +# GEOS-JEDI options: these must be the last query() calls, so that older +# input files (which end before these prompts) replay unchanged +# ---------------------------------------------------------------------- + get_jedi_info(); + if ( $geosjedi eq 1 ) { + # GEOSdas_App/jedi was installed by set_geosjedi() (setup_aanajedi.pl) + } elsif ( $geosjedi eq 2 ) { + set_swell(); + } + # Save inputs # ----------- save_inputs(); @@ -3786,6 +3799,166 @@ sub set_geosjedi_1 { return 0 ; } + +#======================================================================= +# name - get_jedi_info +# purpose - GEOS-JEDI prompts +# +# Notes: +# 1. These must be the LAST query() calls in fvsetup, so that older input +# files (which end before these prompts) replay unchanged. +# 2. GEOSJEDI comes from the environment: it is shown as if answered, +# but it is neither read nor saved in the input file. +# 3. GEOSJEDI=1: no prompts (yet); GEOSdas_App/jedi keeps its own settings. +#======================================================================= +sub get_jedi_info { + my ($dflt); + + $jedi_ens_scheme = 1; # 1: EDA, 2: GETKF + $jedi_ens_member = 32; + $swell_venv = ""; + $swell_src = ""; + $jedi_build = ""; + $jedi_src = ""; + + if ( $geosjedi eq 1 ) { + # no GEOS-JEDI prompts for GEOSdas_App/jedi + } elsif ( $geosjedi eq 2 ) { + print <<"EOF"; + +----------------- +GEOS-JEDI Options +----------------- + + GEOSJEDI = 2:JEDI via swell, 1:JEDI or 0:GSI? $geosjedi (from the environment) +EOF + + $jedi_ens_scheme = query_jedi(" jedi_ens_scheme = 1:EDA or 2:GETKF?", $jedi_ens_scheme, + sub { $_[0] =~ /^[12]$/ }, + "jedi_ens_scheme must be 1 (EDA) or 2 (GETKF)"); + + $jedi_ens_member = query_jedi(" jedi_ens_member?", $jedi_ens_member, + sub { $_[0] =~ /^\d+$/ and $_[0] > 0 }, + "jedi_ens_member must be a positive integer"); + + $dflt = ( defined($ENV{"SWELL_VENV"}) ) ? $ENV{"SWELL_VENV"} : ""; + $swell_venv = query_jedi(" swell venv?", $dflt, + sub { $_[0] ne "" and -e "$_[0]/bin/activate.csh" and -x "$_[0]/bin/swell" }, + "no bin/activate.csh and bin/swell in the swell venv", 1); + + $dflt = ( defined($ENV{"SWELL_SRC"}) ) ? $ENV{"SWELL_SRC"} : ""; + $swell_src = query_jedi(" swell source directory?", $dflt, + sub { $_[0] ne "" and -d $_[0] }, + "swell source directory not found", 1); + + $dflt = ( defined($ENV{"SWELL_JEDI_BUILD"}) ) ? $ENV{"SWELL_JEDI_BUILD"} : ""; + $jedi_build = query_jedi(" JEDI build directory?", $dflt, + sub { $_[0] ne "" and -d "$_[0]/bin" and -e "$_[0]/CMakeCache.txt" }, + "no bin/ and CMakeCache.txt in the JEDI build directory", 1); + $jedi_src = jedi_source_dir($jedi_build); + } + return 0; +} + +#======================================================================= +# name - query_jedi +# purpose - query() and check the answer; a rejected answer is not saved +# in the input file; abort after 3 rejected answers (1 if runjob) +# +# Note: with $savefull, the answer is saved in full even when it is the +# default (e.g. a path offered from the environment) +#======================================================================= +sub query_jedi { + my ($prompt, $dflt, $check, $what, $savefull) = @_; + my ($ans, $try, $limit); + + $limit = ( $runjobFLG ) ? 1 : 3; + for $try (1..$limit) { + $ans = query($prompt, $dflt); + if ( &$check($ans) ) { + $fvANS1[$#fvANS1] = $ans if ( $savefull ); + return $ans; + } + + pop @fvprompt; pop @fvANS1; pop @fvANS2; + print "\n WARNING ($try/$limit): $what: '$ans'\n\n"; + } + die ">>> ERROR <<< $what: '$ans'\n"; +} + +#======================================================================= +# name - jedi_source_dir +# purpose - JEDI source directory of a JEDI build (its CMakeCache.txt) +#======================================================================= +sub jedi_source_dir { + my ($build) = @_; + my ($cache, $src, $home, $line); + + $cache = "$build/CMakeCache.txt"; + open(CACHE, "< $cache") or die ">>> ERROR <<< cannot read $cache: $!\n"; + while ( $line = ) { + $src = $1 if ( $line =~ /^jedi-bundle_SOURCE_DIR:\w+=(.*?)\s*$/ ); + $home = $1 if ( $line =~ /^CMAKE_HOME_DIRECTORY:\w+=(.*?)\s*$/ ); + } + close(CACHE); + $src = $home unless ( $src ); + die ">>> ERROR <<< no JEDI source directory found in $cache\n" unless ( $src and -d $src ); + return $src; +} + +#======================================================================= +# name - set_swell +# purpose - GEOSJEDI=2: install the swell layer (GEOSdas_App/swell/README.md): +# 3D-FGAT central analysis (swell_driver.csh, from GEOSdas.csm), +# JEDI IAU forcing, and the forecast acquiring that IAU +#======================================================================= +sub set_swell { + my ($cres, @set); + + die ">>> ERROR <<< GEOSJEDI=2 needs the JEDI static files: fvsetup -jedistatic DIR\n" + unless ( $jedistatic ); + die ">>> ERROR <<< JEDI static directory not found: $jedistatic\n" unless ( -d $jedistatic ); + if ( $hyb_ens >= 3 ) { + print "\n NOTE: GEOSJEDI=2: the central JEDI analysis is 3D-FGAT with climatological B\n" + . " (hybrid is not available through swell yet)\n\n"; + } + + $cres = $bjedi_im + 1; + die ">>> ERROR <<< no swell central analysis layout for C$bjedi_im backgrounds\n" + unless ( grep { $_ == $cres } ( 13, 25, 91, 181, 361, 721 ) ); + + @set = ( "SWELL_VENV=$swell_venv", + "SWELL_SRC=$swell_src", + "SWELL_JEDI_BUILD=$jedi_build", + "SWELL_JEDI_SRC=$jedi_src", + "SWELL_STATIC_FILES=$jedistatic", + "SWELL_CENTRAL_CRES=$cres" ); + push @set, "SWELL_SLURM_ACCOUNT=$gid" if ( $gid ); + if ( $skipgsi ) { + die ">>> ERROR <<< SKIPGSI: set OFFLINE_IODA_DIR, the IODA archive" + . " //geos_atmosphere\n" unless ( $ENV{"OFFLINE_IODA_DIR"} ); + push @set, "SWELL_OFFLINE_IODA_DIR=$ENV{OFFLINE_IODA_DIR}"; + } + + swell_setup( join(" ", map { "-set $_" } @set) + . " -mkiau $agcm_im," . 6*$agcm_im . ",$vres" + . " -rst4fcst $acqloc,$expid" ); + return 0; +} + +#======================================================================= +# name - swell_setup +# purpose - run swell_setup.pl for this experiment +#======================================================================= +sub swell_setup { + my ($args) = @_; + my ($cmd); + + $cmd = "$fvbin/swell_setup.pl -fvhome $fvhome -fvroot $fvroot $args"; + print "$cmd\n"; + system($cmd) == 0 or die ">>> ERROR <<< swell_setup.pl failed\n"; +} + #======================================================================= sub set_atmens { my ($radbc, $src_arcdir, $prompt, $dflt); From 5d5e7cdd35671b99e1a5807867a3f256476a902e Mon Sep 17 00:00:00 2001 From: Yonggang Yu Date: Thu, 3 Dec 2026 01:36:20 -0500 Subject: [PATCH 4/4] GEOSJEDI=2: ensemble analysis through swell, without atm_ens.j - swell/swell_ens.j (new, installed to bin): the GEOSJEDI=2 ensemble job. It is atm_ens.j without the GSI observer/EnKF and the GEOSJEDI=1 ensemble; the ensemble analysis is swell_ana_atmens.csh, all other steps call the same NCEP_enkf scripts, unchanged. No EDAS scheduler, eanaonly or ensemble-only runs. NCEP_Etc is not changed. - fvsetup: set_swell_atmens (GEOSJEDI=2, hyb_ens >= 3): SWELL_ENSEMBLE (eda, getkf2), SWELL_ENS_CRES and SWELL_ENS_NMEM in run/swell/swell_exp.csh; the cubed member backgrounds of the initial ensemble from the archive of the ensemble restarts (swell_setup.pl -ebkgx); run/swell_ens.j filled in as atm_ens.j. jedi_ens_member defaults to the installed members and must match them. DAS job: submits run/swell_ens.j in place of run/atm_ens.j when GEOSJEDI=2 (FVDAS_Run_Config). - swell_setup.pl: -ebkgx EXPARCDIR,EXPID,YYYYMMDD,HH restores atmens/ensbkgx/memNNN from .atmens_ebkgx..tar. - swell_ana_atmens.csh: abort if the members differ from SWELL_ENS_NMEM. --- src/Applications/GEOSdas_App/fvsetup | 83 ++- .../GEOSdas_App/swell/CMakeLists.txt | 2 +- src/Applications/GEOSdas_App/swell/README.md | 38 +- .../GEOSdas_App/swell/etc/swell_config.csh | 7 +- .../GEOSdas_App/swell/swell_ana_atmens.csh | 12 +- .../GEOSdas_App/swell/swell_ens.j | 562 ++++++++++++++++++ .../GEOSdas_App/swell/swell_setup.pl | 69 ++- 7 files changed, 753 insertions(+), 20 deletions(-) create mode 100644 src/Applications/GEOSdas_App/swell/swell_ens.j diff --git a/src/Applications/GEOSdas_App/fvsetup b/src/Applications/GEOSdas_App/fvsetup index 937f9242..fbc9c258 100755 --- a/src/Applications/GEOSdas_App/fvsetup +++ b/src/Applications/GEOSdas_App/fvsetup @@ -347,6 +347,8 @@ # 3 and 4 reserved; -jedistatic option # 03Dec2026 Yu GEOSJEDI=2: GEOS-JEDI prompts (get_jedi_info) and the swell layer # (set_swell, swell_setup.pl) +# 03Dec2026 Yu GEOSJEDI=2: swell ensemble analysis (set_swell_atmens); the DAS job +# submits run/swell_ens.j in place of atm_ens.j #------------------------------------------------------------------------- use Cwd qw(abs_path cwd); use English; @@ -400,6 +402,7 @@ my ($skipgsi); my ($jedi_ensrpy, $jedi_exprpy); my ($geosjedi, $jedistatic); my ($jedi_ens_scheme, $jedi_ens_member, $swell_venv, $swell_src, $jedi_build, $jedi_src); +my ($aens_src_arcdir); my ($sysfile, $nodeflg); my (@rmTilde); @@ -655,6 +658,7 @@ $ENV{"PATH"} = $FindBin::Bin .":$ENV{PATH}"; # GEOSdas_App/jedi was installed by set_geosjedi() (setup_aanajedi.pl) } elsif ( $geosjedi eq 2 ) { set_swell(); + set_swell_atmens() if ( $hyb_ens >= 3 ); } # Save inputs @@ -3812,7 +3816,7 @@ sub set_geosjedi_1 { # 3. GEOSJEDI=1: no prompts (yet); GEOSdas_App/jedi keeps its own settings. #======================================================================= sub get_jedi_info { - my ($dflt); + my ($dflt, @enslist); $jedi_ens_scheme = 1; # 1: EDA, 2: GETKF $jedi_ens_member = 32; @@ -3837,6 +3841,12 @@ EOF sub { $_[0] =~ /^[12]$/ }, "jedi_ens_scheme must be 1 (EDA) or 2 (GETKF)"); + @enslist = (<$fvhome/atmens/mem???>); + if ( scalar(@enslist) > 0 ) { + $jedi_ens_member = scalar(@enslist); + } elsif ( $atm_nens_input ) { + $jedi_ens_member = $atm_nens_input; + } $jedi_ens_member = query_jedi(" jedi_ens_member?", $jedi_ens_member, sub { $_[0] =~ /^\d+$/ and $_[0] > 0 }, "jedi_ens_member must be a positive integer"); @@ -3946,6 +3956,61 @@ sub set_swell { return 0; } +#======================================================================= +# name - set_swell_atmens +# purpose - GEOSJEDI=2: swell ensemble analysis (swell_ana_atmens.csh), run by +# $FVHOME/run/swell_ens.j, which the DAS job submits in place of +# atm_ens.j; jedi_ens_scheme 1 (EDA) -> eda_atmos, +# 2 (GETKF) -> localensembleda_2steps +#======================================================================= +sub set_swell_atmens { + my ($cres, %method, @enslist, $nens, $args, $src, $dst, $line, $strvar); + + if ( $aens_replay eq "yes" ) { + print "\n Replayed ensemble: no swell ensemble analysis to set up\n\n"; + return 0; + } + + $cres = $aens_im + 1; + die ">>> ERROR <<< no swell ensemble analysis layout for a $aens_res ensemble\n" + unless ( $aens_ocn eq "C" and grep { $_ == $cres } ( 13, 25, 91, 181 ) ); + + @enslist = (<$fvhome/atmens/mem???>); + $nens = scalar(@enslist); + if ( $nens > 0 and $nens != $jedi_ens_member ) { + die ">>> ERROR <<< $nens ensemble members installed in $fvhome/atmens," + . " but jedi_ens_member = $jedi_ens_member\n"; + } + + %method = ( 1 => "eda", 2 => "getkf2" ); + $args = "-set SWELL_ENSEMBLE=$method{$jedi_ens_scheme}" + . " -set SWELL_ENS_CRES=$cres" + . " -set SWELL_ENS_NMEM=$jedi_ens_member"; + if ( $aens_src_arcdir ) { + $args .= " -ebkgx $aens_src_arcdir,$expid,$nymdb,$hhb"; + } else { + print "\n NOTE: with the ensemble restarts installed later, also provide the cubed member\n" + . " backgrounds in $fvhome/atmens/ensbkgx/memNNN (swell ensemble analysis)\n\n"; + } + swell_setup($args); + + # ensemble job script, filled in as atm_ens.j (set_atmens) + $src = "$fvbin/swell_ens.j"; + $dst = "$fvhome/run/swell_ens.j"; + open(TMPL, "< $src") or die ">>> ERROR <<< cannot read $src: $!\n"; + open(JOB, "> $dst") or die ">>> ERROR <<< cannot write $dst: $!\n"; + while ( $line = ) { + foreach $strvar ( keys %replace ) { $line =~ s/$strvar/$replace{$strvar}/g } + die ">>> ERROR <<< unresolved placeholder in $src: $line" if ( $line =~ />>>\w+<<` in `FVDAS_Run_Config`, so a `GEOSJEDI` exported in the shell that submits the job does not matter. An @@ -70,6 +71,10 @@ The three paths have no built-in default (`$SWELL_VENV`, `$SWELL_SRC` and if ( ! $?SWELL_STATIC_FILES ) setenv SWELL_STATIC_FILES <-jedistatic DIR> if ( ! $?SWELL_CENTRAL_CRES ) setenv SWELL_CENTRAL_CRES 91 if ( ! $?SWELL_SLURM_ACCOUNT ) setenv SWELL_SLURM_ACCOUNT + # with the ensemble on (hyb_ens >= 3): + if ( ! $?SWELL_ENSEMBLE ) setenv SWELL_ENSEMBLE eda (jedi_ens_scheme 1; 2: getkf2) + if ( ! $?SWELL_ENS_CRES ) setenv SWELL_ENS_CRES 91 + if ( ! $?SWELL_ENS_NMEM ) setenv SWELL_ENS_NMEM `swell_config.csh` reads it ahead of its own defaults: environment > `swell_exp.csh` > `swell_config.csh`; @@ -77,6 +82,17 @@ The three paths have no built-in default (`$SWELL_VENV`, `$SWELL_SRC` and - `fcst/rst4fcst.acq` acquires the JEDI IAU (`jedi_agcmrst`) in place of the GSI IAU (`agcm_import_rst`); the restart line stays. +With the ensemble on, also: + +- `$FVHOME/run/swell_ens.j`: from `$FVROOT/bin/swell_ens.j`, filled in as `atm_ens.j`; + the DAS job submits it in place of `atm_ens.j`; +- `$FVHOME/atmens/ensbkgx/memNNN`: the cubed member backgrounds of the initial + ensemble, from `/atmens/Y%Y/M%m/.atmens_ebkgx..tar` of the + experiment archive given for the ensemble restarts (`swell_setup.pl -ebkgx`); + with the restarts installed later, they have to be provided by hand; +- `jedi_ens_member` (default: the number of installed members) must match the + members in `$FVHOME/atmens`. + The central analysis is 3D-FGAT with climatological B, also when the ensemble is on (`hyb_ens >= 3`; hybrid through swell is still to come). `SKIPGSI` needs `OFFLINE_IODA_DIR` (→ `SWELL_OFFLINE_IODA_DIR`). @@ -140,7 +156,15 @@ tars below keep the names of the jedi layer, so the archive rules are unchanged. Processor layout and GSIBEC grid follow from `SWELL_CENTRAL_CRES` (table in `swell_ana_central.csh`; any `SWELL_CENTRAL_*` already set wins). -## Ensemble analysis data flow (swell_ana_atmens.csh) +## Ensemble analysis (swell_ens.j, swell_ana_atmens.csh) + +`swell_ens.j` is `atm_ens.j` (`NCEP_Etc/NCEP_enkf/scripts/gmao`) without the GSI +observer and EnKF analysis and without the `GEOSJEDI=1` ensemble; all other steps +(AOD, LDAS, inflation, `post_eana.csh` recentering, `atmos_ens2gcm.csh`, +`gcm_ensemble.csh`, `post_egcm.csh`, archiving, resubmitting the DAS job) call the +same `NCEP_enkf` scripts, unchanged. `ATMENS_ENSQRF=0` (no observer, no OmA +statistics). Not supported: the EDAS scheduler, `eanaonly` and ensemble-only runs. +The swell ensemble analysis runs from the first cycle on. | | | |---|---| diff --git a/src/Applications/GEOSdas_App/swell/etc/swell_config.csh b/src/Applications/GEOSdas_App/swell/etc/swell_config.csh index 7843c36a..cac9822f 100644 --- a/src/Applications/GEOSdas_App/swell/etc/swell_config.csh +++ b/src/Applications/GEOSdas_App/swell/etc/swell_config.csh @@ -119,10 +119,11 @@ endif if ( ! $?SWELL_OBS_SHARE_KEEP ) setenv SWELL_OBS_SHARE_KEEP 4 # --------------------------------------------------------------------------- -# Ensemble analysis (GEOSJEDI=2: atm_ens.j runs swell_ana_atmens.csh) +# Ensemble analysis (GEOSJEDI=2: swell_ens.j runs swell_ana_atmens.csh) # --------------------------------------------------------------------------- -# none: GSI EnKF; eda: eda_atmos; getkf: localensembleda; -# getkf2: localensembleda_2steps +# SWELL_ENSEMBLE (swell_exp.csh; fvsetup jedi_ens_scheme 1 -> eda, 2 -> getkf2): +# eda: eda_atmos; getkf: localensembleda; getkf2: localensembleda_2steps; +# none: no ensemble analysis (no hybrid ensemble) if ( ! $?SWELL_ENSEMBLE ) setenv SWELL_ENSEMBLE none # SWELL_ENS_CRES (swell_exp.csh): cubed-sphere resolution of the ensemble backgrounds diff --git a/src/Applications/GEOSdas_App/swell/swell_ana_atmens.csh b/src/Applications/GEOSdas_App/swell/swell_ana_atmens.csh index 21c8b9df..ffacb8d0 100644 --- a/src/Applications/GEOSdas_App/swell/swell_ana_atmens.csh +++ b/src/Applications/GEOSdas_App/swell/swell_ana_atmens.csh @@ -7,8 +7,9 @@ # nymdb nhmsb beginning of the analysis window # nymda nhmsa analysis time (middle of the window) # -# Replaces jedi_driver_atmens.csh. Method from SWELL_ENSEMBLE, and the lat-lon member -# increments (analysis/memNNN/.inc.eta..nc4) it gives: +# Called by swell_ens.j (GEOSJEDI=2); replaces jedi_driver_atmens.csh. Method from +# SWELL_ENSEMBLE, and the lat-lon member increments (analysis/memNNN/.inc.eta..nc4) +# it gives: # eda swell eda_atmos made here: analysis - background (fv3jedi_diffstates.x), # since swell writes the member analyses # (eda_atmos.ana.ceta..nc4) on the cubed sphere only @@ -145,6 +146,13 @@ if ( $#members == 0 ) then echo "${myname}: no member directories in $ATMENSLOC, aborting" exit 1 endif +# SWELL_ENS_NMEM (swell_exp.csh, fvsetup jedi_ens_member) must match the installed members +if ( $?SWELL_ENS_NMEM ) then + if ( "$SWELL_ENS_NMEM" != "$#members" ) then + echo "${myname}: $#members member directories in $ATMENSLOC, but SWELL_ENS_NMEM=$SWELL_ENS_NMEM, aborting" + exit 1 + endif +endif setenv SWELL_ENS_NMEM $#members echo "${myname}: $SWELL_ENSEMBLE ($suite), $#members members, C$SWELL_ENS_CRES layout ${SWELL_ENS_NPX}x${SWELL_ENS_NPY}x6 = $ntasks tasks on $nodes node(s)" diff --git a/src/Applications/GEOSdas_App/swell/swell_ens.j b/src/Applications/GEOSdas_App/swell/swell_ens.j new file mode 100644 index 00000000..c02688b1 --- /dev/null +++ b/src/Applications/GEOSdas_App/swell/swell_ens.j @@ -0,0 +1,562 @@ +#!/bin/csh -fx +# ------------------------------ +#SBATCH --account=>>>GID<<< +#SBATCH --constraint=>>>NODEFLG<<< +#SBATCH --ntasks=96 +#SBATCH --ntasks-per-node=>>>NCPUS_PER_NODE<<< +#SBATCH --time=6:00:00 +#SBATCH --no-requeue +# +#SBATCH --job-name=swell_ens +#SBATCH --output=swell_ens.log.o%j +#PBS -N swell_ens +#PBS -o swell_ens.log.o%j +#PBS -l walltime=6:00:00 +#PBS -S /bin/csh +#PBS -j eo +# ------------------------------ +# +# EnADAS driver script for GEOSJEDI=2: the ensemble analysis is JEDI through +# swell (swell_ana_atmens.csh, GEOSdas_App/swell). +# +# This file has been automatically generated by fvsetup from $FVROOT/bin/swell_ens.j. +# The DAS job submits it in place of atm_ens.j when GEOSJEDI=2 (FVDAS_Run_Config). +# +# It is atm_ens.j (NCEP_Etc/NCEP_enkf/scripts/gmao) without the GSI observer and +# EnKF analysis and without the GEOSJEDI=1 (GEOSdas_App/jedi) ensemble analysis; +# all other steps call the same NCEP_enkf scripts, unchanged. Not supported: the +# EDAS scheduler (${EXPID}_scheduler.j), eanaonly and ensemble-only runs. +# + +#-------------------------------------------------------------------- + set myname = `basename $0` + +# Source Run Time Environment settings +# ------------------------------------ + setenv EXPID >>>EXPID<<< # experiment ID + setenv FVHOME >>>FVHOME<<< # experiment home directory + if (-e $FVHOME/run/FVDAS_Run_Config) then + source $FVHOME/run/FVDAS_Run_Config + else + echo "swell_ens.j: cannot find $FVHOME/run/FVDAS_Run_Config, aborting ..." + exit(1) + endif + +# GEOSJEDI=2 only, with a swell ensemble analysis set up by fvsetup +# ----------------------------------------------------------------- + if ( ! $?GEOSJEDI ) setenv GEOSJEDI 0 + if ( "$GEOSJEDI" != "2" ) then + echo "swell_ens.j: GEOSJEDI=$GEOSJEDI; this ensemble job is for GEOSJEDI=2 only, aborting ..." + exit(1) + endif + if ( -e $FVHOME/run/${EXPID}_scheduler.j ) then + echo "swell_ens.j: the EDAS scheduler is not supported with GEOSJEDI=2, aborting ..." + exit(1) + endif + if ( ! -e $FVHOME/run/swell/swell_config.csh ) then + echo "swell_ens.j: cannot find $FVHOME/run/swell/swell_config.csh, aborting ..." + exit(1) + endif + source $FVHOME/run/swell/swell_config.csh + if ( "$SWELL_ENSEMBLE" == "none" ) then + echo "swell_ens.j: no swell ensemble analysis (SWELL_ENSEMBLE=none), aborting ..." + exit(1) + endif + +# tell which side of the machine we are on ... + uname -a + + env + +# +# ---------------------------------- +# PART I - Prepare the Environment +# ---------------------------------- + +# Experiment environment +# ---------------------- +# setenv JOBGEN_PARTITION preops +# setenv JOBGEN_QOS dastest +# setenv JOBGEN_ARCH_CONSTRAINT cssrw + setenv JOBGEN_CONSTRAINT >>>NODEFLG<<< +# setenv JOBGEN_NCPUS_PER_NODE >>>NCPUS_PER_NODE<<< + setenv ATMENS_QNAME compute + if ( $?JOBGEN_PARTITION ) then + setenv ATMENS_QNAME $JOBGEN_PARTITION + endif + setenv BATCH_SUBCMD sbatch + setenv GID >>>GID<<< + setenv group_list "SBATCH -A $GID" + setenv ARCH `uname -s` + setenv HOST `uname -n` + setenv CASE $EXPID # experiment ID (for LSM's sake) + setenv FVROOT `cat $FVHOME/.FVROOT` + setenv FVRUN $FVHOME/run + setenv BIGNAME `echo "$EXPID" | tr '[:lower:]' '[:upper:]'` + if( (`uname -s` == "Linux") ) then + if( `uname -m` != "ia64" ) then + setenv FORT90L -Wl,-T + endif + setenv FVWORK $FVHOME/../enswork.$BIGNAME + endif + /bin/mkdir -p $FVWORK # create working directory + echo $FVWORK >! $FVHOME/.ENSWORK # record working directory + + setenv FVBCS $FVHOME/fvInput + setenv EXTDATA $FVWORK/ExtData # External data directory + /bin/mkdir -p $EXTDATA + /bin/touch $EXTDATA/.no_archiving + /bin/rm -f $EXTDATA/chemistry + /bin/ln -s /discover/nobackup/projects/gmao/share/gmao_ops/fvInput_4dvar/chemistry $EXTDATA/ + /bin/rm -f $EXTDATA/g5chem + /bin/ln -s /discover/nobackup/projects/gmao/share/gmao_ops/fvInput_4dvar/g5chem $EXTDATA/ + /bin/rm -f $EXTDATA/g5gcm + /bin/ln -s /discover/nobackup/projects/gmao/share/gmao_ops/fvInput_4dvar/g5gcm $EXTDATA/ + /bin/rm -f $EXTDATA/PIESA + /bin/ln -s /discover/nobackup/projects/gmao/share/gmao_ops/fvInput_4dvar/PIESA $EXTDATA/ + /bin/rm -f $EXTDATA/MERRA2 + /bin/ln -s /discover/nobackup/projects/gmao/share/gmao_ops/fvInput_4dvar/MERRA2 $EXTDATA/ + /bin/rm -f $EXTDATA/AeroCom + /bin/ln -s /discover/nobackup/projects/gmao/share/gmao_ops/fvInput_4dvar/AeroCom $EXTDATA/ + /bin/rm -f $EXTDATA/enAdas + /bin/ln -s /discover/nobackup/projects/gmao/share/gmao_ops/fvInput_4dvar/enAdas $EXTDATA/ + +# Load BASEDIR and modules +# ------------------------ + source $FVROOT/bin/g5_modules + +# Add FVROOT/bin to front of path so fvDAS binaries are found first +# ----------------------------------------------------------------- + if ( `uname -s` == "Linux" ) then + set path = ( . $FVHOME/run $FVROOT/bin /share/dasilva/opengrads/Contents $BASEDIR/$ARCH/bin $path ) + else + set path = ( . $FVHOME/run $FVROOT/bin /share/dasilva/opengrads/Contents $path ) + endif + +# A bit sad that this needs to be here instead of set in the env +# -------------------------------------------------------------- + if ( -e /etc/os-release ) then + setenv PERL5LIB /usr/lib/perl5/5.18.2/CPAN + endif + +# MPI/OpenMP Hybrid Options +# ------------------------- + if ($?I_MPI_ROOT) then + setenv ATMENS_MPIRUN "mpirun " + else + setenv ATMENS_MPIRUN "mpiexec_mpt " + endif + +# For reproducibility between Westmere and Sandybridge nodes +# ---------------------------------------------------------- + setenv MV2_USE_SHMEM_ALLREDUCE 0 + setenv MV2_ON_DEMAND_THRESHOLD 8192 + setenv MKL_CBWR SSE4_2 + +# Regular DAS env vars +# -------------------- + setenv TIMEINC 360 # analysis frequency in minutes (script not general enough for this to be anything) + setenv ASYNBKG 180 # background frequency in minutes (script not general enough for this to be anything) + setenv VAROFFSET 180 # abs value of time off from 1st synoptic hour of var window + setenv NCSUFFIX nc4 + setenv NCEPINPUT $FVBCS + setenv SPECRES 254 # should be able to revisit analyzer to avoid needing this + + setenv GAAS_ANA 1 + setenv LDAS_ANA >>>LDAS_ANA<<< + setenv LDHOME4ENS >>>LDHOME4ENS<<< + + +# Run-time mpi-related options +# ---------------------------- + setenv DAPL_ACK_RETRY 7 + setenv DAPL_ACK_TIMER 20 + setenv DAPL_RNR_RETRY 7 + setenv DAPL_RNR_TIMER 28 + setenv I_MPI_MPD_TMPDIR /tmp + setenv I_MPI_USE_DYNAMIC_CONNECTIONS 0 + setenv I_MPI_JOB_STARTUP_TIMEOUT 10000 + setenv I_MPI_RDMA_RNDV_WRITE 1 + +# MVAPICH variables +# ----------------- + setenv MPI_COLL_REPRODUCIBLE + setenv SLURM_DISTRIBUTION block + setenv MPI_DISPLAY_SETTINGS + +# For some reason, PMI_RANK is randomly set and interferes +# with binarytile.x and other executables. + unsetenv PMI_RANK + + setenv MPI_COMM_MAX 1024 + setenv MPI_GROUP_MAX 1024 + setenv MPI_BUFS_PER_PROC 256 + +# Internal parameters controlling system behavior +# ---------------------------------------------- + source $FVHOME/run/atmens/AtmEnsConfig.csh + + if ( !($?ATMENS_BATCHSUB) ) then + echo "swell_ens.j: missing batch sub command" + exit (1) + endif +# The following release any settings by the central ADAS +# related to overwritting the climatological error cov + if ( $?BERROR_FROMENS ) then + unsetenv BERROR_FROMENS + endif + if ( $?BERROR ) then + unsetenv BERROR + endif + setenv HYBRIDGSI $ATMENSLOC + setenv STAGE4HYBGSI $HYBRIDGSI/central # set to /dev/null to not recenter + touch $ATMENSLOC/.no_archiving + +# No GSI observer: no observation-space (OmA) statistics in post_eana.csh +# ----------------------------------------------------------------------- + setenv ATMENS_ENSQRF 0 + +# Make sure files are accessible +# ------------------------------ + umask 022 + +# Discover specific configuration +# ---------------------------- + limit stacksize unlimited + limit coredumpsize 0 + setenv KMP_STACKSIZE 450m + unsetenv F_UFMTENDIAN + setenv KMP_LIBRARY turnaround + +# Get date/time from restarts +# --------------------------- + set nymdb = `echo $RSTSTAGE4AENS/$EXPID.rst.lcv.????????_??z.bin | cut -d. -f4 | cut -c1-8` + set hhb = `echo $RSTSTAGE4AENS/$EXPID.rst.lcv.????????_??z.bin | cut -d. -f4 | cut -c10-11` + set ddb = `echo $nymdb | cut -c7-8` + set nhmsb = ${hhb}0000 + set yyyymmddhh = ${nymdb}${hhb} + @ anafreq_sc = $TIMEINC * 60 + +# Define prefix and suffix of job names + setenv JOBGEN_PFXNAME e1 + setenv JOBGEN_SFXNAME ${ddb}_${hhb}z + if ( $?PBS_JOBID ) then + qalter -N ${JOBGEN_PFXNAME}_swell_ens_${JOBGEN_SFXNAME} $PBS_JOBID + else + if ( $?SLURM_JOBID ) then + qalter -N ${JOBGEN_PFXNAME}_swell_ens_${JOBGEN_SFXNAME} $SLURM_JOBID + else + echo "no JOBID found, abort" + exit(1) + endif + endif + +# Calculate corresponding analysis time (need care for 4dvar) +# ------------------------------------- + @ varoffset_sc = $VAROFFSET * 60 + set anadate = `tick $nymdb $nhmsb $varoffset_sc` + set anymd = $anadate[1] + set anhms = $anadate[2] + set ahh = `echo ${anhms} | cut -c1-2` + + set members = `ls -d $HYBRIDGSI/mem* | wc` + set nmem = $members[1] + +# Get positioned in work area +# --------------------------- + cd $FVWORK + if ( -e .FAILED ) then + echo " Main: clearing past FAILURE " + /bin/rm .FAILED + endif + +# When applicable, launch forecast for desired time +# ------------------------------------------------- + if ( ($?FCSTIMES) ) then + set crstag = ${nymdb}_${hhb}z + foreach fctime ( $FCSTIMES ) + set fcstdtag = {$nymdb}_${fctime}z + if ( $fcstdtag == $crstag ) then + cd $FVHOME/fcst + echo "launching forecast for: $FVHOME/fcst/forecast.$fcstdtag" + touch forecast.$fcstdtag + $ATMENS_BATCHSUB g5fcst.j + cd - + endif + end + endif + +# Retrieve existing random perturbations (enables for reproducibility) +# -------------------------------------------------------------------- + set lst = (`ls $ATMENSLOC/*rndperts.dates*txt` ) + if ( ! $%lst ) then + if ( -e $ATMENSETC/given_rndperts.acq ) then + if ( ! -e $FVWORK/.DONE_MEM001_GETRNDPERTS.$yyyymmddhh) then + if(! -d $STAGE4HYBGSI ) mkdir -p $STAGE4HYBGSI + set spool = "-s $FVWORK/spool" + jobgen.pl \ + -q datamove \ + getrndperts \ + $GID \ + $OBSVR_WALLCLOCK \ + "acquire -v -strict -rc $ATMENSETC/given_rndperts.acq -d $STAGE4HYBGSI $spool -ssh $anymd $anhms 060000 1" \ + $STAGE4HYBGSI \ + $myname \ + $FVWORK/.DONE_MEM001_GETRNDPERTS.$yyyymmddhh \ + "Main job script Failed for Get Central Analysis" + + if ( -e getrndperts.j ) then + if ( $ATMENS_BATCHSUB == "sbatch" ) then + $ATMENS_BATCHSUB -W getrndperts.j + else + $ATMENS_BATCHSUB -W block=true getrndperts.j + endif + touch .SUBMITTED + else + echo " ${myname}: Failed for Get Rnd-Perturbations, Aborting ... " + touch $FVWORK/.FAILED + exit(1) + endif + endif + set lst = (`ls $STAGE4HYBGSI/*rndperts.dates*txt` ) + if ( $%lst ) then + if ( $#lst == 1 ) then + /bin/mv $STAGE4HYBGSI/*rndperts.dates*txt $ATMENSLOC + else + ls $STAGE4HYBGSI/*rndperts.dates*txt + echo "Main: too many rndperts-dates files found, aborting." + exit(1) + endif + else + echo "Main: failed in retrieve rndperts-dates file, aborting." + exit(1) + endif + endif + endif + +# In case additive inflation, prepare the perturbations +# ----------------------------------------------------- + if ( -e $ATMENSETC/nmcperts.rc ) then + setperts.csh ${EXPID} $nmem $anymd $anhms $TIMEINC $AENSADDINFLOC |& tee -a $FVWORK/setperts.log & + if ($status) then + echo "Main: failed in setperts.csh, aborting." + exit(1) + endif + endif + +# In case central analysis located elsewhere (other than FVHOME/atmens/central) +# ------------------------------------------ + if ( -e $ATMENSETC/central_ana.rc ) then + if ( ! -e $FVWORK/.DONE_MEM001_GETCENTRAL.$yyyymmddhh) then + if(! -d $STAGE4HYBGSI ) mkdir -p $STAGE4HYBGSI + set spool = "-s $FVWORK/spool" + jobgen.pl \ + -q datamove \ + getcentral \ + $GID \ + $OBSVR_WALLCLOCK \ + "acquire -v -strict -rc $ATMENSETC/central_ana.rc -d $STAGE4HYBGSI $spool -ssh $anymd $anhms 060000 1" \ + $STAGE4HYBGSI \ + $myname \ + $FVWORK/.DONE_MEM001_GETCENTRAL.$yyyymmddhh \ + "Main job script Failed for Get Central Analysis" + + if ( -e getcentral.j ) then + if ( $ATMENS_BATCHSUB == "sbatch" ) then + $ATMENS_BATCHSUB -W getcentral.j + else + $ATMENS_BATCHSUB -W block=true getcentral.j + endif + touch .SUBMITTED + else + echo " ${myname}: Failed for Get Central Analysis, Aborting ... " + touch $FVWORK/.FAILED + exit(1) + endif + endif + endif + +# Member backgrounds in the work area (in place of the GSI observer) +# ------------------------------------------------------------------ + cd $FVWORK + @ ic = 1 + while ( $ic <= $nmem ) + set memtag = `echo $ic |awk '{printf "%03d", $1}'` + if ( ! -d mem$memtag ) then + mkdir mem$memtag + /bin/ln -sf $FVHOME/atmens/mem$memtag/$EXPID.bkg.eta.*.$NCSUFFIX mem$memtag/ + endif + @ ic++ + end + +# Run AOD analysis (or proxy of that) +# NOTE: wired time frequency for now +# ----------------------------------- + if ( $GAAS_ANA ) then + zeit_ci.x eaod + atmos_eaod.csh $EXPID $anymd $anhms 030000 |& tee -a swell_ens.log + if( $status) then + echo "eaod failed" + exit(1) + endif + zeit_co.x eaod + endif + +# LDAS ens analysis at ens gcm resolution +# ----------------------------------- + if ( $LDAS_ANA ) then + zeit_ci.x eldas + atmos_eldas.csh $EXPID $anymd $anhms 060000 |& tee -a swell_ens.log + if( $status) then + echo "eldas failed" + exit(1) + endif + zeit_co.x eldas + endif + +# Run ensemble of atmospheric analyses: JEDI through swell +# -------------------------------------------------------- + zeit_ci.x eana + swell_ana_atmens.csh $nymdb $nhmsb $anymd $anhms |& tee -a swell_ens.log + set eana_rc = $status + if ( ! -e $FVWORK/.DONE_swell_ana_atmens.csh.${anymd}${ahh} ) set eana_rc = 1 + if ( $eana_rc ) then + echo "eana (swell_ana_atmens.csh) failed" + exit(1) + endif + zeit_co.x eana + +# SAVING ENSEMBLE ANALYSES BEFORE RECENTERING AND INFLATION +# --------------------------------------------------------- + cd $FVWORK/updated_ens + if ( $ATMENS_SAVE_BREC ) then + if(! -e $HYBRIDGSI/${EXPID}.atmens_eana_brec.${nymdb}_${hhb}z.tar ) then + tar -cvf $HYBRIDGSI/${EXPID}.atmens_eana_brec.${nymdb}_${hhb}z.tar mem0*/*.ana.eta*nc4 + endif + endif + cd $FVWORK + +# Apply additive inflation +# ------------------------ + if ( $AENS_ADDINFLATION && -e $ATMENSETC/nmcperts.rc ) then + set ayyyymmddhh = ${anymd}${ahh} + jobmonitor.csh 1 setperts.csh $FVWORK $ayyyymmddhh + wait # for setperts to complete + endif + +# Calculate post-analysis ensemble statistics +# ------------------------------------------- + zeit_ci.x post_eana + post_eana.csh $EXPID $anymd $anhms spread |& tee -a swell_ens.log + if( $status) then + echo "post_eana failed" + exit(1) + endif + zeit_co.x post_eana + +# Save analyses after recentering +# ------------------------------- + cd $FVWORK/updated_ens + if ( $ATMENS_SAVE_AREC ) then + if(! -e $HYBRIDGSI/${EXPID}.atmens_eana_arec.${nymdb}_${hhb}z.tar ) then + tar -cvf $HYBRIDGSI/${EXPID}.atmens_eana_arec.${nymdb}_${hhb}z.tar mem0*/*.ana.eta*nc4 + endif + endif + cd $FVWORK + +# Calculate IAU-related forcing terms +# ----------------------------------- + zeit_ci.x ens2gcm + if ( $ATMENS_DO4DIAU ) then + atmos_ens2gcm.csh $EXPID $nymdb $nhmsb |& tee -a swell_ens.log + set e2g_rc = $status + else + atmos_ens2gcm.csh $EXPID $anymd $anhms |& tee -a swell_ens.log + set e2g_rc = $status + endif + if( $e2g_rc ) then + echo "ens2gcm failed" + exit(1) + endif + zeit_co.x ens2gcm + +# Run ensemble of atmospheric GCMs +# --------------------------------- + # RT: I don't like this way of determining the dimension, but so be it for now + if ( -e $FVHOME/atmens/ensmean/$EXPID.bkg.eta.${nymdb}_${hhb}00z.$NCSUFFIX ) then + zeit_ci.x gcm_ens + set ens_mres = `getgfiodim.x $FVHOME/atmens/ensmean/$EXPID.bkg.eta.${nymdb}_${hhb}00z.$NCSUFFIX` + set ens_nlons = $ens_mres[1] + set ens_nlats = $ens_mres[2] + @ tfcst_hh = 2 * $TIMEINC / 60 + gcm_ensemble.csh $EXPID $nymdb $nhmsb $tfcst_hh $ens_nlons $ens_nlats |& tee -a swell_ens.log + if( $status) then + echo "gcm_ensemble failed" + exit(1) + endif + zeit_co.x gcm_ens + else + echo "cannot find $ATMENSLOC/ensmean/$EXPID.bkg.eta.${nymdb}_${hhb}00z.$NCSUFFIX " + echo "gcm_ensemble unable to run" + exit(1) + endif + +# Run vortex track on forecast members +# ------------------------------------ + if ( $nhmsb == 210000 || $nhmsb == 090000 ) then # temporarily wired + zeit_ci.x vtrack_ens + atmens_vtrack.csh $EXPID $nymdb $nhmsb + if( $status) then + echo "vtrack_ensemble failed" + exit(1) + endif + zeit_co.x vtrack_ens + endif + +# Store updated ensemble for archiving and prepare for next cycle +# --------------------------------------------------------------- + /bin/mv $ATMENSLOC $FVHOME/atmens4arch.${nymdb}_${hhb} + /bin/mv $FVWORK/updated_ens $ATMENSLOC + +# Calculate statitics (mean and possibly rms) from updated ensemble +# ----------------------------------------------------------------- + set arch_nymd = $nymdb + set arch_nhms = $nhmsb + zeit_ci.x post_egcm + set myrc = $ATMENSETC/post_egcm.rc + if ( -e $ATMENSETC/post_egcm_${hhb}.rc ) set myrc = $ATMENSETC/post_egcm_${hhb}.rc + post_egcm.csh $EXPID $nymdb $nhmsb $TIMEINC spread $myrc $FVHOME/atmens + if ($status) then + echo "post_egcm (bkg) failed" + exit(1) + endif + set myrc = $ATMENSETC/post_egcm_diag.rc + if ( -e $ATMENSETC/post_egcm_diag_${hhb}.rc ) set myrc = $ATMENSETC/post_egcm_diag_${hhb}.rc + if ( -e $myrc ) then + post_egcm.csh $EXPID $nymdb $nhmsb 0 variance $myrc $FVHOME/atmens/ensdiag + if ($status) then + echo "post_egcm (diag) failed" + exit(1) + endif + endif + zeit_co.x post_egcm + +# Summarize timings +# ----------------- + zeit_pr.x + /bin/cp .zeit $FVHOME/atmens4arch.${nymdb}_${hhb}/$EXPID.atmens_zeit.log.${nymdb}_${hhb}z.txt + +# Submit job to run DAS +# --------------------- + cd $FVHOME/run + sbatch >>>JOBNJ<<< + +# If made it here, all is good, then remove the working directory +# --------------------------------------------------------------- + /bin/rm -rf $FVWORK + /bin/rm $FVHOME/.ENSWORK + +# Archive ensemble +# ---------------- + set arch_hh = `echo $arch_nhms | cut -c1-2` + atmens_arch.csh $EXPID $arch_nymd $arch_nhms $FVHOME/run/atmens/atmens_storage.arc eadas atmens4arch.${nymdb}_${hhb} |& tee -a atm_ens_arch.${arch_nymd}_${arch_hh}z.log diff --git a/src/Applications/GEOSdas_App/swell/swell_setup.pl b/src/Applications/GEOSdas_App/swell/swell_setup.pl index 81119aaa..60f3d427 100644 --- a/src/Applications/GEOSdas_App/swell/swell_setup.pl +++ b/src/Applications/GEOSdas_App/swell/swell_setup.pl @@ -4,6 +4,7 @@ # # usage: swell_setup.pl -fvhome DIR -fvroot DIR [-set KEY=VALUE ...] # [-mkiau IM,JM,LM] [-rst4fcst ARCHIVE,EXPID] +# [-ebkgx EXPARCDIR,EXPID,YYYYMMDD,HH] # # (always) copy $FVROOT/etc/swell/swell_config.csh, unchanged, to $FVHOME/run/swell # -set KEY=VALUE experiment setting written to $FVHOME/run/swell/swell_exp.csh @@ -12,6 +13,11 @@ # with @AGCM_IM, @AGCM_JM, @AGCM_LM filled in for the AGCM grid # -rst4fcst ARCH,EXP in $FVHOME/fcst/rst4fcst.acq, replace the GSI IAU (agcm_import_rst) # by the JEDI IAU archive (jedi_agcmrst); the restart line stays +# -ebkgx ARC,EXP,D,H cubed member backgrounds of the initial ensemble (read by +# swell_ana_atmens.csh on the first cycle): from the archive tar +# ARC/atmens/Y%Y/M%m/.atmens_ebkgx.D_Hz.tar ( = basename +# of ARC) into $FVHOME/atmens/ensbkgx/memNNN, for the members +# installed in $FVHOME/atmens, file names renamed . -> EXP. # # swell_exp.csh holds the experiment settings as "if ( ! $?KEY ) setenv KEY VALUE", so # they can still be overridden from the environment at run time; swell_config.csh @@ -20,17 +26,19 @@ use strict; use warnings; +use File::Basename qw(basename); use File::Compare qw(compare); use File::Copy qw(copy); -use File::Path qw(make_path); +use File::Path qw(make_path remove_tree); use Getopt::Long; -my ($fvhome, $fvroot, @sets, $mkiau, $rst4fcst); +my ($fvhome, $fvroot, @sets, $mkiau, $rst4fcst, $ebkgx); GetOptions( "fvhome=s" => \$fvhome, "fvroot=s" => \$fvroot, "set=s" => \@sets, "mkiau=s" => \$mkiau, - "rst4fcst=s" => \$rst4fcst ) or usage(); + "rst4fcst=s" => \$rst4fcst, + "ebkgx=s" => \$ebkgx ) or usage(); usage() unless ( $fvhome and $fvroot ); my $etc = "$fvroot/etc/swell"; @@ -41,6 +49,7 @@ set_exp(@sets) if @sets; install_mkiau($mkiau) if $mkiau; add_rst4fcst($rst4fcst) if $rst4fcst; +restore_ebkgx($ebkgx) if $ebkgx; exit 0; #----------------------------------------------------------------------------------------- @@ -131,9 +140,61 @@ sub add_rst4fcst { print "swell_setup.pl: $acq acquires the JEDI IAU forcing\n"; } +#----------------------------------------------------------------------------------------- +sub restore_ebkgx { + my ($arg) = @_; + my ($exparcdir, $newid, $ymd, $hh) = split(/,/, $arg); + die ">>> ERROR <<< bad -ebkgx '$arg' (expected EXPARCDIR,EXPID,YYYYMMDD,HH)\n" + unless ( $exparcdir and $newid and $ymd and defined($hh) ); + my ($yyyy, $mm) = ( $ymd =~ /^(\d{4})(\d{2})\d{2}$/ ); + die ">>> ERROR <<< bad date in -ebkgx '$arg'\n" unless ( $yyyy and $hh =~ /^\d{2}$/ ); + + $exparcdir =~ s|/+$||; + my $oldid = basename($exparcdir); + my $tag = "${ymd}_${hh}z"; + my $tar = "$exparcdir/atmens/Y$yyyy/M$mm/$oldid.atmens_ebkgx.$tag.tar"; + my $atmens = "$fvhome/atmens"; + + unless ( -e $tar ) { + print "swell_setup.pl: WARNING: no $tar;\n" + . "swell_setup.pl: WARNING: provide $atmens/ensbkgx/memNNN before the first cycle\n"; + return; + } + die ">>> ERROR <<< no ensemble directory $atmens\n" unless ( -d $atmens ); + chdir($atmens) or die ">>> ERROR <<< cannot cd to $atmens: $!\n"; + + my $untar = "$fvroot/bin/parallel-untar.py"; + my $cmd = ( -x $untar ) ? "$untar $tar 16" : "tar -xf $tar"; + print "swell_setup.pl: $cmd\n"; + system($cmd) == 0 or die ">>> ERROR <<< failed: $cmd\n"; + + my $src = "$oldid.atmens_ebkgx.$tag/ensbkgx"; + die ">>> ERROR <<< no $src in $tar\n" unless ( -d $src ); + make_path("ensbkgx"); + system("touch ensbkgx/.no_archiving"); + + my $nmem = 0; + foreach my $mem ( sort glob("mem[0-9][0-9][0-9]") ) { + next unless ( -d $mem ); + unless ( -d "$src/$mem" ) { + print "swell_setup.pl: WARNING: $mem has no cubed backgrounds in $tar\n"; + next; + } + make_path("ensbkgx/$mem"); + foreach my $f ( glob("$src/$mem/*") ) { + (my $new = basename($f)) =~ s/^\Q$oldid\E\./$newid./; + rename($f, "ensbkgx/$mem/$new") or die ">>> ERROR <<< cannot move $f: $!\n"; + } + $nmem++; + } + remove_tree("$oldid.atmens_ebkgx.$tag"); + print "swell_setup.pl: $atmens/ensbkgx: cubed backgrounds of $nmem member(s) from $tar\n"; +} + #----------------------------------------------------------------------------------------- sub usage { print "usage: swell_setup.pl -fvhome DIR -fvroot DIR [-set KEY=VALUE ...]\n" - . " [-mkiau IM,JM,LM] [-rst4fcst ARCHIVE,EXPID]\n"; + . " [-mkiau IM,JM,LM] [-rst4fcst ARCHIVE,EXPID]\n" + . " [-ebkgx EXPARCDIR,EXPID,YYYYMMDD,HH]\n"; exit 1; }