Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[ENH] Ensure unique basement color and improve serialization
Introduce a method to allocate a unique basement color, avoiding duplication among structural elements. Minor enhancements include improved serialization output and cleanup of redundant or commented-out code.
  • Loading branch information
Leguark committed May 26, 2025
commit 39e7b2e61a46d6563c2a156c894af23e883e3528
26 changes: 18 additions & 8 deletions gempy/core/data/structural_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class StructuralFrame:

structural_groups: list[StructuralGroup]
color_generator: ColorsGenerator = Field(default_factory=ColorsGenerator)
basement_color: str = None
# ? Should I create some sort of structural options class? For example, the masking descriptor and faults relations pointer
is_dirty: bool = True

Expand All @@ -41,6 +42,9 @@ class StructuralFrame:
def __init__(self, structural_groups: list[StructuralGroup], color_gen: ColorsGenerator):
self.structural_groups = structural_groups # ? This maybe could be optional
self.color_generator = color_gen

def __post_init__(self):
pass

@classmethod
def from_data_tables(cls, surface_points: SurfacePointsTable, orientations: OrientationsTable):
Expand Down Expand Up @@ -203,22 +207,28 @@ def n_elements(self) -> int:
"""Returns the total number of elements in the structural frame."""
return len(self.structural_elements)

basement_color: str = None

@property
def _basement_element(self) -> StructuralElement:
# Check if the basement color is already defined
"""Returns the basement structural element with a unique color."""

def _get_unique_basement_color(color_generator: ColorsGenerator, used_colors: list[str]) -> str:
color = next(color_generator)
if color in used_colors:
return _get_unique_basement_color(color_generator, used_colors)
return color

elements = []
for group in self.structural_groups:
elements.extend(group.elements)
basement_color_in_elements = self.basement_color in [element.color for element in elements]

if self.basement_color is None or basement_color_in_elements:
self.basement_color = self.color_generator.up_next()
used_colors = [element.color for element in elements]

if basement_color_in_elements:
warnings.warn(f"The basement color was already used in the structural elements."
f"Changing the basement color to {self.basement_color}.")
if self.basement_color is None or self.basement_color in used_colors:
self.basement_color = _get_unique_basement_color(
color_generator=self.color_generator,
used_colors=used_colors
)

basement = StructuralElement(
name="basement",
Expand Down
1 change: 0 additions & 1 deletion gempy/modules/serialization/save_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ def make_info(name):
return buf.getvalue()

def _load_model_from_bytes(data: bytes) -> GeoModel:
import json, zlib
from ...core.data.encoders.converters import loading_model_from_binary

buf = io.BytesIO(data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,11 @@
"solution": null
}
],
"is_dirty": true,
"color_generator": {
"_index": 2
},
"basement_color": "#ffbe00",
"is_dirty": true,
"binary_meta_data": {
"sp_binary_length": 432,
"ori_binary_length": 120
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ def test_optimize_nugget_effect():
validate_serialization=True
)

# TODO: Save model

print(f"Final cond number: {geo_model.interpolation_options.kernel_options.condition_number}")
nugget_effect = geo_model.taped_interpolation_input.surface_points.nugget_effect_scalar.detach().numpy()

Expand Down