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

MOC from zone with upper right corner #180

Open camposandro opened 4 days ago

camposandro commented 4 days ago

I'm currently migrating the HATS box filtering implementation to use mocpy's zones, hats#401, and I identified an edge case that I cannot get to work. When the upper right corner of the zone is in the 0/360-degree boundary, an error is thrown:

from mocpy import MOC
from astropy.coordinates import SkyCoord

>>> moc = MOC.from_zone(SkyCoord([(180,30),(0,50)], unit="deg"), max_depth=3)
thread '<unnamed>' panicked at /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cdshealpix-0.7.0/src/sph_geom/zone.rs:28:5:
assertion failed: (0.0..TWICE_PI).contains(&lon_min) && 0.0 < lon_max && lon_max <= TWICE_PI
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/scampos/anaconda3/envs/lsdb/lib/python3.10/site-packages/mocpy/moc/moc.py", line 1511, in from_zone
    index = mocpy.from_zone(
pyo3_runtime.PanicException: assertion failed: (0.0..TWICE_PI).contains(&lon_min) && 0.0 < lon_max && lon_max <= TWICE_PI

The SkyCoord object wraps the 360 degree longitudes to 0 degrees, and therefore the maximum longitude constraint that imposes 0.0 < lon_max && lon_max <= TWICE_PI fails. It would be great if we could handle both 360/0.

The region I am trying to achieve is approximately the following (used coordinates [(180,30),(359,50)]). Figure_1

ManonMarchand commented 19 hours ago

Indeed, thanks for reporting!