column=vasMapColumn,row=vasMapRow,frame=vasMapFrame,crop=vasMapCrop,mergeMethod=vasMapMergeMethod)
else:
    print 'No vasculature map find. Taking first frame of movie as vasculature map.'
    vasMap = BinarySlicer(movPath)[0,:,:]

vasMap = ia.array_nor(vasMap).astype(np.float32)

tf.imsave(os.path.join(saveFolder,dateRecorded+'_M'+mouseID+'_Trial'+trialNum+'_vasMap.tif'),vasMap)

_, jphys = ft.importRawNewJPhys(jphysPath,dtype=jphysDtype,headerLength=jphysHeaderLength,channels=jphysChannels,sf=jphysFs)

pd = jphys['photodiode']

displayOnsets = hl.segmentPhotodiodeSignal(pd, digitizeThr=pdDigitizeThr, filterSize=pdFilterSize, segmentThr=pdSegmentThr, Fs=jphysFs)

imgFrameTS = ta.get_onset_timeStamps(jphys['read'], Fs=jphysFs, threshold=readThreshold, onsetType=readOnsetType)

logPath = hl.findLogPath(date=dateRecorded,mouseID=mouseID,stimulus='KSstimAllDir',userID=userID,fileNumber=str(fileNum),displayFolder=dataFolder)

displayInfo = hl.analysisMappingDisplayLog(logPath)

sweepNum = len(displayInfo['B2U']['ind']+displayInfo['U2B']['ind']+displayInfo['L2R']['ind']+displayInfo['R2L']['ind'])
if len(displayOnsets) != sweepNum:
    warningMessage = '\nNumber of detected photodiode onsets ('+str(len(displayOnsets))+') is not equal to display sweep number ('+str(sweepNum)+')!\n'
    warnings.warn(warningMessage)

altPosMap,aziPosMap,altPowerMap,aziPowerMap  = hl.getMappingMovies(movPath=movPath,frameTS=imgFrameTS,
                                                                   displayOnsets=displayOnsets,displayInfo=displayInfo,
                                                                   temporalDownSampleRate=temporalDownSampleRate,
                                                                   saveFolder=saveFolder,
                                                                   savePrefix=dateRecorded+'_M'+mouseID+'_Trial'+trialNum,
 def test_get_onset_time_stamps(self):
     trace = np.array(([0.] * 5 + [5.] * 5) * 5)
     ts = ta.get_onset_timeStamps(trace, Fs=10000., onsetType='raising')
     assert(ts[2] == 0.0025)
     ts2 = ta.get_onset_timeStamps(trace, Fs=10000., onsetType='falling')
     assert(ts2[2] == 0.0030)