Skip to content

Commit

Permalink
Reorg of where soca is staged/run (#210)
Browse files Browse the repository at this point in the history
* reorg of where stuff is staged

* Trigger CI

Co-authored-by: Cory Martin <cory.r.martin@noaa.gov>
  • Loading branch information
guillaumevernieres and CoryMartin-NOAA authored Nov 29, 2022
1 parent c26b3f5 commit 41cf7c3
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 44 deletions.
3 changes: 2 additions & 1 deletion parm/templates/stage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ observers: $<< ${OBS_YAML}
background_dir: '{{background_dir}}'
staticb_dir: '{{staticb_dir}}'
COMOUT: '{{COMOUT}}'
DATA: ${DATA}
background_time: '{{background_time}}'
dump: ${CDUMP}
r2d2_obs_db: ${R2D2_OBS_DB}
Expand All @@ -15,5 +16,5 @@ r2d2 window length: ${R2D2_OBS_WINDOW}
r2d2 window begin: '{{r2d2_window_begin}}'
fv3jedi_stage_files: $<< $(fv3jedi_stage)
fv3jedi_stage: ${FV3JEDI_STAGE_YAML}
stage_dir: $(COMOUT)/analysis
stage_dir: $(DATA)
soca_input_fix_dir: '{{soca_input_fix_dir}}'
10 changes: 6 additions & 4 deletions scripts/exgdas_global_marine_analysis_prep.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,20 @@ def gen_bkg_list(window_begin=' ', bkg_path='.', file_type='gdas.t*.ocnf00[3-9]'

comout = os.getenv('COMOUT')
comin_obs = os.getenv('COMIN_OBS')
anl_dir = os.getenv('DATA')
staticsoca_dir = os.getenv('SOCA_INPUT_FIX_DIR')

# create analysis directory for files
anl_dir = os.path.join(comout, 'analysis')
ufsda.mkdir(anl_dir)

# create output directory for obs
diags = os.path.join(comout, 'analysis', 'diags')
diags = os.path.join(anl_dir, 'diags')
ufsda.mkdir(diags)

# create output directory for soca DA
ufsda.mkdir(os.path.join(comout, 'analysis', 'Data'))
anl_out = os.path.join(comout, 'ocnanal_'+os.getenv('CDATE'), 'Data')
ufsda.mkdir(anl_out)
ufsda.symlink(os.path.join(anl_dir, 'Data'), anl_out, remove=False)


################################################################################
Expand Down Expand Up @@ -221,7 +223,7 @@ def gen_bkg_list(window_begin=' ', bkg_path='.', file_type='gdas.t*.ocnf00[3-9]'

# link of convenience
diag_ic = glob.glob(os.path.join(os.getenv('COMIN_GES'), 'gdas.*.ocnf003.nc'))[0]
ufsda.disk_utils.symlink(diag_ic, os.path.join(comout, 'analysis', 'INPUT', 'MOM.res.nc'))
ufsda.disk_utils.symlink(diag_ic, os.path.join(anl_dir, 'INPUT', 'MOM.res.nc'))

# prepare input.nml
mom_input_nml_src = os.path.join(gdas_home, 'parm', 'soca', 'fms', 'input.nml')
Expand Down
2 changes: 1 addition & 1 deletion test/soca/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ add_test(NAME test_gdasapp_soca_ana_prep
# -----------------------------------------
add_test(NAME test_gdasapp_soca_ana_run
COMMAND ${PROJECT_SOURCE_DIR}/test/soca/test_run.sh ${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR}
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/test/soca/3dvar/analysis)
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/test/soca/3dvar/ocnanal_2018041512)
set_tests_properties(test_gdasapp_soca_ana_run
PROPERTIES
DEPENDS "test_gdasapp_soca_ana_prep"
Expand Down
2 changes: 1 addition & 1 deletion test/soca/runtime_vars.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export PDY=20180415
export cyc=12
export assim_freq=6 # DA window
export COMOUT=${project_binary_dir}/test/soca/3dvar
export DATA=${COMOUT}/analysis
export DATA=${project_binary_dir}/test/soca/3dvar/ocnanal_${CDATE}
export COMIN_OBS=${project_binary_dir}/test/soca/obs/r2d2-shared
export COMIN_GES=${project_binary_dir}/test/soca/bkg # Backgrounds from previous forecast
export CASE_ANL="C48" # TODO: Replace with or add OCNRES
Expand Down
17 changes: 8 additions & 9 deletions test/soca/test_prep.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ project_source_dir=$2
source ${project_source_dir}/test/soca/test_utils.sh

# Remove previously fetched obs
rm -f ${project_binary_dir}/test/soca/3dvar/gdas.t12z.sst*.nc4
rm -f ${project_binary_dir}/test/soca/3dvar/gdas.t12z.adt*.nc4
rm -f ${project_binary_dir}/test/soca/3dvar/gdas.t12z.{sst,adt,sss,salt}*.nc4

# Export runtime env. variables
source ${project_source_dir}/test/soca/runtime_vars.sh $project_binary_dir $project_source_dir
Expand All @@ -30,7 +29,7 @@ ${project_source_dir}/scripts/exgdas_global_marine_analysis_prep.py

# Test that the obs path in var.yaml exist
echo "============================= Testing the existence of obs and bkg in var.vaml"
obslist=`grep 'gdas.t12z' $COMOUT/analysis/var.yaml`
obslist=`grep 'gdas.t12z' ${DATA}/var.yaml`
for o in $obslist; do
echo "----------------------- "$o
case $o in
Expand All @@ -52,9 +51,9 @@ done

# Test that the static files have been linked properly
echo "============================= Test that the static files have been linked properly"
test_file $(readlink ${project_binary_dir}/test/soca/3dvar/analysis/diag_table)
test_file $(readlink ${project_binary_dir}/test/soca/3dvar/analysis/field_table)
test_file $(readlink ${project_binary_dir}/test/soca/3dvar/analysis/fields_metadata.yaml)
test_file $(readlink ${project_binary_dir}/test/soca/3dvar/analysis/godas_sst_bgerr.nc)
test_file $(readlink ${project_binary_dir}/test/soca/3dvar/analysis/rossrad.dat)
test_file $(readlink ${project_binary_dir}/test/soca/3dvar/analysis/MOM_input)
test_file $(readlink ${DATA}/diag_table)
test_file $(readlink ${DATA}/field_table)
test_file $(readlink ${DATA}/fields_metadata.yaml)
test_file $(readlink ${DATA}/godas_sst_bgerr.nc)
test_file $(readlink ${DATA}/rossrad.dat)
test_file $(readlink ${DATA}/MOM_input)
32 changes: 16 additions & 16 deletions test/soca/test_run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ source ${project_source_dir}/test/soca/test_utils.sh

# Clean test files created during a previous test
echo "============================= Test that the grid has been generated"
rm -f ${project_binary_dir}/test/soca/3dvar/analysis/soca_gridspec.nc
rm -f ${project_binary_dir}/test/soca/3dvar/analysis/ocn.bkgerr_stddev.incr.2018-04-15T09:00:00Z.nc
rm -f ${project_binary_dir}/test/soca/3dvar/analysis/Data/ocn.iter1.incr.2018-04-15T09:00:00Z.nc
rm -f ${project_binary_dir}/test/soca/3dvar/analysis/Data/ocn.3dvarfgat_pseudo.incr.2018-04-15T09:00:00Z.nc
rm -f ${project_binary_dir}/test/soca/3dvar/analysis/Data/ocn.3dvarfgat_pseudo.an.2018-04-15T09:00:00Z.nc
rm -f ${project_binary_dir}/test/soca/3dvar/analysis/Data/ocn.3dvarfgat_pseudo.an.2018-04-15T12:00:00Z.nc
rm -f ${project_binary_dir}/test/soca/3dvar/analysis/Data/ocn.3dvarfgat_pseudo.an.2018-04-15T15:00:00Z.nc
rm -f ${project_binary_dir}/test/soca/3dvar/analysis/Data/inc.nc
rm -f ${DATA}/soca_gridspec.nc
rm -f ${DATA}/ocn.bkgerr_stddev.incr.2018-04-15T09:00:00Z.nc
rm -f ${DATA}/Data/ocn.iter1.incr.2018-04-15T09:00:00Z.nc
rm -f ${DATA}/Data/ocn.3dvarfgat_pseudo.incr.2018-04-15T09:00:00Z.nc
rm -f ${DATA}/Data/ocn.3dvarfgat_pseudo.an.2018-04-15T09:00:00Z.nc
rm -f ${DATA}/Data/ocn.3dvarfgat_pseudo.an.2018-04-15T12:00:00Z.nc
rm -f ${DATA}/Data/ocn.3dvarfgat_pseudo.an.2018-04-15T15:00:00Z.nc
rm -f ${DATA}/Data/inc.nc

# Export runtime env. variables
source ${project_source_dir}/test/soca/runtime_vars.sh $project_binary_dir $project_source_dir
Expand All @@ -25,15 +25,15 @@ echo "============================= Testing exgdas_global_marine_analysis_run.sh
${project_source_dir}/scripts/exgdas_global_marine_analysis_run.sh > exgdas_global_marine_analysis_run.log

echo "============================= Test that the grid has been generated"
test_file ${project_binary_dir}/test/soca/3dvar/analysis/soca_gridspec.nc
test_file ${DATA}/soca_gridspec.nc

echo "============================= Test that the parametric diag of B was generated"
test_file ${project_binary_dir}/test/soca/3dvar/analysis/ocn.bkgerr_stddev.incr.2018-04-15T09:00:00Z.nc
test_file ${DATA}/ocn.bkgerr_stddev.incr.2018-04-15T09:00:00Z.nc

echo "============================= Test that an increment and an analysis were created"
test_file ${project_binary_dir}/test/soca/3dvar/analysis/Data/ocn.iter1.incr.2018-04-15T09:00:00Z.nc
test_file ${project_binary_dir}/test/soca/3dvar/analysis/Data/ocn.3dvarfgat_pseudo.incr.2018-04-15T09:00:00Z.nc
test_file ${project_binary_dir}/test/soca/3dvar/analysis/Data/ocn.3dvarfgat_pseudo.an.2018-04-15T09:00:00Z.nc
test_file ${project_binary_dir}/test/soca/3dvar/analysis/Data/ocn.3dvarfgat_pseudo.an.2018-04-15T12:00:00Z.nc
test_file ${project_binary_dir}/test/soca/3dvar/analysis/Data/ocn.3dvarfgat_pseudo.an.2018-04-15T15:00:00Z.nc
test_file ${project_binary_dir}/test/soca/3dvar/analysis/Data/inc.nc
test_file ${DATA}/Data/ocn.iter1.incr.2018-04-15T09:00:00Z.nc
test_file ${DATA}/Data/ocn.3dvarfgat_pseudo.incr.2018-04-15T09:00:00Z.nc
test_file ${DATA}/Data/ocn.3dvarfgat_pseudo.an.2018-04-15T09:00:00Z.nc
test_file ${DATA}/Data/ocn.3dvarfgat_pseudo.an.2018-04-15T12:00:00Z.nc
test_file ${DATA}/Data/ocn.3dvarfgat_pseudo.an.2018-04-15T15:00:00Z.nc
test_file ${DATA}/Data/inc.nc
13 changes: 8 additions & 5 deletions ush/ufsda/disk_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,15 @@ def copyfile(src, dest):
logging.info(f"copy of {src} to {dest}")


def symlink(src, dest):
def symlink(src, dest, remove=True):
try:
os.symlink(src, dest)
logging.info(f"Symbolically linked {src} to {dest}")
except FileExistsError:
os.remove(dest)
logging.info(f"{dest} exists, removing...")
os.symlink(src, dest)
logging.info(f"Symbolically linked {src} to {dest}")
if remove:
os.remove(dest)
logging.info(f"{dest} exists, removing...")
os.symlink(src, dest)
logging.info(f"Symbolically linked {src} to {dest}")
else:
logging.info(f"{dest} exists, do nothing.")
10 changes: 3 additions & 7 deletions ush/ufsda/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,8 @@ def background(config):
"""
rst_dir = os.path.join(config['background_dir'], 'RESTART')
ges_dir = os.path.join(config['background_dir'], 'RESTART_GES')
jedi_bkg_dir = os.path.join(config['COMOUT'], 'analysis', 'bkg')
jedi_anl_dir = os.path.join(config['COMOUT'], 'analysis', 'anl')
jedi_bkg_dir = os.path.join(config['DATA'], 'bkg')
jedi_anl_dir = os.path.join(config['DATA'], 'anl')

# copy RESTART to RESTART_GES
try:
Expand All @@ -400,15 +400,11 @@ def obs(config):
based on input `config` dict
"""
# create directory
obs_dir = os.path.join(config['COMOUT'], 'analysis', 'obs')
obs_dir = os.path.join(config['DATA'], 'obs')
mkdir(obs_dir)
for ob in config['observers']:
obname = ob['obs space']['name'].lower()
outfile = ob['obs space']['obsdatain']['engine']['obsfile']
# the above path is what 'FV3-JEDI' expects, need to modify it
outpath = outfile.split('/')
outpath[0] = 'analysis'
outpath = '/'.join(outpath)
# grab obs using R2D2
window_begin = config['window begin']
window_begin = parser.parse(window_begin, fuzzy=True)
Expand Down

0 comments on commit 41cf7c3

Please sign in to comment.