Improved documentation for ClusterFile on the python side (#201)

- Fixed CI job not doing python docs
- added more docs on cluster file 
- fixed generating docs on cluster vector
This commit is contained in:
Erik Fröjdh
2025-06-13 10:41:39 +02:00
committed by GitHub
parent 4976ec1651
commit 11fa95b23c
7 changed files with 40 additions and 8 deletions

View File

@ -43,7 +43,7 @@ jobs:
run: | run: |
mkdir build mkdir build
cd build cd build
cmake .. -DAARE_SYSTEM_LIBRARIES=ON -DAARE_DOCS=ON cmake .. -DAARE_SYSTEM_LIBRARIES=ON -DAARE_PYTHON_BINDINGS=ON -DAARE_DOCS=ON
make -j 2 make -j 2
make docs make docs

View File

@ -4,4 +4,5 @@ ClusterFile
.. doxygenclass:: aare::ClusterFile .. doxygenclass:: aare::ClusterFile
:members: :members:
:undoc-members: :undoc-members:
:private-members: :private-members:

View File

@ -2,9 +2,24 @@
ClusterFile ClusterFile
============ ============
The :class:`ClusterFile` class is the main interface to read and write clusters in aare. Unfortunately the
old file format does not include metadata like the cluster size and the data type. This means that the
user has to know this information from other sources. Specifying the wrong cluster size or data type
will lead to garbage data being read.
.. py:currentmodule:: aare .. py:currentmodule:: aare
.. autoclass:: ClusterFile .. autoclass:: ClusterFile
:members:
:undoc-members:
:inherited-members:
Below is the API of the ClusterFile_Cluster3x3i but all variants share the same API.
.. autoclass:: aare._aare.ClusterFile_Cluster3x3i
:special-members: __init__
:members: :members:
:undoc-members: :undoc-members:
:show-inheritance: :show-inheritance:

View File

@ -2,8 +2,10 @@ ClusterVector
================ ================
The ClusterVector, holds clusters from the ClusterFinder. Since it is templated The ClusterVector, holds clusters from the ClusterFinder. Since it is templated
in C++ we use a suffix indicating the data type in python. The suffix is in C++ we use a suffix indicating the type of cluster it holds. The suffix follows
``_i`` for integer, ``_f`` for float, and ``_d`` for double. the same pattern as for ClusterFile i.e. ``ClusterVector_Cluster3x3i``
for a vector holding 3x3 integer clusters.
At the moment the functionality from python is limited and it is not supported At the moment the functionality from python is limited and it is not supported
to push_back clusters to the vector. The intended use case is to pass it to to push_back clusters to the vector. The intended use case is to pass it to
@ -26,7 +28,8 @@ C++ functions that support the ClusterVector or to view it as a numpy array.
.. py:currentmodule:: aare .. py:currentmodule:: aare
.. autoclass:: ClusterVector_i .. autoclass:: aare._aare.ClusterVector_Cluster3x3i
:special-members: __init__
:members: :members:
:undoc-members: :undoc-members:
:show-inheritance: :show-inheritance:

View File

@ -10,4 +10,5 @@ dependencies:
- sphinx_rtd_theme - sphinx_rtd_theme
- furo - furo
- zeromq - zeromq
- pybind11

View File

@ -70,6 +70,17 @@ def ClusterFile(fname, cluster_size=(3,3), dtype=np.int32, chunk_size = 1000):
""" """
Factory function to create a ClusterFile object. Provides a cleaner syntax for Factory function to create a ClusterFile object. Provides a cleaner syntax for
the templated ClusterFile in C++. the templated ClusterFile in C++.
.. code-block:: python
from aare import ClusterFile
with ClusterFile("clusters.clust", cluster_size=(3,3), dtype=np.int32) as cf:
# cf is now a ClusterFile_Cluster3x3i object but you don't need to know that.
for clusters in cf:
# Loop over clusters in chunks of 1000
# The type of clusters will be a ClusterVector_Cluster3x3i in this case
""" """
cls = _get_class("ClusterFile", cluster_size, dtype) cls = _get_class("ClusterFile", cluster_size, dtype)

View File

@ -38,19 +38,20 @@ void define_ClusterFile(py::module &m, const std::string &typestr) {
self.read_clusters(n_clusters)); self.read_clusters(n_clusters));
return v; return v;
}, },
py::return_value_policy::take_ownership) py::return_value_policy::take_ownership, py::arg("n_clusters"))
.def("read_frame", .def("read_frame",
[](ClusterFile<ClusterType> &self) { [](ClusterFile<ClusterType> &self) {
auto v = new ClusterVector<ClusterType>(self.read_frame()); auto v = new ClusterVector<ClusterType>(self.read_frame());
return v; return v;
}) })
.def("set_roi", &ClusterFile<ClusterType>::set_roi) .def("set_roi", &ClusterFile<ClusterType>::set_roi,
py::arg("roi"))
.def( .def(
"set_noise_map", "set_noise_map",
[](ClusterFile<ClusterType> &self, py::array_t<int32_t> noise_map) { [](ClusterFile<ClusterType> &self, py::array_t<int32_t> noise_map) {
auto view = make_view_2d(noise_map); auto view = make_view_2d(noise_map);
self.set_noise_map(view); self.set_noise_map(view);
}) }, py::arg("noise_map"))
.def("set_gain_map", .def("set_gain_map",
[](ClusterFile<ClusterType> &self, py::array_t<double> gain_map) { [](ClusterFile<ClusterType> &self, py::array_t<double> gain_map) {