Skip to content

Commit

Permalink
Merge branch 'develop' into bugfix/ioda
Browse files Browse the repository at this point in the history
  • Loading branch information
CoryMartin-NOAA authored Oct 11, 2023
2 parents 15c2974 + d6c4660 commit ac1b0a3
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
38 changes: 38 additions & 0 deletions utils/obsproc/NetCDFToIodaConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,44 @@ namespace gdasapp {
location += other.location;
oops::Log::trace() << "IodaVars::IodaVars done appending." << std::endl;
}
void trim(const Eigen::Array<bool, Eigen::Dynamic, 1>& 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
Expand Down
5 changes: 5 additions & 0 deletions utils/obsproc/Smos2Ioda.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ namespace gdasapp {
iodaVars.preQc(i) = sss_qc[i];
iodaVars.datetime(i) = static_cast<int64_t>(datetime[i]*86400.0f) + mjd2000;
}

// basic test for iodaVars.trim
Eigen::Array<bool, Eigen::Dynamic, 1> mask = (iodaVars.obsVal > 0.0);
iodaVars.trim(mask);

return iodaVars;
};
}; // class Smos2Ioda
Expand Down

0 comments on commit ac1b0a3

Please sign in to comment.