-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpolynomial_detrenders.cpp
84 lines (64 loc) · 2.53 KB
/
polynomial_detrenders.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "rf_kernels/polynomial_detrender.hpp"
#include "rf_pipelines_internals.hpp"
using namespace std;
namespace rf_pipelines {
#if 0
}; // pacify emacs c-mode
#endif
struct polynomial_detrender : public wi_transform
{
rf_kernels::polynomial_detrender kernel;
const double epsilon;
polynomial_detrender(rf_kernels::axis_type axis, int nt_chunk_, int polydeg, double epsilon_) :
wi_transform("polynomial_detrender"),
kernel(axis, polydeg),
epsilon(epsilon_)
{
stringstream ss;
ss << "polynomial_detrender(nt_chunk=" << nt_chunk_ << ", axis=" << axis << ", polydeg=" << polydeg << ", epsilon=" << epsilon_ << ")";
this->name = ss.str();
this->nt_chunk = nt_chunk_;
this->kernel_chunk_size = 8;
this->nds = 0; // allows polynomial_detrender to run in a wi_sub_pipeline.
if ((nt_chunk == 0) && (axis != rf_kernels::AXIS_FREQ))
throw runtime_error("rf_pipelines::polynomial_detrender: nt_chunk must be specified (unless axis=AXIS_FREQ)");
}
virtual void _process_chunk(float *intensity, ssize_t istride, float *weights, ssize_t wstride, ssize_t pos) override
{
// Note xdiv(nt_chunk,nds) here
this->kernel.detrend(nfreq, xdiv(nt_chunk,nds), intensity, istride, weights, wstride, epsilon);
}
virtual Json::Value jsonize() const override
{
Json::Value ret;
ret["class_name"] = "polynomial_detrender";
ret["nt_chunk"] = int(this->get_prebind_nt_chunk());
ret["axis"] = rf_kernels::axis_type_to_string(this->kernel.axis);
ret["polydeg"] = this->kernel.polydeg;
ret["epsilon"] = this->epsilon;
return ret;
}
static shared_ptr<polynomial_detrender> from_json(const Json::Value &x)
{
if (string_from_json(x,"class_name") != "polynomial_detrender")
throw runtime_error("rf_pipelines: expected class_name=\"pipeline\" in pipeline json constructor");
rf_kernels::axis_type axis = axis_type_from_json(x, "axis");
int nt_chunk = int_from_json(x, "nt_chunk");
double polydeg = double_from_json(x, "polydeg");
double epsilon = double_from_json(x, "epsilon");
return make_shared<polynomial_detrender> (axis, nt_chunk, polydeg, epsilon);
}
};
// Externally callable factory function
shared_ptr<wi_transform> make_polynomial_detrender(int nt_chunk, rf_kernels::axis_type axis, int polydeg, double epsilon)
{
return make_shared<polynomial_detrender> (axis, nt_chunk, polydeg, epsilon);
}
namespace {
struct _init {
_init() {
pipeline_object::register_json_deserializer("polynomial_detrender", polynomial_detrender::from_json);
}
} init;
}
} // namespace rf_pipelines