File: imageweights.h

package info (click to toggle)
wsclean 2.8-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 2,196 kB
  • sloc: cpp: 34,504; ansic: 234; python: 174; makefile: 10
file content (127 lines) | stat: -rw-r--r-- 3,200 bytes parent folder | download
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
#ifndef IMAGE_WEIGHTS_H
#define IMAGE_WEIGHTS_H

#include <cstddef>
#include <complex>

#include <casacore/ms/MeasurementSets/MeasurementSet.h>

#include "uvector.h"
//#include "wsclean/inversionalgorithm.h"
#include "weightmode.h"
#include "msselection.h"

class ImageWeights
{
	public:
		ImageWeights(const WeightMode& weightMode, size_t imageWidth, size_t imageHeight, double pixelScaleX, double pixelScaleY, bool weightsAsTaper, double superWeight);
		
		double GetWeight(double u, double v) const
		{
			return sampleGridValue(u, v);
		}

		void Grid(casacore::MeasurementSet& ms, const MSSelection& selection);
		void Grid(class MSProvider& ms, const MSSelection& selection);
		void Grid(double u, double v, double weight)
		{
			int x,y;
			uvToXY(u, v, x, y);
			
			if(isWithinLimits(x, y))
			{
				size_t index = (size_t) x + (size_t) y*_imageWidth;
				_grid[index] += weight;
				_totalSum += weight;
			}
		}
		
		void FinishGridding();
		
		void SetMaxUVRange(double maxUVInLambda);
		void SetMinUVRange(double minUVInLambda);
		void SetGaussianTaper(double beamSize);
		void SetTukeyTaper(double transitionSizeInLambda, double maxUVInLambda);
		void SetTukeyInnerTaper(double transitionSizeInLambda, double minUVInLambda);
		void SetEdgeTaper(double sizeInLambda);
		void SetEdgeTukeyTaper(double transitionSizeInLambda, double edgeSizeInLambda);
		
		void GetGrid(double* image) const;
		void Save(const std::string& filename) const;
		
		void RankFilter(double rankLimit, size_t windowSize);
		
		size_t Width() const { return _imageWidth; }
		size_t Height() const { return _imageHeight; }
	private:
		ImageWeights(const ImageWeights&) = delete;
		void operator=(const ImageWeights&) = delete;
		
		
		void uvToXY(double u, double v, int& x, int& y) const
		{
			if(v < 0.0) {
				u = -u;
				v = -v;
			}
			x = int(floor(u*_imageWidth*_pixelScaleX + _imageWidth/2));
			y = int(floor(v*_imageHeight*_pixelScaleY));
		}
		
		void xyToUV(int x, int y, double& u, double& v) const
		{
			if(y < 0.0) {
				x = -x;
				y = -y;
			}
			
			u = double(x-int(_imageWidth/2)) / double(_imageWidth*_pixelScaleX);
			v = double(y) / double(_imageHeight*_pixelScaleY);
		}
		
		bool isWithinLimits(int x, int y) const
		{		
			return x >= 0 && x < int(_imageWidth) && y < int(_imageHeight/2);
		}
		
		double sampleGridValue(double u, double v) const
		{
			int x,y;
			uvToXY(u, v, x, y);
			if(isWithinLimits(x, y))
				return _grid[(size_t) x + (size_t) y*_imageWidth];
			else {
				return 0.0;
			}
		}
		
		double windowMean(size_t x, size_t y, size_t windowSize);
		
		/**
		 * Returns Tukey tapering function. This function is
		 * 0 when x=0 and 1 when x=n.
		 */
		double tukeyFrom0ToN(double x, double n)
		{
			return 0.5 * (1.0 + cos((M_PI/n) * (x - n)));
		}
		
		template<typename T>
		static T frequencyToWavelength(const T frequency)
		{
			return speedOfLight() / frequency; 
		}
		static long double speedOfLight()
		{
			return 299792458.0L;
		}
		const WeightMode _weightMode;
		std::size_t _imageWidth, _imageHeight;
		const double _pixelScaleX, _pixelScaleY;
		
		ao::uvector<double> _grid;
		double _totalSum;
		bool _isGriddingFinished, _weightsAsTaper;
};

#endif