Skip to content

Commit

Permalink
add save_pkl to group result
Browse files Browse the repository at this point in the history
  • Loading branch information
matsvanes committed Sep 10, 2024
1 parent 3c73627 commit e8588f6
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions osl/glm/glm_epochs.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,40 @@ def get_fl_contrast(self, fl_con):
ret_con.data = ret_con.data[:, fl_con, :, :]

return ret_con

def save_pkl(self, outname, overwrite=True, save_data=False):
"""Save GLM-Epochs result to a pickle file.
Parameters
----------
outname : str
Filename or full file path to write pickle to
overwrite : bool
Overwrite previous file if one exists? (Default value = True)
save_data : bool
Save epochs data in pickle? This is omitted by default to save disk
space (Default value = False)
"""
if Path(outname).exists() and not overwrite:
msg = "{} already exists. Please delete or do use overwrite=True."
raise ValueError(msg.format(outname))

if hasattr(self, 'config'):
self.config.detrend_func = None # Have to drop this to pickle

# This is hacky - but pickles are all or nothing and I don't know how
# else to do it. HDF5 would be better longer term
if save_data == False:
# Temporarily remove data before saving
dd = self.data
self.data = None

with open(outname, 'bw') as outp:
pickle.dump(self, outp)

# Put data back
if save_data == False:
self.data = dd

#%% ------------------------------------------------------

Expand Down

0 comments on commit e8588f6

Please sign in to comment.