StartMazeTime = -1
EndMazeTime = -1
#blank black image to draw trajcectory
blank_image = np.zeros((720, 720, 3), np.uint8)

#convert the main clock start time to timedelta object
MAIN_NLX_CLOCK_START = datetime.strptime(MAIN_NLX_CLOCK_START,
                                         '%H:%M:%S.%f').time()
MAIN_NLX_CLOCK_START = timedelta(hours=MAIN_NLX_CLOCK_START.hour,
                                 minutes=MAIN_NLX_CLOCK_START.minute,
                                 seconds=MAIN_NLX_CLOCK_START.second,
                                 microseconds=MAIN_NLX_CLOCK_START.microsecond)
print "Recording Start Time: %s \n" % (MAIN_NLX_CLOCK_START)

#load event timestamps, event names and Id from events.nev file
eventTimestamps, eventId, nttl, eventNames = lynxio.loadNev(Events_File_Name)

#save the events info in the dictionary initialized above with events timestamps as key and [name, timestamp timedelta object] as items
for ts, eventName in zip(eventTimestamps, eventNames):
    events[ts] = [
        eventName,
        timedelta(microseconds=int(ts)) + MAIN_NLX_CLOCK_START
    ]

#print each event stored in the .nev events file
print "Events logged are: "
for key in sorted(events.keys()):
    print key, events[key]

#assign the start and end maze time variable from the events dictionary, used to find index for picamera date time from raw txt file stored
StartMazeTime = events[np.uint64(
EndMazeTime = -1
# blank black image to draw trajcectory
blank_image = np.zeros((720, 720, 3), np.uint8)

# convert the main clock start time to timedelta object
MAIN_NLX_CLOCK_START = datetime.strptime(MAIN_NLX_CLOCK_START, "%H:%M:%S.%f").time()
MAIN_NLX_CLOCK_START = timedelta(
    hours=MAIN_NLX_CLOCK_START.hour,
    minutes=MAIN_NLX_CLOCK_START.minute,
    seconds=MAIN_NLX_CLOCK_START.second,
    microseconds=MAIN_NLX_CLOCK_START.microsecond,
)
print "Recording Start Time: %s \n" % (MAIN_NLX_CLOCK_START)

# load event timestamps, event names and Id from events.nev file
eventTimestamps, eventId, nttl, eventNames = lynxio.loadNev(Events_File_Name)

# save the events info in the dictionary initialized above with events timestamps as key and [name, timestamp timedelta object] as items
for ts, eventName in zip(eventTimestamps, eventNames):
    events[ts] = [eventName, timedelta(microseconds=int(ts)) + MAIN_NLX_CLOCK_START]

# print each event stored in the .nev events file
print "Events logged are: "
for key in sorted(events.keys()):
    print key, events[key]

# assign the start and end maze time variable from the events dictionary, used to find index for picamera date time from raw txt file stored
StartMazeTime = events[np.uint64(raw_input("please enter the eventID for start Maze \n"))][1]
EndMazeTime = events[np.uint64(raw_input("please enter the eventID for End Maze \n"))][1]

print "\nStart Maze Time: %s" % (StartMazeTime)
def fft(datapoints):
    y = datapoints
    n = len(y)  # length of the signal
    Y = np.fft.fft(y) / n  # fft computing and normalization
    return max(abs(Y))[0]


count = 1
plt.figure(figsize=(30, 17))
for filename in os.listdir(os.getcwd()):
    if filename.endswith(".ncs") and filename.startswith("CSC"):
        channelname = filename.split('.')[0]
        plotname = channelname + 'FFT.png'

        csc = lynxio.loadNcs(filename)
        eventTimestamps, eventId, nttl, eventNames = lynxio.loadNev(
            'Events.nev')
        print eventNames

        datapointsbaseline = lynxio.fileSplitterUsingEvents(
            csc, eventTimestamps[1], eventNames[1], eventTimestamps[2],
            eventNames[2])[0:229888]
        datapoints1e1hz = lynxio.fileSplitterUsingEvents(
            csc, eventTimestamps[3], eventNames[3], eventTimestamps[4],
            eventNames[4])[0:229888]
        datapoints3hz = lynxio.fileSplitterUsingEvents(csc, eventTimestamps[5],
                                                       eventNames[5],
                                                       eventTimestamps[6],
                                                       eventNames[6])[0:229888]
        datapoints8hz = lynxio.fileSplitterUsingEvents(csc, eventTimestamps[7],
                                                       eventNames[7],
                                                       eventTimestamps[8],
piCameraTime = []
# start maze time and end maze time (will be noted from events file)
StartMazeTime = -1
EndMazeTime = -1

#Neuralynx clock start time
MAIN_NLX_CLOCK_START = datetime.strptime(NLX_START_TIME, '%H:%M:%S.%f').time()
#convert the main clock start time to timedelta object
MAIN_NLX_CLOCK_START = timedelta(hours=MAIN_NLX_CLOCK_START.hour,
                                 minutes=MAIN_NLX_CLOCK_START.minute,
                                 seconds=MAIN_NLX_CLOCK_START.second,
                                 microseconds=MAIN_NLX_CLOCK_START.microsecond)
print "Recording Start Time: %s \n" % (MAIN_NLX_CLOCK_START)

#load event timestamps, event names and Id from events.nev file
eventTimestamps, eventId, nttl, eventNames = lynxio.loadNev(EVENTS_FILE_NAME)

#save the events info in the dictionary initialized above with events timestamps as key and [name, timestamp timedelta object] as items
for ts, eventName in zip(eventTimestamps, eventNames):
    events[ts] = [
        eventName,
        timedelta(microseconds=int(ts)) + MAIN_NLX_CLOCK_START
    ]

#print each event stored in the .nev events file
print "Events logged are: "
for key in sorted(events.keys()):
    print key, events[key]

#assign the start and end maze time variable from the events dictionary, used to find index for picamera date time from raw txt file stored
StartMazeTime = events[np.uint64(
def fft(datapoints):
    y = datapoints
    n = len(y) # length of the signal
    Y = np.fft.fft(y)/n # fft computing and normalization
    return max(abs(Y))[0] 


count = 1;
plt.figure(figsize=(30,17))
for filename in os.listdir(os.getcwd()):
    if filename.endswith(".ncs") and filename.startswith("CSC"): 
        channelname = filename.split('.')[0]
        plotname = channelname +'FFT.png'
                
        csc = lynxio.loadNcs(filename)
        eventTimestamps, eventId, nttl, eventNames = lynxio.loadNev('Events.nev')
        print eventNames
        
        datapointsbaseline = lynxio.fileSplitterUsingEvents(csc, eventTimestamps[1],
        								 eventNames[1], eventTimestamps[2], eventNames[2])[0:229888]
        datapoints1e1hz = lynxio.fileSplitterUsingEvents(csc, eventTimestamps[3],
        								 eventNames[3], eventTimestamps[4], eventNames[4])[0:229888]     
        datapoints3hz = lynxio.fileSplitterUsingEvents(csc, eventTimestamps[5],
                								 eventNames[5], eventTimestamps[6], eventNames[6])[0:229888]   
        datapoints8hz = lynxio.fileSplitterUsingEvents(csc, eventTimestamps[7],
                								 eventNames[7], eventTimestamps[8], eventNames[8])[0:229888]
        datapoints30hz = lynxio.fileSplitterUsingEvents(csc, eventTimestamps[9],
                								 eventNames[9], eventTimestamps[10], eventNames[10])[0:229888]
        datapoints100hz = lynxio.fileSplitterUsingEvents(csc, eventTimestamps[11],
               								 eventNames[11], eventTimestamps[12], eventNames[12])[0:229888]
        datapoints1khz = lynxio.fileSplitterUsingEvents(csc, eventTimestamps[13],