Skip to content

Renewed attempt to add the InterferometricVisibility frame - #10737

Closed
Joshuaalbert wants to merge 1 commit into
astropy:mainfrom
Joshuaalbert:master
Closed

Joshuaalbert wants to merge 1 commit into
astropy:mainfrom
Joshuaalbert:master

Conversation

@Joshuaalbert

@Joshuaalbert Joshuaalbert commented Sep 16, 2020 •

Copy link
Copy Markdown

This PR reopens #9869 and is a solution for issue #7766.

Individuals that should follow and give input: @caseyjlaw, @eteq, @mhvk, @tikk3r

I think given the prior PR we can largely break this PR into the following tasks:

  • Derive the exact solution
  • Investigate setting up the frame using astropy.coordinates.SkyOffset
  • If possible, set up the frame using astropy.coordinates.SkyOffset or else find other solution
  • Set up CALC11 server to do testing
  • Investigate setting up CALC11 server as part of continuous integration unittesting

The exact solution

In order to compute the coordinates in this frame we follow the approach of computing the proper time for a given
geodesic (which forms the w coordinate) and then computing the u and v coordinates from the directional derivatives of
proper time w.r.t the l and m coordinates.

w = c * proper_time
u = dw/dl
v = dw/dm

Note: In order to perform VLBI-precise calcuations we must take into account the velocity of the local reference frame of each
geodesic origin.

Computing the coordinates can be expensive, which is why VLBI folks compute them over a temporal abscissa of about 120 seconds and do spline interpolation between. I think we should provide the exact coordinates, and let the user choose if they want to use spline interpolation.

@pep8speaks

Copy link
Copy Markdown

Hello @Joshuaalbert 👋! Thanks for opening this pull request, we are very grateful for your contribution! I'm a friendly 🤖 that checks for style issues in this pull request, since this project follows the PEP8 style guidelines. I've listed some small issues I found below, but please don't hesitate to ask if any of them are unclear!

Line 22:5: W292 no newline at end of file

@pllim pllim added this to the v4.2 milestone Sep 16, 2020
@pllim
pllim requested review from adrn, eteq and mhvk September 16, 2020 13:39
@pllim
pllim marked this pull request as draft September 16, 2020 20:16
@pllim

pllim commented Sep 16, 2020

Copy link
Copy Markdown
Member

Hello. I converted your PR to a draft PR due to #10706 .

@mhvk

mhvk commented Sep 16, 2020

Copy link
Copy Markdown
Contributor

