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

TypeError: argument 'lon': 'float64' object cannot be converted to 'PyArray<T, D>' #108

Closed
tikk3r opened this issue Sep 14, 2023 · 3 comments
Assignees
Labels
Milestone

Comments

@tikk3r
Copy link

tikk3r commented Sep 14, 2023

With version 0.12.0 or higher I run into the following issue trying to check a coordinate inside a MOC:

In [2]: import mocpy; import astropy.units as u; moc = mocpy.MOC.from_fits('dr2-moc.moc'); moc.contains_l
   ...: onlat(164.43*u.deg, 45.54*u.deg)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[2], line 1
----> 1 import mocpy; import astropy.units as u; moc = mocpy.MOC.from_fits('dr2-moc.moc'); moc.contains_lonlat(164.43*u.deg, 45.54*u.deg)

File ~/anaconda3/lib/python3.10/site-packages/mocpy/moc/moc.py:259, in MOC.contains_lonlat(self, lon, lat, keep_inside)
    257 lon = lon if isinstance(lon, Longitude) else Longitude(lon)
    258 lat = lat if isinstance(lat, Latitude) else Latitude(lat)
--> 259 mask = mocpy.filter_pos(
    260     self._store_index,
    261     lon.to_value(u.deg).astype(np.float64),
    262     lat.to_value(u.deg).astype(np.float64),
    263 )
    264 if keep_inside:
    265     return mask

TypeError: argument 'lon': 'float64' object cannot be converted to 'PyArray<T, D>'

The MOC in question is available here and works with lower versions such as 0.11.

@ManonMarchand
Copy link
Member

Thanks for reporting, that's an issue with the new contains_lonlat that only takes lists of coordinates.
For now, you can fix by doing :

moc.contains_lonlat([164.43*u.deg], [45.54*u.deg])

@ManonMarchand ManonMarchand added this to the 1.0.0 milestone Sep 14, 2023
@ManonMarchand ManonMarchand self-assigned this Sep 14, 2023
@tikk3r
Copy link
Author

tikk3r commented Sep 14, 2023

Thanks for reporting, that's an issue with the new contains_lonlat that only takes lists of coordinates. For now, you can fix by doing :

moc.contains_lonlat([164.43*u.deg], [45.54*u.deg])

Ah excellent, that works for now. Thanks!

@ManonMarchand
Copy link
Member

It is now solved in the dev version (install with :

   git clone https://github.com/cds-astro/mocpy.git
   cd mocpy
   pip install .

) and it will be in the next official release

Don't hesitate to come back if you have any question/concern with the library or the docs 🙂

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