diff --git a/python/mocpy/moc/moc.py b/python/mocpy/moc/moc.py index c7f21c04..db86e505 100644 --- a/python/mocpy/moc/moc.py +++ b/python/mocpy/moc/moc.py @@ -1040,6 +1040,32 @@ def from_polygon(cls, lon, lat, complement=False, max_depth=10): ) return cls(index) + @classmethod + def from_stcs(cls, stcs, max_depth, delta_depth=2): + """ + Create a MOC from a STC-S. + + + Parameters + ---------- + stcs : str + The STC-S string. + max_depth : int + Maximum HEALPix cell resolution. + delta_depth : int, optional + To control the approximation, you can choose to perform the computations at a deeper + depth using the `depth_delta` parameter. + The depth at which the computations will be made will therefore be equal to + `max_depth` + `depth_delta`. + + Returns + ------- + result : `~mocpy.moc.MOC` + The resulting MOC + """ + 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/src/lib.rs b/src/lib.rs index 05dbb0d6..fd7af245 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -213,6 +213,13 @@ fn mocpy(_py: Python, m: &PyModule) -> PyResult<()> { .map_err(PyValueError::new_err) } + #[pyfn(m)] + pub fn from_stcs(stcs_ascii: &str, depth: u8, delta_depth: u8) -> PyResult { + U64MocStore::get_global_store() + .from_stcs(depth, delta_depth, stcs_ascii) + .map_err(PyValueError::new_err) + } + /// Create a 1D spatial coverage from a list of uniq cells each associated with a value. /// /// The coverage computed contains the cells summing from ``cumul_from`` to ``cumul_to``.