Skip to content

Commit 89a3c5f

Browse files
authored
docs: copilot review/update of docstrings to numpy format (#273)
1 parent 49a24d2 commit 89a3c5f

File tree

11 files changed

+834
-149
lines changed

11 files changed

+834
-149
lines changed

LoopStructural/__init__.py

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,21 @@
2323
loggers = {}
2424
@dataclass
2525
class LoopStructuralConfig:
26-
"""
27-
Configuration for LoopStructural
26+
"""Configuration for LoopStructural package.
27+
28+
This dataclass holds configuration parameters for the LoopStructural
29+
geological modelling package.
30+
31+
Parameters
32+
----------
33+
nelements : int, optional
34+
The default number of elements to use in interpolation, by default 10_000
35+
36+
Examples
37+
--------
38+
>>> config = LoopStructuralConfig(nelements=50000)
39+
>>> config.nelements
40+
50000
2841
"""
2942

3043
nelements: int = 10_000
@@ -42,15 +55,21 @@ class LoopStructuralConfig:
4255

4356

4457
def setLogging(level="info", handler=None):
45-
"""
46-
Set the logging parameters for log file or custom handler
58+
"""Set the logging parameters for log file or custom handler.
4759
4860
Parameters
4961
----------
50-
level : str
51-
'info', 'warning', 'error', 'debug'
62+
level : str, optional
63+
Logging level to set, by default "info"
64+
Valid options: 'info', 'warning', 'error', 'debug'
5265
handler : logging.Handler, optional
53-
A logging handler to use instead of the default StreamHandler
66+
A logging handler to use instead of the default StreamHandler, by default None
67+
68+
Examples
69+
--------
70+
>>> import LoopStructural
71+
>>> LoopStructural.setLogging('debug')
72+
>>> LoopStructural.setLogging('info', logging.FileHandler('loop.log'))
5473
"""
5574
import LoopStructural
5675

LoopStructural/datatypes/_bounding_box.py

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,24 @@ def __init__(
102102

103103
@property
104104
def global_origin(self):
105+
"""Get the global origin of the bounding box.
106+
107+
Returns
108+
-------
109+
np.ndarray
110+
The global origin coordinates
111+
"""
105112
return self._global_origin
106113

107114
@global_origin.setter
108115
def global_origin(self, global_origin):
116+
"""Set the global origin of the bounding box.
117+
118+
Parameters
119+
----------
120+
global_origin : array_like
121+
The global origin coordinates
122+
"""
109123
if self.dimensions != len(global_origin):
110124
logger.warning(
111125
f"Global origin has {len(global_origin)} dimensions but bounding box has {self.dimensions}"
@@ -114,20 +128,53 @@ def global_origin(self, global_origin):
114128

115129
@property
116130
def global_maximum(self):
131+
"""Get the global maximum coordinates of the bounding box.
132+
133+
Returns
134+
-------
135+
np.ndarray
136+
The global maximum coordinates (local maximum + global origin)
137+
"""
117138
return self.maximum + self.global_origin
118139

119140
@property
120141
def valid(self):
142+
"""Check if the bounding box has valid origin and maximum values.
143+
144+
Returns
145+
-------
146+
bool
147+
True if both origin and maximum are set, False otherwise
148+
"""
121149
return self._origin is not None and self._maximum is not None
122150

123151
@property
124152
def origin(self) -> np.ndarray:
153+
"""Get the origin coordinates of the bounding box.
154+
155+
Returns
156+
-------
157+
np.ndarray
158+
Origin coordinates
159+
160+
Raises
161+
------
162+
LoopValueError
163+
If the origin is not set
164+
"""
125165
if self._origin is None:
126166
raise LoopValueError("Origin is not set")
127167
return self._origin
128168

129169
@origin.setter
130170
def origin(self, origin: np.ndarray):
171+
"""Set the origin coordinates of the bounding box.
172+
173+
Parameters
174+
----------
175+
origin : np.ndarray
176+
Origin coordinates
177+
"""
131178
if self.dimensions != len(origin):
132179
logger.warning(
133180
f"Origin has {len(origin)} dimensions but bounding box has {self.dimensions}"
@@ -136,24 +183,64 @@ def origin(self, origin: np.ndarray):
136183

137184
@property
138185
def maximum(self) -> np.ndarray:
186+
"""Get the maximum coordinates of the bounding box.
187+
188+
Returns
189+
-------
190+
np.ndarray
191+
Maximum coordinates
192+
193+
Raises
194+
------
195+
LoopValueError
196+
If the maximum is not set
197+
"""
139198
if self._maximum is None:
140199
raise LoopValueError("Maximum is not set")
141200
return self._maximum
142201

143202
@maximum.setter
144203
def maximum(self, maximum: np.ndarray):
204+
"""Set the maximum coordinates of the bounding box.
205+
206+
Parameters
207+
----------
208+
maximum : np.ndarray
209+
Maximum coordinates
210+
"""
145211
self._maximum = maximum
146212

147213
@property
148214
def nelements(self):
215+
"""Get the total number of elements in the bounding box.
216+
217+
Returns
218+
-------
219+
int
220+
Total number of elements (product of nsteps)
221+
"""
149222
return self.nsteps.prod()
150223

151224
@property
152225
def volume(self):
226+
"""Calculate the volume of the bounding box.
227+
228+
Returns
229+
-------
230+
float
231+
Volume of the bounding box
232+
"""
153233
return np.prod(self.maximum - self.origin)
154234

155235
@property
156236
def bb(self):
237+
"""Get a numpy array containing origin and maximum coordinates.
238+
239+
Returns
240+
-------
241+
np.ndarray
242+
Array with shape (2, n_dimensions) containing [origin, maximum]
243+
"""
157244
return np.array([self.origin, self.maximum])
158245

159246

LoopStructural/datatypes/_structured_grid.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,26 @@
88

99
@dataclass
1010
class StructuredGrid:
11+
"""A structured grid for storing 3D geological data.
12+
13+
This class represents a regular 3D grid with properties and cell properties
14+
that can be used for geological modelling and visualisation.
15+
16+
Parameters
17+
----------
18+
origin : np.ndarray, optional
19+
Origin point of the grid, by default [0, 0, 0]
20+
step_vector : np.ndarray, optional
21+
Step size in each direction, by default [1, 1, 1]
22+
nsteps : np.ndarray, optional
23+
Number of steps in each direction, by default [10, 10, 10]
24+
cell_properties : Dict[str, np.ndarray], optional
25+
Properties defined at cell centres, by default empty dict
26+
properties : Dict[str, np.ndarray], optional
27+
Properties defined at grid nodes, by default empty dict
28+
name : str, optional
29+
Name of the grid, by default "default_grid"
30+
"""
1131
origin: np.ndarray = field(default_factory=lambda: np.array([0, 0, 0]))
1232
step_vector: np.ndarray = field(default_factory=lambda: np.array([1, 1, 1]))
1333
nsteps: np.ndarray = field(default_factory=lambda: np.array([10, 10, 10]))
@@ -16,6 +36,13 @@ class StructuredGrid:
1636
name: str = "default_grid"
1737

1838
def to_dict(self):
39+
"""Convert the structured grid to a dictionary representation.
40+
41+
Returns
42+
-------
43+
dict
44+
Dictionary containing all grid properties and metadata
45+
"""
1946
return {
2047
"origin": self.origin,
2148
"maximum": self.maximum,
@@ -28,9 +55,28 @@ def to_dict(self):
2855

2956
@property
3057
def maximum(self):
58+
"""Calculate the maximum coordinates of the grid.
59+
60+
Returns
61+
-------
62+
np.ndarray
63+
Maximum coordinates (origin + nsteps * step_vector)
64+
"""
3165
return self.origin + self.nsteps * self.step_vector
3266

3367
def vtk(self):
68+
"""Convert the structured grid to a PyVista RectilinearGrid.
69+
70+
Returns
71+
-------
72+
pv.RectilinearGrid
73+
PyVista grid object with all properties attached
74+
75+
Raises
76+
------
77+
ImportError
78+
If PyVista is not installed
79+
"""
3480
try:
3581
import pyvista as pv
3682
except ImportError:
@@ -65,6 +111,13 @@ def plot(self, pyvista_kwargs={}):
65111

66112
@property
67113
def cell_centres(self):
114+
"""Calculate the coordinates of cell centres.
115+
116+
Returns
117+
-------
118+
tuple of np.ndarray
119+
X, Y, Z coordinates of all cell centres
120+
"""
68121
x = np.linspace(
69122
self.origin[0] + self.step_vector[0] * 0.5,
70123
self.maximum[0] + self.step_vector[0] * 0.5,

LoopStructural/interpolators/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
"""
2-
Interpolators and interpolation supports
1+
"""Interpolators and interpolation supports for LoopStructural.
32
3+
This module provides various interpolation methods and support structures
4+
for geological modelling, including finite difference, piecewise linear,
5+
and radial basis function interpolators.
46
"""
57

68

0 commit comments

Comments
 (0)