Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify AF encoder somewhat #34

Merged
merged 2 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 23 additions & 21 deletions aftimeblockencoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

#include <random>

namespace {
void changeChannelFactor(std::vector<AFTimeBlockEncoder::DBufferRow> &data,
float *metaBuffer, size_t visIndex,
double factor) {
metaBuffer[visIndex] /= factor;
for (AFTimeBlockEncoder::DBufferRow &row : data) row.visibilities[visIndex] *= factor;
}
}

AFTimeBlockEncoder::AFTimeBlockEncoder(size_t nPol, size_t nChannels,
bool fitToMaximum)
: _nPol(nPol),
Expand Down Expand Up @@ -88,13 +97,6 @@ void AFTimeBlockEncoder::changeAntennaFactor(std::vector<DBufferRow> &data,
}
}

void AFTimeBlockEncoder::changeChannelFactor(std::vector<DBufferRow> &data,
float *metaBuffer, size_t visIndex,
double factor) {
metaBuffer[visIndex] /= factor;
for (DBufferRow &row : data) row.visibilities[visIndex] *= factor;
}

//
// There are 3 axes to maximize over; antenna1, antenna2, channel
// We want to maximize all values (average abs value as large as possible)
Expand Down Expand Up @@ -126,20 +128,20 @@ void AFTimeBlockEncoder::fitToMaximum(
// value equals the maximum encodable value
const size_t visPerRow = _nPol * _nChannels;
for (size_t visIndex = 0; visIndex != visPerRow; ++visIndex) {
double largestComp = 0.0;
double largest_component = 0.0;
for (const DBufferRow &row : data) {
if (row.antenna1 != row.antenna2) {
const std::complex<double> *ptr = &row.visibilities[visIndex];
double complMax = std::max(std::max(ptr->real(), ptr->imag()),
double local_max = std::max(std::max(ptr->real(), ptr->imag()),
-std::min(ptr->real(), ptr->imag()));
if (std::isfinite(complMax) && complMax > largestComp)
largestComp = complMax;
if (std::isfinite(local_max) && local_max > largest_component)
largest_component = local_max;
}
}
const double factor =
(gausEncoder.MaxQuantity() == 0.0 || largestComp == 0.0)
(gausEncoder.MaxQuantity() == 0.0 || largest_component == 0.0)
? 1.0
: gausEncoder.MaxQuantity() / largestComp;
: gausEncoder.MaxQuantity() / largest_component;
changeChannelFactor(data, metaBuffer, visIndex, factor);
}

Expand All @@ -151,20 +153,20 @@ void AFTimeBlockEncoder::fitToMaximum(
size_t bestChannel = 0;
for (size_t channel = 0; channel != _nChannels; ++channel) {
// By how much can we increase this channel?
double largestComp = 0.0;
double largest_component = 0.0;
for (const DBufferRow &row : data) {
if (row.antenna1 != row.antenna2) {
const std::complex<double> *ptr =
&row.visibilities[channel * _nPol + polIndex];
double complMax = std::max(std::max(ptr->real(), ptr->imag()),
double local_max = std::max(std::max(ptr->real(), ptr->imag()),
-std::min(ptr->real(), ptr->imag()));
if (std::isfinite(complMax) && complMax > largestComp)
largestComp = complMax;
if (std::isfinite(local_max) && local_max > largest_component)
largest_component = local_max;
}
}
double factor = (largestComp == 0.0)
double factor = (largest_component == 0.0)
? 0.0
: (gausEncoder.MaxQuantity() / largestComp - 1.0);
: (gausEncoder.MaxQuantity() / largest_component - 1.0);
// How much does this increase the total?
double thisIncrease = 0.0;
for (DBufferRow &row : data) {
Expand Down Expand Up @@ -271,7 +273,7 @@ void AFTimeBlockEncoder::encode(
buffer.ConvertVector<std::complex<double>>(data);
const size_t visPerRow = _nPol * _nChannels;

// Normalize the channels
// Normalize the RMS of the channels
std::vector<RMSMeasurement> channelRMSes(_nChannels * _nPol);
for (const DBufferRow &row : data) {
for (size_t i = 0; i != visPerRow; ++i) {
Expand All @@ -289,7 +291,7 @@ void AFTimeBlockEncoder::encode(
}

for (size_t p = 0; p != _nPol; ++p) {
// Normalize the antennae
// Normalize the RMS of the antennae
calculateAntennaeRMS(data, p, antennaCount);
for (DBufferRow &row : data) {
double mul =
Expand Down
2 changes: 0 additions & 2 deletions aftimeblockencoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ class AFTimeBlockEncoder : public TimeBlockEncoder {
void changeAntennaFactor(std::vector<DBufferRow> &data, float *metaBuffer,
size_t antennaIndex, size_t antennaCount,
size_t polIndex, double factor);
void changeChannelFactor(std::vector<DBufferRow> &data, float *metaBuffer,
size_t visIndex, double factor);

void fitToMaximum(std::vector<DBufferRow> &data, float *metaBuffer,
const dyscostman::StochasticEncoder<float> &gausEncoder,
Expand Down
10 changes: 7 additions & 3 deletions threadeddyscocolumn.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,10 @@ void ThreadedDyscoColumn<DataType>::storeBlock() {

template <typename DataType>
void ThreadedDyscoColumn<DataType>::putValues(
casacore::uInt rowNr, const casacore::Array<DataType> *dataPtr) {
casacore::uInt rowNr, const casacore::Array<DataType> *dataArr) {
// Make sure array storage is contiguous.
casacore::Bool deleteIt;
const DataType* dataPtr = dataArr->getStorage (deleteIt);
if (!areOffsetsInitialized()) {
// If the manager did not initialize its offsets yet, then it is determined
// from the first "time block" (a block with the same time, field and spw)
Expand Down Expand Up @@ -207,11 +210,12 @@ void ThreadedDyscoColumn<DataType>::putValues(
// Load new block
loadBlock(blockIndex);
}
_timeBlockBuffer->SetData(blockRow, ant1, ant2, dataPtr->data());
_timeBlockBuffer->SetData(blockRow, ant1, ant2, dataPtr);
} else {
_timeBlockBuffer->SetData(rowNr, ant1, ant2, dataPtr->data());
_timeBlockBuffer->SetData(rowNr, ant1, ant2, dataPtr);
}
_isCurrentBlockChanged = true;
dataArr->freeStorage (dataPtr, deleteIt);
}

template <typename DataType>
Expand Down
2 changes: 1 addition & 1 deletion threadeddyscocolumn.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace dyscostman {
class DyscoStMan;

/**
* A column for storing compressed values in a threaded way, tailered for the
* A column for storing compressed values in a threaded way, tailored for the
* data and weight columns that use a threaded approach for encoding.
* @author André Offringa
*/
Expand Down