|
2 | 2 | import os |
3 | 3 | from pathlib import Path |
4 | 4 | import importlib.resources as pkg_resources |
| 5 | +from typing import Dict, List, Optional |
| 6 | + |
| 7 | +__all__ = [ |
| 8 | + "get_paths", |
| 9 | + "create_necessary_dirs", |
| 10 | +] |
5 | 11 |
|
6 | 12 | # Define the project root based on config.py's location. |
7 | 13 | # This assumes config.py is in src/SLM/, so it goes up three levels |
|
18 | 24 | DEFAULT_TOV_DATA_SUBDIR_NAME = "TOV_data" |
19 | 25 | DEFAULT_TEST_DATA_SUBDIR_NAME = "testData" # This is the base for test/QEOS/pSLM |
20 | 26 | DEFAULT_TRAIN_DATA_SUBDIR_NAME = "trainData" |
| 27 | +DEFAULT_VAL_DATA_SUBDIR_NAME = "valData" |
21 | 28 | DEFAULT_DOCS_SUBDIR_NAME = "docs" |
22 | 29 | DEFAULT_TESTS_SUBDIR_NAME = "tests" |
23 | 30 | DEFAULT_TUTORIALS_SUBDIR_NAME = "Tutorials" |
|
33 | 40 |
|
34 | 41 |
|
35 | 42 | def get_paths( |
36 | | - output_base_dir: Path = None, |
| 43 | + output_base_dir: Optional[Path] = None, |
37 | 44 | eos_name: str = "MSEOS", |
38 | 45 | is_parametric_run: bool = True, |
39 | 46 | include_slm_paths: bool = True, |
40 | | -) -> dict: |
| 47 | +) -> Dict[str, Path]: |
41 | 48 | """ |
42 | | - Returns a dictionary of resolved paths for data input/output and other project directories. |
43 | | - All 'current' paths are dynamically set based on the provided 'eos_name'. |
44 | | -
|
45 | | - Args: |
46 | | - output_base_dir (Path, optional): The base directory for all generated outputs. |
47 | | - eos_name (str): The name of the Equation of State (e.g., "MSEOS", "QEOS", "APR"). |
48 | | - This name is used to create specific subdirectories. Defaults to "MSEOS". |
49 | | - is_parametric_run (bool): If True, affects result/plot/test subdirectories (pSLM vs SLM). |
50 | | - include_slm_paths (bool): If True, SLM-specific results, plots, and test directories are included. |
51 | | -
|
52 | | - Returns: |
53 | | - dict: A dictionary containing all relevant path configurations. |
| 49 | + Generates and returns a dictionary of resolved project paths, dynamically |
| 50 | + structuring subdirectories based on the Equation of State (EOS) name and |
| 51 | + run configuration. |
| 52 | +
|
| 53 | + The function provides paths for input data, model binaries, general output, |
| 54 | + and specific subdirectories for results, plots, and test data related to |
| 55 | + SLM (Sparse Linear Modeling) or pSLM (parametric SLM) runs. |
| 56 | +
|
| 57 | + Parameters |
| 58 | + ---------- |
| 59 | + output_base_dir : pathlib.Path, optional |
| 60 | + The root directory where all generated project outputs (results, plots, |
| 61 | + test data) will be stored. If ``None``, the current working directory |
| 62 | + is implicitly used as the root for relative paths. Defaults to ``None``. |
| 63 | + eos_name : str, optional |
| 64 | + The name of the Equation of State (e.g., "MSEOS", "QEOS", "APR"). |
| 65 | + This name dictates the specific subdirectory created for the current run |
| 66 | + within the results, plots, and test directories. Defaults to "MSEOS". |
| 67 | + is_parametric_run : bool, optional |
| 68 | + Flag indicating if the current modeling run is using the parametric SLM |
| 69 | + (pSLM) approach. If ``True``, the output paths will typically include |
| 70 | + 'pSLM'; otherwise, they'll use 'SLM'. Defaults to ``True``. |
| 71 | + include_slm_paths : bool, optional |
| 72 | + If ``True``, the dictionary will include the specific directories |
| 73 | + (``current_results_dir``, ``current_plots_dir``, ``current_test_dir``) |
| 74 | + related to the SLM/pSLM outputs. Defaults to ``True``. |
| 75 | +
|
| 76 | + Returns |
| 77 | + ------- |
| 78 | + dict[str, pathlib.Path] |
| 79 | + A dictionary containing all relevant path configurations. Keys include: |
| 80 | +
|
| 81 | + * ``output_base_dir``: The resolved base output path. |
| 82 | + * ``data_input_dir``: Path to the general input data files. |
| 83 | + * ``bin_dir``: Path to executable binaries (e.g., TOV solver). |
| 84 | + * ``current_results_dir``: Directory for SLM/pSLM results for the given EOS. |
| 85 | + * ``current_plots_dir``: Directory for SLM/pSLM plots for the given EOS. |
| 86 | + * ``current_test_dir``: Directory for SLM/pSLM test data for the given EOS. |
54 | 87 | """ |
| 88 | + |
55 | 89 | project_root = PROJECT_ROOT |
56 | 90 | output_data_base = output_base_dir or project_root |
57 | 91 | src_dir = project_root / DEFAULT_SRC_SUBDIR_NAME |
@@ -93,6 +127,7 @@ def get_paths( |
93 | 127 | "user_eos_data_dir": output_data_base / DEFAULT_EOS_DATA_SUBDIR_NAME, |
94 | 128 | "test_data_dir": output_data_base / DEFAULT_TEST_DATA_SUBDIR_NAME, |
95 | 129 | "train_path": output_data_base / DEFAULT_TRAIN_DATA_SUBDIR_NAME, |
| 130 | + "val_path": output_data_base / DEFAULT_VAL_DATA_SUBDIR_NAME, |
96 | 131 | "generated_eos_files_dir": output_data_base / DEFAULT_EOS_FILES_SUBDIR_NAME, |
97 | 132 |
|
98 | 133 | # Current Dynamic EOS/TOV/Generated paths |
@@ -156,9 +191,35 @@ def get_paths( |
156 | 191 | return final_paths |
157 | 192 |
|
158 | 193 |
|
159 | | -def create_necessary_dirs(paths: dict, additional_dirs: list[Path] = None): |
| 194 | +def create_necessary_dirs( |
| 195 | + paths: Dict[str, Path], |
| 196 | + additional_dirs: Optional[List[Path]] = None |
| 197 | +) -> None: |
160 | 198 | """ |
161 | | - Creates directories for specified output and user-managed data paths if they do not already exist. |
| 199 | + Creates necessary directories specified in a dictionary and an optional list. |
| 200 | +
|
| 201 | + This function iterates through all Path objects provided in the input dictionary's |
| 202 | + values and the optional list, ensuring that each directory is created if it |
| 203 | + does not already exist. It uses pathlib.Path.mkdir with parents=True and |
| 204 | + exist_ok=True, meaning it will create parent directories if necessary and |
| 205 | + will not raise an error if the directory already exists. |
| 206 | +
|
| 207 | + Parameters |
| 208 | + ---------- |
| 209 | + paths : dict[str, pathlib.Path] |
| 210 | + A dictionary where keys are string identifiers (e.g., 'output_path') |
| 211 | + and values are :class:`pathlib.Path` objects representing the directories |
| 212 | + to be created. |
| 213 | + additional_dirs : list[pathlib.Path], optional |
| 214 | + An optional list of additional :class:`pathlib.Path` objects representing |
| 215 | + directories to be created (e.g., user-managed data or model directories). |
| 216 | + The default is None. |
| 217 | +
|
| 218 | + Returns |
| 219 | + ------- |
| 220 | + None |
| 221 | + The function modifies the filesystem but does not return a value. |
| 222 | +
|
162 | 223 | """ |
163 | 224 |
|
164 | 225 | # Define a list of keys corresponding to directories that should be created. |
|
0 commit comments