Skip to content

Commit

Permalink
fix: moc from zone should accept lon_max = 360 deg (#182)
Browse files Browse the repository at this point in the history
* fix: moc from zone should accept lon_max = 360 deg

* fix: upper right corner is not expected in the MOC
  • Loading branch information
ManonMarchand authored Nov 8, 2024
1 parent a76f409 commit 0f91068
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
14 changes: 11 additions & 3 deletions python/mocpy/moc/moc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------
Expand All @@ -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),
)
Expand Down
4 changes: 3 additions & 1 deletion python/mocpy/tests/test_moc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit 0f91068

Please sign in to comment.