achael / eht-imaging

Imaging, analysis, and simulation software for radio interferometry
https://achael.github.io/eht-imaging/
GNU General Public License v3.0
5.29k stars 496 forks source link

`switch_polrep` gives incorrect results when feeds are missing #169

Closed ptiede closed 4 months ago

ptiede commented 1 year ago

I just found a small but silent bug when using eht-imaging to read in polarized data when feeds are missing. Suppose you are reading in data where the R CP feed is missing. If you read in the data using

obs = ehtim.obsdata.load_uvfits(file, polrep="circ")

then everything is fine, and I see the R products are NaN'd. However, if I read in the data using the method

obs = ehtim.obsdata.load_uvfits(file)
obsc = obs.switch_polrep("circ")

I get that the L products are now NaN'd out.

My guess is that the switch_polrep function doesn't know which components are NaN'd when moving from stokes to circular, so it just defaults to the L feeds. I'm unsure if that is the correct behavior because it can lead to some wild d-terms if you get the polarization hands wrong.

achael commented 1 year ago

Hi @ptiede, there is an option in obs.switch_polrep called 'singlepol_hand', which handles exactly this case - it tells the function which hand (not) to NaN when switching feeds. Currently the default is 'R', leading to this issue.

Let me know if you think we should change the default behavior here. Maybe it should not have a default and require the user to enter something manually if it detects incomplete polarization information? Or should there be some finer-grained control to allow for different polarizations on different telescopes?

achael commented 11 months ago

@ptiede is this still an issue? Let me know!

ptiede commented 11 months ago

I think it is fine to close this. The only potential issue I see is if a cite changes its feed during an observation, which does happen but is rare. The only thing I could think of to improve this would be a clear warning when calling load_uvfits if it detects a missing polarization hand and you are loading the data in the stokes basis.