"""Create paths, and handle file locations and vocabulary files."""importshutilimportwarningsfrompathlibimportPathimportappdirsimportpandasaspd
[docs]classPaths(object):"""Object to manage paths"""def__init__(self,project_name=None,cache_dir=None):"""Initialize Paths object to manage paths in project. Parameters ---------- project_name : str Subdirectory in cache dir to store files associated together. cache_dir : _type_, optional Input an alternative cache_dir if you prefer, esp for testing, by default None """# if project_name is None:# warnings.warn("only `VOCAB_DIR` and `VOCAB_PATH` are available without supplying 'project_name'.")ifcache_dirisNone:# set up cache directories for package to use# user application cache directory, appropriate to each OS# dirs = AppDirs("ocean-model-skill-assessor", "axiom-data-science")# cache_dir = Path(dirs.user_cache_dir)cache_dir=Path(appdirs.user_cache_dir(appname="ocean-model-skill-assessor",appauthor="axiom-data-science"))self.cache_dir=cache_dirself.project_name=project_name@propertydefVOCAB_DIR(self):"""Where to store and find vocabularies. Come from an initial set."""loc=self.cache_dir/"vocab"loc.mkdir(parents=True,exist_ok=True)loc_initial=Path(__file__).parent/"vocab"# NEED THIS TO BE THE BASE PATH# copy vocab files to vocab cache location[shutil.copy(vocab_path,loc)forvocab_pathinloc_initial.glob("*.json")]returnloc@propertydefPROJ_DIR(self):"""Return path to project directory."""assertself.project_nameisnotNonepath=self.cache_dir/f"{self.project_name}"path.mkdir(parents=True,exist_ok=True)returnpath
[docs]defCAT_PATH(self,cat_name):"""Return path to catalog."""assertself.project_nameisnotNonepath=(self.PROJ_DIR/cat_name).with_suffix(".yaml")returnpath
[docs]defVOCAB_PATH(self,vocab_name):"""Return path to vocab."""path=(self.VOCAB_DIR/vocab_name).with_suffix(".json")returnpath
@propertydefLOG_PATH(self):"""Return path to vocab."""assertself.project_nameisnotNonepath=(self.PROJ_DIR/f"omsa").with_suffix(".log")# # if I can figure out how to make distinct logs per run# now = str(pd.Timestamp.today().isoformat())# path = PROJ_DIR(project_name) / "logs"# path.mkdir(parents=True, exist_ok=True)# path = (path / f"omsa_{now}").with_suffix(".log")returnpath@propertydefALPHA_PATH(self):"""Return path to alphashape polygon."""assertself.project_nameisnotNonepath=(self.PROJ_DIR/"alphashape").with_suffix(".txt")returnpath
[docs]defMASK_PATH(self,key_variable):"""Return path to mask cache for key_variable."""assertself.project_nameisnotNonepath=(self.PROJ_DIR/f"mask_{key_variable}").with_suffix(".nc")returnpath
@propertydefMODEL_CACHE_DIR(self):"""Return path to model cache directory."""assertself.project_nameisnotNonepath=self.PROJ_DIR/"model_output"path.mkdir(parents=True,exist_ok=True)returnpath@propertydefPROCESSED_CACHE_DIR(self):"""Return path to processed data-model directory."""assertself.project_nameisnotNonepath=self.PROJ_DIR/"processed"path.mkdir(parents=True,exist_ok=True)returnpath@propertydefOUT_DIR(self):"""Return path to output directory."""assertself.project_nameisnotNonepath=self.PROJ_DIR/"out"path.mkdir(parents=True,exist_ok=True)returnpath