cds-astro / mocpy

Python library to easily create and manipulate MOCs (Multi-Order Coverage maps)
https://cds-astro.github.io/mocpy/
BSD 3-Clause "New" or "Revised" License
60 stars 33 forks source link

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

Closed tikk3r closed 1 year ago

tikk3r commented 1 year ago

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 commented 1 year ago

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])
tikk3r commented 1 year ago

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 commented 1 year ago

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 :slightly_smiling_face: