Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jcrivenaes committed Oct 4, 2023
1 parent 658d1a6 commit d3d5471
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 29 deletions.
51 changes: 26 additions & 25 deletions src/xtgeo/well/well1.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,6 @@ class Well:
defaults to None.
"""

VALID_LOGTYPES = {"DISC", "CONT"}

@_well_aux.allow_deprecated_init
def __init__(
self,
Expand Down Expand Up @@ -706,7 +704,7 @@ def get_wlogs(self) -> dict:
wtype = "CONT"
wrecord = None
if key in self._wdata.attr_types:
wtype = self._wdata.attr_types[key]
wtype = self._wdata.attr_types[key].name
if key in self._wdata.attr_records:
wrecord = self._wdata.attr_records[key]

Expand Down Expand Up @@ -734,28 +732,31 @@ def set_wlogs(self, wlogs: dict):
for key in self.get_lognames():
if key in wlogs.keys():
typ, rec = wlogs[key]

if typ in Well.VALID_LOGTYPES:
# self._wlogtypes[key] = deepcopy(typ)
self._wdata.set_attr_type(key, deepcopy(typ))
else:
raise ValueError(f"Invalid log type found in input: {typ}")

if isinstance(rec, dict):
self._wdata.set_attr_record(key, deepcopy(rec))
# self._wlogrecords[key] = deepcopy(rec)
elif not rec:
self._wdata.set_attr_record(key, ("", ""))
# self._wlogrecords[key] = ""
else:
raise ValueError(f"Invalid log record found in input: {rec}")

else:
raise ValueError(f"Key for column not found in input: {key}")

for key in wlogs.keys():
if key not in self.get_lognames():
raise ValueError(f"Invalid input key found: {key}")
self._wdata.set_attr_type(key, typ)
self._wdata.set_attr_record(key, deepcopy(rec))

# if typ in ("DISC", "CONT"):
# self._wdata.set_attr_type(key, typ)
# else:
# raise ValueError(f"Invalid log type found in input: {typ}")

# if isinstance(rec, dict) and typ == "CONT":
# self._wdata.set_attr_record(key, deepcopy(rec))
# # self._wlogrecords[key] = deepcopy(rec)
# elif isinstance(rec, (list, tuple)) and typ == "DISC":
# self._wdata.set_attr_record(key, deepcopy(rec))
# elif not rec:
# self._wdata.set_attr_record(key, ("", ""))
# # self._wlogrecords[key] = ""
# else:
# raise ValueError(f"Invalid log record found in input: {rec}")

# else:
# raise ValueError(f"Key for column not found in input: {key}")

# for key in wlogs.keys():
# if key not in self.get_lognames():
# raise ValueError(f"Invalid input key found: {key}")

self._ensure_consistency()

Expand Down
7 changes: 5 additions & 2 deletions src/xtgeo/xyz_common/_xyz_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,13 +312,16 @@ def get_attr_record(self, name: str):
"""Get a record for a named attribute."""
return self._attr_records[name]

def set_attr_record(self, name: str, record: dict) -> None:
def set_attr_record(self, name: str, record: Optional[dict]) -> None:
"""Set a record for a named log."""

if name not in self._attr_types:
raise ValueError(f"No such attr_name: {name}")

print("XXXXXXX", self._attr_types[name])
if record is None and self._attr_types[name] == _AttrType.DISC:
record = {}
elif record is None and self._attr_types[name] == _AttrType.CONT:
record = CONT_DEFAULT_RECORD

if self._attr_types[name] == _AttrType.CONT and isinstance(
record, (list, tuple)
Expand Down
15 changes: 13 additions & 2 deletions tests/test_well/test_well.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,18 @@ def test_create_and_delete_logs_implicit(loadwell3):
# assert ndeleted == 2


def test_wlogtypes(loadwell3):
mywell = loadwell3
wlogtypes = mywell.wlogtypes
assert wlogtypes == {
"X_UTME": "CONT",
"Y_UTMN": "CONT",
"Z_TVDSS": "CONT",
"GR": "CONT",
"ZONELOG": "DISC",
}


def test_get_set_wlogs(loadwell3):
"""Test on getting ans setting a dictionary with some log attributes."""
mywell = loadwell3
Expand All @@ -364,8 +376,7 @@ def test_get_set_wlogs(loadwell3):
assert mydict2["ZONELOG"][1][24] == "ZONE_24_EDITED"

mydict2["EXTRA"] = None
with pytest.raises(ValueError):
mywell.set_wlogs(mydict2)
mywell.set_wlogs(mydict2)


def test_make_hlen(loadwell1):
Expand Down

0 comments on commit d3d5471

Please sign in to comment.