File: histogrampage.cpp

package info (click to toggle)
aoflagger 3.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 4,476 kB
  • sloc: cpp: 51,868; python: 152; sh: 25; makefile: 17
file content (252 lines) | stat: -rw-r--r-- 10,172 bytes parent folder | download | duplicates (2)
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
#include "histogrampage.h"

#include <boost/bind.hpp>

#include "controllers/histogrampagecontroller.h"

#include "../plot/plotpropertieswindow.h"

#include "datawindow.h"

HistogramPage::HistogramPage(HistogramPageController* controller) :
 	_controller(controller),
	_expander("Side bar"),
	_histogramTypeFrame("Histogram"),
	_totalHistogramButton("Total"),
	_rfiHistogramButton("RFI"),
	_notRFIHistogramButton("Not RFI"),
	_xxPolarizationButton("XX"),
	_xyPolarizationButton("XY"),
	_yxPolarizationButton("YX"),
	_yyPolarizationButton("YY"),
	_sumPolarizationButton("Sum"),
	_fitFrame("Fitting"),
	_fitButton("Fit"),
	_subtractFitButton("Subtract"),
	_fitLogarithmicButton("Log fit"),
	_fitAutoRangeButton("Auto range"),
	_functionFrame("Function"),
	_nsButton("N(S)"),
	_dndsButton("dN(S)/dS"),
	_deltaSEntry(),
	_staircaseFunctionButton("Staircase"),
	_normalizeButton("Normalize"),
	_plotPropertiesButton("Properties"),
	_dataExportButton("Data"),
	_slopeFrame("Slope"),
	_drawSlopeButton("Draw"),
	_drawSlope2Button("Draw2"),
	_slopeAutoRangeButton("Auto range"),
	_plotPropertiesWindow(0)
{
	_histogramTypeBox.pack_start(_totalHistogramButton, Gtk::PACK_SHRINK);
	_totalHistogramButton.set_active(true);
	_totalHistogramButton.signal_clicked().connect(sigc::mem_fun(*this, &HistogramPage::updatePlot));
	_histogramTypeBox.pack_start(_rfiHistogramButton, Gtk::PACK_SHRINK);
	_rfiHistogramButton.set_active(false);
	_rfiHistogramButton.signal_clicked().connect(sigc::mem_fun(*this, &HistogramPage::updatePlot));
	_histogramTypeBox.pack_start(_notRFIHistogramButton, Gtk::PACK_SHRINK);
	_notRFIHistogramButton.set_active(false);
	_notRFIHistogramButton.signal_clicked().connect(sigc::mem_fun(*this, &HistogramPage::updatePlot));
	
	_histogramTypeFrame.add(_histogramTypeBox);
	
	_sideBox.pack_start(_histogramTypeFrame, Gtk::PACK_SHRINK);
	
	_polarizationBox.pack_start(_xxPolarizationButton, Gtk::PACK_SHRINK);
	_xxPolarizationButton.set_active(false);
	_xxPolarizationButton.signal_clicked().connect(sigc::mem_fun(*this, &HistogramPage::updatePlot));
	_polarizationBox.pack_start(_xyPolarizationButton, Gtk::PACK_SHRINK);
	_xyPolarizationButton.set_active(false);
	_xyPolarizationButton.signal_clicked().connect(sigc::mem_fun(*this, &HistogramPage::updatePlot));
	_polarizationBox.pack_start(_yxPolarizationButton, Gtk::PACK_SHRINK);
	_yxPolarizationButton.set_active(false);
	_yxPolarizationButton.signal_clicked().connect(sigc::mem_fun(*this, &HistogramPage::updatePlot));
	_polarizationBox.pack_start(_yyPolarizationButton, Gtk::PACK_SHRINK);
	_yyPolarizationButton.set_active(false);
	_yyPolarizationButton.signal_clicked().connect(sigc::mem_fun(*this, &HistogramPage::updatePlot));
	_polarizationBox.pack_start(_sumPolarizationButton, Gtk::PACK_SHRINK);
	_sumPolarizationButton.set_active(true);
	_sumPolarizationButton.signal_clicked().connect(sigc::mem_fun(*this, &HistogramPage::updatePlot));

	_polarizationFrame.add(_polarizationBox);
	
	_sideBox.pack_start(_polarizationFrame, Gtk::PACK_SHRINK);
	
	_fitBox.pack_start(_fitButton, Gtk::PACK_SHRINK);
	_fitButton.signal_clicked().connect(sigc::mem_fun(*this, &HistogramPage::updatePlot));
	_fitBox.pack_start(_subtractFitButton, Gtk::PACK_SHRINK);
	_subtractFitButton.signal_clicked().connect(sigc::mem_fun(*this, &HistogramPage::updatePlot));
	_fitBox.pack_start(_fitLogarithmicButton, Gtk::PACK_SHRINK);
	_fitLogarithmicButton.signal_clicked().connect(sigc::mem_fun(*this, &HistogramPage::updatePlot));
	_fitBox.pack_start(_fitAutoRangeButton, Gtk::PACK_SHRINK);
	_fitAutoRangeButton.set_active(true);
	_fitAutoRangeButton.signal_clicked().connect(sigc::mem_fun(*this, &HistogramPage::onAutoRangeClicked));
	
	_fitBox.pack_start(_fitStartEntry, Gtk::PACK_SHRINK);
	_fitStartEntry.set_sensitive(false);
	_fitStartEntry.signal_activate().connect(sigc::mem_fun(*this, &HistogramPage::updatePlot));
	_fitBox.pack_start(_fitEndEntry, Gtk::PACK_SHRINK);
	_fitEndEntry.set_sensitive(false);
	_fitEndEntry.signal_activate().connect(sigc::mem_fun(*this, &HistogramPage::updatePlot));
	_fitBox.pack_start(_fitTextView, Gtk::PACK_SHRINK);
	
	_fitFrame.add(_fitBox);
	
	_sideBox.pack_start(_fitFrame, Gtk::PACK_SHRINK);
	
	Gtk::RadioButtonGroup group;
	_functionBox.pack_start(_nsButton, Gtk::PACK_SHRINK);
	_nsButton.signal_clicked().connect(sigc::mem_fun(*this, &HistogramPage::updatePlot));
	_nsButton.set_group(group);
	_functionBox.pack_start(_dndsButton, Gtk::PACK_SHRINK);
	_dndsButton.signal_clicked().connect(sigc::mem_fun(*this, &HistogramPage::updatePlot));
	_dndsButton.set_group(group);
	_nsButton.set_active(true);
	_functionBox.pack_start(_deltaSEntry, Gtk::PACK_SHRINK);
	_deltaSEntry.set_text("2");
	_deltaSEntry.signal_activate().connect(sigc::mem_fun(*this, &HistogramPage::updatePlot));
	_functionBox.pack_start(_staircaseFunctionButton, Gtk::PACK_SHRINK);
	_staircaseFunctionButton.signal_clicked().connect(sigc::mem_fun(*this, &HistogramPage::updatePlot));
	_functionBox.pack_start(_normalizeButton, Gtk::PACK_SHRINK);
	_normalizeButton.set_active(true);
	_normalizeButton.signal_clicked().connect(sigc::mem_fun(*this, &HistogramPage::updatePlot));
	
	_functionFrame.add(_functionBox);
	_sideBox.pack_start(_functionFrame, Gtk::PACK_SHRINK);
	
	_plotPropertiesButton.signal_clicked().connect(sigc::mem_fun(*this, &HistogramPage::onPlotPropertiesClicked));
	_sideBox.pack_start(_plotPropertiesButton, Gtk::PACK_SHRINK);
	
	_dataExportButton.signal_clicked().connect(sigc::mem_fun(*this, &HistogramPage::onDataExportClicked));
	_sideBox.pack_start(_dataExportButton, Gtk::PACK_SHRINK);
	
	_slopeBox.pack_start(_slopeTextView, Gtk::PACK_SHRINK);
	_drawSlopeButton.signal_clicked().connect(sigc::mem_fun(*this, &HistogramPage::updatePlot));
	_slopeBox.pack_start(_drawSlopeButton, Gtk::PACK_SHRINK);
	_drawSlope2Button.signal_clicked().connect(sigc::mem_fun(*this, &HistogramPage::updatePlot));
	_slopeBox.pack_start(_drawSlope2Button, Gtk::PACK_SHRINK);

	_slopeBox.pack_start(_slopeAutoRangeButton, Gtk::PACK_SHRINK);
	_slopeAutoRangeButton.set_active(true);
	_slopeAutoRangeButton.signal_clicked().connect(sigc::mem_fun(*this, &HistogramPage::onSlopeAutoRangeClicked));
	
	_slopeBox.pack_start(_slopeStartEntry, Gtk::PACK_SHRINK);
	_slopeStartEntry.set_sensitive(false);
	_slopeStartEntry.signal_activate().connect(sigc::mem_fun(*this, &HistogramPage::updatePlot));
	_slopeBox.pack_start(_slopeEndEntry, Gtk::PACK_SHRINK);
	_slopeEndEntry.set_sensitive(false);
	_slopeEndEntry.signal_activate().connect(sigc::mem_fun(*this, &HistogramPage::updatePlot));
	_slopeBox.pack_start(_slopeRFIRatio, Gtk::PACK_SHRINK);
	_slopeRFIRatio.set_text("1.0");
	_slopeRFIRatio.signal_activate().connect(sigc::mem_fun(*this, &HistogramPage::updatePlot));
	
	_slopeFrame.add(_slopeBox);
	_sideBox.pack_start(_slopeFrame, Gtk::PACK_SHRINK);
	
	_expander.add(_sideBox);
	
	pack_start(_expander, Gtk::PACK_SHRINK);
	
	_plotWidget.SetPlot(_controller->Plot());
	pack_start(_plotWidget, Gtk::PACK_EXPAND_WIDGET);
	
	show_all_children();
	
	_dataWindow = new DataWindow();
	
	_controller->Attach(this);
}

