Skip to content

Commit

Permalink
Add stc2moc test and enrich the doc
Browse files Browse the repository at this point in the history
  • Loading branch information
fxpineau committed Dec 12, 2023
1 parent 0b3d223 commit f480542
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ bench = true
crate-type = ["cdylib"]

[dependencies]
moc = { version = "0.11.2", features = ["storage"] }
moc = { version = "0.12", features = ["storage"] }
healpix = { package = "cdshealpix", version = "0.6" }
# moc = { git = 'https://github.com/cds-astro/cds-moc-rust', branch = 'main', features = ["storage"] }
# healpix = { package = "cdshealpix", git = 'https://github.com/cds-astro/cds-healpix-rust', branch = 'master' }
Expand Down
22 changes: 21 additions & 1 deletion python/mocpy/moc/moc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,19 @@ def from_stcs(cls, stcs, max_depth, delta_depth=2):
"""
Create a MOC from a STC-S.
Info
----
Time, Spectral and Redshift sub-phrases are ignored.
Warning
-------
There is so far no implicit conversion, so the STC-S string will be rejected if:
* the frame is different from `ICRS`
* the flavor is different from `Spher2`
* the units are different from `degrees`
The implementation is not (yet?) fully compliant with the STC standard (see MOC Lib rust for more details):
* DIFFERENCE is so far interpreted as a symmetrical difference (XOR) while it is a MINUS in the STC standard
* Self-intersecting Polygons are supported, and the "interior" usually has the smallest area
Parameters
----------
Expand All @@ -1062,10 +1075,17 @@ def from_stcs(cls, stcs, max_depth, delta_depth=2):
-------
result : `~mocpy.moc.MOC`
The resulting MOC
Examples
--------
>>> from mocpy import MOC
>>> moc1 = MOC.from_stcs("Circle ICRS 147.6 69.9 0.4", max_depth=14)
>>> moc2 = MOC.from_cone(lon=147.6 * u.deg, lat=69.9 * u.deg, radius=Angle(0.4, u.deg), max_depth=14)
>>> assert (moc1 == moc2)
"""
index = mocpy.from_stcs(stcs, np.uint8(max_depth), np.uint8(delta_depth))
return cls(index)

@classmethod
def new_empty(cls, max_depth):
"""
Expand Down
6 changes: 3 additions & 3 deletions python/mocpy/tests/test_abstract_moc.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
def all_moc_types():
"""Create a fixture with a MOC of each type."""
moc = MOC.from_str("0/0-11")
tmoc = TimeMOC.from_str("0/0-2")
fmoc = FrequencyMOC.from_str("0/0-2")
tmoc = TimeMOC.from_str("0/0-1")
fmoc = FrequencyMOC.from_str("0/0-1")
stmoc = STMOC.from_spatial_coverages(Time("2023-11-13"), Time("2023-11-14"), moc)
return [moc, tmoc, fmoc, stmoc]

Expand Down Expand Up @@ -89,7 +89,7 @@ def test_passing_save(all_moc_types, path):
moc_json = json.load(f)
# test that it is a valid dictionary
indices = moc_json[0]["s"]["0"] if isinstance(moc, STMOC) else moc_json["0"]
assert {0, 1, 2}.issubset(set(indices))
assert {0, 1}.issubset(set(indices))
# delete the moc we just created
path.unlink()
# -----
Expand Down
12 changes: 12 additions & 0 deletions python/mocpy/tests/test_moc.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ def test_moc_serialize_to_json(moc_from_fits_image):
def test_serialize_to_str(moc, expected):
assert moc.serialize(format="str") == expected


# --- TESTING MOC plot functions ---#
def test_mpl_fill():
fits_path = "resources/P-GALEXGR6-AIS-FUV.fits"
Expand Down Expand Up @@ -737,3 +738,14 @@ def test_from_valued_healpix_cells_bayestar_and_split():
assert len(mocs) == 2
for moc in mocs:
assert moc.max_order == 11


def test_from_stcs():
moc1 = MOC.from_stcs("Circle ICRS 147.6 69.9 0.4", 14, 2)
moc2 = MOC.from_cone(
lon=147.6 * u.deg,
lat=69.9 * u.deg,
radius=Angle(0.4, u.deg),
max_depth=14,
)
assert moc1 == moc2

0 comments on commit f480542

Please sign in to comment.