Profile.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 // psrchive/Base/Classes/Pulsar/Profile.h
10 
11 #ifndef __Pulsar_Profile_h
12 #define __Pulsar_Profile_h
13 
14 #include "Pulsar/ProfileAmps.h"
15 #include "Pulsar/Config.h"
16 
17 #include "Types.h"
18 #include "Functor.h"
19 #include "Estimate.h"
20 
21 namespace Pulsar {
22 
23  class PhaseWeight;
24  class ProfileWeightFunction;
25  class SNRatioEstimator;
26 
28 
40  class Profile : public ProfileAmps {
41 
42  public:
43 
45  friend class Integration;
46 
48  static bool verbose;
49 
52 
55 
58 
60  Profile (unsigned nbin = 0);
61 
63  Profile (const Profile& profile);
64 
66  Profile (const Profile* profile);
67 
69  ~Profile ();
70 
72  static unsigned get_instance_count ();
73 
75  virtual Profile* clone () const;
76 
78  virtual void resize (unsigned nbin);
79 
81  const Profile& operator = (const Profile& profile);
82 
84  void copy (const Profile*, bool clone_strategy = true);
85 
87  void average (const Profile* that);
88 
90  void sum (const Profile* profile);
91 
93  void diff (const Profile* profile);
94 
96  const Profile& operator += (float offset);
97 
99  const Profile& operator -= (float offset);
100 
102  const Profile& operator *= (float scale);
103 
105  void scale (double scale);
106 
108  void offset (double offset);
109 
111  void rotate_phase (double phase);
112 
114  void derivative ();
115 
117  void zero ();
118 
120  void square_root ();
121 
123  void absolute ();
124 
126  void logarithm (double base = 10.0, double threshold = 0.0);
127 
129  float max (int bin_start=0, int bin_end=0) const;
131  float min (int bin_start=0, int bin_end=0) const;
132 
134  double sum (int bin_start=0, int bin_end=0) const;
136  double sumsq (int bin_start=0, int bin_end=0) const;
138  double sumfabs (int bin_start=0, int bin_end=0) const;
139 
141  void stats (double* mean, double* variance = 0, double* varmean = 0,
142  int bin_start=0, int bin_end=0) const;
143 
145  void stats (float phase,
146  double* mean, double* variance = 0, double* varmean = 0,
147  float duty_cycle = default_duty_cycle) const;
148 
150  double mean (float phase, float duty_cycle = default_duty_cycle) const;
151 
153  float find_max_phase (float duty_cycle = default_duty_cycle) const;
155  float find_min_phase (float duty_cycle = default_duty_cycle) const;
156 
158  void find_transitions (int& highlow, int& lowhigh, int& width) const;
159 
161  int find_max_bin (int bin_start=0, int bin_end=0) const;
163  int find_min_bin (int bin_start=0, int bin_end=0) const;
164 
165  typedef Functor< std::pair<int,int> (const Profile*) > Edges;
168 
170  void find_peak_edges (int& rise, int& fall) const;
171 
172  class Strategies;
173 
175  Strategies* get_strategy() const;
176 
178  void set_strategy (Strategies*);
179 
181  PhaseWeight* baseline () const;
182 
184  float snr () const;
185 
187  void dedisperse (double dm, double ref_freq, double pfold);
188 
190  Estimate<double> shift (const Profile& std) const;
191 
194  std::vector<float> get_weighted_amps () const;
195 
197  double get_centre_frequency () const { return centrefreq; }
199  virtual void set_centre_frequency (double cfreq) { centrefreq = cfreq; }
200 
202  float get_weight () const { return fabs(weight); }
204  virtual void set_weight (float);
205 
207  void fft_convolve (const Profile* profile);
208 
210  void convolve (const Profile* profile);
211 
213  void correlate (const Profile* profile);
214 
216  void correlate_normalized (const Profile* profile);
217 
219  void pscrunch ();
220 
222  void bscrunch (unsigned nscrunch);
223 
225  void bscrunch_to_nbin (unsigned nbin);
226 
228  void fold (unsigned nfold);
229 
230  // //////////////////////////////////////////////////////////////////
231  //
232  // Extension access
233  //
234  // //////////////////////////////////////////////////////////////////
235 
242 
244  class Extension;
245 
247  virtual unsigned get_nextension () const;
248 
250  virtual const Extension* get_extension (unsigned iextension) const;
251 
253  virtual Extension* get_extension (unsigned iextension);
254 
256  template<class ExtensionType>
257  const ExtensionType* get () const;
258 
260  template<class ExtensionType>
261  ExtensionType* get ();
262 
264 
266  virtual void add_extension (Extension* extension);
267 
268  protected:
269 
270  friend class PolnProfile;
271  friend class StandardSNR;
272 
274  void convolve (const Profile* profile, int direction);
275 
277  void init ();
278 
280  double centrefreq;
281 
283  float weight;
284 
286  mutable std::vector< Reference::To<Extension> > extension;
287 
290  };
291 
292 }
293 
294 
295 
296 
297 #endif // !defined __Pulsar_Profile_h
void bscrunch(Container *, const ScrunchFactor &)
Integrate phase bins.
Definition: ScrunchFactor.h:116
void average(const Profile *that)
set this to the weighted average of this and that
Definition: Profile_average.C:52
~Profile()
destructor
Definition: Profile.C:113
void pscrunch()
some extensions may have to respond to pscrunch
Definition: Profile.C:463
void bscrunch_to_nbin(unsigned nbin)
integrate neighbouring phase bins in profile
Definition: Profile.C:549
void correlate_normalized(const Profile *profile)
cross-correlates and normalizes this with the given profile in time domain
Definition: Profile_convolve.C:24
void phase(Profile *input)
Compute the phase of the input complex-valued Profile.
Definition: Fourier.C:135
static bool no_amps
When true, no memory is allocated for amps.
Definition: ProfileAmps.h:38
std::vector< Reference::To< Extension > > extension
The Extensions added to this Profile instance.
Definition: Profile.h:291
double mean(float phase, float duty_cycle=default_duty_cycle) const
Convenience interface to stats, returns only the mean.
Definition: Profile_stats.C:121
virtual void resize(unsigned nbin)=0
Resize the data area.
virtual void offset(double offset)=0
offsets each bin of the profile by offset
virtual void bscrunch(unsigned nscrunch)=0
integrate neighbouring phase bins in profile
void offset(double offset)
offsets each bin of the profile by offset
Definition: Profile.C:301
void diff(const Profile *profile)
subtract profile from this
Definition: Profile.C:341
float min(int bin_start=0, int bin_end=0) const
Returns the minimum amplitude.
Definition: Profile.C:665
const float * get_amps() const
Return a pointer to the amplitudes array.
Definition: ProfileAmps.C:141
double get_centre_frequency() const
get the centre frequency (in MHz)
Definition: Profile.h:202
void frc1d(size_t nfft, float *into, const float *from)
float get_weight() const
get the weight of the profile
Definition: Profile.h:207
Manages the strategies that implement algorithms.
Definition: ProfileStrategies.h:26
virtual void set_centre_frequency(double cfreq)
set the centre frequency (in MHz)
Definition: Profile.h:204
Estimate< double > shift(const Profile &std) const
Returns the shift (in turns) between profile and standard.
Definition: Profile_shift.C:20
virtual void pscrunch()
some extensions may have to respond to pscrunching
Definition: DataExtension.h:67
int find_min_bin(int bin_start=0, int bin_end=0) const
Returns the bin number with the minimum amplitude.
Definition: Profile.C:636
void bcr1d(size_t nfft, float *into, const float *from)
virtual ~Extension()
Destructor.
Definition: Profile.C:209
Stores a weight for each Profile phase bin.
Definition: PhaseWeight.h:29
float find_min_phase(float duty_cycle=default_duty_cycle) const
Returns the phase of the centre of the region with minimum mean.
Definition: Profile_find_minmax_phase.C:21
float snr() const
Returns the signal to noise ratio of the profile.
Definition: Profile_snr.C:15
void convolve(const Profile *profile)
convolves this with the given profile in time domain
Definition: Profile_convolve.C:14
Definition: ProfileExtension.h:28
const Profile & operator-=(float offset)
subtracts offset from each bin of the profile
Definition: Profile.C:285
Any quantity recorded as a function of pulse phase.
Definition: Profile.h:45
virtual void set_weight(float wt)=0
set the weight of the profile
double sumsq(int bin_start=0, int bin_end=0) const
Returns the sum of all amplitudes squared.
Definition: Profile.C:722
float weight
weight of profile
Definition: Profile.h:288
static Option< Edges > peak_edges_strategy
The default implementation of the edge detection algorithm.
Definition: Profile.h:172
const Profile & operator=(const Profile &profile)
assignment operator
Definition: Profile.C:148
unsigned get_nbin() const
Return the number of bins.
Definition: ProfileAmps.h:50
void scale(double scale)
multiplies each bin of the profile by scale
Definition: Profile.C:311
static bool verbose
flag controls the amount output to stderr by Profile methods
Definition: Profile.h:53
void set_strategy(Strategies *)
Set the strategy manager.
Definition: Profile.C:192
Profile(unsigned nbin=0)
Default constructor.
Definition: Profile.C:84
void derivative()
compute the derivative of profile with respect to index
Definition: Profile_derivative.C:20
const Profile & operator*=(float scale)
multiplies each bin of the profile by scale
Definition: Profile.C:295
void rotate_phase(double phase)
rotates the profile by phase (in turns)
Definition: Profile_rotate.C:35
virtual Profile * clone() const
returns a pointer to a new copy of self
Definition: Profile.C:124
void fft_convolve(const Profile *profile)
convolves this with the given profile (using fft method)
Definition: Profile_convolve.C:65
float find_max_phase(float duty_cycle=default_duty_cycle) const
Returns the phase of the centre of the region with maximum mean.
Definition: Profile_find_minmax_phase.C:43
Array of Profiles integrated over the same time interval.
Definition: Integration.h:37
static Option< bool > rotate_in_phase_domain
When true, Profile::rotate shifts bins in the phase domain.
Definition: Profile.h:56
void find_transitions(int &highlow, int &lowhigh, int &width) const
Find the bin numbers at which the mean power transits.
Definition: Profile_find_transitions.C:45
virtual void fold(unsigned nfold)=0
integrate neighbouring sections of the profile
virtual void zero()=0
set all amplitudes to zero
float max(int bin_start=0, int bin_end=0) const
Returns the maximum amplitude.
Definition: Profile.C:651
void correlate(const Profile *profile)
cross-correlates this with the given profile in time domain
Definition: Profile_convolve.C:19
void dedisperse(double dm, double ref_freq, double pfold)
Rotates the profile to remove dispersion delay.
Definition: Profile_dedisperse.C:24
Polarimetric pulse profile transformations and derivations.
Definition: PolnProfile.h:34
std::string get_extension_name() const
Return the name of the Extension.
Definition: Profile.C:212
void copy(const Profile *, bool clone_strategy=true)
does the work for copy constructor and assignment operator
Definition: Profile.C:154
virtual void resize(unsigned nbin)
Resize the data area.
Definition: ProfileAmps.C:104
void fold(unsigned nfold)
integrate neighbouring sections of the profile
Definition: Profile.C:472
virtual unsigned get_nextension() const
Return the number of extensions available.
Definition: Profile.C:198
static unsigned get_instance_count()
returns the number of Profile instances
Definition: Profile.C:64
void init()
initializes all values to null
Definition: Profile.C:73
void bscrunch(unsigned nscrunch)
integrate neighbouring phase bins in profile
Definition: Profile.C:505
void absolute()
calculare the absolute value of each phase bin
Definition: Profile.C:399
virtual void add_extension(Extension *extension)
Add an Extension to this instance.
Definition: Profile.C:253
static Option< float > default_duty_cycle
fractional phase window used in most functions
Definition: Profile.h:62
void zero()
set all amplitudes to zero
Definition: Profile.C:365
std::vector< float > get_weighted_amps() const
Definition: Profile.C:346
Provides protected access to the Profile amplitudes array.
Definition: ProfileAmps.h:28
double sumfabs(int bin_start=0, int bin_end=0) const
Returns the sum of the absolute value.
Definition: Profile.C:701
void stats(double *mean, double *variance=0, double *varmean=0, int bin_start=0, int bin_end=0) const
Calculates the mean, variance, and variance of the mean.
Definition: Profile_stats.C:27
const Profile & operator+=(float offset)
adds offset to each bin of the profile
Definition: Profile.C:275
PhaseWeight * baseline() const
Return a new PhaseWeight instance with the baseline phase bins masked.
Definition: Profile_baseline.C:15
Reference::To< Strategies > strategy
The strategy manager.
Definition: Profile.h:294
Defines the PSRCHIVE library.
Definition: CalSource.h:17
void logarithm(double base=10.0, double threshold=0.0)
calculate the logarithm of each bin with value greater than threshold
Definition: Profile.C:413
const ExtensionType * get() const
Template method searches for an Extension of the specified type.
virtual Extension * clone() const =0
Return a new copy-constructed instance identical to this instance.
virtual void scale(double scale)=0
multiplies each bin of the profile by scale
Strategies * get_strategy() const
Returns the strategy manager.
Definition: StrategySet.C:122
double centrefreq
centre frequency of profile (in MHz)
Definition: Profile.h:285
virtual void set_weight(float)
set the weight of the profile
Definition: Profile.C:185
Extension(const char *name)
Construct with a name.
Definition: Profile.C:204
virtual void bscrunch_to_nbin(unsigned nbin)=0
integrate neighbouring phase bins in profile
Calculates the signal-to-noise ratio by fitting against a standard.
Definition: StandardSNR.h:27
static Option< float > transition_duty_cycle
fractional phase window used to find rise and fall of running mean
Definition: Profile.h:59
void find_peak_edges(int &rise, int &fall) const
Find the bin numbers at which the cumulative power crosses thresholds.
Definition: Profile_find_peak_edges.C:34
void square_root()
calculate the signed sqrt of the absolute value of each bin
Definition: Profile.C:381
virtual void resize(unsigned nbin)
resize the data area
Definition: Profile.C:134
virtual const Extension * get_extension(unsigned iextension) const
Return a pointer to the specified extension.
Definition: Profile.C:225
int find_max_bin(int bin_start=0, int bin_end=0) const
Returns the bin number with the maximum amplitude.
Definition: Profile.C:622
void sum(const Profile *profile)
add profile to this
Definition: Profile.C:336
normalization get_norm()
virtual std::string get_short_name() const
Return an abbreviated name that can be typed relatively quickly.
Definition: Profile.C:217

Generated using doxygen 1.8.17