11"""Parameters for OpenPTV-Python."""
2- import os
32from dataclasses import asdict , dataclass , field
43from pathlib import Path
54from typing import List , Tuple
@@ -146,9 +145,9 @@ def get_last(self):
146145 return self .last
147146
148147 @classmethod
149- def from_file (cls , filename : str , num_cams : int ):
148+ def from_file (cls , filename : Path , num_cams : int ):
150149 """Read sequence parameters from file."""
151- if not Path ( filename ) .exists ():
150+ if not filename .exists ():
152151 raise IOError ("File {filename} does not exist." )
153152
154153 ret = cls ()
@@ -162,7 +161,7 @@ def from_file(cls, filename: str, num_cams: int):
162161 return ret
163162
164163
165- def read_sequence_par (filename : str , num_cams : int = TR_MAX_CAMS ) -> SequencePar :
164+ def read_sequence_par (filename : Path , num_cams : int = TR_MAX_CAMS ) -> SequencePar :
166165 """Read sequence parameters from file and return SequencePar object."""
167166 return SequencePar ().from_file (filename , num_cams )
168167
@@ -213,7 +212,7 @@ class TrackPar(Parameters):
213212 # }
214213
215214 @classmethod
216- def from_file (cls , filename : str ):
215+ def from_file (cls , filename : Path ):
217216 """Read tracking parameters from file and return TrackPar object.
218217
219218 Note that the structure has 13 attributes, from which we read only 9
@@ -306,7 +305,7 @@ def get_dny(self):
306305 return self .dny
307306
308307
309- def read_track_par (filename : str ) -> TrackPar :
308+ def read_track_par (filename : Path ) -> TrackPar :
310309 """Read tracking parameters from file and return TrackPar object."""
311310 return TrackPar ().from_file (filename )
312311
@@ -377,7 +376,7 @@ def set_corrmin(self, corrmin: float):
377376 self .corrmin = corrmin
378377
379378 @classmethod
380- def from_file (cls , filename : str ):
379+ def from_file (cls , filename : Path ):
381380 """Read volume parameters from file.
382381
383382 Args:
@@ -401,7 +400,7 @@ def from_file(cls, filename: str):
401400 return cls (x_lay , z_min_lay , z_max_lay , cn , cnx , cny , csumg , eps0 , corrmin )
402401
403402
404- def read_volume_par (filename : str ) -> VolumePar :
403+ def read_volume_par (filename : Path ) -> VolumePar :
405404 """Read volume parameters from file and returns volume_par object.
406405
407406 Args:
@@ -497,10 +496,10 @@ def get_tiff_flag(self):
497496 return self .tiff_flag
498497
499498 @classmethod
500- def from_file (cls , filename : str ):
499+ def from_file (cls , filename : Path ):
501500 """Read control parameters from file and return ControlPar object."""
502501 ret = cls ()
503- if not os . path . isfile ( filename ):
502+ if not filename . exists ( ):
504503 raise FileNotFoundError (f"Could not open file { filename } " )
505504
506505 with open (filename , "r" , encoding = "utf-8" ) as par_file :
@@ -546,7 +545,7 @@ def to_dict(cls, data):
546545 return control_par_dict
547546
548547
549- def read_control_par (filename : str ) -> ControlPar :
548+ def read_control_par (filename : Path ) -> ControlPar :
550549 """Read control parameters from file and return ControlPar object."""
551550 return ControlPar ().from_file (filename )
552551
@@ -608,7 +607,7 @@ class TargetPar(Parameters):
608607 # }
609608
610609 @classmethod
611- def from_file (cls , filename : str ):
610+ def from_file (cls , filename : Path ):
612611 """Read target parameters from file and returns target_par object.
613612
614613 Reads target recognition parameters from a legacy detect_plate.par file,
@@ -673,7 +672,7 @@ def get_min_sum_grey(self):
673672 """Return the sum grey bounds."""
674673 return self .sumg_min
675674
676- def read_target_par (filename : str ) -> TargetPar :
675+ def read_target_par (filename : Path ) -> TargetPar :
677676 """Read target parameters from file and returns target_par object."""
678677 tpar = TargetPar ()
679678 return tpar .from_file (filename )
@@ -712,7 +711,7 @@ class OrientPar(Parameters):
712711 interfflag : int = 0
713712
714713 @classmethod
715- def from_file (cls , filename : str ):
714+ def from_file (cls , filename : Path ):
716715 """Read orientation parameters from file and returns orient_par object."""
717716 ret = cls ()
718717 try :
@@ -777,7 +776,7 @@ def from_file(cls, file_path: str, num_cams: int):
777776 return cls (fixp_name , img_name , img_ori0 , tiff_flag , pair_flag , chfield )
778777
779778
780- def read_cal_ori_parameters (file_path : str , num_cams : int ) -> CalibrationPar :
779+ def read_cal_ori_parameters (file_path : Path , num_cams : int ) -> CalibrationPar :
781780 """Read from cal_ori.par file."""
782781 with open (file_path , 'r' , encoding = "utf-8" ) as file :
783782 fixp_name = file .readline ().strip ()
@@ -799,7 +798,7 @@ class MultiPlanesPar(Parameters):
799798 filename : list = field (default_factory = list )
800799
801800 @classmethod
802- def from_file (cls , file_path : str ):
801+ def from_file (cls , file_path : Path ):
803802 """Read from multiplanes.par file."""
804803 with open (file_path , 'r' , encoding = "utf-8" ) as file :
805804 num_planes = int (file .readline ().strip ())
@@ -814,14 +813,14 @@ class ExaminePar(Parameters):
814813 combine_flag : bool = False
815814
816815 @classmethod
817- def from_file (cls , file_path : str ):
816+ def from_file (cls , file_path : Path ):
818817 """Read from examine.par file."""
819818 with open (file_path , 'r' , encoding = "utf-8" ) as file :
820819 examine_flag = bool (int (file .readline ().strip ()))
821820 combine_flag = bool (int (file .readline ().strip ()))
822821 return cls (examine_flag , combine_flag )
823822
824- def read_examine_par (file_path : str ) -> ExaminePar :
823+ def read_examine_par (file_path : Path ) -> ExaminePar :
825824 """Read from examine.par file."""
826825 with open (file_path , 'r' , encoding = "utf-8" ) as file :
827826 examine_flag = bool (int (file .readline ().strip ()))
@@ -835,14 +834,14 @@ class PftVersionPar(Parameters):
835834 existing_target_flag : bool = False
836835
837836 @classmethod
838- def from_file (cls , file_path : str ):
837+ def from_file (cls , file_path : Path ):
839838 """Read from pft_version.par file."""
840839 with open (file_path , 'r' , encoding = "utf-8" ) as file :
841840 pft_version = bool (int (file .readline ().strip ()))
842841 return cls (pft_version )
843842
844843 @classmethod
845- def write (cls , file_path : str ):
844+ def write (cls , file_path : Path ):
846845 """Write to pft_version.par file."""
847846 with open (file_path , 'w' , encoding = "utf-8" ) as file :
848847 file .write (f"{ cls .existing_target_flag } \n " )
0 commit comments