Skip to content

Commit

Permalink
patch issue #79 and get_bdata function
Browse files Browse the repository at this point in the history
  • Loading branch information
dvm-shlee committed Feb 2, 2022
1 parent 946b76f commit de6cb1e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 22 deletions.
51 changes: 31 additions & 20 deletions brkraw/lib/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class BrukerLoader():
get_affine(scan_id, reco_id)
return affine transform matrix
get_bdata(scan_id, reco_id)
return bmat, bvec, bval as string
return bvals, bvecs, as string
get_scan_time(visu_pars=None)
return dictionary contains the datetime object for session initiate time
if visu_pars parameter object is given, it will contains scan start time
Expand Down Expand Up @@ -457,25 +457,29 @@ def save_nifti(self, scan_id, reco_id, filename, dir='./', ext='nii.gz',
# - FSL bval, bvec, and bmat
def save_bdata(self, scan_id, filename, dir='./'):
method = self._method[scan_id]
bval, bvec, bmat = self._get_bdata(method)
# bval, bvec, bmat = self._get_bdata(method) # [220201] bmat seems not necessary
bvals, bvecs = self._get_bdata(method)
output_path = os.path.join(dir, filename)

with open('{}.bval'.format(output_path), 'w') as bval_fobj:
for item in bval:
bval_fobj.write("%f " % item)
bval_fobj.write("\n")
# for item in bval: # [220201] correct the format
# bval_fobj.write("%f " % item)
# bval_fobj.write("\n")
bval_fobj.write(' '.join(bvals.astype('str')) + '\n')

with open('{}.bvec'.format(output_path), 'w') as bvec_fobj:
for row in bvec:
for item in row:
bvec_fobj.write("%f " % item)
bvec_fobj.write("\n")

with open('{}.bmat'.format(output_path), 'w') as bmat_fobj:
for row in bmat:
for item in row.flatten():
bmat_fobj.write("%s " % item)
bmat_fobj.write("\n")
# for row in bvec: # [220201] correct the format
# for item in row:
# bvec_fobj.write("%f " % item)
# bvec_fobj.write("\n")
for row in bvecs:
bvec_fobj.write(' '.join(row.astype('str')) + '\n')

# with open('{}.bmat'.format(output_path), 'w') as bmat_fobj: # [220201] remove bmat
# for row in bmat:
# for item in row.flatten():
# bmat_fobj.write("%s " % item)
# bmat_fobj.write("\n")

# BIDS JSON
def _parse_json(self, scan_id, reco_id, metadata=None):
Expand Down Expand Up @@ -648,7 +652,7 @@ def info(self, io_handler=None):
for i, (scan_id, recos) in enumerate(self._avail.items()):
for j, reco_id in enumerate(recos):
visu_pars = self._get_visu_pars(scan_id, reco_id)
if i == 0:
if i == 0 and j == 0:
sw_version = get_value(visu_pars, 'VisuCreatorVersion')

title = 'Paravision {}'.format(sw_version)
Expand Down Expand Up @@ -810,10 +814,17 @@ def _get_temp_info(self, visu_pars):
# DTI
@staticmethod
def _get_bdata(method):
bval = get_value(method, 'PVM_DwEffBval')
bvec = get_value(method, 'PVM_DwGradVec').T # to have three rows instead of three columns
bmat = get_value(method, 'PVM_DwBMat')
return bval, bvec, bmat
# [220201] parse the input value directly instead of final values & remove bmat
# bval = get_value(method, 'PVM_DwEffBval')
# bvec = get_value(method, 'PVM_DwGradVec').T # to have three rows instead of three columns
# bmat = get_value(method, 'PVM_DwBMat')
# return bval, bvec, bmat
bval = get_value(method, 'PVM_DwBvalEach')
num_b0 = get_value(method, 'PVM_DwAoImages')
num_dir = get_value(method, 'PVM_DwNDiffExp')
bvals = np.r_[np.zeros(num_b0), np.ones(num_dir - num_b0) * bval]
bvecs = np.r_[np.zeros([num_b0, 3]), get_value(method, 'PVM_DwDir')].T
return bvals, bvecs

This comment has been minimized.

Copy link
@jeremie-fouquet

jeremie-fouquet Oct 24, 2022

Contributor

@dvm-shlee: was there a good reason to switch from effective diffusion b-values and b-vec (PVM_DwEffBval and PVM_DwGradVec) to the requested ones (PVM_DwBvalEach and PVM_DwDir)?

I would argue that the effective values are much more useful than the requested ones.

Also, the requested parameters do not hold the b0 scans, and the way this is handled here does not account correctly for b0 scans at any other place than at the beginning of the diffusion scheme. This led to issue #90.

I'd suggest going back to the effective parameters, as @araikes suggested in issue #90.

This comment has been minimized.

Copy link
@gdevenyi

gdevenyi Oct 25, 2022

Collaborator

Probably should open a full issue with this comment for visibility.


# Generals
@staticmethod
Expand Down
3 changes: 1 addition & 2 deletions brkraw/scripts/brkraw.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,12 +375,11 @@ def main():
if len(filtered_dset):
subj_id = list(set(filtered_dset['SubjID']))[0]
subj_code = 'sub-{}'.format(subj_id)

# append to participants.tsv one record
with open(os.path.join(root_path, 'participants.tsv'), 'a+') as f:
f.write(subj_code + '\n')

filtered_dset = completeFieldsCreateFolders(df, filtered_dset, dset, multi_session, root_path, subj_code)
filtered_dset = completeFieldsCreateFolders(df, filtered_dset, dset, include_session, root_path, subj_code)

list_tested_fn = []
# Converting data according to the updated sheet
Expand Down

0 comments on commit de6cb1e

Please sign in to comment.