From f48054260467aee79a3e519b35fb462928c9d23b Mon Sep 17 00:00:00 2001 From: fxpineau Date: Tue, 12 Dec 2023 16:49:07 +0100 Subject: [PATCH] Add stc2moc test and enrich the doc --- Cargo.toml | 2 +- python/mocpy/moc/moc.py | 22 +++++++++++++++++++++- python/mocpy/tests/test_abstract_moc.py | 6 +++--- python/mocpy/tests/test_moc.py | 12 ++++++++++++ 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6741afec..4a1e5210 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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' } diff --git a/python/mocpy/moc/moc.py b/python/mocpy/moc/moc.py index db86e505..b87453e6 100644 --- a/python/mocpy/moc/moc.py +++ b/python/mocpy/moc/moc.py @@ -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 ---------- @@ -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): """ diff --git a/python/mocpy/tests/test_abstract_moc.py b/python/mocpy/tests/test_abstract_moc.py index b5fc2c04..05623c77 100644 --- a/python/mocpy/tests/test_abstract_moc.py +++ b/python/mocpy/tests/test_abstract_moc.py @@ -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] @@ -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() # ----- diff --git a/python/mocpy/tests/test_moc.py b/python/mocpy/tests/test_moc.py index 3bc3dc30..64bf701e 100644 --- a/python/mocpy/tests/test_moc.py +++ b/python/mocpy/tests/test_moc.py @@ -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" @@ -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