-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapplybeam.cpp
68 lines (59 loc) · 1.59 KB
/
applybeam.cpp
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
#include "fitsreader.h"
#include "fitswriter.h"
#include <iostream>
#include <limits>
#include <vector>
#include <stdexcept>
#include <string>
int main(int argc, char *argv[])
{
if(argc < 4)
{
std::cout << "Syntax: applybeam [-not-squared / -is-weight] <inpfits> <beamfits> <outfits>\n";
return 0;
}
bool squared = true, isWeight = false;
int argi = 1;
while(argi < argc && argv[argi][0] == '-')
{
std::string p(&argv[argi][1]);
if(p == "not-squared")
{
squared = false;
}
else if(p == "is-weight")
{
isWeight = true;
}
else throw std::runtime_error("Bad parameter");
++argi;
}
const char *inpFits = argv[argi];
const char *beamFits = argv[argi+1];
const char *outFits = argv[argi+2];
FitsReader inpReader(inpFits);
size_t
width = inpReader.ImageWidth(),
height = inpReader.ImageHeight();
FitsReader beamReader(beamFits);
if(beamReader.ImageWidth() != width || beamReader.ImageHeight() != height)
throw std::runtime_error("Beam and image do not have same size!");
std::vector<double> inpImage(width*height), beamImage(width*height);
inpReader.Read<double>(&inpImage[0]);
beamReader.Read<double>(&beamImage[0]);
std::vector<double>::iterator beamIter = beamImage.begin();
for(std::vector<double>::iterator i=inpImage.begin(); i!=inpImage.end(); ++i)
{
if(std::fabs(*beamIter) < 1e-2)
*i = std::numeric_limits<double>::quiet_NaN();
else if(isWeight)
*i /= sqrt(*beamIter);
else if(squared)
*i /= *beamIter * *beamIter;
else
*i /= *beamIter;
++beamIter;
}
FitsWriter writer(inpReader);
writer.Write<double>(outFits, &inpImage[0]);
}