From 0f910685d92a4eee1054df14e82caa714f7ac42d Mon Sep 17 00:00:00 2001 From: Manon Marchand Date: Fri, 8 Nov 2024 21:46:29 +0100 Subject: [PATCH] fix: moc from zone should accept lon_max = 360 deg (#182) * fix: moc from zone should accept lon_max = 360 deg * fix: upper right corner is not expected in the MOC --- CHANGELOG.md | 4 ++++ Cargo.toml | 4 ++-- python/mocpy/moc/moc.py | 14 +++++++++++--- python/mocpy/tests/test_moc.py | 4 +++- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6cd5582..b8e7613 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [unreleased] +### Fixed + +* in space MOCs: upper right corner of a zone can now have a longitude of 360° [#180] + ## [0.17.0] ### Added diff --git a/Cargo.toml b/Cargo.toml index f75bd21..84fa9c1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,8 +28,8 @@ bench = true crate-type = ["cdylib"] [dependencies] -moc = { version = "0.17", features = ["storage"] } -#moc = { git = 'https://github.com/cds-astro/cds-moc-rust', rev = '361eb278fe782bfc053433495c33e3f16e20cdbd', features = ["storage"] } +#moc = { version = "0.17", features = ["storage"] } +moc = { git = 'https://github.com/cds-astro/cds-moc-rust', rev = 'f252c2ea3f66cef60e501c2beca2977c439236f8', features = ["storage"] } healpix = { package = "cdshealpix", version = "0.7" } # healpix = { package = "cdshealpix", git = 'https://github.com/cds-astro/cds-healpix-rust', branch = 'master' } rayon = "1.10" diff --git a/python/mocpy/moc/moc.py b/python/mocpy/moc/moc.py index b9edfdb..209179c 100644 --- a/python/mocpy/moc/moc.py +++ b/python/mocpy/moc/moc.py @@ -1483,8 +1483,10 @@ def from_zone(cls, coordinates, max_depth): """ Create a MOC from a zone. - The zone is defined by a range of longitudes and latitudes. Its sides follow great - circles in longitudes and small circles for latitudes. + The zone is defined by a range of longitudes and latitudes. Its sides follow + great circles in longitudes and small circles for latitudes. + The bottom and left sides are included in the MOC, while the top and right sides + are not. Parameters ---------- @@ -1508,10 +1510,16 @@ def from_zone(cls, coordinates, max_depth): ... max_depth=5 ... ) """ + # workaround astropy.SkyCoord that wraps longitudes between [0:360[ + # where we want ]0:360] for lon_max. There is no issue for lon_min that is + # expected in [0:360[. + lon_max = coordinates[1].icrs.ra.deg + if lon_max == 0: + lon_max = 360 index = mocpy.from_zone( coordinates[0].icrs.ra.deg, coordinates[0].icrs.dec.deg, - coordinates[1].icrs.ra.deg, + lon_max, coordinates[1].icrs.dec.deg, np.uint8(max_depth), ) diff --git a/python/mocpy/tests/test_moc.py b/python/mocpy/tests/test_moc.py index 2f2727a..c940ae2 100644 --- a/python/mocpy/tests/test_moc.py +++ b/python/mocpy/tests/test_moc.py @@ -600,8 +600,10 @@ def test_from_ring(): def test_from_zone(): moc = MOC.from_zone(SkyCoord([[-50, -50], [50, 50]], unit="deg"), max_depth=5) # test the diagonal - for coordinate in range(-50, 60, 10): + for coordinate in range(-50, 40, 10): ## (50,50) not included assert moc.contains_skycoords(SkyCoord(coordinate, coordinate, unit="deg")) + # regression for #180 + MOC.from_zone(SkyCoord([(180, 30), (360, 50)], unit="deg"), max_depth=3) def test_from_box():