Skip to content

Commit

Permalink
working hybvar
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumevernieres committed Jul 5, 2024
1 parent 8ae7f79 commit ba665f4
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 12 deletions.
11 changes: 10 additions & 1 deletion jobs/JGLOBAL_MARINE_BMAT
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
#!/bin/bash

source "${HOMEgfs}/ush/preamble.sh"

export DATA="${DATAROOT}/${RUN}marinebmat_${cyc}"
export DATA=${DATA:-${DATAROOT}/${RUN}marinebmat_${cyc}}
# source config.base, config.ocnanal and config.ocnanalbmat
# and pass marinebmat to ${machine}.env
source "${HOMEgfs}/ush/jjob_header.sh" -e "marinebmat" -c "base ocnanal marinebmat"

# If ensemble perturbations are used, save them in a DATAenspert directory that will
# exist throughout the DA cycle
if (( 10#${NMEM_ENS:-0} > 0 )); then
export DATAjob="${DATAROOT}/${RUN}marinebmat.${PDY:-}${cyc}"
export DATAenspert="${DATAjob}/enspert"
if [[ ! -d "${DATAenspert}" ]]; then mkdir -p "${DATAenspert}"; fi
fi

##############################################
# Set variables used in the script
##############################################
Expand All @@ -16,7 +26,6 @@ export gcyc=${GDATE:8:2}
export GDUMP="gdas"
export GDUMP_ENS="enkf${GDUMP}"


##############################################
# Begin JOB SPECIFIC work
##############################################
Expand Down
43 changes: 33 additions & 10 deletions ush/python/pygfs/task/marine_bmat.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ def __init__(self, config):
_window_begin = add_to_datetime(self.task_config.current_cycle, -to_timedelta(f"{self.task_config.assim_freq}H") / 2)
_window_end = add_to_datetime(self.task_config.current_cycle, to_timedelta(f"{self.task_config.assim_freq}H") / 2)
_jedi_yaml = os.path.join(self.task_config.DATA, f"{self.task_config.RUN}.t{self.task_config.cyc:02d}z.atmvar.yaml")
# compute the relative path from self.task_config.DATA to self.task_config.DATAenspert
_enspert_relpath = os.path.relpath(self.task_config.DATAenspert, self.task_config.DATA)

# Create a local dictionary that is repeatedly used across this class
local_dict = AttrDict(
Expand All @@ -46,7 +48,7 @@ def __init__(self, config):
'BERROR_YAML_DIR': os.path.join(_home_gdas, 'parm', 'soca', 'berror'),
'GRID_GEN_YAML': os.path.join(_home_gdas, 'parm', 'soca', 'gridgen', 'gridgen.yaml'),
'MARINE_ENSDA_STAGE_BKG_YAML_TMPL': os.path.join(_home_gdas, 'parm', 'soca','ensda', 'stage_ens_mem.yaml.j2'),
'ens_dir': os.path.join(self.task_config.DATA, 'ens')
'ENSPERT_RELPATH': _enspert_relpath
}
)

Expand Down Expand Up @@ -144,11 +146,11 @@ def initialize(self: Task) -> None:
logger.debug(f"Stage ensemble members for the hybrid background error")
mdau.stage_ens_mem(self.task_config)

# generate ensemble recentering YAML file
# generate ensemble recentering/rebalancing YAML file
logger.debug("Generate ensemble recentering YAML file")
ensrecenter_config = parse_j2yaml(path=os.path.join(self.task_config.BERROR_YAML_DIR, 'soca_ensrecenter.yaml.j2'),
ensrecenter_config = parse_j2yaml(path=os.path.join(self.task_config.BERROR_YAML_DIR, 'soca_ensb.yaml.j2'),
data=self.task_config)
ensrecenter_config.save(os.path.join(self.task_config.DATA, 'soca_ensrecenter.yaml'))
ensrecenter_config.save(os.path.join(self.task_config.DATA, 'soca_ensb.yaml'))

# generate ensemble weights YAML file
logger.debug("Generate ensemble recentering YAML file: {self.task_config.abcd_yaml}")
Expand Down Expand Up @@ -243,9 +245,9 @@ def ensemble_perturbations(self: Task) -> None:
exec_cmd = Executable(self.task_config.APRUN_MARINEBMAT)
exec_name = os.path.join(self.task_config.DATA, 'gdas_ens_handler.x')
exec_cmd.add_default_arg(exec_name)
exec_cmd.add_default_arg('soca_ensrecenter.yaml')
exec_cmd.add_default_arg('soca_ensb.yaml')

# compute the coefficients of the diffusion operator
# generate the ensemble perturbations
mdau.run(exec_cmd)

@logit(logger)
Expand All @@ -260,7 +262,10 @@ def hybrid_weight(self: Task) -> None:
exec_cmd = Executable(self.task_config.APRUN_MARINEBMAT)
exec_name = os.path.join(self.task_config.DATA, 'gdas_socahybridweights.x')
exec_cmd.add_default_arg(exec_name)
exec_cmd.add_default_arg('soca_hybridweights.yaml')
exec_cmd.add_default_arg('soca_ensweights.yaml')

# compute the ensemble weights
mdau.run(exec_cmd)


@logit(logger)
Expand All @@ -274,8 +279,10 @@ def execute(self: Task) -> None:
self.variance_partitioning()
self.horizontal_diffusion() # TODO: Make this optional once we've converged on an acceptable set of scales
self.vertical_diffusion()
self.ensemble_perturbations() # TODO: refactor this from the old scripts
self.hybrid_weight() # TODO: refactor this from the old scripts
# hybrid EnVAR case
if self.task_config.DOHYBVAR == "YES" or self.task_config.NMEM_ENS > 3:
self.ensemble_perturbations() # TODO: refactor this from the old scripts
self.hybrid_weight() # TODO: refactor this from the old scripts

@logit(logger)
def finalize(self: Task) -> None:
Expand All @@ -285,7 +292,7 @@ def finalize(self: Task) -> None:
This includes:
- copy the generated static, but cycle dependent background error files to the ROTDIR
- copy the generated YAML file from initialize to the ROTDIR
- keep the re-balanced ensemble perturbation files in the DATA/??? directory
- keep the re-balanced ensemble perturbation files in DATAenspert
- ...
"""
Expand Down Expand Up @@ -331,6 +338,22 @@ def finalize(self: Task) -> None:

FileHandler({'copy': diagb_list}).sync()

# Copy the ensemble perturbation diagnostics to the ROTDIR
if self.task_config.DOHYBVAR == "YES" or self.task_config.NMEM_ENS > 3:
window_middle_iso = self.task_config.MARINE_WINDOW_MIDDLE.strftime('%Y-%m-%dT%H:%M:%SZ')
weight_list = []
src = os.path.join(self.task_config.DATA, f"ocn.ens_weights.incr.{window_middle_iso}.nc")
dst = os.path.join(self.task_config.COMOUT_OCEAN_BMATRIX,
f"{self.task_config.RUN}.t{self.task_config.cyc:02d}z.ocean.ens_weights.nc")
weight_list.append([src, dst])

src = os.path.join(self.task_config.DATA, f"ice.ens_weights.incr.{window_middle_iso}.nc")
dst = os.path.join(self.task_config.COMOUT_ICE_BMATRIX,
f"{self.task_config.RUN}.t{self.task_config.cyc:02d}z.ice.ens_weights.nc")
weight_list.append([src, dst])

FileHandler({'copy': weight_list}).sync()

# Copy the YAML files to the OCEAN ROTDIR
yamls = glob.glob(os.path.join(self.task_config.DATA, '*.yaml'))
yaml_list = []
Expand Down
2 changes: 1 addition & 1 deletion ush/python/pygfs/utils/marine_da_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def link_executable(task_config, exe_name: str) -> None:
@logit(logger)
def prep_input_nml(task_config) -> None:
"""Prepare the input.nml file
TODO: Use jinja2 to template the input.nml file
TODO: Use jinja2 instead of f90nml
"""
# stage input.nml
mom_input_nml_tmpl_src = os.path.join(task_config.HOMEgdas, 'parm', 'soca', 'fms', 'input.nml')
Expand Down

0 comments on commit ba665f4

Please sign in to comment.