polyco.h
1//-*-C++-*-
2/***************************************************************************
3 *
4 * Copyright (C) 1999 by Willem van Straten
5 * Licensed under the Academic Free License version 2.1
6 *
7 ***************************************************************************/
8
9// psrchive/Util/tempo/polyco.h
10
11#ifndef __POLY_H
12#define __POLY_H
13
14#include "Pulsar/Predictor.h"
15#include "Pulsar/Generator.h"
16
17#include <string>
18#include <vector>
19
22
23 friend class polyco;
24
25protected:
26
28 std::string psrname;
29
31 std::string date;
32
34 std::string utc;
35
37 Pulsar::Phase ref_phase;
38
40 double ref_freq;
41
44
47
49 double freq;
50
52 bool binary;
53
55 double binph;
56
58 double binfreq;
59
61 float dm;
62
64 double nspan_mins;
65
68
71
74
76 std::vector<double> coefs;
77
79 void init();
80
82 mutable bool keep;
83
84public:
85
87 class Expert;
88 friend class Expert;
89
91 static double precision;
92
94 polynomial ();
95
97 polynomial (const polynomial& poly);
98
100 ~polynomial ();
101
102 const polynomial& operator = (const polynomial& poly);
103
104 int load (std::string* instr);
105 int unload (std::string *outstr) const;
106 int unload (FILE* fptr) const;
107
108 void prettyprint () const;
109
111 double period (const MJD &t) const;
112
114 Pulsar::Phase phase (const MJD &t) const;
115
117 MJD iphase (const Pulsar::Phase& p, const MJD* = 0) const;
118
120 long double frequency (const MJD &t) const;
121
123 Pulsar::Phase dispersion (const MJD &t, long double MHz) const;
124
126 double chirp (const MJD &t) const;
127
129 double accel (const MJD &t) const { return chirp(t)/frequency(t)*2.9979e8; }
130
131 bool is_tempov11 () const { return tempov11; }
132 char get_telescope () const { return telescope; }
133 double get_freq () const { return freq; }
134 MJD get_reftime () const { return ref_time; }
135 Pulsar::Phase get_refphase () const { return ref_phase; }
136 double get_reffrequency () const { return ref_freq; }
137 double get_nspan () const { return nspan_mins; }
138 float get_dm () const { return dm; }
139 int get_ncoeff () const { return (int) coefs.size(); }
140 double get_doppler_shift () const { return doppler_shift / 1e4; }
141 std::string get_psrname () const { return psrname; }
142 bool get_binary () const { return binary; }
143 double get_binph () const { return binph; }
144 double get_log_rms_resid () const { return log_rms_resid; }
145
146 static double flexibility;
147
148 MJD start_time( double f = flexibility ) const
149 { return ref_time - nspan_mins * (1.0+f) * 60.0/2.0; };
150 MJD end_time( double f = flexibility ) const
151 { return ref_time + nspan_mins * (1.0+f) * 60.0/2.0; };
152
153 Pulsar::Phase start_phase( double f = flexibility ) const
154 { return phase (start_time(f)); };
155 Pulsar::Phase end_phase( double f = flexibility ) const
156 { return phase (end_time(f)); };
157
158 friend bool operator == (const polynomial &, const polynomial &);
159 friend bool operator != (const polynomial &, const polynomial &);
160};
161
164
165public:
166 Expert (polynomial* p) { instance = p; }
167
168 void set_tempov11 (bool v) { instance->tempov11 = v; }
169 void set_telescope (char v) { instance->telescope = v; }
170 void set_freq (double v) { instance->freq = v; }
171 void set_reftime (const MJD& v) { instance->ref_time = v; }
172 void set_refphase (const Pulsar::Phase& v) { instance->ref_phase = v; }
173 void set_reffrequency (double v) { instance->ref_freq = v; }
174 void set_nspan (double v) { instance->nspan_mins = v; }
175 void set_dm (float v) { instance->dm = v; }
176 void set_ncoef (unsigned v) { instance->coefs.resize(v); }
177 void set_doppler_shift (double v) { instance->doppler_shift = v * 1e4; }
178 void set_psrname (const std::string& v) { instance->psrname = v; }
179 void set_binary (bool v) { instance->binary = v; }
180 void set_binph (double v) { instance->binph = v; }
181
182 double* get_coefs () { return &(instance->coefs[0]); }
183
184 polynomial* instance;
185};
186
188class polyco : public Pulsar::Predictor {
189
190public:
191 static bool debug;
192
194 std::vector<polynomial> pollys;
195
197 polyco ();
198
200 polyco (const polyco&);
201
203 const polyco& operator = (const polyco&);
204
206 ~polyco ();
207
208 //
209 // Pulsar::Predictor implementation
210 //
211
213 Predictor* clone () const;
214
217
219 void insert (const Predictor*);
220
222 void keep (const std::vector<MJD>& epochs);
223
225 bool matches (const Predictor*) const;
226
228 void set_observing_frequency (long double MHz);
229
231 long double get_observing_frequency () const;
232
234 Pulsar::Phase phase (const MJD& t) const
235 { return best(t).phase(t); }
236
238 Pulsar::Phase phase (const MJD& t, long double MHz) const
239 { const polynomial& b = best(t); return b.phase(t) + b.dispersion(t,MHz); }
240
242 MJD iphase (const Pulsar::Phase& phase, const MJD* guess = 0) const
243 { return best(phase).iphase(phase, guess); }
244
246 long double frequency (const MJD& t) const
247 { return best(t).frequency(t); }
248
250 Pulsar::Phase dispersion (const MJD &t, long double MHz) const
251 { return best(t).dispersion(t,MHz); }
252
254 void load (FILE*);
255
257 void unload (FILE*) const;
258
259 //
260 // the rest
261 //
262
264 polyco (const std::string& id);
265
267 int load (const std::string& filename);
268 int load (std::string* instr);
269
270 // these functions return -1 upon error
271 int unload (const std::string& filename) const;
272
273 // these functions return the number of bytes unloaded (-1 on error)
274 int unload (std::string *outstr) const;
275
276 void append (const polyco& poly);
277
278 void prettyprint () const;
279
280 const polynomial* nearest (const MJD &t) const;
281
282 const polynomial& best (const MJD &t) const;
283 const polynomial& best (const Pulsar::Phase &p) const;
284
285 int i_nearest (const MJD &t, bool throw_exception = false) const;
286 int i_nearest (const Pulsar::Phase &p, bool throw_exception = false) const;
287
288 double doppler_shift (const MJD& t) const
289 { return best(t).get_doppler_shift(); };
290
291 double period(const MJD& t) const
292 { return best(t).period(t); };
293
294 double chirp(const MJD& t) const
295 { return best(t).chirp(t); };
296
297 double accel(const MJD& t) const
298 { return best(t).accel(t); };
299
300 char get_telescope () const;
301 double get_freq () const;
302 MJD get_reftime () const;
303 double get_refperiod () const;
304 double get_nspan () const;
305 float get_dm () const;
306 int get_ncoeff () const;
307 std::string get_psrname () const;
308
309 bool is_tempov11() const;
310
311 MJD start_time () const { return pollys.front().start_time(); };
312 MJD end_time () const { return pollys.back().end_time(); };
313
314 Pulsar::Phase start_phase () const { return pollys.front().start_phase(); };
315 Pulsar::Phase end_phase () const { return pollys.back().end_phase(); };
316
317 friend bool operator == (const polyco &, const polyco &);
318 friend bool operator != (const polyco &, const polyco &);
319
320private:
321
322 // these attributes enable optimized i_nearest
323 mutable int last_index;
324
325 mutable MJD last_epoch;
326 mutable double last_span_epoch;
327
328 mutable Pulsar::Phase last_phase;
329 mutable double last_span_phase;
330
331 void init();
332 void set_last (int i) const;
333};
334
335inline std::ostream& operator<< (std::ostream& ostr, const polyco& p)
336{
337 std::string out; p.unload(&out); return ostr << out;
338}
339
340#endif
341
Class for representing modified Julian dates with high precision.
Definition MJD.h:23
Generator of functions that predict pulse phase.
Definition Generator.h:26
Functions that predict pulse phase.
Definition Predictor.h:28
Implements Predictor class for Tempo.
Definition polyco.h:188
Pulsar::Phase phase(const MJD &t, long double MHz) const
Return the phase plus the dispersion delay.
Definition polyco.h:238
long double get_observing_frequency() const
Get the observing frequency at which phase and epoch are related.
Definition polyco.C:624
void set_observing_frequency(long double MHz)
Set the observing frequency at which predictions will be made.
Definition polyco.C:620
void load(FILE *)
Load from an open stream.
Definition polyco.C:728
void unload(FILE *) const
Unload to an open stream.
Definition polyco.C:802
void keep(const std::vector< MJD > &epochs)
Keep only the components required to span the given epochs.
Definition polyco.C:863
Pulsar::Phase phase(const MJD &t) const
Return the phase, given the epoch.
Definition polyco.h:234
MJD iphase(const Pulsar::Phase &phase, const MJD *guess=0) const
Return the epoch, given the phase.
Definition polyco.h:242
void insert(const Predictor *)
Add the information from the supplied predictor to self.
Definition polyco.C:597
bool matches(const Predictor *) const
Return true if the Predictor configuration matches this.
Definition polyco.C:607
std::vector< polynomial > pollys
The polynomial sets.
Definition polyco.h:194
~polyco()
Destructor.
Definition polyco.C:568
polyco()
Default constructor.
Definition polyco.C:530
Pulsar::Phase dispersion(const MJD &t, long double MHz) const
Return the phase correction for dispersion delay.
Definition polyco.h:250
const polyco & operator=(const polyco &)
Assignment operator.
Definition polyco.C:547
long double frequency(const MJD &t) const
Return the spin frequency, given the epoch.
Definition polyco.h:246
Pulsar::Generator * generator() const
Return a new Generator set up to produce a new Predictor like self.
Definition polyco.C:588
Predictor * clone() const
Return a new, copy constructed instance of self.
Definition polyco.C:583
Expert interface to polynomial attributes.
Definition polyco.h:163
Describes a single Tempo polyco set.
Definition polyco.h:21
std::string psrname
The pulsar name.
Definition polyco.h:28
std::string utc
The UTC string.
Definition polyco.h:34
bool tempov11
Flag that the polyco was created using TEMPO v.11 or greater.
Definition polyco.h:67
double freq
Observing frequency.
Definition polyco.h:49
MJD iphase(const Pulsar::Phase &p, const MJD *=0) const
Returns the time at the given pulse phase.
Definition polyco.C:411
bool keep
used by polyco::keep to determine if this polynomial is used
Definition polyco.h:82
double doppler_shift
Doppler shift due to Earth's motion along line of sight.
Definition polyco.h:70
double log_rms_resid
log of the r.m.s residual between polynomial and model
Definition polyco.h:73
double period(const MJD &t) const
Returns the pulse period (in seconds) at the given time.
Definition polyco.C:454
double binph
if binary, binary phase
Definition polyco.h:55
std::string date
The calendar date string.
Definition polyco.h:31
bool binary
true if the pulsar is in a binary system
Definition polyco.h:52
void init()
intializes all values to null
Definition polyco.C:47
double chirp(const MJD &t) const
Returns the spin frequency derivative (in Hz/s) at the given time.
Definition polyco.C:436
Pulsar::Phase phase(const MJD &t) const
Returns the pulse phase (in turns) at the given time.
Definition polyco.C:391
static double precision
Determines the precision of iphase (stopping threshold) in seconds.
Definition polyco.h:91
~polynomial()
destructor
Definition polyco.C:100
float dm
dispersion measure
Definition polyco.h:61
polynomial()
default constructor
Definition polyco.C:62
MJD ref_time
The epoch to which the polynomial is referenced.
Definition polyco.h:43
double nspan_mins
number of minutes spanned by polynomial
Definition polyco.h:64
double accel(const MJD &t) const
Returns the apparent acceleration toward observer (m s^-2)
Definition polyco.h:129
double ref_freq
Reference rotation frequency, F0 (Hz)
Definition polyco.h:40
Pulsar::Phase ref_phase
The pulsar phase at reftime.
Definition polyco.h:37
long double frequency(const MJD &t) const
Returns the spin frequency (in Hz) at the given time.
Definition polyco.C:419
char telescope
TEMPO telescope id code.
Definition polyco.h:46
std::vector< double > coefs
polynomial coefficients
Definition polyco.h:76
Pulsar::Phase dispersion(const MJD &t, long double MHz) const
Return the phase correction for dispersion delay.
Definition polyco.C:459
double binfreq
if binary, binary frequency
Definition polyco.h:58

Generated using doxygen 1.14.0