UCBerkeleySETI / rawspec

6 stars 7 forks source link

Fix case NPOL = 2 #68

Closed daniestevez closed 2 years ago

daniestevez commented 2 years ago

The case where NPOL = 2 in the GUPPI header (i.e., when the data is single polarization) was not handled correctly. The number of polarizations would be interpreted as 2 when reading the GUPPI header, causing problems later on.

Here we set the number of polarizations to 1 when NPOL = 2. Additionally, we fail if NPOL is not either 2 or 4, since in rawspec_initialized() it is checked that the number of polarizations is either 1 or 2. However, an NPOL = 1 in the header (which is meaningless) would get through and be interpreted as 1 polarization unless we fail in this case.

david-macmahon commented 2 years ago

NPOL=1 is what should be used for single polarization files. NPOL=2 and NPOL=4 both indicate dual-polarization data. The ambiguity from 2 vs 4 is because sometimes people have used NPOL to mean the number of input polarizations (e.g. X and Y) and sometimes people have used NPOL to mean the number of crosspol output products (e.g. XX, YY, re(XY), im(XY) or I,Q,U,V). So basically NPOL == 1 means single polarization and NPOL != 1 means dual polarization.

GUPPI RAW files contain voltage data (i.e. they do not contain cross polarization products), so technically NPOL should be only 1 or 2. NPOL==4 is a somewhat aspirational way of saying NPOL==2 (because the dual-pol voltage data could be used to make 4 cross-ppl output products). Unfortunately, we can't change history so we have to adapt and live in the world that we find ourselves.

daniestevez commented 2 years ago

Thanks for the explanation. The documentation I was reading for the GUPPI format was misleading me. In this page they say "NPOL: Number of polarizations times 2. For example, NPOL=4 means 2 polarizations.", and this paper says "NPOL: Number of samples per time step -- 4 corresponds to dual-polarization complex data". Putting these two together, I had mistakenly assumed that the reason for using NPOL=4 for dual-polarization was because of 2 polarizations times 2 real "samples" (I and Q). And then concluded that NPOL=2 is single-polarization (that's what the first webpage literally says).

This problem showed up when trying to process some GUPPI files that I'm generating with a new tool (a GUPPI file output block for GNU Radio, which I'll release in a few days). I guess that the correct solution would be to change my tool so that it writes NPOL=1 in the header for single-polarization. What do you think I should write for dual-polarization? I get the impression that most people are using NPOL=4 in this case (for instance, BL datasets from Green Bank).

In any case, this pull request can be closed, since the current code implements correctly NPOL as you described it.