Skip to content

Commit d5f4321

Browse files
Merge pull request #26 from asemposki/slalit
updates to code
2 parents 2a5d10f + 4705571 commit d5f4321

File tree

6 files changed

+465
-223
lines changed

6 files changed

+465
-223
lines changed

src/slmemulator/EOS_Codes/MSEOS.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ def main(self, Ls, Lv, zeta, xi, out_file=None):
340340
xf = (10.0, 10.0, 2e-3, 2e-3)
341341
ls = (zeta, xi)
342342
paths = get_paths()
343-
eos_data_dir = paths["eos_data_dir"]
343+
eos_data_dir = paths["package_eos_data_dir"]
344344

345345
mft_path = eos_data_dir / "MFT_ns6p.dat"
346346
lowden = np.loadtxt(mft_path)

src/slmemulator/EOS_Codes/Quarkyonia.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def generate_quarkyonia_eos(lamInput, kappa, output_filepath):
5454
kArray = np.linspace(kfmin, kfmax, 400)
5555
# set paths
5656
paths = get_paths()
57-
eos_data_dir = paths["eos_data_dir"]
57+
eos_data_dir = paths["package_eos_data_dir"]
5858
output_filepath = Path(output_filepath)
5959
output_filepath.parent.mkdir(parents=True, exist_ok=True)
6060
# Initialize arrays

src/slmemulator/__init__.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1+
# __init__.py for automatic discovery
12
import os
23
import sys
3-
# from .recombination import *
4-
# from .SLM import *
5-
# from .TOV_class import TOV
6-
# from .plotData import *
7-
# from .config import get_paths
8-
# from .cleanData import *
9-
# from .pSLM import *
10-
# from .EOS_Codes import Quarkyonia, MSEOS
4+
5+
# Import everything from the listed sub-modules:
6+
from .recombination import * # This will expose every function/class from recombination.py
7+
from .SLM import *
8+
from .TOV_class import *
9+
from .plotData import *
10+
from .config import * # This will expose get_paths (and anything else)
11+
from .cleanData import * # This will expose clean_directory (and anything else)
12+
from .pSLM import *
13+
from .EOS_Codes import * # This will expose MSEOS (and anything else)
14+
15+
# This line is not needed if you use from .EOS_Codes import *
1116
# from .EOS_Codes.Quarkyonia import generate_quarkyonia_eos
1217

13-
# from . import *
14-
# Add base directory (project root) to sys path
15-
# If __file__ is /project_root/src/slmemulator/__init__.py,
16-
# then this correctly calculates /project_root/
18+
# [Rest of your config and path code...]
1719
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
1820
if BASE_DIR not in sys.path:
1921
sys.path.insert(0, BASE_DIR)
20-
21-
# Versioning (good practice)
22-
__version__ = "0.1.0"
22+
__version__ = "0.1.0"

src/slmemulator/config.py

Lines changed: 88 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
DEFAULT_PLOTS_SUBDIR_NAME = "Plots"
1717
DEFAULT_RESULTS_SUBDIR_NAME = "Results"
1818
DEFAULT_TOV_DATA_SUBDIR_NAME = "TOV_data"
19-
DEFAULT_TEST_DATA_SUBDIR_NAME = "testData"
19+
DEFAULT_TEST_DATA_SUBDIR_NAME = "testData" # This is the base for test/QEOS/pSLM
2020
DEFAULT_TRAIN_DATA_SUBDIR_NAME = "trainData"
2121
DEFAULT_DOCS_SUBDIR_NAME = "docs"
2222
DEFAULT_TESTS_SUBDIR_NAME = "tests"
@@ -28,231 +28,168 @@
2828

2929
# Default subdirectory name for Parametric SLM results/plots
3030
DEFAULT_PSLM_SUBDIR_NAME = "pSLM"
31-
# NEW: Default subdirectory name for non-Parametric SLM results/plots
31+
# Default subdirectory name for non-Parametric SLM results/plots
3232
DEFAULT_SLM_SUBDIR_NAME = "SLM"
3333

3434

