2022-07-04 23:52:05 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#ifndef clip_h
|
|
|
|
#define clip_h
|
|
|
|
|
2022-07-05 19:02:59 +08:00
|
|
|
#include "utils.h"
|
2022-07-04 23:52:05 +08:00
|
|
|
|
2022-07-05 19:02:59 +08:00
|
|
|
#include <Eigen/Dense>
|
2022-07-04 23:52:05 +08:00
|
|
|
|
|
|
|
class SigmaClip {
|
|
|
|
private:
|
2022-07-05 19:02:59 +08:00
|
|
|
int maxiters = 5;
|
|
|
|
double sigma = 3, minValue = INF, maxValue = -INF;
|
|
|
|
double (*cenF)(std::vector<Eigen::Vector2d> data) = nullptr;
|
|
|
|
double (*stdF)(std::vector<Eigen::Vector2d> data) = nullptr;
|
2022-07-04 23:52:05 +08:00
|
|
|
|
|
|
|
public:
|
2022-07-05 19:02:59 +08:00
|
|
|
SigmaClip(double sigma = 3, int maxiters = 5,
|
|
|
|
double (*cenF)(std::vector<Eigen::Vector2d> data) = nullptr,
|
|
|
|
double (*stdF)(std::vector<Eigen::Vector2d> data) = nullptr);
|
2022-07-06 23:47:50 +08:00
|
|
|
~SigmaClip() {};
|
2022-07-05 19:02:59 +08:00
|
|
|
std::vector<Eigen::Vector2d> clip(std::vector<Eigen::Vector2d> data);
|
2022-07-06 23:33:12 +08:00
|
|
|
std::vector<Eigen::Vector2d> clipN(std::vector<Eigen::Vector2d> data);
|
2022-07-04 23:52:05 +08:00
|
|
|
|
|
|
|
private:
|
2022-07-05 19:02:59 +08:00
|
|
|
void computeBound(std::vector<Eigen::Vector2d> data);
|
2022-07-04 23:52:05 +08:00
|
|
|
};
|
|
|
|
|
2022-07-05 19:02:59 +08:00
|
|
|
SigmaClip::SigmaClip(double sigma_, int maxiters_,
|
|
|
|
double (*cenF_)(std::vector<Eigen::Vector2d> data),
|
|
|
|
double (*stdF_)(std::vector<Eigen::Vector2d> data)) {
|
|
|
|
sigma = sigma_;
|
|
|
|
maxiters = maxiters_;
|
2022-07-06 23:33:12 +08:00
|
|
|
cenF = cenF_ == nullptr ? dataAvg2D : cenF_;
|
|
|
|
stdF = stdF_ == nullptr ? dataStd2D : stdF_;
|
2022-07-04 23:52:05 +08:00
|
|
|
}
|
|
|
|
|
2022-07-05 19:02:59 +08:00
|
|
|
void SigmaClip::computeBound(std::vector<Eigen::Vector2d> data) {
|
|
|
|
double std = (*stdF)(data);
|
|
|
|
double mean = (*cenF)(data);
|
2022-07-04 23:52:05 +08:00
|
|
|
|
|
|
|
minValue = mean - (std * sigma);
|
|
|
|
maxValue = mean + (std * sigma);
|
|
|
|
}
|
|
|
|
|
2022-07-05 19:02:59 +08:00
|
|
|
std::vector<Eigen::Vector2d> SigmaClip::clip(std::vector<Eigen::Vector2d> data) {
|
|
|
|
std::vector<Eigen::Vector2d>::iterator itor;
|
2022-07-06 23:33:12 +08:00
|
|
|
|
2022-07-05 19:02:59 +08:00
|
|
|
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++;
|
|
|
|
}
|
2022-07-04 23:52:05 +08:00
|
|
|
}
|
|
|
|
|
2022-07-05 19:02:59 +08:00
|
|
|
return data;
|
2022-07-04 23:52:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|