Skip to content

Commit 029fe6a

Browse files
Merge pull request #249 from SyneRBI/fix-working-path
add & fix `exercises_working_path`
2 parents a239c0b + 00669ac commit 029fe6a

File tree

5 files changed

+15
-12
lines changed

5 files changed

+15
-12
lines changed

lib/sirf_exercises/__init__.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ def exercises_data_path(*data_type):
3838
return os.path.join(data_path, *data_type)
3939

4040

41-
def cd_to_working_dir(*subfolders):
41+
42+
def exercises_working_path(*subfolders):
4243
'''
43-
Creates and changes the current directory to a working directory for the
44+
Creates and returns the working directory for the
4445
current exercise, based on the argument(s). If multiple
4546
strings are given, they will be treated as subdirectories.
4647
@@ -56,5 +57,9 @@ def cd_to_working_dir(*subfolders):
5657
except ImportError:
5758
working_dir = exercises_data_path('working_folder', *subfolders)
5859
os.makedirs(working_dir, exist_ok=True)
59-
os.chdir(working_dir)
60+
return working_dir
6061

62+
63+
def cd_to_working_dir(*subfolders):
64+
'''Same as os.chdir(exercises_working_path(*subfolders))'''
65+
os.chdir(exercises_working_path(*subfolders))

notebooks/Synergistic/BrainWeb.ipynb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,11 @@
7070
"import sirf.Reg as reg\n",
7171
"from math import cos, sin, pi\n",
7272
"from sirf.Utilities import examples_data_path\n",
73-
"from sirf_exercises import exercises_data_path\n",
73+
"from sirf_exercises import cd_to_working_dir\n",
7474
"import shutil\n",
7575
"from scipy.ndimage import gaussian_filter\n",
7676
"\n",
77-
"wd = exercises_data_path('working_folder', 'Synergistic', 'BrainWeb')\n",
78-
"makedirs(wd, exist_ok=True)\n",
79-
"chdir(wd)"
77+
"cd_to_working_dir('Synergistic', 'BrainWeb')"
8078
]
8179
},
8280
{

notebooks/Synergistic/Dual_PET.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
"outputs": [],
9797
"source": [
9898
"# copy files to working folder and change directory to where the output files are\n",
99-
"brainweb_sim_data_path = exercises_data_path('working_folder', 'Synergistic', 'BrainWeb')\n",
99+
"brainweb_sim_data_path = exercises_working_path('Synergistic', 'BrainWeb')\n",
100100
"\n",
101101
"fname_FDG_sino = os.path.join(brainweb_sim_data_path, 'FDG_sino_noisy.hs')\n",
102102
"fname_FDG_uMap = os.path.join(brainweb_sim_data_path, 'uMap_small.hv')\n",

notebooks/Synergistic/HKEM_reconstruction.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@
101101
"#import scipy\n",
102102
"#from scipy import optimize\n",
103103
"import sirf.STIR as pet\n",
104-
"from sirf_exercises import exercises_data_path\n",
104+
"from sirf_exercises import exercises_working_path\n",
105105
"\n",
106-
"brainweb_sim_data_path = exercises_data_path('working_folder', 'Synergistic', 'BrainWeb')"
106+
"brainweb_sim_data_path = exercises_working_path('Synergistic', 'BrainWeb')"
107107
]
108108
},
109109
{

notebooks/Synergistic/MAPEM_Bowsher.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@
7575
"from scipy.ndimage.filters import gaussian_filter\n",
7676
"import sirf.STIR as pet\n",
7777
"from numba import jit\n",
78-
"from sirf_exercises import exercises_data_path\n",
78+
"from sirf_exercises import exercises_working_path\n",
7979
"\n",
80-
"brainweb_sim_data_path = exercises_data_path('working_folder', 'Synergistic', 'BrainWeb')\n",
80+
"brainweb_sim_data_path = exercises_working_path('Synergistic', 'BrainWeb')\n",
8181
"# set-up redirection of STIR messages to files\n",
8282
"msg_red = pet.MessageRedirector('info.txt', 'warnings.txt', 'errors.txt')\n",
8383
"# plotting settings\n",

0 commit comments

Comments
 (0)