File: idgmsgridder.h

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

#ifdef HAVE_IDG

#include "../wsclean/imagebufferallocator.h"
#include "../wsclean/msgridderbase.h"

//#include "interface.h"
#include <idg-api.h>

#include "../lane.h"
#include "../uvector.h"

#include <boost/thread/mutex.hpp>

class IdgMsGridder : public MSGridderBase
{
public:
	IdgMsGridder(const class WSCleanSettings& settings, ImageBufferAllocator& allocator);
	
	virtual ~IdgMsGridder() final override { }
	
	virtual void Invert() final override;
	
	virtual void Predict(ImageBufferAllocator::Ptr real) final override;
	
	virtual void Predict(ImageBufferAllocator::Ptr real, ImageBufferAllocator::Ptr imaginary) final override;
	
	virtual ImageBufferAllocator::Ptr ImageRealResult() final override;
	
	virtual ImageBufferAllocator::Ptr ImageImaginaryResult() final override;
	
	virtual void GetGriddingCorrectionImage(double* image) const final override;
	
	virtual bool HasGriddingCorrectionImage() const final override;
	
	void SavePBCorrectedImages(class FitsWriter& writer, const class ImageFilename& filename, const std::string& filenameKind, class ImageBufferAllocator& allocator) const;
	
	void SaveBeamImage(const class ImagingTableEntry& entry, class ImageFilename& filename) const;

private:
	class AverageBeam : public AverageBeamBase
	{
	public:
		AverageBeam() { }
		bool Empty() { return (!_scalarBeam || !_matrixInverseBeam); }
		void SetScalarBeam(const std::shared_ptr<std::vector<float>>& scalarBeam) { _scalarBeam = scalarBeam; }
		void SetMatrixInverseBeam(const std::shared_ptr<std::vector<std::complex<float>>>& matrixInverseBeam) { _matrixInverseBeam = matrixInverseBeam; }
		
		/**
		 * The image resulting from IDG gridding is multiplied by the scalar beam. It is the result of this multiplication that is
		 * returned to WSClean. The scalar beam is chosen such that the Stokes I image is flat noise. There is no guarantee that
		 * Stokes Q, U, V will be flat noise, nor that there is no correlation between the noise in I,Q,U,V, but for all practical
		 * purposes they can be treated as such.
		 */
		std::shared_ptr<std::vector<float>>& ScalarBeam() { return _scalarBeam; }
		
		/**
		 * The matrix inverse beam is applied while gridding. It is the inverse of the mean square matrix beam.
		 */
		std::shared_ptr<std::vector<std::complex<float>>>& MatrixInverseBeam() { return _matrixInverseBeam; }
		
	private:
		std::shared_ptr<std::vector<float>> _scalarBeam;
		std::shared_ptr<std::vector<std::complex<float>>> _matrixInverseBeam;
	};

	AverageBeam* _averageBeam;

	virtual size_t getSuggestedWGridSize() const override final {
		return 1; // TODO
	}
		
	void gridMeasurementSet(MSGridderBase::MSData& msData);
	void gridThreadFunction();
	
	void predictMeasurementSet(MSGridderBase::MSData& msData);
	void readConfiguration();
	
	void setIdgType();
	
	std::unique_ptr<class ATermBase> getATermMaker(MSGridderBase::MSData& msData);
	
	struct IDGInversionRow : public MSGridderBase::InversionRow {
		size_t antenna1, antenna2, timeIndex;
	};
	struct IDGPredictionRow {
		double uvw[3];
		size_t dataDescId, antenna1, antenna2, timeIndex, rowId;
	};
	void predictRow(IDGPredictionRow& row);
	void computePredictionBuffer(size_t dataDescId);
	
	std::unique_ptr<idg::api::BufferSet> _bufferset;
	size_t _subgridSize;
	ao::uvector<double> _image;
	ao::uvector<float> _taper_subgrid;
	ao::uvector<float> _taper_grid;
	MSProvider* _outputProvider;
	MultiBandData _selectedBands;
	const WSCleanSettings& _settings;
	idg::api::Type _proxyType;
	int _buffersize;
	idg::api::options_type _options;
	ImageBufferAllocator& _allocator;
};

void init_optimal_taper_1D(int subgridsize, int gridsize, float kernelsize, float padding, float* taper_subgrid, float* taper_grid);
void init_optimal_gridding_taper_1D(int subgridsize, int gridsize, float kernelsize, float* taper_subgrid, float* taper_grid);

#else

#include "../wsclean/unavailablegridder.h"

#define IdgMsGridder UnavailableGridder

#endif // HAVE IDG

#endif