Fold.h
1 //-*-C++-*-
2 /***************************************************************************
3  *
4  * Copyright (C) 2002-2010 by Willem van Straten
5  * Licensed under the Academic Free License version 2.1
6  *
7  ***************************************************************************/
8 
9 // dspsr/Signal/Pulsar/dsp/Fold.h
10 
11 #ifndef __baseband_dsp_Fold_h
12 #define __baseband_dsp_Fold_h
13 
14 #include "dsp/Transformation.h"
15 #include "dsp/TimeSeries.h"
16 #include "dsp/PhaseSeries.h"
17 
18 namespace Pulsar
19 {
20  class Predictor;
21  class Parameters;
22 }
23 
24 namespace dsp
25 {
26  class WeightedTimeSeries;
27  class ObservationChange;
28 
30 
34  class Fold : public Transformation <TimeSeries, PhaseSeries>
35  {
36  friend class MultiFold;
37 
38  public:
39 
41  static unsigned maximum_nbin;
42 
44  static double minimum_bin_width;
45 
47  static bool power_of_two;
48 
50  Fold ();
51 
53  ~Fold ();
54 
56  virtual Fold* clone () const;
57 
58  PhaseSeries* get_output () const;
59 
61  virtual void prepare ();
62 
64  void prepare (const Observation* observation);
65 
67  void combine (const Operation*);
68 
70  void reset ();
71 
73  virtual void finish ();
74 
76  uint64_t bytes_storage() const override;
77 
79  PhaseSeries* get_result () const;
80 
82  void set_nbin (unsigned _nbin) { requested_nbin = _nbin; }
84  unsigned get_nbin () const { return requested_nbin; }
85 
86  void set_force_sensible_nbin (bool _force_sensible) { force_sensible_nbin = _force_sensible; }
87  bool get_force_sensible_nbin () { return force_sensible_nbin; }
88 
90  void set_ncoef (unsigned ncoef);
92  unsigned get_ncoef () const { return ncoef; }
93 
95  void set_nspan (unsigned nspan);
97  unsigned get_nspan () const { return nspan; }
98 
100  void set_change (const ObservationChange*);
101 
103 
104  void set_folding_period (double folding_period);
105 
107  void set_reference_epoch (const MJD&);
108 
110  double get_folding_period () const;
111 
113  bool has_folding_period() const { return (folding_period>0); }
114 
117 
119  bool has_folding_predictor () const;
120 
123 
126 
128  bool has_pulsar_ephemeris() const { return pulsar_ephemeris.ptr(); }
129 
132 
134  virtual void set_reference_phase (double phase);
136  double get_reference_phase () const { return reference_phase; }
137 
139  void set_input (const TimeSeries* input);
140 
142  unsigned choose_nbin (bool quiet = false) const;
143 
145  class Engine;
146 
147  virtual void set_engine (Engine*);
148 
150  virtual void set_cerr (std::ostream& os) const;
151 
152  virtual Engine * get_engine() { return engine; }
153 
154  protected:
155 
157  virtual void transformation ();
158 
160  virtual void fold (uint64_t nweights, const unsigned* weights,
161  unsigned ndatperweight, unsigned weight_idat);
162 
164  virtual void set_limits (const Observation* input);
165 
167  virtual void check_input();
168 
170  virtual void prepare_output();
171 
173  void set_idat_start(uint64_t _idat_start){ idat_start = _idat_start; }
175  uint64_t get_idat_start(){ return idat_start; }
177  void set_ndat_fold(uint64_t _ndat_fold){ ndat_fold = _ndat_fold; }
179  uint64_t get_ndat_fold(){ return ndat_fold; }
180 
182  double get_pfold (const MJD& start_time);
183 
185  double get_phi (const MJD& start_time);
186 
189 
192 
194  unsigned folding_nbin;
195 
197  unsigned requested_nbin;
198 
199  bool force_sensible_nbin;
200 
203 
206 
208  unsigned ncoef;
209 
211  unsigned nspan;
212 
215 
217  bool built;
218 
220  uint64_t idat_start;
221 
223  uint64_t ndat_fold;
224 
226  // This is called from prepare() rather than the constructor so that reducer
227  // can set parameters (globally) if they have not been initialised locally for a given
228  // dsp::Fold
229  void initialise();
230 
233 
234  private:
235 
236  // Generates folding_predictor from the given ephemeris
238  const Observation*);
239 
241  Reference::To<const Pulsar::Predictor> folding_predictor;
242 
245 
247  double pfold;
248 
249  };
250 
252  class Fold::Engine : public OwnStream
253  {
254  public:
255 
256  void set_parent (Fold*);
257 
259  virtual void set_nbin (unsigned nbin) = 0;
260 
262  virtual void set_bin (uint64_t idat, double ibin, double bins_per_samp) = 0;
263 
264  // Alternative fucntion to setup binplan all at once, rather than point by point
265  virtual uint64_t set_bins (double phi, double phase_per_sample, uint64_t _ndat, uint64_t idat_start)=0;
266  // Set this property true to use set_bins instead of set_bin
267  bool use_set_bins;
268  // fuction used when set_bins is used to update the number of hits in each bin
269  virtual uint64_t get_bin_hits (int ibin)=0;
270 
272  virtual uint64_t get_ndat_folded () const = 0;
273 
275  virtual PhaseSeries* get_profiles () = 0;
276 
278  virtual void fold () = 0;
279 
281  virtual void synch (PhaseSeries*) = 0;
282 
284  virtual void zero () = 0;
285 
287  virtual void set_ndat (uint64_t ndat, uint64_t idat_start) {}
288 
289  protected:
290 
291  float* output;
292  unsigned output_span;
293 
294  const float* input;
295  unsigned input_span;
296 
297  unsigned* hits;
298  unsigned hits_nchan;
299  bool zeroed_samples;
300 
301  unsigned ndat_fold;
302  uint64_t idat_start;
303 
304  unsigned nchan, npol, ndim;
305 
307  void setup ();
308 
309  Fold* parent;
310 
311  bool synchronized;
312  };
313 
314 }
315 
316 #endif // !defined(__Fold_h)
double get_reference_phase() const
Get the reference phase (phase of bin zero)
Definition: Fold.h:136
virtual void set_limits(const Observation *input)
Set the idat_start and ndat_fold attributes.
Definition: Fold.C:966
double get_folding_period() const
Get the period at which data are being folded (in seconds)
Definition: Fold.C:428
uint64_t idat_start
INTERNAL: the time sample at which to start folding.
Definition: Fold.h:220
virtual void set_bin(uint64_t idat, double ibin, double bins_per_samp)=0
Set the phase bin into which the idat'th sample will be integrated.
Reference::To< const ObservationChange > change
The attributes to be changed in the output PhaseSeries.
Definition: Fold.h:214
void initialise()
Makes sure parameters are initialised.
Definition: Fold.C:72
void set_reference_epoch(const MJD &)
Set the reference epoch that defines phase = 0 when folding_period > 0.
Definition: Fold.C:399
virtual void prepare()
Prepare to fold the input TimeSeries.
Definition: Fold.C:110
uint64_t get_idat_start()
Used by the MultiFold class.
Definition: Fold.h:175
void set_nbin(unsigned _nbin)
Set the number of phase bins into which data will be folded.
Definition: Fold.h:82
PhaseSeries * get_result() const
Before returning output, ensure that it is synchronized with Engine.
Definition: Fold.C:136
virtual void reset()
Reset accumulated results to intial values.
Definition: Operation.C:161
uint64_t bytes_storage() const override
The number of bytes of additional storage used by the operation.
Definition: Fold.C:59
Contains all Baseband Data Reduction Library classes.
Definition: ASCIIObservation.h:17
Defines the interface by which Transformations are performed on data.
Definition: Transformation.h:54
virtual void set_time_span(const MJD &start, const MJD &finish)=0
virtual void set_reference_phase(double phase)
Set the reference phase (phase of bin zero)
Definition: Fold.C:405
void set_input(const In *input)
Set the container from which input data will be read.
Definition: Transformation.h:258
void set_ncoef(unsigned ncoef)
double reference_phase
Reference phase (phase of bin zero)
Definition: Fold.h:202
virtual void set_cerr(std::ostream &os) const
Set verbosity ostream.
Definition: Transformation.h:110
void set_nspan(unsigned minutes)
unsigned get_ndim() const
Return the dimension of each datum.
Definition: Observation.h:80
void set_nspan(unsigned nspan)
Set the number of minutes over which polynomial coefficients are valid.
Definition: Fold.C:463
Data as a function of pulse phase.
Definition: PhaseSeries.h:28
virtual void combine(const Operation *)
Combine accumulated results with another operation.
Definition: Operation.C:149
bool psrdisp_compatible
Set true to enable backward compatibility features.
Definition: dsp.C:10
Reference::To< const WeightedTimeSeries > weighted_input
Set when Tranformation::input is a Weighted TimeSeries.
Definition: Fold.h:191
const Extensions * get_extensions() const
Get the Extensions to be communicated to the Archiver class.
Definition: PhaseSeries.C:564
virtual void set_ndat(uint64_t ndat, uint64_t idat_start)
Enable engine to prepare any internal memory required for the plan.
Definition: Fold.h:287
unsigned * get_hits(unsigned ichan=0)
Get the hits array for the specified ichan.
Definition: PhaseSeries.C:219
double get_pfold(const MJD &start_time)
Called by fold to return pfold.
Definition: Fold.C:957
float * get_datptr(unsigned ichan=0, unsigned ipol=0)
Return pointer to the specified data block.
Definition: TimeSeries.C:304
bool has_folding_predictor() const
Returns true if data will be folded using Pulsar::Predictor.
Definition: Fold.C:449
uint64_t get_ndat_fold()
Used by the MultiFold class.
Definition: Fold.h:179
virtual void synch(PhaseSeries *)=0
Synchronize the folded profile.
static Generator * factory(const Parameters *)
uint64_t ndat_total
Total number of time samples passed to folding routine.
Definition: PhaseSeries.h:190
void set_pulsar_ephemeris(const Pulsar::Parameters *)
Set the pulsar ephemeris used to fold.
Definition: PhaseSeries.C:168
virtual void fold(uint64_t nweights, const unsigned *weights, unsigned ndatperweight, unsigned weight_idat)
Fold nblock blocks of data.
Definition: Fold.C:641
Fold TimeSeries data into phase-averaged profile(s)
Definition: Fold.h:34
void combine(const Operation *)
If Operation is a Fold, integrate its PhaseSeries.
Definition: Fold.C:119
bool has_pulsar_ephemeris() const
use to see whether pulsar eph is stored
Definition: Fold.h:128
double get_phi(const MJD &start_time)
Called by new_fold() to return phi.
Definition: Fold.C:948
virtual void finish()
Perform any final operations.
Definition: Fold.C:163
virtual Fold * clone() const
Create a clonse.
Definition: Fold.C:96
virtual void zero()=0
Zero out internal data.
virtual void set_dispersion_measure(double dm)
Set the pulsar dispersion mesure.
Definition: Observation.h:202
MJD reference_epoch
Reference epoch that defines phase = 0 when folding_period > 0.
Definition: Fold.h:205
unsigned get_npol() const
Return the number of polarizations.
Definition: Observation.h:90
virtual void set_site(const std::string &)=0
virtual void transformation()
The transformation folds the data into the profile.
Definition: Fold.C:525
Interface to alternate processing engine (e.g. GPU)
Definition: Fold.h:252
Defines the interface by which operations are performed on data.
Definition: Operation.h:37
void set_folding_period(double folding_period)
Set the period at which to fold data for all sources.
Definition: Fold.C:413
Container of weighted time-major order floating point data.
Definition: WeightedTimeSeries.h:26
Stores information about digital, band-limited, time-varying signals.
Definition: Observation.h:33
std::string get_telescope() const
Return the telescope name.
Definition: Observation.h:112
unsigned get_ncoef() const
Get the number of polynomial coefficients in model.
Definition: Fold.h:92
~Fold()
Destructor.
Definition: Fold.C:92
void set_pulsar_ephemeris(const Pulsar::Parameters *)
Set the ephemeris with which to create a new phase model.
Definition: Fold.C:472
unsigned requested_nbin
Number of phase bins set using set_nbin.
Definition: Fold.h:197
Arrays of consecutive samples for each polarization and frequency channel.
Definition: TimeSeries.h:29
double get_calfreq() const
get the calibrator frequency
Definition: Observation.h:222
double get_bandwidth() const
Return the bandwidth of signal in MHz (-ve = lsb; +ve = usb)
Definition: Observation.h:147
void set_idat_start(uint64_t _idat_start)
Used by the MultiFold class.
Definition: Fold.h:173
uint64_t ndat_fold
INTERNAL: the number of time samples to fold.
Definition: Fold.h:223
virtual uint64_t get_ndat_folded() const =0
Return the number of time samples folded.
virtual PhaseSeries * get_profiles()=0
Return the PhaseSeries into which data will be folded.
void reset()
Reset the PhaseSeries.
Definition: Fold.C:150
virtual void set_cerr(std::ostream &os) const
Set output cerr stream.
Definition: Fold.C:51
virtual void set_nbin(unsigned nbin)=0
Set the number of phase bins and initialize any other data structures.
unsigned get_nbin() const
Get the number of phase bins into which data will be folded.
Definition: Fold.h:84
std::string get_source() const
Return the source name.
Definition: Observation.h:122
void set_ndat_fold(uint64_t _ndat_fold)
Used by the MultiFold class.
Definition: Fold.h:177
unsigned choose_nbin(bool quiet=false) const
Return an appropriate number of pulse phase bins.
Definition: Fold.C:304
Stores parameters that should be changed.
Definition: ObservationChange.h:21
virtual void fold()=0
Perform the fold operation.
double folding_period
Period at which to fold data.
Definition: Fold.h:188
double get_centre_frequency() const
Return the centre frequency of the band-limited signal in MHz.
Definition: Observation.h:134
virtual void set_parameters(const Parameters *)=0
void set_folding_period(double _folding_period)
Set the period at which to fold data (in seconds)
Definition: PhaseSeries.C:138
uint64_t get_nfloat_span() const
Get the span (number of floats)
Definition: TimeSeries.C:344
void setup()
Set the above attributes.
Definition: Fold.C:978
const Type * ptr() const
Signal::Source get_type() const
Return the source type.
Definition: Observation.h:75
Fold()
Constructor.
Definition: Fold.C:21
virtual void prepare_output()
Prepare output PhaseSeries parameters.
Definition: Fold.C:510
virtual void set_frequency_span(long double low, long double high)=0
static bool power_of_two
Controls the number of phase bins returned by Fold::choose_nbin.
Definition: Fold.h:47
unsigned ncoef
Number of polynomial coefficients in model.
Definition: Fold.h:208
void set_reference_phase(double phase)
Set the reference phase (phase of bin zero)
Definition: PhaseSeries.h:61
void set_folding_predictor(const Pulsar::Predictor *)
Set the phase model with which to fold data.
Definition: Fold.C:437
void set_input(const TimeSeries *input)
Overload Transformation::set_input to set weighted_input.
Definition: Fold.C:486
void set_folding_predictor(const Pulsar::Predictor *)
Set the phase predictor with which the data were folded.
Definition: PhaseSeries.C:173
bool has_extensions() const
Return true if Extensions have been set.
Definition: PhaseSeries.C:574
void set_change(const ObservationChange *)
Set the attributes to be changed in the output PhaseSeries.
Definition: Fold.C:421
unsigned get_hits_nchan()
Get the number of channels in the hits array.
Definition: PhaseSeries.h:115
static double minimum_bin_width
The minimum width of each pulse phase bin; used by Fold::choose_nbin.
Definition: Fold.h:44
static unsigned maximum_nbin
The maximum number of phase bins returned by Fold::choose_nbin.
Definition: Fold.h:41
virtual Predictor * generate() const=0
double integration_length
The number of seconds integrated into the profile(s)
Definition: PhaseSeries.h:196
const Pulsar::Parameters * get_pulsar_ephemeris() const
Get the ephemeris used to create the phase model.
Definition: Fold.C:481
virtual void set_rate(double _rate)
Set the sampling rate (time samples per second in Hz)
Definition: Observation.h:155
double get_reference_phase() const
Get the reference phase (phase of bin zero)
Definition: PhaseSeries.h:63
unsigned nspan
Number of minutes over which polynomial coefficients are valid.
Definition: Fold.h:211
void set_ncoef(unsigned ncoef)
Set the number of polynomial coefficients in model.
Definition: Fold.C:454
bool has_folding_period() const
Returns true if data will be folded at a constant period.
Definition: Fold.h:113
MJD get_start_time() const
Return the start time of the leading edge of the first time sample.
Definition: Observation.h:152
bool built
Flag that the predictor is built for the given ephemeris and input.
Definition: Fold.h:217
bool get_zeroed_data() const
Get the zeroed data flag.
Definition: TimeSeries.h:162
const Pulsar::Predictor * get_folding_predictor() const
Get the phase model which is currently being used to fold data.
Definition: Fold.C:444
float * get_dattfp()
Return pointer to the specified data block.
Definition: TimeSeries.C:325
Reference::To< const TimeSeries > input
Container from which input data will be read.
Definition: HasInput.h:49
Reference::To< Engine > engine
Interface to alternate processing engine (e.g. GPU)
Definition: Fold.h:232
unsigned get_nspan() const
Get the number of minutes over which polynomial coefficients are valid.
Definition: Fold.h:97
@ OrderFPT
Frequency, Polarization, Time (default before 3 October 2008)
Definition: TimeSeries.h:47
unsigned folding_nbin
Number of phase bins into which the data will be integrated.
Definition: Fold.h:194
Order get_order() const
Get the order.
Definition: TimeSeries.C:92
unsigned get_nbin() const
Get the number of phase bins.
Definition: PhaseSeries.h:99
virtual void check_input()
Check that the input state is appropriate for folding.
Definition: Fold.C:499
unsigned get_nchan() const
Return the number of channels into which the band is divided.
Definition: Observation.h:85

Generated using doxygen 1.8.17