Thanks very much - the description of the tasks looks good. Agreed also to start with just getting as-exact-as-possible solutions, even if they are expensive, and worry about interpolation later (though I can resist noting that we just merged a PR that allows it for the current transforms - #10646; even though that focuses on erfa routines, I think the infrastructure would be useful here too).

@caseyjlaw

Copy link
Copy Markdown

I'd also encourage consideration of an approximate solution that is appropriate for connected interferometers. Computational intensity is one concern. It would be good to know if the SkyOffset approach will allow a fast, vectorized calculation in time (use case: calculate uvw for 8 hours of data with 1 second samples).

@Joshuaalbert

Copy link
Copy Markdown
Author

I'm going to look at the SkyOffset code to get acquainted with it.

@Joshuaalbert

Copy link
Copy Markdown
Author

Ok after looking at SkyOffset we may not use it for the exact solution. From SkyOffset docs:

    Coordinates in this frame are both centered on the position specified by the
    ``origin`` coordinate, *and* they are oriented in the same manner as the
    ``origin`` frame.  E.g., if ``origin`` is `~astropy.coordinates.ICRS`, this
    object's ``lat`` will be pointed in the direction of Dec, while ``lon``
    will point in the direction of RA.

This won't work for two antennas in different reference frames.

@mhvk

mhvk commented Sep 18, 2020

Copy link
Copy Markdown
Contributor

@Joshuaalbert - have you checked the rotation argument to the initializer? Also, if it is close, I think it would be fine to adapt or subclass SkyOffsetFrame. The question may be the extent to which actual transformations are similar to what we need:

@frame_transform_graph.transform(DynamicMatrixTransform, framecls, _SkyOffsetFramecls)
def reference_to_skyoffset(reference_frame, skyoffset_frame):
"""Convert a reference coordinate to an sky offset frame."""
# Define rotation matrices along the position angle vector, and
# relative to the origin.
origin = skyoffset_frame.origin.spherical
mat1 = rotation_matrix(-skyoffset_frame.rotation, 'x')
mat2 = rotation_matrix(-origin.lat, 'y')
mat3 = rotation_matrix(origin.lon, 'z')
return matrix_product(mat1, mat2, mat3)

@mhvk

mhvk commented Sep 18, 2020

Copy link
Copy Markdown
Contributor

p.s. Just to be sure: I think a conclusion from the previous discussion was that the SkyOffsetFrame idea was quite similar to what's needed for InterferometricVisibility, in things being based around a particular pointing direction. If it is not obvious and easy, it would seem totally fine to start with a set of classes that work and verify they reproduce calc, before worrying too much about whether SkyOffsetFrame is directly usable itself.

@Joshuaalbert

Copy link
Copy Markdown
Author

Hey @mhvk I mean due to relativistic effects the notion of a pointing offset is incorrect in the exact formulation suitable for VLBI. In the exact solution the UVW coordinates are a function of both the antenna position and the direction of the radio source. The w coordinate is the speed of like times the group delay,
Screenshot from 2020-09-19 01-36-07

and u and v are the partial derivatives with respect to the first two components of s in a Cartesian system.

@Joshuaalbert

Copy link
Copy Markdown
Author

p.s. that's not exact still because it's lacking some terms, but is still very accurate. The full group delay is in section 11.4.1 of https://www.iers.org/SharedDocs/Publikationen/EN/IERS/Publications/tn/TechnNote36/tn36.pdf

@mhvk

mhvk commented Sep 18, 2020

Copy link
Copy Markdown
Contributor

Ah, thanks! (I fear you had in fact told me this before...) So, it sounds like, if anything, SkyOffsetFrame would be a special case. The idea of SkyOffsetFrame to set oneself up with a meta-class might still be a good one, though.

@Joshuaalbert

Joshuaalbert commented Sep 19, 2020 •

Copy link
Copy Markdown
Author

To get an idea of the importance of the relativistic kinematic (non gravitational) corrections here I show the difference in delay between including and not including them:

Baseline=1.00 km, max diff=0.33ns, mean diff=0.17ns
Baseline=2.78 km, max diff=0.93ns, mean diff=0.47ns
Baseline=7.74 km, max diff=2.58ns, mean diff=1.30ns
Baseline=21.54 km, max diff=7.18ns, mean diff=3.62ns
Baseline=59.95 km, max diff=19.99ns, mean diff=10.07ns
Baseline=166.81 km, max diff=55.63ns, mean diff=28.02ns
Baseline=464.16 km, max diff=154.80ns, mean diff=77.96ns
Baseline=1291.55 km, max diff=430.73ns, mean diff=216.93ns
Baseline=3593.81 km, max diff=1198.52ns, mean diff=603.62ns
Baseline=10000.00 km, max diff=3334.96ns, mean diff=1679.61ns

@Joshuaalbert

Copy link
Copy Markdown
Author

What we can do is provide an option that computes all components with delays above a certain threshold. E.g. Most telescopes will get away with 0.1ns precision.

@pllim

pllim commented Oct 22, 2020

Copy link
Copy Markdown
Member

Hello, given the draft status of this PR and the impending feature freeze tomorrow, I am moving the milestone. Thank you for your understanding.

@pllim pllim modified the milestones: v4.2, v4.3 Oct 22, 2020
@Jan-Willem

Copy link
Copy Markdown

I have created a python package that wraps CALC11 (https://github.com/casangi/radio_telescope_delay_model/blob/main/README.md). Currently, it only wraps the almacalc function which calls the main CALC function aDRIVR. The Fortran files of interest are calc11/src/almacalc.f and calc11/src/adrvr.f

Here is a link to the example notebook that can be run on Google Colab (https://colab.research.google.com/github/casangi/radio_telescope_delay_model/blob/main/example_notebooks/Radio_Telescope_Delay_Model_Example.ipynb). It compares CALC, CASA, Astropy, and data from a measurement set. The Astropy and CASA calculations are done using code from @demorest. There is no exact agreement and the ms uvw coordinates show a strange difference pattern with the other methods. If I understand correctly the uvw coordinates in an Alma ms (converted from asdm) are done in https://open-bitbucket.nrao.edu/projects/CASA/repos/casa6/browse/casa5/code/alma/apps/asdm2MS/UvwCoords.cc . I have not yet done a careful comparison between UvwCoords.cc and CASA code in the notebook. In the "Run and Compare Functions" section of the notebook, you can change the pointing direction by changing use_user_pointing and user_pointing_direction.

Let me know if I should expose any of the other CALC functions.

@mhvk

mhvk commented Nov 2, 2020

Copy link
Copy Markdown
Contributor

@Jan-Willem - thanks so much! Will need some time to really go through it all...

@Joshuaalbert

Copy link
Copy Markdown
Author

@Jan-Willem great job! I'm taking a look at the notebook now.

@Joshuaalbert

Copy link
Copy Markdown
Author

Quite strange the difference between MS and the others. Perhaps something related to precision? Thanks for making this notebook. I think it'll be good for comparing against the astropy version which should be as precise or better than CALC.

@demorest

demorest commented Nov 2, 2020

Copy link
Copy Markdown

Hi all, after reviewing some of the older discussion, I'm still not sure a new frame is needed. It still seems to me that the existing SkyOffsetFrame does the job of defining the "l" and "m" directions in the usual way relative to a specified sky position. It would be great to have VLBI-level UVW calculation implemented using astropy, possibly using the derivative method as mentioned above, but I'm not seeing how this needs a new coordinate frame or what that frame would be.

Thanks @Jan-Willem for posting the new comparisons! When I looked at this before, it seemed that the difference between my astropy and CASA UVWs was a small rotation that got larger for sky positions near the poles. But I never really tracked down the cause. Also I looked a bit at CASA code but I think you have much more experience with it than I do.. if UvwCoords.cc is doing something different that would be good to know.

@caseyjlaw

Copy link
Copy Markdown

It seems like it would be easy to implement a high-level function that could call either the "astropy-like" function or "calc-like" function, based on the application and precision required. If we took that approach, we could create a PR now that uses the astropy-like function and document the fact that it has known variances from CASA and calc.
I agree that we haven't actually fully characterized those variances, though.

@mhvk

mhvk commented Nov 3, 2020

Copy link
Copy Markdown
Contributor

Indeed, there is precedence for that idea of allowing users to chose in how one sets, e.g., the solar system ephemeris. But as you note, we first have to be sure we understand the variances.

@Joshuaalbert

Copy link
Copy Markdown
Author

Hi @demorest, the point is that for the precise formulation, the UVW coordinates are a function of position, direction (of the geodesic), and velocity with respect to the solar system barycenter. I agree SkyOffsetFrame could be useful if delay is linearised in direction, as it just does an arbitrary rotation of a right-handed-system:

origin = skyoffset_frame.origin.spherical
mat1 = rotation_matrix(-skyoffset_frame.rotation, 'x')
mat2 = rotation_matrix(-origin.lat, 'y')
mat3 = rotation_matrix(origin.lon, 'z')

However, even in that case the origin and rotation arguments would need to be calculated per antenna, direction, and time. I also agree that we can provide varying levels of precision. I personally, don't see why it would be difficult to provide the VLBI-precise transform. Astropy has all the ingredients already.

@mhvk

mhvk commented Dec 8, 2020

Copy link
Copy Markdown
Contributor

Slightly randomly but I started another way to access CALC11, one that uses numpy.f2py so one can access all subroutines, over at https://github.com/mhvk/pycalc11. For now, mostly just tests.

This happened to be picked up by @aelanman who mentioned his own efforts to see how consistent astropy and CALC11 were (and more interface routines at https://github.com/aelanman/difxcalc_astropy). He also mentioned the https://github.com/RadioAstronomySoftwareGroup/pyuvdata package that does non-relativistic UVW (and apparently uses astropy throughout).

No chance yet to look into any of this in detail...

@github-actions

github-actions Bot commented Sep 3, 2021

Copy link
Copy Markdown
Contributor

Hi humans 👋 - this pull request hasn't had any new commits for approximately 11 months. I plan to close this in 30 days if the pull request doesn't have any new commits by then.

In lieu of a stalled pull request, please consider closing this and open an issue instead if a reminder is needed to revisit in the future. Maintainers may also choose to add keep-open label to keep this PR open but it is discouraged unless absolutely necessary.

If this PR still needs to be reviewed, as an author, you can rebase it to reset the clock.

If you believe I commented on this pull request incorrectly, please report this here.

@github-actions github-actions Bot added the Close? Tell stale bot that this issue/PR is stale label Sep 3, 2021
@github-actions

github-actions Bot commented Sep 4, 2021

Copy link
Copy Markdown
Contributor

Hi humans 👋 - this pull request hasn't had any new commits for approximately 11 months. I plan to close this in 30 days if the pull request doesn't have any new commits by then.

In lieu of a stalled pull request, please consider closing this and open an issue instead if a reminder is needed to revisit in the future. Maintainers may also choose to add keep-open label to keep this PR open but it is discouraged unless absolutely necessary.

If this PR still needs to be reviewed, as an author, you can rebase it to reset the clock.

If you believe I commented on this pull request incorrectly, please report this here.

@pllim

pllim commented Sep 4, 2021

Copy link
Copy Markdown
Member

Ops, sorry for the double bot post. Hopefully I fixed the bug upstream.

@github-actions github-actions Bot added the closed-by-bot Closed by stale bot label Oct 5, 2021
@github-actions

github-actions Bot commented Oct 5, 2021

Copy link
Copy Markdown
Contributor

I'm going to close this pull request as per my previous message. If you think what is being added/fixed here is still important, please remember to open an issue to keep track of it. Thanks!

If this is the first time I am commenting on this issue, or if you believe I closed this issue incorrectly, please report this here.

@Joshuaalbert

Copy link
Copy Markdown
Author

@caseyjlaw I have written a JAX+astropy based VLBI-accurate UVW engine here https://github.com/Joshuaalbert/DSA2000-Cal/blob/main/dsa2000_cal/dsa2000_cal/common/uvw_utils.py for the DSA2000 project and wonder if there is any desire still to have this functionality in astropy. #9869

@mhvk

mhvk commented Jun 18, 2024

Copy link
Copy Markdown
Contributor

Definitely still would like to have UVW in astropy (though not a dependency on JAX; is it optional?)

@Joshuaalbert

Copy link
Copy Markdown
Author

The implementation relies on the auto-diff functionality of JAX to compute the I've coordinates. Without it derivatives would have to be written out by hand.

@Joshuaalbert

Copy link
Copy Markdown
Author

@mhvk

mhvk commented Jun 18, 2024

Copy link
Copy Markdown
Contributor

We do have transformations that do automatic differentation too -- FunctionTransformWithFiniteDifference -- so hopefully this is not a showstopper!

@caseyjlaw

Copy link
Copy Markdown

Nice to see this work coming back into astropy.
@Joshuaalbert Would you suggest we open a PR to start discussing the question of dependencies, etc. with astropy developers?

@Joshuaalbert

Copy link
Copy Markdown
Author

Sure we can open another PR for that. @mhvk that might be an option, do you have some examples of how that might work?

@mhvk

mhvk commented Jun 19, 2024

Copy link
Copy Markdown
Contributor

I think I wrote a bit too quickly, FunctionTransformWithFiniteDifference does the finite difference only to transform velocities, so that is not directly relevant here. But I think we really should discuss in #7766, since this is a closed PR, and hence will not be easily found/tracked!!

@mhvk

mhvk commented Jun 19, 2024

Copy link
Copy Markdown
Contributor

I started an entry at #7766 (comment) to transfer us over to #7766.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Close? Tell stale bot that this issue/PR is stale closed-by-bot Closed by stale bot coordinates Enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants