"--n_jobs", str(args.n_jobs),
              "--factor_background",str(factor_background),
              "--o_size",str(o_size),
              "--d_size",str(d_size),
              "--narrow_band",
              "--n_estimators", str(n_estimators),
              "--n_tests", str(n_tests),
              "--max_depth", str(max_depth) ] )
    if not_centered:
        cmd.append( "--not_centered" )
    if heart_only:
        cmd.append( "--heart_only" )

    if shape_model or args.shape_model_only:
        cmd_shape_model = ( [ "python", "shape_model.py",
                              "--seg" ] + seg_files +
                            [ "--output_folder", output_folder + "/" + patient_id,
                              "--n_jobs", str(args.n_jobs) ] )
        if args.shape_model_only:
            cmd = cmd_shape_model
        else:
            cmd = cmd_shape_model + ["&&"] + cmd
        
    sbatch( cmd,
            mem=args.mem,
            c=args.n_jobs,
            partition=args.partition,
            verbose=args.verbose,
            dryrun=args.dryrun )

sys.path.insert(1, "../commonlib")
from SimpleSlurm import sbatch

n_jobs = 1
mem = 50
partition = "long"

detection_folder = "/vol/vipdata/data/fetal_data/OUTPUT/whole_body_shape_padding50/"

all_files = sorted(glob(detection_folder + "/*/prediction_2/img.nii.gz"))

for f in all_files:
    dirname = f[: -len("img.nii.gz")]

    cmd = [
        "python",
        "segment_random_walker.py",
        "--img",
        f,
        "--seg",
        dirname + "/final_seg.nii.gz",
        "--output",
        dirname + "/rw10.nii.gz",
        "--narrow_band",
        str(10),
        "--thorax",
    ]

    sbatch(cmd, mem=mem, c=n_jobs, partition=partition, verbose=False, dryrun=False)
sys.path.append("lib")
from SimpleSlurm import sbatch

n_jobs = 5

ground_truth_folder = "/vol/bitbucket/kpk09/detector/data_resampled"
output_folder = "/vol/medic02/users/kpk09/OUTPUT/stage1_prediction"
heart_only = True
detector = "/vol/medic02/users/kpk09/OUTPUT/stage1"

all_files = sorted(glob(ground_truth_folder+'/*_img.nii.gz'))

for f in all_files:
    patient_id = os.path.basename(f)[:-len("_img.nii.gz")]

    if os.path.exists( output_folder + "/" + patient_id + "/votes_heart.nii.gz"):
        continue
    
    cmd = [ "python", "predict.py",
            "--input", f ,
            "--output", output_folder + "/" + patient_id,
            "--detector", detector + "/" + patient_id,
            "--chunk_size", str(int(1e5)),
            "--n_jobs", str(n_jobs),
            "--narrow_band"
            ] 
    if heart_only:
        cmd.append( "--heart_only" )
        
    sbatch( cmd, mem=30, c=n_jobs, verbose=False, dryrun=True )