HistogramPage::~HistogramPage()
{
	if(_plotPropertiesWindow != 0)
		delete _plotPropertiesWindow;
	delete _dataWindow;
}

void HistogramPage::updatePlot()
{
	_controller->SetDrawXX(_xxPolarizationButton.get_active());
	_controller->SetDrawXY(_xyPolarizationButton.get_active());
	_controller->SetDrawYX(_yxPolarizationButton.get_active());
	_controller->SetDrawYY(_yyPolarizationButton.get_active());
	_controller->SetDrawSum(_sumPolarizationButton.get_active());

	_controller->SetAutomaticFitRange(_fitAutoRangeButton.get_active());
	_controller->SetFitStart(atof(_fitStartEntry.get_text().c_str()));
	_controller->SetFitEnd(atof(_fitEndEntry.get_text().c_str()));
	_controller->SetFitLogarithmic(_fitLogarithmicButton.get_active());
	
	_controller->SetAutomaticSlopeRange( _slopeAutoRangeButton.get_active() );
	_controller->SetSlopeStart( atof(_slopeStartEntry.get_text().c_str()));
	_controller->SetSlopeEnd( atof(_slopeEndEntry.get_text().c_str()));
	_controller->SetSlopeRFIRatio( atof(_slopeRFIRatio.get_text().c_str()) );
	double deltaS = atof(_deltaSEntry.get_text().c_str());
	if(deltaS <= 1.0001) deltaS = 1.0001;
	_controller->SetDeltaS( deltaS );
	
	_controller->SetDrawTotal(_totalHistogramButton.get_active());
	_controller->SetDrawFit(_fitButton.get_active());
	_controller->SetDrawSubtractedFit(_subtractFitButton.get_active());
	_controller->SetDrawSlope(_drawSlopeButton.get_active());
	_controller->SetDrawSlope2(_drawSlope2Button.get_active());
	_controller->SetDrawRFI(_rfiHistogramButton.get_active());
	_controller->SetDrawNonRFI(_notRFIHistogramButton.get_active());
	
	_controller->SetDerivative(_dndsButton.get_active());
	_controller->SetStaircase(_staircaseFunctionButton.get_active());
	_controller->SetNormalize(_normalizeButton.get_active());
	_controller->SetDeltaS(atof(_deltaSEntry.get_text().c_str()));
}

