Skip to content

Commit a03b622

Browse files
committed
Updated documentationfor some files
1 parent d5f4321 commit a03b622

File tree

4 files changed

+217
-56
lines changed

4 files changed

+217
-56
lines changed

src/slmemulator/SLM.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def SLM(X, dt, error_threshold=1e-4, max_r=None):
133133
# Using original X (log-transformed) for comparison
134134
current_error = np.max(np.abs(X - Xdmd_current_original_vars))
135135

136-
print(f"Testing r={r_current}: Max absolute error = {current_error:.6f}")
136+
# print(f"Testing r={r_current}: Max absolute error = {current_error:.6f}")
137137

138138
if current_error <= error_threshold:
139139
r_optimal = r_current
@@ -193,7 +193,7 @@ def solve_tov(fileName, tidal=False, parametric=False, mseos=True):
193193
194194
Returns:
195195
dataArray (array): Data array containing radii, central pressure
196-
and mass.
196+
and mass (includes tidal deformability k_2 if set to true).
197197
"""
198198
# Get current paths from the config module
199199
paths = get_paths()

src/slmemulator/cleanData.py

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import shutil
88
import sys
99
from pathlib import Path
10+
from typing import Optional
1011

1112
# Import default subdirectory names from config for consistent cleanup targets
1213
from slmemulator.config import (
@@ -16,8 +17,11 @@
1617
DEFAULT_TEST_DATA_SUBDIR_NAME,
1718
DEFAULT_TRAIN_DATA_SUBDIR_NAME,
1819
DEFAULT_PLOTS_SUBDIR_NAME,
20+
DEFAULT_VAL_DATA_SUBDIR_NAME,
1921
)
2022

23+
__all__ = ["clean_directory"]
24+
2125
# List of common cleanup targets (directories and file extensions)
2226
cleanup_targets = [
2327
"__pycache__", # directory for compiled Python bytecode
@@ -31,13 +35,41 @@
3135
]
3236

3337

34-
def clean_directory(directory: str = None):
38+
def clean_directory(directory: Optional[str] = None) -> None:
3539
"""
36-
Cleans up specified files and directories within a given directory.
40+
Recursively cleans a specified directory by removing common project artifacts
41+
and specific, code-generated subdirectories.
42+
43+
The function targets temporary files (by extension) and removes specific
44+
directories generated during modeling, plotting, and data processing.
45+
46+
Parameters
47+
----------
48+
directory : str, optional
49+
The path to the directory to clean. If :obj:`None`, the function
50+
defaults to cleaning the **current working directory** (:func:`os.getcwd`).
51+
52+
Returns
53+
-------
54+
None
55+
The function modifies the filesystem but does not return a value.
56+
57+
Notes
58+
-----
59+
The cleanup process recursively deletes:
60+
61+
1. **Files** matching extensions defined in the global ``cleanup_targets``
62+
(e.g., ``.pyo``, ``.pyc``).
63+
2. **Directories** matching names in the global ``cleanup_targets`` (e.g.,
64+
``__pycache__``).
65+
3. **Specific Subdirectories** generated by the code, including those named by
66+
the global default constants: ``DEFAULT_EOS_FILES_SUBDIR_NAME``,
67+
``DEFAULT_RESULTS_SUBDIR_NAME``, ``DEFAULT_PLOTS_SUBDIR_NAME``,
68+
and subdirectories related to data splitting (train/validation/test).
3769
38-
Parameters:
39-
directory (str): The path to the directory to clean. Defaults to the
40-
current working directory if None.
70+
The traversal is performed from bottom-to-top (:attr:`os.walk` with
71+
``topdown=False``) to allow for safe recursive directory removal
72+
using :func:`shutil.rmtree`.
4173
"""
4274
if directory is None:
4375
directory = os.getcwd()
@@ -58,6 +90,7 @@ def clean_directory(directory: str = None):
5890
DEFAULT_TOV_DATA_SUBDIR_NAME,
5991
DEFAULT_TEST_DATA_SUBDIR_NAME,
6092
DEFAULT_TRAIN_DATA_SUBDIR_NAME,
93+
DEFAULT_VAL_DATA_SUBDIR_NAME,
6194
DEFAULT_PLOTS_SUBDIR_NAME,
6295
]
6396

src/slmemulator/config.py

Lines changed: 77 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
import os
33
from pathlib import Path
44
import importlib.resources as pkg_resources
5+
from typing import Dict, List, Optional
6+
7+
__all__ = [
8+
"get_paths",
9+
"create_necessary_dirs",
10+
]
511

612
# Define the project root based on config.py's location.
713
# This assumes config.py is in src/SLM/, so it goes up three levels
@@ -18,6 +24,7 @@
1824
DEFAULT_TOV_DATA_SUBDIR_NAME = "TOV_data"
1925
DEFAULT_TEST_DATA_SUBDIR_NAME = "testData" # This is the base for test/QEOS/pSLM
2026
DEFAULT_TRAIN_DATA_SUBDIR_NAME = "trainData"
27+
DEFAULT_VAL_DATA_SUBDIR_NAME = "valData"
2128
DEFAULT_DOCS_SUBDIR_NAME = "docs"
2229
DEFAULT_TESTS_SUBDIR_NAME = "tests"
2330
DEFAULT_TUTORIALS_SUBDIR_NAME = "Tutorials"
@@ -33,25 +40,52 @@
3340

3441

3542
def get_paths(
36-
output_base_dir: Path = None,
43+
output_base_dir: Optional[Path] = None,
3744
eos_name: str = "MSEOS",
3845
is_parametric_run: bool = True,
3946
include_slm_paths: bool = True,
40-
) -> dict:
47+
) -> Dict[str, Path]:
4148
"""
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.
5487
"""
88+
5589
project_root = PROJECT_ROOT
5690
output_data_base = output_base_dir or project_root
5791
src_dir = project_root / DEFAULT_SRC_SUBDIR_NAME
@@ -93,6 +127,7 @@ def get_paths(
93127
"user_eos_data_dir": output_data_base / DEFAULT_EOS_DATA_SUBDIR_NAME,
94128
"test_data_dir": output_data_base / DEFAULT_TEST_DATA_SUBDIR_NAME,
95129
"train_path": output_data_base / DEFAULT_TRAIN_DATA_SUBDIR_NAME,
130+
"val_path": output_data_base / DEFAULT_VAL_DATA_SUBDIR_NAME,
96131
"generated_eos_files_dir": output_data_base / DEFAULT_EOS_FILES_SUBDIR_NAME,
97132

98133
# Current Dynamic EOS/TOV/Generated paths
@@ -156,9 +191,35 @@ def get_paths(
156191
return final_paths
157192

158193

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:
160198
"""
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+
162223
"""
163224

164225
# Define a list of keys corresponding to directories that should be created.

0 commit comments

Comments
 (0)