Skip to content

Commit

Permalink
Fix args in export_file call
Browse files Browse the repository at this point in the history
- Add suffix to exported data
  • Loading branch information
gdolle committed Oct 16, 2020
1 parent 5f6ce4a commit 8b773e8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
30 changes: 17 additions & 13 deletions mnelab/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
from .utils import have, has_locations, image_path, interface_style
from .io import writers
from .io.xdf import get_xml, get_streams
import os


from inspect import signature

__version__ = "0.6.0.dev0"

Expand Down Expand Up @@ -136,15 +134,15 @@ def __init__(self, model):
self.actions["export_bads"] = file_menu.addAction(
"Export &bad channels...",
lambda: self.export_file(model.export_bads, "Export bad channels",
"*.csv"))
"*.csv", "bad_channels"))
self.actions["export_events"] = file_menu.addAction(
"Export &events...",
lambda: self.export_file(model.export_events, "Export events",
"*.csv"))
"*.csv", "events"))
self.actions["export_annotations"] = file_menu.addAction(
"Export &annotations...",
lambda: self.export_file(model.export_annotations,
"Export annotations","*.csv","annotation"))
"Export annotations","*.csv","annotations"))
self.actions["export_ica"] = file_menu.addAction(
"Export ICA...",
lambda: self.export_file(model.export_ica,
Expand Down Expand Up @@ -436,21 +434,27 @@ def open_file(self, f, text, ffilter="*"):
if fname:
f(fname)

def export_file(self, f, text, ffilter="*",default_name=''):
def export_file(self, f, text, ffilter="*",suffix=''):
"""Export to file."""

if default_name != '' :
default_name += "_"
if suffix != '' :
suffix = "_"+suffix

curent_file_path = os.path.dirname(self.model.current["data"].filenames[0])
curent_file_path = Path(self.model.current["data"].filenames[0]).parent
curent_file_name = self.model.current["name"]

Dialog = QFileDialog.getSaveFileName(self,text,os.path.join(curent_file_path,default_name+curent_file_name),filter=ffilter)
Dialog = QFileDialog.getSaveFileName(self,text,str(curent_file_path.joinpath(curent_file_name+suffix)),filter=ffilter)

fname = Dialog[0]

sig = signature(f)

args={"fname": fname}
for i in sig.parameters.items():
if(i[0]=="ffilter"):
args[i]=ffilter

if fname:
f(fname, ffilter)
f(*args.values())

def import_file(self, f, text, ffilter="*"):
"""Import file."""
Expand Down
3 changes: 3 additions & 0 deletions mnelab/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ def export_bads(self, fname):
fname = join(split(fname)[0], name + ext)
with open(fname, "w") as f:
f.write(",".join(self.current["data"].info["bads"]))
print("Bad channels exported: ", fname)

def export_events(self, fname):
"""Export events to a CSV file."""
Expand All @@ -183,6 +184,7 @@ def export_events(self, fname):
fname = join(split(fname)[0], name + ext)
np.savetxt(fname, self.current["events"][:, [0, 2]], fmt="%d",
delimiter=",", header="pos,type", comments="")
print("Events exported: ", fname)

def export_annotations(self, fname):
"""Export annotations to a CSV file."""
Expand All @@ -195,6 +197,7 @@ def export_annotations(self, fname):
for a in zip(anns.description, anns.onset, anns.duration):
f.write(",".join([a[0], str(a[1]), str(a[2])]))
f.write("\n")
print("Annotations exported: ", fname)

def export_ica(self, fname):
name, ext = splitext(split(fname)[-1])
Expand Down

0 comments on commit 8b773e8

Please sign in to comment.