Skip to content

Commit

Permalink
added ens. weights app
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumevernieres committed Jun 16, 2023
1 parent 4ee6c2d commit 1d06644
Show file tree
Hide file tree
Showing 9 changed files with 178 additions and 8 deletions.
16 changes: 10 additions & 6 deletions parm/soca/berror/saber_blocks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,15 @@ components:
read local nicas: true
model:
do not cross mask boundaries: false
groups:
- group name: group 1
variables: [tocn, socn, uocn, vocn, ssh]
- group name: group 2
variables: [cicen, hicen, hsnon]
# groups:
# - group name: group 1
# variables: [tocn, socn, uocn, vocn, ssh]
# - group name: group 2
# variables: [cicen, hicen, hsnon]

weight:
value: 0.5
read_from_file: 3
basename: ./
ocn_filename: 'ocn.ens_weights.incr.{{ATM_WINDOW_MIDDLE}}.nc'
ice_filename: 'ice.ens_weights.incr.{{ATM_WINDOW_MIDDLE}}.nc'
date: '{{ATM_WINDOW_MIDDLE}}'
26 changes: 26 additions & 0 deletions parm/soca/berror/soca_ensweights.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
geometry:
mom6_input_nml: mom_input.nml
fields metadata: ./fields_metadata.yaml

date: '{{ATM_WINDOW_MIDDLE}}'

variables:
ice: [cicen, hicen, hsnon]
ocean: [tocn, socn, uocn, vocn, ssh]

background:
date: '{{ATM_WINDOW_BEGIN}}'
basename: ./INPUT/
ocn_filename: MOM.res.nc
ice_filename: cice.res.nc
read_from_file: 1

weights:
ice: 0.1
ocean: 0.5

