Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
problem with my code
#1
hi i had this cod but i dont know how to input my file in it please edit code for me
exmaple my input file in this adress c:\destktop\eeg\eeg1


import argparse
import mne
import numpy as np
from scipy import io

if __name__ == '__main__':

parser = argparse.ArgumentParser(prog='fif2mat',
description='converts raw EEG data in FIF format into MAT format;'
'events are stored in an extra file in EEGLab format.')

parser.add_argument('fif_filepath',
help='path to the input FIF file')

parser.add_argument('eeg_filepath',
help='path to the output MAT file for the raw EEG data')

parser.add_argument('events_filepath',
help='path to the output MAT file for the events')

args = parser.parse_args()

print 'loading raw data from ', args.fif_filepath
raw = mne.io.Raw(args.fif_filepath, preload=True, verbose=True)
data, time = raw[:,:]

print 'saving raw data to', args.eeg_filepath
io.savemat(args.eeg_filepath, dict(data=data), oned_as='row')

events = mne.find_events(raw, stim_channel='STI 014', shortest_event=0)

# EEGLab event structure: type, latency, urevent
# Event latencies are stored in units of data sample points relative to (0)
# the beginning of the continuous data matrix (EEG.data).
eeglab_events = [[event[2], event[0], 0] for event in events]
eeglab_events = np.asarray(eeglab_events, dtype=int)

print 'saving events to', args.events_filepath
io.savemat(args.events_filepath, dict(data=eeglab_events), oned_as='row')
Reply
#2
hi i had this cod but i dont know how to input my file in it please edit code for me
exmaple my input file in this adress c:\destktop\eeg\eeg1

import argparse
import mne
import numpy as np
from scipy import io

if __name__ == '__main__':

parser = argparse.ArgumentParser(prog='fif2mat',
description='converts raw EEG data in FIF format into MAT format;'
'events are stored in an extra file in EEGLab format.')

parser.add_argument('fif_filepath',
help='path to the input FIF file')

parser.add_argument('eeg_filepath',
help='path to the output MAT file for the raw EEG data')

parser.add_argument('events_filepath',
help='path to the output MAT file for the events')

args = parser.parse_args()

print 'loading raw data from ', args.fif_filepath
raw = mne.io.Raw(args.fif_filepath, preload=True, verbose=True)
data, time = raw[:,:]

print 'saving raw data to', args.eeg_filepath
io.savemat(args.eeg_filepath, dict(data=data), oned_as='row')

events = mne.find_events(raw, stim_channel='STI 014', shortest_event=0)

# EEGLab event structure: type, latency, urevent
# Event latencies are stored in units of data sample points relative to (0) 
# the beginning of the continuous data matrix (EEG.data).
eeglab_events = [[event[2], event[0], 0] for event in events]
eeglab_events = np.asarray(eeglab_events, dtype=int)

print 'saving events to', args.events_filepath
io.savemat(args.events_filepath, dict(data=eeglab_events), oned_as='row')
Reply
#3
What kind of error is it producing?

import argparse
import mne
import numpy as np
from scipy import io

if __name__ == '__main__':

    parser = argparse.ArgumentParser(prog='fif2mat',
                                     description='converts raw EEG data in FIF format into MAT format;'
                                                 'events are stored in an extra file in EEGLab format.')

    parser.add_argument('fif_filepath',
                        help='path to the input FIF file')

    parser.add_argument('eeg_filepath',
                        help='path to the output MAT file for the raw EEG data')

    parser.add_argument('events_filepath',
                        help='path to the output MAT file for the events')

    args = parser.parse_args()

    print('loading raw data from ', args.fif_filepath)
    raw = mne.io.Raw(args.fif_filepath, preload=True, verbose=True)
    data, time = raw[:, :]

    print('saving raw data to', args.eeg_filepath)
    io.savemat(args.eeg_filepath, dict(data=data), oned_as='row')

    events = mne.find_events(raw, stim_channel='STI 014', shortest_event=0)

    # EEGLab event structure: type, latency, urevent
    # Event latencies are stored in units of data sample points relative to (0)
    # the beginning of the continuous data matrix (EEG.data).
    eeglab_events = [[event[2], event[0], 0] for event in events]
    eeglab_events = np.asarray(eeglab_events, dtype=int)

    print('saving events to', args.events_filepath)
    io.savemat(args.events_filepath, dict(data=eeglab_events), oned_as='row')
You have to pass your file as argument:
Output:
$ python3.6 name_of_script_file.py [argument_1] [argument_2] [argument_3]
Reply
#4
thanks for your reply
the error was fif2mat: error: the following arguments are required: fif_filepath, eeg_filepath, events_filepath
i dont know how to inport my fif_filepath adress
could you write the code for me to import [argument_1] from this example adrees c:\destktop\new
Reply
#5
(Oct-06-2018, 04:58 PM)gontajones Wrote: You have to pass your file as argument:

$ python3.6 name_of_script_file.py [argument_1] [argument_2] [argument_3]

you don't need code. As @gontajones already explained you need to supply command line arguments when you run the script
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#6
thanks but i dont know anything about python i dont know how to pass argumnet, coulad you wirte for me with example or upload a link to i can learn
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020