def mp_fn(j,nearest_n,bm,test): train={} dist=[] fn.grid(io.StringIO(j),train,bm) n=min(len(list(train.values())[0]),len(test),6) if (n<3): return(False) b=np.array(test[len(test)-n:]) for k in range(0,len(list(train.values())[0])-n+1): a=np.array(list(train.values())[0][k:n+k]) dist.append(np.sum(np.sqrt(np.diagonal(np.dot(a-b,np.transpose(a-b)))))) nearest_n[j.split(",",8)[0].strip('"')]=min(dist) return(True)
def program(word, action): if action == "under": under(word) elif action =="over": over(word) elif action =="both": both(word) elif action =="grid": grid_size = int(input("what size of grid would you like to display?\n")) grid(word,grid_size) else: print("Invalid action. Please try again.") program()
def run(): #word input from user word = input('Please enter a word:\n') #option in put from user option = int( input("""Please choose from the following options: 1 - underline the word 2 - overline the word 3 - under and overline the word 4 - display the word in a grid\n""")) #decision based on option input if option == 1: under(word) elif option == 2: over(word) elif option == 3: both(word) elif option == 4: n = int(input('Please input a grid size:\n')) grid(word, n)
def run(): word = str(input("Please enter a word: ")) print("Please pick an option (1 - 4) from the following:") print("1) Under - display the word with a line under it.") print("2) Over - display the word with a line over it.") print("3) Both - display the word in an underline and overline.") print("4) Grid - display the word in a grid that is n x n in size.") #This is a check to see if the input is valid. try: option = int(input()) if option > 4 or option < 1: print("That number isn't an option") print() run() except: print("That's not a number.") print() run() print() #choosing the function based on the user's choice. if option == 1: functions.over(word) elif option == 2: functions.under(word) elif option == 3: functions.both(word) elif option == 4: #asking user for grid size grid_size = int( input( "Please enter the 'n' value for the size of the grid (n x n): " )) functions.grid(word, grid_size) else: run()
# Cycle through each raw file for file in os.listdir(): print('Gridding: ' + file) nc = Dataset(file, 'r') lat = nc.variables['Latitude'][:]#.tolist() lon = nc.variables['Longitude'][:]#.tolist() ssh = nc.variables['Sea Surface Height'][:]#.tolist() ice_conc = nc.variables['Sea Ice Concentration'][:]#.tolist() nc.close() # Grid sea surface height to a 1-degree grid data = funct.grid(ssh, lon, lat, 1) grid_ssh = data['Grid'] grid_lon = data['Lon'] grid_lat = data['Lat'] print('ssh data gridded...') data = funct.grid(ice_conc, lon, lat, 1) grid_ice_conc = data['Grid'] print('sea ice concentration gridded...') # Put the data in a .nc file in /Users/jmh2g09/Documents/PhD/Data/Gridded os.chdir('/Users/jmh2g09/Documents/PhD/Data/Gridded/' + year) month = file[-9:-7] nc = Dataset(year + month + '_nogeoid.nc', 'w', FORMAT='NETCDF4_CLASSIC')
#m = Basemap(projection='cyl', llcrnrlat=-90, urcrnrlat=-30, # llcrnrlon=-180, urcrnrlon=180, resolution='c') #m.drawmapboundary() #m.drawcoastlines(zorder=10) #m.fillcontinents(zorder=10) #m.drawparallels(np.arange(-80., 81., 20.), labels=[1, 0, 0, 0]) #m.drawmeridians(np.arange(-180., 181., 20.), labels=[0, 0, 0, 1]) #x_map_cyl, y_map_cyl = m(lon, lat) #m.scatter(x_map_cyl, y_map_cyl, c=ssh, edgecolor='none') #m.colorbar() #pl.clim(-50, 50) #pl.show() # Grid the data to a 1-degree grid data = funct.grid(ssh, lon, lat, 1) grid_data = data['Grid'] grid_lon = data['Lon'] grid_lat = data['Lat'] pl.figure(str(month) + '_' + str(year) + '_gridded_1degree_cyl') pl.clf() m = Basemap(projection='cyl', llcrnrlat=-90, urcrnrlat=-30, llcrnrlon=-180, urcrnrlon=180, resolution='c') m.drawmapboundary() m.drawcoastlines(zorder=10) m.fillcontinents(zorder=10) m.drawparallels(np.arange(-80., 81., 20.), labels=[1, 0, 0, 0]) m.drawmeridians(np.arange(-180., 181., 20.), labels=[0, 0, 0, 1]) m.pcolor(grid_lon, grid_lat, np.transpose(grid_data)) m.colorbar()
if tried != -1: tried, last = functions.test(im, p_bot, game, last, mode, change, tried, random) random = False if tried >= 15: change = False if mode == "tree": print("> I'M SORRY, BACK TO CHOPPING") else: print("> I'M SORRY, BACK TO MINING") tried = 0 functions.draw(im) functions.grid(im) cv2.imshow("frame1", im) delta = time.time() - start if delta < SLEEP_TIME: time.sleep(SLEEP_TIME - delta) key = cv2.waitKey(1) & 0xFF if key == ESC_KEY: break else: time.sleep(1) cv2.destroyAllWindows()
data=pd.read_csv('train.csv',parse_dates=[5],date_parser=datetime_parser,usecols=[0,1,2,3,4,5,6,7]) data.set_index(['TRIP_ID'],inplace=True) #setting basemap coordinate bm=Basemap(llcrnrlat=37,llcrnrlon=-9.5,urcrnrlat=41.5 ,urcrnrlon=-6.5,epsg=3763) x=math.ceil(bm.xmax/100) y=math.ceil(bm.ymax/100) train_path={} #dividing into grids #grid("train.csv",train_path,bm) #binning test paths into grids test_path={} fn.grid(open("test.csv",'r'),test_path,bm) test_match=[] for i in test_path: nearest_n={} file=open("train.csv","r") file.readline(); for j in iter(file.readline,''): train={} dist=[] fn.grid(io.StringIO(j),train,bm) n=min(len(list(train.values())[0]),len(test_path[i]),6) if (n<3): continue b=np.array(test_path[i][:n]) for k in range(0,len(list(train.values())[0])-n+1):
# main program #from functions import under, over, both, grid, run from functions import under, over, both, grid word = input("Please enter a word: " "\n") print("\nEnter one of the following options:") print(" (1) Under - display the word with a line under it.") print(" (2) Over - display the word with a line over it") print(" (3) Both - display the word in an underline and overline") print(" (4) Grid - display the word in a grid that is n x n in size.") option = input("Enter 1 to 4: ") if option == "1": under(word) print() elif option == "2": over(word) print() elif option == "3": both(word) print() elif option == "4": size = int(input("Please enter value for grid: ")) grid(word, size) print() else: print("...invalid option number") print()