output:
datadir: ./
date: '{{ATM_WINDOW_MIDDLE}}'
exp: ens_weights
type: incr
8 changes: 8 additions & 0 deletions scripts/exgdas_global_marine_analysis_bmat.sh
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,14 @@ if [ ${#files[@]} -gt 0 ]; then
shopt -u nullglob
fi

################################################################################
# Write ensemble weights for the hybrid envar
$APRUN_OCNANAL $JEDI_BIN/socahybridweights.x soca_ensweights.yaml
export err=$?; err_chk
if [ $err -gt 0 ]; then
exit $err
fi

################################################################################
# Set decorrelation scales for bump C
$APRUN_OCNANAL $JEDI_BIN/soca_setcorscales.x soca_setcorscales.yaml
Expand Down
7 changes: 7 additions & 0 deletions scripts/exgdas_global_marine_analysis_prep.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,13 @@ def find_clim_ens(input_date):
config = Template.substitute_structure(config, TemplateConstants.DOLLAR_PARENTHESES, envconfig.get)
config.save(berr_yaml)

logging.info(f"---------------- generate soca_ensweights.yaml")
berr_yaml = os.path.join(anl_dir, 'soca_ensweights.yaml')
berr_yaml_template = os.path.join(berror_yaml_dir, 'soca_ensweights.yaml')
config = YAMLFile(path=berr_yaml_template)
config = Template.substitute_structure(config, TemplateConstants.DOUBLE_CURLY_BRACES, envconfig.get)
config.save(berr_yaml)

################################################################################
# copy yaml for decorrelation length scales

Expand Down
8 changes: 7 additions & 1 deletion test/soca/gw/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ set(jjob_list "JGDAS_GLOBAL_OCEAN_ANALYSIS_PREP"
# "JGDAS_GLOBAL_OCEAN_ANALYSIS_BMAT_VRFY"
"JGDAS_GLOBAL_OCEAN_ANALYSIS_RUN"
"JGDAS_GLOBAL_OCEAN_ANALYSIS_CHKPT"
"JGDAS_GLOBAL_OCEAN_ANALYSIS_POST")
# "JGDAS_GLOBAL_OCEAN_ANALYSIS_POST")
# "JGDAS_GLOBAL_OCEAN_ANALYSIS_VRFY")
)

set(setup "")
foreach(jjob ${jjob_list})
Expand All @@ -62,3 +63,8 @@ foreach(jjob ${jjob_list})
set(setup "--skip") # Only run the setup of the first test, if not, it will hang
# waiting for standard input from setup_expt.py
endforeach()

# Test hyb-weights app
add_test(NAME test_gdasapp_hyb_weights
COMMAND ${PROJECT_BINARY_DIR}/bin/socahybridweights.x ${PROJECT_SOURCE_DIR}/test/testinput/soca_hybweights.yaml
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/test/soca/gw/testrun/testjjobs/RUNDIRS/gdas_test/gdasocnanal_12)
26 changes: 26 additions & 0 deletions test/testinput/soca_hybweights.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
geometry:
mom6_input_nml: mom_input.nml
fields metadata: ./fields_metadata.yaml

date: 2018-04-15T09:00:00Z

variables:
ice: [cicen, hicen, hsnon]
ocean: [tocn, socn, uocn, vocn, ssh]

background:
date: '2018-04-15T09:00:00Z'
basename: ./INPUT/
ocn_filename: MOM.res.nc
ice_filename: cice.res.nc
read_from_file: 1

weights:
ice: 0.1
ocean: 0.5

output:
datadir: ./
date: '2018-04-15T12:00:00Z'
exp: hybrid_weights
type: incr
8 changes: 8 additions & 0 deletions utils/socahybridweights.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include "socahybridweights.h"
#include "oops/runs/Run.h"

int main(int argc, char ** argv) {
oops::Run run(argc, argv);
gdasapp::SocaHybridWeights socahybridweights;
return run.execute(socahybridweights);
}
86 changes: 86 additions & 0 deletions utils/socahybridweights.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#include <netcdf>
#include <iostream>
#include <filesystem>

#include "eckit/config/LocalConfiguration.h"

#include "atlas/field.h"

#include "oops/base/PostProcessor.h"
#include "oops/mpi/mpi.h"
#include "oops/runs/Application.h"
#include "oops/util/DateTime.h"
#include "oops/util/Duration.h"
#include "oops/util/Logger.h"

#include "soca/State/State.h"
#include "soca/Geometry/Geometry.h"
#include "soca/Increment/Increment.h"

namespace gdasapp {

class SocaHybridWeights : public oops::Application {
public:
explicit SocaHybridWeights(const eckit::mpi::Comm & comm = oops::mpi::world())
: Application(comm) {}
static const std::string classname() {return "gdasapp::SocaHybridWeights";}

int execute(const eckit::Configuration & fullConfig, bool /*validate*/) const {

/// Setup the soca geometry
const eckit::LocalConfiguration geomConfig(fullConfig, "geometry");
oops::Log::info() << "geometry: " << std::endl << geomConfig << std::endl;
const soca::Geometry geom(geomConfig, this->getComm());

/// Get the date
std::string strdt;
fullConfig.get("date", strdt);
util::DateTime dt = util::DateTime(strdt);

/// Get the list of variables
oops::Variables socaOcnVars(fullConfig, "variables.ocean");
oops::Variables socaIceVars(fullConfig, "variables.ice");
oops::Variables socaVars(socaIceVars);
socaVars += socaOcnVars;

/// Read the background
// TODO: Use the ice extent to set the weights ... no clue if this is
// possible at this level
soca::State socaBkg(geom, socaVars, dt);
const eckit::LocalConfiguration socaBkgConfig(fullConfig, "background");
socaBkg.read(socaBkgConfig);
oops::Log::info() << "socaBkg: " << std::endl << socaBkg << std::endl;

/// Read weights
const eckit::LocalConfiguration socaHWConfig(fullConfig, "weights");
double wIce = socaHWConfig.getDouble("ice");
double wOcean = socaHWConfig.getDouble("ocean");
oops::Log::info() << "wIce: " << wIce << std::endl;
oops::Log::info() << "wOcean: " << wOcean << std::endl;

/// Create fields of weights for seaice
soca::Increment socaIceHW(geom, socaVars, dt); // ocean field is mandatory for writting
socaIceHW.ones();
socaIceHW *= wIce;
oops::Log::info() << "socaIceHW: " << std::endl << socaIceHW << std::endl;
const eckit::LocalConfiguration socaHWOutConfig(fullConfig, "output");
socaIceHW.write(socaHWOutConfig);

/// Create fields of weights for the ocean
soca::Increment socaOcnHW(geom, socaOcnVars, dt);
socaOcnHW.ones();
socaOcnHW *= wOcean;
oops::Log::info() << "socaOcnHW: " << std::endl << socaOcnHW << std::endl;
socaOcnHW.write(socaHWOutConfig);

return 0;
}
// -----------------------------------------------------------------------------
private:
std::string appname() const {
return "gdasapp::SocaHybridWeights";
}
// -----------------------------------------------------------------------------
};

} // namespace gdasapp
1 change: 0 additions & 1 deletion utils/socaincr2mom6.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "oops/util/Duration.h"
#include "oops/util/Logger.h"

#include "soca/State/State.h"
#include "soca/Geometry/Geometry.h"
#include "soca/Increment/Increment.h"

Expand Down

0 comments on commit 1d06644

Please sign in to comment.