Skip to content

Commit a63de12

Browse files
Updating troublesome path behaviour in old make data helpers.
1 parent d9adb26 commit a63de12

3 files changed

Lines changed: 50 additions & 34 deletions

File tree

RMtools_1D/mk_test_ascii_data.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import os
5151
import shutil
5252
import sys
53+
from pathlib import Path
5354

5455
import numpy as np
5556

@@ -306,20 +307,24 @@ def create_IQU_ascii_data(
306307
# Create the output directory path
307308
dataPath = dataPath.rstrip("/")
308309
print("Creating test dataset in '%s/'" % dataPath)
309-
dirs = dataPath.split("/")
310-
for i in range(1, len(dirs)):
311-
dirStr = "/".join(dirs[:i])
312-
if not os.path.exists(dirStr):
313-
os.mkdir(dirStr)
314-
if os.path.exists(dataPath):
315-
print("\n ", end=" ")
316-
print("*** WARNING ***" * 5)
317-
print(" About to delete existing data directory!", end=" ")
318-
print("Previous results will be deleted.\n")
319-
print("Press <RETURN> to continue ...", end=" ")
320-
input()
321-
shutil.rmtree(dataPath, True)
322-
os.mkdir(dataPath)
310+
if not Path(dataPath).exists():
311+
Path(dataPath).mkdir(parents=True)
312+
313+
# dirs = dataPath.split("/")
314+
# print(dirs)
315+
# for i in range(1, len(dirs)):
316+
# dirStr = "/".join(dirs[:i])
317+
# if not os.path.exists(dirStr):
318+
# os.mkdir(dirStr)
319+
# if os.path.exists(dataPath):
320+
# print("\n ", end=" ")
321+
# print("*** WARNING ***" * 5)
322+
# print(" About to delete existing data directory!", end=" ")
323+
# print("Previous results will be deleted.\n")
324+
# print("Press <RETURN> to continue ...", end=" ")
325+
# input()
326+
# shutil.rmtree(dataPath, True)
327+
# os.mkdir(dataPath)
323328

324329
# Loop through the sources, calculate the spectra and save to disk
325330
successCount = 0

RMtools_3D/mk_test_cube_data.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
import os
8080
import shutil
8181
import sys
82+
from pathlib import Path
8283

8384
import astropy.wcs.wcs as pw
8485
import numpy as np
@@ -312,22 +313,24 @@ def create_IQU_cube_data(
312313
sys.exit()
313314
catInLst = csv_read_to_list(inCatFile, doFloat=True)
314315
print("Found %d entries in the catalogue." % len(catInLst))
315-
316-
# Create the output directory path
317-
dirs = dataPath.rstrip("/").split("/")
318-
for i in range(1, len(dirs)):
319-
dirStr = "/".join(dirs[:i])
320-
if not os.path.exists(dirStr):
321-
os.mkdir(dirStr)
322-
if os.path.exists(dataPath):
323-
print("\n ", end=" ")
324-
print("*** WARNING ***" * 5)
325-
print(" About to delete existing data directory!", end=" ")
326-
print("Previous results will be deleted.\n")
327-
print("Press <RETURN> to continue ...", end=" ")
328-
input()
329-
shutil.rmtree(dataPath, True)
330-
os.mkdir(dataPath)
316+
if not Path(dataPath).exists():
317+
Path(dataPath).mkdir(parents=True)
318+
319+
# # Create the output directory path
320+
# dirs = dataPath.rstrip("/").split("/")
321+
# for i in range(1, len(dirs)):
322+
# dirStr = "/".join(dirs[:i])
323+
# if not os.path.exists(dirStr):
324+
# os.mkdir(dirStr)
325+
# if os.path.exists(dataPath):
326+
# print("\n ", end=" ")
327+
# print("*** WARNING ***" * 5)
328+
# print(" About to delete existing data directory!", end=" ")
329+
# print("Previous results will be deleted.\n")
330+
# print("Press <RETURN> to continue ...", end=" ")
331+
# input()
332+
# shutil.rmtree(dataPath, True)
333+
# os.mkdir(dataPath)
331334

332335
# Create simple HDUs in memmory
333336
print("Creating test data in memory.")

tests/helper_test.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,12 @@ def setUp(self):
112112

113113
def test_testdata3D(self):
114114
"""Test that rmtools_testdata3D runs and outputs."""
115+
115116
res = subprocess.run(
116117
[
117118
"rmtools_testdata3D",
118119
f"{TEST_PATH}/../RMtools_3D/catalogue.csv",
119-
"./simdata/3D",
120+
f"{THREED_PATH}",
120121
]
121122
)
122123
self.assertEqual(res.returncode, 0, "testdata3D fails to run to completion.")
@@ -128,24 +129,31 @@ def test_testdata3D(self):
128129

129130
def test_testdata1D(self):
130131
"""Test that rmtools_testdata1D runs and outputs."""
132+
131133
res = subprocess.run(
132134
[
133135
"rmtools_testdata1D",
134136
f"{TEST_PATH}/../RMtools_3D/catalogue.csv",
135-
"./simdata/1D",
137+
f"{ONED_PATH}",
136138
]
137139
)
138140
self.assertEqual(res.returncode, 0, "testdata1D fails to run to completion.")
139141

140142
self.assertTrue(
141-
(TEST_PATH / "simdata/1D/Source8.dat").exists(),
143+
(ONED_PATH / "Source8.dat").exists(),
142144
"testdata1D not outputting files as expected.",
143145
)
144146

145147
def test_calcRMSF(self):
146148
"""Test that rmtools_calcRMSF runs as expected."""
149+
150+
if not ONED_PATH.exists():
151+
ONED_PATH.mkdir(parents=True)
152+
147153
res = subprocess.run(
148-
shlex.split("rmtools_calcRMSF -f 800e6 1088e6 1e6 -s ./simdata/rmsf.png"),
154+
shlex.split(
155+
f"rmtools_calcRMSF -f 800e6 1088e6 1e6 -s {TEST_PATH}/rmsf.png"
156+
),
149157
capture_output=True,
150158
text=True,
151159
)

0 commit comments

Comments
 (0)