Changeset 1018 for XIOS/trunk/src/filter


Ignore:
Timestamp:
01/10/17 13:52:53 (7 years ago)
Author:
mhnguyen
Message:

Improving missing-value processing
If detect_missing_value is activated, then all missing value will be converted to
NaN (Not-a-number) in input of data flow then they will be reconverted to missing value on output

+) Update SourceFilter?, TemporalFilter? and SpatialTransformFilter? with new processing
+) Update all transformations with new processing

Test
+) On Curie
+) Work

Location:
XIOS/trunk/src/filter
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/src/filter/file_writer_filter.cpp

    r639 r1018  
    22#include "exception.hpp" 
    33#include "field.hpp" 
     4#include "utils.hpp" 
    45 
    56namespace xios 
     
    1617  void CFileWriterFilter::onInputReady(std::vector<CDataPacketPtr> data) 
    1718  { 
     19    bool ignoreMissingValue = (!field->detect_missing_value.isEmpty() &&  
     20                               !field->default_value.isEmpty() &&  
     21                               field->detect_missing_value == true); 
     22    if (ignoreMissingValue) 
     23    { 
     24      double missingValue = field->default_value; 
     25      size_t nbData = data[0]->data.numElements(); 
     26      for (size_t idx = 0; idx < nbData; ++idx) 
     27      { 
     28        if (NumTraits<double>::isnan(data[0]->data(idx))) 
     29          data[0]->data(idx) = missingValue; 
     30      } 
     31    }     
     32 
    1833    field->sendUpdateData(data[0]->data); 
    1934  } 
  • XIOS/trunk/src/filter/source_filter.cpp

    r1006 r1018  
    33#include "exception.hpp" 
    44#include "calendar_util.hpp" 
     5#include <limits>  
    56 
    67namespace xios 
    78{ 
    89  CSourceFilter::CSourceFilter(CGarbageCollector& gc, CGrid* grid, 
    9                                const CDuration offset /*= NoneDu*/, bool manualTrigger /*= false*/) 
     10                               const CDuration offset /*= NoneDu*/, bool manualTrigger /*= false*/, 
     11                               bool hasMissingValue /*= false*/, 
     12                               double defaultValue /*= 0.0*/) 
    1013    : COutputPin(gc, manualTrigger) 
    1114    , grid(grid) 
    1215    , offset(offset) 
     16    , hasMissingValue(hasMissingValue), defaultValue(defaultValue) 
    1317  { 
    1418    if (!grid) 
     
    2933    packet->data.resize(grid->storeIndex_client.numElements()); 
    3034    grid->inputField(data, packet->data); 
     35 
     36    // Convert missing values to NaN 
     37    if (hasMissingValue) 
     38    { 
     39      double nanValue = std::numeric_limits<double>::quiet_NaN(); 
     40      size_t nbData = packet->data.numElements(); 
     41      for (size_t idx = 0; idx < nbData; ++idx) 
     42      { 
     43        if (defaultValue == packet->data(idx)) 
     44          packet->data(idx) = nanValue; 
     45      } 
     46    } 
    3147 
    3248    onOutputReady(packet); 
  • XIOS/trunk/src/filter/source_filter.hpp

    r1006 r1018  
    2323       * \param offset the offset applied to the timestamp of all packets 
    2424       * \param manualTrigger whether the output should be triggered manually 
     25       * \param hasMissingValue whether data has missing value 
     26       * \param defaultValue missing value to detect 
    2527       */ 
    2628      CSourceFilter(CGarbageCollector& gc, CGrid* grid, 
    27                     const CDuration offset = NoneDu, bool manualTrigger = false); 
     29                    const CDuration offset = NoneDu, bool manualTrigger = false, 
     30                    bool hasMissingValue = false, 
     31                    double defaultValue = 0.0); 
    2832 
    2933      /*! 
     
    5862      CGrid* grid; //!< The grid attached to the data the filter can accept 
    5963      const CDuration offset; //!< The offset applied to the timestamp of all packets 
     64      bool hasMissingValue; 
     65      double defaultValue; 
    6066  }; // class CSourceFilter 
    6167} // namespace xios 
  • XIOS/trunk/src/filter/spatial_transform_filter.cpp

    r1006 r1018  
    1111 
    1212  std::pair<boost::shared_ptr<CSpatialTransformFilter>, boost::shared_ptr<CSpatialTransformFilter> > 
    13   CSpatialTransformFilter::buildFilterGraph(CGarbageCollector& gc, CGrid* srcGrid, CGrid* destGrid, double defaultValue) 
     13  CSpatialTransformFilter::buildFilterGraph(CGarbageCollector& gc, CGrid* srcGrid, CGrid* destGrid, bool hasMissingValue, double missingValue) 
    1414  { 
    1515    if (!srcGrid || !destGrid) 
     
    2626      const std::vector<StdString>& auxInputs = gridTransformation->getAuxInputs(); 
    2727      size_t inputCount = 1 + (auxInputs.empty() ? 0 : auxInputs.size()); 
     28      double defaultValue  = (hasMissingValue) ? std::numeric_limits<double>::quiet_NaN() : missingValue; 
    2829      boost::shared_ptr<CSpatialTransformFilter> filter(new CSpatialTransformFilter(gc, engine, defaultValue, inputCount)); 
    2930 
     
    103104      } 
    104105      packet->data.resize(gridTransformation->getGridDestination()->storeIndex_client.numElements()); 
    105       packet->data = defaultValue; 
     106      if (0 != packet->data.numElements()) 
     107        (packet->data)(0) = defaultValue; 
    106108      apply(data[0]->data, packet->data); 
    107109    } 
  • XIOS/trunk/src/filter/spatial_transform_filter.hpp

    r873 r1018  
    3232       * \param srcGrid the source grid 
    3333       * \param destGrid the destination grid 
     34       * \param hasMissingValue whether field source has missing value 
     35       * \param defaultValue default value 
    3436       * \return the first and the last filters of the filter graph 
    3537       */ 
    3638      static std::pair<boost::shared_ptr<CSpatialTransformFilter>, boost::shared_ptr<CSpatialTransformFilter> > 
    37       buildFilterGraph(CGarbageCollector& gc, CGrid* srcGrid, CGrid* destGrid, double defaultValue); 
     39      buildFilterGraph(CGarbageCollector& gc, CGrid* srcGrid, CGrid* destGrid, bool hasMissingValue, double defaultValue); 
    3840 
    3941    protected: 
  • XIOS/trunk/src/filter/temporal_filter.cpp

    r854 r1018  
    1515    , isFirstOperation(true) 
    1616  { 
     17    double defaultValue = ignoreMissingValue ? std::numeric_limits<double>::quiet_NaN() : missingValue; 
     18     
    1719#define DECLARE_FUNCTOR(MType, mtype) \ 
    1820    if (opId.compare(#mtype) == 0) \ 
     
    2022      if (ignoreMissingValue) \ 
    2123      { \ 
    22         functor.reset(new func::C##MType(tmpData, missingValue)); \ 
     24        functor.reset(new func::C##MType(tmpData, defaultValue)); \ 
    2325      } \ 
    2426      else \ 
Note: See TracChangeset for help on using the changeset viewer.