3535
def get_paths(
3636
output_base_dir: Path = None,
37-
use_mseos: bool = True,
37+
eos_name: str = "MSEOS",
3838
is_parametric_run: bool = True,
39-
include_slm_paths: bool = True, # New parameter to control SLM specific paths
39+
include_slm_paths: bool = True,
4040
) -> dict:
4141
"""
4242
Returns a dictionary of resolved paths for data input/output and other project directories.
43-
Prioritizes explicit arguments for output_base_dir, then sensible defaults.
44-
Conditionally sets 'current' EOS/TOV/results paths based on the use_mseos flag.
43+
All 'current' paths are dynamically set based on the provided 'eos_name'.
4544
4645
Args:
47-
output_base_dir (Path, optional): The base directory for all generated outputs
48-
and user-managed data. If None, defaults to
49-
the overall PROJECT_ROOT.
50-
use_mseos (bool): If True, 'current' paths will point to MSEOS-related directories.
51-
If False, 'current' paths will point to QEOS-related directories.
52-
Defaults to True.
53-
is_parametric_run (bool): If True, indicates a parametric run, affecting result/plot
54-
subdirectories. Defaults to True.
55-
include_slm_paths (bool): If True, SLM-specific results and plots directories
56-
will be included. If False, these paths are omitted.
57-
Defaults to True.
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.
5851
5952
Returns:
6053
dict: A dictionary containing all relevant path configurations.
6154
"""
62-
# The overall project root, constant regardless of output_base_dir
6355
project_root = PROJECT_ROOT
64-
65-
# The base directory for all generated outputs and user-managed data.
66-
# If output_base_dir is provided, use it. Otherwise, use the overall project_root.
6756
output_data_base = output_base_dir or project_root
68-
69-
# The source directory, always relative to the overall project_root
7057
src_dir = project_root / DEFAULT_SRC_SUBDIR_NAME
58+
59+
# Define extensions to strip
60+
EXTENSIONS_TO_STRIP = [".txt", ".dat", ".table"]
61+
62+
# Strip extensions and convert to uppercase for directory naming
63+
clean_eos_name = eos_name
64+
for ext in EXTENSIONS_TO_STRIP:
65+
if clean_eos_name.lower().endswith(ext):
66+
clean_eos_name = clean_eos_name[:-len(ext)]
67+
break # Stop after stripping the first matching extension
68+
69+
# --- Dynamic EOS-specific folder name, ensuring it's uppercase for directories ---
70+
EOS_FOLDER_NAME = clean_eos_name.upper()
71+
72+
# --- Define SLM subdirectory based on run type (SLM or pSLM) ---
73+
SLM_SUBDIR = DEFAULT_PSLM_SUBDIR_NAME if is_parametric_run else DEFAULT_SLM_SUBDIR_NAME
7174

