Skip to content

Commit c9af7c6

Browse files
committed
Update save_mat functionality for GUI usage. Fixes #1235.
1 parent 042b4a3 commit c9af7c6

2 files changed

Lines changed: 15 additions & 28 deletions

File tree

suite2p/gui/io.py

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -457,29 +457,12 @@ def save_iscell(parent):
457457

458458
def save_mat(parent):
459459
print("saving to mat")
460-
matpath = os.path.join(parent.basename, "Fall.mat")
461-
if "date_proc" in parent.ops:
462-
parent.ops["date_proc"] = []
463-
scipy.io.savemat(
464-
matpath, {
465-
"stat":
466-
parent.stat,
467-
"settings":
468-
parent.ops,
469-
"F":
470-
parent.Fcell,
471-
"Fneu":
472-
parent.Fneu,
473-
"spks":
474-
parent.Spks,
475-
"iscell":
476-
np.concatenate(
477-
(parent.iscell[:, np.newaxis], parent.probcell[:, np.newaxis]),
478-
axis=1),
479-
"redcell":
480-
np.concatenate((np.expand_dims(parent.redcell, axis=1),
481-
np.expand_dims(parent.probredcell, axis=1)), axis=1)
482-
})
460+
iscell = np.concatenate(
461+
(parent.iscell[:, np.newaxis], parent.probcell[:, np.newaxis]), axis=1)
462+
redcell = np.concatenate(
463+
(np.expand_dims(parent.redcell, axis=1), np.expand_dims(parent.probredcell, axis=1)), axis=1)
464+
ops = {**parent.ops, "save_path": parent.basename}
465+
io.save_mat(ops, parent.stat, parent.Fcell, parent.Fneu, parent.Spks, iscell, redcell)
483466

484467

485468
def save_merge(parent):

suite2p/io/save.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,15 @@ def save_mat(ops, stat, F, Fneu, spks, iscell, redcell,
6060
stat = np.array(stat, dtype=object)
6161

6262

63-
# Check for None values in ops_matlab and replace with empty arrays
64-
for k, v in ops_matlab.items():
65-
if v is None:
66-
logger.warning(f"ops_matlab['{k}'] is None, replacing with empty array")
67-
ops_matlab[k] = np.array([])
63+
# Check for None values in ops_matlab and replace with empty arrays in recursive manner
64+
def replace_none(d):
65+
for k, v in d.items():
66+
if v is None:
67+
logger.warning(f"'{k}' is None, replacing with empty array")
68+
d[k] = np.array([])
69+
elif isinstance(v, dict):
70+
replace_none(v)
71+
replace_none(ops_matlab)
6872

6973
# Handle None variables by replacing with empty arrays
7074
if redcell is None:

0 commit comments

Comments
 (0)