Skip to content

Commit

Permalink
rework dfn -> toml conversion
Browse files Browse the repository at this point in the history
TOML conversion as per group discussions and as prototyped in flopy3 in the Jinja PR.

This is a nested structure where components have blocks, which have variables, which may be composites of other variables.

Add the latest DFNs as well as the converted TOML files.

The structure is still tentative and may evolve.
  • Loading branch information
wpbonelli committed Dec 10, 2024
1 parent d1ac9ee commit 830426f
Show file tree
Hide file tree
Showing 275 changed files with 44,299 additions and 8,159 deletions.
12 changes: 3 additions & 9 deletions docs/examples/array_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,7 @@

fhandle = open(ilayered)
shape = (3, 1000, 100)
ilmfa = MFArray.load(
fhandle, data_path, shape, type=dtype, header=False, layered=True
)
ilmfa = MFArray.load(fhandle, data_path, shape, type=dtype, header=False, layered=True)
vals = ilmfa.value

ilmfa._value # internal storage
Expand Down Expand Up @@ -185,9 +183,7 @@

fhandle = open(clayered)
shape = (3, 1000, 100)
clmfa = MFArray.load(
fhandle, data_path, shape, type=dtype, header=False, layered=True
)
clmfa = MFArray.load(fhandle, data_path, shape, type=dtype, header=False, layered=True)

clmfa._value

Expand Down Expand Up @@ -240,9 +236,7 @@

fhandle = open(mlayered)
shape = (3, 1000, 100)
mlmfa = MFArray.load(
fhandle, data_path, shape, type=dtype, header=False, layered=True
)
mlmfa = MFArray.load(fhandle, data_path, shape, type=dtype, header=False, layered=True)

mlmfa.how

Expand Down
4 changes: 1 addition & 3 deletions docs/examples/attrs_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,4 @@ def output_control_data_hook(value, _) -> OutputControlData:
assert gwfoc.options.printhead.format == "scientific"
period = gwfoc.periods[0]
assert len(period) == 2
assert period[0] == OutputControlData.from_tuple(
("print", "budget", "steps", 1, 3, 5)
)
assert period[0] == OutputControlData.from_tuple(("print", "budget", "steps", 1, 3, 5))
10 changes: 3 additions & 7 deletions flopy4/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,7 @@ def __array_ufunc__(self, ufunc, method, *inputs, **kwargs):
if len(inputs) == 1:
result = raw.__array_ufunc__(ufunc, method, raw, **kwargs)
else:
result = raw.__array_ufunc__(
ufunc, method, raw, *inputs[1:], kwargs
)
result = raw.__array_ufunc__(ufunc, method, raw, *inputs[1:], kwargs)
if not isinstance(result, np.ndarray):
raise NotImplementedError(f"{str(ufunc)} has not been implemented")

Expand Down Expand Up @@ -299,8 +297,7 @@ def value(self, value: Optional[np.ndarray]):

if value.shape != self.shape:
raise ValueError(
f"Expected array with shape {self.shape},"
f"got shape {value.shape}"
f"Expected array with shape {self.shape}," f"got shape {value.shape}"
)
self._value = value

Expand Down Expand Up @@ -407,8 +404,7 @@ def write(self, f, **kwargs):
elif self._how == MFArrayType.external:
lines = (
f"{PAD}" + f"{self.name.upper()}\n"
f"{PAD*2}"
+ f"{MFArrayType.to_string(self._how)} {self._path}\n"
f"{PAD*2}" + f"{MFArrayType.to_string(self._how)} {self._path}\n"
)
elif self._how == MFArrayType.constant:
lines = (
Expand Down
12 changes: 3 additions & 9 deletions flopy4/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ def __new__(cls, clsname, bases, attrs):

# infer block name
block_name = (
clsname[list(find_upper(clsname))[1] :]
.replace("Block", "")
.lower()
clsname[list(find_upper(clsname))[1] :].replace("Block", "").lower()
)

# collect parameters
Expand Down Expand Up @@ -314,9 +312,7 @@ def __repr__(self):
def __eq__(self, other):
if not isinstance(other, MFBlocks):
raise TypeError(f"Expected MFBlocks, got {type(other)}")
return OrderedDict(sorted(self.value)) == OrderedDict(
sorted(other.value)
)
return OrderedDict(sorted(self.value)) == OrderedDict(sorted(other.value))

@staticmethod
def assert_blocks(blocks):
Expand All @@ -329,9 +325,7 @@ def assert_blocks(blocks):
elif isinstance(blocks, dict):
blocks = blocks.values()
not_blocks = [
b
for b in blocks
if b is not None and not issubclass(type(b), MFBlock)
b for b in blocks if b is not None and not issubclass(type(b), MFBlock)
]
if any(not_blocks):
raise TypeError(f"Expected MFBlock subclasses, got {not_blocks}")
Expand Down
4 changes: 1 addition & 3 deletions flopy4/compound.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ def params(self) -> MFParams:
@property
def value(self) -> Dict[str, Any]:
"""Get component names/values."""
return {
k: s.value for k, s in self.data.items() if s.value is not None
}
return {k: s.value for k, s in self.data.items() if s.value is not None}

@value.setter
def value(self, value: Optional[Dict[str, Any]]):
Expand Down
Loading

0 comments on commit 830426f

Please sign in to comment.