Observation.h
1 //-*-C++-*-
2 /***************************************************************************
3  *
4  * Copyright (C) 2002 - 2023 by Willem van Straten
5  * Licensed under the Academic Free License version 2.1
6  *
7  ***************************************************************************/
8 
9 #ifndef __Observation_h
10 #define __Observation_h
11 
12 #include "environ.h"
13 #include "dsp/dsp.h"
14 
15 #include "OwnStream.h"
16 #include "sky_coord.h"
17 #include "Types.h"
18 #include "MJD.h"
19 #include "Rational.h"
20 #include "dsp/FIRFilter.h"
21 
22 #include <vector>
23 
24 // forward declaration of text interface
25 namespace TextInterface
26 {
27  class Parser;
28 };
29 
30 namespace dsp
31 {
33  class Observation : public OwnStream
34  {
35 
36  public:
37 
39  static bool verbose;
40 
42  Observation ();
43 
45  Observation (const Observation&);
46 
48  Observation (const Observation*);
49 
51  const Observation& operator = (const Observation&);
52 
54  virtual ~Observation();
55 
57  virtual void copy (const Observation* obs) { operator=( *obs ); }
58 
60  virtual Observation* clone() const;
61 
63  virtual void set_basis (Signal::Basis _basis) { basis = _basis; }
65  Signal::Basis get_basis () const { return basis; }
66 
68  virtual void set_state (Signal::State _state);
70  Signal::State get_state () const { return state; }
71 
73  virtual void set_type (Signal::Source _type) { type = _type; }
75  Signal::Source get_type () const { return type; }
76 
78  virtual void set_ndim (unsigned _ndim) { ndim = _ndim; }
80  unsigned get_ndim () const { return ndim; }
81 
83  virtual void set_nchan (unsigned _nchan) { nchan = _nchan; }
85  unsigned get_nchan () const { return nchan; }
86 
88  virtual void set_npol (unsigned _npol) { npol = _npol; }
90  unsigned get_npol () const { return npol; }
91 
93  virtual void set_nbit (unsigned _nbit) { nbit = _nbit; }
95  unsigned get_nbit () const { return nbit; }
96 
98  uint64_t bits_per_sample () const;
99 
101 
105  virtual void set_ndat (uint64_t _ndat) { ndat = _ndat; }
107  uint64_t get_ndat () const { return ndat; }
108 
110  virtual void set_telescope (const std::string& name) { telescope = name; }
112  std::string get_telescope () const { return telescope; }
113 
115  virtual void set_receiver (const std::string& name) { receiver = name; }
117  std::string get_receiver () const { return receiver; }
118 
120  virtual void set_source (const std::string& name) { source = name; }
122  std::string get_source () const { return source; }
123 
125  virtual void set_coordinates (sky_coord _coordinates)
126  { coordinates=_coordinates; }
129  { return coordinates; }
130 
132  virtual void set_centre_frequency (double cf) { centre_frequency = cf; }
134  double get_centre_frequency () const{ return centre_frequency; }
135 
137  double get_centre_frequency (unsigned ichan) const;
139  double get_base_frequency () const;
140 
142  unsigned get_unswapped_ichan (unsigned ichan) const;
143 
145  virtual void set_bandwidth (double _bandwidth) { bandwidth = _bandwidth; }
147  double get_bandwidth () const { return bandwidth; }
148 
150  virtual void set_start_time (MJD _start_time) { start_time = _start_time; }
152  MJD get_start_time () const { return start_time; }
153 
155  virtual void set_rate (double _rate) { rate = _rate; }
157  double get_rate () const { return rate; }
158 
160  virtual void set_scale (double _scale) { scale = _scale; }
162  double get_scale () const { return scale; }
163 
165  virtual void set_swap (bool _swap) { swap = _swap; }
167  bool get_swap () const { return swap; }
168 
170  virtual void set_nsub_swap (unsigned _nsub) { nsub_swap = _nsub; }
172  unsigned get_nsub_swap () const { return nsub_swap; }
173 
175 
177  virtual void set_dual_sideband (int _dual);
179  int get_dual_sideband () const;
180 
182 
183  virtual void set_dc_centred (bool _centred) { dc_centred = _centred; }
184  bool get_dc_centred () const { return dc_centred; }
185 
187  virtual void set_identifier (const std::string& _id) { identifier = _id; }
189  std::string get_identifier () const { return identifier; }
190 
192  virtual void set_machine (const std::string& _m) { machine = _m; }
194  std::string get_machine () const { return machine; }
195 
197  virtual void set_format (const std::string& _f) { format = _f; }
199  std::string get_format () const { return format; }
200 
202  virtual void set_dispersion_measure (double dm)
203  { dispersion_measure = dm; }
205  double get_dispersion_measure () const { return dispersion_measure; }
206 
208  virtual void set_rotation_measure (double rm)
209  { rotation_measure = rm; }
211  double get_rotation_measure () const
212  { return rotation_measure; }
213 
215  virtual void set_mode (const std::string& _mode) { mode = _mode; }
217  std::string get_mode () const { return mode; }
218 
220  virtual void set_calfreq (double _calfreq) {calfreq = _calfreq;}
222  double get_calfreq() const {return calfreq;}
223 
225  virtual void set_oversampling_factor (const Rational& _osf)
226  { oversampling_factor = _osf; }
227 
230  { return oversampling_factor; }
231 
232  virtual void set_deripple (const std::vector<dsp::FIRFilter>& _deripple)
233  { deripple = _deripple; }
234 
235  const std::vector<dsp::FIRFilter>& get_deripple () const { return deripple; }
236 
237  // get the number of derippling stages,
238  // or the number of upsteam layers of channelization
239  unsigned get_deripple_stages () const { return deripple.size(); }
240 
242  virtual void set_pfb_dc_chan (const bool _pfb_dc_chan) { pfb_dc_chan = _pfb_dc_chan; }
243 
244  bool get_pfb_dc_chan () const { return pfb_dc_chan; }
245 
247  virtual void set_pfb_nchan (unsigned nchan) { pfb_nchan = nchan; }
248  unsigned get_pfb_nchan () const { return pfb_nchan; }
249 
251  virtual void change_state (Signal::State new_state);
252 
254  bool state_is_valid (std::string& reason) const;
255 
257  bool get_detected () const;
258 
260  void change_start_time (int64_t _ndat);
261 
263  // Returns correct answer if ndat=rate=0 and avoids division by zero
264  virtual MJD get_end_time () const;
265 
267  uint64_t get_idat (const MJD& mjd);
268 
270  void rescale (double factor) { scale *= factor; }
271 
273  virtual uint64_t get_nbytes (uint64_t nsamples) const;
274 
276  uint64_t get_nbytes () const
277  { return get_nbytes (get_ndat()); }
278 
279  uint64_t verbose_nbytes (uint64_t nsamples) const;
280 
282  float get_nbyte () const;
283 
285  virtual uint64_t get_nsamples (uint64_t nbytes) const;
286 
288  void copy_dimensions (const Observation*);
289 
291  bool combinable (const Observation& obs) const;
292 
294  std::string get_reason () { return reason; }
295 
297  bool contiguous (const Observation& next) const;
298 
300  void init ();
301 
303  class NbyteNsamplePolicy;
304 
306  void set_nbyte_nsample_policy (NbyteNsamplePolicy*);
307 
309  const NbyteNsamplePolicy* get_nbyte_nsample_policy () const;
310 
312  class Interface;
313 
316 
317  protected:
318 
320  std::string telescope;
321 
323  std::string receiver;
324 
326  std::string source;
327 
329  double centre_frequency = 0.0;
330 
332  double bandwidth = 0.0;
333 
336 
339 
342 
344  double rate = 0.0;
345 
348 
350  std::string identifier;
351 
353  std::string mode;
354 
356  std::string machine;
357 
359  std::string format;
360 
363 
365  double dispersion_measure = 0.0;
366 
368  double rotation_measure = 0.0;
369 
372 
374  bool require_equal_rates = true;
375 
377  double scale = 1.0;
378 
380  bool swap = false;
381 
383  unsigned nsub_swap = 0;
384 
386  bool dc_centred = false;
387 
390 
392  std::vector<FIRFilter> deripple;
393 
395  bool pfb_dc_chan = true;
396 
398 
404  unsigned pfb_nchan = 0;
405 
406  private:
407 
409  //
410  // Private variables should be accessed only using set/get at all times!
411  //
412 
414 
417  uint64_t ndat = 0;
418 
420 
423  unsigned ndim = 1;
424 
426  unsigned nchan = 1;
427 
429  unsigned npol = 1;
430 
432  unsigned nbit = 0;
433 
435  double calfreq = 0.0;
436 
438 
442  int dual_sideband = 0;
443 
444  bool dual_sideband_set = false;
445 
447  mutable std::string reason;
448 
450  Reference::To<NbyteNsamplePolicy> nbyte_nsample_policy;
451  };
452 
453  class Observation::NbyteNsamplePolicy : public Reference::Able
454  {
455  public:
456 
457  Observation* obs = nullptr;
458 
460  virtual NbyteNsamplePolicy* clone () const;
461 
463  virtual uint64_t get_nbytes (uint64_t nsamples) const;
464 
466  virtual uint64_t get_nsamples (uint64_t nbytes) const;
467 
469  uint64_t bits_per_sample () const;
470  };
471 
472 }
473 
474 #ifdef ACTIVATE_MPI
475 
476 #include <mpi.h>
477 
479 int mpiPack_size (const dsp::Observation&, MPI_Comm comm, int* size);
480 
482 int mpiPack (const dsp::Observation&,
483  void* outbuf, int outcount, int* position, MPI_Comm comm);
484 
486 int mpiUnpack (void* inbuf, int insize, int* position,
487  dsp::Observation*, MPI_Comm comm);
488 
489 #endif
490 
491 #endif // ! __Observation_h
double get_scale() const
Return the amount by which data has been scaled.
Definition: Observation.h:162
Rational oversampling_factor
oversampling factor
Definition: Observation.h:389
virtual void set_ndat(uint64_t _ndat)
Set the number of time samples in container.
Definition: Observation.h:105
virtual void set_nbit(unsigned _nbit)
Set the number of bits per value.
Definition: Observation.h:93
virtual void set_bandwidth(double _bandwidth)
Set the bandwidth of signal in MHz (-ve = lsb; +ve = usb)
Definition: Observation.h:145
bool dc_centred
Flag set when centre channel is centred on centre frequency.
Definition: Observation.h:386
double centre_frequency
Centre frequency of band-limited signal in MHz.
Definition: Observation.h:329
const Observation & operator=(const Observation &)
Assignment operator.
Definition: Observation.C:404
std::string get_mode() const
Return the observation mode.
Definition: Observation.h:217
virtual uint64_t get_nsamples(uint64_t nbytes) const
Return the number of samples in nbytes bytes.
Definition: Observation.C:548
void set_nbyte_nsample_policy(NbyteNsamplePolicy *)
Set the policy that defines the bijection between number of bytes and number of samples.
Definition: Observation.C:73
virtual MJD get_end_time() const
Return the end time of the trailing edge of the last time sample.
Definition: Observation.C:521
Observation()
Null constructor.
Definition: Observation.C:26
bool swap
Flag set when frequency channels are out of order (band swappped)
Definition: Observation.h:380
virtual void set_rotation_measure(double rm)
Set the pulsar rotation mesure.
Definition: Observation.h:208
double scale
Amount by which data has been scaled.
Definition: Observation.h:377
Contains all Baseband Data Reduction Library classes.
Definition: ASCIIObservation.h:17
static bool verbose
Verbosity flag.
Definition: Observation.h:39
uint64_t get_nbytes() const
Return the size in bytes of ndat time samples.
Definition: Observation.h:276
unsigned get_ndim() const
Return the dimension of each datum.
Definition: Observation.h:80
double get_base_frequency() const
Returns the centre frequency of the reference channel in MHz.
Definition: Observation.C:490
double get_rotation_measure() const
Returns the pulsar rotation measure.
Definition: Observation.h:211
bool require_equal_sources
Require equal sources in combinable.
Definition: Observation.h:371
virtual void set_type(Signal::Source _type)
Set the source type.
Definition: Observation.h:73
int get_dual_sideband() const
Return the dual-sideband.
Definition: Observation.C:93
Signal::State get_state() const
Return the state of the signal.
Definition: Observation.h:70
sky_coord coordinates
Coordinates of the source.
Definition: Observation.h:362
unsigned get_nbit() const
Return the number of bits per value.
Definition: Observation.h:95
std::string get_format() const
Return the format used to record signal.
Definition: Observation.h:199
sky_coord get_coordinates() const
Return the coordinates of the source.
Definition: Observation.h:128
virtual void set_nsub_swap(unsigned _nsub)
Set the number of sub-bands that must be band swapped.
Definition: Observation.h:170
unsigned nsub_swap
The number of sub-bands that must be band swapped.
Definition: Observation.h:383
bool state_is_valid(std::string &reason) const
Return true if the state of the Observation is valid.
Definition: Observation.C:139
virtual void copy(const Observation *obs)
Same as operator= but takes a pointer.
Definition: Observation.h:57
virtual void change_state(Signal::State new_state)
Change the state and correct other attributes accordingly.
Definition: Observation.C:499
virtual void set_receiver(const std::string &name)
Set the receiver name.
Definition: Observation.h:115
std::string format
Data format used to record signal.
Definition: Observation.h:359
virtual void set_machine(const std::string &_m)
Set the instrument used to record signal.
Definition: Observation.h:192
virtual TextInterface::Parser * get_interface()
Return a text interface that can be used to access this instance.
Definition: Observation.C:528
virtual void set_mode(const std::string &_mode)
Set the observation mode.
Definition: Observation.h:215
virtual void set_dc_centred(bool _centred)
Set true if centre channel is centred on centre frequency.
Definition: Observation.h:183
std::string receiver
Receiver name.
Definition: Observation.h:323
double get_dispersion_measure() const
Returns the pulsar dispersion measure.
Definition: Observation.h:205
double get_rate() const
Return the sampling rate (time samples per second in Hz)
Definition: Observation.h:157
uint64_t get_ndat() const
Return the number of time samples in container.
Definition: Observation.h:107
double rotation_measure
The rotation measure to be archived.
Definition: Observation.h:368
double bandwidth
Bandwidth of signal in MHz (-ve = lsb; +ve = usb)
Definition: Observation.h:332
void init()
Set all attributes to null default.
Definition: Observation.C:31
Represents a rational number.
Definition: Rational.h:15
virtual void set_dual_sideband(int _dual)
Set to 1 if the spectrum in each channel has dual-sideband frequency order.
Definition: Observation.C:85
virtual void set_dispersion_measure(double dm)
Set the pulsar dispersion mesure.
Definition: Observation.h:202
std::string mode
Observation mode.
Definition: Observation.h:353
const NbyteNsamplePolicy * get_nbyte_nsample_policy() const
Get the policy that defines the bijection between number of bytes and number of samples.
Definition: Observation.C:456
virtual void set_identifier(const std::string &_id)
Set the observation identifier.
Definition: Observation.h:187
virtual void set_telescope(const std::string &name)
Set the telescope name.
Definition: Observation.h:110
unsigned get_npol() const
Return the number of polarizations.
Definition: Observation.h:90
unsigned get_nsub_swap() const
Return the number of sub-bands that must be band swapped.
Definition: Observation.h:172
virtual void set_oversampling_factor(const Rational &_osf)
Set the oversampling factor.
Definition: Observation.h:225
virtual void set_npol(unsigned _npol)
Set the number of polarizations.
Definition: Observation.h:88
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
virtual Observation * clone() const
Cloner (calls new)
Definition: Observation.C:388
virtual void set_source(const std::string &name)
Set the source name.
Definition: Observation.h:120
double dispersion_measure
The dispersion measure to be archived.
Definition: Observation.h:365
virtual ~Observation()
Virtual destructor (see Effective C++ Item 14)
Definition: Observation.C:372
const Rational & get_oversampling_factor() const
Get the oversampling factor.
Definition: Observation.h:229
Signal::Basis basis
Type of receiver feeds (Linear or Circular)
Definition: Observation.h:341
std::string identifier
Observation identifier.
Definition: Observation.h:350
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 rescale(double factor)
Multiply scale by factor.
Definition: Observation.h:270
std::string source
Source name. If a pulsar, should be J2000.
Definition: Observation.h:326
virtual void set_basis(Signal::Basis _basis)
Set the type of receiver feeds.
Definition: Observation.h:63
Signal::Basis get_basis() const
Return the type of receiver feeds.
Definition: Observation.h:65
uint64_t get_idat(const MJD &mjd)
Return the nearest time sample corresponding to the specified MJD.
Definition: Observation.C:573
Provides a text interface to get and set Observation attributes.
Definition: ObservationInterface.h:26
virtual void set_calfreq(double _calfreq)
Set the calibrator frequency.
Definition: Observation.h:220
float get_nbyte() const
Return the size in bytes of one time sample.
Definition: Observation.C:534
virtual void set_pfb_nchan(unsigned nchan)
set/get the number of channels output by the PFB per input channel
Definition: Observation.h:247
bool combinable(const Observation &obs) const
Returns true if the signal may be integrated.
Definition: Observation.C:152
virtual void set_start_time(MJD _start_time)
Set the start time of the leading edge of the first time sample.
Definition: Observation.h:150
Signal::State state
State of the signal (Full Stokes, Total Intensity, etc.)
Definition: Observation.h:338
bool get_detected() const
Returns true if state is Detected, Coherence, or Stokes.
Definition: Observation.C:144
std::string get_source() const
Return the source name.
Definition: Observation.h:122
bool require_equal_rates
Require equal rates in combinable.
Definition: Observation.h:374
std::string machine
Instrument used to record signal.
Definition: Observation.h:356
std::string get_identifier() const
Return the observation identifier.
Definition: Observation.h:189
virtual void set_ndim(unsigned _ndim)
Set the dimension of each datum.
Definition: Observation.h:78
virtual void set_pfb_dc_chan(const bool _pfb_dc_chan)
set/get the DC PFB channel flag (for inverse filterbank)
Definition: Observation.h:242
bool valid_state(State state, unsigned ndim, unsigned npol, std::string &reason)
virtual void set_nchan(unsigned _nchan)
Set the number of channels into which the band is divided.
Definition: Observation.h:83
double get_centre_frequency() const
Return the centre frequency of the band-limited signal in MHz.
Definition: Observation.h:134
MJD start_time
Start time of the leading edge of the first time sample.
Definition: Observation.h:347
virtual void set_scale(double _scale)
Set the amount by which data has been scaled.
Definition: Observation.h:160
virtual void set_format(const std::string &_f)
Set the format used to record signal.
Definition: Observation.h:197
std::string telescope
Telescope name.
Definition: Observation.h:320
std::string get_reason()
Returns the reason if combinable returns false.
Definition: Observation.h:294
unsigned get_unswapped_ichan(unsigned ichan) const
Returns the unswapped channel index of the specified channel.
Definition: Observation.C:464
Signal::Source get_type() const
Return the source type.
Definition: Observation.h:75
virtual void set_swap(bool _swap)
Set true if frequency channels are out of order (band swappped)
Definition: Observation.h:165
virtual void set_centre_frequency(double cf)
Set the centre frequency of the band-limited signal in MHz.
Definition: Observation.h:132
uint64_t bits_per_sample() const
Return the number of bits in a single time sample (over all channels, pols, and dimensions)
Definition: Observation.C:79
void copy_dimensions(const Observation *)
Copy the dimensions of another observation.
Definition: Observation.C:394
std::string get_receiver() const
Return the receiver name.
Definition: Observation.h:117
Signal::Source type
Type of signal source (Pulsar, CAL, etc.)
Definition: Observation.h:335
virtual void set_coordinates(sky_coord _coordinates)
Set the coordinates of the source.
Definition: Observation.h:125
std::vector< FIRFilter > deripple
information about deripple correction
Definition: Observation.h:392
virtual void set_rate(double _rate)
Set the sampling rate (time samples per second in Hz)
Definition: Observation.h:155
bool pfb_dc_chan
Do we have the DC, or zeroth PFB channel?
Definition: Observation.h:395
MJD get_start_time() const
Return the start time of the leading edge of the first time sample.
Definition: Observation.h:152
void change_start_time(int64_t _ndat)
Change the start time by the number of time samples specified.
Definition: Observation.C:514
bool get_swap() const
Return true if frequency channels are out of order (band swappped)
Definition: Observation.h:167
bool contiguous(const Observation &next) const
Return true if the first sample of next follows the last sample of this.
Definition: Observation.C:336
double rate
Time samples per second in Hz.
Definition: Observation.h:344
std::string get_machine() const
Return the instrument used to record signal.
Definition: Observation.h:194
virtual void set_state(Signal::State _state)
Set the state of the signal.
Definition: Observation.C:103
unsigned get_nchan() const
Return the number of channels into which the band is divided.
Definition: Observation.h:85
unsigned pfb_nchan
Number of channels output by PFB for a single input time series.
Definition: Observation.h:404

Generated using doxygen 1.8.17