PolnCalibrator.h
1 //-*-C++-*-
2 /***************************************************************************
3  *
4  * Copyright (C) 2003 - 2022 by Willem van Straten
5  * Licensed under the Academic Free License version 2.1
6  *
7  ***************************************************************************/
8 
9 // psrchive/More/Polarimetry/Pulsar/PolnCalibrator.h
10 
11 #ifndef __Pulsar_PolnCalibrator_H
12 #define __Pulsar_PolnCalibrator_H
13 
14 #include "Pulsar/Calibrator.h"
15 #include "Pulsar/Index.h"
16 
17 #include "MEAL/LeastSquares.h"
18 #include "MEAL/Complex2.h"
19 
20 #include "ReferenceVector.h"
21 #include "Jones.h"
22 
23 namespace Pulsar {
24 
25  class PolnCalibratorExtension;
26  class FeedExtension;
27  class Receiver;
28  class Integration;
29 
31 
36  class PolnCalibrator : public Calibrator
37  {
38 
39  public:
40 
42 
44  static Option<double> minimum_determinant;
45 
47  PolnCalibrator (const Archive* archive = 0);
48 
50  PolnCalibrator (const PolnCalibrator& calibrator);
51 
53  virtual ~PolnCalibrator ();
54 
56  void set_calibrator (const Archive* archive);
57 
59  void set_subint (const Index& isub);
60 
61  // ///////////////////////////////////////////////////////////////////
62  //
63  // useful for calibrating
64  //
65 
67  virtual void set_response_nchan (unsigned nchan);
69  virtual unsigned get_response_nchan () const;
70 
72  virtual Jones<float> get_response (unsigned ichan) const;
73 
75  bool has_Receiver () const;
76 
78  const Receiver* get_Receiver () const;
79 
81  void set_Receiver (const Archive*);
82  std::string get_receiver_basis_filename () const;
83 
84 
85  // ///////////////////////////////////////////////////////////////////
86  //
87  // useful for unloading
88  //
89 
90  void transformation_resize (unsigned nchan);
91 
93  bool get_transformation_valid (unsigned ch) const;
94 
96  void set_transformation_invalid (unsigned ch, const std::string& reason);
97 
99  const std::string& get_transformation_invalid_reason (unsigned ichan) const;
100 
102  const MEAL::Complex2* get_transformation (unsigned ichan) const;
103 
105  MEAL::Complex2* get_transformation (unsigned ichan);
106 
108  void set_transformation (unsigned ichan, MEAL::Complex2*);
109 
111  bool has_covariance () const;
112 
114  void get_covariance (unsigned ichan, std::vector<double>&) const;
115 
117  virtual bool has_solver () const;
118 
120  virtual const MEAL::LeastSquares* get_solver (unsigned ichan) const;
121  MEAL::LeastSquares* get_solver (unsigned ichan);
122 
123  // ///////////////////////////////////////////////////////////////////
124  //
125  // Pulsar::Calibrator implementation
126  //
127  // ///////////////////////////////////////////////////////////////////
128 
130  void set_backend_correction (bool f) { do_backend_correction = f; }
131 
133  virtual void calibrate (Archive* archive);
134 
136  virtual const Type* get_type () const;
137 
139  virtual unsigned get_nchan () const;
140 
142  unsigned get_nchan (bool build_if_needed) const;
143 
145  CalibratorExtension* new_Extension () const;
146 
148  Calibrator::Info* get_Info () const;
149 
151  class Info;
152 
154  void calibration_setup (const Archive* arch);
155 
156  private:
157 
159  Reference::Vector<MEAL::Complex2> transformation;
160 
162  std::vector< std::string> invalid_reason;
163 
164  protected:
165 
167  std::vector< std::vector<double> > covariance;
168 
170  void setup_transformation () const;
171 
173  std::vector< Jones<float> > response;
174 
177 
180 
182  bool built;
183 
185  unsigned observation_nchan;
186 
189 
191  virtual void calculate_transformation ();
192 
194  virtual bool get_valid (unsigned ichan) const;
195 
197  float get_weight (unsigned ichan) const;
198 
200  virtual unsigned get_maximum_nchan () const;
201 
203  Index subint;
204 
205  private:
206 
208  void build (unsigned nchan = 0);
209 
211  mutable Reference::Vector<MEAL::LeastSquares> tmp_solver;
212 
214  std::vector<bool> bad;
215  unsigned bad_count;
216 
217  void build_response();
218  void patch_response();
219 
222  std::string receiver_basis_filename;
223 
225  void init ();
226 
227  };
228 
231  new_transformation (const PolnCalibratorExtension*, unsigned ichan);
232 
235 
237  MEAL::Complex2* transformation_factory (const std::string& name);
238 
240  MEAL::Complex2* load_transformation (const std::string& filename);
241 
244 
245 
246  class PolnCalibrator::Info : public Calibrator::Info
247  {
248 
249  public:
250 
252  static PolnCalibrator::Info* create (const PolnCalibrator* calibrator);
253 
255  Info (const PolnCalibrator* calibrator);
256 
258  std::string get_title () const;
259 
261  unsigned get_nchan () const;
262 
264  unsigned get_nclass () const;
265 
267  std::string get_name (unsigned iclass) const;
268 
270  unsigned get_nparam (unsigned iclass) const;
271 
273  Estimate<float> get_param (unsigned ichan, unsigned iclass,
274  unsigned iparam) const;
275 
277  int get_colour_index (unsigned iclass, unsigned iparam) const;
278 
280  int get_graph_marker (unsigned iclass, unsigned iparam) const;
281 
282  protected:
283 
286 
288  unsigned nparam;
289 
290  };
291 
292 }
293 
294 #endif
295 
Calibrator
Definition: Integration.h:429
virtual unsigned get_nchan() const
Get the number of frequency channels in the calibrator.
Definition: PolnCalibrator.C:237
bool has_covariance() const
Return true if parameter covariances are stored.
Definition: PolnCalibrator.C:354
virtual unsigned get_npol() const =0
Get the number of polarizations.
Index subint
The sub-integration from which to construct a solution.
Definition: PolnCalibrator.h:208
bool do_backend_correction
Perform backend corrections before inverting.
Definition: PolnCalibrator.h:193
virtual void calibrate(Archive *archive)
Calibrate the polarization of the given archive.
Definition: PolnCalibrator.C:874
Combines an index value and integrate flag.
Definition: Index.h:24
bool get_transformation_valid(unsigned ch) const
Return true if the transformation for the specified channel is valid.
Definition: PolnCalibrator.C:258
std::vector< std::vector< double > > covariance
The array of covariance matrix vectors.
Definition: PolnCalibrator.h:172
Stores a known feed transformation.
Definition: FeedExtension.h:29
bool built
Flag set when response has been built.
Definition: PolnCalibrator.h:187
float get_weight() const
get the weight of the profile
Definition: Profile.h:207
virtual unsigned get_nsubint() const =0
Get the number of sub-integrations stored in the file.
virtual const Type * get_type() const
Return the Calibrator::Type of derived class.
Definition: PolnCalibrator.C:971
MEAL::Complex2 * transformation_factory(const std::string &name)
Create a new transformation instance based on the Calibrator::Type name.
Definition: CalibratorType_factory.C:89
void setup_transformation() const
Set up to call calculate_transformation.
Definition: PolnCalibrator.C:419
Any quantity recorded as a function of pulse phase.
Definition: Profile.h:45
The primary interface to pulsar observational data.
Definition: Archive.h:45
Contains information about the receiver and receiver platform.
Definition: Receiver.h:28
unsigned observation_nchan
The number of frequency channels in the observation to be calibrated.
Definition: PolnCalibrator.h:190
const ScalarMath sqrt(const ScalarMath &x)
void set_transformation(unsigned ichan, MEAL::Complex2 *)
Set the transformation for the secified channel.
Definition: PolnCalibrator.C:343
Type * get() const
const ExtensionType * get() const
Template method searches for an Extension of the specified type.
void calibration_setup(const Archive *arch)
Set up done before calibrating an archive.
Definition: PolnCalibrator.C:846
ReferenceFluxDensity
Reference::To< const PolnCalibratorExtension > poln_extension
The PolnCalibratorExtension of the Archive passed during construction.
Definition: PolnCalibrator.h:181
virtual unsigned get_nchan() const =0
Get the number of frequency channels used.
virtual void set_poln_calibrated(bool done=true)=0
Set the value to be returned by get_poln_calibrated.
virtual bool get_valid(unsigned ichan) const
Derived classes can add conditions for channel validity.
Definition: PolnCalibrator.C:837
const MEAL::Complex2 * get_transformation(unsigned ichan) const
Return the transformation for the specified channel.
Definition: PolnCalibrator.C:309
static Option< double > minimum_determinant
Minimum allowable determinant of Jones matrices.
Definition: PolnCalibrator.h:49
virtual unsigned get_maximum_nchan() const
Derived classes may be able to shrink the transformation array.
Definition: PolnCalibrator.C:230
CalibratorExtension * new_Extension() const
Return a new PolnCalibratorExtension.
Definition: PolnCalibrator.C:986
std::vector< Jones< float > > response
The array of Jones matrices derived from the transformation array.
Definition: PolnCalibrator.h:178
float get_weight(unsigned ichan) const
Return the weight (0 or 1) of the specified channel.
Definition: PolnCalibrator.C:831
Integration * get_Integration(unsigned subint)
Return pointer to the specified Integration.
Definition: IntegrationManager.C:41
Array of Profiles integrated over the same time interval.
Definition: Integration.h:37
void set_backend_correction(bool f)
Perform backend corrections before inverting response.
Definition: PolnCalibrator.h:135
Definition: Calibrator.h:152
bool has_Receiver() const
Return true if the Receiver is set.
Definition: PolnCalibrator.C:195
virtual void calculate_transformation()
Derived classes can create and fill the transformation array.
Definition: PolnCalibrator.C:430
virtual Jones< float > get_response(unsigned ichan) const
Return the system response for the specified channel.
Definition: PolnCalibrator.C:181
Stores PolnCalibrator parameters in an Archive instance.
Definition: PolnCalibratorExtension.h:28
A calibration solution that spans a finite bandwidth and time.
Definition: CalibrationInterpolator.h:32
void get_covariance(unsigned ichan, std::vector< double > &) const
Return the covariance matrix vector for the specified channel.
Definition: PolnCalibrator.C:367
unsigned get_nfit() const
Get the number of model parameters varied to find best fit.
Definition: PolnCalibratorExtension.C:351
const Receiver * get_Receiver() const
Return the Receiver.
Definition: PolnCalibrator.C:201
MEAL::Complex2 * load_transformation(const std::string &filename)
Load a new transformation instance from file.
Definition: CalibratorType_factory.C:94
ExtensionType * getadd()
Template method returns an Extension of the specified type.
void set_subint(const Index &isub)
Set the sub-integration index.
Definition: PolnCalibrator.C:146
void set_basis_corrected(bool)
Set true when receptor basis has been corrected.
Definition: Receiver.C:174
Definition: CalibratorType.h:30
unsigned get_nfree() const
Get the number of degrees of freedom.
Definition: PolnCalibratorExtension.C:341
void set_calibrator(const Archive *archive)
Set the calibrator archive used to define basic attributes.
Definition: PolnCalibrator.C:127
MEAL::Complex2 * new_transformation(const PolnCalibratorExtension *, unsigned ichan)
Create a new transformation instance described by the extension.
Definition: PolnCalibratorExt.C:126
Stores Calibrator parameters in an Archive.
Definition: CalibratorExtension.h:27
Polarimetric calibrators.
Definition: PolnCalibrator.h:41
virtual const MEAL::LeastSquares * get_solver(unsigned ichan) const
Return the transformation for the specified channel.
Definition: PolnCalibrator.C:392
double get_chisq() const
Get the best fit value of chi squared.
Definition: PolnCalibratorExtension.C:331
std::string get_filename() const
Get the name of the file to which the archive will be unloaded.
Definition: Archive.h:108
virtual void set_response_nchan(unsigned nchan)
Set the number of frequency channels in the response array.
Definition: PolnCalibrator.C:164
void set_transformation_invalid(unsigned ch, const std::string &reason)
Set the transformation invalid flag for the specified channel.
Definition: PolnCalibrator.C:276
Correct the backend convention.
Definition: BackendCorrection.h:28
virtual unsigned get_response_nchan() const
Get the number of frequency channels in the response array.
Definition: PolnCalibrator.C:173
const std::string & get_transformation_invalid_reason(unsigned ichan) const
Get the reason that the transformation in the specified channel is invalid.
Definition: PolnCalibrator.C:297
Calibrator::Info * get_Info() const
Return plotting information.
Definition: PolnCalibrator.C:994
Calibrator::Type * new_CalibratorType(const MEAL::Complex2 *xform)
Create a new Calibrator::Type instance according to the transformation.
Definition: CalibratorType_factory.C:61
PolnCalibrator(const Archive *archive=0)
Construct with optional processed calibrator Archive.
Definition: PolnCalibrator.C:75
Defines the PSRCHIVE library.
Definition: CalSource.h:17
Stores Polarization Calibration Model Interpolator information.
Definition: CalibrationInterpolatorExtension.h:29
virtual bool has_solver() const
Return true if least squares minimization solvers are available.
Definition: PolnCalibrator.C:375
Reference::To< const FeedExtension > feed
The FeedExtension of the Archive passed during construction.
Definition: PolnCalibrator.h:184
virtual void set_scale(Signal::Scale scale)=0
Set the scale in which flux density is measured.
void set_Receiver(const Archive *)
Set the Receiver extension to that of the input Archive.
Definition: PolnCalibrator.C:105
virtual ~PolnCalibrator()
Destructor.
Definition: PolnCalibrator.C:159
Intermediate storage of MEAL::Complex parameters.
Definition: PolnCalibratorExtension.h:135

Generated using doxygen 1.8.17