ssagear / zoomies

Kinematic stellar age prediction tool from Gaia astrometry + radial velocity.
MIT License
8 stars 0 forks source link

Issue with Jz calculation #2

Open caganze opened 5 months ago

caganze commented 5 months ago

Hi,

I am running into the following issue while trying to estimate Jz based on the notebook tutorial

Here is my code

import zoomies
from astroquery.gaia import Gaia
from astropy.coordinates import SkyCoord
c=SkyCoord('13:44:25.4773 −40:20:15.5222', unit=(u.hourangle, u.deg))
r=Gaia.query_object(c, radius=5*u.arcsec)
r_actions = zoomies.calc_jz(r, method='agama')

I get the following error

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[46], line 2
      1 c=SkyCoord('13:44:25.4773 −40:20:15.5222', unit=(u.hourangle, u.deg))
----> 2 r_actions = zoomies.calc_jz(r, method='agama')
      3 r_actions

File ~/anaconda3/lib/python3.11/site-packages/zoomies/quick_jz.py:67, in calc_jz(gaia_table, method, mwmodel, write, fname)
     64 import agama
     66 agama.setUnits(mass=u.Msun, length=u.kpc, time=u.Myr)
---> 67 agama_pot = mw.as_interop("agama")
     68 af = agama.ActionFinder(agama_pot)
     69 Jr, Jz, Jphi = af(w.w(galactic).T).T * 1000 # agama units are different from galpy

AttributeError: 'MilkyWayPotential2022' object has no attribute 'as_interop'

Also, when I try using galpy, there is an error

r_actions = zoomies.calc_jz(r, method='galpy')
File ~/anaconda3/lib/python3.11/site-packages/zoomies/quick_jz.py:55, in calc_jz(gaia_table, method, mwmodel, write, fname)
     49 w = gd.PhaseSpacePosition(galcen.data)
     51 if method=='galpy':
     52 
     53     # print('Calculating actions with galpy...')
---> 55     aaf = galpy_find_actions_staeckel(mw, w)
     56     Jz = aaf['actions'][:, 2]
     57     Jphi = aaf['actions'][:, 1]

File ~/anaconda3/lib/python3.11/site-packages/gala/dynamics/actionangle/tests/staeckel_helpers.py:84, in galpy_find_actions_staeckel(potential, w, mean, delta, ro, vo)
     81 o = w_.to_galpy_orbit(ro, vo)
     82 aAS = actionAngleStaeckel(pot=galpy_potential, delta=delta_)
---> 84 aaf = aAS.actionsFreqsAngles(o)
     85 aaf = {
     86     "actions": np.array(aaf[:3]).T * ro * vo,
     87     "freqs": np.array(aaf[3:6]).T * vo / ro,
     88     "angles": coord.Angle(np.array(aaf[6:]).T * u.rad),
     89 }
     90 if mean:

File ~/anaconda3/lib/python3.11/site-packages/galpy/util/conversion.py:1220, in actionAngle_physical_input.<locals>.wrapper(*args, **kwargs)
   1217 @wraps(method)
   1218 def wrapper(*args, **kwargs):
   1219     if len(args) < 3:  # orbit input
-> 1220         return method(*args, **kwargs)
   1221     ro = kwargs.get("ro", None)
   1222     if ro is None and hasattr(args[0], "_ro"):

File ~/anaconda3/lib/python3.11/site-packages/galpy/util/conversion.py:1206, in physical_conversion_actionAngle.<locals>.wrapper.<locals>.wrapped(*args, **kwargs)
   1204     return newOut
   1205 else:
-> 1206     return method(*args, **kwargs)

File ~/anaconda3/lib/python3.11/site-packages/galpy/actionAngle/actionAngle.py:269, in actionAngle.actionsFreqsAngles(self, *args, **kwargs)
    245 """
    246 Evaluate the actions, frequencies, and angles (jr,lz,jz,Omegar,Omegaphi,Omegaz,angler,anglephi,anglez)
    247 
   (...)
    266 - 2014-01-03 - Written for top level - Bovy (IAS)
    267 """
    268 try:
--> 269     return self._actionsFreqsAngles(*args, **kwargs)
    270 except AttributeError:  # pragma: no cover
    271     raise NotImplementedError(
    272         "'actionsFreqsAngles' method not implemented for this actionAngle module"
    273     )

File ~/anaconda3/lib/python3.11/site-packages/galpy/actionAngle/actionAngleStaeckel.py:386, in actionAngleStaeckel._actionsFreqsAngles(self, *args, **kwargs)
    384     R, vR, vT, z, vz, phi = args
    385 else:
--> 386     self._parse_eval_args(*args)
    387     R = self._eval_R
    388     vR = self._eval_vR

File ~/anaconda3/lib/python3.11/site-packages/galpy/actionAngle/actionAngle.py:155, in actionAngle._parse_eval_args(self, *args, **kwargs)
    153     orb = args[0]
    154 if len(orb.shape) > 1:
--> 155     raise RuntimeError(
    156         "Evaluating actionAngle methods with Orbit instances with multi-dimensional shapes is not supported"
    157     )
    158 self._eval_R = orb.R(use_physical=False)
    159 self._eval_vR = orb.vR(use_physical=False)

RuntimeError: Evaluating actionAngle methods with Orbit instances with multi-dimensional shapes is not supported
ssagear commented 5 months ago

Hello,

Can you tell me what version of gala you're running -- and if it's not the most recent version, could you try updating the gala package and run the code again?

I believe the gala.potential.as_interop() function was added to the package recently, so if you're running version < 1.8 it might not include that function. I'll update the requirements for that -- thank you for pointing this out! Let me know if updating gala works.

As for galpy -- I have been having the same issue you've run into, and I should probably remove support for calculating action with galpy until I get that figured out. Using agama should still work though.

Sheila