Skip to content

Commit

Permalink
[bug pathes] Issue #2,3,5,6
Browse files Browse the repository at this point in the history
  • Loading branch information
dvm-shlee committed Jun 2, 2020
1 parent be5f30e commit 0c2bb6f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
2 changes: 1 addition & 1 deletion brkraw/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .lib import *

__version__ = '0.3.3rc5'
__version__ = '0.3.3rc6'
__all__ = ['BrukerLoader', '__version__']


Expand Down
24 changes: 16 additions & 8 deletions brkraw/lib/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import re
np.set_printoptions(formatter={'float_kind':'{:f}'.format})


def load(path):
path = pathlib.Path(path)
if os.path.isdir(path):
Expand Down Expand Up @@ -201,15 +202,8 @@ def swap_slice_axis(group_id_, dataobj_):
dataobj = np.swapaxes(dataobj, slice_axis, -1)
dataobj = np.swapaxes(dataobj, 2, -1)

elif group_id[0] == 'FG_DIFFUSION':
dataobj = swap_slice_axis(group_id, dataobj)

elif group_id[0] == 'FG_DTI': # reconstructed
dataobj = swap_slice_axis(group_id, dataobj)

elif group_id[0] == 'FG_MOVIE':
elif group_id[0] in ['FG_DIFFUSION', 'FG_DTI', 'FG_MOVIE', 'FG_COIL', 'FG_CYCLE', 'FG_COMPLEX']:
dataobj = swap_slice_axis(group_id, dataobj)

else:
raise UnexpectedError(message='Unexpected frame group combination;'
f'{ISSUE_REPORT}')
Expand Down Expand Up @@ -389,6 +383,18 @@ def save_sitk(self, io_type=None):
def save_as(self):
return self.save_nifti

def _inspect_ids(self, scan_id, reco_id):
if scan_id not in self._avail.keys():
print(f'Invalid Scan ID.\n'
f'Your input: {scan_id}\n'
f'Available Scan IDs: {list(self._avail.keys())}')
raise KeyError
else:
if reco_id not in self._avail[scan_id]:
print(f'Invalid Reco ID.\n'
f'Your input: {reco_id}\n'
f'Available Reco IDs: {self._avail[scan_id]}')

def save_nifti(self, scan_id, reco_id, filename, dir='./', ext='nii.gz',
crop=None):
niiobj = self.get_niftiobj(scan_id, reco_id, crop=crop)
Expand Down Expand Up @@ -1050,6 +1056,8 @@ def _get_disk_slice_order(visu_pars):
return disk_slice_order

def _get_visu_pars(self, scan_id, reco_id):
# test validation of scan_id and reco_id here
self._inspect_ids(scan_id, reco_id)
return self._pvobj.get_visu_pars(scan_id, reco_id)

@staticmethod
Expand Down
13 changes: 4 additions & 9 deletions brkraw/scripts/brkraw.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ def main():
nii.add_argument("input", help=input_str, type=str)
nii.add_argument("-b", "--bids", help=bids_opt, action='store_true')
nii.add_argument("-o", "--output", help=output_fnm_str, type=str, default=False)
nii.add_argument("-r", "--recoid", help="RECO ID", type=int, default=1)
nii.add_argument("-s", "--scanid", help="Scan ID", type=str)
nii.add_argument("-r", "--recoid", help="RECO ID (default=1), option to specify a particular reco to convert",
type=int, default=1)
nii.add_argument("-s", "--scanid", help="Scan ID, option to specify a particular scan to convert.", type=str)

niiall.add_argument("input", help=input_dir_str, type=str)
niiall.add_argument("-o", "--output", help=output_dir_str, type=str)
Expand Down Expand Up @@ -153,15 +154,11 @@ def main():
os.mkdir(subj_path)
except OSError:
pass
else:
raise UnexpectedError
sess_path = os.path.join(subj_path, 'ses-{}'.format(study._pvobj.study_id))
try:
os.mkdir(sess_path)
except OSError:
pass
else:
raise UnexpectedError
for scan_id, recos in study._pvobj.avail_reco_id.items():
method = study._pvobj._method[scan_id].parameters['Method']
if re.search('epi', method, re.IGNORECASE) and not re.search('dti', method, re.IGNORECASE):
Expand All @@ -176,8 +173,6 @@ def main():
os.mkdir(output_path)
except OSError:
pass
else:
raise UnexpectedError
filename = 'sub-{}_ses-{}_{}'.format(study._pvobj.subj_id, study._pvobj.study_id,
str(scan_id).zfill(2))
for reco_id in recos:
Expand All @@ -188,7 +183,7 @@ def main():
if args.bids:
study.save_json(scan_id, reco_id, output_fname)
if re.search('dti', method, re.IGNORECASE):
study.save_bdata(scan_id, reco_id, output_fname)
study.save_bdata(scan_id, output_fname)
except Exception as e:
print(e)
print(f'{raw} is converted...')
Expand Down

0 comments on commit 0c2bb6f

Please sign in to comment.