Skip to content
Snippets Groups Projects
Commit e12997f5 authored by chaskar2's avatar chaskar2
Browse files

added default value for base_path

parent 61318e11
Branches assignment1.2
No related tags found
No related merge requests found
......@@ -213,8 +213,8 @@ def imageflow_dag(**dag_input):
# Create the base path directory if it doesn't exist
if not os.path.exists(f"{Variable.get('base_path')}"):
os.mkdir(f"{Variable.get('base_path')}")
if not os.path.exists(f"{Variable.get('base_output_path', 'placeholder')}"):
os.mkdir(f"{Variable.get('base_output_path', 'placeholder')}")
# Load the scan configuration from the file
with open("/scan_params/scan_config.json", "r") as conf:
......@@ -227,8 +227,8 @@ def imageflow_dag(**dag_input):
curr_conf_dict = prepare_current_scan_config(scan_config, tumor_activity_choice)
# Save the current scan configuration to a file
with open(f"{Variable.get('base_path')}/curr_scan_config.json", "w+") as curr_conf:
print(f"Directory scan params written to: {Variable.get('base_path')}")
with open(f"{Variable.get('base_output_path', 'placeholder')}/curr_scan_config.json", "w+") as curr_conf:
print(f"Directory scan params written to: {Variable.get('base_output_path', 'placeholder')}")
json.dump(curr_conf_dict, curr_conf)
return 0
......@@ -241,9 +241,9 @@ def imageflow_dag(**dag_input):
# TODO: Copy all macros file data files
shutil.copytree('/gate_output/NCSA_RubInWater/Macros', f"{Variable.get('base_path')}/Macros")
shutil.copytree('/gate_output/NCSA_RubInWater/Data', f"{Variable.get('base_path')}/Data")
shutil.copy('/gate_output/NCSA_RubInWater/main.mac', f"{Variable.get('base_path')}/main.mac")
shutil.copytree('/gate_output/NCSA_RubInWater/Macros', f"{Variable.get('base_output_path', 'placeholder')}/Macros")
shutil.copytree('/gate_output/NCSA_RubInWater/Data', f"{Variable.get('base_output_path', 'placeholder')}/Data")
shutil.copy('/gate_output/NCSA_RubInWater/main.mac', f"{Variable.get('base_output_path', 'placeholder')}/main.mac")
return 0
......@@ -259,20 +259,20 @@ def imageflow_dag(**dag_input):
# TODO: Replace the macros with user selected values
# Open the current scan configuration file
with open(f"{Variable.get('base_path')}/curr_scan_config.json", "r+") as curr_conf:
with open(f"{Variable.get('base_output_path', 'placeholder')}/curr_scan_config.json", "r+") as curr_conf:
curr_conf = json.load(curr_conf)
# Set the activity file property for the GATE simulation software
activity_file_property = "/gate/source/voxel_blob/imageReader/rangeTranslator/readTable"
activity_file_value = curr_conf["activity_file"]
set_macro_property(f"{Variable.get('base_path')}/Macros/VoxelizedSource.mac", activity_file_property, activity_file_value, f"{Variable.get('base_path')}/Macros/VoxelizedSource.mac")
set_macro_property(f"{Variable.get('base_output_path', 'placeholder')}/Macros/VoxelizedSource.mac", activity_file_property, activity_file_value, f"{Variable.get('base_output_path', 'placeholder')}/Macros/VoxelizedSource.mac")
main_mac_file = f"{Variable.get('base_path')}/main.mac"
main_mac_file = f"{Variable.get('base_output_path', 'placeholder')}/main.mac"
for component in range(20):
# Set the output file property for the GATE simulation software
new_mac_file = f"{Variable.get('base_path')}/main_{component}.mac"
new_mac_file = f"{Variable.get('base_output_path', 'placeholder')}/main_{component}.mac"
output_mac_file_property = "/control/execute"
original_output_file_value = "Macros/Output.mac"
......@@ -281,12 +281,12 @@ def imageflow_dag(**dag_input):
output_file_property = "/gate/output/root/setFileName"
output_file_value = f"Output/output_{component}.root"
set_macro_property(f"{Variable.get('base_path')}/Macros/Output.mac", output_file_property, output_file_value, f"{Variable.get('base_path')}/Macros/Output_{component}.mac")
set_macro_property(f"{Variable.get('base_output_path', 'placeholder')}/Macros/Output.mac", output_file_property, output_file_value, f"{Variable.get('base_output_path', 'placeholder')}/Macros/Output_{component}.mac")
# Create the Output directory if it doesn't exist
if not os.path.exists(f"{Variable.get('base_path')}/Output"):
os.makedirs(f"{Variable.get('base_path')}/Output")
if not os.path.exists(f"{Variable.get('base_output_path', 'placeholder')}/Output"):
os.makedirs(f"{Variable.get('base_output_path', 'placeholder')}/Output")
return 0
......@@ -305,10 +305,10 @@ def imageflow_dag(**dag_input):
print(f"Folder does not exist: {Variable.get('base_output_path', 'placeholder')}")
# Move the output files from the pipeline to the output directory
shutil.copytree(Variable.get('base_path'), Variable.get('base_output_path', 'placeholder'))
shutil.copytree(Variable.get('base_output_path', 'placeholder'), Variable.get('base_output_path', 'placeholder'))
# Remove the pipeline output directory
shutil.rmtree(Variable.get('base_path'))
shutil.rmtree(Variable.get('base_output_path', 'placeholder'))
# Copy the castor reconstruction script to the output directory
shutil.copy("/castor_files/castor_reconstruction.sh", Variable.get('base_output_path', 'placeholder'))
......@@ -338,7 +338,7 @@ def imageflow_dag(**dag_input):
get_image_statistics: Get layer wise mean values for the volume
"""
# Remove the output.root file from the base path
os.remove(f"{Variable.get('base_path')}/Output/output.root.root")
os.remove(f"{Variable.get('base_output_path', 'placeholder')}/Output/output.root.root")
img_mean_stats = []
......@@ -384,7 +384,7 @@ def imageflow_dag(**dag_input):
img_mean_stats, img_sd_stats = get_image_statistics(stack_of_images)
with open('/castor_files/stats_output/img_statistics.csv','a') as fd:
fd.write(f"{Variable.get('base_path')},{img_mean_stats},{img_sd_stats}\n")
fd.write(f"{Variable.get('base_output_path', 'placeholder')},{img_mean_stats},{img_sd_stats}\n")
print("Statistics written to file")
return 0
......@@ -429,7 +429,7 @@ def imageflow_dag(**dag_input):
volumes=[gate_volume, gate_output_volume, gate_scan_params_volume, gate_output_pipeline_volume],
volume_mounts=[gate_volume_mount, gate_output_volume_mount, gate_scan_params_volume_mount, gate_output_pipeline_volume_mount],
cmds=["/gate_files/gate_runner/runGate.sh"],
arguments=[Variable.get('base_path'), f"main_{i}.mac"],
arguments=[Variable.get('base_output_path', 'placeholder'), f"main_{i}.mac"],
execution_timeout = timedelta(minutes=30),
get_logs=True,
affinity={
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment