Skip to content

Commit c3a9fd6

Browse files
committed
[CLN] Refactor color management to improve initialization
Removed redundant `ColorGenerator` attribute from `StructuralFrame` and streamlined color initialization using default `Field` values. Updated tests accordingly to reflect these changes.
1 parent 32f95d3 commit c3a9fd6

File tree

3 files changed

+14
-84
lines changed

3 files changed

+14
-84
lines changed

gempy/core/color_generator.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,16 @@
33
from typing import Optional
44

55
import numpy as np
6+
from pydantic import Field
67

78

89
@dataclass
910
class ColorsGenerator:
1011
"""
1112
Object that handles the color management.
1213
"""
13-
hex_colors: list[str]
14-
_index: int = 0
15-
16-
def __init__(self):
17-
self._gempy_default_colors = [
14+
15+
_gempy_default_colors = [
1816
'#015482', '#9f0052', '#ffbe00', '#728f02', '#443988',
1917
'#ff3f20', '#5DA629', '#b271d0', '#72e54a', '#583bd1',
2018
'#d0e63d', '#b949e2', '#95ce4b', '#6d2b9f', '#60eb91',
@@ -29,10 +27,16 @@ def __init__(self):
2927
'#945624', '#517c91', '#de8a68', '#3c4b64', '#9d8a4d',
3028
'#825f7e', '#2c3821', '#ddadaa', '#5e3524', '#a3a68e',
3129
'#a2706b', '#686d56'
32-
] # source: https://medialab.github.io/iwanthue/
33-
34-
self.regenerate_color_palette()
30+
] # source: https://medialab.github.io/iwanthue/
3531

32+
hex_colors: list[str] = Field(
33+
default=_gempy_default_colors,
34+
exclude=True
35+
)
36+
_index: int = 0
37+
38+
def __init__(self):
39+
self.regenerate_color_palette()
3640

3741
@staticmethod
3842
def _random_hexcolor() -> str:
@@ -50,19 +54,18 @@ def regenerate_color_palette(self, seaborn_palettes: Optional[list[str]] = None)
5054
hex_colors = []
5155
for palette in seaborn_palettes: # for each palette
5256
hex_colors += sns.color_palette(palette).as_hex() # get all colors in palette and add to list
53-
57+
5458
elif seaborn_palettes and not seaborn_installed:
5559
raise ImportError("Seaborn is not installed. Please install it to use color palettes.")
5660
else:
5761
hex_colors = list(self._gempy_default_colors)
5862

5963
self.hex_colors = hex_colors
6064

61-
6265
def __iter__(self) -> 'ColorsGenerator':
6366
"""Returns the object itself as an iterator."""
6467
return self
65-
68+
6669
def __next__(self) -> str:
6770
"""Generator that yields the next color."""
6871
color = self.up_next()

gempy/core/data/structural_frame.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ class StructuralFrame:
3232
"""
3333

3434
structural_groups: list[StructuralGroup]
35-
color_generator: ColorsGenerator
3635
# ? Should I create some sort of structural options class? For example, the masking descriptor and faults relations pointer
3736
is_dirty: bool = True
3837

test/test_modules/test_serialize_model.test_generate_horizontal_stratigraphic_model.verify/Horizontal Stratigraphic Model serialization.approved.txt

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -63,78 +63,6 @@
6363
"solution": null
6464
}
6565
],
66-
"color_generator": {
67-
"hex_colors": [
68-
"#015482",
69-
"#9f0052",
70-
"#ffbe00",
71-
"#728f02",
72-
"#443988",
73-
"#ff3f20",
74-
"#5DA629",
75-
"#b271d0",
76-
"#72e54a",
77-
"#583bd1",
78-
"#d0e63d",
79-
"#b949e2",
80-
"#95ce4b",
81-
"#6d2b9f",
82-
"#60eb91",
83-
"#d746be",
84-
"#52a22e",
85-
"#5e63d8",
86-
"#e5c339",
87-
"#371970",
88-
"#d3dc76",
89-
"#4d478e",
90-
"#43b665",
91-
"#d14897",
92-
"#59e5b8",
93-
"#e5421d",
94-
"#62dedb",
95-
"#df344e",
96-
"#9ce4a9",
97-
"#d94077",
98-
"#99c573",
99-
"#842f74",
100-
"#578131",
101-
"#708de7",
102-
"#df872f",
103-
"#5a73b1",
104-
"#ab912b",
105-
"#321f4d",
106-
"#e4bd7c",
107-
"#142932",
108-
"#cd4f30",
109-
"#69aedd",
110-
"#892a23",
111-
"#aad6de",
112-
"#5c1a34",
113-
"#cfddb4",
114-
"#381d29",
115-
"#5da37c",
116-
"#d8676e",
117-
"#52a2a3",
118-
"#9b405c",
119-
"#346542",
120-
"#de91c9",
121-
"#555719",
122-
"#bbaed6",
123-
"#945624",
124-
"#517c91",
125-
"#de8a68",
126-
"#3c4b64",
127-
"#9d8a4d",
128-
"#825f7e",
129-
"#2c3821",
130-
"#ddadaa",
131-
"#5e3524",
132-
"#a3a68e",
133-
"#a2706b",
134-
"#686d56"
135-
],
136-
"_index": 2
137-
},
13866
"is_dirty": true,
13967
"basement_color": "#ffbe00",
14068
"binary_meta_data": {

0 commit comments

Comments
 (0)