22
33import json
44from collections .abc import Iterable
5+ from os import PathLike
56from pathlib import Path
67from typing import Union
78
1415from RATapi .utils .enums import Geometries , Languages , LayerModels
1516
1617
17- def r1_to_project_class (filename : str ) -> Project :
18+ def r1_to_project_class (filename : Union [ str , PathLike ] ) -> Project :
1819 """Read a RasCAL1 project struct as a Python `Project`.
1920
2021 Parameters
2122 ----------
22- filename : str
23+ filename : str, PathLike
2324 The path to a .mat file containing project data.
2425
2526 Returns
@@ -28,7 +29,7 @@ def r1_to_project_class(filename: str) -> Project:
2829 A RAT `Project` equivalent to the RasCAL1 project struct.
2930
3031 """
31- mat_project = loadmat (filename , simplify_cells = True )["problem" ]
32+ mat_project = loadmat (str ( filename ) , simplify_cells = True )["problem" ]
3233
3334 mat_module = mat_project ["module" ]
3435 if mat_module ["experiment_type" ] == "Air / Liquid (or solid)" :
@@ -271,15 +272,15 @@ def read_param(names, constrs, values, fits):
271272
272273
273274def project_class_to_r1 (
274- project : Project , filename : str = "RAT_project" , return_struct : bool = False
275+ project : Project , filename : Union [ str , PathLike ] = "RAT_project" , return_struct : bool = False
275276) -> Union [dict , None ]:
276277 """Convert a RAT Project to a RasCAL1 project struct.
277278
278279 Parameters
279280 ----------
280281 project : Project
281282 The RAT Project to convert.
282- filename : str, default "RAT_project"
283+ filename : str or PathLike , default "RAT_project"
283284 If given, saves as a .mat file with the given filename.
284285 return_struct : bool, default False
285286 If True, do not save and instead return the R1 struct.
@@ -503,7 +504,7 @@ def convert_parameters(
503504 if eng is None :
504505 raise ImportError ("matlabengine is not installed." )
505506 eng .workspace ["problem" ] = r1
506- eng .save (filename , "problem" , nargout = 0 )
507+ eng .save (str ( filename ) , "problem" , nargout = 0 )
507508 eng .exit ()
508509 return None
509510
0 commit comments