"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/CDMOverlay.cc" between
fimex-1.6.4.tar.gz and fimex-1.6.5.tar.gz

About: Fimex is a the File Interpolation, Manipulation and EXtraction library for gridded geospatial data. It converts between different, extensible dataformats (currently netcdf, NcML, grib1/2 and felt).

CDMOverlay.cc  (fimex-1.6.4):CDMOverlay.cc  (fimex-1.6.5)
/* /*
* Fimex, CDMOverlay.cc * Fimex, CDMOverlay.cc
* *
* (C) Copyright 2013, met.no * (C) Copyright 2013-2021, met.no
* *
* Project Info: https://wiki.met.no/fimex/start * Project Info: https://wiki.met.no/fimex/start
* *
* This library is free software; you can redistribute it and/or modify it * This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by * under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or * the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This library is distributed in the hope that it will be useful, but * This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
skipping to change at line 42 skipping to change at line 42
#include "fimex/Data.h" #include "fimex/Data.h"
#include "fimex/Logger.h" #include "fimex/Logger.h"
#include "fimex/MathUtils.h" #include "fimex/MathUtils.h"
#include "CDMMergeUtils.h" #include "CDMMergeUtils.h"
using namespace std; using namespace std;
namespace MetNoFimex { namespace MetNoFimex {
//static LoggerPtr logger(getLogger("fimex.CDMOverlay")); static Logger_p logger(getLogger("fimex.CDMOverlay"));
// ======================================================================== // ========================================================================
struct CDMOverlayPrivate { struct CDMOverlayPrivate {
CDMReader_p readerB; CDMReader_p readerB;
CDMReader_p readerT; CDMReader_p readerT;
CDMInterpolator_p interpolatedB; CDMInterpolator_p interpolatedB;
CDM init(int gridInterpolationMethod, bool keepOuterVariables); CDM init(int gridInterpolationMethod, bool keepOuterVariables);
}; };
skipping to change at line 69 skipping to change at line 69
{ {
p->readerB = base; p->readerB = base;
p->readerT = top; p->readerT = top;
*cdm_ = p->init(grim, keepOuterVariables); *cdm_ = p->init(grim, keepOuterVariables);
} }
CDMOverlay::~CDMOverlay() {} CDMOverlay::~CDMOverlay() {}
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
namespace {
template<class T> bool value_is_nan(T) { return false; }
template<> bool value_is_nan<float>(float f) { return mifi_isnan(f); }
template<> bool value_is_nan<double>(double d) { return mifi_isnan(d); }
template <class T>
DataPtr overlayDataSlices(T fillT, DataPtr sliceT, DataPtr sliceB)
{
const shared_array<T> valuesT = dataAs<T>(sliceT);
shared_array<T> valuesB = dataAs<T>(sliceB);
for (size_t i = 0; i < sliceB->size(); ++i) {
const T valueT = valuesT[i];
if (!(value_is_nan<T>(valueT) || valueT == fillT))
valuesB[i] = valueT;
}
return createData(sliceB->size(), valuesB);
}
} // namespace
DataPtr CDMOverlay::getDataSlice(const std::string &varName, size_t unLimDimPos) DataPtr CDMOverlay::getDataSlice(const std::string &varName, size_t unLimDimPos)
{ {
const CDM& cdmT = p->readerT->getCDM();
// use cdmB if not defined in cdmT // use cdmB if not defined in cdmT
// get simple coordinate variables from readerT // get simple coordinate variables from readerT
if (cdm_->hasDimension(varName) and p->readerT->getCDM().hasVariable(varName )) { if (cdm_->hasDimension(varName) && cdmT.hasVariable(varName)) {
// read dimension variables from top // read dimension variables from top
return p->readerT->getDataSlice(varName, unLimDimPos); // not scaled return p->readerT->getDataSlice(varName, unLimDimPos); // not scaled
} }
if (not p->readerT->getCDM().hasVariable(varName)) { if (!cdmT.hasVariable(varName)) {
// use complete base-data // use complete base-data
return p->interpolatedB->getDataSlice(varName, unLimDimPos); return p->interpolatedB->getDataSlice(varName, unLimDimPos);
} }
const CDM& cdmB = p->interpolatedB->getCDM(); const CDM& cdmB = p->interpolatedB->getCDM();
if (not cdmB.hasVariable(varName)) if (not cdmB.hasVariable(varName))
THROW("variable '" << varName << "' unknown in base"); THROW("variable '" << varName << "' unknown in base");
DataPtr sliceT = p->readerT->getScaledDataSlice(varName, unLimDimPos); const std::string unitsT = cdmT.getUnits(varName);
const std::string unitsB = cdmB.getUnits(varName);
const CDMDataType dtT = cdmT.getVariable(varName).getDataType();
const CDMDataType dtB = cdmB.getVariable(varName).getDataType();
if (unitsT == unitsB
&& dtT == dtB
&& cdmT.getScaleFactor(varName) == cdmB.getScaleFactor(varName)
&& cdmT.getAddOffset(varName) == cdmB.getAddOffset(varName))
{
DataPtr sliceT = p->readerT->getDataSlice(varName, unLimDimPos);
DataPtr sliceB = p->interpolatedB->getDataSlice(varName, unLimDimPos);
if (dtT == CDM_FLOAT) {
LOG4FIMEX(logger, Logger::DEBUG, "overlay using float without scalin
g");
return overlayDataSlices<float>(cdmT.getFillValue(varName), sliceT,
sliceB);
} else if (dtT == CDM_DOUBLE) {
LOG4FIMEX(logger, Logger::DEBUG, "overlay using double without scali
ng");
return overlayDataSlices<double>(cdmT.getFillValue(varName), sliceT,
sliceB);
}
}
// getScaledDataSlice always returns DataPtr with CDM_DOUBLE
const bool emptyUnits = unitsT.empty() || unitsB.empty();
DataPtr sliceT;
if (emptyUnits || unitsT == unitsB) {
if (emptyUnits) {
LOG4FIMEX(logger, Logger::WARN,
"no unit conversion for variable '" << varName << "': unit
s '" << unitsT << "' in top and '" << unitsB << "' in base");
}
sliceT = p->readerT->getScaledDataSlice(varName, unLimDimPos);
} else {
LOG4FIMEX(logger, Logger::INFO, "unit conversion for variable '" << varN
ame << "' from '" << unitsT << "' in top to '" << unitsB << "' in base");
sliceT = p->readerT->getScaledDataSliceInUnit(varName, unitsB, unLimDimP
os);
}
DataPtr sliceB = p->interpolatedB->getScaledDataSlice(varName, unLimDimPos); DataPtr sliceB = p->interpolatedB->getScaledDataSlice(varName, unLimDimPos);
for (size_t i=0; i<sliceB->size(); ++i) { for (size_t i=0; i<sliceB->size(); ++i) {
const double valueT = sliceT->getDouble(i); const double valueT = sliceT->getDouble(i);
if (not mifi_isnan(valueT)) if (not mifi_isnan(valueT))
sliceB->setValue(i, valueT); sliceB->setValue(i, valueT);
} }
double scale=1, offset=0; double scale=1, offset=0;
getScaleAndOffsetOf(varName, scale, offset); getScaleAndOffsetOf(varName, scale, offset);
return sliceB->convertDataType(MIFI_UNDEFINED_D, 1, 0, return sliceB->convertDataType(MIFI_UNDEFINED_D, 1, 0,
cdm_->getVariable(varName).getDataType(), cdm_->getVariable(varName).getDataType(),
 End of changes. 8 change blocks. 
5 lines changed or deleted 68 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)