-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathdat_file_writer.cpp
More file actions
73 lines (63 loc) · 2.54 KB
/
Copy pathdat_file_writer.cpp
File metadata and controls
73 lines (63 loc) · 2.54 KB
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
#include <boost/algorithm/string.hpp>
#include <fmt/core.h>
#include <string>
#include <vector>
#include "dat_file_writer.h"
#include "h5_reader.h"
using namespace std;
/*
Opens a dat file for writing, to log hits that we find.
Some metadata for headers is copied out from the h5 file.
*/
DatFileWriter::DatFileWriter(const string& filename,
const FilterbankFileReader& metadata,
double max_drift) : metadata(metadata) {
hit_count = 0;
file.open(filename);
vector<string> parts;
boost::split(parts, filename, boost::is_any_of("/"));
file << "# -------------------------- o --------------------------\n";
file << "# File ID: " << parts[parts.size() - 1] << " \n";
file << "# -------------------------- o --------------------------\n";
file << "# Source:" << metadata.source_name << "\n";
file << fmt::format("# MJD: {:18.12f}\tRA: {:.6f}\tDEC: {:.6f}\n",
metadata.tstart, metadata.src_raj, metadata.src_dej);
file << fmt::format("# DELTAT: {:10.6f}\tDELTAF(Hz): {:10.6f}\t"
"max_drift_rate: {:10.6f}\tobs_length: {:10.6f}\n",
metadata.tsamp, metadata.foff * 1000000.0, max_drift,
metadata.num_timesteps * metadata.tsamp);
file << "# --------------------------\n"
"# Top_Hit_# \t"
"Drift_Rate \t"
"SNR \t"
"Uncorrected_Frequency \t"
"Corrected_Frequency \t"
"Index \t"
"freq_start \t"
"freq_end \t"
"SEFD \t"
"SEFD_freq \t"
"Coarse_Channel_Number \t"
"Full_number_of_hits \t"
"\n"
"# --------------------------\n";
file << flush;
}
DatFileWriter::~DatFileWriter() {
file.close();
}
// Ignores the beam
void DatFileWriter::recordHit(DedopplerHit hit, const float* input) {
++hit_count;
int global_index = hit.coarse_channel * metadata.coarse_channel_size + hit.index;
double frequency = metadata.fch1 + global_index * metadata.foff;
// Currently we just output one frequency for all frequency-type columns.
// We also just output 1 instead of counting up pre-deduping hits because I suspect
// that nobody wants it, and it's bothersome to calculate with our current algorithm.
// TODO: see what the astronomers actually want here
file << fmt::format("{}\t{:10.6f}\t{:10.6f}\t{:14.6f}\t{:14.6f}\t{}\t{:14.6f}\t{:14.6f}\t",
hit_count, hit.drift_rate, hit.snr, frequency,
frequency, hit.index, frequency, frequency);
file << fmt::format("0.0\t0.000000\t{}\t1\t\n", hit.coarse_channel);
file << flush;
}