FITSArchive.h
1 //-*-C++-*-
2 /***************************************************************************
3  *
4  * Copyright (C) 2003-2009 by Willem van Straten
5  * Licensed under the Academic Free License version 2.1
6  *
7  ***************************************************************************/
8 
9 // psrchive/Base/Formats/PSRFITS/Pulsar/FITSArchive.h
10 
11 #ifndef __Pulsar_FITSArchive_h
12 #define __Pulsar_FITSArchive_h
13 
14 #include "Pulsar/BasicArchive.h"
15 #include "Pulsar/Agent.h"
16 #include "FITSError.h"
17 
18 #include <fitsio.h>
19 
20 namespace Pulsar
21 {
22  class FITSHdrExtension;
23  class ObsExtension;
24  class WidebandCorrelator;
25  class Receiver;
26  class ITRFExtension;
27  class CalInfoExtension;
28  class ProcHistory;
29  class Passband;
30  class DigitiserStatistics;
31  class PolnCalibratorExtension;
32  class FluxCalibratorExtension;
33  class CalibratorStokes;
34  class CalibrationInterpolatorExtension;
35  class DigitiserCounts;
36  class FITSSUBHdrExtension;
37  class ProfileColumn;
38  class CoherentDedispersion;
39  class SpectralKurtosis;
40  class ObsDescription;
41  class CrossCovarianceMatrix;
42 
43  class Pointing;
44  class AuxColdPlasmaMeasures;
45 
47 
58  class FITSArchive : public BasicArchive {
59 
60  public:
61 
64 
66  FITSArchive (const FITSArchive& archive);
67 
69  ~FITSArchive ();
70 
72  const FITSArchive& operator= (const FITSArchive& archive);
73 
75  FITSArchive (const Archive& archive);
76 
78  void copy (const Archive& archive);
79 
80  // //////////////////////////////////////////////////////////////////
81  //
82  // implement the pure virtual methods of the Archive base class
83  //
84 
86  FITSArchive* clone () const;
87 
88  // //////////////////////////////////////////////////////////////////
89  //
90  // FITSArchive specific interface
91  //
92 
94  void update_history ();
95 
97  static std::string get_template_name ();
98 
100  static void unload (fitsfile*, const FITSHdrExtension*);
101 
103  static void unload (fitsfile*, const ObsExtension*);
104 
106  static void unload (fitsfile*, const Receiver*);
107 
109  static void unload (fitsfile*, const WidebandCorrelator*);
110 
112  static void unload (fitsfile*, const ITRFExtension*);
113 
115  static void unload (fitsfile*, const CalInfoExtension*);
116 
118  static void unload (fitsfile*, const ProcHistory*);
119 
121  static void unload (fitsfile*, const Passband*);
122 
124  static void unload (fitsfile*, const DigitiserStatistics*);
125 
127  static void unload (fitsfile*, const DigitiserCounts*);
128 
130  static void unload (fitsfile*, const PolnCalibratorExtension*);
131 
133  static void unload (fitsfile*, const FluxCalibratorExtension*);
134 
136  static void unload (fitsfile*, const CalibratorStokes*);
137 
139  static void unload (fitsfile*, const CalibrationInterpolatorExtension*);
140 
142  static void unload (fitsfile*, const FITSSUBHdrExtension*);
143 
145  static void unload (fitsfile*, const CoherentDedispersion*);
146 
148  void unload (fitsfile*, const Pointing*, int row) const;
149 
151  static void unload (fitsfile*, const AuxColdPlasmaMeasures*, int row);
152 
154  static void unload (fitsfile*, const ObsDescription*);
155 
157  static void unload (fitsfile*, const CrossCovarianceMatrix*);
158 
160  double get_offs_sub( unsigned int isub ) const;
161 
162  // Correct error due to REF_MJD precision
163  void refmjd_rounding_correction();
164 
166  void set_search_mode() { search_mode = true; };
167 
168  protected:
169 
170  class SKLoader;
171 
172  friend class Archive::Advocate<FITSArchive>;
173 
174  // Advocates the use of the FITSArchive plugin
175  class Agent : public Archive::Advocate<FITSArchive> {
176 
177  public:
178 
180  Agent () {}
181 
183  bool advocate (const char* filename);
184 
186  std::string get_name () { return "PSRFITS"; }
187 
189  std::string get_description ();
190 
191  };
192 
194  virtual void load_header (const char* filename);
195 
197  virtual Integration*
198  load_Integration (const char* filename, unsigned subint);
199 
201  bool can_unload () const { return true; }
202 
204  virtual void unload_file (const char* filename) const;
205 
207  template<typename T>
208  void load_amps (fitsfile*, Integration*, unsigned isubint, int colnum);
209 
210  // //////////////////////////////////////////////////////////////////////
211  //
212  // ADDITIONAL ATTRIBUTES
213  //
214 
216  float psrfits_version;
217 
219  double chanbw;
220 
223 
225  std::string state_scale;
226 
228  std::string state_pol_type;
229 
231  double predicted_phase;
232 
235 
236 
237  // //////////////////////////////////////////////////////////////////////
238 
239  // load the Pulsar::Parameters
240  void load_Parameters (fitsfile*);
241 
242  // unload the Pulsar::Parameters
243  void unload_Parameters (fitsfile*) const;
244 
245  // load the Pulsar::Predictor model
246  void load_Predictor (fitsfile*);
247 
248  // unload the Pulsar::Predictor model
249  void unload_Predictor (fitsfile*) const;
250 
251  // Archive Extensions used by FITSArchive
252 
253  // Extension I/O routines
254  void load_ProcHistory (fitsfile*);
255  void no_ProcHistory (fitsfile*);
256 
257  void load_DigitiserStatistics (fitsfile*);
258  void load_DigitiserCounts(fitsfile*);
259  void load_Passband (fitsfile*);
260  void load_PolnCalibratorExtension (fitsfile*);
261  void load_FluxCalibratorExtension (fitsfile*);
262  void load_CalibratorStokes (fitsfile*);
263  void load_CalibrationInterpolatorExtension (fitsfile*);
264  void load_Receiver (fitsfile*);
265  void load_ITRFExtension (fitsfile*);
266  void load_CalInfoExtension (fitsfile*);
267  void load_WidebandCorrelator (fitsfile*);
268  void load_FITSSUBHdrExtension ( fitsfile * );
269  void load_CoherentDedispersion (fitsfile*);
270  void load_ObsDescription (fitsfile*);
271  void load_CrossCovarianceMatrix (fitsfile*);
272 
273  template<class Ext>
274  void unload (fitsfile*, const char* hdu_name) const;
275 
276  void load_integration_state ( fitsfile * );
277  void load_state ( fitsfile * );
278 
279  void load_Pointing (fitsfile*, int row, Integration*);
280  void load_Plasma (fitsfile*, int row, Integration*);
281  void load_SpectralKurtosis (fitsfile*, int row, Integration*);
282 
283  void interpret_scale ( );
284  void interpret_pol_type ( );
285 
287  static void delete_hdu (fitsfile*, const char* hdu_name);
288 
289  // //////////////////////////////////////////////////////////////////////
290 
291  // Helper function to write an integration to a file
292  void unload_Integration (fitsfile*, int row, const Integration*) const;
293 
295  void unload_integrations (fitsfile*) const;
296 
298  void clean_Pointing_columns (fitsfile*) const;
299 
301  void add_Pointing_columns (fitsfile*) const;
302 
304  void load_Pointing_columns (fitsfile* fptr);
305 
307  int get_last_pointing_column (fitsfile* fptr) const;
308 
310  void unload_sk_integrations (fitsfile*) const;
311 
312  private:
313 
314  // Correct the reference epoch in WBC data taken during commissioning
315  void P236_reference_epoch_correction ();
316 
317  // Correct the reference epoch in WBC data taken during commissioning
318  bool correct_P236_reference_epoch;
319 
320  // The data file contains search mode data, not folded pulse profiles
321  bool search_mode;
322 
323  // Flag set when data are loaded from a PSRFITS file
324  bool loaded_from_fits;
325 
327  mutable unsigned naux_profile;
328 
330  mutable double aux_nsample;
331 
332  // Reference epoch is used during unload_Integration
333  /* This attribute enables proper handling of time stamps when there
334  is no FITSHdrExtension in use (as is the case in psrconv) */
335  mutable MJD reference_epoch;
336 
337  struct pointing_info_column
338  {
339  std::string name;
340  std::string unit;
341  std::string description;
342  int colnum;
343  };
344 
345  mutable std::vector<pointing_info_column> extra_pointing_columns;
346 
347  // Gate duty cycle passed on to all sub-integrations
348  mutable double gate_duty_cycle;
349 
350  // Profile load/unload algorithm
351  mutable Reference::To<ProfileColumn> load_dat_io, unload_dat_io;
352 
353  // Prepare dat_io attribute for use
354  void setup_dat (fitsfile*, Reference::To<ProfileColumn>&) const;
355 
356  // Auxilliary data load/unload algorithm
357  mutable Reference::To<ProfileColumn> load_aux_io, unload_aux_io;
358 
359  // Prepare dat_io attribute for use
360  void setup_aux (fitsfile*, Reference::To<ProfileColumn>&, unsigned) const;
361 
362  // Set all attributes to default values
363  void init ();
364 
365  // Pointer to file used for reading (only)
366  fitsfile* read_fptr;
367 
368  // Name of file used for reading
369  std::string read_filename;
370  };
371 
372  extern template Registry::List<Archive::Agent>::Enter<FITSArchive::Agent>
373  Archive::Advocate<FITSArchive>::entry;
374 
375 }
376 
377 #endif
Calibrator
Definition: Integration.h:429
bool can_unload() const
The unload_file method is implemented.
Definition: FITSArchive.h:206
std::string state_pol_type
String describing polarization state.
Definition: FITSArchive.h:233
void unload_sk_integrations(fitsfile *) const
Unload Spectral Kurtosis Integration data to the SPECKURT HDU.
Definition: unload_SpectralKurtosis.C:16
Loads and unloads PSRFITS archives.
Definition: FITSArchive.h:63
void unload_Integration(fitsfile *, int row, const Integration *) const
A function to write an integration to a row in a FITS file on disk.
Definition: unload_Integration.C:35
Warning warning
Warning messages filter.
Definition: Pulsar.C:12
void load_Pointing(fitsfile *, int row, Integration *)
Definition: load_Pointing.C:46
std::string stt_time
Start UT (hh:mm:ss)
Definition: FITSHdrExtension.h:217
Reference::To< Predictor > hdr_model
The polyco parsed from the PSRFITS file.
Definition: FITSArchive.h:239
std::string creation_date
File creation date.
Definition: FITSHdrExtension.h:202
void set_obsnchan(int set_obsnchan)
Set the observed number of channels.
Definition: FITSHdrExtension.C:137
virtual MJD get_epoch() const =0
Get the epoch of the rising edge of bin zero.
Stores information about the instrument backend.
Definition: Backend.h:26
std::string hdrver
Pulsar FITS header version information.
Definition: FITSHdrExtension.h:197
bool get_downconversion_corrected() const
True if backend has compensated for lower sideband downconversion.
Definition: Backend.C:119
void unload_integrations(fitsfile *) const
Unload Integration data to the SUBINT HDU of the specified FITS file.
Definition: unload_integrations.C:26
const FITSArchive & operator=(const FITSArchive &archive)
Assignment operator.
Definition: FITSArchive.C:129
const Integration * get_Integration(const Archive *data, Index subint)
Return the requested profile, cloning and integrating when needed.
Definition: Index.C:118
bool scale_cross_products
Double cross coherence term.
Definition: FITSArchive.h:227
Instrumental passband (or bandpass)
Definition: Passband.h:25
void clean_Pointing_columns(fitsfile *) const
Delete Pointing-related columns, if not needed.
Definition: clean_Pointing_columns.C:13
double stt_lst
Start LST.
Definition: FITSHdrExtension.h:220
void load_Plasma(fitsfile *, int row, Integration *)
Definition: load_Plasma.C:17
The primary interface to pulsar observational data.
Definition: Archive.h:45
Contains information about the receiver and receiver platform.
Definition: Receiver.h:28
virtual void load_header(const char *filename)
Load the FITS header information from filename.
Definition: FITSArchive.C:195
double get_delay() const
Get the delay.
Definition: Backend.h:93
Stores Parkes Wideband Correlator parameters.
Definition: WidebandCorrelator.h:27
Stores the Stokes parameters of the reference source.
Definition: CalibratorStokes.h:28
Stores PSRFITS header extensions.
Definition: FITSHdrExtension.h:25
std::string pnt_id
Name or ID for pointing ctr (multibeam feeds)
Definition: FITSHdrExtension.h:168
double get_offs_sub(unsigned int isub) const
Get the offs_sub value (only present in fits files)
Definition: FITSArchive.C:1218
Stores pulsar parameters as uninterpreted text.
Definition: ObsDescription.h:24
Record of phase-coherent dispersion removal algorithm.
Definition: CoherentDedispersion.h:27
International Terrestrial Reference Frame Extension.
Definition: ITRFExtension.h:27
virtual double get_duration() const =0
Get the total time integrated (in seconds)
std::string state_scale
String describing scale.
Definition: FITSArchive.h:230
std::string get_name() const
Return the name of the Backend.
Definition: Backend.C:83
void add_Pointing_columns(fitsfile *) const
Add additional Pointing::Info columns, if needed.
Definition: add_Pointing_columns.C:30
Spectral Kurtosis Staticstics calculated during observation.
Definition: SpectralKurtosis.h:25
FITSArchive * clone() const
Return a pointer to a new copy constructed instance equal to this.
Definition: FITSArchive.C:182
Array of Profiles integrated over the same time interval.
Definition: Integration.h:37
void load_state(fitsfile *)
Definition: load_integration_state.C:284
std::string project_ID
Project ID.
Definition: ObsExtension.h:84
Stores PSRFITS SUBINT header parameters.
Definition: FITSSUBHdrExtension.h:28
std::string ibeam
Beam number for multibeam systems (1=ctr beam)
Definition: FITSHdrExtension.h:163
double chanbw
Channel bandwidth.
Definition: FITSArchive.h:224
void load_DigitiserCounts(fitsfile *)
FITSArchive::load_DigitiserCounts Creates a DigitiserCounts extension and loads it from the fits file...
Definition: load_DigitiserCounts.C:139
Stores PolnCalibrator parameters in an Archive instance.
Definition: PolnCalibratorExtension.h:28
Stores digitizer histograms.
Definition: DigitiserCounts.h:25
Contains information about the telescope used for the observation.
Definition: Telescope.h:26
std::string stt_date
Start UT date (YYYY-MM-DD)
Definition: FITSHdrExtension.h:214
void load_SpectralKurtosis(fitsfile *, int row, Integration *)
Definition: load_SpectralKurtosis.C:18
Observation Information Extension.
Definition: ObsExtension.h:29
Stores digitizer statistics.
Definition: DigitiserStatistics.h:25
void set_bmaj(const double _bmaj)
Set the beam major axis length.
Definition: FITSHdrExtension.h:97
std::string observer
Observer name.
Definition: ObsExtension.h:78
void copy(const Archive &archive)
Copy all of the class attributes and the selected Integration data.
Definition: FITSArchive.C:152
virtual Integration * load_Integration(const char *filename, unsigned subint)
Load the specified Integration from filename, returning new instance.
Definition: load_Integration.C:37
double predicted_phase
Extra polyco information stored in POLYCO HDU.
Definition: FITSArchive.h:236
std::string get_extension_name() const
Return the name of the Extension.
Definition: Archive.C:145
Flux Calibrator Extension.
Definition: FluxCalibratorExtension.h:28
std::string trk_mode
Track mode (TRACK, SCANGC, SCANLAT)
Definition: FITSHdrExtension.h:211
void set_obsfreq(double set_obsfreq)
Set the observed frequency.
Definition: FITSHdrExtension.C:117
static std::string get_runtime()
Return the name of the runtime directory.
Definition: Config.C:120
void set_search_mode()
Indicate the FITSArchive contains search mode data.
Definition: FITSArchive.h:171
static void delete_hdu(fitsfile *, const char *hdu_name)
Delete the HDU with the specified name.
Definition: delete_hdu.C:19
void update_history()
Add a new row to the history, reflecting the current state.
Definition: update_history.C:64
const std::string get_message() const
Defines the PSRCHIVE library.
Definition: CalSource.h:17
Stores Polarization Calibration Model Interpolator information.
Definition: CalibrationInterpolatorExtension.h:29
std::string coordmode
Coordinate mode (EQUAT, GAL, ECLIP, AZEL, HADEC)
Definition: FITSHdrExtension.h:205
Stores parameters used to correct auxiliary dispersion and birefringence.
Definition: AuxColdPlasmaMeasures.h:24
MJD get_start_time() const
Get the start time.
Definition: FITSHdrExtension.h:125
float psrfits_version
The PSRFITS version.
Definition: FITSArchive.h:221
double equinox
Equinox of coordinates.
Definition: FITSHdrExtension.h:208
void load_Pointing_columns(fitsfile *fptr)
Load additional Pointing::Info column information, if any.
Definition: load_Pointing_columns.C:14
static void unload(fitsfile *, const FITSHdrExtension *)
Unload FITSHdrExtension to the current HDU of the specified FITS file.
Definition: unload_FITSHdrExtension.C:18
~FITSArchive()
Destructor.
Definition: FITSArchive.C:109
Signal::Argument get_argument() const
Get the argument of the backend.
Definition: Backend.C:107
static std::string get_template_name()
Return the name of the PSRFITS definition template file.
Definition: FITSArchive.C:800
void load_amps(fitsfile *, Integration *, unsigned isubint, int colnum)
Load data of any type.
int get_last_pointing_column(fitsfile *fptr) const
Get the column past which to write/read additional Pointing::Info.
Definition: add_Pointing_columns.C:14
Stores information about the reference source (ATNF)
Definition: CalInfoExtension.h:28
void set_bpa(const double _bpa)
Set the beam position angle.
Definition: FITSHdrExtension.h:92
FITSArchive()
Default constructor.
Definition: FITSArchive.C:84
void set_bmin(const double _bmin)
Set the beam minor axis length.
Definition: FITSHdrExtension.h:102
const ExtensionType * get() const
Template method searches for an Extension of the specified type.
Telescope pointing parameters recorded during the observation.
Definition: Pointing.h:27
void set_obsbw(double set_obsbw)
Set the observed bandwidth.
Definition: FITSHdrExtension.C:127
virtual void unload_file(const char *filename) const
Unload the FITSArchive (header and Integration data) to filename.
Definition: FITSArchive.C:825

Generated using doxygen 1.8.17