Skip to content

Commit

Permalink
Fixes bug in oarsub command
Browse files Browse the repository at this point in the history
1. Executes program with mpiexec when using oarsub that was missed
before.

2. Adds notebooks to create mu images with different values.
  • Loading branch information
bishesh committed Feb 29, 2016
1 parent e48fd09 commit a1135d0
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
results/
diagnostics/
build/
buildNewNef/

/src/Makefile
/GPATH
Expand Down
9 changes: 3 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ set(CMAKE_CXX_COMPILER ${PETSC_COMPILER})
#Home directory
if(IS_CLUSTER)
if(IS_NEW_CLUSTER)
set(MY_HOME /data/asclepios/user/bkhanal/softwares)
set(ITK_DIR ${MY_HOME}/ITK-build)
set(ITK_DIR /data/asclepios/user/bkhanal/softwares/ITK-build)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
# This part taken from: http://stackoverflow.com/questions/10851247/how-to-activate-c-11-in-cmake
include(CheckCXXCompilerFlag)
Expand All @@ -36,14 +35,12 @@ if(IS_CLUSTER)
message("setting up for new cluster")

else(IS_NEW_CLUSTER)
set(MY_HOME /epi/asclepios2/bkhanal)
set(ITK_DIR ${MY_HOME}/ITK-build)
set(ITK_DIR /epi/asclepios2/bkhanal/ITK-build)
message("setting up for legacy cluster")
endif(IS_NEW_CLUSTER)

else(IS_CLUSTER)
set(MY_HOME /home/bkhanal)
set(ITK_DIR ${MY_HOME}/Documents/softwares/ITK-build)
set(ITK_DIR /home/bkhanal/Documents/softwares/ITK-build)
set(CMAKE_EXPORT_COMPILE_COMMANDS on) #Will generate compile_commands.json file used by irony-mode in emacs code completion.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
# This part taken from: http://stackoverflow.com/questions/10851247/how-to-activate-c-11-in-cmake
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"cells": [],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 0
}
114 changes: 114 additions & 0 deletions notebooks/create_image_from_labels.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Create images using label images and tables of desired values"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import sys\n",
"sys.path.insert(0, '../scripts')\n",
"\n",
"def create_table_file(fname, header, label_value_pairs):\n",
" '''\n",
" Write a new file which starts with header and then writes\n",
" in each line the label_value_pairs given as a list.\n",
" '''\n",
" with open(fname, 'w') as fil:\n",
" fil.write(header)\n",
" for pair in label_value_pairs:\n",
" fil.write('%s\\t%s\\n' % (pair[0], pair[1]))\n",
" return\n",
"\n",
"def create_image(img_file, label_value_pairs, label_img, modify_img=None):\n",
" '''\n",
" Creates image by putting values present in label_value_pairs in \n",
" the selected labels in corresponding ROIs present in label_img.\n",
" If modify_img is given update it instead of creating a new image\n",
" with zero in all regions where the asked label is not present.\n",
" '''\n",
" import bish_utils as bu\n",
" tbl_fl = 'tmp++table'\n",
" header = 'labels\\tnewValues\\n'\n",
" create_table_file(tbl_fl, header, label_value_pairs)\n",
" cmd = ('../build/src/createImageFromLabelImage -t %s -l %s -o %s'\n",
" % (tbl_fl, label_img, img_file))\n",
" if modify_img:\n",
" cmd += ' -m %s' % (modify_img)\n",
" bu.print_and_execute(cmd)\n",
" bu.print_and_execute('rm %s' % tbl_fl)\n",
" "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import os as os\n",
"import os.path as op\n",
"\n",
"in_img_dir = '/proj/asclepios/cluster/asclepios2/bkhanal/works/AdLemModel/results/patients/miriad_189_AD_M_10_MR_1'\n",
"#in_img_dir = '../results/patients/miriad_189_AD_M_10_MR_1'\n",
"\n",
"csf_model_label = op.join(in_img_dir, 'maskwithCsfD2R0.nii.gz')\n",
"#aseg_label = op.join(in_img_dir, 'aseg_cropped.nii.gz')\n",
"aseg_label = op.join(in_img_dir, 'labelsWithCsfD2R0.nii.gz')\n",
"\n",
"out_img_dir = in_img_dir\n",
"out_img = op.join(out_img_dir, 'muImageWmBstem10_GmCsf1.nii.gz')\n",
"\n",
"# make all tissue and CSF 1 first\n",
"lab_val = [(1, 1), (2, 1)]\n",
"create_image(out_img, lab_val, csf_model_label)\n",
"\n",
"# change labels of Brain stem and WM\n",
"h_val = 10\n",
"lab_val = [(16, h_val), (28, h_val), (60, h_val), (41, h_val), (2, h_val), (46, h_val), (7, h_val)]\n",
"create_image(out_img, lab_val, aseg_label, out_img)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.10"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
11 changes: 7 additions & 4 deletions scripts/runAdLemModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,11 @@ def main():
work_dir = os.getenv('ADLEM_DIR')
if work_dir is None:
raise ValueError('environment variable ADLEM_DIR not set.')
target = op.join(work_dir, 'build/src/AdLemMain')

ops = get_input_options()
if ops.in_new_cluster:
target = op.join(work_dir, 'buildNewNef/src/AdLemMain')
else:
target = op.join(work_dir, 'build/src/AdLemMain')
res_dir = op.join(work_dir, 'results/patients', ops.patient)
in_img = op.join(res_dir, ops.in_img)
atrophy = op.join(res_dir, ops.atrophy)
Expand Down Expand Up @@ -156,10 +158,11 @@ def main():
#procs='nodes=5:xeon:ppn=20', mem='mem=900gb',
dest_dir=res_dir, cmd=cmd)
elif ops.in_new_cluster:
# oarsub inline requires job command to be in quotes.
cluster_mpi = '/opt/openmpi/gcc/current/bin/mpiexec '
cmd = cluster_mpi + cmd
job_name = '%sSteps%s' % (ops.res_prefix, ops.time_steps)
if not ops.res:
ops.res = '/nodes=3/core=24,walltime=02:00:00'
ops.res = '/nodes=6/core=24,walltime=01:30:00'
# if not ops.prop:
# ops.prop = '"cputype=\'xeon\'"'
bu.oarsub_job(ops.res, ops.prop, res_dir, job_name, cmd)
Expand Down

0 comments on commit a1135d0

Please sign in to comment.