Commits
Darrell Schiebel authored 82f6ec0b1b7 Merge
32 32 | |
33 33 | |
34 34 | using namespace casacore; |
35 35 | using namespace casac; |
36 36 | |
37 37 | namespace casa { |
38 38 | namespace vi { |
39 39 | |
40 40 | const String StatWtTVI::CHANBIN = "stchanbin"; |
41 41 | |
42 - | const Complex StatWtTVI::DEFAULT_MODEL_VALUE(1, 0); |
43 - | |
44 42 | StatWtTVI::StatWtTVI(ViImplementation2 * inputVii, const Record &configuration) |
45 43 | : TransformingVi2 (inputVii) { |
46 44 | // Parse and check configuration parameters |
47 45 | // Note: if a constructor finishes by throwing an exception, the memory |
48 46 | // associated with the object itself is cleaned up there is no memory leak. |
49 47 | ThrowIf( |
50 48 | ! _parseConfiguration(configuration), |
51 49 | "Error parsing StatWtTVI configuration" |
52 50 | ); |
51 + | // FIXME when the TVI framework has methods to |
52 + | // check for metadata, like the existence of |
53 + | // columns, remove references to the original MS |
54 + | const auto& origMS = ms(); |
53 55 | ThrowIf( |
54 56 | (_column == CORRECTED || _column == RESIDUAL) |
55 - | && ! ms().isColumn(MSMainEnums::CORRECTED_DATA), |
57 + | && ! origMS.isColumn(MSMainEnums::CORRECTED_DATA), |
56 58 | "StatWtTVI requires the MS to have a " |
57 59 | "CORRECTED_DATA column. This MS does not" |
58 60 | ); |
59 61 | ThrowIf( |
60 62 | (_column == DATA || _column == RESIDUAL_DATA) |
61 - | && ! ms().isColumn(MSMainEnums::DATA), |
63 + | && ! origMS.isColumn(MSMainEnums::DATA), |
62 64 | "StatWtTVI requires the MS to have a " |
63 65 | "DATA column. This MS does not" |
64 66 | ); |
65 - | _useDefaultModelValue = (_column == RESIDUAL || _column == RESIDUAL_DATA) |
66 - | && ! ms().isColumn(MSMainEnums::MODEL_DATA); |
67 + | _noModel = (_column == RESIDUAL || _column == RESIDUAL_DATA) |
68 + | && ! origMS.isColumn(MSMainEnums::MODEL_DATA) |
69 + | && ! origMS.source().isColumn(MSSourceEnums::SOURCE_MODEL); |
67 70 | // Initialize attached VisBuffer |
68 71 | setVisBuffer(createAttachedVisBuffer(VbRekeyable)); |
69 72 | } |
70 73 | |
71 74 | StatWtTVI::~StatWtTVI() {} |
72 75 | |
73 76 | Bool StatWtTVI::_parseConfiguration(const Record& config) { |
74 77 | String field = CHANBIN; |
75 78 | if (config.isDefined(field)) { |
76 79 | // channel binning |
938 941 | _computeWeightsSlidingTimeWindow(chunkData, chunkFlags, rowMap, spw); |
939 942 | } |
940 943 | |
941 944 | const casacore::Cube<casacore::Complex> StatWtTVI::_dataCube(const VisBuffer2 *const vb) const { |
942 945 | switch (_column) { |
943 946 | case CORRECTED: |
944 947 | return vb->visCubeCorrected(); |
945 948 | case DATA: |
946 949 | return vb->visCube(); |
947 950 | case RESIDUAL: |
948 - | return _useDefaultModelValue ? vb->visCubeCorrected() - DEFAULT_MODEL_VALUE |
949 - | : vb->visCubeCorrected() - vb->visCubeModel(); |
951 + | if (_noModel) { |
952 + | return vb->visCubeCorrected(); |
953 + | } |
954 + | else { |
955 + | return vb->visCubeCorrected() - vb->visCubeModel(); |
956 + | } |
950 957 | case RESIDUAL_DATA: |
951 - | return _useDefaultModelValue ? vb->visCube() - DEFAULT_MODEL_VALUE |
952 - | : vb->visCube() - vb->visCubeModel(); |
958 + | if(_noModel) { |
959 + | return vb->visCube(); |
960 + | } |
961 + | else { |
962 + | return vb->visCube() - vb->visCubeModel(); |
963 + | } |
953 964 | default: |
954 965 | ThrowCc("Logic error: column type not handled"); |
955 966 | } |
956 967 | } |
957 968 | |
958 969 | void StatWtTVI::_computeWeightsSlidingTimeWindow( |
959 970 | const casacore::Cube<casacore::Complex>& data, |
960 971 | const casacore::Cube<casacore::Bool>& flags, |
961 972 | const std::vector<std::set<uInt>>& rowMap, |
962 973 | uInt spw |