Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 8 additions & 4 deletions src/pyfabm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

# typing.Final not available in Python 3.7
from typing import Any

try:
from typing import Final, SupportsIndex
except ImportError:
Expand All @@ -42,7 +43,6 @@
sys.exit(1)
import numpy.typing as npt


LOG_CALLBACK = ctypes.CFUNCTYPE(None, ctypes.c_char_p)


Expand Down Expand Up @@ -1068,7 +1068,7 @@ def __init__(self, model: "Model", name: str):
class Model(object):
def __init__(
self,
path: Union[str, dict] = "fabm.yaml",
path: Union[str, dict, os.PathLike] = "fabm.yaml",
shape: Tuple[int, ...] = (),
libname: Optional[str] = None,
start: Optional[Tuple[int, ...]] = None,
Expand All @@ -1095,6 +1095,8 @@ def _none_representer(self: Dumper, _: None) -> Any:
yaml.dump(path, wrapper, Dumper=Dumper)
path = f.name
delete = True
else:
path = os.fspath(path)

if libname is None:
# Pick one of the built-in FABM libraries (0D or 1D)
Expand Down Expand Up @@ -1292,9 +1294,11 @@ def setCellThickness(self, value: npt.ArrayLike):
def getSubModel(self, name: str) -> SubModel:
return SubModel(self, name)

def save_settings(self, path: str, display: int = DISPLAY_NORMAL):
def save_settings(
self, path: Union[str, os.PathLike], display: int = DISPLAY_NORMAL
):
"""Write model configuration to yaml file"""
self.fabm.save_settings(self.pmodel, path.encode("ascii"), display)
self.fabm.save_settings(self.pmodel, os.fspath(path).encode("ascii"), display)

def _save_state(self) -> Tuple[Mapping[str, np.ndarray], Mapping[str, np.ndarray]]:
environment = {}
Expand Down
7 changes: 5 additions & 2 deletions src/pyfabm/complete_yaml.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from typing import Union
import os

import pyfabm


def processFile(
infile: str,
outfile: str,
infile: Union[str, os.PathLike],
outfile: Union[str, os.PathLike],
subtract_background: bool = False,
add_missing: bool = False,
):
Expand Down
3 changes: 3 additions & 0 deletions src/pyfabm/utils/fabm_complete_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"""

import sys
from pathlib import Path

try:
import pyfabm.complete_yaml
Expand All @@ -21,13 +22,15 @@ def main() -> None:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
"path",
type=Path,
help=(
"Path to a YAML file with the model configuration that needs to"
" be completed."
),
)
parser.add_argument(
"output_path",
type=Path,
help=(
"Path to save the completed YAML file to. If not provided,"
" this defaults to the file from which the model configuration is read."
Expand Down
4 changes: 3 additions & 1 deletion src/pyfabm/utils/fabm_configuration_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""

import sys
from pathlib import Path

try:
import pyfabm
Expand All @@ -26,7 +27,8 @@ def main() -> None:
"path",
help="Path to a YAML file with the model configuration",
nargs="?",
default="fabm.yaml",
type=Path,
default=Path("fabm.yaml"),
)
args = parser.parse_args()

Expand Down
4 changes: 3 additions & 1 deletion src/pyfabm/utils/fabm_describe_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"""

import sys
from pathlib import Path

try:
import pyfabm
Expand All @@ -22,7 +23,8 @@ def main() -> None:
"path",
help="Path to a YAML file with the model configuration",
nargs="?",
default="fabm.yaml",
type=Path,
default=Path("fabm.yaml"),
)
parser.add_argument(
"--all",
Expand Down