Commit cb14f974 authored by Roque Porchetto's avatar Roque Porchetto

erp5_wendelin_telecom_ingestion: process data operation processes also edf raw files

parent d525c91a
...@@ -2,9 +2,8 @@ import os ...@@ -2,9 +2,8 @@ import os
import mne import mne
import json import json
from DateTime import DateTime from DateTime import DateTime
from Products.ERP5Type.Log import log
from mne.report import Report from mne.report import Report
from mne import read_evokeds #from Products.ERP5Type.Log import log
def getHTMLReport(file_name, raw): def getHTMLReport(file_name, raw):
try: try:
...@@ -28,14 +27,28 @@ def getJSONMetadata(raw_info): ...@@ -28,14 +27,28 @@ def getJSONMetadata(raw_info):
} }
return json.dumps(info) return json.dumps(info)
def getRawData(file_name, data_stream_content):
with open(file_name, 'wb') as fif_file:
fif_file.write(data_stream_content)
raw = None
try:
raw = mne.io.read_raw_fif(file_name, preload=True)
except:
pass
if raw is None:
try:
raw = mne.io.read_raw_edf(file_name, preload=True)
except:
pass
return raw
def processRawData(data_stream, data_array, data_descriptor): def processRawData(data_stream, data_array, data_descriptor):
file_name = "temporal_file_%s" % DateTime().strftime('%Y%m%d-%H%M%S') file_name = "temporal_file_%s" % DateTime().strftime('%Y%m%d-%H%M%S')
try: try:
data_stream_content = data_stream.getData() data_stream_content = data_stream.getData()
raw_file = file_name + "_raw.fif" raw_file = file_name + "_raw.fif"
with open(raw_file, 'wb') as fif_file: raw = getRawData(raw_file, data_stream_content)
fif_file.write(data_stream_content) if raw is None: raise StandardError("the file does not contain raw data.")
raw = mne.io.read_raw_fif(raw_file, preload=True)
json_metadata = getJSONMetadata(raw.info) json_metadata = getJSONMetadata(raw.info)
html_report = getHTMLReport(file_name, raw) html_report = getHTMLReport(file_name, raw)
data_descriptor.setTextContent(json_metadata) data_descriptor.setTextContent(json_metadata)
......
...@@ -52,8 +52,8 @@ ...@@ -52,8 +52,8 @@
<key> <string>text_content_warning_message</string> </key> <key> <string>text_content_warning_message</string> </key>
<value> <value>
<tuple> <tuple>
<string>W: 5, 0: Unused log imported from Products.ERP5Type.Log (unused-import)</string> <string>W: 36, 2: No exception type(s) specified (bare-except)</string>
<string>W: 7, 0: Unused read_evokeds imported from mne (unused-import)</string> <string>W: 41, 4: No exception type(s) specified (bare-except)</string>
</tuple> </tuple>
</value> </value>
</item> </item>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment