Skip to content

Commit 591e863

Browse files
committed
default to os.getcwd() for saving plots
1 parent 9468a9b commit 591e863

3 files changed

Lines changed: 28 additions & 10 deletions

File tree

gnss_lib_py/utils/file_operations.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,22 @@ def get_timestamp():
3737
"""
3838
timestamp = time.strftime("%Y%m%d%H%M%S")
3939
return timestamp
40+
41+
def print_directory_levels():
42+
"""Prints out file directory levels.
43+
44+
"""
45+
46+
printed_path = os.path.realpath(__file__)
47+
48+
for level in range(5):
49+
print(f"{level} level(s) up: {printed_path}")
50+
printed_path = os.path.dirname(printed_path)
51+
52+
def print_cwd():
53+
"""Prints out file directory levels.
54+
55+
"""
56+
57+
print("cwd:",os.getcwd())
58+
print("dir above cwd:",os.path.dirname(os.getcwd()))

gnss_lib_py/utils/visualizations.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -670,11 +670,7 @@ def _save_figure(figures, titles=None, prefix="", fnames=None): # pragma: no cov
670670
if (len(fnames) == 1 and fnames[0] is None) \
671671
or fnames[fig_idx] is None:
672672
# create results folder if it does not yet exist.
673-
root_path = os.path.dirname(
674-
os.path.dirname(
675-
os.path.dirname(
676-
os.path.realpath(__file__))))
677-
log_path = os.path.join(root_path,"results",TIMESTAMP)
673+
log_path = os.path.join(os.getcwd(),"results",TIMESTAMP)
678674
fo.make_dir(log_path)
679675

680676
# make name path friendly
@@ -856,11 +852,7 @@ def _save_plotly(figures, titles=None, prefix="", fnames=None,
856852
if (len(fnames) == 1 and fnames[0] is None) \
857853
or fnames[fig_idx] is None:
858854
# create results folder if it does not yet exist.
859-
root_path = os.path.dirname(
860-
os.path.dirname(
861-
os.path.dirname(
862-
os.path.realpath(__file__))))
863-
log_path = os.path.join(root_path,"results",TIMESTAMP)
855+
log_path = os.path.join(os.getcwd(),"results",TIMESTAMP)
864856
fo.make_dir(log_path)
865857

866858
# make name path friendly

tests/utils/test_file_operations.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,10 @@ def test_get_timestamp():
2020

2121
# timestamp should all be numeric characters
2222
assert timestamp.isnumeric()
23+
24+
def test_directory_printing():
25+
"""Test directory printing functions.
26+
27+
"""
28+
fo.print_directory_levels()
29+
fo.print_cwd()

0 commit comments

Comments
 (0)