FITSDigitizer.h
1 //-*-C++-*-
2 /***************************************************************************
3  *
4  * Copyright (C) 2015 by Matthew Kerr
5  * Licensed under the Academic Free License version 2.1
6  *
7  ***************************************************************************/
8 
9 // Recall that PSRFITS search mode data are in TPF order, which complicates
10 // packing into bytes.
11 
12 #ifndef __FITSDigitizer_h
13 #define __FITSDigitizer_h
14 
15 #include "dsp/Digitizer.h"
16 
17 namespace dsp
18 {
20  class FITSDigitizer: public Digitizer
21  {
22  public:
23 
25  FITSDigitizer (unsigned _nbit);
26 
28  ~FITSDigitizer ();
29 
30  unsigned get_nbit () const {return nbit;}
31 
34  void set_rescale_samples (unsigned nsamp);
35 
38  void set_rescale_nblock (unsigned nsamp);
39 
41  void set_rescale_constant (bool rconst);
42 
44  void set_upper_sideband_output (bool usb) { upper_sideband_output = usb; };
45 
46  //virtual void transformation ();
47 
49  void pack ();
50 
52  // TODO -- is this needed?
53  uint64_t get_minimum_samples () { return 2048; }
54 
55  void get_scales (std::vector<float>* dat_scl, std::vector<float>* dat_offs);
56 
58 
59  class Engine;
60 
61  void set_engine (Engine*);
62 
63  protected:
64 
65  void set_nbit (unsigned);
66 
68  void rescale_pack ();
69 
70  void init ();
71  void measure_scale ();
72 
73  void set_digi_scales();
74 
76  unsigned rescale_nsamp;
77  unsigned rescale_idx;
78  unsigned rescale_nblock;
79  unsigned rescale_counter;
80 
82  bool rescale_constant;
83 
84  float digi_mean,digi_scale;
85  int digi_min,digi_max;
86 
88  double *freq_totalsq, *freq_total, *scale, *offset;
89 
90  Reference::To<Engine> engine;
91 
92  protected:
93 
94  bool upper_sideband_output;
95 
96  };
97 
98  class ChannelSort
99  {
100  const bool flip_band;
101  const bool swap_band;
102  const unsigned nchan;
103  const unsigned half_chan;
104  const dsp::Observation* input;
105 
106  public:
107 
108  ChannelSort (const dsp::Observation* input, bool upper_sideband) :
109  flip_band ((upper_sideband && input->get_bandwidth() < 0) ||
110  (!upper_sideband && input->get_bandwidth() > 0)),
111  swap_band ( input->get_swap() ),
112  nchan ( input->get_nchan() ),
113  half_chan ( nchan / 2 ),
114  input ( input ) { }
115 
117  inline unsigned operator () (unsigned out_chan)
118  {
119  unsigned in_chan = out_chan;
120  if (flip_band)
121  in_chan = (nchan-in_chan-1);
122  if (input->get_nsub_swap() > 1)
123  in_chan = input->get_unswapped_ichan(out_chan);
124  else if (swap_band)
125  in_chan = (in_chan+half_chan)%nchan;
126  return in_chan;
127  }
128  };
129 
130  class FITSDigitizer::Engine : public OwnStream
131  {
132  public:
133 
134  virtual void set_scratch (dsp::Scratch *) = 0;
135 
136  virtual void set_rescale_nblock (const dsp::TimeSeries * in,
137  unsigned rescale_nblock) = 0;
138 
139  virtual void set_mapping (const dsp::TimeSeries * in,
140  dsp::ChannelSort& channel) = 0;
141 
142  virtual void measure_scale (const dsp::TimeSeries * in,
143  unsigned rescale_nsamp) = 0;
144 
145  virtual void digitize (const dsp::TimeSeries * in,
146  dsp::BitSeries * out, uint64_t ndat, unsigned nbit,
147  float digi_mean, float digi_scale,
148  int digi_min, int digi_max) = 0;
149 
150  virtual void get_scale_offsets (double * scale, double * offset,
151  unsigned nchan, unsigned npol) = 0;
152 
153  };
154 
155 }
156 
157 #endif
void set_upper_sideband_output(bool usb)
Set the channel ordering of the output.
Definition: FITSDigitizer.h:54
void set_rescale_nblock(unsigned nsamp)
Set the number of blocks to remember when computing scales.
Definition: FITSDigitizer.C:110
Contains all Baseband Data Reduction Library classes.
Definition: ASCIIObservation.h:17
void set_rescale_samples(unsigned nsamp)
Set the number of samples to rescale before digitization.
Definition: FITSDigitizer.C:102
void set_rescale_constant(bool rconst)
If true, leave scales/offsets constant after first measurement.
Definition: FITSDigitizer.C:121
void rescale_pack()
rescale input based on mean / variance
Definition: FITSDigitizer.C:489
FITSDigitizer(unsigned _nbit)
Default constructor.
Definition: FITSDigitizer.C:49
Convert floating point samples to N-bit samples.
Definition: Digitizer.h:27
const ScalarMath sqrt(const ScalarMath &x)
Scratch space that can be shared between Operations.
Definition: Scratch.h:27
virtual void set_scratch(Scratch *)
Set the scratch space.
Definition: Operation.C:137
Buffers the Transformation input.
Definition: InputBuffering.h:26
Stores information about digital, band-limited, time-varying signals.
Definition: Observation.h:33
bool rescale_constant
Keep scaling/offset constant after first estimate.
Definition: FITSDigitizer.h:92
unsigned rescale_nsamp
keep track of first time through scale-measuring procedure
Definition: FITSDigitizer.h:86
Arrays of consecutive samples for each polarization and frequency channel.
Definition: TimeSeries.h:29
void pack()
Pack the data.
Definition: FITSDigitizer.C:322
double * freq_totalsq
arrays for accumulating and storing scales
Definition: FITSDigitizer.h:98
A container for storing digitized (generally not floating point) data
Definition: BitSeries.h:35
void set_nbit(unsigned)
Set the number of bits per sample.
Definition: FITSDigitizer.C:84
uint64_t get_minimum_samples()
Return minimum samples.
Definition: FITSDigitizer.h:63
~FITSDigitizer()
Default destructor.
Definition: FITSDigitizer.C:68
@ OrderFPT
Frequency, Polarization, Time (default before 3 October 2008)
Definition: TimeSeries.h:47
@ OrderTFP
Time, Frequency, Polarization (better for many things)
Definition: TimeSeries.h:50

Generated using doxygen 1.8.17