Skip to content

Commit

Permalink
Add STCS2MOC function (tests to be added) [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
fxpineau committed Dec 12, 2023
1 parent 38fc093 commit 0b3d223
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
26 changes: 26 additions & 0 deletions python/mocpy/moc/moc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
7 changes: 7 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<usize> {
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``.
Expand Down

0 comments on commit 0b3d223

Please sign in to comment.