def get_method(dic, dir, local_dir): try: nonlocal_dir = "/" + dic["username"] + dir transport = paramiko.Transport(dic["hostname"], int(dic["port"])) transport.connect(username=dic["username"], password=dic["password"]) sftp = paramiko.SFTPClient.from_transport(transport) sftp.get(nonlocal_dir, local_dir) show("host [%s] download file seccess" % dic["hostname"], "info") except Exception as e: show("host [%s] error:%s" % (dic["hostname"], e), "error")
def host_parse(list): while True: command = input("Input command[q=quit]>>>:").strip() if command == "help": help_info = """ |------- [help] ------- 1: [put ] upload files. 2: [get ] download files. 3: [df ] show disk info. 4: [ls ] view file or dirname. 5: [uname ] view the system information. 6: [ifconfig] view the network information """ show(help_info, "msg") elif command == "put": dir = input("Input upload files name>>>:").strip() local_dir = settings.LOCAL_DIR + "/" + dir if not os.path.exists(local_dir): show("filename doesn't exist...", "msg") dir0 = input("Input file path>>>:").strip() for dic in list: TH = threading.Thread(target=put_method, args=( dic, local_dir, dir0, )) TH.start() TH.join() elif command == "get": dir1 = input("Input download files path>>>:").strip() res_list = dir1.split("/") local_dir = settings.LOCAL_DIR + "/" + res_list[len(res_list) - 1] for dic in list: TH = threading.Thread(target=get_method, args=( dic, dir1, local_dir, )) TH.start() TH.join() elif command == "q": break else: for dic in list: TH = threading.Thread(target=command_method, args=( dic, command, )) TH.start() TH.join()
def command_method(dic, command): try: ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(hostname=dic["hostname"], port=int(dic["port"]), username=dic["username"], password=dic["password"]) stdin, stdout, sterr = ssh.exec_command(command) result = stdout.read() print(result.decode()) except Exception as e: show("host [%s] error:%s" % (dic["hostname"], e), "error")
def connect_host(): """ connect host method, :return: """ hostinfo_list = hostinfo_read() if len(hostinfo_list) == 0: print( "\033[31;1m There is no host at the moment. Please create the host first \033[0m" ) exit() print("\033[32;1m|----- host list -----\033[0m") for dic in hostinfo_list: show("\t hostname: %s" % dic["hostname"], "msg") TH = threading.Thread(target=ssh_parse, args=(dic, )) TH.setDaemon(True) TH.start() TH.join()
def main_func(): """ main function,call program function :return: """ menu_dic = {"1": create_host, "2": connect_host, "3": run_host} menu_info = """ |----- Welcome To Fabric Host management interface ----- 1: create new host 2: connect host 3: command host 4: exit program """ while True: show(menu_info, "info") chioce = input("Input You Choice>>>:").strip() if chioce == "1": create_host() continue if chioce == "2": connect_host() continue if chioce == "3": run_host() continue if chioce == "4": show("exit program success....", "info") exit() else: show("Input Error...", "error")
def run_host(): """ operate command host :return: """ try: active_host = [] hostinfo_list = hostinfo_read() for dic in hostinfo_list: if dic["status"] == 1: active_host.append(dic) if len(active_host) == 0: print( "\033[31;1m At present, there is no connection host. " "Please connect the host first to ensure that the host can connect properly \033[0m" ) exit() show("connect host:", "msg") for i, j in enumerate(active_host): show("%s:%s" % (i + 1, j["hostname"]), "msg") chioce = input("Input You choice host>>>:").strip() if chioce == "all": host_parse(active_host) else: list = [] list.append(active_host[int(chioce) - 1]) host_parse(list) except Exception as e: show("chioce run host error....", "error")
def ssh_parse(dic): """ use ssh connect host.if can't connect ,make it's status to 0 ,else to 1 :param dic: :return: """ ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) try: ssh.connect(hostname=dic["hostname"], port=int(dic["port"]), username=dic["username"], password=dic["password"]) except Exception as e: show("host[%s] connect failed...\t Reason:%s" % (dic["hostname"], e), "error") dic["status"] = 0 hostinfo_write(dic, dic["hostname"]) else: show("host[%s]connect success..." % (dic["hostname"]), "a") dic["status"] = 1 hostinfo_write(dic, dic["hostname"]) ssh.close()
def create_host(): """ create a new host method.save host name, host port, user name and user password in file form. :return: """ hostname = input("Input hostname IP>>>:").strip() port = input("Input host ssh port>>>:").strip() username = input("Input host login username>>>:").strip() password = input("Input host login password>>>:").strip() host_dict = { "hostname": hostname, "port": port, "username": username, "password": password, "status": 0 } host_dir = settings.HOST_DIR + "/" + hostname if hostinfo_write(host_dict, hostname): show("create host success....", "info") return True else: show("create host error....", "error") return False
def pair(n): return order(n), degree(n) def pair_int(n): return order_int(n), degree_int(n) if __name__ == "__main__": def show_n(n, gbc): G = gbc(n) show(G) for i in range(2, 20): show(gbc(i)) ''' for p in pyprimes.primes_below(50): print(p) show_n(p, lambda n: gbc(n, nondegenerate_nodes)) for m in range(1,6): print(m) show_n(p, lambda n: gbc60(n, nondegenerate_nodes, m)) print() ''' ''' for n in range(2,40): print(n) show_n(n, lambda n: gbc(n, nodes)) show_n(n, lambda n: gbc(n, nondegenerate_nodes)) #show_n(n, gbc60)
except SystemExit: sys.exit(0) N = args.n NR = int((N-1)/2) # Load the image image = scipy.ndimage.imread(args.image_path)[:,:,0:3]/255.0 # Cut the image into blocks blocks = image_split_blocks(image, N, N) print(blocks.shape) kernel = img_gen(KernelGenCircle(args.aperture, NR), (N,N,1))[:,:,0] print("Aperture kernel:") show(kernel) kernel = kernel[:, :, np.newaxis, np.newaxis, np.newaxis] blocks = blocks*kernel; def gather(blocks, shift): print("Gathering for shift %f" % shift) # Perform shifting for focal adjustment for y in range(N): for x in range(N): if kernel[y,x] < 0.001: continue dy, dx = y - NR, x - NR translate = np.array([dx * shift/(N-1), dy * shift/(N-1)]) # blocks[y,x] = img_transform_translate(blocks[y,x], -translate, blocks[x,y].shape, order=1) blocks[y,x] = scipy.ndimage.interpolation.shift(blocks[y,x], (dy * shift/(N-1), dx * shift/(N-1), 0), order=1)
G = nx.relabel.convert_node_labels_to_integers(nx.read_edgelist(filename)) ig_G = nx_to_ig(G) N2, ds2, D2, aspl2 = len(G), set( G.degree().values()), ig_G.diameter(), ig_G.average_path_length() assert (N1, ds1, D1, aspl1) == (N2, ds2, D2, aspl2) print N2, ds2, D2, aspl2 ''' for node in G.nodes(): if G.degree()[node] == q - 1: for node2 in G.nodes(): if G.degree()[node2] == q - 1: if nx_to_ig(G).shortest_paths()[node][node2] == 3: G.add_edge(node, node2) break show(G) ''' filename = os.path.join('results', 'n' + str(len(G)) + 'd' + str(max(G.degree().values())) + '_edgelist.txt') nx.write_edgelist(G, filename) if args.verbose: G = nx.read_edgelist(filename) ig_G = nx_to_ig(G) N2, ds2, D2, aspl2 = len(G), set( G.degree().values()), ig_G.diameter(), ig_G.average_path_length() assert (N1, ds1, D1, aspl1) == (N2, ds2, D2, aspl2) print N2, ds2, D2, aspl2 '''
sys.exit(0) TAKE = 900 MATCHES = 600 SCALE = 1.0 RANSAC_TRESHOLD = 5 RANSAC_SAMPLES = 4500 show_epipolar = False make_last_image_green = False P_TEST_POINTS = 20 CORRESP_2D_3D = 8 K = np.array([[2759.48, 0.00000, 1520.69], [0.00000, 2764.16, 1006.81], [0.00000, 0.00000, 1.00000]]) print("Note: Using K = ") show(K) K_inv = np.linalg.inv(K) image_files = [args.image1, args.image2] + args.IMAGES # Open image files print("Opening image files...") images = [] for image_file in image_files: image = scipy.ndimage.imread(image_file)[:, :, 0:3] image = zoom_3ch(image, SCALE) images += [image] if make_last_image_green: images[-1][:, :] = np.array([0, 255, 0])
print(Hs) """ Hci = np.linalg.inv(Hs[center]) Hs = [Hci . dot(H) for H in Hs] """ His = [np.linalg.inv(H) for H in Hs] imgBBs = [ np.einsum('ba,na->nb', Hi, pointlist_to_homog(image_bounds_pointlist(img))) for Hi, img in zip(His, imgs) ] BB = pointlist_from_homog(np.vstack(imgBBs)) show(BB) xmin, ymin = BB.min(axis=0) xmax, ymax = BB.max(axis=0) xsize = int(xmax - xmin) ysize = int(ymax - ymin) offset = np.array([xmin, ymin]) result = np.zeros((ysize, xsize, 3)) mask_gen_func = img_gen_mask_smooth print("Sampling images") warps = [ img_transform_H(img, H, result.shape, offset=offset) for H, img in zip(Hs, imgs)
def show_n(n): R = Zmod(n) G = gbc(R) show(G)
cost = compute_cost(x_vals, y_vals, Theta, hypothesis_func) print("itr=%d, cost=%f, Theta0=%f, Theta1=%f" % (i, cost, Theta[0], Theta[1])) return Theta if __name__ == "__main__": # 01. データを読み込む #--------------------------------------------- # 今回利用するデータを読み込みます data, x_vals, y_vals = cmn.load_data() # 上10件ほど、見てみましょう print('-----------------\n#今回利用するデータ(上10件)') pprint(data[:10]) # データをグラフに表示します cmn.show(data) # 02. (最適化前)予測とコストを計算する #--------------------------------------------- # 初期値のシータは10にしておきます(別の値でも良いです) # 「Theta0 = 10, Theta1 = 10」の意味です。 Theta = [10, 10] # このシータを使って、上位10件のデータの予測を作ってみましょう hypo = hypothesis(x_vals, Theta) # 上位3件の予測結果を表示します(最適化前) print('-----------------\n#回帰直線(最適化前)(上3件)') pprint(hypo[:3]) # 以下の値が表示されればOKです print("should be:", [1310.0, 1310.0, 1530.0])
print(offset) img1_rect = img_transform_H(img1, H1, size, offset=offset) img2_rect = img_transform_H(img2, H2, size, offset=(offset + np.array([0, 0]))) # Ask openCV about disparities. dispar_min = 50 dispar_max = 160 window = 11 left = np.uint8(256 * img1_rect) right = np.uint8(256 * img2_rect) sbm = cv2.StereoSGBM_create(dispar_min, dispar_max, window, 2000, 8000) disparity = sbm.compute(left, right) / 16.0 show(disparity) dmin, dmax = disparity.min(), disparity.max() print((dmin, dmax)) drange = dmax - dmin dnorm = (disparity - dmin) / drange # Draw a mesh on rectified images cx, cy = np.meshgrid(np.arange(0, left.shape[1], 40), np.arange(0, left.shape[0], 40)) coords_sparse = np.fliplr( np.stack((cx, cy), axis=2).reshape((-1, 2), order='F')) res_sparse = scipy.ndimage.map_coordinates(disparity, coords_sparse.T, cval=-1) right_dots = right.copy() left_dots = left.copy()
def show_n(n, gbc): G = gbc(n) show(G)
# TODO この関数を実装して下さい # return 0 if __name__ == "__main__": # 01. データを読み込む #--------------------------------------------- # 今回利用するデータを読み込みます data, x_vals, y_vals = cmn.load_data() # 上10件ほど、見てみましょう print('-----------------\n#今回利用するデータ(上10件)') pprint(data[:10]) # データをグラフに表示します cmn.show(data) # 02. (最適化前)予測とコストを計算する #--------------------------------------------- # 初期値のシータは10にしておきます(別の値でも良いです) Theta = 10 # このシータを使って、上位10件のデータの予測を作ってみましょう hypo = hypothesis(x_vals, Theta) # 上位3件の予測結果を表示します(最適化前) print('-----------------\n#原点を通る回帰直線(最適化前)(上3件)') pprint(hypo[:3]) # 以下の値が表示されればOKです print("should be:", [1300.0, 1300.0, 1520.0]) # データと回帰直線をグラフに表示します cmn.show(data, x_vals, y_vals, Theta, hypothesis_func=hypothesis) # 初期コストを計算します
from common import show import networkx as nx def hoffman_singleton_graph(): '''Return the Hoffman-Singleton Graph.''' G = nx.Graph() for i in range(5): for j in range(5): G.add_edge(('pentagon', i, j), ('pentagon', i, (j - 1) % 5)) G.add_edge(('pentagon', i, j), ('pentagon', i, (j + 1) % 5)) G.add_edge(('pentagram', i, j), ('pentagram', i, (j - 2) % 5)) G.add_edge(('pentagram', i, j), ('pentagram', i, (j + 2) % 5)) for k in range(5): G.add_edge(('pentagon', i, j), ('pentagram', k, (i * k + j) % 5)) G = nx.convert_node_labels_to_integers(G) G.name = 'Hoffman-Singleton Graph' return G if __name__ == '__main__': G = hoffman_singleton_graph() show(G)
Qangle16 = angle16[sy,sx] Qhist, _ = np.histogram(Qangle16, 9, (-180 - 45, 180 + 45), weights=Qmagn16, density=False) Qhist[0] += Qhist[-1] Qhist = Qhist[:8] d += list(Qhist) assert(len(d) == 128) d = np.asarray(d).reshape(16,8) d = d/d.max(); d[d > 0.2] = 0.2 d = d/d.max(); descrips += [(x,y,scale, angle, d)] if step_by_step_debug: print("Dominant angle: %d" % angle) show(hist) show(bins) cv2.imshow('patch', image_to_3ch(scipy.ndimage.zoom(patch, 10.0, order=0))) cv2.imshow('kernel', image_to_3ch(scipy.ndimage.zoom(kernel, 10.0, order=0))) cv2.imshow('grads', scipy.ndimage.zoom(cgrad_display(patch_cgrad), (10,10,1), order=0)) patch_cgrad_mult = patch_cgrad * kernel cv2.imshow('grads_mult', scipy.ndimage.zoom(cgrad_display(patch_cgrad_mult), (10,10,1), order=0)) cv2.imshow('rotated_patch', image_to_3ch(scipy.ndimage.zoom(rotated_patch, 3.0, order=0))) cv2.imshow('patch16', image_to_3ch(scipy.ndimage.zoom(patch16, 12.0, order=0))) cv2.imshow('grad16', scipy.ndimage.zoom(cgrad_display(cgrad16), (10,10,1), order=0)) cv2.imshow('kernel16', image_to_3ch(scipy.ndimage.zoom(kernel16, (10,10), order=0))) show(d) while cv2.waitKey(20) & 0xff != 27: pass