diff --git a/utils/obsproc/NetCDFToIodaConverter.h b/utils/obsproc/NetCDFToIodaConverter.h index 8f7b4cf52..7248b6136 100644 --- a/utils/obsproc/NetCDFToIodaConverter.h +++ b/utils/obsproc/NetCDFToIodaConverter.h @@ -93,6 +93,44 @@ namespace gdasapp { location += other.location; oops::Log::trace() << "IodaVars::IodaVars done appending." << std::endl; } + void trim(const Eigen::Array& mask ) { + int newlocation = mask.count(); + + IodaVars iodaVarsMasked(newlocation, this->floatMetadataName, this->intMetadataName); + + // this feels downright crude, but apparently numpy-type masks are on the todo list for Eigen + int j = 0; + for (int i = 0; i < this->location; i++) { + if (mask(i)) { + iodaVarsMasked.longitude(j) = this->longitude(i); + iodaVarsMasked.latitude(j) = this->latitude(i); + iodaVarsMasked.obsVal(j) = this->obsVal(i); + iodaVarsMasked.obsError(j) = this->obsError(i); + iodaVarsMasked.preQc(j) = this->preQc(i); + iodaVarsMasked.datetime(j) = this->datetime(i); + for (int k = 0; k < this->nfMetadata; k++) { + iodaVarsMasked.intMetadata(j, k) = this->intMetadata(i, k); + } + for (int k = 0; k < this->niMetadata; k++) { + iodaVarsMasked.intMetadata(j, k) = this->intMetadata(i, k); + } + j++; + } // end if (mask(i)) + } + + this->longitude = iodaVarsMasked.longitude; + this->latitude = iodaVarsMasked.latitude; + this->datetime = iodaVarsMasked.datetime; + this->obsVal = iodaVarsMasked.obsVal; + this->obsError = iodaVarsMasked.obsError; + this->preQc = iodaVarsMasked.preQc; + this->floatMetadata = iodaVarsMasked.floatMetadata; + this->intMetadata = iodaVarsMasked.intMetadata; + + // Update obs count + this->location = iodaVarsMasked.location; + oops::Log::info() << "IodaVars::IodaVars done masking." << std::endl; + } }; // Base class for the converters diff --git a/utils/obsproc/Smos2Ioda.h b/utils/obsproc/Smos2Ioda.h index b28c37fc5..a0cf06a51 100644 --- a/utils/obsproc/Smos2Ioda.h +++ b/utils/obsproc/Smos2Ioda.h @@ -81,6 +81,11 @@ namespace gdasapp { iodaVars.preQc(i) = sss_qc[i]; iodaVars.datetime(i) = static_cast(datetime[i]*86400.0f) + mjd2000; } + + // basic test for iodaVars.trim + Eigen::Array mask = (iodaVars.obsVal > 0.0); + iodaVars.trim(mask); + return iodaVars; }; }; // class Smos2Ioda