Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions utils/preproc/NetCDFToIodaConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ namespace obsforge {
// Read the provider's netcdf file
obsforge::preproc::iodavars::IodaVars iodaVars = providerToIodaVars(inputFilenames_[myrank]);


for (int i = myrank + comm_.size(); i < inputFilenames_.size(); i += comm_.size()) {
iodaVars.append(providerToIodaVars(inputFilenames_[i]));
oops::Log::info() << " appending: " << inputFilenames_[i] << std::endl;
Expand All @@ -73,6 +72,7 @@ namespace obsforge {
}
nobs = iodaVars.location_;


// Get the total number of obs across pe's
int nobsAll(0);
comm_.allReduce(nobs, nobsAll, eckit::mpi::sum());
Expand All @@ -88,6 +88,7 @@ namespace obsforge {
gatherObs(iodaVars.obsError_, iodaVarsAll.obsError_);
gatherObs(iodaVars.preQc_, iodaVarsAll.preQc_);


// Create empty group backed by HDF file
if (oops::mpi::world().rank() == 0) {
ioda::Group group =
Expand Down Expand Up @@ -122,7 +123,7 @@ namespace obsforge {
ioda::VariableCreationParameters int_params = createVariableParams<int>();
ioda::VariableCreationParameters long_params = createVariableParams<int64_t>();

// Create the mendatory IODA variables
// Create the mandatory IODA variables
ioda::Variable iodaDatetime =
ogrp.vars.createWithScales<int64_t>("MetaData/dateTime",
{ogrp.vars["Location"]}, long_params);
Expand Down Expand Up @@ -178,6 +179,8 @@ namespace obsforge {
}
}
tmpIntMeta.writeWithEigenRegular(iodaVars.intMetadata_.col(count));


count++;
}

Expand All @@ -191,6 +194,14 @@ namespace obsforge {
count++;
}

if (iodaVars.originalDatetime_.size() != 0) {
ioda::Variable iodaOriginalDatetime =
ogrp.vars.createWithScales<int64_t>("MetaData/originalDateTime",
{ogrp.vars["Location"]}, long_params);
iodaOriginalDatetime.writeWithEigenRegular(iodaVars.originalDatetime_);
}


// Test output
iodaVars.testOutput();

Expand Down
21 changes: 19 additions & 2 deletions utils/preproc/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ namespace obsforge {
std::vector<std::string> floatMetadataName_; // String descriptor of the float metadata
Eigen::ArrayXXi intMetadata_; // Optional array of integer metadata
Comment thread
givelberg marked this conversation as resolved.
std::vector<std::string> intMetadataName_; // String descriptor of the integer metadata
Eigen::Array<int64_t, Eigen::Dynamic, 1> originalDatetime_; // Epoch date in seconds

// Optional global attributes
std::map<std::string, std::string> strGlobalAttr_;
Expand All @@ -133,6 +134,7 @@ namespace obsforge {
floatMetadataName_(fmnames),
intMetadata_(location_, imnames.size()),
intMetadataName_(imnames),
originalDatetime_(), // initialized as empty
channel_(1),
channelValues_(Eigen::ArrayXi::Constant(channel_, -1))
{
Expand All @@ -145,8 +147,6 @@ namespace obsforge {
ASSERT(nVars_ == other.nVars_);
ASSERT(nfMetadata_ == other.nfMetadata_);
ASSERT(niMetadata_ == other.niMetadata_);
ASSERT(floatMetadataName_ == floatMetadataName_);
ASSERT(intMetadataName_ == intMetadataName_);
Comment thread
givelberg marked this conversation as resolved.

// Concatenate Eigen arrays and vectors
longitude_.conservativeResize(location_ + other.location_);
Expand All @@ -157,6 +157,9 @@ namespace obsforge {
preQc_.conservativeResize(location_ * channel_ + other.location_ * other.channel_);
floatMetadata_.conservativeResize(location_ + other.location_, nfMetadata_);
intMetadata_.conservativeResize(location_ + other.location_, niMetadata_);
if (originalDatetime_.size() != 0) {
originalDatetime_.conservativeResize(location_ + other.location_);
}

// Copy data from the 'other' object to this object
longitude_.tail(other.location_) = other.longitude_;
Expand All @@ -167,6 +170,9 @@ namespace obsforge {
preQc_.tail(other.location_) = other.preQc_;
floatMetadata_.bottomRows(other.location_) = other.floatMetadata_;
intMetadata_.bottomRows(other.location_) = other.intMetadata_;
if (originalDatetime_.size() != 0) {
originalDatetime_.tail(other.location_) = other.originalDatetime_;
}

// Update obs count
location_ += other.location_;
Expand Down Expand Up @@ -194,6 +200,10 @@ namespace obsforge {
for (int k = 0; k < niMetadata_; k++) {
iodaVarsMasked.intMetadata_(j, k) = intMetadata_(i, k);
}
// ugly, may be unnecessary; just to be safe
if (originalDatetime_.size() != 0) {
iodaVarsMasked.originalDatetime_(j) = originalDatetime_(i);
}
j++;
} // end if (mask(i))
}
Expand All @@ -206,6 +216,7 @@ namespace obsforge {
preQc_ = iodaVarsMasked.preQc_;
floatMetadata_ = iodaVarsMasked.floatMetadata_;
intMetadata_ = iodaVarsMasked.intMetadata_;
originalDatetime_ = iodaVarsMasked.originalDatetime_;

// Update obs count
location_ = iodaVarsMasked.location_;
Expand All @@ -221,11 +232,17 @@ namespace obsforge {
oops::Log::test() << checksum(longitude_, "longitude") << std::endl;
oops::Log::test() << checksum(latitude_, "latitude") << std::endl;
oops::Log::test() << checksum(datetime_, "datetime") << std::endl;
if (originalDatetime_.size() != 0) {
oops::Log::test() << checksum(originalDatetime_, "originalDatetime") << std::endl;
}
}

// Changing the date and Adjusting Errors
void reDate(const util::DateTime & windowBegin, const util::DateTime & windowEnd,
const std::string &epochDate, float errRatio) {
// save the original
originalDatetime_ = datetime_;

// windowBegin and End into DAwindowTimes
std::vector<util::DateTime> DAwindowTimes = {windowBegin, windowEnd};
// Epoch DateTime from Provider
Expand Down
4 changes: 4 additions & 0 deletions utils/test/testref/insituall2ioda.test
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ datetime:
Min: 1616619601
Max: 1616641199
Sum: 51732172800
originalDatetime:
Min: 1616598720
Max: 1616645340
Sum: 51731904960
4 changes: 4 additions & 0 deletions utils/test/testref/rads2ioda.test
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ datetime:
Min: 5131805184
Max: 5131807744
Sum: 112899742208
originalDatetime:
Min: 5131805184
Max: 5131807744
Sum: 112899742208