7275
paths = {
7376
"project_root": project_root,
7477
"src_dir": src_dir,
75-
# Internal package resources (read-only, typically part of the installed package)
76-
# Assumes the package is named 'slmemulator' for pkg_resources.
78+
# Internal package resources (read-only)
7779
"package_eos_codes_dir": pkg_resources.files("slmemulator").joinpath(
7880
DEFAULT_EOS_CODES_SUBDIR_NAME
7981
),
8082
"package_eos_data_dir": pkg_resources.files("slmemulator").joinpath(
8183
DEFAULT_EOS_DATA_SUBDIR_NAME
8284
),
83-
# Directories for generated outputs and user-managed data, relative to output_data_base.
84-
# These are the directories your application will typically write to.
85+
# General output directories
8586
"plots_dir": output_data_base / DEFAULT_PLOTS_SUBDIR_NAME,
8687
"results_dir": output_data_base / DEFAULT_RESULTS_SUBDIR_NAME,
8788
"docs_dir": output_data_base / DEFAULT_DOCS_SUBDIR_NAME,
8889
"tests_dir": output_data_base / DEFAULT_TESTS_SUBDIR_NAME,
8990
"tutorials_dir": output_data_base / DEFAULT_TUTORIALS_SUBDIR_NAME,
90-
# User-managed/project-level EOS and TOV data (can be inputs or outputs)
91+
92+
# User-managed/project-level EOS and TOV data
9193
"user_eos_data_dir": output_data_base / DEFAULT_EOS_DATA_SUBDIR_NAME,
92-
"user_tov_data_dir": output_data_base / DEFAULT_TOV_DATA_SUBDIR_NAME,
9394
"test_data_dir": output_data_base / DEFAULT_TEST_DATA_SUBDIR_NAME,
9495
"train_path": output_data_base / DEFAULT_TRAIN_DATA_SUBDIR_NAME,
95-
# Generated EOS files (e.g., from MSEOS.py/Quarkyonia.py)
9696
"generated_eos_files_dir": output_data_base / DEFAULT_EOS_FILES_SUBDIR_NAME,
97-
# Specific paths for QEOS and MSEOS generated files within generated_eos_files_dir
98-
"qeos_path_specific": (output_data_base / DEFAULT_EOS_FILES_SUBDIR_NAME)
99-
/ "QEOS",
100-
"mseos_path_specific": (output_data_base / DEFAULT_EOS_FILES_SUBDIR_NAME)
101-
/ "MSEOS",
102-
# Specific TOV data paths within user_tov_data_dir
103-
"qeos_tov_path_specific": (output_data_base / DEFAULT_TOV_DATA_SUBDIR_NAME)
104-
/ "QEOS",
105-
"mseos_tov_path_specific": (output_data_base / DEFAULT_TOV_DATA_SUBDIR_NAME)
106-
/ "MSEOS",
107-
# Removed DMD-related output directories from here. They will be user-defined.
97+
98+
# Current Dynamic EOS/TOV/Generated paths
99+
"current_eos_input_dir": (
100+
output_data_base / DEFAULT_EOS_FILES_SUBDIR_NAME
101+
) / EOS_FOLDER_NAME,
102+
"current_tov_data_dir": (
103+
output_data_base / DEFAULT_TOV_DATA_SUBDIR_NAME
104+
) / EOS_FOLDER_NAME,
105+
106+
# Kept old names for minimal compatibility changes
107+
"qeos_path_specific": (output_data_base / DEFAULT_EOS_FILES_SUBDIR_NAME) / "QEOS",
108+
"mseos_path_specific": (output_data_base / DEFAULT_EOS_FILES_SUBDIR_NAME) / "MSEOS",
109+
"qeos_tov_path_specific": (output_data_base / DEFAULT_TOV_DATA_SUBDIR_NAME) / "QEOS",
110+
"mseos_tov_path_specific": (output_data_base / DEFAULT_TOV_DATA_SUBDIR_NAME) / "MSEOS",
111+
"user_tov_data_dir": output_data_base / DEFAULT_TOV_DATA_SUBDIR_NAME,
108112
}
109113

