#NEWLINE# def proc_f32( filename ) : #NEWLINE# #INDENT# "Load an f32 file that has already been processed by the official matlab\n    file converter.  That matlab data is saved to an m-file, which is then\n    converted to a numpy '.npz' file.  This numpy file is the file actually\n    loaded.  This function converts it to a neo block and returns the block.\n    This block can be compared to the block produced by BrainwareF32IO to\n    make sure BrainwareF32IO is working properly\n\n    block = proc_f32(filename)\n\n    filename: The file name of the numpy file to load.  It should end with\n    '*_f32_py?.npz'. This will be converted to a neo 'file_origin' property\n    with the value '*.f32', so the filename to compare should fit that pattern.\n    'py?' should be 'py2' for the python 2 version of the numpy file or 'py3'\n    for the python 3 version of the numpy file.\n\n    example: filename = 'file1_f32_py2.npz'\n             f32 file name = 'file1.f32'\n    " #NEWLINE# filenameorig = os . path . basename ( ( filename [ : ( - 12 ) ] + '.f32' ) ) #NEWLINE# block = Block ( file_origin = filenameorig ) #NEWLINE# rcg = RecordingChannelGroup ( file_origin = filenameorig ) #NEWLINE# rcg . channel_indexes = np . array ( [ ] , dtype = np . int ) #NEWLINE# rcg . channel_names = np . array ( [ ] , dtype = 'S' ) #NEWLINE# unit = Unit ( file_origin = filenameorig ) #NEWLINE# block . recordingchannelgroups . append ( rcg ) #NEWLINE# rcg . units . append ( unit ) #NEWLINE# try : #NEWLINE# #INDENT# with np . load ( filename ) as f32obj : #NEWLINE# #INDENT# f32file = f32obj . items ( ) [ 0 ] [ 1 ] . flatten ( ) #NEWLINE# #UNINDENT# #UNINDENT# except IOError as exc : #NEWLINE# #INDENT# if ( 'as a pickle' in exc . message ) : #NEWLINE# #INDENT# block . create_many_to_one_relationship ( ) #NEWLINE# return block #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise #NEWLINE# #UNINDENT# #UNINDENT# sweeplengths = [ res [ ( 0 , 0 ) ] . tolist ( ) for res in f32file [ 'sweeplength' ] ] #NEWLINE# stims = [ res . flatten ( ) . tolist ( ) for res in f32file [ 'stim' ] ] #NEWLINE# sweeps = [ res [ 'spikes' ] . flatten ( ) for res in f32file [ 'sweep' ] if res . size ] #NEWLINE# fullf32 = zip ( sweeplengths , stims , sweeps ) #NEWLINE# for ( sweeplength , stim , sweep ) in fullf32 : #NEWLINE# #INDENT# for trainpts in fullf32 : #NEWLINE# #INDENT# if trainpts . size : #NEWLINE# #INDENT# trainpts = trainpts . flatten ( ) . astype ( 'float32' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# trainpts = [ ] #NEWLINE# #UNINDENT# paramnames = [ ( 'Param%s' % i ) for i in range ( len ( stim ) ) ] #NEWLINE# params = dict ( zip ( paramnames , stim ) ) #NEWLINE# train = SpikeTrain ( trainpts , units = pq . ms , t_start = 0 , t_stop = sweeplength , file_origin = filenameorig ) #NEWLINE# segment = Segment ( file_origin = filenameorig , ** params ) #NEWLINE# segment . spiketrains = [ train ] #NEWLINE# unit . spiketrains . append ( train ) #NEWLINE# block . segments . append ( segment ) #NEWLINE# #UNINDENT# #UNINDENT# block . create_many_to_one_relationship ( ) #NEWLINE# return block