00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef _CASA_BLPARAMETER_PARSER_H_
00028 #define _CASA_BLPARAMETER_PARSER_H_
00029
00030 #include <string>
00031 #include <map>
00032 #include <vector>
00033
00034 #include <climits>
00035 #include <sstream>
00036
00037 #include <casa/aipstype.h>
00038 #include <casa/Logging/LogIO.h>
00039 #include <casa/Logging/LogOrigin.h>
00040 #include <libsakura/sakura.h>
00041 #include <singledish/SingleDish/BaselineTable.h>
00042
00043 namespace casa {
00044
00045 struct LineFinderParameter {
00046 LineFinderParameter(bool const use_lf=false, float const thresh=5.0,
00047 std::vector<size_t> const &edges=std::vector<size_t>(2,0),
00048 size_t const chavglim=0)
00049 {
00050 use_line_finder=use_lf;
00051 threshold = thresh;
00052 chan_avg_limit = chavglim;
00053 for (size_t iedge=0; iedge < 2; ++ iedge) {
00054 edge[iedge] = edges[iedge % edges.size()] ;
00055 }
00056 }
00057 bool use_line_finder;
00058 float threshold;
00059 size_t edge[2];
00060 size_t chan_avg_limit;
00061 };
00062
00063 struct BLParameterSet {
00064 BLParameterSet(string const blmask="", uint16_t const nfit_max=0,
00065 float const clipthres=3.0,
00066 LineFinderParameter lf_param=LineFinderParameter(),
00067 size_t const bl_type = BaselineType_kNumElements,
00068 uint16_t const fit_order = USHRT_MAX,
00069 size_t const num_piece = USHRT_MAX,
00070 std::vector<size_t> const &nwaves = std::vector<size_t>()
00071 )
00072 {
00073 baseline_mask = blmask;
00074 num_fitting_max = nfit_max;
00075 clip_threshold_sigma = clipthres;
00076 line_finder = lf_param;
00077 baseline_type = bl_type;
00078 order = fit_order;
00079 npiece = num_piece;
00080 nwave = nwaves;
00081 }
00082
00083 void PrintSummary() {
00084 LogIO os(LogOrigin("BLParameterSet","PrintSummary"));
00085 os << "- mask: " << baseline_mask << LogIO::POST;
00086 os << "- clip: iteration=" << num_fitting_max
00087 << ", threshold=" << clip_threshold_sigma << LogIO::POST;
00088 os
00089 << "- line finder: "
00090 << (line_finder.use_line_finder==1 ? "true" : "false")
00091 << ", threshold=" << line_finder.threshold
00092 << ", edge=[" << line_finder.edge[0] << ","
00093 << line_finder.edge[1] << "], chan_average="
00094 << line_finder.chan_avg_limit << LogIO::POST;
00095 os << "- baseline: type=" << baseline_type
00096 << ", order=" << order << ", npiece=" << npiece
00097 << LogIO::POST;
00098 }
00099
00100 string baseline_mask;
00101 uint16_t num_fitting_max;
00102 float clip_threshold_sigma;
00103 LineFinderParameter line_finder;
00104 size_t baseline_type;
00105 uint16_t order;
00106 size_t npiece;
00107 std::vector<size_t> nwave;
00108 };
00109
00110
00111 class BLParameterParser {
00112 public:
00113
00114 explicit BLParameterParser(string const file_name);
00115 ~BLParameterParser();
00116
00117
00118
00119
00120 bool GetFitParameter(size_t const rowid,size_t const polid,
00121 BLParameterSet &bl_param);
00122
00123
00124 inline string get_file_name(){return blparam_file_;};
00125
00126 inline std::vector<size_t> get_function_types(){return baseline_types_;};
00127
00128 uint16_t get_max_order(size_t const bltype);
00129
00130 protected:
00131
00132 void initialize();
00133 void Clearup();
00134
00135 void parse(string const file_name);
00136
00137 void SplitLine(string const &linestr, char const separator,
00138 std::vector<string> &strvec);
00139
00140 void ConvertLineToParam(string const &linestr, size_t &rowid,
00141 size_t &polid, BLParameterSet ¶mset);
00142
00143 uint16_t GetTypeOrder(BLParameterSet const &bl_param);
00144
00145
00146 string blparam_file_;
00147 std::map<const std::pair<size_t, size_t>, BLParameterSet*> bl_parameters_;
00148 std::vector<size_t> baseline_types_;
00149 uint16_t max_orders_[BaselineType_kNumElements];
00150
00151 typedef enum {BLParameters_kRow = 0,
00152 BLParameters_kPol,
00153 BLParameters_kMask,
00154 BLParameters_kNumIteration,
00155 BLParameters_kClipThreshold,
00156 BLParameters_kLineFinder,
00157 BLParameters_kLFThreshold,
00158 BLParameters_kLeftEdge,
00159 BLParameters_kRightEdge,
00160 BLParameters_kChanAverageLim,
00161 BLParameters_kBaselineType,
00162 BLParameters_kOrder,
00163 BLParameters_kNPiece,
00164 BLParameters_kNWave,
00165 BLParameters_kNumElements
00166 } BLParameters;
00167
00168
00169 template<typename DataType>
00170 inline DataType ConvertString(string const &svalue)
00171 {
00172 DataType out_value;
00173 std::istringstream istr(svalue.data());
00174 istr >> out_value;
00175 return out_value;
00176 };
00177
00178 };
00179
00180 struct BLIdSet {};
00181
00182 class BLTableParser : public BLParameterParser {
00183 public:
00184 explicit BLTableParser(string const file_name);
00185 ~BLTableParser();
00186 bool GetFitParameterIdx(double const time, double const interval,
00187 size_t const scanid, size_t const beamid,
00188 size_t const antid, size_t const spwid, size_t &idx);
00189 void GetFitParameterByIdx(size_t const idx, size_t const ipol,
00190 bool &apply, std::vector<float> &coeff,
00191 std::vector<double> &boundary,
00192 BLParameterSet &bl_param);
00193 private:
00194 void initialize();
00195 void parse();
00196
00197 uint16_t GetTypeOrder(size_t const &baseline_type,
00198 uInt const irow, uInt const ipol);
00199 BaselineTable *bt_;
00200 std::map<string, std::vector<double> > sortedTimes_;
00201 std::map<string, std::vector<uInt> > timeSortedIdx_;
00202 std::map<string, size_t> numRows_;
00203 };
00204
00205 }
00206
00207 #endif