-
Notifications
You must be signed in to change notification settings - Fork 2
/
ch-show-intensity-file.cpp
88 lines (67 loc) · 2.64 KB
/
ch-show-intensity-file.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <iostream>
#include "ch_frb_io_internals.hpp"
using namespace std;
using namespace ch_frb_io;
static void usage()
{
cerr << "usage: ch-show-intensity-file [-t] [-m] <filename1.h5> <filename2.h5> ...\n"
<< " if -t is specified, then unit tests will be run\n"
<< " if -m is specified, then the mean intensity/weight will be shown in each channel (generates a lot of output!)\n";
exit(2);
}
int main(int argc, char **argv)
{
vector<string> filename_list;
bool run_unit_tests = false;
bool show_mean_values = false;
// Low-budget command line parsing
for (int i = 1; i < argc; i++) {
if (!strcmp(argv[i], "-t"))
run_unit_tests = true;
else if (!strcmp(argv[i], "-m"))
show_mean_values = true;
else
filename_list.push_back(string(argv[i]));
}
if (filename_list.size() == 0)
usage();
for (unsigned int ifile = 0; ifile < filename_list.size(); ifile++) {
if (ifile > 1)
cout << "\n";
intensity_hdf5_file f(filename_list[ifile], true); // noisy=true
if (show_mean_values) {
int ns = f.npol * f.nt_file;
if (ns == 0)
throw runtime_error("No data in file!\n");
for (int ifreq = 0; ifreq < f.nfreq; ifreq++) {
double sum_wi = 0.0;
double sum_wt = 0.0;
for (int s = 0; s < ns; s++) {
sum_wi += f.weights[ifreq*ns+s] * f.intensity[ifreq*ns+s];
sum_wt += f.weights[ifreq*ns+s];
}
cout << "channel " << ifreq << "/" << f.nfreq << ": ";
if (sum_wt <= 0.0) {
cout << "empty\n";
continue;
}
cout << " mean_int=" << (sum_wi/sum_wt) << ", mean_wt=" << (sum_wt/ns) << endl;
}
}
cout << " nfreq = " << f.nfreq << endl
<< " npol = " << f.npol << endl
<< " nt_file = " << f.nt_file << " # Number of time indices in file\n"
<< " nt_logical = " << f.nt_logical << " # Number of \"logical\" time indices spanned by file, including missing time regions\n"
<< " frequencies_are_increasing = " << f.frequencies_are_increasing << " # boolean (should be 'false' for CHIME)\n"
<< " freq_lo_MHz = " << f.freq_lo_MHz << endl
<< " freq_hi_MHz = " << f.freq_hi_MHz << endl
<< " time_lo = " << f.time_lo << endl
<< " time_hi = " << f.time_hi << endl
<< " dt_sample = " << f.dt_sample << endl
<< " frac_ungapped = " << f.frac_ungapped << " # Fraction of time interval which is present in file (i.e. nt_file/nt_logical)\n"
<< " frac_unmasked = " << f.frac_unmasked << " # This is sum(weights)/max(weights) with time gaps omitted\n";
if (run_unit_tests)
f.run_unit_tests();
}
return 0;
}