#pragma once #ifndef clip_h #define clip_h #include "utils.h" #include class SigmaClip { private: int maxiters = 5; double sigma = 3, minValue = INF, maxValue = -INF; double (*cenF)(std::vector data) = nullptr; double (*stdF)(std::vector data) = nullptr; public: SigmaClip(double sigma = 3, int maxiters = 5, double (*cenF)(std::vector data) = nullptr, double (*stdF)(std::vector data) = nullptr); ~SigmaClip() {}; std::vector clip(std::vector data); std::vector clipN(std::vector data); private: void computeBound(std::vector data); }; SigmaClip::SigmaClip(double sigma_, int maxiters_, double (*cenF_)(std::vector data), double (*stdF_)(std::vector data)) { sigma = sigma_; maxiters = maxiters_; cenF = cenF_ == nullptr ? dataAvg2D : cenF_; stdF = stdF_ == nullptr ? dataStd2D : stdF_; } void SigmaClip::computeBound(std::vector data) { double std = (*stdF)(data); double mean = (*cenF)(data); minValue = mean - (std * sigma); maxValue = mean + (std * sigma); } std::vector SigmaClip::clip(std::vector data) { std::vector::iterator itor; minValue = INF, maxValue = -INF; for (int k = 1; k <= maxiters; k++) { computeBound(data); for (itor = data.begin(); itor != data.end();) { if ((*itor)(0) < minValue || (*itor)(0) > maxValue) data.erase(itor); else itor++; } } return data; } #endif