Skip to content
Merged
11 changes: 7 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ repos:
types_or: [python, pyi, jupyter]
additional_dependencies: [".[jupyter]"]

- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
- repo: https://github.com/pycqa/flake8
rev: 4.0.1
hooks:
- id: flake8
# additional_dependencies: [flake8-bugbear]
- id: flake8
additional_dependencies:
- flake8-bugbear
- flake8-comprehensions
- flake8-simplify

- repo: https://gitlab.com/iamlikeme/nbhooks
rev: 1.0.0
Expand Down
4 changes: 4 additions & 0 deletions news/71.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

Changed the :class:`~sequence.sediment_flexure.SedimentFlexure` component so
that it is no longer dependent on the ordering of components. It has been
simplified so that it now takes sediment loading as its only input field.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ pyyaml
rich-click
scipy
tomlkit
tqdm
36 changes: 18 additions & 18 deletions sequence/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import pathlib
import re
from contextlib import suppress
from io import StringIO
from os import PathLike
from typing import Any, Iterable, Iterator, Optional, Union
Expand Down Expand Up @@ -91,11 +92,13 @@ def as_csv(data: ArrayLike, header: str = "") -> str:
contents = {
"sequence.yaml": yaml.dump(params, default_flow_style=False),
"sequence.toml": toml.dumps(
dict(
sequence=dict(
_time=0.0, processes=SequenceModel.ALL_PROCESSES, **params
)
)
{
"sequence": {
"_time": 0.0,
"processes": SequenceModel.ALL_PROCESSES,
**params,
}
}
),
"bathymetry.csv": as_csv(
[[0.0, 20.0], [100000.0, -80.0]], header="X [m], Elevation [m]"
Expand All @@ -122,7 +125,7 @@ def as_csv(data: ArrayLike, header: str = "") -> str:
return contents[str(infile)]


def _time_from_filename(name: Union[str, PathLike[str]]) -> Union[int, None]:
def _time_from_filename(name: Union[str, PathLike[str]]) -> Optional[int]:
"""Parse a time stamp from a file name.

Parameters
Expand Down Expand Up @@ -299,14 +302,11 @@ def run(ctx: Any, with_citations: bool, dry_run: bool) -> None:
disable=True if silent else None,
)

try:
with progressbar as bar:
while 1:
model.run_one_step()
model.set_params(params.update(1))
bar.update(1)
except StopIteration:
pass
with suppress(StopIteration), progressbar as bar:
while 1:
model.run_one_step()
model.set_params(params.update(1))
bar.update(1)

if verbose and not silent:
total = sum(model.timer.values())
Expand Down Expand Up @@ -394,7 +394,7 @@ def plot(ctx: Any, set: str) -> None:
config.update(
TimeVaryingConfig.from_file(folder / "sequence.toml")
.as_dict()
.get("plot", dict())
.get("plot", {})
)

config.update(**_load_params_from_strings(set))
Expand All @@ -403,8 +403,8 @@ def plot(ctx: Any, set: str) -> None:
logger.info(
os.linesep.join(
[
"Reading configuration\n",
toml.dumps(dict(sequence=dict(plot=config))),
"Reading configuration",
toml.dumps({"sequence": {"plot": config}}),
]
)
)
Expand Down Expand Up @@ -471,7 +471,7 @@ def _walk_dict(indict: Union[dict, Any], prev: Optional[list] = None) -> Iterato
for key, value in indict.items():
if isinstance(value, dict):
yield from _walk_dict(value, [key] + prev)
elif isinstance(value, list) or isinstance(value, tuple):
elif isinstance(value, (list, tuple)):
yield prev + [key, value]
else:
yield prev + [key, value]
Expand Down
8 changes: 4 additions & 4 deletions sequence/input_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def dump(self, fmt: str = "toml") -> str:
doc["_time"] = time

if fmt == "toml":
return toml.dumps(dict(sequence=docs))
return toml.dumps({"sequence": docs})
elif fmt == "yaml":
return yaml.dump(docs, default_flow_style=False)
else:
Expand Down Expand Up @@ -276,9 +276,9 @@ def load_toml(stream: TextIO) -> list[tuple[float, dict]]:
The configurations and their associated times.
"""

def _tomlkit_to_popo(d: dict) -> Any:
def _tomlkit_to_popo(d: Any) -> Any:
try:
result = getattr(d, "value")
result = d.value
except AttributeError:
result = d

Expand Down Expand Up @@ -446,7 +446,7 @@ def _walk_dict(
for key, value in indict.items():
if isinstance(value, dict):
yield from _walk_dict(value, prev_dicts + [key])
elif isinstance(value, list) or isinstance(value, tuple):
elif isinstance(value, (list, tuple)):
yield tuple(prev_dicts + [key]), value
else:
yield tuple(prev_dicts + [key]), value
Expand Down
2 changes: 1 addition & 1 deletion sequence/netcdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def to_netcdf(
at: Optional[Union[str, Sequence[str]]] = None,
ids: Optional[Union[dict[str, Iterable[int]], int, Iterable[int], slice]] = None,
names: Optional[
Union[dict[str, Union[Iterable[str], None]], str, Iterable[str]]
Union[dict[str, Optional[Iterable[str]]], str, Iterable[str]]
] = None,
with_layers: bool = True,
) -> None:
Expand Down
6 changes: 3 additions & 3 deletions sequence/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def plot_file(filename: Union[str, PathLike], **kwds: Any) -> None:
)


def _get_layers_to_plot(start: int, stop: int, num: int = -1) -> Union[slice, None]:
def _get_layers_to_plot(start: int, stop: int, num: int = -1) -> Optional[slice]:
if num == 0:
return None
elif num < 0 or num > stop - start + 1:
Expand Down Expand Up @@ -292,8 +292,8 @@ def _outline_layer(
x: NDArray,
y_of_bottom_layer: NDArray,
y_of_top_layer: NDArray,
bottom_limits: Optional[tuple[Union[float, None], Union[float, None]]] = None,
top_limits: Optional[tuple[Union[float, None], Union[float, None]]] = None,
bottom_limits: Optional[tuple[Optional[float], Optional[float]]] = None,
top_limits: Optional[tuple[Optional[float], Optional[float]]] = None,
) -> tuple[NDArray, NDArray]:
if bottom_limits is None:
bottom_limits = (None, None)
Expand Down
Loading