Skip to content

Commit

Permalink
- config file separation script and sct_run_batch
Browse files Browse the repository at this point in the history
- yaml parser must point towards required yaml file with flag -i
  • Loading branch information
PaulBautin committed Aug 3, 2020
1 parent ab13653 commit ba949f4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
10 changes: 5 additions & 5 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ transfo:
bounds:
angle_bound: 5
shift_bound: 2.5

# config file for sct_run_batch
path_data : "data"
path_output : "csa_atrophy_results_t2"
script : "process_data.sh"
jobs : -1
#path_data : "data"
#path_output : "csa_atrophy_results_t2"
#script : "process_data.sh"
#jobs : -1
5 changes: 5 additions & 0 deletions config_sct_run_batch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# config file for sct_run_batch
path_data : "data"
path_output : "csa_atrophy_results_t2"
script : "process_data.sh"
jobs : -1
8 changes: 4 additions & 4 deletions process_data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ SUBJECT=$1
# The following global variables are retrieved from config.yaml file
# set n_transfo to the desired number of transformed images of same subject for segmentation,
# n_transfo also represents the number of iterations of the transformation, segmentation and labeling process
n_transfo=$(yaml_parser -o n_transfo)
n_transfo=$(yaml_parser -o n_transfo -i config.yaml)
# define rescaling coefficients (always keep value 1 for reference)
rescaling=$(yaml_parser -o rescaling)
rescaling=$(yaml_parser -o rescaling -i config.yaml)
R_COEFS=$(echo $rescaling | tr '[]' ' ' | tr ',' ' ' | tr "'" ' ')
contrast=$(yaml_parser -o contrast)
contrast=$(yaml_parser -o contrast -i config.yaml)
if [ $contrast == "t2" ]; then
contrast_str="T2w"
fi
if [ $contrast == "t1" ]; then
contrast_str="T1w"
fi
path_output=$(yaml_parser -o path_output)
path_output=$(yaml_parser -o path_output -i config_sct_run_batch.yml)


# FUNCTIONS
Expand Down
7 changes: 6 additions & 1 deletion yaml_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ def get_parser():
required=True,
help="parameters to output from config.yaml",
)
mandatory.add_argument(
"-i",
required=True,
help="input path to configuration of file",
)
optional = parser.add_argument_group("\nOPTIONAL ARGUMENTS")
optional.add_argument(
'-h',
Expand All @@ -43,7 +48,7 @@ def main():
parser = get_parser()
arguments = parser.parse_args(args=None if sys.argv[0:] else ['--help'])
# Read yaml file
with open("config.yaml", 'r') as config_var:
with open(arguments.i, 'r') as config_var:
data_loaded = yaml.safe_load(config_var)
# print yaml file parameters to be read by bash script
print(data_loaded[arguments.o])

0 comments on commit ba949f4

Please sign in to comment.