From 94a8c539db93255a36db17b7fb90760c95c8aa85 Mon Sep 17 00:00:00 2001 From: Brittany Scheid Date: Tue, 7 Jul 2020 13:03:42 -0400 Subject: [PATCH] added compatibility for py2/py3 raw_input/input --- img_pipe/img_pipe.py | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/img_pipe/img_pipe.py b/img_pipe/img_pipe.py index 93bfc46..4c2c017 100644 --- a/img_pipe/img_pipe.py +++ b/img_pipe/img_pipe.py @@ -24,6 +24,7 @@ import numpy as np import scipy.io import scipy.spatial +from six.moves import input import matplotlib matplotlib.use('Agg') from matplotlib import pyplot as plt @@ -191,7 +192,7 @@ def __init__(self, subj, hem, zero_indexed_electrodes=True, fs_dir=os.environ['F # Check if subj is valid if not os.path.isdir(os.path.join(self.subj_dir, self.subj)): print('No such subject directory as %s' % (os.path.join(self.subj_dir, self.subj))) - ans = raw_input('Would you like to create a new subject directory? (y/N): ') + ans = input('Would you like to create a new subject directory? (y/N): ') if ans.upper() == 'Y' or ans.upper() == 'YES': os.chdir(self.subj_dir) print("Making subject directory") @@ -652,11 +653,11 @@ def project_electrodes(self, elecfile_prefix='hd_grid', use_mean_normal=True, \ # project the electrodes to the convex hull of the pial surface print('Projection direction vector: ', direction) else: - proj_direction = raw_input('Enter a custom projection direction as a string (lh,rh,top,bottom,front,back,or custom): If none provided, will default to hemisphere: \n') + proj_direction = input('Enter a custom projection direction as a string (lh,rh,top,bottom,front,back,or custom): If none provided, will default to hemisphere: \n') if proj_direction == 'custom': - x = raw_input('Enter projection vector\'s x-component: \n') - y = raw_input('Enter projection vector\'s y-component: \n') - z = raw_input('Enter projection vector\'s z-component: \n') + x = input('Enter projection vector\'s x-component: \n') + y = input('Enter projection vector\'s y-component: \n') + z = input('Enter projection vector\'s z-component: \n') direction = [float(x),float(y),float(z)] elif proj_direction not in ['lh','rh','top','bottom','front','back','custom']: direction = self.hem @@ -967,26 +968,26 @@ def make_elecs_all(self, input_list=None, outfile=None): else: #interactive done = False while done == False: - num_empty_rows = raw_input('Are you adding a row that will be NaN in the elecmatrix? If not, press enter. If so, enter the number of empty rows to add: \n') + num_empty_rows = input('Are you adding a row that will be NaN in the elecmatrix? If not, press enter. If so, enter the number of empty rows to add: \n') if len(num_empty_rows): num_empty_rows = int(num_empty_rows) - short_name_prefix = raw_input('What is the short name prefix (e.g. G, AD, HD)?\n') + short_name_prefix = input('What is the short name prefix (e.g. G, AD, HD)?\n') short_names.extend([short_name_prefix for i in range(1,num_empty_rows+1)]) - long_name_prefix = raw_input('What is the long name prefix (e.g. L256Grid, HippocampalDepth)?\n') + long_name_prefix = input('What is the long name prefix (e.g. L256Grid, HippocampalDepth)?\n') long_names.extend([long_name_prefix for i in range(1,num_empty_rows+1)]) - elec_type = raw_input('What is the type of the device (e.g. grid, strip, depth)?\n') + elec_type = input('What is the type of the device (e.g. grid, strip, depth)?\n') elec_types.extend([elec_type for i in range(num_empty_rows)]) elecmatrix_all.append(np.ones((num_empty_rows,3))*np.nan) else: - short_name_prefix = raw_input('What is the short name prefix of the device (e.g. G, AD, HD)?\n') - long_name_prefix = raw_input('What is the long name prefix of the device? (e.g. L256Grid, HippocampalDepth)\n') - elec_type = raw_input('What is the type of the device? (e.g. grid, strip, depth)\n') + short_name_prefix = input('What is the short name prefix of the device (e.g. G, AD, HD)?\n') + long_name_prefix = input('What is the long name prefix of the device? (e.g. L256Grid, HippocampalDepth)\n') + elec_type = input('What is the type of the device? (e.g. grid, strip, depth)\n') try: - file_name = raw_input('What is the filename of the device\'s electrode coordinate matrix?\n') + file_name = input('What is the filename of the device\'s electrode coordinate matrix?\n') indiv_file = os.path.join(self.elecs_dir,'individual_elecs', file_name) elecmatrix = scipy.io.loadmat(indiv_file)['elecmatrix'] except IOError: - file_name = raw_input('Sorry, that file was not found. Please enter the correct filename of the device: \n ') + file_name = input('Sorry, that file was not found. Please enter the correct filename of the device: \n ') indiv_file = os.path.join(self.elecs_dir,'individual_elecs', file_name) elecmatrix = scipy.io.loadmat(indiv_file)['elecmatrix'] num_elecs = elecmatrix.shape[0] @@ -994,10 +995,10 @@ def make_elecs_all(self, input_list=None, outfile=None): short_names.extend([short_name_prefix+str(i) for i in range(1,num_elecs+1)]) long_names.extend([long_name_prefix+str(i) for i in range(1,num_elecs+1)]) elec_types.extend([elec_type for i in range(num_elecs)]) - completed = raw_input('Finished entering devices? Enter \'y\' if finished.') + completed = input('Finished entering devices? Enter \'y\' if finished.') if completed=='y': done = True - outfile = raw_input('What filename would you like to save out to?\n') + outfile = input('What filename would you like to save out to?\n') elecmatrix_all = np.vstack(elecmatrix_all) eleclabels = np.ones(elecmatrix_all.shape,dtype=np.object) eleclabels[:,0] = short_names