Skip to content

Commit

Permalink
Force saving seldict
Browse files Browse the repository at this point in the history
  • Loading branch information
emdupre committed May 10, 2018
1 parent 756e8d5 commit 968dda0
Showing 1 changed file with 6 additions and 27 deletions.
33 changes: 6 additions & 27 deletions tedana/interfaces/tedana.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,8 +650,8 @@ def fitmodels_direct(catd, mmix, mask, t2s, t2sG, tes, combmode, ref_img,
return seldict, comptab, betas, mmix_new


def selcomps(seldict, mmix, mask, ref_img, manacc, n_echos, t2s, s0, olevel=2, oversion=99,
filecsdata=False, savecsdiag=True, strict_mode=False):
def selcomps(seldict, mmix, mask, ref_img, manacc, n_echos, t2s, s0, olevel=2,
oversion=99, savecsdiag=True, strict_mode=False):
"""
Labels components in `mmix`
Expand All @@ -674,8 +674,6 @@ def selcomps(seldict, mmix, mask, ref_img, manacc, n_echos, t2s, s0, olevel=2, o
Default: 2
oversion : int, optional
Default: 99
filecsdata: bool, optional
Default: False
savecsdiag: bool, optional
Default: True
strict_mode: bool, optional
Expand All @@ -692,23 +690,8 @@ def selcomps(seldict, mmix, mask, ref_img, manacc, n_echos, t2s, s0, olevel=2, o
ign : list
Indices of ignored components in `mmix`
"""

if filecsdata:
import bz2
if seldict is not None:
lgr.info('++ Saving component selection data')
csstate_f = bz2.BZ2File('compseldata.pklbz', 'wb')
pickle.dump(seldict, csstate_f)
csstate_f.close()
else:
try:
csstate_f = bz2.BZ2File('compseldata.pklbz', 'rb')
seldict = pickle.load(csstate_f)
csstate_f.close()
except FileNotFoundError:
lgr.warning('++ Failed to load component selection data')
return None

with open('compsel.json', 'w') as f:
json.dump(seldict, f)
# List of components
midk = []
ign = []
Expand Down Expand Up @@ -1749,7 +1732,7 @@ def writeresults_echoes(catd, mmix, mask, acc, rej, midk, ref_img):
def main(data, tes, mixm=None, ctab=None, manacc=None, strict=False,
no_gscontrol=False, kdaw=10., rdaw=1., conv=2.5e-5, ste=-1,
combmode='t2s', dne=False, initcost='tanh', finalcost='tanh',
stabilize=False, fout=False, filecsdata=False, label=None,
stabilize=False, fout=False, label=None,
fixed_seed=42):
"""
Parameters
Expand Down Expand Up @@ -1796,8 +1779,6 @@ def main(data, tes, mixm=None, ctab=None, manacc=None, strict=False,
Default is False.
fout : :obj:`bool`, optional
Save output TE-dependence Kappa/Rho SPMs. Default is False.
filecsdata : :obj:`bool`, optional
Save component selection data to file. Default is False.
label : :obj:`str` or :obj:`None`, optional
Label for output directory. Default is None.
fixed_seed : :obj:`int`, optional
Expand Down Expand Up @@ -1884,8 +1865,7 @@ def main(data, tes, mixm=None, ctab=None, manacc=None, strict=False,
np.savetxt(op.join(out_dir, 'meica_mix.1D'), mmix)

acc, rej, midk, empty = selcomps(seldict, mmix, mask, ref_img, manacc, n_echos, t2s, s0,
strict_mode=strict,
filecsdata=filecsdata)
strict_mode=strict)
else:
mmix_orig = np.loadtxt(op.join(out_dir, 'meica_mix.1D'))
seldict, comptable, betas, mmix = fitmodels_direct(catd, mmix_orig,
Expand All @@ -1896,7 +1876,6 @@ def main(data, tes, mixm=None, ctab=None, manacc=None, strict=False,
if ctab is None:
acc, rej, midk, empty = selcomps(seldict, mmix, mask, ref_img, manacc,
n_echos, t2s, s0,
filecsdata=filecsdata,
strict_mode=strict)
else:
acc, rej, midk, empty = ctabsel(ctab)
Expand Down

0 comments on commit 968dda0

Please sign in to comment.