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
import mne
import json
from DateTime import DateTime
from Products.ERP5Type.Log import log
from mne.report import Report
from mne import read_evokeds
#from Products.ERP5Type.Log import log
def getHTMLReport(file_name, raw):
try:
......@@ -28,14 +27,28 @@ def getJSONMetadata(raw_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):
file_name = "temporal_file_%s" % DateTime().strftime('%Y%m%d-%H%M%S')
try:
data_stream_content = data_stream.getData()
raw_file = file_name + "_raw.fif"
with open(raw_file, 'wb') as fif_file:
fif_file.write(data_stream_content)
raw = mne.io.read_raw_fif(raw_file, preload=True)
raw = getRawData(raw_file, data_stream_content)
if raw is None: raise StandardError("the file does not contain raw data.")
json_metadata = getJSONMetadata(raw.info)
html_report = getHTMLReport(file_name, raw)
data_descriptor.setTextContent(json_metadata)
......@@ -46,4 +59,4 @@ def processRawData(data_stream, data_array, data_descriptor):
os.remove(raw_file)
return "Raw data processed."
except Exception, e:
return "Error while processing raw data: " + str(e)
\ No newline at end of file
return "Error while processing raw data: " + str(e)
......@@ -52,8 +52,8 @@
<key> <string>text_content_warning_message</string> </key>
<value>
<tuple>
<string>W: 5, 0: Unused log imported from Products.ERP5Type.Log (unused-import)</string>
<string>W: 7, 0: Unused read_evokeds imported from mne (unused-import)</string>
<string>W: 36, 2: No exception type(s) specified (bare-except)</string>
<string>W: 41, 4: No exception type(s) specified (bare-except)</string>
</tuple>
</value>
</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