Skip to content

Commit 18bd42c

Browse files
jwmbeenakkercrnh
andauthored
add module level docstrings (#8)
* add module level docstrings * fmt * add docstring to init * Update pyrot/eye_modelling/__init__.py Co-authored-by: crnh <30109443+crnh@users.noreply.github.com> * Update pyrot/eye_modelling/datamodels/__init__.py Co-authored-by: crnh <30109443+crnh@users.noreply.github.com> * Format docstrings * (re)write docstrings * Do not generate documentation for undocumented members * Fix datamodels docstring --------- Co-authored-by: crnh <30109443+crnh@users.noreply.github.com>
1 parent 15f967e commit 18bd42c

File tree

18 files changed

+142
-101
lines changed

18 files changed

+142
-101
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,7 @@ jobs:
2727
- name: Install Python
2828
run: uv python install ${{ matrix.python-version }}
2929
- name: Run tests
30-
run: uvx hatch test
30+
run: uvx hatch test
31+
- name: Lint docstrings
32+
if: always() # Run even if previous step fails
33+
run: uvx pydocstringformatter --exit-code scripts tests pyrot standalone

docs/conf.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@
9191

9292
autoapi_dirs = ["../pyrot"]
9393
autoapi_root = "api"
94-
# autoapi_options = [
95-
# "members",
96-
# "show-inheritance",
97-
# "show-module-summary",
98-
# ]
94+
autoapi_options = [
95+
"members",
96+
"show-inheritance",
97+
"show-module-summary",
98+
]

pyproject.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ exclude = [".github/", "docs/"]
3535
[tool.hatch.build.targets.wheel]
3636
packages = ["pyrot"]
3737

38+
[tool.hatch.envs.default]
39+
installer = "uv"
40+
python = "3.8"
41+
42+
[tool.hatch.envs.default.scripts]
43+
# Format docstrings according to numpydoc
44+
format-docstrings = "{env:HATCH_UV:uv} tool run pydocstringformatter --write {args:scripts tests pyrot standalone}"
45+
3846
# Testing
3947

4048
[[tool.hatch.envs.hatch-test.matrix]]
@@ -109,3 +117,10 @@ convention = "numpy"
109117

110118
[tool.ruff.format]
111119
quote-style = "double"
120+
121+
[tool.pydocstringformatter]
122+
style = "numpydoc"
123+
max-line-length = 120
124+
max-summary-lines = 1
125+
summary-quotes-same-line = true
126+
linewrap-full-docstring = true

pyrot/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
"""PyROT: Python RayOcular Tools.
2+
3+
A set of tools to work with eye models in Python. This library is designed to be as vendor-agnostic
4+
as possible, allowing it to be used without RayStation. Interactions with RayStation are handled
5+
through the `ro_interface` module.
6+
"""
7+
18
from __future__ import annotations
29

310
from pyrot import ro_interface

pyrot/config.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Configuration for pyROT."""
2+
13
from __future__ import annotations
24

35
from typing import TYPE_CHECKING, Literal
@@ -9,8 +11,9 @@
911

1012

1113
class Config:
12-
r"""Configuration for pyROT.
13-
Settings can be overwritten by `scripts\customization.py`, which is imported by `__common__.py`.
14+
"""Configuration for pyROT.
15+
16+
Settings can be overwritten by scripts/customization.py, which is imported by `__common__.py`.
1417
"""
1518

1619
ELLIPSOID_FIT_MINIMUM_MATRIX_CONDITION: float = 100
@@ -39,9 +42,9 @@ class Config:
3942
"""The eye model number. Needs to be altered/ checked in the case of multiple eye models."""
4043

4144
ROI_EXPORT_UNIT: Literal["Centimeter", "Millimeter"] = "Centimeter"
42-
"""The unit in which rois are exported."""
45+
"""The unit in which ROIs are exported."""
4346

44-
ROI_EXPORT_ROI_SUFFIX: str = None
47+
ROI_EXPORT_ROI_SUFFIX: str | None = None
4548
"""The suffix after the roi name of the rois that need to be exported.
4649
4750
By default, there is no suffix in RayOcular.

pyrot/eye_modelling/__init__.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
"""Eye modelling
2+
=============
3+
4+
The eye_modelling module provides methods matching the geometric eye-model to imaging and biometry data.
5+
6+
Notes
7+
-----
8+
The methods used in this package are based on the work of Pors et al. (submitted)
9+
10+
Modules
11+
-------
12+
clipbased_model
13+
Match a clip-based eye model to the clips.
14+
common_methods
15+
Shared utility functions and methods for eye modeling.
16+
ellipsoid_fit
17+
Functions for fitting an ellipsoid to POIs.
18+
match_sclera_to_markers
19+
Methods for matching sclera ellipse to POIs.
20+
match_with_biometry
21+
Methods to determine the best-fitting eye-model based on imaging and biometry data.
22+
"""
23+
124
from __future__ import annotations
225

326
from pyrot.eye_modelling import (

pyrot/eye_modelling/clipbased_model.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Create eye models based on clip locations and optic disk location."""
2+
13
from __future__ import annotations
24

35
import logging
@@ -15,9 +17,10 @@
1517
def match_ellipse_with_pois(
1618
eye_model_generators, eye_model_parameters, structure_set, input_ellipse, poi_type_clips, poi_type_on
1719
):
18-
"""
19-
Aligns the eye model's translation and rotation to best fit known clip locations (POIs) and the optic disk location.
20-
This function updates the eye model center and rotation so that the model's sclera surface matches the positions of physical markers (clips) and the optic disk.
20+
"""Aligns the eye model's translation and rotation to best fit known clip locations (POIs) and the optic disk
21+
location.
22+
This function updates the eye model center and rotation so that the model's sclera surface matches the positions of
23+
physical markers (clips) and the optic disk.
2124
2225
Parameters
2326
----------
@@ -99,8 +102,7 @@ def match_ellipse_with_pois(
99102

100103

101104
def calc_on_model_loc_patient(geometry_generators, eye_model_parameters, on_model_loc_method):
102-
"""
103-
Calculates the location of the optic nerve ROI on the unity circle for a given eye model.
105+
"""Calculates the location of the optic nerve ROI on the unity circle for a given eye model.
104106
105107
This function determines the standardized location of the optic disk as if the eye model were positioned at the origin
106108
([0, 0, 0]) with input angles [0, 0, 0] and sclera radii [1, 1, 1]. This is necessary for fitting procedures that
@@ -179,8 +181,7 @@ def calc_on_model_loc_patient(geometry_generators, eye_model_parameters, on_mode
179181

180182

181183
def registration_residuals(params, clip_data, optic_nerve_data, axes):
182-
"""
183-
Compute the residuals for ellipsoid registration and optic nerve location alignment.
184+
"""Compute the residuals for ellipsoid registration and optic nerve location alignment.
184185
185186
This function calculates the residuals between a set of 3D points (clip_data) and an ellipsoid model,
186187
as well as the normalized distance between the transformed optic nerve location and its model POI.
@@ -260,8 +261,7 @@ def registration_residuals(params, clip_data, optic_nerve_data, axes):
260261

261262

262263
def calc_ellipsoid_registration(clip_data, on_model_loc, on_image_loc, axes, initial_guess=None):
263-
"""
264-
Perform ellipsoid registration to align clip data and optic nerve locations.
264+
"""Perform ellipsoid registration to align clip data and optic nerve locations.
265265
266266
This function calculates the optimal translation and rotation parameters to align
267267
a set of 3D points (clip_data) with an ellipsoid defined by the given axes, while

pyrot/eye_modelling/common_methods.py

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Common methods for eye modelling."""
2+
13
from __future__ import annotations
24

35
import logging
@@ -9,8 +11,7 @@
911

1012

1113
def getTranslationMatrix(x: float, y: float, z: float) -> np.ndarray:
12-
"""
13-
Generate a translation matrix for 3D transformations.
14+
"""Generate a translation matrix for 3D transformations.
1415
1516
Parameters
1617
----------
@@ -30,8 +31,7 @@ def getTranslationMatrix(x: float, y: float, z: float) -> np.ndarray:
3031

3132

3233
def toRadians(angleDegrees: float) -> float:
33-
"""
34-
Convert an angle from degrees to radians.
34+
"""Convert an angle from degrees to radians.
3535
3636
Parameters
3737
----------
@@ -47,8 +47,7 @@ def toRadians(angleDegrees: float) -> float:
4747

4848

4949
def toDegrees(angleRadians: float) -> float:
50-
"""
51-
Convert an angle from radians to degrees.
50+
"""Convert an angle from radians to degrees.
5251
5352
Parameters
5453
----------
@@ -64,8 +63,7 @@ def toDegrees(angleRadians: float) -> float:
6463

6564

6665
def getIdentityMatrix() -> np.ndarray:
67-
"""
68-
Returns a 4x4 identity matrix.
66+
"""Returns a 4x4 identity matrix.
6967
7068
Returns
7169
-------
@@ -76,8 +74,7 @@ def getIdentityMatrix() -> np.ndarray:
7674

7775

7876
def getRotationMatrixX(angleDeg: float) -> np.ndarray:
79-
"""
80-
Calculate the rotation matrix for a rotation around the X-axis.
77+
"""Calculate the rotation matrix for a rotation around the X-axis.
8178
8279
Parameters
8380
----------
@@ -96,8 +93,7 @@ def getRotationMatrixX(angleDeg: float) -> np.ndarray:
9693

9794

9895
def getRotationMatrixY(angleDeg: float) -> np.ndarray:
99-
"""
100-
Generate a rotation matrix for a rotation around the Y-axis.
96+
"""Generate a rotation matrix for a rotation around the Y-axis.
10197
10298
Parameters
10399
----------
@@ -116,8 +112,7 @@ def getRotationMatrixY(angleDeg: float) -> np.ndarray:
116112

117113

118114
def getRotationMatrixZ(angleDeg: float) -> np.ndarray:
119-
"""
120-
Generate a rotation matrix for a rotation around the Z-axis.
115+
"""Generate a rotation matrix for a rotation around the Z-axis.
121116
122117
Parameters
123118
----------
@@ -136,8 +131,7 @@ def getRotationMatrixZ(angleDeg: float) -> np.ndarray:
136131

137132

138133
def getEyeModelGeometry(eyeModel: object, structureType: str) -> object:
139-
"""
140-
Retrieve the geometry for a specific structure type from the eye model.
134+
"""Retrieve the geometry for a specific structure type from the eye model.
141135
142136
Parameters
143137
----------
@@ -161,8 +155,7 @@ def getEyeModelGeometry(eyeModel: object, structureType: str) -> object:
161155

162156

163157
def getClipGeometries(eyeModel: object) -> list:
164-
"""
165-
Retrieve all clip geometries from the eye model.
158+
"""Retrieve all clip geometries from the eye model.
166159
167160
Parameters
168161
----------
@@ -178,8 +171,7 @@ def getClipGeometries(eyeModel: object) -> list:
178171

179172

180173
def getEyeModelToPatientRotationMatrix(rotationXDeg: float, rotationYDeg: float, rotationZDeg: float) -> np.ndarray:
181-
"""
182-
Calculate the rotation matrix to transform from eye model coordinates to patient coordinates.
174+
"""Calculate the rotation matrix to transform from eye model coordinates to patient coordinates.
183175
184176
Parameters
185177
----------

pyrot/eye_modelling/datamodels/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
"""Data structures for eye models in RayOcular.
2+
3+
This package provides classes and functions to interact with eye models in RayOcular.
4+
"""
5+
16
from __future__ import annotations
27

38
from pyrot.eye_modelling.datamodels import export, models, validators

pyrot/eye_modelling/datamodels/export.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Export eye model geometries and regions of interest from RayOcular."""
2+
13
from __future__ import annotations
24

35
import json
@@ -24,8 +26,7 @@ def full_export(
2426
export_suffix: str,
2527
roi_export_unit: Literal["Millimeters", "Centimeters"],
2628
):
27-
"""
28-
Exports all relevant data for a given eye model to a structured output directory.
29+
"""Exports all relevant data for a given eye model to a structured output directory.
2930
This function gathers patient, case, and examination information, creates a uniquely named
3031
export directory, and exports ROI geometries, eye model data, and points of interest (POIs)
3132
for the specified eye model number.
@@ -95,10 +96,11 @@ def export_roi_geometries(
9596
export_suffix: str,
9697
roi_export_unit: str,
9798
):
98-
"""
99-
Exports ROI geometries from a given structure set to STL files.
100-
The function iterates over the ROI geometries in the provided structure set, filters them based on the specified export suffix,
101-
and exports each selected geometry as an STL file to the specified output directory. Exported files are named according to the ROI name,
99+
"""Exports ROI geometries from a given structure set to STL files.
100+
The function iterates over the ROI geometries in the provided structure set, filters them based on the specified
101+
export suffix,
102+
and exports each selected geometry as an STL file to the specified output directory. Exported files are named
103+
according to the ROI name,
102104
with spaces replaced by underscores, and include the export unit in the filename.
103105
104106
Parameters
@@ -168,8 +170,7 @@ def export_roi_geometries(
168170

169171

170172
def export_eye_model(structure_set, output_directory: Path, eyemodelnr: int):
171-
"""
172-
Export an eye model to a JSON file.
173+
"""Export an eye model to a JSON file.
173174
174175
Parameters
175176
----------
@@ -198,8 +199,7 @@ def export_eye_model(structure_set, output_directory: Path, eyemodelnr: int):
198199

199200

200201
def export_pois(structure_set, output_directory: Path, examination_name: str):
201-
"""
202-
Exports points of interest (POIs) from a structure set to a JSON file.
202+
"""Exports points of interest (POIs) from a structure set to a JSON file.
203203
204204
Parameters
205205
----------

0 commit comments

Comments
 (0)