Skip to content

Commit

Permalink
Fillvalue normalisation
Browse files Browse the repository at this point in the history
  • Loading branch information
twsearle committed Jul 11, 2023
1 parent b6f26ba commit b115cb8
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 9 deletions.
10 changes: 6 additions & 4 deletions src/nemo-feedback/NemoFeedback.cc
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,13 @@ void NemoFeedback::write_all_data(feedback_io::Writer<T>& writer,
for (size_t iLevel = 0;
iLevel < variableDoNotAssimilateData.length(iProfile);
++iLevel) {
variableFinalQCData(iProfile, iLevel) =
static_cast<feedback_io::QC::Level>(
if (variableDoNotAssimilateData(iProfile, iLevel) ==
feedback_io::QC::Level::DoNotAssimilate) {
variableFinalQCData(iProfile, iLevel) =
static_cast<feedback_io::QC::Level>(
static_cast<int32_t>(variableFinalQCData(iProfile, iLevel)) +
static_cast<int32_t>(
variableDoNotAssimilateData(iProfile, iLevel)));
static_cast<int32_t>(feedback_io::QC::Level::DoNotAssimilate));
}
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/nemo-feedback/feedback_io/Utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ template <> const float typeToFill::value<float>() {
template <> const int32_t typeToFill::value<int32_t>() {
return INT32_FILLVALUE;
}
template <> const QC::Level typeToFill::value<QC::Level>() {
return QC::Level::None;
}
template <> const std::string typeToFill::value<std::string>() {
return STRING_FILLVALUE;
}
Expand Down
36 changes: 31 additions & 5 deletions src/nemo-feedback/feedback_io/Writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ void Writer<C>::write_metadata_variables(
/// JULD_QC_FLAGS, POSITION_QC, POSITION_QC_FLAGS
template <class C>
void Writer<C>::define_whole_report_variables() {
// Note: This ought to be true/deleted, but it is set to false for OPS
// compatibilty reasons until OS46 release and to make our intentions clear
constexpr bool kSetQCFillValues = false;
std::string flag_conventions = "JEDI UFO QC flag conventions";
{
const std::vector<netCDF::NcDim> dims{*nobs_dim, ncFile->getDim(STRINGWMO)};
Expand All @@ -237,6 +240,11 @@ void Writer<C>::define_whole_report_variables() {
{
const std::vector<netCDF::NcDim> dims{*nobs_dim, *nlevels_dim};
netCDF::NcVar tmp_var = ncFile->addVar("DEPTH_QC", netCDF::ncInt, dims);
if (kSetQCFillValues) {
const auto fill =
static_cast<int32_t>(typeToFill::value<QC::Level>());
tmp_var.setFill(true, fill);
}
tmp_var.putAtt("long_name", "Quality on depth");
tmp_var.putAtt("Conventions", QC_CONVENTIONS);
}
Expand All @@ -253,6 +261,11 @@ void Writer<C>::define_whole_report_variables() {
{
netCDF::NcVar tmp_var = ncFile->addVar("OBSERVATION_QC", netCDF::ncInt,
*nobs_dim);
if (kSetQCFillValues) {
const auto fill =
static_cast<int32_t>(typeToFill::value<QC::Level>());
tmp_var.setFill(true, fill);
}
tmp_var.putAtt("long_name", "Quality on observation");
tmp_var.putAtt("Conventions", QC_CONVENTIONS);
}
Expand All @@ -268,6 +281,11 @@ void Writer<C>::define_whole_report_variables() {
{
netCDF::NcVar tmp_var = ncFile->addVar("POSITION_QC", netCDF::ncInt,
*nobs_dim);
if (kSetQCFillValues) {
const auto fill =
static_cast<int32_t>(typeToFill::value<QC::Level>());
tmp_var.setFill(true, fill);
}
tmp_var.putAtt("long_name", "Quality on position");
tmp_var.putAtt("Conventions", QC_CONVENTIONS);
}
Expand All @@ -282,6 +300,11 @@ void Writer<C>::define_whole_report_variables() {

{
netCDF::NcVar tmp_var = ncFile->addVar("JULD_QC", netCDF::ncInt, *nobs_dim);
if (kSetQCFillValues) {
const auto fill =
static_cast<int32_t>(typeToFill::value<QC::Level>());
tmp_var.setFill(true, fill);
}
tmp_var.putAtt("long_name", "Quality on date and time");
tmp_var.putAtt("Conventions", QC_CONVENTIONS);
}
Expand Down Expand Up @@ -324,22 +347,22 @@ void Writer<C>::define_variable(
typeToNcType(), dims);
obs_var.putAtt("long_name", longName);
obs_var.putAtt("units", units);
obs_var.setFill(true, feedback_io::typeToFill::value<C>());
obs_var.setFill(true, typeToFill::value<C>());

for (const auto &name : name_data_.additional_names) {
netCDF::NcVar add_var;
add_var = ncFile->addVar(variable_name + "_" + name,
typeToNcType(), dims);
add_var.putAtt("long_name", longName + " " + name);
add_var.putAtt("units", units);
add_var.setFill(true, feedback_io::typeToFill::value<C>());
add_var.setFill(true, typeToFill::value<C>());
}

{
const std::vector<netCDF::NcDim> qcf_dims{*nobs_dim, *nqcf_dim};
netCDF::NcVar qc_flags_var = ncFile->addVar(variable_name + "_QC_FLAGS",
netCDF::ncInt, qcf_dims);
qc_flags_var.setFill(true, feedback_io::typeToFill::value<int32_t>());
qc_flags_var.setFill(true, typeToFill::value<int32_t>());
qc_flags_var.putAtt("long_name", std::string("quality flags on ")
+ longName);
qc_flags_var.putAtt("Conventions", flag_conventions);
Expand All @@ -350,7 +373,7 @@ void Writer<C>::define_variable(
*nqcf_dim};
netCDF::NcVar level_qc_flags_var = ncFile->addVar(variable_name
+ "_LEVEL_QC_FLAGS", netCDF::ncInt, lvl_qcf_dims);
level_qc_flags_var.setFill(true, feedback_io::typeToFill::value<int32_t>());
level_qc_flags_var.setFill(true, typeToFill::value<int32_t>());
level_qc_flags_var.putAtt("long_name",
std::string("quality flags for each level on ") + longName);
level_qc_flags_var.putAtt("Conventions", flag_conventions);
Expand All @@ -363,7 +386,9 @@ void Writer<C>::define_variable(

netCDF::NcVar level_qc_var = ncFile->addVar(variable_name + "_LEVEL_QC",
netCDF::ncInt, dims);
level_qc_var.setFill(true, feedback_io::typeToFill::value<int32_t>());
const auto fill =
static_cast<int32_t>(typeToFill::value<QC::Level>());
level_qc_var.setFill(true, fill);
level_qc_var.putAtt("long_name", std::string("quality for each level on ")
+ longName);
level_qc_var.putAtt("Conventions", QC_CONVENTIONS);
Expand Down Expand Up @@ -421,6 +446,7 @@ void Writer<C>::write_coord_variables() {
const std::vector<netCDF::NcDim> dims{*nobs_dim, *nlevels_dim};
netCDF::NcVar depth_var = ncFile->addVar("DEPTH", netCDF::ncDouble,
dims);
depth_var.setFill(true, typeToFill::value<double>());
depth_var.putAtt("units", "metre");
depth_var.putAtt("long_name", "Depth");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ variables:
LONGITUDE:units = "degrees_east" ;
LONGITUDE:long_name = "longitude" ;
double DEPTH(N_OBS, N_LEVELS) ;
DEPTH:_FillValue = 99999. ;
DEPTH:units = "metre" ;
DEPTH:long_name = "Depth" ;
double JULD(N_OBS) ;
Expand Down
1 change: 1 addition & 0 deletions src/tests/testoutput/test_hofx_profiles_writer_out_ref.cdl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ variables:
LONGITUDE:units = "degrees_east" ;
LONGITUDE:long_name = "longitude" ;
double DEPTH(N_OBS, N_LEVELS) ;
DEPTH:_FillValue = 99999. ;
DEPTH:units = "metre" ;
DEPTH:long_name = "Depth" ;
double JULD(N_OBS) ;
Expand Down
1 change: 1 addition & 0 deletions src/tests/testoutput/test_hofx_sic_writer_out_ref.cdl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ variables:
LONGITUDE:units = "degrees_east" ;
LONGITUDE:long_name = "longitude" ;
double DEPTH(N_OBS, N_LEVELS) ;
DEPTH:_FillValue = 99999. ;
DEPTH:units = "metre" ;
DEPTH:long_name = "Depth" ;
double JULD(N_OBS) ;
Expand Down
1 change: 1 addition & 0 deletions src/tests/testoutput/test_hofx_two_vars_writer_out_ref.cdl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ variables:
LONGITUDE:units = "degrees_east" ;
LONGITUDE:long_name = "longitude" ;
double DEPTH(N_OBS, N_LEVELS) ;
DEPTH:_FillValue = 99999. ;
DEPTH:units = "metre" ;
DEPTH:long_name = "Depth" ;
double JULD(N_OBS) ;
Expand Down

0 comments on commit b115cb8

Please sign in to comment.