110-
# Conditionally add SLM-specific result/plot subdirectories
114+
# Conditionally add SLM-specific result/plot/test subdirectories
111115
if include_slm_paths:
112-
# General SLM specific result/plot subdirectories (non-parametric)
113-
paths["slm_res_mseos_specific"] = (
114-
output_data_base
115-
/ DEFAULT_RESULTS_SUBDIR_NAME
116-
/ "MSEOS"
117-
/ DEFAULT_SLM_SUBDIR_NAME
118-
)
119-
paths["slm_res_qeos_specific"] = (
120-
output_data_base
121-
/ DEFAULT_RESULTS_SUBDIR_NAME
122-
/ "QEOS"
123-
/ DEFAULT_SLM_SUBDIR_NAME
124-
)
125-
paths["slm_plots_mseos_specific"] = (
126-
output_data_base
127-
/ DEFAULT_PLOTS_SUBDIR_NAME
128-
/ "MSEOS"
129-
/ DEFAULT_SLM_SUBDIR_NAME
130-
)
131-
paths["slm_plots_qeos_specific"] = (
132-
output_data_base
133-
/ DEFAULT_PLOTS_SUBDIR_NAME
134-
/ "QEOS"
135-
/ DEFAULT_SLM_SUBDIR_NAME
136-
)
137-
138-
# Parametric SLM specific result/plot subdirectories
139-
paths["slm_res_mseos_parametric_specific"] = (
116+
117+
# Define the dynamic current SLM results and plots paths
118+
paths["current_slm_results_dir"] = (
140119
output_data_base
141120
/ DEFAULT_RESULTS_SUBDIR_NAME
142-
/ "MSEOS"
143-
/ DEFAULT_PSLM_SUBDIR_NAME
121+
/ EOS_FOLDER_NAME
122+
/ SLM_SUBDIR
144123
)
145-
paths["slm_res_qeos_parametric_specific"] = (
146-
output_data_base
147-
/ DEFAULT_RESULTS_SUBDIR_NAME
148-
/ "QEOS"
149-
/ DEFAULT_PSLM_SUBDIR_NAME
150-
)
151-
paths["slm_plots_mseos_parametric_specific"] = (
124+
paths["current_slm_plots_dir"] = (
152125
output_data_base
153126
/ DEFAULT_PLOTS_SUBDIR_NAME
154-
/ "MSEOS"
155-
/ DEFAULT_PSLM_SUBDIR_NAME
127+
/ EOS_FOLDER_NAME
128+
/ SLM_SUBDIR
156129
)
157-
paths["slm_plots_qeos_parametric_specific"] = (
158-
output_data_base
159-
/ DEFAULT_PLOTS_SUBDIR_NAME
160-
/ "QEOS"
161-
/ DEFAULT_PSLM_SUBDIR_NAME
162-
)
163-
164-
# Conditionally set the "current" paths based on the use_mseos flag AND `is_parametric_run`
165-
# These 'current' paths also depend on whether SLM paths are included.
166-
if use_mseos:
167-
paths["current_eos_input_dir"] = paths["mseos_path_specific"]
168-
paths["current_tov_data_dir"] = paths["mseos_tov_path_specific"]
169-
if include_slm_paths: # Only set if SLM paths are desired
170-
if is_parametric_run:
171-
paths["current_slm_results_dir"] = paths[
172-
"slm_res_mseos_parametric_specific"
173-
]
174-
paths["current_slm_plots_dir"] = paths[
175-
"slm_plots_mseos_parametric_specific"
176-
]
177-
else: # Non-parametric SLM run for MSEOS
178-
paths["current_slm_results_dir"] = paths["slm_res_mseos_specific"]
179-
paths["current_slm_plots_dir"] = paths["slm_plots_mseos_specific"]
180-
else: # QEOS
181-
paths["current_eos_input_dir"] = paths["qeos_path_specific"]
182-
paths["current_tov_data_dir"] = paths["qeos_tov_path_specific"]
183-
if include_slm_paths: # Only set if SLM paths are desired
184-
if is_parametric_run:
185-
paths["current_slm_results_dir"] = paths[
186-
"slm_res_qeos_parametric_specific"
187-
]
188-
paths["current_slm_plots_dir"] = paths[
189-
"slm_plots_qeos_parametric_specific"
190-
]
191-
else: # Non-parametric SLM run for QEOS
192-
paths["current_slm_results_dir"] = paths["slm_res_qeos_specific"]
193-
paths["current_slm_plots_dir"] = paths["slm_plots_qeos_specific"]
194130

195-
# Ensure all paths are Path objects, handling cases where a key might not be set
196-
# if include_slm_paths is False and a 'current_slm_...' path was attempted to be accessed.
131+
# --- NEW PATH: Dynamic SLM Test Data Path ---
132+
if is_parametric_run:
133+
# Only create the /pSLM folder for tests if it's a parametric run
134+
paths["current_slm_tests_dir"] = (
135+
output_data_base
136+
/ DEFAULT_TEST_DATA_SUBDIR_NAME
137+
/ EOS_FOLDER_NAME
138+
/ DEFAULT_PSLM_SUBDIR_NAME # Always use 'pSLM' for parametric tests
139+
)
140+
else:
141+
# If not parametric, use the base testData/EOS_NAME folder
142+
paths["current_slm_tests_dir"] = (
143+
output_data_base
144+
/ DEFAULT_TEST_DATA_SUBDIR_NAME
145+
/ EOS_FOLDER_NAME
146+
)
147+
148+
# Ensure all paths are Path objects and filter out any None/non-Path values
197149
final_paths = {}
198150
for k, v in paths.items():
199151
if isinstance(v, Path):
200152
final_paths[k] = v
153+
elif include_slm_paths and k.startswith("current_slm_") and k in paths:
154+
final_paths[k] = paths[k]
201155

202156
return final_paths
203157

204158

205159
def create_necessary_dirs(paths: dict, additional_dirs: list[Path] = None):
206160
"""
207161
Creates directories for specified output and user-managed data paths if they do not already exist.
208-
This function focuses on creating directories that the application will write to.
209-
210-
Args:
211-
paths (dict): A dictionary of Path objects, typically obtained from get_paths().
212-
additional_dirs (list[Path], optional): A list of additional Path objects
213-
to create (e.g., user-input directories).
214-
Defaults to None.
215162
"""
163+
216164
# Define a list of keys corresponding to directories that should be created.
217-
# These are typically output directories or user-managed data directories.
218-
# This list should be exhaustive for all directories you intend your application to write to.
219-
# Note: 'current_*' paths are included as they are the effective targets for writing.
220165
output_directory_keys = [
221166
"plots_dir",
222167
"results_dir",
223-
"docs_dir", # If generated docs/reports go here
224-
"tests_dir", # If test reports/output go here
225-
"tutorials_dir", # If generated tutorial output goes here
168+
"docs_dir",
169+
"tests_dir",
170+
"tutorials_dir",
226171
"user_eos_data_dir",
227172
"user_tov_data_dir",
228173
"test_data_dir",
229174
"train_path",
230175
"generated_eos_files_dir",
231-
"qeos_path_specific",
232-
"mseos_path_specific",
233-
"qeos_tov_path_specific",
234-
"mseos_tov_path_specific",
235-
# SLM specific paths (will only be present in 'paths' if include_slm_paths was True)
236-
"slm_res_mseos_specific",
237-
"slm_res_qeos_specific",
238-
"slm_plots_mseos_specific",
239-
"slm_plots_qeos_specific",
240-
"slm_res_mseos_parametric_specific",
241-
"slm_res_qeos_parametric_specific",
242-
"slm_plots_mseos_parametric_specific",
243-
"slm_plots_qeos_parametric_specific",
244-
# The 'current' paths are the effective targets, so ensure they are also created
176+
177+
# The 'current' paths are the effective targets, so ensure they are created
245178
"current_eos_input_dir",
246179
"current_tov_data_dir",
247180
"current_slm_results_dir",
248181
"current_slm_plots_dir",
249-
# Removed "dmd_output_base_dir", "foo_files_dir", "dmd_input_dir" from here.
250-
# They will be passed dynamically via 'additional_dirs'.
182+
"current_slm_tests_dir", # <-- ADDED NEW PATH
183+
184+
# Kept for backward compatibility
185+
"qeos_path_specific",
186+
"mseos_path_specific",
187+
"qeos_tov_path_specific",
188+
"mseos_tov_path_specific",
251189
]
252190

253191
unique_dirs_to_create = set()
254192
for key in output_directory_keys:
255-
# Only add to the set if the key exists in 'paths' and its value is a Path object
256193
if key in paths and isinstance(paths[key], Path):
257194
unique_dirs_to_create.add(paths[key])
258195

@@ -268,4 +205,4 @@ def create_necessary_dirs(paths: dict, additional_dirs: list[Path] = None):
268205
path.mkdir(parents=True, exist_ok=True)
269206
print(f"Created directory: {path}")
270207
except OSError as e:
271-
print(f"Error creating directory {path}: {e}")
208+
print(f"Error creating directory {path}: {e}")

0 commit comments

Comments
 (0)