55import os
66import shutil
77from os .path import join , abspath , relpath , dirname , isfile , split , exists
8+ from pathlib import Path
89from typing import Union , List , Dict , Sequence
910
1011import numpy
@@ -113,12 +114,10 @@ def __init__(
113114 # Or filter region?
114115 # Instantiate
115116
116- workdir = abspath (kwargs .get ("path" , os .getcwd ()))
117+ workdir = Path (kwargs .get ("path" , os .getcwd ())). resolve ( )
117118 if kwargs .get ("timestamp" , False ):
118- rundir = os .path .join (
119- rundir , f"run_{ datetime .datetime .utcnow ().date ().isoformat ()} "
120- )
121- os .makedirs (os .path .join (workdir , rundir ), exist_ok = True )
119+ rundir = Path (rundir , f"run_{ datetime .datetime .utcnow ().date ().isoformat ()} " )
120+ os .makedirs (Path (workdir , rundir ), exist_ok = True )
122121
123122 self .name = name if name else "floatingExp"
124123 self .registry = ExperimentRegistry .factory (workdir = workdir , run_dir = rundir )
@@ -359,7 +358,6 @@ def set_input_cat(self, tstring: str, model: Model) -> None:
359358 model (:class:`~floatcsep.model.Model`): Model to give the input
360359 catalog
361360 """
362-
363361 self .catalog_repo .set_input_cat (tstring , model )
364362
365363 def set_tasks (self ) -> None :
@@ -581,11 +579,14 @@ def make_repr(self) -> None:
581579 if not exists (target_cat ):
582580 shutil .copy2 (self .registry .abs (self .catalog_repo .cat_path ), target_cat )
583581
584- relative_path = os .path .relpath (
585- self .registry .workdir , os .path .join (self .registry .workdir , self .registry .run_dir )
582+ # relative_path = self.registry.rel(self.registry.run_dir)
583+ # print(self.registry.workdir.__class__, self.registry.run_dir.__class__)
584+ relative_path = Path (
585+ os .path .relpath (self .registry .workdir .as_posix (), self .registry .run_dir .as_posix ())
586586 )
587587 self .registry .workdir = relative_path
588- self .to_yml (repr_config , extended = True )
588+
589+ self .to_yml (repr_config .as_posix (), extended = True )
589590
590591 def as_dict (self , extra : Sequence = (), extended = False ) -> dict :
591592 """
@@ -603,8 +604,8 @@ def as_dict(self, extra: Sequence = (), extended=False) -> dict:
603604 dict_walk = {
604605 "name" : self .name ,
605606 "config_file" : self .config_file ,
606- "path" : self .registry .workdir ,
607- "run_dir" : self .registry .run_dir ,
607+ "path" : self .registry .workdir . as_posix () ,
608+ "run_dir" : self .registry .rel ( self . registry . run_dir ). as_posix () ,
608609 "time_config" : {
609610 i : j
610611 for i , j in self .time_config .items ()
@@ -615,12 +616,11 @@ def as_dict(self, extra: Sequence = (), extended=False) -> dict:
615616 for i , j in self .region_config .items ()
616617 if (i not in ("magnitudes" , "depths" ) or extended )
617618 },
618- "catalog" : self .catalog_repo .cat_path ,
619+ "catalog" : self .registry . rel ( self . catalog_repo .cat_path ). as_posix () ,
619620 "models" : [i .as_dict () for i in self .models ],
620621 "tests" : [i .as_dict () for i in self .tests ],
621622 }
622623 dict_walk .update (extra )
623-
624624 return parse_nested_dicts (dict_walk )
625625
626626 def to_yml (self , filename : str , ** kwargs ) -> None :
@@ -816,7 +816,9 @@ def get_filecomp(self):
816816 results [test .name ] = dict .fromkeys (models_orig )
817817 for model in models_orig :
818818 orig_path = self .original .registry .get_result_key (win_orig [- 1 ], test , model )
819- repr_path = self .reproduced .registry .get_result_key (win_orig [- 1 ], test , model )
819+ repr_path = self .reproduced .registry .get_result_key (
820+ win_orig [- 1 ], test , model
821+ )
820822 results [test .name ][model ] = {
821823 "hash" : (self .get_hash (orig_path ) == self .get_hash (repr_path )),
822824 "byte2byte" : filecmp .cmp (orig_path , repr_path ),
0 commit comments