66from time import sleep
77import numpy as np
88
9- from models import *
9+ from . models import *
1010
1111ASC_SFIELDS_EYE = {
1212 'l' :[('onset' , np .int64 ),
@@ -174,10 +174,10 @@ def pandas_df_from_txt(file_path):
174174 # accordingly. It would be nice if the dtypes would work in read_csv, but
175175 # so far no luck...
176176 df = pd .read_csv (file_path , sep = "\t " , index_col = "TIMESTAMP" , low_memory = False , na_values = ["." ],)
177- fields = [str (x ) for x in df .dtypes .keys ()]
178- dtypes = dict ([(d , object ) for d in fields if not d in TXT_FIELDS .keys ()])
179- dtypes .update (dict ([(k , v ) for k , v in TXT_FIELDS .iteritems () if k in fields ]))
180- nums = [k for k , v in dtypes .iteritems () if v not in [object ]]
177+ fields = [str (x ) for x in list ( df .dtypes .keys () )]
178+ dtypes = dict ([(d , object ) for d in fields if not d in list ( TXT_FIELDS .keys () )])
179+ dtypes .update (dict ([(k , v ) for k , v in TXT_FIELDS .items () if k in fields ]))
180+ nums = [k for k , v in dtypes .items () if v not in [object ]]
181181 ints = [k for k in nums if dtypes [k ] in TXT_INT_TYPES ]
182182 df [nums ] = df [nums ].convert_objects (convert_numeric = True )
183183 df [ints ] = df [ints ].astype (np .int64 )
@@ -233,9 +233,9 @@ def pandas_dfs_from_asc(file_path):
233233
234234def pandas_df_from_lines (csv_lines , dtypes , ignore ):
235235 import pandas as pd
236- import cStringIO
237- c = cStringIO .StringIO ("" .join (csv_lines ))
238- fields , dts = zip (* dtypes )
236+ import io
237+ c = io .StringIO ("" .join (csv_lines ))
238+ fields , dts = list ( zip (* dtypes ) )
239239 # use_names = [n for n in fields if not n in ignore]
240240 df = pd .read_csv (c ,
241241 delim_whitespace = True ,
@@ -404,14 +404,14 @@ def list_run_corruption(asc_dir):
404404 vals = {}
405405 for i , fn in enumerate (files ):
406406 vals [os .path .basename (fn )] = file_checks [i ]
407- print "\n Dropout by File:"
407+ print ( "\n Dropout by File:" )
408408 pprint (vals )
409409
410410def constrain_events (samples , events ):
411411 """ adjusts start times of any events that overflow sample bounds"""
412412 lowtime = samples .index [0 ]
413413 hightime = samples .index [- 1 ]
414- enames = events .dframes .keys ()
414+ enames = list ( events .dframes .keys () )
415415 for en in enames :
416416 df = events .dframes [en ]
417417 idxs = np .where (df .index < lowtime )[0 ]
@@ -435,7 +435,7 @@ def main(argv=None):
435435 try :
436436 try :
437437 opts , args = getopt .getopt (argv [1 :], "d:" , ["dir" , "dropout" ])
438- except getopt .error , msg :
438+ except getopt .error as msg :
439439 raise Usage (msg = "\n " + str (msg ))
440440 # option processing
441441 drop_check = False
@@ -452,12 +452,12 @@ def main(argv=None):
452452 if drop_check and asc_dir :
453453 list_run_corruption (asc_dir )
454454 return
455- except Usage , err :
455+ except Usage as err :
456456 f_str = sys .argv [0 ].split ("/" )[- 1 ] + ":"
457457 lfs = len (f_str )
458458 f_str = "%s\n %s\n %s\n " % ("-" * lfs , f_str , "-" * lfs )
459- print >> sys . stderr , f_str + str (err .msg )
460- print >> sys . stderr , "-------------------\n for help use --help\n -------------------"
459+ print ( f_str + str (err .msg ), file = sys . stderr )
460+ print ( "-------------------\n for help use --help\n -------------------" , file = sys . stderr )
461461 return 2
462462
463463if __name__ == '__main__' :
0 commit comments