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

Indexing orbit with integration time fails #415

Closed
jamesmlane opened this issue Feb 4, 2020 · 1 comment
Closed

Indexing orbit with integration time fails #415

jamesmlane opened this issue Feb 4, 2020 · 1 comment
Assignees
Labels
Milestone

Comments

@jamesmlane
Copy link
Contributor

jamesmlane commented Feb 4, 2020

Orbit instances should be able to be indexed by times after integration, as long as the time is within the integration range. This fails for non-array arguments. The error is of slightly different origin depending on whether astropy units are used.

Example for astropy units

from galpy import potential, orbit
import numpy as np
from astropy import units as apu

pot = potential.MWPotential2014
o = orbit.Orbit()
times = np.array([0,1,2])*apu.Gyr

o.integrate(times,pot)
o(times[-1])

Throws an error on line 4236 when calling len(t).

Example for no astropy units

from galpy import potential, orbit
import numpy as np

pot = potential.MWPotential2014
o = orbit.Orbit()
times = np.array([0,1,2])

o.integrate(times,pot)
o(times[-1])

Throws an error on line 4261 because isinstance(t,(int,float)) returns False for numpy dtypes, then len(t) is evaluated.

@jamesmlane
Copy link
Contributor Author

I think this can be fixed by just calling t= np.atleast_1d(out[0]) right away after the first if/elif/else statement in _call_internal to make it an array, and then refactoring the remaining conditional statements

@jobovy jobovy self-assigned this Feb 6, 2020
@jobovy jobovy added the bug label Feb 6, 2020
@jobovy jobovy added this to the v1.6 milestone Feb 6, 2020
jobovy added a commit that referenced this issue Feb 6, 2020
@jobovy jobovy closed this as completed in a42411f Feb 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants