Skip to content

Commit 0b2ac49

Browse files
Copilotlachlangrose
andcommitted
Phase 4 partial: Enhanced modeling framework with numpy docstrings
Co-authored-by: lachlangrose <7371904+lachlangrose@users.noreply.github.com>
1 parent 6b851ca commit 0b2ac49

3 files changed

Lines changed: 257 additions & 74 deletions

File tree

LoopStructural/interpolators/_interpolator_builder.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,6 @@ def add_gradient_constraints(self, gradient_constraints: np.ndarray) -> 'Interpo
7777
bool
7878
True if constraints were added successfully
7979
"""
80-
InterpolatorBuilder
81-
reference to the builder
82-
"""
8380

8481
if self.interpolator:
8582
self.interpolator.set_gradient_constraints(gradient_constraints)

LoopStructural/modelling/core/stratigraphic_column.py

Lines changed: 209 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,59 @@
55
logger = getLogger(__name__)
66
logger.info("Imported LoopStructural Stratigraphic Column module")
77
class UnconformityType(enum.Enum):
8-
"""
9-
An enumeration for different types of unconformities in a stratigraphic column.
8+
"""Enumeration for different types of unconformities in a stratigraphic column.
9+
10+
Attributes
11+
----------
12+
ERODE : str
13+
Erosional unconformity type
14+
ONLAP : str
15+
Onlap unconformity type
1016
"""
1117

1218
ERODE = 'erode'
1319
ONLAP = 'onlap'
1420

1521

1622
class StratigraphicColumnElementType(enum.Enum):
17-
"""
18-
An enumeration for different types of elements in a stratigraphic column.
23+
"""Enumeration for different types of elements in a stratigraphic column.
24+
25+
Attributes
26+
----------
27+
UNIT : str
28+
Stratigraphic unit element type
29+
UNCONFORMITY : str
30+
Unconformity element type
1931
"""
2032

2133
UNIT = 'unit'
2234
UNCONFORMITY = 'unconformity'
2335

2436

2537
class StratigraphicColumnElement:
26-
"""
27-
A class to represent an element in a stratigraphic column, which can be a unit or a topological object
28-
for example unconformity.
38+
"""Base class for elements in a stratigraphic column.
39+
40+
This class represents a generic element that can be either a stratigraphic unit
41+
or a topological object such as an unconformity.
42+
43+
Parameters
44+
----------
45+
uuid : str, optional
46+
Unique identifier for the element. If None, a UUID4 is generated, by default None
47+
48+
Attributes
49+
----------
50+
uuid : str
51+
Unique identifier for the element
2952
"""
3053

3154
def __init__(self, uuid=None):
32-
"""
33-
Initializes the StratigraphicColumnElement with a uuid.
55+
"""Initialize the StratigraphicColumnElement with a UUID.
56+
57+
Parameters
58+
----------
59+
uuid : str, optional
60+
Unique identifier for the element. If None, a UUID4 is generated, by default None
3461
"""
3562
if uuid is None:
3663
import uuid as uuid_module
@@ -40,13 +67,53 @@ def __init__(self, uuid=None):
4067

4168

4269
class StratigraphicUnit(StratigraphicColumnElement, Observable['StratigraphicUnit']):
43-
"""
44-
A class to represent a stratigraphic unit.
70+
"""A class representing a stratigraphic unit in the geological column.
71+
72+
This class combines the basic element functionality with observable capabilities
73+
to track changes to unit properties such as thickness and ID.
74+
75+
Parameters
76+
----------
77+
uuid : str, optional
78+
Unique identifier for the unit, by default None
79+
name : str, optional
80+
Human-readable name for the unit, by default None
81+
colour : array_like, optional
82+
RGB colour values for visualization. If None, random colour is assigned, by default None
83+
thickness : float, optional
84+
Thickness of the unit, by default None
85+
data : dict, optional
86+
Additional data associated with the unit, by default None
87+
id : int, optional
88+
Numeric identifier for the unit, by default None
89+
90+
Attributes
91+
----------
92+
element_type : StratigraphicColumnElementType
93+
Type of the element (always UNIT for this class)
94+
min_value : float
95+
Minimum scalar field value for the unit
96+
max_value : float
97+
Maximum scalar field value for the unit
4598
"""
4699

47100
def __init__(self, *, uuid=None, name=None, colour=None, thickness=None, data=None, id=None):
48-
"""
49-
Initializes the StratigraphicUnit with a name and an optional description.
101+
"""Initialize the StratigraphicUnit.
102+
103+
Parameters
104+
----------
105+
uuid : str, optional
106+
Unique identifier for the unit, by default None
107+
name : str, optional
108+
Human-readable name for the unit, by default None
109+
colour : array_like, optional
110+
RGB colour values for visualization. If None, random colour is assigned, by default None
111+
thickness : float, optional
112+
Thickness of the unit, by default None
113+
data : dict, optional
114+
Additional data associated with the unit, by default None
115+
id : int, optional
116+
Numeric identifier for the unit, by default None
50117
"""
51118
StratigraphicColumnElement.__init__(self, uuid)
52119
Observable.__init__(self)
@@ -62,39 +129,78 @@ def __init__(self, *, uuid=None, name=None, colour=None, thickness=None, data=No
62129
self.max_value = None # Maximum scalar field value for the unit
63130
@property
64131
def id(self):
132+
"""Get the numeric identifier of the unit.
133+
134+
Returns
135+
-------
136+
int
137+
The numeric identifier
138+
"""
65139
return self._id
140+
66141
@property
67142
def thickness(self):
143+
"""Get the thickness of the unit.
144+
145+
Returns
146+
-------
147+
float
148+
The thickness value
149+
"""
68150
return self._thickness
151+
69152
@thickness.setter
70153
def thickness(self, value):
71-
"""
72-
Sets the thickness of the unit.
154+
"""Set the thickness of the unit and notify observers.
155+
156+
Parameters
157+
----------
158+
value : float
159+
The new thickness value
73160
"""
74161
self._thickness = value
75162
self.notify('unit/thickness_updated', unit=self)
163+
76164
@id.setter
77165
def id(self, value):
78-
"""
79-
Sets the ID of the unit.
166+
"""Set the ID of the unit and notify observers.
167+
168+
Parameters
169+
----------
170+
value : int
171+
The new ID value
80172
"""
81173
if not isinstance(value, int):
82174
raise TypeError("ID must be an integer")
83175
self._id = value
84176
self.notify('unit/id_updated', unit=self)
85177
def min(self):
86-
"""
87-
Returns the minimum value of the unit.
178+
"""Return the minimum scalar field value of the unit.
179+
180+
Returns
181+
-------
182+
float
183+
Minimum value, or 0 if not set
88184
"""
89185
return self.min_value if self.min_value is not None else 0
186+
90187
def max(self):
91-
"""
92-
Returns the maximum value of the unit.
188+
"""Return the maximum scalar field value of the unit.
189+
190+
Returns
191+
-------
192+
float
193+
Maximum value, or infinity if not set
93194
"""
94195
return self.max_value if self.max_value is not None else np.inf
196+
95197
def to_dict(self):
96-
"""
97-
Converts the stratigraphic unit to a dictionary representation.
198+
"""Convert the stratigraphic unit to a dictionary representation.
199+
200+
Returns
201+
-------
202+
dict
203+
Dictionary containing unit properties: name, colour, thickness, uuid, and id
98204
"""
99205
colour = self.colour
100206
if isinstance(colour, np.ndarray):
@@ -103,8 +209,22 @@ def to_dict(self):
103209

104210
@classmethod
105211
def from_dict(cls, data):
106-
"""
107-
Creates a StratigraphicUnit from a dictionary representation.
212+
"""Create a StratigraphicUnit from a dictionary representation.
213+
214+
Parameters
215+
----------
216+
data : dict
217+
Dictionary containing unit properties
218+
219+
Returns
220+
-------
221+
StratigraphicUnit
222+
New stratigraphic unit instance
223+
224+
Raises
225+
------
226+
TypeError
227+
If data is not a dictionary
108228
"""
109229
if not isinstance(data, dict):
110230
raise TypeError("Data must be a dictionary")
@@ -115,8 +235,12 @@ def from_dict(cls, data):
115235
return cls(uuid=uuid, name=name, colour=colour, thickness=thickness, id=data.get("id", None))
116236

117237
def __str__(self):
118-
"""
119-
Returns a string representation of the stratigraphic unit.
238+
"""Return a string representation of the stratigraphic unit.
239+
240+
Returns
241+
-------
242+
str
243+
String representation showing name, colour, and thickness
120244
"""
121245
return (
122246
f"StratigraphicUnit(name={self.name}, colour={self.colour}, thickness={self.thickness})"
@@ -175,49 +299,92 @@ def from_dict(cls, data):
175299
uuid = data.get("uuid", None)
176300
return cls(uuid=uuid, name=name, unconformity_type=unconformity_type)
177301
class StratigraphicGroup:
178-
"""
179-
A class to represent a group of stratigraphic units.
180-
This class is not fully implemented and serves as a placeholder for future development.
302+
"""A class representing a group of stratigraphic units.
303+
304+
This class serves as a container for related stratigraphic units and provides
305+
a placeholder for future group-level functionality.
306+
307+
Parameters
308+
----------
309+
name : str, optional
310+
Name of the stratigraphic group, by default None
311+
units : list, optional
312+
List of stratigraphic units in the group, by default None
313+
314+
Attributes
315+
----------
316+
name : str
317+
Name of the group
318+
units : list
319+
List of units contained in the group
181320
"""
182321

183322
def __init__(self, name=None, units=None):
184-
"""
185-
Initializes the StratigraphicGroup with a name and an optional list of units.
323+
"""Initialize the StratigraphicGroup.
324+
325+
Parameters
326+
----------
327+
name : str, optional
328+
Name of the stratigraphic group, by default None
329+
units : list, optional
330+
List of stratigraphic units in the group, by default None
186331
"""
187332
self.name = name
188333
self.units = units if units is not None else []
189334

190335

191336
class StratigraphicColumn(Observable['StratigraphicColumn']):
192-
"""
193-
A class to represent a stratigraphic column, which is a vertical section of the Earth's crust
194-
showing the sequence of rock layers and their relationships.
337+
"""A class representing a stratigraphic column.
338+
339+
The stratigraphic column represents a vertical section of the Earth's crust
340+
showing the sequence of rock layers and their relationships, including
341+
unconformities and basement rock.
342+
343+
Attributes
344+
----------
345+
order : list
346+
Ordered list of stratigraphic elements (units and unconformities)
347+
group_mapping : dict
348+
Mapping of groups to their constituent units
195349
"""
196350

197351
def __init__(self):
198-
"""
199-
Initializes the StratigraphicColumn with a name and a list of layers.
200-
"""
352+
"""Initialize the StratigraphicColumn with basement and base unconformity."""
201353
super().__init__()
202354
self.order = []
203355
self.add_basement()
204356
self.group_mapping = {}
205357

206358
def get_new_id(self):
207-
"""
208-
Generates a new unique ID for a stratigraphic unit.
359+
"""Generate a new unique ID for a stratigraphic unit.
360+
361+
Returns
362+
-------
363+
int
364+
New unique ID for the next unit
209365
"""
210366
if not self.order:
211367
return 0
212368
return max([u.id for u in self.order if isinstance(u, StratigraphicUnit)], default=0) + 1
369+
213370
def add_basement(self):
371+
"""Add basement unit and base unconformity to the stratigraphic column.
372+
373+
This method adds the fundamental basement unit with infinite thickness
374+
and an erosional unconformity at the base of the column.
375+
"""
214376
self.add_unit(name='Basement', colour='grey', thickness=np.inf)
215377
self.add_unconformity(
216378
name='Base Unconformity', unconformity_type=UnconformityType.ERODE
217379
)
380+
218381
def clear(self, basement=True):
219-
"""
220-
Clears the stratigraphic column, removing all elements.
382+
"""Clear the stratigraphic column, removing all elements.
383+
384+
Parameters
385+
----------
386+
basement : bool, optional
387+
Whether to add basement after clearing, by default True
221388
"""
222389
if basement:
223390
self.add_basement()

0 commit comments

Comments
 (0)