RadioAstronomySoftwareGroup / pyuvdata

A pythonic interface for radio astronomy interferometry data (uvfits, miriad, others)
https://pyuvdata.readthedocs.io/en/latest/index.html
BSD 2-Clause "Simplified" License
82 stars 27 forks source link

Coordinate of antenna position in UVFITS? #1486

Open fxzjshm opened 1 month ago

fxzjshm commented 1 month ago

I'm converting some visibility from custom format to UVFITS/MeasurementSets and importing it to CASA. When using UVFITS as intermediate format (write_uvfits) and importing it using CASA task importuvfits, antenna positions are not expected:

Station   Offset from array center (m)       
             East         North     Elevation
E01       -0.0000        0.0000        0.0000
E02        1.5671      -26.6355       29.6190
E04        6.9827     -107.0955      118.4858
E05       10.6311     -160.7576      177.7517
E06       17.6700     -280.8892      311.7160
E07       19.0035     -294.5801      326.2694
E08       23.9970     -361.8501      400.0746
E09       24.4710     -375.0060      415.1973
E10       24.8243     -388.0366      430.3301

When using MS (write_ms), results are expected:

Station Offset from array center (m)       
           East         North     Elevation
E01      0.0000        0.0000        0.0000
E02     39.8547       -0.0939        0.8886
E04    159.8423       -0.2025        2.7755
E05    239.8672       -0.2537        4.0060
E06    419.8971       -0.5340        8.2220
E07    439.9214       -0.5419        7.9621
E08    539.9059       -0.5591        8.9570
E09    559.9360       -0.5795        9.8587
E10    579.8818       -0.6064       10.9127

After some investigation I think it is related to https://github.com/RadioAstronomySoftwareGroup/pyuvdata/blob/d6e94366758480a31a062fa84632855701aeb521/pyuvdata/uvdata/uvfits.py#L810-L817

But it seems that in casacore, array XYZ and antenna XYZ are added without rotation (if not VLA): https://github.com/casacore/casacore/blob/bf9e411892b3816724eb11737cc32d12f86a6436/msfits/MSFits/MSFitsInput.cc#L2228

Also found a PR related to "modifications to uvfits AN read/write rules": https://github.com/casacore/casacore/pull/400

So is that rotation required/expected? What's best practice to set antenna locations if I want to convert a custom format into UVFITS?

kartographer commented 1 month ago

Hey @fxzjshm! I'll get an answer to the UVFITS question for you here in just a sec, but an immediate question for you: is there some reason why your outputting to UVFITS and importing that via importuvfits rather than writing out a MeasurementSet (via UVData.write_ms) from the get go? The importuvfits has not always been, in my opinion, the most reliable of utilities, and of course is not something that we can fix directly (if it turns out that there's an underlying issue in it) since it's not part of the pyuvdata package.

fxzjshm commented 1 month ago

I'm new to synthesis imaging and someone told me that MeasurementSet format isn't stable even between minor versions of CASA, so I decided to try UVFITS first..

bhazelton commented 3 weeks ago

Hi @fxzjshm, as Karto mentioned above, the importuvfits utility in CASA is known to have some errors, specifically in that it does not always follow the AIPS memo on the UVFITS file convention. We do follow that memo pretty strictly and the memo is pretty clear on this front. Karto and others have done a bunch of testing on the write_ms functionality and I think sticking to that is the safest approach.

We have done loopback tests using the importuvfits CASA task and have identified several mistakes that the importuvfits task makes, but weirdly this isn't one of the ones we've already identified. Thanks for letting us know about this. We'll try to do some testing on this on our end too and we should add some notes in our documentation about the various issues we've found with importuvfits.