Skip to content
Snippets Groups Projects
Commit fc470a17 authored by sakthipriyas's avatar sakthipriyas
Browse files

restructured SKRfiReplacement class

parent 4defbf2b
No related branches found
No related tags found
No related merge requests found
...@@ -31,9 +31,9 @@ public: ...@@ -31,9 +31,9 @@ public:
~SKRfiReplacementCuda(); ~SKRfiReplacementCuda();
/** /**
* @brief Replaces data in rfi_windows with replacement data (generated using statistics of data from clean_windows). * @brief Replaces RFI data with data generated using statistics of data from chosen number of clean_windows.
* *
* @param(in) rfi_status rfi_status of input data * @param(in) rfi_status rfi_status of input data stream
* @param(in & out) data Data on which RFI has to be replaced. Returns the same but with RFI replaced. * @param(in & out) data Data on which RFI has to be replaced. Returns the same but with RFI replaced.
* @param(in) clean_windows number of clean windows used for computing data statistics. * @param(in) clean_windows number of clean windows used for computing data statistics.
*/ */
...@@ -43,32 +43,11 @@ public: ...@@ -43,32 +43,11 @@ public:
private: private:
/** /**
* @brief Initializes data members of the class * @brief Initializes the states of the class members for the given data to be processed.
*/
void init();
/**
* @brief Gets indices of clean windows, _clean_window_indices
*/
void get_clean_window_indices();
/**
* @brief Gets indices of RFI windows, _rfi_window_indices
*/
void get_rfi_window_indices();
/**
* @brief Computes statistics of clean (rfi free) data.
*
*/
void compute_clean_data_statistics();
/**
* @brief Gathers data from DEFAULT_NUM_CLEAN_WINDOW number of clean windows and computes its statistics
* *
* @param(in) data actual data * @param(in) data Data stream that has to be processed.
*/ */
void get_clean_data_statistics(const thrust::device_vector<thrust::complex<float>> &data); void init(const thrust::device_vector<thrust::complex<float>> &data);
thrust::device_vector<int> _rfi_status; thrust::device_vector<int> _rfi_status;
std::size_t _window_size; std::size_t _window_size;
......
...@@ -39,19 +39,13 @@ SKRfiReplacementCuda::~SKRfiReplacementCuda() ...@@ -39,19 +39,13 @@ SKRfiReplacementCuda::~SKRfiReplacementCuda()
BOOST_LOG_TRIVIAL(info) << "Destroying SKRfiReplacementCuda instance..\n"; BOOST_LOG_TRIVIAL(info) << "Destroying SKRfiReplacementCuda instance..\n";
} }
void SKRfiReplacementCuda::init() void SKRfiReplacementCuda::init(const thrust::device_vector<thrust::complex<float>> &data)
{ {
BOOST_LOG_TRIVIAL(info) << "initializing data_members of SKRfiReplacementCuda class..\n"; BOOST_LOG_TRIVIAL(info) << "initializing the states of SKRfiReplacementCuda"
<< " class members for the data to be processed..\n";
_nwindows = _rfi_status.size(); _nwindows = _rfi_status.size();
_rfi_window_indices.reserve(_nwindows); //get_rfi_window_indices();
get_rfi_window_indices(); BOOST_LOG_TRIVIAL(debug) << "getting RFI window indices..\n";
_clean_window_indices.reserve(_nwindows);
get_clean_window_indices();
}
void SKRfiReplacementCuda::get_rfi_window_indices()
{
nvtxRangePushA("get_rfi_window_indices");
_nrfi_windows = thrust::count(_rfi_status.begin(), _rfi_status.end(), 1); _nrfi_windows = thrust::count(_rfi_status.begin(), _rfi_status.end(), 1);
_rfi_window_indices.resize(_nrfi_windows); _rfi_window_indices.resize(_nrfi_windows);
thrust::copy_if(thrust::make_counting_iterator<int>(0), thrust::copy_if(thrust::make_counting_iterator<int>(0),
...@@ -59,58 +53,42 @@ void SKRfiReplacementCuda::get_rfi_window_indices() ...@@ -59,58 +53,42 @@ void SKRfiReplacementCuda::get_rfi_window_indices()
_rfi_status.begin(), _rfi_status.begin(),
_rfi_window_indices.begin(), _rfi_window_indices.begin(),
thrust::placeholders::_1 == 1); thrust::placeholders::_1 == 1);
nvtxRangePop(); //get_clean_window_indices();
} BOOST_LOG_TRIVIAL(debug) << "getting clean window indices..\n";
void SKRfiReplacementCuda::get_clean_window_indices()
{
nvtxRangePushA("get_clean_window_indices");
_nclean_windows = thrust::count(_rfi_status.begin(), _rfi_status.end(), 0); _nclean_windows = thrust::count(_rfi_status.begin(), _rfi_status.end(), 0);
if (_nclean_windows > _nclean_windows_stat) _clean_window_indices.resize(_nclean_windows_stat); _clean_window_indices.resize(_nclean_windows);
else{
BOOST_LOG_TRIVIAL(info) << "Total number of clean windows is less than number of clean windows (_nclean_windows_stat)"
<< "chosen to compute data statistics.\n"
<<" Therefore choosing total clean windows for statistics computation.\n";
_clean_window_indices.resize(_nclean_windows);
}
thrust::copy_if(thrust::make_counting_iterator<int>(0), thrust::copy_if(thrust::make_counting_iterator<int>(0),
thrust::make_counting_iterator<int>(_nwindows), thrust::make_counting_iterator<int>(_nwindows),
_rfi_status.begin(), _rfi_status.begin(),
_clean_window_indices.begin(), _clean_window_indices.begin(),
thrust::placeholders::_1 == 0); thrust::placeholders::_1 == 0);
nvtxRangePop();
} if(_nclean_windows < _nwindows){ //if RFI is present
//Getting clean data statistics of chosen number of clean windows
void SKRfiReplacementCuda::get_clean_data_statistics(const thrust::device_vector<thrust::complex<float>> &data) if (_nclean_windows < _nclean_windows_stat) _nclean_windows_stat = _nclean_windows;
{ BOOST_LOG_TRIVIAL(debug) << "collecting clean data from chosen number of clean windows..\n";
nvtxRangePushA("get_clean_data_statistics"); _window_size = data.size() / _nwindows;
_window_size = data.size() / _nwindows; _clean_data.resize(_nclean_windows_stat * _window_size);
_clean_data.resize(_nclean_windows_stat * _window_size); for(std::size_t ii = 0; ii < _nclean_windows_stat; ii++){
for(std::size_t ii = 0; ii < _nclean_windows_stat; ii++){ std::size_t window_index = _clean_window_indices[ii];
std::size_t window_index = _clean_window_indices[ii]; std::size_t ibegin = window_index * _window_size;
std::size_t ibegin = window_index * _window_size; std::size_t iend = ibegin + _window_size - 1;
std::size_t iend = ibegin + _window_size - 1; std::size_t jj = ii * _window_size;
std::size_t jj = ii * _window_size; thrust::copy((data.begin() + ibegin), (data.begin() + iend), (_clean_data.begin() + jj));
thrust::copy((data.begin() + ibegin), (data.begin() + iend), (_clean_data.begin() + jj)); BOOST_LOG_TRIVIAL(debug) <<"clean_win_index = " << window_index
BOOST_LOG_TRIVIAL(debug) <<"clean_win_index = " << window_index << " ibegin = " << ibegin << " iend = " << iend;
<< " ibegin = " << ibegin << " iend = " << iend; }
//computing clean data statistics
BOOST_LOG_TRIVIAL(debug) << "computing statistics of clean data..\n";
//The distribution of both real and imag have same mean and standard deviation.
//Therefore computing _ref_mean, _ref_sd for real distribution only.
std::size_t length = _clean_data.size();
_ref_mean = (thrust::reduce(_clean_data.begin(), _clean_data.end(), thrust::complex<float> (0.0f, 0.0f))). real() / length;
_ref_sd = std::sqrt(thrust::transform_reduce(_clean_data.begin(), _clean_data.end(), mean_subtraction_square(_ref_mean),
0.0f, thrust::plus<float> ()) / length);
BOOST_LOG_TRIVIAL(debug) << "DataStatistics mean = " << _ref_mean
<< " sd = " << _ref_sd;
} }
nvtxRangePop();
compute_clean_data_statistics();
}
void SKRfiReplacementCuda::compute_clean_data_statistics()
{
nvtxRangePushA("compute_clean_data_statistics");
std::size_t length = _clean_data.size();
//The distribution of both real and imag have same mean and standard deviation.
//Therefore computing _ref_mean, _ref_sd for real distribution only.
_ref_mean = (thrust::reduce(_clean_data.begin(), _clean_data.end(), thrust::complex<float> (0.0f, 0.0f))). real() / length;
_ref_sd = std::sqrt(thrust::transform_reduce(_clean_data.begin(), _clean_data.end(), mean_subtraction_square(_ref_mean),
0.0f, thrust::plus<float> ()) / length);
nvtxRangePop();
BOOST_LOG_TRIVIAL(debug) << "DataStatistics mean = " << _ref_mean
<< " sd = " << _ref_sd;
} }
void SKRfiReplacementCuda::replace_rfi_data(const thrust::device_vector<int> &rfi_status, void SKRfiReplacementCuda::replace_rfi_data(const thrust::device_vector<int> &rfi_status,
...@@ -122,10 +100,9 @@ void SKRfiReplacementCuda::replace_rfi_data(const thrust::device_vector<int> &rf ...@@ -122,10 +100,9 @@ void SKRfiReplacementCuda::replace_rfi_data(const thrust::device_vector<int> &rf
thrust::device_vector<thrust::complex<float>> replacement_data; thrust::device_vector<thrust::complex<float>> replacement_data;
//initialize data members of the class //initialize data members of the class
_nclean_windows_stat = clean_windows; //no. of clean windows used for computing statistics _nclean_windows_stat = clean_windows; //no. of clean windows used for computing statistics
init(); init(data);
//RFI present and not in all windows //RFI present and not in all windows
if(_nclean_windows < _nwindows){ if(_nclean_windows < _nwindows){
get_clean_data_statistics(data);
//Replacing RFI //Replacing RFI
thrust::counting_iterator<unsigned int> sequence_index_begin(0); thrust::counting_iterator<unsigned int> sequence_index_begin(0);
nvtxRangePushA("replace_rfi_datai_loop"); nvtxRangePushA("replace_rfi_datai_loop");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment