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

Weird radial velocities when flipping orbit #481

Closed
smeingast opened this issue May 11, 2022 · 3 comments
Closed

Weird radial velocities when flipping orbit #481

smeingast opened this issue May 11, 2022 · 3 comments

Comments

@smeingast
Copy link

Hey. Just noticed that when flipping an orbit, I get very strange radial velocity readings. Here's the code to reproduce the result:

import numpy as np
from astropy import units as u
from astropy.coordinates import SkyCoord
from galpy.orbit import Orbit
from galpy.potential import MWPotential2014

ts = np.linspace(0, 100, 5) * u.Myr

coo = SkyCoord(
    ra=250 * u.deg,
    dec=-20 * u.deg,
    distance=250 * u.pc,
    pm_ra_cosdec=-20 * u.mas / u.yr,
    pm_dec=20 * u.mas / u.yr,
    radial_velocity=10 * u.km / u.s,
    frame="icrs",
)

o = Orbit(coo)
o.integrate(ts, MWPotential2014)

rv = o.SkyCoord(ts).radial_velocity
print(rv)
# [ 10.           7.11215027  -9.72675932 -22.65899826 -28.49652797] km / s

o.flip(inplace=True)
rv = o.SkyCoord(ts).radial_velocity
print(rv)
# [ -25.50342192 -439.74186573 -356.92852705 -244.44249105 -119.58920121] km / s

The same happens when reading them directly with o.vlos(ts). Is this an error on my end with the orbit flipping, or is this an issue with galpy?

Many thanks for looking into this!! 😊

@jobovy
Copy link
Owner

jobovy commented May 11, 2022

Yes, this is expected. Flipping the velocities flips them in the Galactocentric frame, so you suddenly have your stars moving in the opposite way of the Sun (so you effectively add ~2x vcirc ~ 450 km/s). Flipping an orbit is mainly useful as an alternative way to integrate an orbit backwards (flip, integrate, flip back), but there's little reason to do this ever instead of just integrating towards smaller times (e.g., ts= numpy.linspace(0.,-100.,,5)*u.Myr).

@smeingast
Copy link
Author

Ah! Alright then, thanks for the tip (and the quick reply). Is it possible that integrating with negative times has only become possible recently with galpy? I feel like I tried this a few years ago and needed to flip the orbit to make the backward integration work. 🤔
In any case, this not only fixes my problem, it also makes writing my script far easier!! :D

@jobovy
Copy link
Owner

jobovy commented May 11, 2022

Is it possible that integrating with negative times has only become possible recently with galpy? I feel like I tried this a few years ago and needed to flip the orbit to make the backward integration work. 🤔

I don't quite remember, but I think there used to be issues with integrating backward with negative times. I don't remember what they were though... Anyway, it should now work and please open an issue if it doesn't!

@jobovy jobovy closed this as completed May 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants