Skip to content

Commit

Permalink
feat: update analysis server to return computed steady state frequenc…
Browse files Browse the repository at this point in the history
…y averages
  • Loading branch information
oreHGA committed Dec 21, 2023
1 parent aafc39c commit 3367bd7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
20 changes: 18 additions & 2 deletions analysis_server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,19 @@
import time
from PIL import Image
from flask_cors import CORS
import base64

import eeg

app = Flask(__name__)
CORS(app, resources={r"/api/*": {"origins": "*"}})


def encode_image_to_base64(image_path):
with open(image_path, "rb") as image_file:
encoded_string = base64.b64encode(image_file.read()).decode('utf-8')
return encoded_string

# TODO: handle multiple files
@app.route('/api/v1/process_eeg', methods=['POST'])
def process():
Expand Down Expand Up @@ -66,14 +73,23 @@ def process():
powerComparisonImage = Image.fromarray(powerComparisonData)
powerComparisonImage.save("powerComparisons.png")

powerDistributionBase64= encode_image_to_base64("powerDistributions.png")
powerComparisonBase64 = encode_image_to_base64("powerComparisons.png")

# remember to delete folder after processing
return jsonify({"files": os.listdir(temp_dir)}), 200
# do foof analysis and display that

# # remember to delete folder after processing
return jsonify({"images": {
"powerDistribution": powerDistributionBase64,
"powerComparison": powerComparisonBase64
}, "summary": "Steady State Frequency Averages from Recordings"}), 200

except Exception as e:
print("error", e)
return jsonify({'error': str(e)}), 500

# TODO: endpoint for ERP analysis


if __name__ == '__main__':
app.run(debug=True, port=8000)
Expand Down
14 changes: 4 additions & 10 deletions analysis_server/eeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def load_session_epochs(files: dict, _on: set, _channels: list = [],qualityCutof

return on

def load_session_summery(files: dict, _channels: list = [], qualityCutoffFilter: int = 0, epochSize: int = -1, returnEpoched = False, debug=False) -> dict:
def load_session_summary(files: dict, _channels: list = [], qualityCutoffFilter: int = 0, epochSize: int = -1, returnEpoched = False, debug=False) -> dict:
"""
Takes a session of EEG data, computes some metrics, and returns them.
Expand Down Expand Up @@ -457,10 +457,10 @@ def __init__(self,fileBundles: dict,epochSize=5, qualityCutoffFilter=0.95, debug
if bundleType == "tags": # this means it's a dict of datasets based on tags
# this means it's an array of datasets based on tags
for y in self.fileBundles[x]:
self.fileBundleSummeries[x].append(load_session_summery(self.fileBundles[x][y],qualityCutoffFilter=qualityCutoffFilter,epochSize=epochSize,returnEpoched=True,debug=debug))
self.fileBundleSummeries[x].append(load_session_summary(self.fileBundles[x][y],qualityCutoffFilter=qualityCutoffFilter,epochSize=epochSize,returnEpoched=True,debug=debug))
sum += len(self.fileBundleSummeries[x][-1])
elif bundleType == "ids":
self.fileBundleSummeries[x].append(load_session_summery(self.fileBundles[x],qualityCutoffFilter=qualityCutoffFilter,epochSize=epochSize,returnEpoched=True,debug=debug))
self.fileBundleSummeries[x].append(load_session_summary(self.fileBundles[x],qualityCutoffFilter=qualityCutoffFilter,epochSize=epochSize,returnEpoched=True,debug=debug))
sum += len(self.fileBundleSummeries[x])
else:
raise Exception("Invalid bundleType")
Expand Down Expand Up @@ -736,10 +736,4 @@ def load_fileset(
continue
*type, session = f.stem.split("_")
sessions[session]["_".join(type)] = str(f)
return sessions


if __name__ == "__main__":
df = load_data()
print(df)
print(df.describe())
return sessions

0 comments on commit 3367bd7

Please sign in to comment.