void HistogramPage::onPlotPropertiesClicked()
{
	if(_plotPropertiesWindow == 0)
	{
		_plotPropertiesWindow = new PlotPropertiesWindow(_controller->Plot(), "Plot properties");
		_plotPropertiesWindow->OnChangesApplied = boost::bind(&HistogramPage::Redraw, this);
	}
	
	_plotPropertiesWindow->show();
	_plotPropertiesWindow->raise();
}

void HistogramPage::onDataExportClicked()
{
	_dataWindow->show();
	_dataWindow->raise();
	updateDataWindow();
}

void HistogramPage::SetSlopeFrame(const std::string& str)
{
	_slopeTextView.get_buffer()->set_text(str);
	
	if(_slopeAutoRangeButton.get_active())
	{
		double
			minRange = _controller->SlopeStart(),
			maxRange = _controller->SlopeEnd();
		std::stringstream minRangeStr, maxRangeStr;
		minRangeStr << minRange;
		maxRangeStr << maxRange;
		_slopeStartEntry.set_text(minRangeStr.str());
		_slopeEndEntry.set_text(maxRangeStr.str());
	}
	
	if(_fitAutoRangeButton.get_active())
	{
		std::stringstream minRangeStr, maxRangeStr;
		minRangeStr << _controller->FitStart();
		maxRangeStr << _controller->FitEnd();
		_fitStartEntry.set_text(minRangeStr.str());
		_fitEndEntry.set_text(maxRangeStr.str());
	}
}

void HistogramPage::updateDataWindow()
{
	if(_dataWindow->get_visible())
		_dataWindow->SetData(_controller->Plot());
}