Skip to content

Commit

Permalink
Fix bug when saving features to a file.
Browse files Browse the repository at this point in the history
  • Loading branch information
pablomc88 committed Nov 28, 2024
1 parent 58038a7 commit 5b5bb5f
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions examples/Hagen_model/simulation/compute_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@

# Split CDM data into 10 chunks when computing EEGs to avoid memory issues
if compute_EEG:
all_CDM_data = np.array_split(CDM_data,10)
# Check if the features have already been computed for this file
if os.path.isfile(os.path.join(features_path, method, 'tmp',
'sim_X_'+file.split('_')[-1]+'_0')) == False:
all_CDM_data = np.array_split(CDM_data, 10)
else:
print(f'Features have already been computed for CDM data {file.split("_")[-1]}.')
continue
else:
all_CDM_data = [CDM_data]

Expand All @@ -61,7 +67,7 @@
print(f'Computing features for CDM data chunk {ii+1}/{len(all_CDM_data)}')
# Computation of EEGs
if compute_EEG:
# Check if the features have already been computed
# Check if the features have already been computed for this chunk
if os.path.isfile(os.path.join(features_path, method, 'tmp',
'all_features_' + file.split('_')[-1] + '_' + str(ii))) == False:
print(f'Computing EEGs for CDM data chunk {ii+1}/{len(all_CDM_data)}')
Expand Down Expand Up @@ -144,13 +150,16 @@
'all_features_' + file.split('_')[-1] + '_' + str(ii)))

# Save the features to a file
print('\nSaving EEG features to files.')
for i in range(20):
elec_data = []
for j in range(len(all_features)):
elec_data.append(all_features[j][i])

pickle.dump(np.array(elec_data),open(os.path.join(features_path, method, 'tmp',
'sim_X_'+file.split('_')[-1]+'_'+str(i)), 'wb'))
pickle.dump(np.array(elec_data),open(os.path.join(features_path, method, 'tmp',
'sim_X_'+file.split('_')[-1]+'_'+str(i)), 'wb'))
# Kill the process
os._exit(0)

else:
df = all_features[0]
Expand Down

0 comments on commit 5b5bb5f

Please sign in to comment.