casacore
Loading...
Searching...
No Matches
weightblockencoder.h
Go to the documentation of this file.
1#ifndef DYSCO_WEIGHT_BLOCK_ENCODER_H
2#define DYSCO_WEIGHT_BLOCK_ENCODER_H
3
4#include <cmath>
5#include <cstring>
6
7#include "timeblockbuffer.h"
8
10 public:
11 WeightBlockEncoder(size_t nPolarizations, size_t nChannels, size_t quantCount)
12 : _nPolarizations(nPolarizations),
13 _nChannels(nChannels),
14 _quantCount(quantCount) {}
15
16 size_t MetaDataFloatCount() const { return 1.0; }
17
18 size_t SymbolCount(size_t nRowsInBlock) const {
19 return nRowsInBlock * _nChannels;
20 }
21
22 void InitializeDecode(const float *metaBuffer) {
23 _decodeMaxValue = metaBuffer[0];
24 }
25
26 void Decode(TimeBlockBuffer<float> &buffer, const unsigned int *symbolBuffer,
27 size_t blockRow) const {
28 double scaleValue = _decodeMaxValue / (double(_quantCount - 1));
29 TimeBlockBuffer<float>::DataRow &row = buffer[blockRow];
30 const unsigned int *rowBuffer = &symbolBuffer[blockRow * _nChannels];
31 for (size_t ch = 0; ch != _nChannels; ++ch) {
32 float value = *rowBuffer * scaleValue;
34 float *chPtr = &row.visibilities[ch * _nPolarizations];
35 for (size_t p = 0; p != _nPolarizations; ++p) chPtr[p] = value;
36 ++rowBuffer;
37 }
38 }
39
40 void Encode(TimeBlockBuffer<float> &buffer, float *metaBuffer,
41 unsigned int *symbolBuffer) const {
42 float maxValue = 0.0;
43 for (const TimeBlockBuffer<float>::DataRow &row : buffer.GetVector()) {
44 for (size_t ch = 0; ch != _nChannels; ++ch) {
45 const float *visPtr = &row.visibilities[ch * _nPolarizations];
46 float weight = *visPtr;
47 for (size_t p = 1; p != _nPolarizations; ++p)
48 if (visPtr[p] < weight) weight = visPtr[p];
49 if (weight > maxValue) maxValue = weight;
50 }
51 }
52 if (maxValue == 0.0) maxValue = 1.0;
53 metaBuffer[0] = maxValue;
54
55 double scaleValue = double(_quantCount - 1) / maxValue;
56
57 for (const TimeBlockBuffer<float>::DataRow &row : buffer.GetVector()) {
58 for (size_t ch = 0; ch != _nChannels; ++ch) {
59 const float *visPtr = &row.visibilities[ch * _nPolarizations];
60 float weight = *visPtr;
61 for (size_t p = 1; p != _nPolarizations; ++p)
62 if (visPtr[p] < weight) weight = visPtr[p];
63
64 *symbolBuffer = roundf(double(weight) * scaleValue);
65 ++symbolBuffer;
66 }
67 }
68 }
69
70 private:
71 const size_t _nPolarizations;
72 const size_t _nChannels;
73 const size_t _quantCount;
75};
76
77#endif
const std::vector< DataRow > & GetVector() const
void InitializeDecode(const float *metaBuffer)
size_t MetaDataFloatCount() const
void Encode(TimeBlockBuffer< float > &buffer, float *metaBuffer, unsigned int *symbolBuffer) const
void Decode(TimeBlockBuffer< float > &buffer, const unsigned int *symbolBuffer, size_t blockRow) const
WeightBlockEncoder(size_t nPolarizations, size_t nChannels, size_t quantCount)
const size_t _nPolarizations
size_t SymbolCount(size_t nRowsInBlock) const
std::vector< data_t > visibilities