casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BLParameterParser.h
Go to the documentation of this file.
1 //# BLParameterParser.h: this code perses baseline fitting parameters
2 //# Copyright (C) 2015
3 //# National Astronomical Observatory of Japan
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id$
27 #ifndef _CASA_BLPARAMETER_PARSER_H_
28 #define _CASA_BLPARAMETER_PARSER_H_
29 
30 #include <string>
31 #include <map>
32 #include <vector>
33 //#include<cstdint> //with c++11 support
34 #include <climits>
35 #include <sstream>
36 
37 #include <casa/aipstype.h>
38 #include <casa/Logging/LogIO.h>
39 #include <casa/Logging/LogOrigin.h>
40 #include <libsakura/sakura.h>
42 
43 namespace casa { //# NAMESPACE CASA - BEGIN
44 
46  LineFinderParameter(bool const use_lf=false, float const thresh=5.0,
47  std::vector<size_t> const &edges=std::vector<size_t>(2,0),
48  size_t const chavglim=0)
49  {
50  use_line_finder=use_lf;
51  threshold = thresh;
52  chan_avg_limit = chavglim;
53  for (size_t iedge=0; iedge < 2; ++ iedge) {
54  edge[iedge] = edges[iedge % edges.size()] ;
55  }
56  }
58  float threshold;
59  size_t edge[2];
61 };
62 
64  BLParameterSet(string const blmask="", uint16_t const nfit_max=0,
65  float const clipthres=3.0,
67  size_t const bl_type = BaselineType_kNumElements,
68  uint16_t const fit_order = USHRT_MAX, //UINT16_MAX,
69  size_t const num_piece = USHRT_MAX, //SIZE_MAX,
70  std::vector<size_t> const &nwaves = std::vector<size_t>()
71  )
72  {
73  baseline_mask = blmask;
74  num_fitting_max = nfit_max;
75  clip_threshold_sigma = clipthres;
76  line_finder = lf_param;
77  baseline_type = bl_type;
78  order = fit_order;
79  npiece = num_piece;
80  nwave = nwaves;
81  }
82 
83  void PrintSummary() {
84  casacore::LogIO os(casacore::LogOrigin("BLParameterSet","PrintSummary"));
85  os << "- mask: " << baseline_mask << casacore::LogIO::POST;
86  os << "- clip: iteration=" << num_fitting_max
87  << ", threshold=" << clip_threshold_sigma << casacore::LogIO::POST;
88  os
89  << "- line finder: "
90  << (line_finder.use_line_finder==1 ? "true" : "false")
91  << ", threshold=" << line_finder.threshold
92  << ", edge=[" << line_finder.edge[0] << ","
93  << line_finder.edge[1] << "], chan_average="
94  << line_finder.chan_avg_limit << casacore::LogIO::POST;
95  os << "- baseline: type=" << baseline_type
96  << ", order=" << order << ", npiece=" << npiece
97  << casacore::LogIO::POST;
98  }
99 
101  uint16_t num_fitting_max;
105  uint16_t order; //initialize with invalid parameters
106  size_t npiece;
107  std::vector<size_t> nwave;
108 };
109 
110 
112 public:
113 
114  explicit BLParameterParser(string const file_name);
116 
117  //Returns false if there is no fitting parameters for the row and pol.
118  //Else, returns a baseline fitting parameter of a certain
119  //row and pol IDs in MS
120  bool GetFitParameter(size_t const rowid,size_t const polid,
121  BLParameterSet &bl_param);
122 
123  //Returns the name of file that stores
124  inline string get_file_name(){return blparam_file_;};
125  //Returns a list of baseline type in the file
126  inline std::vector<size_t> get_function_types(){return baseline_types_;};
127  //Returns the maximum fit order of specified baseline type to construct BaselineContext
128  uint16_t get_max_order(size_t const bltype);
129 
130 protected:
131  //private:
132  void initialize();
133  void Clearup();
134  // parse a file
135  void parse(string const file_name);
136  // split string by separator character
137  void SplitLine(string const &linestr, char const separator,
138  std::vector<string> &strvec);
139  // convert a line of string to a BLParameterSet data structure
140  void ConvertLineToParam(string const &linestr, size_t &rowid,
141  size_t &polid, BLParameterSet &paramset);
142  //Returns order or npiece in BLParameterSet structure depending on datatype.
143  uint16_t GetTypeOrder(BLParameterSet const &bl_param);
144 
145  // Member variables
147  std::map<const std::pair<size_t, size_t>, BLParameterSet*> bl_parameters_;
148  std::vector<size_t> baseline_types_;
150  // The enum for columns in fitting parameter file
151  typedef enum {BLParameters_kRow = 0,
166  } BLParameters;
167 
168  //
169  template<typename DataType>
170  inline DataType ConvertString(string const &svalue)
171  {
172  DataType out_value;
173  std::istringstream istr(svalue.data());
174  istr >> out_value;
175  return out_value;
176  };
177 
178 }; // class BLParameterParser -END
179 
180 struct BLIdSet {};
181 
183  public:
184  explicit BLTableParser(string const file_name);
185  ~BLTableParser();
186  bool GetFitParameterIdx(double const time, double const interval,
187  size_t const scanid, size_t const beamid,
188  size_t const antid, size_t const spwid, size_t &idx);
189  void GetFitParameterByIdx(size_t const idx, size_t const ipol,
190  bool &apply, std::vector<float> &coeff,
191  std::vector<double> &boundary,
192  BLParameterSet &bl_param);
193  private:
194  void initialize();
195  void parse();
196  //Returns order or npiece in BLParameterSet structure depending on datatype.
197  uint16_t GetTypeOrder(size_t const &baseline_type,
198  casacore::uInt const irow, casacore::uInt const ipol);
200  std::map<string, std::vector<double> > sortedTimes_;
201  std::map<string, std::vector<casacore::uInt> > timeSortedIdx_;
202  std::map<string, size_t> numRows_;
203 };
204 
205 } //# NAMESPACE CASA - END
206 
207 #endif /* _CASA_BLPARAMETER_PARSER_H_ */
std::vector< size_t > nwave
void apply(const Jones &j1, VisVector &v, const Jones &j2)
Apply a pair of Jones to a VisVector:
uint16_t get_max_order(size_t const bltype)
Returns the maximum fit order of specified baseline type to construct BaselineContext.
DataType ConvertString(string const &svalue)
ABSTRACT TOOL CLASSES A PlotTool is a higher level event handler for a PlotCanvas The idea is to take common tasks which may require multiple events and put them in one place PlotTools also provide additional functionality in that they can be active and blocking non blocking The PlotCanvas will only send events to active and will not send events to later tools or event handlers if the latest tool was blocking In this way a single tool can be used to handle ALL user interaction via the GUI at one time
Definition: PlotTool.h:43
std::vector< size_t > get_function_types()
Returns a list of baseline type in the file.
bool GetFitParameterIdx(double const time, double const interval, size_t const scanid, size_t const beamid, size_t const antid, size_t const spwid, size_t &idx)
std::map< string, std::vector< double > > sortedTimes_
ostream-like interface to creating log messages.
Definition: LogIO.h:167
uint16_t GetTypeOrder(size_t const &baseline_type, casacore::uInt const irow, casacore::uInt const ipol)
Returns order or npiece in BLParameterSet structure depending on datatype.
void GetFitParameterByIdx(size_t const idx, size_t const ipol, bool &apply, std::vector< float > &coeff, std::vector< double > &boundary, BLParameterSet &bl_param)
BLParameters
The enum for columns in fitting parameter file.
bool GetFitParameter(size_t const rowid, size_t const polid, BLParameterSet &bl_param)
Returns false if there is no fitting parameters for the row and pol.
std::vector< size_t > baseline_types_
void initialize()
private:
std::map< const std::pair< size_t, size_t >, BLParameterSet * > bl_parameters_
std::map< string, std::vector< casacore::uInt > > timeSortedIdx_
std::map< string, size_t > numRows_
BLTableParser(string const file_name)
void SplitLine(string const &linestr, char const separator, std::vector< string > &strvec)
split string by separator character
LineFinderParameter(bool const use_lf=false, float const thresh=5.0, std::vector< size_t > const &edges=std::vector< size_t >(2, 0), size_t const chavglim=0)
void parse(string const file_name)
parse a file
BLParameterParser(string const file_name)
string get_file_name()
Returns the name of file that stores.
BLParameterSet(string const blmask="", uint16_t const nfit_max=0, float const clipthres=3.0, LineFinderParameter lf_param=LineFinderParameter(), size_t const bl_type=BaselineType_kNumElements, uint16_t const fit_order=USHRT_MAX, size_t const num_piece=USHRT_MAX, std::vector< size_t > const &nwaves=std::vector< size_t >())
Post the accumulated message.
Definition: LogIO.h:173
LogOrigin: The source code location of the originator of a LogMessage.
Definition: LogOrigin.h:94
uint16_t max_orders_[BaselineType_kNumElements]
string blparam_file_
Member variables.
LineFinderParameter line_finder
void ConvertLineToParam(string const &linestr, size_t &rowid, size_t &polid, BLParameterSet &paramset)
convert a line of string to a BLParameterSet data structure
#define BaselineType_kNumElements
Definition: BaselineTable.h:45
uint16_t GetTypeOrder(BLParameterSet const &bl_param)
Returns order or npiece in BLParameterSet structure depending on datatype.
unsigned int uInt
Definition: aipstype.h:51