Skip to content

Commit

Permalink
Merge pull request #677 from suny-downstate-medical-center/dipole-sum…
Browse files Browse the repository at this point in the history
…-save-load-improvements

added saving and gathering 'LFPPops' and 'dipoleSum' where it was missing
  • Loading branch information
vvbragin authored Apr 15, 2022
2 parents eeb677f + 12ce252 commit 522f377
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
16 changes: 16 additions & 0 deletions netpyne/sim/gather.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ def gatherData(gatherLFP=True, gatherDipole=True):
for k in list(gather[0]['simData'].keys()): # initialize all keys of allSimData dict
if gatherLFP and k == 'LFP':
sim.allSimData[k] = np.zeros((gather[0]['simData']['LFP'].shape))
elif gatherLFP and k == 'LFPPops':
sim.allSimData[k] = {p: np.zeros(gather[0]['simData']['LFP'].shape) for p in gather[0]['simData']['LFPPops'].keys()}
elif gatherDipole and k == 'dipoleSum':
sim.allSimData[k] = np.zeros((gather[0]['simData']['dipoleSum'].shape))
elif sim.cfg.recordDipolesHNN and k == 'dipole':
Expand Down Expand Up @@ -136,6 +138,9 @@ def gatherData(gatherLFP=True, gatherDipole=True):
sim.allSimData[key] = list(sim.allSimData[key])+list(val) # udpate simData dicts which are Vectors
elif gatherLFP and key == 'LFP':
sim.allSimData[key] += np.array(val)
elif gatherLFP and key == 'LFPPops':
for p in val:
sim.allSimData[key][p] += np.array(val[p])
elif gatherDipole and key == 'dipoleSum':
sim.allSimData[key] += np.array(val)
elif key not in singleNodeVecs:
Expand Down Expand Up @@ -175,6 +180,8 @@ def gatherData(gatherLFP=True, gatherDipole=True):
for k in list(gather[0]['simData'].keys()): # initialize all keys of allSimData dict
if gatherLFP and k == 'LFP':
sim.allSimData[k] = np.zeros((gather[0]['simData']['LFP'].shape))
elif gatherLFP and k == 'LFPPops':
sim.allSimData[k] = {p: np.zeros(gather[0]['simData']['LFP'].shape) for p in gather[0]['simData']['LFPPops'].keys()}
elif gatherDipole and k == 'dipoleSum':
sim.allSimData[k] = np.zeros((gather[0]['simData']['dipoleSum'].shape))
elif sim.cfg.recordDipolesHNN and k == 'dipole':
Expand Down Expand Up @@ -208,6 +215,9 @@ def gatherData(gatherLFP=True, gatherDipole=True):
sim.allSimData[key] = list(sim.allSimData[key])+list(val) # udpate simData dicts which are Vectors
elif gatherLFP and key == 'LFP':
sim.allSimData[key] += np.array(val)
elif gatherLFP and key == 'LFPPops':
for p in val:
sim.allSimData[key][p] += np.array(val[p])
elif gatherDipole and key == 'dipoleSum':
sim.allSimData[key] += np.array(val)
elif key not in singleNodeVecs:
Expand Down Expand Up @@ -469,6 +479,12 @@ def sort(popKeyAndValue):
for p in value:
allSimData['LFPPops'][p] += np.array(value[p])

elif key == 'dipoleSum':
if key not in allSimData.keys():
allSimData[key] = value
else:
allSimData[key] += value

elif key not in singleNodeVecs:
allSimData[key].update(value)

Expand Down
9 changes: 9 additions & 0 deletions netpyne/sim/save.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,9 +406,13 @@ def intervalSave(simTime, gatherLFP=True):
for k in list(gather[0]['simData'].keys()): # initialize all keys of allSimData dict
if gatherLFP and k == 'LFP':
sim.allSimData[k] = np.zeros((gather[0]['simData']['LFP'].shape))
elif gatherLFP and k == 'LFPPops':
sim.allSimData[k] = {p: np.zeros(gather[0]['simData']['LFP'].shape) for p in gather[0]['simData']['LFPPops'].keys()}
elif sim.cfg.recordDipolesHNN and k == 'dipole':
for dk in sim.cfg.recordDipolesHNN:
sim.allSimData[k][dk] = np.zeros(len(gather[0]['simData']['dipole'][dk]))
elif sim.cfg.recordDipole and k == 'dipoleSum':
sim.allSimData[k] = np.zeros(gather[0]['simData']['dipoleSum'].shape)
else:
sim.allSimData[k] = {}

Expand Down Expand Up @@ -437,6 +441,11 @@ def intervalSave(simTime, gatherLFP=True):
sim.allSimData[key] = list(sim.allSimData[key])+list(val) # udpate simData dicts which are Vectors
elif gatherLFP and key == 'LFP':
sim.allSimData[key] += np.array(val)
elif gatherLFP and key == 'LFPPops':
for p in val:
sim.allSimData[key][p] += np.array(val[p])
elif key == 'dipoleSum':
sim.allSimData[key] += val
elif key not in singleNodeVecs:
sim.allSimData[key].update(val) # update simData dicts which are not Vectors
if 'xElectrodeTransferResistances' in node:
Expand Down

0 comments on commit 522f377

Please sign in to comment.