content
stringlengths
1
1.05M
input_ids
listlengths
1
883k
ratio_char_token
float64
1
22.9
token_count
int64
1
883k
import json import requests import pandas as pd import websocket # Get Alpaca API Credential endpoint = "https://data.alpaca.markets/v2" headers = json.loads(open("key.txt", 'r').read()) def hist_data(symbols, start="2021-01-01", timeframe="1Hour", limit=50, end=""): """ returns historical bar data for a string of symbols separated by comma symbols should be in a string format separated by comma e.g. symbols = "MSFT,AMZN,GOOG" """ df_data_tickers = {} for symbol in symbols: bar_url = endpoint + "/stocks/{}/bars".format(symbol) params = {"start":start, "limit" :limit, "timeframe":timeframe} data = {"bars": [], "next_page_token":'', "symbol":symbol} while True: r = requests.get(bar_url, headers = headers, params = params) r = r.json() if r["next_page_token"] == None: data["bars"]+=r["bars"] break else: params["page_token"] = r["next_page_token"] data["bars"]+=r["bars"] data["next_page_token"] = r["next_page_token"] df_data = pd.DataFrame(data["bars"]) df_data.rename({"t":"time","o":"open","h":"high","l":"low","c":"close","v":"volume"},axis=1, inplace=True) df_data["time"] = pd.to_datetime(df_data["time"]) df_data.set_index("time",inplace=True) df_data.index = df_data.index.tz_convert("America/Indiana/Petersburg") df_data_tickers[symbol] = df_data return df_data_tickers def get_historical_data(ticker_list, start_date, end_date=None, limit=10000, timeframe="1Day"): """ returns historical bar data for a string of symbols separated by comma symbols should be in a string format separated by comma e.g. symbols = "MSFT,AMZN,GOOG" * timeframe - Timeframe for the aggregation. Available values are: `1Min`, `1Hour`, `1Day` https://alpaca.markets/docs/api-documentation/api-v2/market-data/alpaca-data-api-v2/historical/#bars """ df_data_tickers = {} for symbol in ticker_list: bar_url = endpoint + "/stocks/{}/bars".format(symbol) params = {"start":start_date, "end": end_date, "limit": limit, "timeframe":timeframe} data = {"bars": [], "next_page_token": '', "symbol": symbol} # r = requests.get(bar_url, headers=headers, params=params) # r = r.json() # data["bars"] += r["bars"] while True: r = requests.get(bar_url, headers=headers, params=params) r = r.json() try: if r["next_page_token"] == None: data["bars"] += r["bars"] break else: params["page_token"] = r["next_page_token"] data["bars"] += r["bars"] data["next_page_token"] = r["next_page_token"] except: break # Create a DataFrame for the data["bars"] of each stock df_data = pd.DataFrame(data["bars"]) df_data.rename({"t":"time","o":"open","h":"high","l":"low","c":"close","v":"volume"},axis=1, inplace=True) try: df_data["time"] = pd.to_datetime(df_data["time"]) df_data.set_index("time",inplace=True) df_data.index = df_data.index.tz_convert("America/New_York") df_data_tickers[symbol] = df_data except: pass print("---- Created for [{}]".format(symbol)) return df_data_tickers
[ 11748, 33918, 201, 198, 11748, 7007, 201, 198, 11748, 19798, 292, 355, 279, 67, 220, 201, 198, 11748, 2639, 5459, 201, 198, 201, 198, 201, 198, 2, 3497, 978, 79, 22260, 7824, 327, 445, 1843, 201, 198, 437, 4122, 796, 366, 5450, 1378...
2.049555
1,796
import asyncio from yaps.api import protocol from yaps.utils.log import Log SLEEP_SLOT_TIME = 1 # In seconds. def is_dead(self) -> bool: return not self._alive def die(self) -> None: if not self._alive: return self._alive = False Log.debug(f'Subscription died {self}') def _set_identifier(self, topic: str) -> None: """ Sets the identification of the subscription. This consists of: 1. Topic 2. File descripter number from reader/writer stream. """ self.topic = topic try: self.fd = self._writer.get_extra_info('socket').fileno() except AttributeError: # Streams are incorrect Log.err(f'Incorrect streams to subscription to {self.topic}') self.fd = None def __repr__(self): return f'| ID:{self.fd} Topic: {self.topic} |'
[ 11748, 30351, 952, 198, 198, 6738, 331, 1686, 13, 15042, 1330, 8435, 198, 6738, 331, 1686, 13, 26791, 13, 6404, 1330, 5972, 628, 198, 50, 2538, 8905, 62, 8634, 2394, 62, 34694, 796, 352, 220, 220, 220, 220, 220, 220, 220, 220, 1303,...
2.203791
422
import pickle bad_fid = pickle.load(open('autogenfid.pkl', 'rb')) comdata = 'com_pp.txt' good_fid = [] outfile = './output/dataset.coms' fo = open(outfile, 'w') for line in open(comdata): tmp = line.split(',') fid = int(tmp[0].strip()) if bad_fid[fid]: continue com = tmp[1].strip() com = com.split() if len(com) > 13 or len(com) < 3: continue com = ' '.join(com) fo.write('{}, <s> {} </s>\n'.format(fid, com)) fo.close()
[ 11748, 2298, 293, 198, 198, 14774, 62, 69, 312, 796, 2298, 293, 13, 2220, 7, 9654, 10786, 2306, 6644, 69, 312, 13, 79, 41582, 3256, 705, 26145, 6, 4008, 198, 198, 785, 7890, 796, 705, 785, 62, 381, 13, 14116, 6, 198, 11274, 62, ...
2.012397
242
""" Cubic symmetric graphs. Most of the embeddings realised here were taken from MathWorld. """ from mpmath import * from functools import reduce from shibuya.generators import cu, star_radius, ring_edges, lcf_edges from shibuya.generators import all_unit_distances, circumcentre from shibuya.generators import fixparams_unitdist, symmetrise # F4A = tetrahedron() or complete(4) (not unit-distance) # F6A = circulant(6, (1, 3)) or mobiusladder(3) (not unit-distance) # F8A = genpetersen("cube") # F10A = genpetersen("petersen") def heawood(): """Return the symmetric unit-distance embedding of the Heawood graph (F14A) tucked away in Mathematica's GraphData.""" P = [10485760, 78643200, 263192576, 543686656, 812777472, 942080000, 843317248, 552468480, 208879616, -31170560, -99213312, -76779520, -32795648, 7878144, 17269760, 16256512, 11392032, 4836080, 3014064, 361320, 69498, -165789] v0 = findroot(lambda v: polyval(P, v), 0.275) p0 = mpc(0.5, v0) p1 = mpc(sqrt(1-(v0+0.5)**2)-0.5, -0.5) p2 = cu(p0, -p0) p3 = cu(p1, -p1) p4 = cu(p2, p3) vertices = [mpc(s*re(v), im(v)) for s in (1, -1) for v in (p0, -p0, p1, -p1, p2, p3, p4)] return all_unit_distances(vertices) # F16A = genpetersen("mobiuskantor") def pappus(): """Return a unit-distance embedding of the Pappus graph (F18A).""" u6 = unitroots(6) r0 = [u*0.5j for u in u6] z1 = cu(r0[2], r0[0]) r1 = [z1*u for u in u6] z2 = cu(0, z1) r2 = [z2*u for u in u6] vertices = r0 + r1 + r2 edges = ring_edges(6, ((0, 0, 3), (0, 1, 0), (0, 1, -2), (2, 2, 1), (1, 2, 0))) return (vertices, edges) # F20A = genpetersen("dodecahedron") # F20B = genpetersen("desargues") # F24A = genpetersen("nauru") def f26a(): """Return a unit-distance embedding of the F26A graph.""" t0 = findroot(lambda t: f26a_vertices(t)[1], 0.2) return all_unit_distances(f26a_vertices(t0)[0]) def coxeter(): """Return a unit-distance embedding of the Coxeter graph (F28A).""" u7 = unitroots(7) s1 = star_radius(7) s2 = star_radius(7, 2) s3 = star_radius(7, 3) r0 = [-s2*u for u in u7] r1 = [s3*u for u in u7] z2 = cu(r0[0], r1[3]) r2 = [z2*u for u in u7] z3 = cu(0, z2, s1, 1) r3 = [z3*u for u in u7] vertices = r0 + r1 + r2 + r3 edges = ring_edges(7, ((0, 0, 2), (1, 1, 3), (3, 3, 1), (0, 2, 0), (1, 2, -3), (2, 3, 0))) return (vertices, edges) def dyck(): """Return a unit-distance embedding of the Dyck graph (F32A).""" r0 = unitroots(8) r1 = [sqrt(2)*u for u in r0] z2 = cu(r0[1], 0, 1, star_radius(8)) r2 = [z2*u for u in r0] z3 = cu(0, r1[0], star_radius(8, 3), 1) r3 = [z3*u for u in r0] vertices = r0 + r1 + r2 + r3 edges = ring_edges(8, ((0, 1, 1), (0, 1, -1), (0, 2, -1), (2, 2, 1), (1, 3, 0), (3, 3, 3))) return (vertices, edges) def dyck2(): """Return a unit-distance embedding of the Dyck graph with D4 symmetry.""" t0 = findroot(lambda t: dyck2_vertices(t)[1], 0.1) return all_unit_distances(dyck2_vertices(t0)[0]) def f38a(): """Return a unit-distance embedding of the F38A graph.""" t0 = findroot(lambda t: f38a_vertices(t)[1], 0.29) return all_unit_distances(f38a_vertices(t0)[0]) def f40a(x=0.75): """Return a unit-distance embedding of F40A (bipartite double cover of F20A). x can be anything between (sqrt(5)-1)/2 and 1.""" u10 = unitroots(10) z0 = star_radius(10) r0 = [z0*u for u in u10] z1 = cu(r0[1], 0, 1, x) r1 = [z1*u for u in u10] z2 = cu(r1[2], r1[-2]) r2 = [z2*u for u in u10] z3 = cu(0, z2, z0, 1) r3 = [z3*u for u in u10] vertices = r0 + r1 + r2 + r3 return all_unit_distances(vertices) def f42a(mode=0): """Return a unit-distance embedding of the F42A graph. mode (0 or 1) selects between two algebraically related forms.""" x0 = (0.27, 1.36, 0.52) if mode == 0 else (1.24, 0.18, -0.53) t0 = findroot(lambda *t: f42a_vertices(*t)[1], x0) return all_unit_distances(f42a_vertices(*t0)[0]) # F48A = genpetersen("f48a") but the resulting embedding is vertex-edge-degenerate, so... def f48a(): """Return a non-degenerate unit-distance embedding of the F48A graph.""" R = (2 + 3*sqrt(2) + sqrt(12*sqrt(6)-26)) / 4 r = (2 + 3*sqrt(2) - sqrt(12*sqrt(6)-26)) / 4 L = R-1 l = r-1 u24 = unitroots(24) ring_R = [u*R for u in u24[::2]] ring_r = [u*r for u in u24[1::2]] ring_L = [u*L for u in u24[::2]] ring_l = [u*l for u in u24[1::2]] vertices = ring_R + ring_r + ring_L + ring_l edges = ring_edges(12, ((0, 1, 0), (0, 1, -1), (0, 2, 0), (1, 3, 0), (2, 3, 2), (2, 3, -3))) return (vertices, edges) def f50a(): """Return a unit-distance embedding of the F50A graph, an embedding found by the computer (specifically the embedding_run() function in embeddingsearch).""" t0 = findroot(lambda t: f50a_vertices(t)[1], 2) return (f50a_vertices(t0)[0], lcf_edges(50, [21, -21, -19, 19, -19, 19, -19, 19, 21, -21])) def f54a(i=2): """Return one of three (depending on i in {0, 1, 2}) algebraically related unit-distance embeddings of the F54A graph.""" px = [[3], [-10, -12], [13, 6, 34], [-17, -5, -14]] # x = a(1-c) py = [[3], [2, -2, -10], [1, -6, 9], [-19, 41, -10]] # y = c(1-a) pz = [[3], [5, -8, 2], [11, -14, -13], [-19, 41, -10]] # z = b(1-b) x = polyroots([polyval(l, 2*cos(pi/9)) for l in px])[i] y = polyroots([polyval(l, 2*cos(pi/9)) for l in py])[i] sxy = sqrt((1+x-y)**2 - 4*x) a = (1+x-y+sxy) / 2 c = (1-x+y+sxy) / 2 z = polyroots([polyval(l, 2*cos(pi/9)) for l in pz])[(1-i)%3] b = (1 + (-1 if i else 1)*sqrt(1-4*z)) / 2 triple = [a, b, c] line = [p-d for p in triple for d in (0, 1)] return all_unit_distances(symmetrise(line, "C9")) def f56a(): """Return a unit-distance embedding of the F56A graph. Note that MathWorld's LCF notation for this is incorrect; it should be [11, 13, -13, -11]^14.""" t = tan(pi/14) u = sqrt(polyval([-21, 98, 71], t*t)) z1 = 2*sqrt(14*polyval([31*u, -20, -154*u, 104, 87*u, -68], t)) z2 = 7*t*(t*t-3)**2 - 4*u a = (z1 + z2) / 64 b = (z1 - z2) / 64 u14 = unitroots(14) pa = mpc(a, 0.5) pb = mpc(b, 0.5) pac, pbc = conj(pa), conj(pb) d1 = abs(pa - u14[-1]*pb)**2 - 1 d2 = abs(pb - u14[-2]*pa)**2 - 1 vertices = [u*p for u in u14 for p in (pa, pb, pac, pbc)] return all_unit_distances(vertices) def klein(a1=4.47, a2=2.42, a3=0.7, s1=1, s2=-1): """Return a unit-distance embedding of the cubic Klein graph (F56B).""" u7 = unitroots(7) z0 = star_radius(7) r0 = [z0*u for u in u7] z1 = z0 + expj(a1) z2 = z1 + expj(a2) z3 = z1 + expj(a3) r1 = [z1*u for u in u7] r2 = [z2*u for u in u7] r3 = [z3*u for u in u7] z4 = cu(*(r2[2], r3[0])[::s1]) z5 = cu(*(r2[0], r3[1])[::s2]) r4 = [z4*u for u in u7] r5 = [z5*u for u in u7] z6 = cu(0, r4[0], star_radius(7, 2), 1) z7 = cu(0, r5[0], star_radius(7, 3), 1) r6 = [z6*u for u in u7] r7 = [z7*u for u in u7] vertices = r0 + r1 + r2 + r3 + r4 + r5 + r6 + r7 edges = ring_edges(7, ((0, 0, 1), (0, 1, 0), (1, 2, 0), (1, 3, 0), (2, 4, -2), (3, 4, 0), (2, 5, 0), (3, 5, -1), (4, 6, 0), (5, 7, 0), (6, 6, 2), (7, 7, 3))) return (vertices, edges) def f56c(): """Return a unit-distance embedding of the F56C graph, the bipartite double cover of the Coxeter graph.""" u14 = unitroots(14) z0 = star_radius(14, 5) r0 = [z0*u for u in u14] z1 = star_radius(14, 3) r1 = [z1*u for u in u14] z2 = cu(r1[4], r0[0]) r2 = [z2*u for u in u14] z3 = cu(0, z2, star_radius(14), 1) r3 = [z3*u for u in u14] vertices = r0 + r1 + r2 + r3 edges = ring_edges(14, ((0, 0, 5), (1, 1, 3), (2, 1, 4), (2, 0, 0), (2, 3, 0), (3, 3, 1))) return (vertices, edges) def f60a(t=-0.35): """Return a unit-distance embedding of the F60A graph.""" u15 = unitroots(15) z0 = star_radius(15, 7) r0 = [z0*u for u in u15] z1 = z0 + expj(t) r1 = [z1*u for u in u15] z2 = cu(r1[3], r1[0]) r2 = [z2*u for u in u15] z3 = cu(0, z2, star_radius(15, 2), 1) r3 = [z3*u for u in u15] vertices = r0 + r1 + r2 + r3 edges = ring_edges(15, ((0, 0, 7), (0, 1, 0), (2, 1, 0), (2, 1, 3), (2, 3, 0), (3, 3, 2))) return (vertices, edges) def f62a(): """Return a unit-distance embedding of the F62A graph.""" t0 = [-1.017, -0.819, 2.96, -0.282, -1.091, -0.624, 0.354] t0 = findroot(lambda *t: f62a_vertices(*t)[1], t0) return all_unit_distances(f62a_vertices(*t0)[0]) def f64a(): """Return a unit-distance embedding of the F64A graph.""" t0 = findroot(lambda *t: f64a_vertices(*t)[1], (0.53, 1.6)) return all_unit_distances(f64a_vertices(*t0)[0]) def f72a(): """Return a unit-distance embedding of the F72A graph.""" t0 = findroot(lambda t: f72a_vertices(t)[1], 2.2) return all_unit_distances(f72a_vertices(t0)[0]) def f74a(): """Return a unit-distance embedding of the F74A graph.""" t0 = [2.91, 4.74, 5.5, 4.88, 5, -0.05, 0.07] t0 = findroot(lambda *t: f74a_vertices(*t)[1], t0) return all_unit_distances(f74a_vertices(*t0)[0]) def f80a(t=1.39): """Return a unit-distance embedding of the F80A graph.""" u20 = unitroots(20) z0 = star_radius(20, 7) r0 = [z0*u for u in u20] z1 = z0 + expj(t) r1 = [z1*u for u in u20] z2 = cu(r1[2], r1[0]) r2 = [z2*u for u in u20] z3 = cu(0, z2, star_radius(20, 3), 1) r3 = [z3*u for u in u20] vertices = r0 + r1 + r2 + r3 edges = ring_edges(20, ((0, 0, 7), (0, 1, 0), (2, 1, 0), (2, 1, 2), (2, 3, 0), (3, 3, 3))) return (vertices, edges) def f84a(): """Return a unit-distance embedding of the F84A graph - not degenerate despite its looks. The graph is notable in having the simple PSL(2,8) as its automorphism group.""" t0 = findroot(lambda *t: f84a_vertices(*t)[1], (-0.46, -1.44, 0.25, 0.75)) return all_unit_distances(f84a_vertices(*t0)[0]) def f86a(): """Return a unit-distance embedding of the F86A graph.""" t0 = [3.60383, 3.44007, 4.34048, 5.63174, 3.26345, 0.488743, 0.113378, 0.236693] t0 = findroot(lambda *t: f86a_vertices(*t)[1], t0) return all_unit_distances(f86a_vertices(*t0)[0]) def foster(i=5): """Return any one of six (depending on 0 <= i <= 5) unit-distance embeddings of the Foster graph (F90A).""" n, t0 = [(0, 0.38), (1, 1.35), (2, 0.15), (2, 1.18), (2, 4.68), (3, [1.5, 1.6])][i] tstar = findroot(lambda t: foster_vertices(n, t)[1], t0) return (foster_vertices(n, tstar)[0], lcf_edges(90, (17, -9, 37, -37, 9, -17))) def foster_old(): """Return the unit-distance embedding of the Foster graph (F90A) originally in Dounreay.""" r0 = findroot(lambda r: foster_old_vertices(r)[1], 0.35) vertices = foster_old_vertices(r0)[0] edges = ring_edges(15, ((0, 1, 0), (1, 2, 0), (2, 3, 0), (3, 4, 0), (4, 5, 0), (5, 0, -1), (0, 5, -2), (2, 3, -6), (4, 1, -2))) return (vertices, edges) def f96a(): """Return a unit-distance embedding of the F96A graph.""" a0 = findroot(lambda a: f96a_vertices(a)[1], 0.7) return all_unit_distances(f96a_vertices(a0)[0]) def f96b(a=2.32, b=1.92, c=-0.26, s1=-1, s2=1, s3=1, s4=-1): """Return a unit-distance embedding of the F96B graph.""" u12 = unitroots(12) z2 = star_radius(12, 5) r2 = [u*z2 for u in u12] z3 = z2 + expj(a) r3 = [u*z3 for u in u12] z1 = z3 + expj(b) r1 = [u*z1 for u in u12] z4 = cu(*(u12[3]*z1, z3)[::s1]) r4 = [u*z4 for u in u12] z5 = z1 + expj(c) r5 = [u*z5 for u in u12] z6 = cu(*(u12[-5]*z5, z4)[::s2]) r6 = [u*z6 for u in u12] z8 = cu(*(u12[-4]*z6, z5)[::s3]) r8 = [u*z8 for u in u12] z7 = cu(z8, 0, 1, star_radius(12)) if s4 == 1 else cu(0, z8, star_radius(12), 1) r7 = [u*z7 for u in u12] vertices = r1 + r2 + r3 + r4 + r5 + r6 + r7 + r8 edges = ring_edges(12, ((1, 1, 5), (1, 2, 0), (2, 0, 0), (3, 0, 3), (3, 2, 0), (4, 0, 0), (5, 4, -5), (5, 3, 0), (7, 5, -4), (7, 4, 0), (6, 7, 0), (6, 6, 1))) return (vertices, edges) def biggssmith(): """Return a unit-distance embedding of the BiggsSmith graph (F102A).""" s1 = star_radius(17) s2 = star_radius(17, 2) s4 = star_radius(17, 4) s8 = star_radius(17, 8) u17 = unitroots(17) r1 = [s1*u*1j for u in u17] r4 = [s4*u*1j for u in u17] r8 = [s8*u*-1j for u in u17] sh1 = cu(r1[0], r4[0]) rh1 = [sh1*u for u in u17] sh2 = cu(sh1, r8[7]) rh2 = [sh2*u for u in u17] s2 = cu(sh2, 0, 1, s2) r2 = [s2*u for u in u17] vertices = r1 + r4 + rh1 + r8 + rh2 + r2 edges = ring_edges(17, ((0, 0, 1), (1, 1, 4), (3, 3, 8), (5, 5, 2), (0, 2, 0), (1, 2, 0), (2, 4, 0), (4, 5, 0), (4, 3, 7))) return (vertices, edges)
[ 37811, 198, 43632, 291, 23606, 19482, 28770, 13, 4042, 286, 262, 11525, 67, 654, 19169, 994, 547, 2077, 422, 16320, 10603, 13, 198, 37811, 198, 6738, 285, 4426, 776, 1330, 1635, 198, 6738, 1257, 310, 10141, 1330, 4646, 198, 6738, 427, ...
1.941623
6,715
#!/cygdrive/c/Python27/python.exe # Daniel J. Parente, Ph.D. # Swint-Kruse Laboratory # Physician Scientist Training Program # University of Kansas Medical Center # This code is adapted from the example available at # http://pandasplotting.blogspot.com/2012/04/added-kde-to-scatter-matrix-diagonals.html # Creates a scatterplot matrix (off-diagonals) with a kernal density estimate (KDE) # of the distribution of (univariate) data on the diagonal import numpy as np import matplotlib.pyplot as plt import pandas import sys infile=sys.argv[1] outfile=sys.argv[2] maindata = pandas.read_csv(infile, sep="\t") plt.rcParams['patch.facecolor'] = 'k' # Make the markers black # Plot ax = pandas.tools.plotting.scatter_matrix(maindata, alpha=0.1, marker='k.', figsize=(8,8), diagonal='kde', range_padding=0.1) # Give a small inter-plot spacing plt.subplots_adjust(wspace=.05, hspace=.05) #Save the figure plt.savefig(outfile, dpi=600)
[ 2, 48443, 948, 70, 19472, 14, 66, 14, 37906, 1983, 14, 29412, 13, 13499, 198, 198, 2, 7806, 449, 13, 16774, 68, 11, 1380, 13, 35, 13, 198, 2, 2451, 600, 12, 42, 622, 325, 18643, 198, 2, 8687, 6749, 33374, 13614, 6118, 198, 2, ...
2.772189
338
import pygame; import numpy as np; from math import sin, cos; pygame.init(); width, height, depth = 640, 480, 800; camera = [width // 2, height // 2, depth]; units_x, units_y, units_z = 8, 8, 8; scale_x, scale_y, scale_z = width / units_x, height / units_y, depth / units_z; screen = pygame.display.set_mode((width, height)); pygame.display.set_caption("3D perspective projection test"); pygame.key.set_repeat(100, 50); def scale(p): """ scale a point by the number of pixels per unit in each direction """ return p[0] * scale_x, p[1] * scale_y, p[2] * scale_z; def translate_to_screen(p): """ convert from projected cartesian coordinates to canvas coordinates """ return p[0] + width // 2, height // 2 - p[1]; def project(p): """ project a point onto the 2D plane """ proj_x = (camera[2] * (p[0] - camera[0])) / (camera[2] + p[2]) + camera[0]; proj_y = (camera[2] * (p[1] - camera[1])) / (camera[2] + p[2]) + camera[1]; return proj_x, proj_y; def screen_point(p): """ convert a point in 3D cartesian space to a point in 2D canvas space """ return translate_to_screen(project(scale(p))); def project_triangle(tri): """ return the screen coordinates of a triangle """ angs = (tx, ty, tz); return rproj(tri[0], *angs), rproj(tri[1], *angs), rproj(tri[2], *angs); ## return screen_point(tri[0]), screen_point(tri[1]), screen_point(tri[2]); def project_line(line): """ return the screen coordinates of a line """ return screen_point(line[0]), screen_point(line[1]); triangle = ((1, 1, 1), (2, 2, 2), (1, 2, 1)); x_axis = ((-2, 0, 0), (2, 0, 0)); y_axis = ((0, -2, 0), (0, 2, 0)); z_axis = ((0, 0, -2), (0, 0, 2)); tx, ty, tz = 0, 0, 0; clock = pygame.time.Clock(); running = True; while running: screen.fill((255, 255, 200)); proj_triangle = project_triangle(triangle); pygame.draw.polygon(screen, (255, 0, 200), proj_triangle); pygame.draw.polygon(screen, (0, 0, 0), proj_triangle, 1); pygame.draw.rect(screen, (255, 0, 0), (*proj_triangle[0], 10, 10)); pygame.draw.rect(screen, (0, 255, 0), (*proj_triangle[1], 10, 10)); pygame.draw.rect(screen, (0, 0, 255), (*proj_triangle[2], 10, 10)); ## proj_ax, proj_ay, proj_az = project_line(x_axis), project_line(y_axis), project_line(z_axis); ## pygame.draw.line(screen, (255, 0, 0), proj_ax[0], proj_ax[1], 1); ## pygame.draw.line(screen, (0, 255, 0), proj_ay[0], proj_ay[1], 1); ## pygame.draw.line(screen, (0, 0, 255), proj_az[0], proj_az[1], 1); pygame.display.flip(); for event in pygame.event.get(): if event.type == pygame.QUIT: running = False; break; elif event.type == pygame.KEYDOWN: if event.key == pygame.K_LEFT: #camera[0] -= 25; ## camera = list(np.array([camera]).dot(rot_mat_y(0.2).dot(rot_mat_z(0.1)))[0]); tx += 0.1; elif event.key == pygame.K_RIGHT: #camera[0] += 25; ## camera = list(np.array([camera]).dot(rot_mat_z(-0.1))[0]); tx -= 0.1; elif event.key == pygame.K_UP: ty += 0.1; elif event.key == pygame.K_DOWN: ty -= 0.1; elif event.key == pygame.K_SPACE: print(camera); elif event.key == pygame.K_ESCAPE: running = False; break; clock.tick(30); pygame.quit();
[ 11748, 12972, 6057, 26, 198, 11748, 299, 32152, 355, 45941, 26, 198, 6738, 10688, 1330, 7813, 11, 8615, 26, 198, 9078, 6057, 13, 15003, 9783, 198, 198, 10394, 11, 6001, 11, 6795, 796, 33759, 11, 23487, 11, 10460, 26, 198, 25695, 796, ...
2.164038
1,585
import grasp_net, grasp_params, h5py, aolib.img as ig, os, numpy as np, aolib.util as ut net_pr = grasp_params.im_fulldata_v5() net_pr = grasp_params.gel_im_fulldata_v5() checkpoint_file = '/home/manu/ros_ws/src/manu_research/manu_sawyer/src/tensorflow_model_is_gripping/training/net.tf-6499' gpu = '/gpu:0' db_file = '/media/backup_disk/dataset_manu/ver2/2017-06-22/2017-06-22_212702.hdf5' with h5py.File(db_file, 'r') as db: pre, mid, _ = grasp_net.milestone_frames(db) # sc = lambda x : ig.scale(x, (224, 224)) def sc(x): """ do a center crop (helps with gelsight) """ x = ig.scale(x, (256, 256)) return ut.crop_center(x, 224) u = ig.uncompress crop = grasp_net.crop_kinect inputs = dict( gel0_pre=sc(u(db['GelSightA_image'].value[pre])), gel1_pre=sc(u(db['GelSightB_image'].value[pre])), gel0_post=sc(u(db['GelSightA_image'].value[mid])), gel1_post=sc(u(db['GelSightB_image'].value[mid])), im0_pre=sc(crop(u(db['color_image_KinectA'].value[pre]))), im0_post=sc(crop(u(db['color_image_KinectA'].value[mid]))), # these are probably unnecessary depth0_pre=sc(crop(db['depth_image_KinectA'].value[pre].astype('float32'))), depth0_post=sc(crop(db['depth_image_KinectA'].value[mid].astype('float32')))) net = grasp_net.NetClf(net_pr, checkpoint_file, gpu) prob = net.predict(**inputs) print 'prob = ', prob
[ 11748, 13180, 62, 3262, 11, 13180, 62, 37266, 11, 289, 20, 9078, 11, 257, 349, 571, 13, 9600, 355, 45329, 11, 28686, 11, 299, 32152, 355, 45941, 11, 257, 349, 571, 13, 22602, 355, 3384, 198, 198, 3262, 62, 1050, 796, 13180, 62, 37...
2.101892
687
from API.db import db from datetime import datetime from passlib.apps import custom_app_context as pwd_context class Card(db.Model): __tablename__ = "card" id = db.Column(db.Integer, primary_key=True, autoincrement=True) name = db.Column(db.String(255), nullable=False) number = db.Column(db.String(16), nullable=False) ccv = db.Column(db.String(3), nullable=False) due_date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) expiration_date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) limit = db.Column(db.Float, nullable=False) spent_limit = db.Column(db.Float, nullable=False) user_id = db.Column(db.Integer, db.ForeignKey("users.id"), nullable=False) user = db.relationship("User", back_populates="cards")
[ 6738, 7824, 13, 9945, 1330, 20613, 198, 6738, 4818, 8079, 1330, 4818, 8079, 198, 6738, 1208, 8019, 13, 18211, 1330, 2183, 62, 1324, 62, 22866, 355, 279, 16993, 62, 22866, 628, 628, 198, 198, 4871, 5172, 7, 9945, 13, 17633, 2599, 198, ...
2.683502
297
import unittest from Dice import Dice if __name__ == '__main__': # pragma no cover unittest.main()
[ 11748, 555, 715, 395, 198, 6738, 34381, 1330, 34381, 628, 198, 198, 361, 11593, 3672, 834, 6624, 705, 834, 12417, 834, 10354, 220, 1303, 23864, 2611, 645, 3002, 198, 220, 220, 220, 555, 715, 395, 13, 12417, 3419, 198 ]
2.74359
39
"""Command line tool to extract meaningful health info from accelerometer data.""" import accelerometer.accUtils import argparse import collections import datetime import accelerometer.device import json import os import accelerometer.summariseEpoch import sys import pandas as pd import numpy as np import matplotlib.pyplot as plt from filter_data import data_filter from import_npy import import_npy def main(): """ Application entry point responsible for parsing command line requests """ parser = argparse.ArgumentParser( description="""A tool to extract physical activity information from raw accelerometer files.""", add_help=True ) # required parser.add_argument('rawFile', metavar='input file', type=str, help="""the <.cwa/.cwa.gz> file to process (e.g. sample.cwa.gz). If the file path contains spaces,it must be enclosed in quote marks (e.g. \"../My Documents/sample.cwa\") """) #optional inputs parser.add_argument('--startTime', metavar='e.g. 1991-01-01T23:59', default=None, type=str2date, help="""removes data before this time in the final analysis (default : %(default)s)""") parser.add_argument('--endTime', metavar='e.g 1991-01-01T23:59', default=None, type=str2date, help="""removes data after this time in the final analysis (default : %(default)s)""") parser.add_argument('--timeSeriesDateColumn', metavar='True/False', default=False, type=str2bool, help="""adds a date/time column to the timeSeries file, so acceleration and imputation values can be compared easily. This increases output filesize (default : %(default)s)""") parser.add_argument('--processRawFile', metavar='True/False', default=True, type=str2bool, help="""False will skip processing of the .cwa file (the epoch.csv file must already exist for this to work) (default : %(default)s)""") parser.add_argument('--epochPeriod', metavar='length', default=30, type=int, help="""length in seconds of a single epoch (default : %(default)ss, must be an integer)""") parser.add_argument('--sampleRate', metavar='Hz, or samples/second', default=100, type=int, help="""resample data to n Hz (default : %(default)ss, must be an integer)""") parser.add_argument('--useAbs', metavar='useAbs', default=False, type=str2bool, help="""use abs(VM) instead of trunc(VM) (default : %(default)s)""") parser.add_argument('--skipFiltering', metavar='True/False', default=False, type=str2bool, help="""Skip filtering stage (default : %(default)s)""") # calibration parameters parser.add_argument('--skipCalibration', metavar='True/False', default=False, type=str2bool, help="""skip calibration? (default : %(default)s)""") parser.add_argument('--calOffset', metavar=('x', 'y', 'z'),default=[0.0, 0.0, 0.0], type=float, nargs=3, help="""accelerometer calibration offset (default : %(default)s)""") parser.add_argument('--calSlope', metavar=('x', 'y', 'z'), default=[1.0, 1.0, 1.0], type=float, nargs=3, help="""accelerometer calibration slope linking offset to temperature (default : %(default)s)""") parser.add_argument('--calTemp', metavar=('x', 'y', 'z'), default=[0.0, 0.0, 0.0], type=float, nargs=3, help="""mean temperature in degrees Celsius of stationary data for calibration (default : %(default)s)""") parser.add_argument('--meanTemp', metavar="temp", default=20.0, type=float, help="""mean calibration temperature in degrees Celsius (default : %(default)s)""") parser.add_argument('--stationaryStd', metavar='mg', default=13, type=int, help="""stationary mg threshold (default : %(default)s mg))""") parser.add_argument('--calibrationSphereCriteria', metavar='mg', default=0.3, type=float, help="""calibration sphere threshold (default : %(default)s mg))""") # activity parameters parser.add_argument('--mgMVPA', metavar="mg", default=100, type=int, help="""MVPA threshold (default : %(default)s)""") parser.add_argument('--mgVPA', metavar="mg", default=425, type=int, help="""VPA threshold (default : %(default)s)""") # calling helper processess and conducting multi-threadings parser.add_argument('--rawDataParser', metavar="rawDataParser", default="AxivityAx3Epochs", type=str, help="""file containing a java program to process raw .cwa binary file, must end with .class (omitted) (default : %(default)s)""") parser.add_argument('--javaHeapSpace', metavar="amount in MB", default="", type=str, help="""amount of heap space allocated to the java subprocesses,useful for limiting RAM usage (default : unlimited)""") # activity classification arguments parser.add_argument('--activityClassification', metavar='True/False', default=True, type=str2bool, help="""Use pre-trained random forest to predict activity type (default : %(default)s)""") parser.add_argument('--activityModel', type=str, default="activityModels/doherty2018.tar", help="""trained activity model .tar file""") parser.add_argument('--rawOutput', metavar='True/False', default=False, type=str2bool, help="""output calibrated and resampled raw data to a .csv.gz file? NOTE: requires ~50MB per day. (default : %(default)s)""") parser.add_argument('--npyOutput', metavar='True/False', default=True, type=str2bool, help="""output calibrated and resampled raw data to .npy file? NOTE: requires ~60MB per day. (default : %(default)s)""") parser.add_argument('--fftOutput', metavar='True/False', default=False, type=str2bool, help="""output FFT epochs to a .csv file? NOTE: requires ~0.1GB per day. (default : %(default)s)""") # optional outputs parser.add_argument('--outputFolder', metavar='filename',default="", help="""folder for all of the output files, \ unless specified using other options""") parser.add_argument('--summaryFolder', metavar='filename',default="", help="folder for -summary.json summary stats") parser.add_argument('--epochFolder', metavar='filename', default="", help="""folder -epoch.csv.gz - must be an existing file if "-processRawFile" is set to False""") parser.add_argument('--timeSeriesFolder', metavar='filename', default="", help="folder for -timeSeries.csv.gz file") parser.add_argument('--nonWearFolder', metavar='filename',default="", help="folder for -nonWearBouts.csv.gz file") parser.add_argument('--stationaryFolder', metavar='filename', default="", help="folder -stationaryPoints.csv.gz file") parser.add_argument('--rawFolder', metavar='filename', default="", help="folder for raw .csv.gz file") parser.add_argument('--verbose', metavar='True/False', default=False, type=str2bool, help="""enable verbose logging? (default : %(default)s)""") parser.add_argument('--deleteIntermediateFiles', metavar='True/False', default=True, type=str2bool, help="""True will remove extra "helper" files created by the program (default : %(default)s)""") parser.add_argument('--intensityDistribution', metavar='True/False', default=False, type=str2bool, help="""Save intensity distribution (default : %(default)s)""") # # check that enough command line arguments are entered # if len(sys.argv) < 2: msg = "\nInvalid input, please enter at least 1 parameter, e.g." msg += "\npython accProcess.py data/sample.cwa.gz \n" accelerometer.accUtils.toScreen(msg) parser.print_help() sys.exit(-1) processingStartTime = datetime.datetime.now() args = parser.parse_args() ########################## # check input/output files/dirs exist and validate input args ########################## if args.processRawFile is False: #! TODO: this breaks for .cwa.gz files if len(args.rawFile.split('.')) < 2: args.rawFile += ".cwa" # TODO edge case since we still need a name? elif not os.path.isfile(args.rawFile): if args.rawFile: print("error: specified file " + args.rawFile + " does not exist. Exiting..") else: print("error: no file specified. Exiting..") sys.exit(-2) # get file extension rawFilePath, rawFileName = os.path.split(args.rawFile) rawFileName = rawFileName.split('.')[0] # remove any extension # check target output folders exist for path in [args.summaryFolder, args.nonWearFolder, args.epochFolder, args.stationaryFolder, args.timeSeriesFolder, args.outputFolder]: if len(path) > 0 and not os.access(path, os.F_OK): print("error: " + path + " is not a valid directory") sys.exit(-3) # assign output file names if args.outputFolder == "" and rawFilePath != "": args.outputFolder = rawFilePath + '/' if args.summaryFolder == "": args.summaryFolder = args.outputFolder if args.nonWearFolder == "": args.nonWearFolder = args.outputFolder if args.epochFolder == "": args.epochFolder = args.outputFolder if args.stationaryFolder == "": args.stationaryFolder = args.outputFolder if args.timeSeriesFolder == "": args.timeSeriesFolder = args.outputFolder if args.rawFolder == "": args.rawFolder = args.outputFolder args.summaryFile = args.summaryFolder + rawFileName + "-summary.json" args.nonWearFile = args.nonWearFolder + rawFileName + "-nonWearBouts.csv.gz" args.epochFile = args.epochFolder + rawFileName + "-epoch.csv.gz" args.stationaryFile = args.stationaryFolder + rawFileName + "-stationaryPoints.csv" args.tsFile = args.timeSeriesFolder + rawFileName + "-timeSeries.csv.gz" args.rawOutputFile = args.rawFolder + rawFileName + ".csv.gz" args.npyOutputFile = args.rawFolder + rawFileName + ".npy" # check user specified end time is not before start time if args.startTime and args.endTime: if args.startTime >= args.endTime: print("start and end time arguments are invalid!") print("startTime:", args.startTime.strftime("%Y-%m-%dT%H:%M")) print("endTime:", args.endTime.strftime("%Y-%m-%dT%H:%M")) sys.exit(-4) # print processing options to screen print("processing file " + args.rawFile + "' with these arguments:\n") for key, value in sorted(vars(args).items()): if not (isinstance(value, str) and len(value)==0): print(key.ljust(15), ':', value) print("\n") ########################## # start processing file ########################## summary = {} # now process the .CWA file if args.processRawFile: summary['file-name'] = args.rawFile accelerometer.device.processRawFileToEpoch(args.rawFile, args.epochFile, args.stationaryFile, summary, skipCalibration=args.skipCalibration, stationaryStd=args.stationaryStd, xIntercept=args.calOffset[0], yIntercept=args.calOffset[1], zIntercept=args.calOffset[2], xSlope=args.calSlope[0], ySlope=args.calSlope[1], zSlope=args.calSlope[2], xTemp=args.calTemp[0], yTemp=args.calTemp[1], zTemp=args.calTemp[2], meanTemp=args.meanTemp, rawDataParser=args.rawDataParser, javaHeapSpace=args.javaHeapSpace, skipFiltering=args.skipFiltering, sampleRate=args.sampleRate, epochPeriod=args.epochPeriod, useAbs=args.useAbs, activityClassification=args.activityClassification, rawOutput=args.rawOutput, rawOutputFile=args.rawOutputFile, npyOutput=args.npyOutput, npyOutputFile=args.npyOutputFile, fftOutput=args.fftOutput, startTime=args.startTime, endTime=args.endTime, verbose=args.verbose) print(args.rawFile) else: summary['file-name'] = args.epochFile data, time = import_npy(args.rawFile) # Place your code here ########################## # remove helper files and close program ########################## if args.deleteIntermediateFiles: try: os.remove(args.stationaryFile) os.remove(args.epochFile) os.remove(args.rawFile[:-4] + '.npy') except: accelerometer.accUtils.toScreen('could not delete helper file') # finally, print out processing summary message processingEndTime = datetime.datetime.now() processingTime = (processingEndTime - processingStartTime).total_seconds() accelerometer.accUtils.toScreen("in total, processing took " + \ str(processingTime) + " seconds") def str2bool(v): """ Used to parse true/false values from the command line. E.g. "True" -> True """ return v.lower() in ("yes", "true", "t", "1") def str2date(v): """ Used to parse date values from the command line. E.g. "1994-11-30T12:00" -> time.datetime """ eg = "1994-11-30T12:00" # example date if v.count("-")!=eg.count("-"): print("ERROR: not enough dashes in date") elif v.count("T")!=eg.count("T"): print("ERROR: no T seperator in date") elif v.count(":")!=eg.count(":"): print("ERROR: no ':' seperator in date") elif len(v.split("-")[0])!=4: print("ERROR: year in date must be 4 numbers") elif len(v.split("-")[1])!=2 and len(v.split("-")[1])!=1: print("ERROR: month in date must be 1-2 numbers") elif len(v.split("-")[2].split("T")[0])!=2 and len(v.split("-")[2].split("T")[0])!=1: print("ERROR: day in date must be 1-2 numbers") else: return pd.datetime.strptime(v, "%Y-%m-%dT%H:%M") print("please change your input date:") print('"'+v+'"') print("to match the example date format:") print('"'+eg+'"') raise ValueError("date in incorrect format") if __name__ == '__main__': main() # Standard boilerplate to call the main() function to begin the program.
[ 37811, 21575, 1627, 2891, 284, 7925, 11570, 1535, 7508, 422, 8320, 15635, 1366, 526, 15931, 198, 198, 11748, 8320, 15635, 13, 4134, 18274, 4487, 198, 11748, 1822, 29572, 198, 11748, 17268, 198, 11748, 4818, 8079, 198, 11748, 8320, 15635, ...
2.09198
7,980
from django.shortcuts import render from .models import VetsInfoTable # Create your views here.
[ 6738, 42625, 14208, 13, 19509, 23779, 1330, 8543, 198, 6738, 764, 27530, 1330, 569, 1039, 12360, 10962, 628, 198, 2, 13610, 534, 5009, 994, 13, 628 ]
3.807692
26
import sys import math import random # Figure out what we should name our output file, and how big it should be if len(sys.argv) != 3: # Make sure we get a file argument, and only that print("Incorrect number of arguments found, should be \"generate <file> 10^<x>\"") for i in range(10): with open("./gen/%s%d" % (sys.argv[1], i), "w") as file: for x in range(pow(10, int(sys.argv[2]))): xNum = random.randint(1, 10000) yNum = random.randint(1, 10000) file.write("%d %d\n" % (xNum, yNum))
[ 11748, 25064, 198, 11748, 10688, 198, 11748, 4738, 198, 198, 2, 11291, 503, 644, 356, 815, 1438, 674, 5072, 2393, 11, 290, 703, 1263, 340, 815, 307, 198, 361, 18896, 7, 17597, 13, 853, 85, 8, 14512, 513, 25, 1303, 6889, 1654, 356, ...
2.366812
229
from django.urls import path from wagtail.snippets.views import chooser, snippets app_name = 'wagtailsnippets' urlpatterns = [ path('', snippets.index, name='index'), path('choose/', chooser.choose, name='choose_generic'), path('choose/<slug:app_label>/<slug:model_name>/', chooser.choose, name='choose'), path('choose/<slug:app_label>/<slug:model_name>/<str:pk>/', chooser.chosen, name='chosen'), path('<slug:app_label>/<slug:model_name>/', snippets.list, name='list'), path('<slug:app_label>/<slug:model_name>/add/', snippets.create, name='add'), path('<slug:app_label>/<slug:model_name>/<str:pk>/', snippets.edit, name='edit'), path('<slug:app_label>/<slug:model_name>/multiple/delete/', snippets.delete, name='delete-multiple'), path('<slug:app_label>/<slug:model_name>/<str:pk>/delete/', snippets.delete, name='delete'), path('<slug:app_label>/<slug:model_name>/<str:pk>/usage/', snippets.usage, name='usage'), ]
[ 6738, 42625, 14208, 13, 6371, 82, 1330, 3108, 198, 198, 6738, 266, 363, 13199, 13, 16184, 3974, 1039, 13, 33571, 1330, 1727, 13416, 11, 45114, 628, 198, 1324, 62, 3672, 796, 705, 86, 363, 26404, 77, 3974, 1039, 6, 198, 6371, 33279, ...
2.395522
402
import pytest from easydict import EasyDict import numpy as np import gym from copy import deepcopy from ding.envs.env import check_array_space, check_different_memory, check_all, demonstrate_correct_procedure from ding.envs.env.tests import DemoEnv
[ 11748, 12972, 9288, 198, 6738, 2562, 11600, 1330, 16789, 35, 713, 198, 11748, 299, 32152, 355, 45941, 198, 11748, 11550, 198, 6738, 4866, 1330, 2769, 30073, 198, 198, 6738, 44852, 13, 268, 14259, 13, 24330, 1330, 2198, 62, 18747, 62, 13...
3.386667
75
# -*- encoding: utf-8 -*- """Unit tests for src/evergreen/metrics/buildmetrics.py.""" from __future__ import absolute_import from unittest.mock import MagicMock import pytest import evergreen.metrics.buildmetrics as under_test from evergreen.errors.exceptions import ActiveTaskMetricsException from evergreen.task import Task
[ 2, 532, 9, 12, 21004, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 37811, 26453, 5254, 329, 12351, 14, 964, 14809, 14, 4164, 10466, 14, 11249, 4164, 10466, 13, 9078, 526, 15931, 198, 6738, 11593, 37443, 834, 1330, 4112, 62, 11748, 198, ...
3.287129
101
#!/usr/bin/env python # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved import pickle as pkl import sys import torch """ Usage: # download your pretrained model: wget https://github.com/LikeLy-Journey/SegmenTron/releases/download/v0.1.0/tf-xception65-270e81cf.pth -O x65.pth # run the conversion ./convert-pretrained-model-to-d2.py x65.pth x65.pkl # Then, use x65.pkl with the following changes in config: MODEL: WEIGHTS: "/path/to/x65.pkl" PIXEL_MEAN: [128, 128, 128] PIXEL_STD: [128, 128, 128] INPUT: FORMAT: "RGB" """ if __name__ == "__main__": input = sys.argv[1] obj = torch.load(input, map_location="cpu") res = {"model": obj, "__author__": "third_party", "matching_heuristics": True} with open(sys.argv[2], "wb") as f: pkl.dump(res, f)
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 198, 2, 15069, 357, 66, 8, 3203, 11, 3457, 13, 290, 663, 29116, 13, 1439, 6923, 33876, 198, 198, 11748, 2298, 293, 355, 279, 41582, 198, 11748, 25064, 198, 11748, 28034, 198, 198, 37811, ...
2.419643
336
import random from floodsystem.utils import sorted_by_key # noqa from floodsystem.geo import stations_by_distance, stations_within_radius, rivers_with_station, stations_by_river,rivers_by_station_number from floodsystem.stationdata import build_station_list '''def test_geo(): #Task 1A #does the function give an output & if it's a list: out = build_station_list() assert type(out) == list #checking that list is a reasonable length assert len(out) >1700 assert len(out) <2500''' #Task 1B #Task 1D #Task1E
[ 11748, 4738, 198, 6738, 6947, 10057, 13, 26791, 1330, 23243, 62, 1525, 62, 2539, 220, 1303, 645, 20402, 198, 6738, 6947, 10057, 13, 469, 78, 1330, 8985, 62, 1525, 62, 30246, 11, 8985, 62, 33479, 62, 42172, 11, 18180, 62, 4480, 62, 1...
2.721698
212
#!/usr/bin/env python3 import os import aws_cdk as cdk # For consistency with TypeScript code, `cdk` is the preferred import name for # the CDK's core module. The following line also imports it as `core` for use # with examples from the CDK Developer's Guide, which are in the process of # being updated to use `cdk`. You may delete this import if you don't need it. from cdk_pipelines.cdk_pipelines import CdkPipelineStack app = cdk.App() CdkPipelineStack(app, "AWSomeServiceCatalogPipeline", description="CI/CD CDK Pipelines for Service Catalog Example", env={ 'region': app.node.try_get_context("region"), 'account': app.node.try_get_context("pipeline_account") } ) app.synth()
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 18, 198, 11748, 28686, 198, 198, 11748, 3253, 82, 62, 10210, 74, 355, 22927, 74, 198, 198, 2, 1114, 15794, 351, 5994, 7391, 2438, 11, 4600, 10210, 74, 63, 318, 262, 9871, 1330, 1438, 329,...
2.86166
253
# -*- coding: utf-8 -*- """ Authors: Tim Hessels UNESCO-IHE 2017 Contact: t.hessels@unesco-ihe.org Repository: https://github.com/wateraccounting/wa Module: Generator/Sheet3 """ import os def Create(Dir_Basin, Basin, Simulation, Dir_Basin_CSV_a, Dir_Basin_CSV_b): """ This functions create the monthly and yearly sheet 3 in pdf format, based on the csv files. Parameters ---------- Dir_Basin : str Path to all the output data of the Basin Basin : str Name of the basin Simulation : int Defines the simulation Dir_Basin_CSV_a : str Data path pointing to the CSV output files for sheet a Dir_Basin_CSV_b : str Data path pointing to the CSV output files for sheet b """ # import wa module from watools.Sheets import create_sheet3 # Create output folder for PDF files Dir_Basin_PDF = os.path.join(Dir_Basin, "Simulations", "Simulation_%d" %Simulation, "PDF") if not os.path.exists(Dir_Basin_PDF): os.mkdir(Dir_Basin_PDF) # Create output filename for PDFs FileName_Splitted = Dir_Basin_CSV_a.split('_') Year = str(FileName_Splitted[-1].split('.')[0]) outFile_a = os.path.join(Dir_Basin_PDF,'Sheet3a_Sim%s_%s_%s.pdf' %(Simulation, Basin, Year)) outFile_b = os.path.join(Dir_Basin_PDF,'Sheet3b_Sim%s_%s_%s.pdf' %(Simulation, Basin, Year)) # Create PDFs sheet3a_fh, sheet3b_fh = create_sheet3(Basin, str(Year), ['km3/year', 'kg/ha/year', 'kg/m3'], [Dir_Basin_CSV_a, Dir_Basin_CSV_b], [outFile_a, outFile_b]) return()
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 37811, 198, 30515, 669, 25, 5045, 367, 7878, 82, 198, 220, 220, 220, 220, 220, 220, 220, 220, 49372, 12, 40, 13909, 2177, 198, 17829, 25, 256, 13, 956, 14002, 31, 40...
2.38204
657
"""The user command.""" from json import dumps from .base import Base from bonita.api.bonita_client import BonitaClient
[ 37811, 464, 2836, 3141, 526, 15931, 198, 198, 6738, 33918, 1330, 45514, 198, 6738, 764, 8692, 1330, 7308, 198, 6738, 5351, 5350, 13, 15042, 13, 4189, 5350, 62, 16366, 1330, 7979, 5350, 11792, 628 ]
3.588235
34
from config import ANET_CFG import sys sys.path.append(ANET_CFG.DENSE_FLOW_ROOT+'/build') from libpydenseflow import TVL1FlowExtractor import action_caffe import numpy as np if __name__ == "__main__": import cv2 im1 = cv2.imread('../data/img_1.jpg') im2 = cv2.imread('../data/img_2.jpg') f = FlowExtractor(0) flow_frames = f.extract_flow([im1, im2]) from pylab import * plt.figure() plt.imshow(flow_frames[0]) plt.figure() plt.imshow(flow_frames[1]) plt.figure() plt.imshow(im1) plt.show() print flow_frames
[ 6738, 4566, 1330, 3537, 2767, 62, 22495, 38, 198, 198, 11748, 25064, 198, 198, 17597, 13, 6978, 13, 33295, 7, 1565, 2767, 62, 22495, 38, 13, 35, 24290, 62, 3697, 3913, 62, 13252, 2394, 10, 26488, 11249, 11537, 198, 198, 6738, 9195, ...
2.162264
265
#####################################################. # This file stores all the functions # # used for genrating all parameters # #####################################################. from rdkit.Chem import AllChem as Chem from rdkit.Chem import rdMolTransforms import os import pandas as pd from aqme.csearch import getDihedralMatches
[ 29113, 14468, 4242, 2, 13, 198, 2, 220, 220, 220, 220, 220, 220, 220, 770, 2393, 7000, 477, 262, 5499, 220, 220, 220, 220, 220, 220, 220, 220, 1303, 198, 2, 220, 220, 220, 220, 220, 220, 220, 220, 220, 973, 329, 2429, 8821, 477,...
3.300885
113
# Copyright 2014 Google Inc. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Tool for generating a user mapping from Google Code user to BitBucket user. """ import argparse import json import sys import issues def addIfNotPresent(users, user): """Adds a user if it is not already set.""" if user not in users: users[user] = user def _CreateUsersDict(issue_data, project_name): """Extract users from list of issues into a dict. Args: issue_data: Issue data project_name: The name of the project being exported. Returns: Dict of users associated with a list of issues """ users = {} for issue in issue_data: googlecode_issue = issues.GoogleCodeIssue( issue, project_name, OptionalMap()) reporting_user = googlecode_issue.GetAuthor() addIfNotPresent(users, reporting_user) assignee_user = googlecode_issue.GetOwner() addIfNotPresent(users, assignee_user) googlecode_comments = googlecode_issue.GetComments() for comment in googlecode_comments: googlecode_comment = issues.GoogleCodeComment(googlecode_issue, comment) commenting_user = googlecode_comment.GetAuthor() addIfNotPresent(users, commenting_user) return { "users": users } def Generate(issue_file_path, project_name): """Generates a user map for the specified issues. """ issue_data = None user_file = open(issue_file_path) user_data = json.load(user_file) user_projects = user_data["projects"] for project in user_projects: if project_name in project["name"]: issue_data = project["issues"]["items"] break if issue_data is None: raise issues.ProjectNotFoundError( "Project %s not found" % project_name) users = _CreateUsersDict(issue_data, project_name) with open("users.json", "w") as users_file: user_json = json.dumps(users, sort_keys=True, indent=4, separators=(",", ": "), ensure_ascii=False) users_file.write(unicode(user_json)) print "\nCreated file users.json.\n" def main(args): """The main function. Args: args: The command line arguments. Raises: issues.ProjectNotFoundError: The user passed in an invalid project name. """ parser = argparse.ArgumentParser() parser.add_argument("--issue_file_path", required=True, help="The path to the file containing the issues from" "Google Code.") parser.add_argument("--project_name", required=True, help="The name of the Google Code project you wish to" "export") parsed_args, _ = parser.parse_known_args(args) Generate(parsed_args.issue_file_path, parsed_args.project_name) if __name__ == "__main__": main(sys.argv)
[ 2, 15069, 1946, 3012, 3457, 13, 1439, 6923, 33876, 13, 198, 2, 198, 2, 49962, 739, 262, 24843, 13789, 11, 10628, 362, 13, 15, 357, 1169, 366, 34156, 15341, 198, 2, 345, 743, 407, 779, 428, 2393, 2845, 287, 11846, 351, 262, 13789, ...
2.911032
1,124
from flask import Blueprint from apps.auth.business.wxlogin import WxLoginBusiness from apps.auth.extentions import validation, parse_json_form from library.api.render import json_detail_render wxlogin = Blueprint("wxlogin", __name__)
[ 6738, 42903, 1330, 39932, 198, 198, 6738, 6725, 13, 18439, 13, 22680, 13, 49345, 38235, 1330, 370, 87, 47790, 24749, 198, 6738, 6725, 13, 18439, 13, 2302, 298, 507, 1330, 21201, 11, 21136, 62, 17752, 62, 687, 198, 6738, 5888, 13, 1504...
3.661538
65
# -*- coding: utf-8 -* # ALGG 03-01-2017 Creacin de mdulo jornada_teorica.
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 201, 198, 201, 198, 2, 8355, 11190, 7643, 12, 486, 12, 5539, 5844, 330, 259, 390, 45243, 43348, 474, 1211, 4763, 62, 660, 273, 3970, 13, 201, 198, 201, 198, 201, 198 ]
1.886364
44
''' This code was based on these repositories, so special thanks to: https://github.com/datademofun/spotify-flask https://github.com/drshrey/spotify-flask-auth-example ''' from flask import Flask, request, redirect, g, render_template, session from spotify_requests import spotify app = Flask(__name__) app.secret_key = 'some key for session' # ----------------------- AUTH API PROCEDURE ------------------------- def valid_token(resp): return resp is not None and not 'error' in resp # -------------------------- API REQUESTS ---------------------------- def make_search(search_type, name): if search_type not in ['artist', 'album', 'playlist', 'track']: return render_template('index.html') data = spotify.search(search_type, name) api_url = data[search_type + 's']['href'] items = data[search_type + 's']['items'] return render_template('search.html', name=name, results=items, api_url=api_url, search_type=search_type) if __name__ == "__main__": app.run(debug=True, port=spotify.PORT)
[ 7061, 6, 198, 220, 220, 220, 770, 2438, 373, 1912, 319, 777, 38072, 11, 198, 220, 220, 220, 523, 2041, 5176, 284, 25, 198, 220, 220, 220, 220, 220, 220, 220, 3740, 1378, 12567, 13, 785, 14, 19608, 36920, 1659, 403, 14, 20485, 1958...
2.494692
471
from ckan import model from ckan.lib.cli import CkanCommand from ckan.lib.munge import munge_title_to_name, substitute_ascii_equivalents from ckan.logic import get_action from ckan.lib.helpers import render_markdown from ckan.plugins import toolkit import logging log = logging.getLogger(__name__)
[ 6738, 269, 27541, 1330, 2746, 198, 6738, 269, 27541, 13, 8019, 13, 44506, 1330, 327, 27541, 21575, 198, 6738, 269, 27541, 13, 8019, 13, 6199, 469, 1330, 29856, 469, 62, 7839, 62, 1462, 62, 3672, 11, 15373, 62, 292, 979, 72, 62, 4853...
3.103093
97
# -*- coding: utf-8 -*- import numpy as np import cv2 from scipy.misc import imsave import matplotlib.pyplot as plt import analysis import imageprocess import datainterface import imagemosaicking town_names = ['', '', '', '', '', \ '', '', '', ''] for index in range(len(town_names)): town_names[index] = unicode(town_names[index], 'utf8') geojson_path = 'testdata/' #12 winter12933 = 'LC81290332016343LGN00_MTL' winter12833 = 'LC81280332016336LGN00_MTL' winter12834 = 'LC81280342016336LGN00_MTL' winter12 = (winter12933, winter12833, winter12834) #01 winter12933 = 'LC81290332017025LGN00_MTL' winter12833 = 'LC81280332017002LGN00_MTL' winter12834 = 'LC81280342017002LGN00_MTL' winter01 = (winter12933, winter12833, winter12834) #02 winter12933 = 'LC81290332017089LGN00_MTL'#32 winter12833 = 'LC81280332017034LGN00_MTL' winter12834 = 'LC81280342017034LGN00_MTL' winter02 = (winter12933, winter12833, winter12834) #06 summer12933 = 'LC81290332016151LGN00_MTL' summer12833 = 'LC81280332016176LGN00_MTL' summer12834 = 'LC81280342016176LGN00_MTL' summer06 = (summer12933, summer12833, summer12834) #07 summer12933 = 'LC81290332016183LGN00_MTL' summer12833 = 'LC81280332016208LGN00_MTL' summer12834 = 'LC81280342016208LGN00_MTL' summer07 = (summer12933, summer12833, summer12834) #08 summer12933 = 'LC81290332016247LGN00_MTL' summer12833 = 'LC81280332016240LGN00_MTL' summer12834 = 'LC81280342016240LGN00_MTL' summer08 = (summer12933, summer12833, summer12834) cases = (summer08,) case_name = ('Aug',) #cases = (winter12, winter01, winter02, summer06, summer07, summer08) #case_name = ('Nov','Jan','Feb','Jun','Jul','Aug',) #cases = (wintercode,) #case_name = ('winter') for ii in range(len(cases)): case = cases[ii] # image load imgcode1 = case[0] imgcode2 = case[1] imgcode3 = case[2] path1 = 'testdata/1-12933/' path2 = 'testdata/2-12833/' path3 = 'testdata/3-12834/' corner1 = datainterface.get_corner(imgcode1, path1) corner2 = datainterface.get_corner(imgcode2, path2) corner3 = datainterface.get_corner(imgcode3, path3) img1 = datainterface.get_band(imgcode1, 4, path1) img2 = datainterface.get_band(imgcode2, 4, path2) img3 = datainterface.get_band(imgcode3, 4, path3) bqa1 = datainterface.get_bqa(imgcode1, path1) bqa2 = datainterface.get_bqa(imgcode2, path2) bqa3 = datainterface.get_bqa(imgcode3, path3) file_date1 = datainterface.get_date(imgcode1, path1) file_date2 = datainterface.get_date(imgcode2, path2) file_date3 = datainterface.get_date(imgcode3, path3) # image analysis ndvi1, vfc1 = analysis.get_plant(imgcode1, path1) ndvi2, vfc2 = analysis.get_plant(imgcode2, path2) ndvi3, vfc3 = analysis.get_plant(imgcode3, path3) print 'complete ndvi calculation...' Ts1 = analysis.get_temperature(imgcode1, path1) Ts2 = analysis.get_temperature(imgcode2, path2) Ts3 = analysis.get_temperature(imgcode3, path3) print 'complete Ts calculation...' tvdi1, cover1 = analysis.get_drought(ndvi1, Ts1, bqa1) tvdi2, cover2 = analysis.get_drought(ndvi2, Ts2, bqa2) tvdi3, cover3 = analysis.get_drought(ndvi3, Ts3, bqa3) print 'complete tvdi calculation...' ndvi1_d = cv2.resize(ndvi1,None,fx=0.1,fy=0.1) ndvi2_d = cv2.resize(ndvi2,None,fx=0.1,fy=0.1) ndvi3_d = cv2.resize(ndvi3,None,fx=0.1,fy=0.1) vfc1_d = cv2.resize(vfc1,None,fx=0.1,fy=0.1) vfc2_d = cv2.resize(vfc2,None,fx=0.1,fy=0.1) vfc3_d = cv2.resize(vfc3,None,fx=0.1,fy=0.1) Ts1_d = cv2.resize(Ts1,None,fx=0.1,fy=0.1) Ts2_d = cv2.resize(Ts2,None,fx=0.1,fy=0.1) Ts3_d = cv2.resize(Ts3,None,fx=0.1,fy=0.1) tvdi1_d = cv2.resize(tvdi1,None,fx=0.1,fy=0.1) tvdi2_d = cv2.resize(tvdi2,None,fx=0.1,fy=0.1) tvdi3_d = cv2.resize(tvdi3,None,fx=0.1,fy=0.1) print 'complete image analyzing...' save_filename = 'output/' + case_name[ii] + '_' + 'ndvi1' + '.png' imsave(save_filename, ndvi1) save_filename = 'output/' + case_name[ii] + '_' + 'vfc1' + '.png' imsave(save_filename, vfc1) save_filename = 'output/' + case_name[ii] + '_' + 'ndvi2' + '.png' imsave(save_filename, ndvi2) save_filename = 'output/' + case_name[ii] + '_' + 'vfc2' + '.png' imsave(save_filename, vfc2) save_filename = 'output/' + case_name[ii] + '_' + 'ndvi3' + '.png' imsave(save_filename, ndvi3) save_filename = 'output/' + case_name[ii] + '_' + 'vfc3' + '.png' imsave(save_filename, vfc3) save_filename = 'output/' + case_name[ii] + '_' + 'Ts1' + '.png' imsave(save_filename, Ts1) save_filename = 'output/' + case_name[ii] + '_' + 'Ts2' + '.png' imsave(save_filename, Ts2) save_filename = 'output/' + case_name[ii] + '_' + 'Ts3' + '.png' imsave(save_filename, Ts3) save_filename = 'output/' + case_name[ii] + '_' + 'tvdi1' + '.png' imsave(save_filename, tvdi1) save_filename = 'output/' + case_name[ii] + '_' + 'tvdi2' + '.png' imsave(save_filename, tvdi2) save_filename = 'output/' + case_name[ii] + '_' + 'tvdi3' + '.png' imsave(save_filename, tvdi3) save_filename = 'output/d' + case_name[ii] + '_' + 'ndvi1_d' + '.png' imsave(save_filename, ndvi1_d) save_filename = 'output/d' + case_name[ii] + '_' + 'vfc1_d' + '.png' imsave(save_filename, vfc1_d) save_filename = 'output/d' + case_name[ii] + '_' + 'ndvi2_d' + '.png' imsave(save_filename, ndvi2_d) save_filename = 'output/d' + case_name[ii] + '_' + 'vfc2_d' + '.png' imsave(save_filename, vfc2_d) save_filename = 'output/d' + case_name[ii] + '_' + 'ndvi3_d' + '.png' imsave(save_filename, ndvi3_d) save_filename = 'output/d' + case_name[ii] + '_' + 'vfc3_d' + '.png' imsave(save_filename, vfc3_d) save_filename = 'output/d' + case_name[ii] + '_' + 'Ts1_d' + '.png' imsave(save_filename, Ts1_d) save_filename = 'output/d' + case_name[ii] + '_' + 'Ts2_d' + '.png' imsave(save_filename, Ts2_d) save_filename = 'output/d' + case_name[ii] + '_' + 'Ts3_d' + '.png' imsave(save_filename, Ts3_d) save_filename = 'output/d' + case_name[ii] + '_' + 'tvdi1_d' + '.png' imsave(save_filename, tvdi1_d) save_filename = 'output/d' + case_name[ii] + '_' + 'tvdi2_d' + '.png' imsave(save_filename, tvdi2_d) save_filename = 'output/d' + case_name[ii] + '_' + 'tvdi3_d' + '.png' imsave(save_filename, tvdi3_d) # image mosaicking imgall_origin, corner_origin = imagemosaicking.cut_img_easy(img1, img2, img3, corner1, corner2, corner3) imgall_ndvi, corner_ndvi = imagemosaicking.cut_img_easy(ndvi1, ndvi2, ndvi3, corner1, corner2, corner3) imgall_vfc, corner_vfc = imagemosaicking.cut_img_easy(vfc1, vfc2, vfc3, corner1, corner2, corner3) imgall_Ts, corner_Ts = imagemosaicking.cut_img_easy(Ts1, Ts2, Ts3, corner1, corner2, corner3) imgall_tvdi, corner_tvdi = imagemosaicking.cut_img_easy(tvdi1, tvdi2, tvdi3, corner1, corner2, corner3) imgall_tvdi_cover, corner_cover = imagemosaicking.cut_img_easy(cover1, cover2, cover3, corner1, corner2, corner3) save_filename = 'output/' + case_name[ii] + '_' + 'imgall_origin' + '.png' imsave(save_filename, imgall_origin) save_filename = 'output/' + case_name[ii] + '_' + 'imgall_ndvi' + '.png' imsave(save_filename, imgall_ndvi) save_filename = 'output/' + case_name[ii] + '_' + 'imgall_vfc' + '.png' imsave(save_filename, imgall_vfc) save_filename = 'output/' + case_name[ii] + '_' + 'imgall_Ts' + '.png' imsave(save_filename, imgall_Ts) save_filename = 'output/' + case_name[ii] + '_' + 'imgall_tvdi' + '.png' imsave(save_filename, imgall_tvdi) imgall_origin_d = cv2.resize(imgall_origin, None, fx=0.2, fy=0.2) imgall_ndvi_d = cv2.resize(imgall_ndvi, None, fx=0.2, fy=0.2) imgall_vfc_d = cv2.resize(imgall_vfc, None, fx=0.2, fy=0.2) imgall_Ts_d = cv2.resize(imgall_Ts, None, fx=0.2, fy=0.2) imgall_tvdi_d = cv2.resize(imgall_tvdi, None, fx=0.2, fy=0.2) imgall_tvdi_cover_d = cv2.resize(imgall_tvdi_cover, None, fx=0.2, fy=0.2) save_filename = 'output/d' + case_name[ii] + '_' + 'imgall_origin_d' + '.png' imsave(save_filename, imgall_origin_d) save_filename = 'output/d' + case_name[ii] + '_' + 'imgall_ndvi_d' + '.png' imsave(save_filename, imgall_ndvi_d) save_filename = 'output/d' + case_name[ii] + '_' + 'imgall_vfc_d' + '.png' imsave(save_filename, imgall_vfc_d) save_filename = 'output/d' + case_name[ii] + '_' + 'imgall_Ts_d' + '.png' imsave(save_filename, imgall_Ts_d) save_filename = 'output/d' + case_name[ii] + '_' + 'imgall_tvdi_d' + '.png' imsave(save_filename, imgall_tvdi_d) print 'complete image mosaicking...' # image filtering filter_box = 20 imgall_origin_filtered = imageprocess.mean_filter(imgall_origin_d, filter_box) imgall_ndvi_filtered = imageprocess.mean_filter(imgall_ndvi_d, filter_box) imgall_vfc_filtered = imageprocess.mean_filter(imgall_vfc_d, filter_box) imgall_Ts_filtered = imageprocess.mean_filter(imgall_Ts_d, filter_box) imgall_tvdi_filtered = imageprocess.mean_filter(imgall_tvdi_d, filter_box) print 'complete image filtering...' """ save_filename = 'output/' + case_name[ii] + '_' + 'imgall_origin_filtered' + '.png' imsave(save_filename, imgall_origin_filtered) save_filename = 'output/' + case_name[ii] + '_' + 'imgall_ndvi_filtered' + '.png' imsave(save_filename, imgall_ndvi_filtered) save_filename = 'output/' + case_name[ii] + '_' + 'imgall_vfc_filtered' + '.png' imsave(save_filename, imgall_vfc_filtered) save_filename = 'output/' + case_name[ii] + '_' + 'imgall_Ts_filtered' + '.png' imsave(save_filename, imgall_Ts_filtered) save_filename = 'output/' + case_name[ii] + '_' + 'imgall_tvdi_filtered' + '.png' imsave(save_filename, imgall_tvdi_filtered) """ filter_box = 5 imgall_origin = imageprocess.mean_filter(imgall_origin_d, filter_box) imgall_ndvi = imageprocess.mean_filter(imgall_ndvi_d, filter_box) imgall_vfc = imageprocess.mean_filter(imgall_vfc_d, filter_box) imgall_Ts = imageprocess.mean_filter(imgall_Ts_d, filter_box) imgall_tvdi = imageprocess.mean_filter(imgall_tvdi_d, filter_box) print 'complete image filtering...' # density divide vfc_3d = analysis.vfc_divide(imgall_vfc, imgall_ndvi) tvdi_3d = analysis.tvdi_divide(imgall_tvdi, imgall_ndvi, imgall_tvdi_cover_d) print 'complete density divide...' save_filename = 'output/' + case_name[ii] + '_' + 'vfc_3d' + '.png' imsave(save_filename, vfc_3d) save_filename = 'output/' + case_name[ii] + '_' + 'tvdi_3d' + '.png' imsave(save_filename, tvdi_3d) """ #pn_poly county_cover = np.zeros_like(imgall_origin) for town_num in range(len(town_names)): print town_num + 1 geo_filename = geojson_path + town_names[town_num] + '.geojson' geodata = datainterface.geojson_read(geo_filename) town_cover = imageprocess.pn_poly(imgall_origin, corner_origin, geodata) county_cover += town_cover town_origin = town_cover * imgall_origin town_vfc = town_cover * imgall_vfc town_Ts = town_cover * imgall_Ts town_tvdi = town_cover * imgall_tvdi town_vfc_4d = np.zeros((vfc_3d.shape[0], vfc_3d.shape[1], 4)) town_tvdi_4d = np.zeros((tvdi_3d.shape[0], tvdi_3d.shape[1], 4)) for i in range(3): town_vfc_4d[:, :, i] = vfc_3d[:, :, i] / 255.0 town_tvdi_4d[:, :, i] = tvdi_3d[:, :, i] / 255.0 town_vfc_4d[:,:,3] = town_cover town_tvdi_4d[:,:,3] = town_cover var_names = ('town_origin', 'town_vfc', 'town_Ts', 'town_tvdi',\ 'town_vfc_4d', 'town_tvdi_4d') for var_name in var_names: save_filename = 'output/' + case_name[ii] + town_names[town_num] + var_name + '_' + '.png' print 'saving images of '+ town_names[town_num] + var_name + '...' if (var_name != 'town_vfc_4d') and (var_name != 'town_tvdi_4d'): imsave(save_filename, eval(var_name) * town_cover) else: # img_temp = np.zeros((town_cover.shape[0], town_cover.shape[1],4)) # img_temp[:,:,0:3] = eval(var_name) # img_temp[:,:,3] = town_cover # imsave(save_filename, img_temp) imsave(save_filename, eval(var_name)) print 'saving images of county...' county_origin = county_cover * imgall_origin county_vfc = county_cover * imgall_vfc county_Ts = county_cover * imgall_Ts county_tvdi = county_cover * imgall_tvdi county_vfc_4d = np.zeros((vfc_3d.shape[0], vfc_3d.shape[1], 4)) county_tvdi_4d = np.zeros((tvdi_3d.shape[0], tvdi_3d.shape[1], 4)) for i in range(3): county_vfc_4d[:, :, i] = vfc_3d[:, :, i] / 255.0 county_tvdi_4d[:, :, i] = tvdi_3d[:, :, i] / 255.0 county_vfc_4d[:,:,3] = county_cover county_tvdi_4d[:,:,3] = county_cover # save county var_names = ('county_origin', 'county_vfc', 'county_Ts', 'county_tvdi',\ 'county_vfc_4d', 'county_tvdi_4d') for var_name in var_names: print var_name save_filename = 'output/' + case_name[ii] + var_name + '_' + '.png' print 'saving images of ' + var_name +'...' if (var_name != 'county_vfc_4d') and (var_name != 'county_tvdi_4d'): imsave(save_filename, eval(var_name) * county_cover) else: imsave(save_filename, eval(var_name)) # img_temp = np.zeros((county_cover.shape[0], county_cover.shape[1],4)) # img_temp[:,:,0:3] = eval(var_name) # img_temp[:,:,3] = county_cover # imsave(save_filename, img_temp) """
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 11748, 299, 32152, 355, 45941, 198, 11748, 269, 85, 17, 198, 6738, 629, 541, 88, 13, 44374, 1330, 545, 21928, 198, 11748, 2603, 29487, 8019, 13, 9078, 29487, 355, 458, ...
2.089792
6,593
import logging import os import unittest from logging.config import fileConfig from src.lambda_function import validate_configurations as validate # create logger assuming running from ./run script fileConfig('tests/logging_config.ini') logger = logging.getLogger(__name__) if __name__ == '__main__': unittest.main()
[ 11748, 18931, 198, 11748, 28686, 198, 11748, 555, 715, 395, 198, 198, 6738, 18931, 13, 11250, 1330, 2393, 16934, 198, 6738, 12351, 13, 50033, 62, 8818, 1330, 26571, 62, 11250, 20074, 355, 26571, 198, 198, 2, 2251, 49706, 13148, 2491, 42...
3.457447
94
import numpy as np import tensorflow from keras import Input, optimizers from keras import backend as K from keras.engine import Model from keras import layers from keras.layers import Bidirectional, LSTM, merge, Reshape, Lambda, Dense, BatchNormalization K.clear_session() print("...") # tendorflow config = tensorflow.ConfigProto() config.gpu_options.allow_growth = True session = tensorflow.Session(config=config) question_max_len = 40 answer_max_len = 40 embedding_dim = 300 input_question = Input(shape=(question_max_len, embedding_dim)) input_answer = Input(shape=(answer_max_len, embedding_dim)) # lstm question_lstm = Bidirectional(LSTM(64)) answer_lstm = Bidirectional(LSTM(64)) encoded_question = question_lstm(input_question) encoded_answer = answer_lstm(input_answer) cos_distance = merge([encoded_question, encoded_answer], mode='cos', dot_axes=1) cos_distance = Reshape((1,))(cos_distance) cos_similarity = Lambda(lambda x: 1 - x)(cos_distance) predictions = Dense(1, activation='sigmoid')(cos_similarity) model = Model([input_question, input_answer], [predictions]) sgd = optimizers.SGD(lr=0.1, clipvalue=0.5) model.compile(optimizer=sgd, loss='binary_crossentropy', metrics=['binary_accuracy']) model.summary() # questions = np.load('train' + '_' + 'questions' + '.npy') answers = np.load('train' + '_' + 'answers' + '.npy') labels = np.load('train' + '_' + 'labels' + '.npy') # dev dev_questions = np.load('dev' + '_' + 'questions' + '.npy') dev_answers = np.load('dev' + '_' + 'answers' + '.npy') dev_labels = np.load('dev' + '_' + 'labels' + '.npy') # model.fit([questions, answers], [labels], epochs=2, batch_size=256, validation_data=([dev_questions, dev_answers], [dev_labels])) # print('') predict = model.predict([dev_questions, dev_answers], verbose=1, batch_size=256) print(predict) np.save('predict.npy', predict)
[ 11748, 299, 32152, 355, 45941, 198, 11748, 11192, 273, 11125, 198, 6738, 41927, 292, 1330, 23412, 11, 6436, 11341, 198, 6738, 41927, 292, 1330, 30203, 355, 509, 198, 6738, 41927, 292, 13, 18392, 1330, 9104, 198, 6738, 41927, 292, 1330, ...
2.521739
759
from flask_socketio import SocketIO NOTI = 'notification'
[ 6738, 42903, 62, 44971, 952, 1330, 47068, 9399, 628, 198, 11929, 40, 796, 705, 1662, 2649, 6, 628 ]
3.388889
18
import pytest from weaverbird.backends.sql_translator.metadata import SqlQueryMetadataManager from weaverbird.backends.sql_translator.steps import translate_filter from weaverbird.backends.sql_translator.types import SQLQuery from weaverbird.pipeline.conditions import ComparisonCondition from weaverbird.pipeline.steps import FilterStep
[ 11748, 12972, 9288, 198, 198, 6738, 356, 8770, 16944, 13, 1891, 2412, 13, 25410, 62, 7645, 41880, 13, 38993, 1330, 311, 13976, 20746, 9171, 14706, 13511, 198, 6738, 356, 8770, 16944, 13, 1891, 2412, 13, 25410, 62, 7645, 41880, 13, 20214...
3.62766
94
""" Load tests from :class:`unittest.TestCase` subclasses. This plugin implements :func:`loadTestsFromName` and :func:`loadTestsFromModule` to load tests from :class:`unittest.TestCase` subclasses found in modules or named on the command line. """ # Adapted from unittest2/loader.py from the unittest2 plugins branch. # This module contains some code copied from unittest2/loader.py and other # code developed in reference to that module and others within unittest2. # unittest2 is Copyright (c) 2001-2010 Python Software Foundation; All # Rights Reserved. See: http://docs.python.org/license.html import logging import unittest from nose2 import events, util __unittest = True log = logging.getLogger(__name__)
[ 37811, 198, 8912, 5254, 422, 1058, 4871, 25, 63, 403, 715, 395, 13, 14402, 20448, 63, 850, 37724, 13, 198, 198, 1212, 13877, 23986, 1058, 20786, 25, 63, 2220, 51, 3558, 4863, 5376, 63, 290, 198, 25, 20786, 25, 63, 2220, 51, 3558, ...
3.384977
213
from app import app, db import models import views if __name__ == '__main__': app.run() # No need to do (debug=True), as in config.py, debug = true is already set. # app.run(debug=True) # app.run(debug=True, use_debugger=False, use_reloader=False)
[ 6738, 598, 1330, 598, 11, 20613, 198, 11748, 4981, 198, 11748, 5009, 198, 198, 361, 11593, 3672, 834, 6624, 705, 834, 12417, 834, 10354, 198, 220, 220, 220, 598, 13, 5143, 3419, 198, 220, 220, 220, 1303, 1400, 761, 284, 466, 357, 24...
2.65
100
import sys sys.path.append("./pysphere") from pysphere import VIServer from pysphere.resources.vi_exception import VIException, VIApiException, \ FaultTypes import sys if len(sys.argv) != 6: sys.exit("error = please check arguments") serverName = sys.argv[1] login = sys.argv[2] passwd = sys.argv[3] vm_name = sys.argv[4] snap_name = sys.argv[5] server = VIServer() server.connect(serverName, login, passwd) myVm = server.get_vm_by_name(vm_name) try: revertTask = myVm.revert_to_named_snapshot(snap_name) server.disconnect() except (VIException), err: print "RevertResult = " + err.message sys.exit(1) if revertTask is None: print "RevertResult = success" else: print "RevertResult = failure"
[ 11748, 25064, 201, 198, 17597, 13, 6978, 13, 33295, 7, 1911, 14, 79, 893, 79, 1456, 4943, 201, 198, 6738, 279, 893, 79, 1456, 1330, 50035, 18497, 201, 198, 6738, 279, 893, 79, 1456, 13, 37540, 13, 8903, 62, 1069, 4516, 1330, 13889, ...
2.254286
350
import json import logging import tensorflow as tf from easy_rec.python.protos.dataset_pb2 import DatasetConfig from easy_rec.python.protos.feature_config_pb2 import FeatureConfig from easy_rec.python.utils.config_util import get_compatible_feature_configs from easy_rec.python.utils.convert_rtp_fg import load_input_field_and_feature_config # NOQA if tf.__version__ >= '2.0': tf = tf.compat.v1
[ 11748, 33918, 198, 11748, 18931, 198, 198, 11748, 11192, 273, 11125, 355, 48700, 198, 198, 6738, 2562, 62, 8344, 13, 29412, 13, 11235, 418, 13, 19608, 292, 316, 62, 40842, 17, 1330, 16092, 292, 316, 16934, 198, 6738, 2562, 62, 8344, 1...
2.899281
139
import pytest
[ 11748, 12972, 9288, 628 ]
3.75
4
from enum import Enum import requests import argparse import nflgame def get_user_id_to_team_name(league_id): """ Gets a map of fantasy player user id to their team name """ user_id_to_team_name = {} r = requests.get("https://api.sleeper.app/v1/league/%s/users" % league_id) user_data = r.json() for user in user_data: user_id_to_team_name[user['user_id']] = user['display_name'] return user_id_to_team_name def get_roster_id_to_owner(user_id_to_team_name, league_id): """ Gets a map of the roster id to the fantasy owner team name """ roster_id_to_owner = {} r = requests.get('https://api.sleeper.app/v1/league/%s/rosters' % league_id) roster_info = r.json() for roster in roster_info: name = user_id_to_team_name[roster['owner_id']] roster_id_to_owner[roster['roster_id']] = name return roster_id_to_owner def get_owner_to_roster(player_id_to_custom_id, roster_id_to_owner, league_id, week): """ Gets a map of the owner team name to the roster players Also determines which two teams are in each matchup by getting a map of matchu pid to the two owners playing the game """ owner_to_roster = {} matchup_id_to_owners = {} r = requests.get('https://api.sleeper.app/v1/league/%s/matchups/%s' % (league_id, week)) rosters = r.json() for roster in rosters: owner = roster_id_to_owner[roster['roster_id']] player_ids = roster['players'] custom_ids = [player_id_to_custom_id[player_id] for player_id in player_ids] owner_to_roster[owner] = custom_ids matchup_id = roster['matchup_id'] if matchup_id in matchup_id_to_owners: matchup_id_to_owners[matchup_id].append(owner) else: matchup_id_to_owners[matchup_id] = [owner] return owner_to_roster, matchup_id_to_owners def get_player_id(first_name, last_name, team): """ Returns a custom player ID of first initial + last name + team i.e. for Tom Brady in New England that is T.Brady-NE """ if (team == None): team = 'None' return first_name[0] + "." + last_name + "-" + team def get_custom_id_to_info(): """ Gets a map of player name/team to position """ custom_id_to_info = {} player_id_to_custom_id = {} r = requests.get('https://api.sleeper.app/v1/players/nfl') players = r.json() for player_id in players: player = players[player_id] if player['fantasy_positions']: position = player['fantasy_positions'][0] if position in ('RB', 'WR', 'QB', 'TE'): custom_id = get_player_id(player['first_name'], player['last_name'], player['team']) if not custom_id: continue player_id_to_custom_id[player_id] = custom_id custom_id_to_info[custom_id] = position return custom_id_to_info, player_id_to_custom_id def get_player_to_points(year, week, custom_id_to_info): """ Gets a map of player ID to a tuple of the player's points and position """ player_id_to_points = {} games = nflgame.games(int(year), week=int(week)) players = nflgame.combine_game_stats(games) for player in players: custom_id = player.name + "-" + player.team if (custom_id in custom_id_to_info): points = calculate_player_points(player) player_id_to_points[custom_id] = (points, custom_id_to_info[custom_id]) print (player_id_to_points) return player_id_to_points def get_points(rbs, wrs, qbs, tes, roster_count): """ Gets the number of points a set of players makes up given the roster counts """ flex = rbs[roster_count['rb']:] + \ wrs[roster_count['wr']:] + \ tes[roster_count['te']:] flex.sort(reverse=True) return sum(rbs[:roster_count['rb']]) + \ sum(wrs[:roster_count['wr']]) + \ sum(qbs[:roster_count['qb']]) + \ sum(tes[:roster_count['te']]) + \ sum(flex[:roster_count['flex']]) def get_owner_to_score(owner_to_roster, player_to_points, roster_count): """ Gets a map of the owner to their fantasy score """ owner_to_score = {} for owner in owner_to_roster: rbs = [] wrs = [] qbs = [] tes = [] for player in owner_to_roster[owner]: if player in player_to_points: points, position = player_to_points[player] if position == 'RB': rbs.append(points) elif position == 'WR': wrs.append(points) elif position == 'QB': qbs.append(points) elif position == 'TE': tes.append(points) rbs.sort(reverse=True) wrs.sort(reverse=True) qbs.sort(reverse=True) tes.sort(reverse=True) owner_to_score[owner] = get_points(rbs, wrs, qbs, tes, roster_count) return owner_to_score def get_owner_to_weekly_record(matchup_id_to_owners, final_owner_to_score): """ Gets a map of the owner to their best ball record """ owner_to_record = {} for matchup_id in matchup_id_to_owners: owner_1 = matchup_id_to_owners[matchup_id][0] owner_2 = matchup_id_to_owners[matchup_id][1] score_1 = final_owner_to_score[owner_1] score_2 = final_owner_to_score[owner_2] if score_1 > score_2: owner_to_record[owner_1] = [1, 0, 0] owner_to_record[owner_2] = [0, 1, 0] elif score_1 == score_2: owner_to_record[owner_1] = [0, 0, 1] owner_to_record[owner_2] = [0, 0, 1] else: owner_to_record[owner_1] = [0, 1, 0] owner_to_record[owner_2] = [1, 0, 0] return owner_to_record if __name__ == "__main__": "Parses all the arguments into variables" args = parse_args() league_id = args['league_id'] year = args['year'] week = args['week'] end_week = args['end_week'] roster_count = {} roster_count['rb'] = args['num_rb'] roster_count['wr'] = args['num_wr'] roster_count['qb'] = args['num_qb'] roster_count['te'] = args['num_te'] roster_count['flex'] = args['num_flex'] # Gets a map of the user id to the owner team name user_id_to_team_name = get_user_id_to_team_name(league_id) # Gets a map of the roster id to the owner team name roster_id_to_owner = get_roster_id_to_owner(user_id_to_team_name, league_id) # Gets a map of each player id to their name and position custom_id_to_info, player_id_to_custom_id = get_custom_id_to_info() # A map to track the owner name to its best ball score final_owner_to_score = {} # A map of each owner to their best ball record final_owner_to_record = {} # A map of each owner to their best ball rank final_owner_to_rank = {} # A map of each owner to number of top 6 best ball performances final_owner_to_top_half_or_bottom = {} num_teams = len(user_id_to_team_name) if week: # If we are getting it for an individual week, calculate that data # Get the number of fantasy points each player scored that week player_to_points = get_player_to_points(year, week, custom_id_to_info) # Gets the map of each owner to their players and which two teams are playing each other owner_to_roster, matchup_id_to_owners = get_owner_to_roster( player_id_to_custom_id, roster_id_to_owner, league_id, week) # Gets the best ball score for each owner final_owner_to_score = get_owner_to_score(owner_to_roster, player_to_points, roster_count) # Gets the best ball record for each owner final_owner_to_record = get_owner_to_weekly_record( matchup_id_to_owners, final_owner_to_score) # Sorts the teams by score and determines if they are top 6 sorted_by_score = sorted(final_owner_to_score.items(), key=lambda kv: kv[1]) for i in range(len(sorted_by_score)): owner = sorted_by_score[i][0] final_owner_to_rank[owner] = [num_teams-i] if(i >= 6): final_owner_to_top_half_or_bottom[owner] = 1 else: # If we are getting it for the whole season, calculate that data for each week for week in range(1, end_week + 1): # Get the number of fantasy points each player scored that week player_to_points = get_player_to_points(year, week, custom_id_to_info) # Gets the map of each owner to their players and which two teams are playing each other owner_to_roster, matchup_id_to_owners = get_owner_to_roster( player_id_to_custom_id, roster_id_to_owner, league_id, week) # Gets the best ball score for each owner owner_to_score = get_owner_to_score(owner_to_roster, player_to_points, roster_count) # Gets the best ball record for each owner owner_to_record = get_owner_to_weekly_record( matchup_id_to_owners, owner_to_score) # Adds the total scores and records for each team for owner in owner_to_score: if owner in final_owner_to_score: final_owner_to_score[owner] += owner_to_score[owner] records = final_owner_to_record[owner] new_record = owner_to_record[owner] final_owner_to_record[owner] = [sum(x) for x in zip(records, new_record)] else: final_owner_to_score[owner] = owner_to_score[owner] final_owner_to_record[owner] = owner_to_record[owner] # Creates list of tuple of (owner, score) sorted by score sorted_by_score = sorted(final_owner_to_score.items(), key=lambda kv: kv[1]) # Sorts the teams by score and determines if they are top 6 for i in range(num_teams): owner = sorted_by_score[i][0] if owner in final_owner_to_rank: final_owner_to_rank[owner].append(num_teams-i) else: final_owner_to_rank[owner] = [num_teams-i] if(i >= 6): if owner in final_owner_to_top_half_or_bottom: final_owner_to_top_half_or_bottom[owner] += 1 else: final_owner_to_top_half_or_bottom[owner] = 1 # Prints out all the information sorted as the user wants for owner in final_owner_to_record: final_owner_to_record[owner] = ("-").join([str(elem) for elem in final_owner_to_record[owner]]) final_owner_to_rank[owner] = round(float(sum(final_owner_to_rank[owner])) / len(final_owner_to_rank[owner]), 2) if owner not in final_owner_to_top_half_or_bottom: final_owner_to_top_half_or_bottom[owner] = 0 if args['sort_by'] == 'record': sorted_records = final_owner_to_record.items() sorted_records = sorted(sorted_records, key=lambda tup: int(tup[1].split("-")[0])) # sort by the records print("{0:<20}{1:<20}{2:<20}{3:<20}{4:<20}".format('Team', 'Record(W-L-T)', 'Score', 'Top 6 Performances', 'Average Rank')) for record in sorted_records: owner = record[0] print("{0:<20}{1:<20}{2:<20}{3:<20}{4:<20}".format(owner, record[1], final_owner_to_score[owner], final_owner_to_top_half_or_bottom[owner], final_owner_to_rank[owner])) elif args['sort_by'] == 'rank': sorted_rank = final_owner_to_rank.items() sorted_rank = sorted(sorted_rank, key=lambda tup: tup[1], reverse=True) # sort by the ranks print("{0:<20}{1:<20}{2:<20}{3:<20}{4:<20}".format('Team', 'Average Rank', 'Score', 'Record(W-L-T)', 'Top 6 Performances')) for rank in sorted_rank: owner = rank[0] print("{0:<20}{1:<20}{2:<20}{3:<20}{4:<20}".format(owner, rank[1], final_owner_to_score[owner], final_owner_to_record[owner], final_owner_to_top_half_or_bottom[owner])) elif args['sort_by'] == 'top6': sorted_top6 = final_owner_to_top_half_or_bottom.items() sorted_top6 = sorted(sorted_top6, key=lambda tup: tup[1]) # sort by the top 6 performances print("{0:<20}{1:<20}{2:<20}{3:<20}{4:<20}".format('Team', 'Top 6 Performances', 'Score', 'Record(W-L-T)', 'Average Rank')) for top6 in sorted_top6: owner = top6[0] print("{0:<20}{1:<20}{2:<20}{3:<20}{4:<20}".format(owner, top6[1], final_owner_to_score[owner], final_owner_to_record[owner], final_owner_to_rank[owner])) elif args['sort_by'] == 'score': sorted_scores = final_owner_to_score.items() sorted_scores = sorted(sorted_scores, key=lambda tup: tup[1]) # sort by the scores print("{0:<20}{1:<20}{2:<20}{3:<20}{4:<20}".format('Team', 'Score', 'Record(W-L-T)', 'Top 6 Performances', 'Average Rank')) for score in sorted_scores: owner = score[0] print("{0:<20}{1:<20}{2:<20}{3:<20}{4:<20}".format(owner, score[1], final_owner_to_record[owner], final_owner_to_top_half_or_bottom[owner], final_owner_to_rank[owner])) else: print("Please enter either 'score', 'record', 'rank', or 'top6' for the sort option. %s isn't recognized" % args['sort_by'])
[ 6738, 33829, 1330, 2039, 388, 198, 11748, 7007, 198, 11748, 1822, 29572, 198, 11748, 299, 2704, 6057, 198, 198, 4299, 651, 62, 7220, 62, 312, 62, 1462, 62, 15097, 62, 3672, 7, 19316, 62, 312, 2599, 198, 220, 220, 220, 37227, 198, 22...
2.190008
6,105
#!/usr/bin/env python from datetime import datetime, timedelta import numpy as np from opendrift.readers import reader_basemap_landmask from opendrift.readers import reader_ROMS_native from kelp.kelpClass import PelagicPlanktonDrift from opendrift.readers import reader_netCDF_CF_generic import logging import gdal import os from netCDF4 import Dataset, datetime, date2num,num2date from numpy.random import RandomState import random import glob import matplotlib.pyplot as plt try: import ogr import osr except Exception as e: print(e) raise ValueError('OGR library is needed to read shapefiles.') ######################### # SETUP FOR KELP PROJECT ######################### startTime=datetime(2016,4,10,12,0,0) endTime=datetime(2016,5,26,23,0,0) startReleaseTime=startTime endReleaseTime=datetime(2016,4,12,12,0,0) releaseParticles=4 # Per timestep multiplied by gaussian bell (so maximum is releaseParticles and minimum is close to zero) lowDepth, highDepth = -7, -2 # in negative meters verticalBehavior=False hoursBetweenTimestepInROMSFiles=1 #kinoDirectory='/work/users/trondk/KINO/FORWARD/Run/RESULTS/'+str(startTime.year)+'/' kinoDirectory='/work/shared/nn9297k/Nordfjord/' kinoDirectory='/imr/vol1/NorFjords5/Malangen-160m_AUG2015-AUG2016/' svimDirectory='/work/shared/imr/SVIM/'+str(startTime.year)+'/' firstkino = int(date2num(startTime,units="days since 1948-01-01 00:00:00",calendar="standard")) lastkino = int(date2num(endTime,units="days since 1948-01-01 00:00:00",calendar="standard")) apattern = 'norfjords_160m_his.nc4_%s*'%(startTime.year) argument="%s%s"%(kinoDirectory,apattern) pattern_kino = glob.glob(argument) pattern_kino.sort() print(pattern_kino) pattern_svim='ocean_avg_*.nc' shapefile='/work/shared/nn9297k/Kelp/Shapefile/KelpExPol_utenNASAland.shp' print("=> Using shapefile %s"%(shapefile)) s = ogr.Open(shapefile) for layer in s: polygons=[x+1 for x in range(layer.GetFeatureCount()-1)] #polygons=[1,2,3,4,7] #N.Trench,Dogger bank C, Dogger bank, German bight, Viking bank #polygons=[2] #N.Trench,Dogger bank C, Dogger bank, German bight, Viking bank for polygonIndex in polygons: feature = layer.GetFeature(polygonIndex-1) print("Area",feature.GetGeometryRef().GetArea()) geom = feature.GetGeometryRef() points = geom.GetGeometryCount() ring = geom.GetGeometryRef(0) print("jj",polygonIndex, points) if ring.GetPointCount() > 3: outputFilename, animationFilename, plotFilename = createOutputFilenames(startTime,endTime,polygonIndex,shapefile,verticalBehavior) print("Result files will be stored as:\nnetCDF=> %s\nmp4=> %s"%(outputFilename,animationFilename)) createAndRunSimulation(lowDepth,highDepth,endTime, layer,polygonIndex,shapefile, outputFilename,animationFilename,plotFilename,releaseParticles, kinoDirectory,pattern_kino,svimDirectory,pattern_svim,verticalBehavior)
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 198, 198, 6738, 4818, 8079, 1330, 4818, 8079, 11, 28805, 12514, 198, 11748, 299, 32152, 355, 45941, 198, 198, 6738, 1034, 437, 35357, 13, 961, 364, 1330, 9173, 62, 12093, 368, 499, 62, 1044...
2.502447
1,226
import json import sqlite3 import typing from typing import Optional, Dict from copy import deepcopy from contextlib import suppress from bson.objectid import ObjectId from pymongo import MongoClient from pymongo.errors import ConfigurationError
[ 11748, 33918, 198, 11748, 44161, 578, 18, 198, 11748, 19720, 198, 6738, 19720, 1330, 32233, 11, 360, 713, 198, 6738, 4866, 1330, 2769, 30073, 198, 6738, 4732, 8019, 1330, 18175, 198, 198, 6738, 275, 1559, 13, 15252, 312, 1330, 9515, 739...
4.081967
61
# pylint: skip-file # type: ignore # -*- coding: utf-8 -*- # # tests.models.opstress.opstress_integration_test.py is part of The RAMSTK Project # # All rights reserved. # Copyright since 2007 Doyle "weibullguy" Rowland doyle.rowland <AT> reliaqual <DOT> com """Class for testing operating stress integrations.""" # Third Party Imports import pytest from pubsub import pub from treelib import Tree # RAMSTK Package Imports from ramstk.models import RAMSTKOpStressRecord, RAMSTKOpStressTable
[ 2, 279, 2645, 600, 25, 14267, 12, 7753, 198, 2, 2099, 25, 8856, 198, 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 2, 198, 2, 220, 220, 220, 220, 220, 220, 5254, 13, 27530, 13, 404, 41494, 13, 404, 41494, 62, ...
2.964706
170
import os from validr import T from aiohttp.web import json_response from aiohttp.web_request import Request from rssant_common import timezone from rssant_common.image_token import ImageToken, ImageTokenDecodeError from rssant_config import CONFIG from .rest_validr import ValidrRouteTableDef from .image_proxy import image_proxy routes = ValidrRouteTableDef()
[ 11748, 28686, 198, 6738, 4938, 81, 1330, 309, 198, 6738, 257, 952, 4023, 13, 12384, 1330, 33918, 62, 26209, 198, 6738, 257, 952, 4023, 13, 12384, 62, 25927, 1330, 19390, 198, 198, 6738, 374, 824, 415, 62, 11321, 1330, 640, 11340, 198,...
3.407407
108
from testing_config import BaseTestConfig from application.models import User from application.models import Chatroom import json from application.utils import auth
[ 6738, 4856, 62, 11250, 1330, 7308, 14402, 16934, 198, 6738, 3586, 13, 27530, 1330, 11787, 198, 6738, 3586, 13, 27530, 1330, 24101, 3823, 198, 11748, 33918, 198, 6738, 3586, 13, 26791, 1330, 6284, 628, 628, 198 ]
4.694444
36
import sys sys.path.insert(0, '/home/hena/caffe-ocr/buildcmake/install/python') sys.path.insert(0, '/home/hena/tool/protobuf-3.1.0/python') import caffe import math import numpy as np
[ 11748, 25064, 198, 17597, 13, 6978, 13, 28463, 7, 15, 11, 31051, 11195, 14, 831, 64, 14, 66, 21223, 12, 1696, 14, 11249, 11215, 539, 14, 17350, 14, 29412, 11537, 198, 17597, 13, 6978, 13, 28463, 7, 15, 11, 31051, 11195, 14, 831, 6...
2.395062
81
""" Tools for creating and working with Line (Station) Grids """ from typing import Union import pyproj import numpy as np _atype = Union[type(None), np.ndarray] _ptype = Union[type(None), pyproj.Proj]
[ 37811, 198, 33637, 329, 4441, 290, 1762, 351, 6910, 357, 12367, 8, 1902, 2340, 198, 37811, 198, 198, 6738, 19720, 1330, 4479, 198, 11748, 12972, 1676, 73, 198, 11748, 299, 32152, 355, 45941, 628, 198, 62, 265, 2981, 796, 4479, 58, 490...
2.957143
70
import numpy as np from ..reco.disp import disp_vector import astropy.units as u import matplotlib.pyplot as plt from ctapipe.visualization import CameraDisplay __all__ = [ 'overlay_disp_vector', 'overlay_hillas_major_axis', 'overlay_source', 'display_dl1_event', ] def display_dl1_event(event, camera_geometry, tel_id=1, axes=None, **kwargs): """ Display a DL1 event (image and pulse time map) side by side Parameters ---------- event: ctapipe event tel_id: int axes: list of `matplotlib.pyplot.axes` of shape (2,) or None kwargs: kwargs for `ctapipe.visualization.CameraDisplay` Returns ------- axes: `matplotlib.pyplot.axes` """ if axes is None: fig, axes = plt.subplots(1, 2, figsize=(12, 5)) image = event.dl1.tel[tel_id].image peak_time = event.dl1.tel[tel_id].peak_time if image is None or peak_time is None: raise Exception(f"There is no calibrated image or pulse time map for telescope {tel_id}") d1 = CameraDisplay(camera_geometry, image, ax=axes[0], **kwargs) d1.add_colorbar(ax=axes[0]) d2 = CameraDisplay(camera_geometry, peak_time, ax=axes[1], **kwargs) d2.add_colorbar(ax=axes[1]) return axes def overlay_source(display, source_pos_x, source_pos_y, **kwargs): """ Display the source (event) position in the camera Parameters ---------- display: `ctapipe.visualization.CameraDisplay` source_pos_x: `astropy.units.Quantity` source_pos_y: `astropy.units.Quantity` kwargs: args for `matplotlib.pyplot.scatter` Returns ------- `matplotlib.pyplot.axes` """ kwargs['marker'] = 'x' if 'marker' not in kwargs else kwargs['marker'] kwargs['color'] = 'red' if 'color' not in kwargs else kwargs['color'] display.axes.scatter(source_pos_x, source_pos_y, **kwargs) def overlay_disp_vector(display, disp, hillas, **kwargs): """ Overlay disp vector on a CameraDisplay Parameters ---------- display: `ctapipe.visualization.CameraDisplay` disp: `DispContainer` hillas: `ctapipe.containers.HillasParametersContainer` kwargs: args for `matplotlib.pyplot.quiver` """ assert np.isfinite([hillas.x.value, hillas.y.value]).all() if not np.isfinite([disp.dx.value, disp.dy.value]).all(): disp_vector(disp) display.axes.quiver(hillas.x, hillas.y, disp.dx, disp.dy, units='xy', scale=1*u.m, angles='xy', **kwargs, ) display.axes.quiver(hillas.x.value, hillas.y.value, disp.dx.value, disp.dy.value, units='xy', scale=1) def overlay_hillas_major_axis(display, hillas, **kwargs): """ Overlay hillas ellipse major axis on a CameraDisplay. Parameters ---------- display: `ctapipe.visualization.CameraDisplay` hillas: `ctapipe.containers.HillaParametersContainer` kwargs: args for `matplotlib.pyplot.plot` """ kwargs['color'] = 'black' if 'color' not in kwargs else kwargs['color'] length = hillas.length * 2 x = -length + 2 * length * np.arange(10) / 10 display.axes.plot(hillas.x + x * np.cos(hillas.psi.to(u.rad).value), hillas.y + x * np.sin(hillas.psi.to(u.rad).value), **kwargs, )
[ 11748, 299, 32152, 355, 45941, 198, 6738, 11485, 260, 1073, 13, 6381, 79, 1330, 4596, 62, 31364, 198, 11748, 6468, 28338, 13, 41667, 355, 334, 198, 11748, 2603, 29487, 8019, 13, 9078, 29487, 355, 458, 83, 198, 6738, 269, 44335, 3757, ...
2.289993
1,469
import numpy as np import random from scipy.stats import skew as scipy_skew from skimage.transform import resize as skimage_resize from QFlow import config ## set of functions for loading and preparing a dataset for training. def get_num_min_class(labels): ''' Get the number of the minimum represented class in label vector. Used for resampling data. input: labels: np.ndarray of labels outputs: num_samples: int number of samples for minimum class ''' # use argmax as example's class argmax_labels = np.argmax(labels, axis=-1) # max of num_samples is all one label num_samples = labels.shape[0] for i in range(labels.shape[-1]): lab_elems = np.sum(argmax_labels==i) if lab_elems < num_samples: num_samples = lab_elems return num_samples def resample_data(features, state_labels, labels=None, seed=None): ''' Resample data to be evenly distributed across classes in labels by cutting number of examples for each class to be equal to the number of examples in the least represented class. (classes assumed to be last axis of labels). Shuffles after resampling. inputs: features: ndarray of features to be resampled. Resample along first axis. state_labels: ndarray of labels to be used for resampling labels: ndarray of labels to be resampled. return_state: bool specifying whether to return state labels seed: Seed of random number generator for shuffling idxs during resample and for shuffling resampled features and labels. outputs: features: list of resampled features labels: list of resampled labels ''' rng = np.random.default_rng(seed) num_samples = get_num_min_class(state_labels) features_resamp = []; state_labels_resamp = []; labels_resamp = [] for i in range(state_labels.shape[-1]): s_idxs = state_labels.argmax(axis=-1)==i # first get full array of single state features_s_full = features[s_idxs] state_labels_s_full = state_labels[s_idxs] if labels is not None: labels_s_full = labels[s_idxs] # then get idxs (0-length), shuffle, and slice to num_samples # shuffle idxs to be sure labels and features are shuffled together idxs = list(range(features_s_full.shape[0])) rng.shuffle(idxs) features_resamp.append(features_s_full[idxs[:num_samples]]) state_labels_resamp.append(state_labels_s_full[idxs[:num_samples]]) if labels is not None: labels_resamp.append(labels_s_full[idxs[:num_samples]]) features_resamp_arr = np.concatenate(features_resamp, axis=0) state_labels_resamp_arr = np.concatenate(state_labels_resamp, axis=0) if labels is not None: labels_resamp_arr = np.concatenate(labels_resamp, axis=0) idxs = list(range(features_resamp_arr.shape[0])) rng.shuffle(idxs) if labels is not None: return features_resamp_arr[idxs], labels_resamp_arr[idxs] elif labels is None: return features_resamp_arr[idxs], state_labels_resamp_arr[idxs] def noise_mag_to_class(state_labels, noise_mags, low_thresholds=None, high_thresholds=None): ''' Function to convert noise magnitudes to noise classes. Noise class thresholds are defined here. Thresholds for states order is: no dot, left dot, central dot, right dot, double dot Default low thresholds is the linear extrapolation to 100 % accuracy of an average noisy-trained model vs. noise_mag. Default high thresholds are from linear extrapolation to 0 % accuracy of an average noisy trained model vs. noise_mag. inputs: state_labels: list of state labels. shape assumed to be (num_examples, num_states). noise_mags: list of float noise_mags for state_labels. shape assumed to be (num_examples, ). low_thresholds: list of floats of shape (num_state, ) specifying high signal to noise class thresholds. high_thresholds: list of floats of shape (num_state, ) specifying high signal to noise class thresholds. ''' # set number of noise classes and states. # length of thresholds must be equal to num_states. # no num_quality_classes != 3 are supported. num_quality_classes = config.NUM_QUALITY_CLASSES num_states = config.NUM_STATES # set default thresholds if high_thresholds is None: high_thresholds = [1.22, 1.00, 1.21, 0.68, 2.00] if low_thresholds is None: low_thresholds = [0.31, 0.32, 0.41, 0.05, 0.47] low_thresholds = np.array(low_thresholds) high_thresholds = np.array(high_thresholds) quality_classes = np.zeros(noise_mags.shape+(num_quality_classes,)) # use fractional labels by taking weighted average after # applying thresholds num_states = state_labels.shape[-1] # get per state classes then sum across last axis later per_state_classes = np.zeros( noise_mags.shape + (num_quality_classes,) + (num_states,)) # use boolean indexing to define classes from noise mags/threshold arrays for i in range(num_states): per_state_classes[noise_mags <= low_thresholds[i],0, i] = 1 per_state_classes[(noise_mags > low_thresholds[i]) &\ (noise_mags <= high_thresholds[i]), 1, i] = 1 per_state_classes[noise_mags > high_thresholds[i], 2, i] = 1 # multiply each first axis element then sum across last axes quality_classes = np.einsum('ijk,ik->ij', per_state_classes, state_labels) return quality_classes def get_data(f, train_test_split=0.9, dat_key='sensor', label_key='state', resample=True, seed=None, low_thresholds=None, high_thresholds=None): ''' Reads in the subregion data and converts it to a format useful for training Note that the data is shuffled after reading in. inputs: f: one of: str path to .npz file containing cropped data dict of cropped data. train_test_split: float fraction of data to use for training. resample: bool specifying whether to resample data to get even state representation. seed: int random seed for file shuffling. label_key: string key for data used for the label. One of: 'data_quality', 'noise_mag_factor', 'state'. low_threshold: list of noise levels to use for high/moderate signal to noise ratio threshold. high_threshold: list of noise levels to use for moderate/low signal to noise ratio threshold. outputs: train_data: np.ndarray of training data. train_labels: np.ndarray of training labels. eval_data: np.ndarray of training data. eval_labels: np.ndarray of training labels. ''' # treat f as path, or if TypeError treat as dict. try: dict_of_dicts = np.load(f, allow_pickle = True) file_on_disk = True except TypeError: dict_of_dicts = f file_on_disk = False files = list(dict_of_dicts.keys()) random.Random(seed).shuffle(files) inp = [] oup_state = [] # if we want a nonstate label load it so we can resample if label_key!='state': oup_labels = [] else: oup_labels = None train_labels = None eval_labels = None # if label is noise class, we need to get noise mag labels first # then process to turn the mag into a class label if label_key == 'data_quality': data_quality = True label_key = 'noise_mag_factor' else: data_quality = False for file in files: # for compressed data, file is the key of the dict of dicts if file_on_disk: data_dict = dict_of_dicts[file].item() else: data_dict = dict_of_dicts[file] dat = data_dict[dat_key] # generates a list of arrays inp.append(dat.reshape(config.SUB_SIZE,config.SUB_SIZE,1)) oup_state.append(data_dict['state']) # generates a list of arrays if oup_labels is not None: oup_labels.append(data_dict[label_key]) inp = np.array(inp) # converts the list to np.array oup_state = np.array(oup_state) # converts the list to np.array if oup_labels is not None: oup_labels = np.array(oup_labels) # split data into train and evaluatoin data/labels n_samples = inp.shape[0] print("Total number of samples :", n_samples) n_train = int(train_test_split * n_samples) train_data = inp[:n_train] print("Training data info:", train_data.shape) train_states = oup_state[:n_train] if oup_labels is not None: train_labels = oup_labels[:n_train] eval_data = inp[n_train:] print("Evaluation data info:", eval_data.shape) eval_states = oup_state[n_train:] if oup_labels is not None: eval_labels = oup_labels[n_train:] # convert noise mag to class before resampling/getting noise mags if # needed because resampling doesnt return state labels if data_quality: train_labels = noise_mag_to_class( train_states, train_labels, low_thresholds=low_thresholds, high_thresholds=high_thresholds, ) eval_labels = noise_mag_to_class( eval_states, eval_labels, low_thresholds=low_thresholds, high_thresholds=high_thresholds, ) # resample to make state representation even if resample: train_data, train_labels = resample_data( train_data, train_states, train_labels) eval_data, eval_labels = resample_data( eval_data, eval_states, eval_labels) elif not resample and label_key=='state': train_labels = train_states eval_labels = eval_states # expand dim of labels to make sure that they have proper shape if oup_labels is not None and len(train_labels.shape)==1: np.expand_dims(train_labels, 1) if oup_labels is not None and len(eval_labels.shape)==1: np.expand_dims(eval_labels, 1) return train_data, train_labels, eval_data, eval_labels ## preprocess functions def gradient(x): ''' Take gradient of an ndarray in specified direction. Thin wrapper around np.gradient(). Also note that x -> axis=1 and y-> axis=0 input: x: An numpy ndarray to take the gradient of output: numpy ndarray containing gradient in x direction. ''' return np.gradient(x, axis=1) def apply_threshold(x, threshold_val=10, threshold_to=0): ''' Thresholds an numpy ndarray to remove Args: x = numpy array with data to be filtered threshold_val = percentile below which to set values to zero ''' x[x < np.abs(np.percentile(x.flatten(),threshold_val))] = threshold_to return x def apply_clipping(x, clip_val=3, clip_to='clip_val'): ''' Clip input symmetrically at clip_val number of std devs. Do not zscore norm x, but apply thresholds using normed x ''' x_clipped = np.copy(x) mean = np.mean(x) std = np.std(x) norm_x = (x - mean) / std # set clipped values to either the mean or clip threshold if clip_to.lower() == 'clip_val': x_clipped[norm_x < -clip_val] = -clip_val * std + mean x_clipped[norm_x > clip_val] = clip_val * std + mean elif clip_to.lower() == 'mean': x_clipped[norm_x < -clip_val] = mean x_clipped[norm_x > clip_val] = mean else: raise KeyError('"clip_to" option not valid: ' +str(clip_to) +\ 'Valid options: clip_val, mean') return x_clipped def autoflip_skew(data): ''' Autoflip a numpy ndarray based on the skew of the values (effective for gradient data). ''' skew_sign = np.sign(scipy_skew(np.ravel(data))) return data*skew_sign def zscore_norm(x): ''' Takes a numpy ndarray and returns a z-score normalized version ''' return (x-x.mean())/x.std()
[ 11748, 299, 32152, 355, 45941, 198, 11748, 4738, 198, 6738, 629, 541, 88, 13, 34242, 1330, 43370, 355, 629, 541, 88, 62, 82, 365, 86, 198, 6738, 1341, 9060, 13, 35636, 1330, 47558, 355, 1341, 9060, 62, 411, 1096, 198, 198, 6738, 119...
2.423729
5,015
""" Test PEP 0448 -- Additional Unpacking Generalizations https://www.python.org/dev/peps/pep-0448/ """ # pylint: disable=superfluous-parens, unnecessary-comprehension UNPACK_TUPLE = (*range(4), 4) UNPACK_LIST = [*range(4), 4] UNPACK_SET = {*range(4), 4} UNPACK_DICT = {'a': 1, **{'b': '2'}} UNPACK_DICT2 = {**UNPACK_DICT, "x": 1, "y": 2} UNPACK_DICT3 = {**{'a': 1}, 'a': 2, **{'a': 3}} UNPACK_IN_COMP = {elem for elem in (*range(10))} # [star-needs-assignment-target]
[ 37811, 198, 14402, 350, 8905, 657, 31115, 1377, 15891, 791, 41291, 3611, 4582, 198, 5450, 1378, 2503, 13, 29412, 13, 2398, 14, 7959, 14, 431, 862, 14, 431, 79, 12, 15, 31115, 14, 198, 37811, 198, 198, 2, 279, 2645, 600, 25, 15560, ...
2.165138
218
# -*- coding: utf-8 -*-
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198 ]
1.714286
14
import pyglet print('Loading resources') def center_image(image): """Sets an image's anchor point to its center""" image.anchor_x = image.width / 2 image.anchor_y = image.height / 2 # Tell pyglet where to find the resources pyglet.resource.path = ['./resources', './resources/backgrounds'] pyglet.resource.reindex() images = list() # Load the three main resources and get them to draw centered tank_body_img = pyglet.resource.image('tank_body.png') images.append(tank_body_img) tank_head_img = pyglet.resource.image('tank_head.png') images.append(tank_head_img) boxlife_img = pyglet.resource.image('boxlife.png') images.append(boxlife_img) boxlife_dead_img = pyglet.resource.image('boxlife_dead.png') images.append(boxlife_dead_img) wheel_img = pyglet.resource.image('wheel.png') images.append(wheel_img) thread_img = pyglet.resource.image('thread.png') images.append(thread_img) motorbike_chassis_img = pyglet.resource.image('motorbike_chassis.png') images.append(motorbike_chassis_img) mb_wheel_img = pyglet.resource.image('mb_wheel.png') images.append(mb_wheel_img) mb_holder_img = pyglet.resource.image('mb_holder.png') images.append(mb_holder_img) vbv_chassis_img = pyglet.resource.image('vbv_chassis.png') images.append(vbv_chassis_img) vbv_wheels_img = pyglet.resource.image('vbv_wheels.png') images.append(vbv_wheels_img) vbv_platform_img = pyglet.resource.image('vbv_platform.png') images.append(vbv_platform_img) vb_net_img = pyglet.resource.image('vb_net.png') images.append(vb_net_img) vb_ball_img = pyglet.resource.image('vb_ball.png') images.append(vb_ball_img) game1_button_img = pyglet.resource.image('game1.png') images.append(game1_button_img) game1_button_hover_img = pyglet.resource.image('game1_hover.png') images.append(game1_button_hover_img) game2_button_img = pyglet.resource.image('game2.png') images.append(game2_button_img) game2_button_hover_img = pyglet.resource.image('game2_hover.png') images.append(game2_button_hover_img) game3_button_img = pyglet.resource.image('game3.png') images.append(game3_button_img) game3_button_hover_img = pyglet.resource.image('game3_hover.png') images.append(game3_button_hover_img) game1_hs_button_img = pyglet.resource.image('game1_hs.png') images.append(game1_hs_button_img) game1_hs_button_hover_img = pyglet.resource.image('game1_hs_hover.png') images.append(game1_hs_button_hover_img) game2_hs_button_img = pyglet.resource.image('game2_hs.png') images.append(game2_hs_button_img) game2_hs_button_hover_img = pyglet.resource.image('game2_hs_hover.png') images.append(game2_hs_button_hover_img) menu_button_img = pyglet.resource.image('menu.png') images.append(menu_button_img) gravity_button_img = pyglet.resource.image('gravity.png') images.append(gravity_button_img) fullscreen_button_img = pyglet.resource.image('fullscreen.png') images.append(fullscreen_button_img) restart_button_img = pyglet.resource.image('restart_button.png') images.append(restart_button_img) enter_button_img = pyglet.resource.image('enter_button.png') images.append(enter_button_img) enter_button_hover_img = pyglet.resource.image('enter_button_hover.png') images.append(enter_button_hover_img) circle_meter_img = pyglet.resource.image('circle_meter.png') images.append(circle_meter_img) pointer_img = pyglet.resource.image('pointer.png') images.append(pointer_img) finishflag_img = pyglet.resource.image('finishflag.png') images.append(finishflag_img) goal_meter_img = pyglet.resource.image('goal_meter.png') images.append(goal_meter_img) bg_goal_meter_img = pyglet.resource.image('bg_goal_meter.png') images.append(bg_goal_meter_img) background_img = pyglet.resource.image('background.png') images.append(background_img) for image in images: center_image(image) # load backgrounds parallax_bgs = list() layer_counts = (3, 2, 2, 2, 3, 4) for bg_i, layer_count in enumerate(layer_counts): bg_set = list() for layer_i in range(layer_count): bg_set.append(pyglet.resource.image('{}layer_{}.png'.format(bg_i, layer_i))) parallax_bgs.append(tuple(bg_set)) parallax_bgs = tuple(parallax_bgs) # Load sfx without streaming engine_sfx = pyglet.media.load('./resources/engine_sfx.wav', streaming=False) bg_music = pyglet.media.load('./resources/bg_music.wav', streaming=False) print('Resource loading successful')
[ 11748, 12972, 70, 1616, 198, 198, 4798, 10786, 19031, 4133, 11537, 198, 198, 4299, 3641, 62, 9060, 7, 9060, 2599, 198, 220, 220, 220, 37227, 50, 1039, 281, 2939, 338, 18021, 966, 284, 663, 3641, 37811, 198, 220, 220, 220, 2939, 13, ...
2.616918
1,655
#!/usr/bin/env python3 # -*- coding: utf-8 -*- __author__ = 'ipetrash' # SOURCE: https://github.com/gil9red/VideoStreamingWithEncryption/blob/37cf7f501460a286ec44a20db7b2403e8cb05d97/server_GUI_Qt/inner_libs/gui/SelectDirBox.py import os from PyQt5.QtWidgets import QWidget, QLineEdit, QLabel, QPushButton, QHBoxLayout, QFileDialog, QStyle from PyQt5.QtCore import pyqtSignal if __name__ == '__main__': from PyQt5.QtWidgets import QApplication app = QApplication([]) mw = SelectDirBox() mw.valueChanged.connect( lambda value: print(f'Selected directory: {value}') ) mw.show() app.exec()
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 18, 198, 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 198, 834, 9800, 834, 796, 705, 541, 21879, 1077, 6, 628, 198, 2, 311, 31033, 25, 3740, 1378, 12567, 13, 785, 14...
2.330882
272
import numpy as np import picoscript import cv2 import HeightTracker import atexit print "Setting Parameters..." zDacRange = 0.215 # Sensor specific number windowSize = 3e-6 # window size in meters windowBLHCX = 3.5e-6 # window bottom left hand corner X-axis in meters windowBLHCY = 3.5e-6 # window bottom left hand corner Y-axis in meters imageBuffer = 0 # buffer for tracking image (0-7) binary = True servoRange = picoscript.GetServoTopographyRange() imageRange = servoRange * zDacRange MAX_SHORT = 2**15 # Calculates scan offset for new image. Takes an image, roi template and bottom # left hand corner if __name__ == "__main__": atexit.register(picoscript.Disconnect) heighttrack = HeightTracker.Track() heighttrack.start() RunStabilize = True print "Waiting for current scan to end..." picoscript.WaitForStatusScanning(False) print "Starting stabilization..." while True: if RunStabilize: Stabilize() position = picoscript.GetStatusApproachPosition() picoscript.ScanStartDown() picoscript.WaitForStatusScanning(True) picoscript.WaitForStatusScanning(False) RunStabilize = position == picoscript.GetStatusApproachPosition()
[ 11748, 299, 32152, 355, 45941, 198, 11748, 8301, 418, 6519, 198, 11748, 269, 85, 17, 198, 11748, 27280, 35694, 198, 11748, 379, 37023, 198, 198, 4798, 366, 34149, 40117, 9313, 198, 198, 89, 35, 330, 17257, 796, 657, 13, 23349, 1303, 3...
2.699789
473
import snscrape.modules.twitter as sntwitter import pandas as pd # Creating list to append tweet data to tweets_list2 = [] # Using TwitterSearchScraper to scrape data and append tweets to list for i,tweet in enumerate(sntwitter.TwitterSearchScraper('covid vaccine until:2021-05-24').get_items()): if i>100000: break tweets_list2.append([tweet.date, tweet.id, tweet.content, tweet.user.username, tweet.user.verified, tweet.user.followersCount, tweet.user.friendsCount, tweet.likeCount, tweet.retweetCount, tweet.quoteCount, tweet.user.created, tweet.user.location, tweet.user.displayname, tweet.lang, tweet.coordinates, tweet.place]) # Creating a dataframe from the tweets list above tweets_df2 = pd.DataFrame(tweets_list2, columns=['Datetime', 'Tweet Id', 'Text', 'Username', 'Verified', 'Followers Count', 'Friends Count', 'Like Count', 'Retweet Count', 'Quote Count', 'Created','Location','Display Name', 'Language', 'Coordinates', 'Place']) tweets_df2.to_csv('First Extract.csv') # Creating list to append tweet data to tweets_list2 = [] # Using TwitterSearchScraper to scrape data and append tweets to list for i,tweet in enumerate(sntwitter.TwitterSearchScraper('covid vaccine until:2021-05-13').get_items()): if i>100000: break tweets_list2.append([tweet.date, tweet.id, tweet.content, tweet.user.username, tweet.user.verified, tweet.user.followersCount, tweet.user.friendsCount, tweet.likeCount, tweet.retweetCount, tweet.quoteCount, tweet.user.created, tweet.user.location, tweet.user.displayname, tweet.lang, tweet.coordinates, tweet.place]) # Creating a dataframe from the tweets list above tweets_df3 = pd.DataFrame(tweets_list2, columns=['Datetime', 'Tweet Id', 'Text', 'Username', 'Verified', 'Followers Count', 'Friends Count', 'Like Count', 'Retweet Count', 'Quote Count', 'Created','Location','Display Name', 'Language', 'Coordinates', 'Place']) tweets_df3.to_csv('Second Extract.csv')
[ 11748, 3013, 1416, 13484, 13, 18170, 13, 6956, 355, 264, 429, 86, 1967, 198, 11748, 19798, 292, 355, 279, 67, 198, 2, 30481, 1351, 284, 24443, 6126, 1366, 284, 198, 83, 732, 1039, 62, 4868, 17, 796, 17635, 198, 198, 2, 8554, 3009, ...
3.061321
636
from .repository import Repository from .manager import Manager __all__ = ["Manager", "Repository", "__version__"] __version__ = "0.2.0"
[ 6738, 764, 260, 1930, 37765, 1330, 1432, 13264, 198, 6738, 764, 37153, 1330, 9142, 198, 198, 834, 439, 834, 796, 14631, 13511, 1600, 366, 6207, 13264, 1600, 366, 834, 9641, 834, 8973, 198, 834, 9641, 834, 796, 366, 15, 13, 17, 13, 1...
3.066667
45
''' ==================================================================== Copyright (c) 2016-2017 Barry A Scott. All rights reserved. This software is licensed as described in the file LICENSE.txt, which you should have received as part of this distribution. ==================================================================== wb_git_project.py ''' import sys import os import pathlib import wb_annotate_node import wb_platform_specific import wb_git_callback_server import git import git.exc import git.index GitCommandError = git.exc.GitCommandError __callback_server = None git_extra_environ = {}
[ 7061, 6, 198, 38093, 18604, 198, 15069, 357, 66, 8, 1584, 12, 5539, 14488, 317, 4746, 13, 220, 1439, 2489, 10395, 13, 628, 770, 3788, 318, 11971, 355, 3417, 287, 262, 2393, 38559, 24290, 13, 14116, 11, 198, 543, 345, 815, 423, 2722,...
4.025974
154
XPAHS_CONSULT = { 'jobs_urls': '//div[contains(@class, "listResults")]//div[contains(@data-jobid, "")]//h2//a/@href', 'results': '//span[@class="description fc-light fs-body1"]//text()', 'pagination_indicator': '//a[contains(@class, "s-pagination--item")][last()]//span[contains(text(), "next")]', 'pagination_url': '//a[contains(@class, "s-pagination--item")][last()]/@href', } START_URL = 'https://stackoverflow.com/jobs/'
[ 198, 55, 4537, 7998, 62, 10943, 50, 16724, 796, 1391, 198, 220, 220, 220, 705, 43863, 62, 6371, 82, 10354, 705, 1003, 7146, 58, 3642, 1299, 7, 31, 4871, 11, 366, 4868, 25468, 4943, 60, 1003, 7146, 58, 3642, 1299, 7, 31, 7890, 12, ...
2.271795
195
import logging import os import random import time import datetime import sys import math from screen import Screen from scorer import Scorer from trigger import Trigger from psychopy import core, event, sound from psychopy.hardware import keyboard from pupil_labs import PupilCore from datalog import Datalog from config.configSample import CONF ######################################################################### ###################################### # Initialize screen, logger and inputs logging.basicConfig( level=CONF["loggingLevel"], format='%(asctime)s-%(levelname)s-%(message)s', ) # This is a log for debugging the script, and prints messages to the terminal # needs to be first, so that if it doesn't succeed, it doesn't freeze everything eyetracker = PupilCore(ip=CONF["pupillometry"] ["ip"], port=CONF["pupillometry"]["port"], shouldRecord=CONF["recordEyetracking"]) trigger = Trigger(CONF["trigger"]["serial_device"], CONF["sendTriggers"], CONF["trigger"]["labels"]) screen = Screen(CONF) datalog = Datalog(OUTPUT_FOLDER=os.path.join( 'output', CONF["participant"] + "_" + CONF["session"], datetime.datetime.now().strftime("%Y-%m-%d")), CONF=CONF) # This is for saving data kb = keyboard.Keyboard() mainClock = core.MonotonicClock() # starts clock for timestamping events alarm = sound.Sound(os.path.join('sounds', CONF["instructions"]["alarm"]), stereo=True) questionnaireReminder = sound.Sound(os.path.join( 'sounds', CONF["instructions"]["questionnaireReminder"]), stereo=True) scorer = Scorer() logging.info('Initialization completed') ######################################################################### def quitExperimentIf(shouldQuit): "Quit experiment if condition is met" if shouldQuit: trigger.send("Quit") scorer.getScore() logging.info('quit experiment') eyetracker.stop_recording() trigger.reset() sys.exit(2) def onFlip(stimName, logName): "send trigger on flip, set keyboard clock, and save timepoint" trigger.send(stimName) kb.clock.reset() # this starts the keyboard clock as soon as stimulus appears datalog[logName] = mainClock.getTime() ############## # Introduction ############## # Display overview of session screen.show_overview() core.wait(CONF["timing"]["overview"]) # Optionally, display instructions if CONF["showInstructions"]: screen.show_instructions() key = event.waitKeys() quitExperimentIf(key[0] == 'q') eyetracker.start_recording(os.path.join( CONF["participant"], CONF["session"], CONF["task"]["name"])) # Blank screen for initial rest screen.show_blank() logging.info('Starting blank period') trigger.send("StartBlank") core.wait(CONF["timing"]["rest"]) trigger.send("EndBlank") # Cue start of the experiment screen.show_cue("START") trigger.send("Start") core.wait(CONF["timing"]["cue"]) ################# # Main experiment ################# # customize datalog["trialID"] = trigger.sendTriggerId() eyetracker.send_trigger("Stim", {"id": 1, "condition": "sample"}) datalog["pupilSize"] = eyetracker.getPupildiameter() # save data to file datalog.flush() ########### # Concluion ########### # End main experiment screen.show_cue("DONE!") trigger.send("End") core.wait(CONF["timing"]["cue"]) # Blank screen for final rest screen.show_blank() logging.info('Starting blank period') trigger.send("StartBlank") core.wait(CONF["timing"]["rest"]) trigger.send("EndBlank") logging.info('Finished') scorer.getScore() trigger.reset() eyetracker.stop_recording() questionnaireReminder.play() core.wait(2)
[ 11748, 18931, 198, 11748, 28686, 198, 11748, 4738, 198, 11748, 640, 198, 11748, 4818, 8079, 198, 11748, 25064, 198, 11748, 10688, 198, 198, 6738, 3159, 1330, 15216, 198, 6738, 30664, 1330, 1446, 11934, 198, 6738, 7616, 1330, 24593, 198, 6...
2.908228
1,264
# DO NOT EDIT! This file is automatically generated import typing from commercetools.helpers import RemoveEmptyValuesMixin from commercetools.platform.models.inventory import ( InventoryEntry, InventoryEntryDraft, InventoryEntryUpdate, InventoryEntryUpdateAction, InventoryPagedQueryResponse, ) from commercetools.typing import OptionalListStr from . import abstract, traits
[ 2, 8410, 5626, 48483, 0, 770, 2393, 318, 6338, 7560, 198, 11748, 19720, 198, 198, 6738, 4412, 66, 316, 10141, 13, 16794, 364, 1330, 17220, 40613, 40161, 35608, 259, 198, 6738, 4412, 66, 316, 10141, 13, 24254, 13, 27530, 13, 24807, 133...
3.612613
111
from __future__ import print_function # so print doesn't show brackets import copy import numpy as np import time as time import matplotlib.pyplot as plt import pickle import redis import qmla.model_for_learning import qmla.redis_settings import qmla.logging pickle.HIGHEST_PROTOCOL = 4 plt.switch_backend("agg") __all__ = ["remote_learn_model_parameters"] def remote_learn_model_parameters( name, model_id, branch_id, exploration_rule, qmla_core_info_dict=None, remote=False, host_name="localhost", port_number=6379, qid=0, log_file="rq_output.log", ): """ Standalone function to perform Quantum Hamiltonian Learning on individual models. Used in conjunction with redis databases so this calculation can be performed without any knowledge of the QMLA instance. Given model ids and names are used to instantiate the ModelInstanceForLearning class, which is then used for learning the models parameters. QMLA info is unpickled from a redis databse, containing true operator, params etc. Once parameters are learned, we pickle the results to dictionaries held on a redis database which can be accessed by other actors. :param str name: model name string :param int model_id: unique model id :param int branch_id: QMLA branch where the model was generated :param str exploration_rule: string corresponding to a unique exploration strategy, used by get_exploration_class to generate a ExplorationStrategy (or subclass) instance. :param dict qmla_core_info_dict: crucial data for QMLA, such as number of experiments/particles etc. Default None: core info is stored on the redis database so can be retrieved there on a server; if running locally, can be passed to save pickling. :param bool remote: whether QMLA is running remotely via RQ workers. :param str host_name: name of host server on which redis database exists. :param int port_number: this QMLA instance's unique port number, on which redis database exists. :param int qid: QMLA id, unique to a single instance within a run. Used to identify the redis database corresponding to this instance. :param str log_file: Path of the log file. """ log_print(["Starting QHL for Model {} on branch {}".format(model_id, branch_id)]) time_start = time.time() num_redis_retries = 5 # Access databases redis_databases = qmla.redis_settings.get_redis_databases_by_qmla_id( host_name, port_number, qid ) qmla_core_info_database = redis_databases["qmla_core_info_database"] learned_models_info_db = redis_databases["learned_models_info_db"] learned_models_ids = redis_databases["learned_models_ids"] active_branches_learning_models = redis_databases["active_branches_learning_models"] any_job_failed_db = redis_databases["any_job_failed"] if qmla_core_info_dict is not None: # for local runs, qmla_core_info_dict passed, with probe_dict included # in it. probe_dict = qmla_core_info_dict["probe_dict"] else: qmla_core_info_dict = pickle.loads(qmla_core_info_database["qmla_settings"]) probe_dict = pickle.loads(qmla_core_info_database["probes_system"]) true_model_terms_matrices = qmla_core_info_dict["true_oplist"] qhl_plots = qmla_core_info_dict["qhl_plots"] plots_directory = qmla_core_info_dict["plots_directory"] long_id = qmla_core_info_dict["long_id"] # Generate model instance qml_instance = qmla.model_for_learning.ModelInstanceForLearning( model_id=model_id, model_name=name, qid=qid, log_file=log_file, exploration_rule=exploration_rule, host_name=host_name, port_number=port_number, ) try: # Learn parameters update_timer_start = time.time() qml_instance.update_model() log_print( ["Time for update alone: {}".format(time.time() - update_timer_start)] ) # Evaluate learned parameterisation # qml_instance.compute_likelihood_after_parameter_learning() except NameError: log_print( [ "Model learning failed. QHL failed for model id {}. Setting job failure model_building_utilities.".format( model_id ) ] ) any_job_failed_db.set("Status", 1) raise except BaseException: log_print( [ "Model learning failed. QHL failed for model id {}. Setting job failure model_building_utilities.".format( model_id ) ] ) any_job_failed_db.set("Status", 1) raise if qhl_plots: log_print(["Drawing plots for QHL"]) try: if len(true_model_terms_matrices) == 1: # TODO buggy qml_instance.plot_distribution_progression( save_to_file=str( plots_directory + "qhl_distribution_progression_" + str(long_id) + ".png" ) ) qml_instance.plot_distribution_progression( renormalise=False, save_to_file=str( plots_directory + "qhl_distribution_progression_uniform_" + str(long_id) + ".png" ), ) except BaseException: pass # Throw away model instance; only need to store results. updated_model_info = copy.deepcopy(qml_instance.learned_info_dict()) compressed_info = pickle.dumps(updated_model_info, protocol=4) # Store the (compressed) result set on the redis database. for k in range(num_redis_retries): try: learned_models_info_db.set(str(model_id), compressed_info) log_print( [ "learned_models_info_db added to db for model {} after {} attempts".format( str(model_id), k ) ] ) break except Exception as e: if k == num_redis_retries - 1: log_print( ["Model learning failed at the storage stage. Error: {}".format(e)] ) any_job_failed_db.set("Status", 1) pass # Update databases to record that this model has finished. for k in range(num_redis_retries): try: active_branches_learning_models.incr(int(branch_id), 1) learned_models_ids.set(str(model_id), 1) log_print( [ "Updated model/branch learned on redis db {}/{}".format( model_id, branch_id ) ] ) break except Exception as e: if k == num_redis_retries - 1: log_print(["Model learning failed to update branch info. Error: ", e]) any_job_failed_db.set("Status", 1) if remote: del updated_model_info del compressed_info del qml_instance log_print( [ "Learned model; remote time:", str(np.round((time.time() - time_start), 2)), ] ) return None else: return updated_model_info
[ 6738, 11593, 37443, 834, 1330, 3601, 62, 8818, 220, 1303, 523, 3601, 1595, 470, 905, 28103, 201, 198, 201, 198, 11748, 4866, 201, 198, 11748, 299, 32152, 355, 45941, 201, 198, 11748, 640, 355, 640, 201, 198, 201, 198, 11748, 2603, 294...
2.100972
3,704
""" File: pylinex/quantity/CompiledQuantity.py Author: Keith Tauscher Date: 3 Sep 2017 Description: File containing a class representing a list of Quantities to be evaluated with the same (or overlapping) arguments. When it is called, each underlying Quantity is called. """ from ..util import int_types, sequence_types, Savable, Loadable from .Quantity import Quantity from .AttributeQuantity import AttributeQuantity from .ConstantQuantity import ConstantQuantity from .FunctionQuantity import FunctionQuantity try: # this runs with no issues in python 2 but raises error in python 3 basestring except: # this try/except allows for python 2/3 compatible string type checking basestring = str def __add__(self, other): """ Appends other to this CompiledQuantity. other: CompiledQuantity (or some other Quantity) returns: if other is another CompiledQuantity, names quantity lists of both CompiledQuantity objects are combined otherwise, other must be a Quantity object. It will be added to the quantity list of this CompiledQuantity (whose name won't change) """ if isinstance(other, CompiledQuantity): new_name = '{0!s}+{1!s}'.format(self.name, other.name) new_quantities = self.quantities + other.quantities elif isinstance(other, Quantity): new_name = self.name new_quantities = [quantity for quantity in self.quantities] new_quantities.append(other) else: raise TypeError("Only Quantity objects can be added to " +\ "compiled quantities.") return CompiledQuantity(new_name, *new_quantities) def __call__(self, *args, **kwargs): """ Finds the values of all of the Quantity objects underlying this obejct. args: list of arguments to pass on to the constituent Quantity objects kwargs: list of keyword arguments to pass on to the constituent Quantity objects returns: list containing the values of all of the Quantity objects underlying this one """ return [quantity(*args, **kwargs) for quantity in self.quantities] def __contains__(self, key): """ Checks if a quantity with the given name exists in this CompiledQuantity. key: string name of Quantity to check for returns: True if there exists at least one Quantity named key """ return any([(quantity.name == key) for quantity in self.quantities]) def fill_hdf5_group(self, group, exclude=[]): """ Fills given hdf5 file group with data about this CompiledQuantity. group: hdf5 file group to fill with data about this CompiledQuantity """ iquantity = 0 group.attrs['name'] = self.name group.attrs['class'] = 'CompiledQuantity' for quantity in self.quantities: excluded = (quantity.name in exclude) savable = isinstance(quantity, Savable) if (not excluded) and savable: subgroup = group.create_group('quantity_{}'.format(iquantity)) if isinstance(quantity, Savable): quantity.fill_hdf5_group(subgroup) else: raise TypeError("This CompiledQuantity cannot be saved " +\ "because it contains Quantity objects which cannot " +\ "be saved.") iquantity += 1
[ 37811, 198, 8979, 25, 12972, 1370, 87, 14, 40972, 414, 14, 7293, 3902, 31208, 13, 9078, 198, 13838, 25, 14926, 309, 8717, 2044, 198, 10430, 25, 513, 8621, 2177, 198, 198, 11828, 25, 9220, 7268, 257, 1398, 10200, 257, 1351, 286, 16972,...
2.348419
1,613
s = 0 cont = 0 for c in range(1, 501, 2): if c % 3 == 0: s = s + c cont = cont + 1 print('A soma de todos os {} valores solicitados {}'.format(cont, s))
[ 82, 796, 657, 201, 198, 3642, 796, 657, 201, 198, 1640, 269, 287, 2837, 7, 16, 11, 24555, 11, 362, 2599, 201, 198, 220, 220, 220, 611, 269, 4064, 513, 6624, 657, 25, 201, 198, 220, 220, 220, 220, 220, 220, 220, 264, 796, 264, ...
2.033333
90
#!/usr/bin/env python # -*- coding: utf-8 -*- # # This file is subject to the terms and conditions defined in # file 'LICENSE.md', which is part of this source code package. # import time import uuid from kubernetes.K8sCronJob import K8sCronJob from kubernetes.K8sPod import K8sPod from kubernetes.models.v2alpha1.CronJob import CronJob from kubernetes.K8sExceptions import CronJobAlreadyRunningException from tests import _constants from tests import _utils from tests.BaseTest import BaseTest
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 198, 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 198, 2, 198, 2, 770, 2393, 318, 2426, 284, 262, 2846, 290, 3403, 5447, 287, 198, 2, 2393, 705, 43, 2149, 24290, 13,...
3.024242
165
''' This file implements various optimization methods, including -- SGD with gradient norm clipping -- AdaGrad -- AdaDelta -- Adam Transparent to switch between CPU / GPU. @author: Tao Lei (taolei@csail.mit.edu) ''' import random from collections import OrderedDict import numpy as np import theano import theano.tensor as T from theano.sandbox.cuda.basic_ops import HostFromGpu from theano.sandbox.cuda.var import CudaNdarraySharedVariable from theano.printing import debugprint from .initialization import default_mrng def get_similar_subtensor(matrix, indexes, param_op): ''' So far there is only two possible subtensor operation used. ''' if isinstance(param_op.owner.op, T.AdvancedSubtensor1): return matrix[indexes] else: # indexes is start index in this case return matrix[indexes:]
[ 7061, 6, 198, 220, 220, 220, 770, 2393, 23986, 2972, 23989, 5050, 11, 1390, 198, 220, 220, 220, 220, 220, 220, 220, 1377, 26147, 35, 351, 31312, 2593, 45013, 198, 220, 220, 220, 220, 220, 220, 220, 1377, 47395, 42731, 198, 220, 220,...
2.795597
318
import sys from PyQt5.QtWidgets import QMainWindow from PyQt5.QtGui import QPixmap, QIcon from PyQt5 import uic from internationalization import LANGUAGE
[ 11748, 25064, 198, 6738, 9485, 48, 83, 20, 13, 48, 83, 54, 312, 11407, 1330, 1195, 13383, 27703, 198, 6738, 9485, 48, 83, 20, 13, 48, 83, 8205, 72, 1330, 1195, 47, 844, 8899, 11, 1195, 19578, 198, 6738, 9485, 48, 83, 20, 1330, 3...
2.781818
55
import requests
[ 11748, 7007 ]
7.5
2
import argparse import Functions_Features.functionsToDetermineMotifStrength as fdm import pandas as pd parser = argparse.ArgumentParser() parser.add_argument("-w","--tmpfolder",type=str,help="Input the upperlevel folder containing folder to Write to") parser.add_argument("-t","--foldertitle",type=str,help="Input the title of the mutation file") parser.add_argument("-m","--mutationfile",type=str,help="Input a mutation file") parser.add_argument("-q","--quantile",nargs='?',default=0.95,type=float,help="Input a quantile value to set a threshold strength score for each motif cluster, default is 0.95") args = parser.parse_args() TMPfolder=args.tmpfolder folderTitle=args.foldertitle MUTATION_FILE=args.mutationfile QUANTILE=args.quantile dict_NumCluster={"ESE":8,"ESS":7,"ISE":7,"ISS":8} strength_threshold_dict=fdm.createSREclusterThresholdDictionary(TMPfolder,dict_NumCluster,QUANTILE) with open(MUTATION_FILE) as f: #with open("../data/MAPT_MUTs_ToTest.tsv") as f: mutations=[line.strip().split("\t") for line in f] #mutsToIgnore=["Mut3","Mut10","Mut33"] to_write = [] # Go through each mutation for mut in mutations: mutID=mut[0] ESE_motifStrengths = fdm.getSumOfMotifScoreDiffsPerSRECluster(TMPfolder,folderTitle,mutID,"ESE",dict_NumCluster["ESE"],strength_threshold_dict) ESS_motifStrengths = fdm.getSumOfMotifScoreDiffsPerSRECluster(TMPfolder,folderTitle,mutID,"ESS",dict_NumCluster["ESS"],strength_threshold_dict) ISE_motifStrengths = fdm.getSumOfMotifScoreDiffsPerSRECluster(TMPfolder,folderTitle,mutID,"ISE",dict_NumCluster["ISE"],strength_threshold_dict) ISS_motifStrengths = fdm.getSumOfMotifScoreDiffsPerSRECluster(TMPfolder,folderTitle,mutID,"ISS",dict_NumCluster["ISS"],strength_threshold_dict) motifStrengths_forMut = [mutID]+ESE_motifStrengths+ESS_motifStrengths+ISE_motifStrengths+ISS_motifStrengths to_write.append(motifStrengths_forMut) with open(TMPfolder+MUTATION_FILE.split("/")[2].split(".")[0]+"_SREstrengthsDifferences_perCluster.tsv","w") as fw: #with open(TMPfolder+motifType+"_MUTsToTest_ScoreDifferences.tsv","w") as fw: fw.write("MutID") for motifType in ["ESE","ESS","ISE","ISS"]: for cluster in range(1,dict_NumCluster[motifType]+1): fw.write("\t") fw.write(motifType+"_Cluster"+str(cluster)) fw.write("\n") for i in to_write: fw.write("\t".join(i)) fw.write("\n")
[ 11748, 1822, 29572, 198, 11748, 40480, 62, 23595, 13, 12543, 2733, 2514, 35, 2357, 3810, 47733, 361, 45027, 355, 277, 36020, 198, 11748, 19798, 292, 355, 279, 67, 198, 198, 48610, 796, 1822, 29572, 13, 28100, 1713, 46677, 3419, 198, 486...
2.525
960
import os import subprocess import time
[ 11748, 28686, 198, 11748, 850, 14681, 198, 11748, 640, 628, 198 ]
3.818182
11
from django.contrib import admin from .models import Movie admin.site.register(Movie)
[ 6738, 42625, 14208, 13, 3642, 822, 1330, 13169, 198, 6738, 764, 27530, 1330, 15875, 628, 198, 28482, 13, 15654, 13, 30238, 7, 25097, 8, 198 ]
3.52
25
#!/usr/bin/env python # -*- coding: utf-8 -*- """Asian Language Treebank (ALT) Project""" from __future__ import absolute_import, division, print_function import os import datasets _CITATION = """\ @inproceedings{riza2016introduction, title={Introduction of the asian language treebank}, author={Riza, Hammam and Purwoadi, Michael and Uliniansyah, Teduh and Ti, Aw Ai and Aljunied, Sharifah Mahani and Mai, Luong Chi and Thang, Vu Tat and Thai, Nguyen Phuong and Chea, Vichet and Sam, Sethserey and others}, booktitle={2016 Conference of The Oriental Chapter of International Committee for Coordination and Standardization of Speech Databases and Assessment Techniques (O-COCOSDA)}, pages={1--6}, year={2016}, organization={IEEE} } """ _HOMEPAGE = "https://www2.nict.go.jp/astrec-att/member/mutiyama/ALT/" _DESCRIPTION = """\ The ALT project aims to advance the state-of-the-art Asian natural language processing (NLP) techniques through the open collaboration for developing and using ALT. It was first conducted by NICT and UCSY as described in Ye Kyaw Thu, Win Pa Pa, Masao Utiyama, Andrew Finch and Eiichiro Sumita (2016). Then, it was developed under ASEAN IVO as described in this Web page. The process of building ALT began with sampling about 20,000 sentences from English Wikinews, and then these sentences were translated into the other languages. ALT now has 13 languages: Bengali, English, Filipino, Hindi, Bahasa Indonesia, Japanese, Khmer, Lao, Malay, Myanmar (Burmese), Thai, Vietnamese, Chinese (Simplified Chinese). """ _URLs = { "alt": "https://www2.nict.go.jp/astrec-att/member/mutiyama/ALT/ALT-Parallel-Corpus-20191206.zip", "alt-en": "https://www2.nict.go.jp/astrec-att/member/mutiyama/ALT/English-ALT-20170107.zip", "alt-jp": "https://www2.nict.go.jp/astrec-att/member/mutiyama/ALT/Japanese-ALT-20170330.zip", "alt-my": "https://www2.nict.go.jp/astrec-att/member/mutiyama/ALT/my-alt-190530.zip", "alt-my-transliteration": "https://www2.nict.go.jp/astrec-att/member/mutiyama/ALT/my-en-transliteration.zip", "alt-my-west-transliteration": "https://www2.nict.go.jp/astrec-att/member/mutiyama/ALT/western-myanmar-transliteration.zip", "alt-km": "https://www2.nict.go.jp/astrec-att/member/mutiyama/ALT/km-nova-181101.zip", } _SPLIT = { "train": "https://www2.nict.go.jp/astrec-att/member/mutiyama/ALT/URL-train.txt", "dev": "https://www2.nict.go.jp/astrec-att/member/mutiyama/ALT/URL-dev.txt", "test": "https://www2.nict.go.jp/astrec-att/member/mutiyama/ALT/URL-test.txt", } _WIKI_URL = "https://www2.nict.go.jp/astrec-att/member/mutiyama/ALT/ALT-Parallel-Corpus-20191206/URL.txt"
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 198, 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 37811, 43224, 15417, 12200, 17796, 357, 31429, 8, 4935, 37811, 198, 198, 6738, 11593, 37443, 834, 1330, 4112, 62, 11748, ...
2.778706
958
from setuptools import setup, find_packages setup( name='awis-py', version='0.0.2', url='https://github.com/whistlebee/awis-py', packages=find_packages(), install_requires=['requests', 'lxml'], python_requires='>=3.6' )
[ 6738, 900, 37623, 10141, 1330, 9058, 11, 1064, 62, 43789, 628, 198, 40406, 7, 198, 220, 220, 220, 1438, 11639, 707, 271, 12, 9078, 3256, 198, 220, 220, 220, 2196, 11639, 15, 13, 15, 13, 17, 3256, 198, 220, 220, 220, 19016, 11639, ...
2.411765
102
import sys from pathlib import Path import numpy as np import pandas as pd from bokeh.models import ColumnDataSource from bokeh.io import export_png from bokeh.plotting import figure def gini_coefficient(x): """Compute Gini coefficient of array of values""" diffsum = 0 for i, xi in enumerate(x[:-1], 1): diffsum += np.sum(np.abs(xi - x[i:])) return diffsum / (len(x)**2 * np.mean(x))
[ 11748, 25064, 198, 6738, 3108, 8019, 1330, 10644, 198, 11748, 299, 32152, 355, 45941, 198, 11748, 19798, 292, 355, 279, 67, 198, 198, 6738, 1489, 365, 71, 13, 27530, 1330, 29201, 6601, 7416, 198, 6738, 1489, 365, 71, 13, 952, 1330, 10...
2.508876
169
from multiprocessing import Process server = Process(target=app.run)# ... server.terminate()
[ 6738, 18540, 305, 919, 278, 1330, 10854, 201, 198, 201, 198, 15388, 796, 10854, 7, 16793, 28, 1324, 13, 5143, 8, 2, 2644, 201, 198, 15388, 13, 23705, 378, 3419, 201, 198 ]
3.0625
32
from OpenGL.arrays import vbo from OpenGL.GLES2.VERSION import GLES2_2_0 from OpenGL.GLES2.OES import mapbuffer Implementation.register()
[ 6738, 30672, 13, 3258, 592, 1330, 410, 2127, 198, 6738, 30672, 13, 8763, 1546, 17, 13, 43717, 1330, 10188, 1546, 17, 62, 17, 62, 15, 198, 6738, 30672, 13, 8763, 1546, 17, 13, 46, 1546, 1330, 3975, 22252, 198, 3546, 32851, 13, 30238,...
3.066667
45
import unittest import numpy as np import openjij as oj import cxxjij as cj if __name__ == '__main__': unittest.main()
[ 11748, 555, 715, 395, 198, 198, 11748, 299, 32152, 355, 45941, 198, 11748, 1280, 73, 2926, 355, 267, 73, 198, 11748, 269, 5324, 73, 2926, 355, 269, 73, 628, 628, 628, 198, 361, 11593, 3672, 834, 6624, 705, 834, 12417, 834, 10354, 19...
2.45283
53
#!/usr/bin/env python # coding=utf-8 import grpc from datetime import datetime import sys import logging import socket import os from ipaddress import ip_network, ip_address, IPv4Address import json import signal import traceback import re from concurrent.futures import ThreadPoolExecutor import sdk_service_pb2 import sdk_service_pb2_grpc import config_service_pb2 # To report state back import telemetry_service_pb2 import telemetry_service_pb2_grpc from pygnmi.client import gNMIclient, telemetryParser from logging.handlers import RotatingFileHandler ############################################################ ## Agent will start with this name ############################################################ agent_name='bgp_acl_agent' acl_sequence_start=1000 # Default ACL sequence number base, can be configured acl_count=0 # Number of ACL entries created/managed ############################################################ ## Open a GRPC channel to connect to sdk_mgr on the dut ## sdk_mgr will be listening on 50053 ############################################################ channel = grpc.insecure_channel('unix:///opt/srlinux/var/run/sr_sdk_service_manager:50053') # channel = grpc.insecure_channel('127.0.0.1:50053') metadata = [('agent_name', agent_name)] stub = sdk_service_pb2_grpc.SdkMgrServiceStub(channel) ############################################################ ## Subscribe to required event ## This proc handles subscription of: Interface, LLDP, ## Route, Network Instance, Config ############################################################ ############################################################ ## Subscribe to all the events that Agent needs ############################################################ def Subscribe_Notifications(stream_id): ''' Agent will receive notifications to what is subscribed here. ''' if not stream_id: logging.info("Stream ID not sent.") return False # Subscribe to config changes, first Subscribe(stream_id, 'cfg') ################################################################## ## Proc to process the config Notifications received by auto_config_agent ## At present processing config from js_path = .fib-agent ################################################################## # # Checks if this is an IPv4 or IPv6 address, and normalizes host prefixes # # # Because it is possible that ACL entries get saved to 'startup', the agent may # not have a full map of sequence number to peer_ip. Therefore, we perform a # lookup based on IP address each time # Since 'prefix' is not a key, we have to loop through all entries with a prefix # ################################################################################################## ## This is the main proc where all processing for auto_config_agent starts. ## Agent registration, notification registration, Subscrition to notifications. ## Waits on the subscribed Notifications and once any config is received, handles that config ## If there are critical errors, Unregisters the fib_agent gracefully. ################################################################################################## ############################################################ ## Gracefully handle SIGTERM signal ## When called, will unregister Agent and gracefully exit ############################################################ ################################################################################################## ## Main from where the Agent starts ## Log file is written to: /var/log/srlinux/stdout/bgp_acl_agent.log ## Signals handled for graceful exit: SIGTERM ################################################################################################## if __name__ == '__main__': # hostname = socket.gethostname() stdout_dir = '/var/log/srlinux/stdout' # PyTEnv.SRL_STDOUT_DIR signal.signal(signal.SIGTERM, Exit_Gracefully) if not os.path.exists(stdout_dir): os.makedirs(stdout_dir, exist_ok=True) log_filename = f'{stdout_dir}/{agent_name}.log' logging.basicConfig( handlers=[RotatingFileHandler(log_filename, maxBytes=3000000,backupCount=5)], format='%(asctime)s,%(msecs)03d %(name)s %(levelname)s %(message)s', datefmt='%H:%M:%S', level=logging.INFO) logging.info("START TIME :: {}".format(datetime.now())) if Run(): logging.info('Agent unregistered') else: logging.info('Should not happen')
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 198, 2, 19617, 28, 40477, 12, 23, 198, 198, 11748, 1036, 14751, 198, 6738, 4818, 8079, 1330, 4818, 8079, 198, 11748, 25064, 198, 11748, 18931, 198, 11748, 17802, 198, 11748, 28686, 198, 6738,...
3.772651
1,192
from __future__ import absolute_import, division, print_function, unicode_literals import os.path import pytest xr = pytest.importorskip('xarray') # noqa from cfgrib import cfgrib_ SAMPLE_DATA_FOLDER = os.path.join(os.path.dirname(__file__), 'sample-data') TEST_DATA = os.path.join(SAMPLE_DATA_FOLDER, 'era5-levels-members.grib')
[ 198, 6738, 11593, 37443, 834, 1330, 4112, 62, 11748, 11, 7297, 11, 3601, 62, 8818, 11, 28000, 1098, 62, 17201, 874, 198, 198, 11748, 28686, 13, 6978, 198, 198, 11748, 12972, 9288, 198, 87, 81, 796, 12972, 9288, 13, 11748, 669, 74, 5...
2.627907
129
#! /usr/bin/env python3 # Copyright(c) 2017 Intel Corporation. # License: MIT See LICENSE file in root directory. # NPS # pulls images from camera device and places them in a Queue # if the queue is full will start to skip camera frames. #import numpy as np import cv2 import queue import threading import time
[ 2, 0, 1220, 14629, 14, 8800, 14, 24330, 21015, 18, 198, 198, 2, 15069, 7, 66, 8, 2177, 8180, 10501, 13, 198, 2, 13789, 25, 17168, 4091, 38559, 24290, 2393, 287, 6808, 8619, 13, 198, 2, 399, 3705, 198, 198, 2, 16194, 4263, 422, 4...
3.450549
91
import ipfinder con = ipfinder.config('f67f788f8a02a188ec84502e0dff066ed4413a85') # YOUR_TOKEN_GOES_HERE # domain name by = 'DZ'; dby = con.getDomainBy(by) print(dby.all)
[ 11748, 20966, 22805, 198, 198, 1102, 796, 20966, 22805, 13, 11250, 10786, 69, 3134, 69, 22, 3459, 69, 23, 64, 2999, 64, 20356, 721, 5705, 35126, 68, 15, 67, 487, 15, 2791, 276, 2598, 1485, 64, 5332, 11537, 1303, 16592, 62, 10468, 43...
2.083333
84
""" Author: bkc@data_analysis Project: autoencoder_ng Created: 7/29/20 10:51 Purpose: START SCRIPT FOR AUTOENCODER_NG PROJECT """
[ 37811, 198, 220, 6434, 25, 220, 275, 74, 66, 31, 7890, 62, 20930, 198, 220, 4935, 25, 1960, 6571, 66, 12342, 62, 782, 198, 220, 15622, 25, 767, 14, 1959, 14, 1238, 838, 25, 4349, 198, 220, 32039, 25, 33303, 6374, 46023, 7473, 4704...
2.527273
55
from .list import SalesPaymentListSchema # noqa
[ 6738, 764, 4868, 1330, 17329, 19197, 434, 8053, 27054, 2611, 220, 1303, 645, 20402, 198 ]
3.266667
15
import numpy as np from matplotlib import pyplot as plt from sympy import symbols, solve a, b, c, d, x, , = symbols("a b c d x ") # polynomial function f(x) = ax + bx + cx + d f = a * x ** 3 + b * x ** 2 + c * x + d fp = f.diff(x) # derivative f'(x) # evaluate both at x=0 and x=1 f0, f1 = [f.subs(x, i) for i in range(2)] fp0, fp1 = [fp.subs(x, i) for i in range(2)] # we want a, b, c, d such that the following conditions hold: # # f(0) = 0 # f(1) = 0 # f'(0) = # f'(1) = S = solve([f0, f1, fp0 - , fp1 - ], [a, b, c, d]) # print the analytic solution and plot a graphical example coeffs = [] num_ = 0.3 num_ = -0.03 for key in [a, b, c, d]: print(key, "=", S[key]) coeffs.append(S[key].subs(dict(=num_, =num_))) xvals = np.linspace(0, 1, 101) yvals = np.polyval(coeffs, xvals) plt.plot(xvals, yvals) plt.show()
[ 11748, 299, 32152, 355, 45941, 198, 6738, 2603, 29487, 8019, 1330, 12972, 29487, 355, 458, 83, 198, 6738, 10558, 88, 1330, 14354, 11, 8494, 198, 198, 64, 11, 275, 11, 269, 11, 288, 11, 2124, 11, 837, 220, 796, 14354, 7203, 64, 275, ...
2.099751
401
#!/usr/bin/python2.5 # # Copyright 2009 Google Inc. # # Licensed under the Apache License, Version 2.0 (the 'License') # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an 'AS IS' BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Test admin_rankers.""" __author__ = 'slamm@google.com (Stephen Lamm)' import datetime import logging import unittest import mock_data import settings from django.test.client import Client from django.utils import simplejson from google.appengine.api import memcache from google.appengine.ext import db from categories import all_test_sets from models import result_stats from models.result import ResultParent from models.result import ResultTime from models.user_agent import UserAgent from third_party import mox from base import admin USER_AGENT_STRINGS = { 'Firefox 3.0.6': ('Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.6) ' 'Gecko/2009011912 Firefox/3.0.6'), 'Firefox 3.5': ('Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.6) ' 'Gecko/2009011912 Firefox/3.5'), 'Firefox 3.0.9': ('Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.6) ' 'Gecko/2009011912 Firefox/3.0.9'), }
[ 2, 48443, 14629, 14, 8800, 14, 29412, 17, 13, 20, 198, 2, 198, 2, 15069, 3717, 3012, 3457, 13, 198, 2, 198, 2, 49962, 739, 262, 24843, 13789, 11, 10628, 362, 13, 15, 357, 1169, 705, 34156, 11537, 198, 2, 345, 743, 407, 779, 428,...
2.733102
577
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. import logging from dataclasses import dataclass from typing import Dict, List import torch import torch.nn as nn from ml.rl import types as rlt from ml.rl.models.base import ModelBase logger = logging.getLogger(__name__) HISTORY_LENGTH = 5 class ExampleSequenceModel(ModelBase):
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 18, 198, 2, 15069, 357, 66, 8, 3203, 11, 3457, 13, 290, 663, 29116, 13, 1439, 2489, 10395, 13, 198, 198, 11748, 18931, 198, 6738, 4818, 330, 28958, 1330, 4818, 330, 31172, 198, 6738, 1972...
3.225
120
import pygame import math #Dibuja triangulo y lo escala con el teclado ANCHO=600 ALTO=480 def dibujarTriangulo(a, b, c, plano): ''' pygame.draw.line(plano, [0, 255, 0], [a[0], a[1]], [b[0], b[1]] ) pygame.draw.line(plano, [0, 255, 0], [b[0], b[1]], [c[0], c[1]] ) pygame.draw.line(plano, [0, 255, 0], [c[0], c[1]], [a[0], a[1]] ) ''' pygame.draw.polygon(plano, [0, 255, 0], [a,b,c]) pygame.display.flip() return a, b, c if __name__ == '__main__': pygame.init() pantalla=pygame.display.set_mode([ANCHO, ALTO]) #Crea la ventana o=[ANCHO/2, ALTO/2] dibujarPlano(o, pantalla) pygame.display.flip() print 'Funciona' cont=0 lista=[] fin=False while not fin: for event in pygame.event.get(): if event.type == pygame.QUIT: fin=True if event.type == pygame.MOUSEBUTTONDOWN: cont+=1 lista.append(mostrarPos()) if event.type == pygame.KEYDOWN: if event.key==pygame.K_RIGHT: pantalla.fill([0, 0, 0]) dibujarPlano(o, pantalla) pygame.display.flip() puntos=lista puntos[0]=calcularPosPlano(o, puntos[0]) puntos[1]=calcularPosPlano(o, puntos[1]) puntos[2]=calcularPosPlano(o, puntos[2]) ''' print 'Puntos iniciales:' print puntos ''' puntos[0]=rotacionHoraria(puntos[0]) puntos[1]=rotacionHoraria(puntos[1]) puntos[2]=rotacionHoraria(puntos[2]) puntos[0]=calcularPosPantalla(o, puntos[0]) puntos[1]=calcularPosPantalla(o, puntos[1]) puntos[2]=calcularPosPantalla(o, puntos[2]) '''' print 'Puntos finales:' print puntos ''' dibujarTriangulo(puntos[0], puntos[1], puntos[2], pantalla) if event.key==pygame.K_LEFT: pantalla.fill([0, 0, 0]) dibujarPlano(o, pantalla) pygame.display.flip() puntos=lista puntos[0]=calcularPosPlano(o, puntos[0]) puntos[1]=calcularPosPlano(o, puntos[1]) puntos[2]=calcularPosPlano(o, puntos[2]) ''' print 'Puntos iniciales:' print puntos ''' puntos[0]=rotacionAntiHoraria(puntos[0]) puntos[1]=rotacionAntiHoraria(puntos[1]) puntos[2]=rotacionAntiHoraria(puntos[2]) puntos[0]=calcularPosPantalla(o, puntos[0]) puntos[1]=calcularPosPantalla(o, puntos[1]) puntos[2]=calcularPosPantalla(o, puntos[2]) ''' print 'Puntos finales:' print puntos ''' dibujarTriangulo(puntos[0], puntos[1], puntos[2], pantalla) if cont==3: dibujarTriangulo(lista[0], lista[1], lista[2], pantalla) cont=0 #lista=[]
[ 11748, 12972, 6057, 198, 11748, 10688, 198, 2, 35, 33828, 6592, 1333, 648, 43348, 331, 2376, 3671, 6081, 369, 1288, 573, 565, 4533, 198, 1565, 44899, 28, 8054, 198, 1847, 10468, 28, 22148, 198, 198, 4299, 288, 33828, 9491, 14824, 648, ...
1.61769
2,069
from __future__ import print_function import os, sys import pickle import time import glob import numpy as np import torch from model import PVSE from loss import cosine_sim, order_sim from vocab import Vocabulary from data import get_test_loader from logger import AverageMeter from option import parser, verify_input_args ORDER_BATCH_SIZE = 100 def encode_data(model, data_loader, use_gpu=False): """Encode all images and sentences loadable by data_loader""" # switch to evaluate mode model.eval() use_mil = model.module.mil if hasattr(model, 'module') else model.mil # numpy array to keep all the embeddings img_embs, txt_embs = None, None for i, data in enumerate(data_loader): img, txt, txt_len, ids = data if torch.cuda.is_available(): img, txt, txt_len = img.cuda(), txt.cuda(), txt_len.cuda() # compute the embeddings img_emb, txt_emb, _, _, _, _ = model.forward(img, txt, txt_len) del img, txt, txt_len # initialize the output embeddings if img_embs is None: if use_gpu: emb_sz = [len(data_loader.dataset), img_emb.size(1), img_emb.size(2)] \ if use_mil else [len(data_loader.dataset), img_emb.size(1)] img_embs = torch.zeros(emb_sz, dtype=img_emb.dtype, requires_grad=False).cuda() txt_embs = torch.zeros(emb_sz, dtype=txt_emb.dtype, requires_grad=False).cuda() else: emb_sz = (len(data_loader.dataset), img_emb.size(1), img_emb.size(2)) \ if use_mil else (len(data_loader.dataset), img_emb.size(1)) img_embs = np.zeros(emb_sz) txt_embs = np.zeros(emb_sz) # preserve the embeddings by copying from gpu and converting to numpy img_embs[ids] = img_emb if use_gpu else img_emb.data.cpu().numpy().copy() txt_embs[ids] = txt_emb if use_gpu else txt_emb.data.cpu().numpy().copy() return img_embs, txt_embs def i2t(images, sentences, nreps=1, npts=None, return_ranks=False, order=False, use_gpu=False): """ Images->Text (Image Annotation) Images: (nreps*N, K) matrix of images Captions: (nreps*N, K) matrix of sentences """ if use_gpu: assert not order, 'Order embedding not supported in GPU mode' if npts is None: npts = int(images.shape[0] / nreps) index_list = [] ranks, top1 = np.zeros(npts), np.zeros(npts) for index in range(npts): # Get query image im = images[nreps * index] im = im.reshape((1,) + im.shape) # Compute scores if use_gpu: if len(sentences.shape) == 2: sim = im.mm(sentences.t()).view(-1) else: _, K, D = im.shape sim_kk = im.view(-1, D).mm(sentences.view(-1, D).t()) sim_kk = sim_kk.view(im.size(0), K, sentences.size(0), K) sim_kk = sim_kk.permute(0,1,3,2).contiguous() sim_kk = sim_kk.view(im.size(0), -1, sentences.size(0)) sim, _ = sim_kk.max(dim=1) sim = sim.flatten() else: if order: if index % ORDER_BATCH_SIZE == 0: mx = min(images.shape[0], nreps * (index + ORDER_BATCH_SIZE)) im2 = images[nreps * index:mx:nreps] sim_batch = order_sim(torch.Tensor(im2).cuda(), torch.Tensor(sentences).cuda()) sim_batch = sim_batch.cpu().numpy() sim = sim_batch[index % ORDER_BATCH_SIZE] else: sim = np.tensordot(im, sentences, axes=[2, 2]).max(axis=(0,1,3)).flatten() \ if len(sentences.shape) == 3 else np.dot(im, sentences.T).flatten() if use_gpu: _, inds_gpu = sim.sort() inds = inds_gpu.cpu().numpy().copy()[::-1] else: inds = np.argsort(sim)[::-1] index_list.append(inds[0]) # Score rank = 1e20 for i in range(nreps * index, nreps * (index + 1), 1): tmp = np.where(inds == i)[0][0] if tmp < rank: rank = tmp ranks[index] = rank top1[index] = inds[0] # Compute metrics r1 = 100.0 * len(np.where(ranks < 1)[0]) / len(ranks) r5 = 100.0 * len(np.where(ranks < 5)[0]) / len(ranks) r10 = 100.0 * len(np.where(ranks < 10)[0]) / len(ranks) medr = np.floor(np.median(ranks)) + 1 meanr = ranks.mean() + 1 if return_ranks: return (r1, r5, r10, medr, meanr), (ranks, top1) else: return (r1, r5, r10, medr, meanr) def t2i(images, sentences, nreps=1, npts=None, return_ranks=False, order=False, use_gpu=False): """ Text->Images (Image Search) Images: (nreps*N, K) matrix of images Captions: (nreps*N, K) matrix of sentences """ if use_gpu: assert not order, 'Order embedding not supported in GPU mode' if npts is None: npts = int(images.shape[0] / nreps) if use_gpu: ims = torch.stack([images[i] for i in range(0, len(images), nreps)]) else: ims = np.array([images[i] for i in range(0, len(images), nreps)]) ranks, top1 = np.zeros(nreps * npts), np.zeros(nreps * npts) for index in range(npts): # Get query sentences queries = sentences[nreps * index:nreps * (index + 1)] # Compute scores if use_gpu: if len(sentences.shape) == 2: sim = queries.mm(ims.t()) else: sim_kk = queries.view(-1, queries.size(-1)).mm(ims.view(-1, ims.size(-1)).t()) sim_kk = sim_kk.view(queries.size(0), queries.size(1), ims.size(0), ims.size(1)) sim_kk = sim_kk.permute(0,1,3,2).contiguous() sim_kk = sim_kk.view(queries.size(0), -1, ims.size(0)) sim, _ = sim_kk.max(dim=1) else: if order: if nreps * index % ORDER_BATCH_SIZE == 0: mx = min(sentences.shape[0], nreps * index + ORDER_BATCH_SIZE) sentences_batch = sentences[nreps * index:mx] sim_batch = order_sim(torch.Tensor(images).cuda(), torch.Tensor(sentences_batch).cuda()) sim_batch = sim_batch.cpu().numpy() sim = sim_batch[:, (nreps * index) % ORDER_BATCH_SIZE:(nreps * index) % ORDER_BATCH_SIZE + nreps].T else: sim = np.tensordot(queries, ims, axes=[2, 2]).max(axis=(1,3)) \ if len(sentences.shape) == 3 else np.dot(queries, ims.T) inds = np.zeros(sim.shape) for i in range(len(inds)): if use_gpu: _, inds_gpu = sim[i].sort() inds[i] = inds_gpu.cpu().numpy().copy()[::-1] else: inds[i] = np.argsort(sim[i])[::-1] ranks[nreps * index + i] = np.where(inds[i] == index)[0][0] top1[nreps * index + i] = inds[i][0] # Compute metrics r1 = 100.0 * len(np.where(ranks < 1)[0]) / len(ranks) r5 = 100.0 * len(np.where(ranks < 5)[0]) / len(ranks) r10 = 100.0 * len(np.where(ranks < 10)[0]) / len(ranks) medr = np.floor(np.median(ranks)) + 1 meanr = ranks.mean() + 1 if return_ranks: return (r1, r5, r10, medr, meanr), (ranks, top1) else: return (r1, r5, r10, medr, meanr) if __name__ == '__main__': multi_gpu = torch.cuda.device_count() > 1 args = verify_input_args(parser.parse_args()) opt = verify_input_args(parser.parse_args()) # load vocabulary used by the model with open('./vocab/%s_vocab.pkl' % args.data_name, 'rb') as f: vocab = pickle.load(f) args.vocab_size = len(vocab) # load model and options assert os.path.isfile(args.ckpt) model = PVSE(vocab.word2idx, args) if torch.cuda.is_available(): model = torch.nn.DataParallel(model).cuda() if multi_gpu else model torch.backends.cudnn.benchmark = True model.load_state_dict(torch.load(args.ckpt)) # evaluate metrics = evalrank(model, args, split='test')
[ 6738, 11593, 37443, 834, 1330, 3601, 62, 8818, 198, 11748, 28686, 11, 25064, 198, 11748, 2298, 293, 198, 11748, 640, 198, 11748, 15095, 198, 198, 11748, 299, 32152, 355, 45941, 198, 11748, 28034, 198, 198, 6738, 2746, 1330, 31392, 5188, ...
2.185841
3,390
# Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from __future__ import absolute_import from __future__ import division from __future__ import print_function import paddle import paddle.nn as nn import paddle.nn.functional as F from paddlex.ppdet.core.workspace import register import pycocotools.mask as mask_util from ..initializer import linear_init_, constant_ from ..transformers.utils import inverse_sigmoid __all__ = ['DETRHead', 'DeformableDETRHead']
[ 2, 15069, 357, 66, 8, 33448, 350, 37382, 47, 37382, 46665, 13, 1439, 6923, 33876, 13, 198, 2, 198, 2, 49962, 739, 262, 24843, 13789, 11, 10628, 362, 13, 15, 357, 1169, 366, 34156, 15341, 198, 2, 345, 743, 407, 779, 428, 2393, 2845...
3.64539
282
#!/usr/bin/env python3 import json import time import sys #import numpy as np import cv2 from cscore import CameraServer, VideoSource, CvSource, VideoMode, CvSink, UsbCamera from networktables import NetworkTablesInstance cap1 = cv2.VideoCapture(0) cap2 = cv2.VideoCapture(1) #HatchPanel = HatchPanelPipeline() team = None ntinst = NetworkTablesInstance.getDefault() ntinst.startClientTeam(team) SmartDashBoardValues = ntinst.getTable('SmartDashboard') while(True): # Capture frame-by-frame if SmartDashBoardValues.getNumber("Camera to Use", 0): ret, frame = cap1.read() #use camera 0 SmartDashBoardValues.putNumber("Using Camera", 0) elif SmartDashBoardValues.getNumber("Camera to Use", 1): ret, frame = cap2.read() #use camera 1 SmartDashBoardValues.putNumber("Using Camera", 1) else: print("No camera selected using camera 0") ret, frame = cap1.read() #found no value for camera to use, using cam 0 SmartDashBoardValues.putNumber("Using Camera", 2) # Our operations on the frame come here Track(frame, SmartDashBoardValues) cv2.imshow('frame',frame) #print(type(mask)) #res = cv2.bitwise_and(frame,frame, mask=mask) #cv2.imshow('frame',frame) #cv2.imshow('mask',mask) #cv2.imshow('res',res) if cv2.waitKey(1) & 0xFF == ord('q'): break # When everything done, release the capture cap1.release() cap2.release() cv2.destroyAllWindows()
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 18, 198, 11748, 33918, 198, 11748, 640, 198, 11748, 25064, 198, 2, 11748, 299, 32152, 355, 45941, 198, 11748, 269, 85, 17, 198, 198, 6738, 269, 26675, 1330, 20432, 10697, 11, 7623, 7416, 11...
2.411765
646
import sys from collections import deque import soccer_toolbox import csv_tools if __name__ == "__main__": main()
[ 11748, 25064, 198, 6738, 17268, 1330, 390, 4188, 198, 11748, 11783, 62, 25981, 3524, 198, 11748, 269, 21370, 62, 31391, 628, 198, 361, 11593, 3672, 834, 6624, 366, 834, 12417, 834, 1298, 198, 220, 220, 220, 1388, 3419, 198 ]
3.076923
39
from __future__ import unicode_literals from django.shortcuts import render, redirect from django.template import loader from django.http import HttpResponse from django.views import generic from .models import Movie from . import searchapi from django.urls import reverse # Create your views here.
[ 6738, 11593, 37443, 834, 1330, 28000, 1098, 62, 17201, 874, 198, 198, 6738, 42625, 14208, 13, 19509, 23779, 1330, 8543, 11, 18941, 198, 6738, 42625, 14208, 13, 28243, 1330, 40213, 198, 6738, 42625, 14208, 13, 4023, 1330, 367, 29281, 31077...
3.835443
79
#!/usr/bin/env python # # Copyright 2010 Google Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # """Defines executor tasks handlers for MapReduce implementation.""" # Disable "Invalid method name" # pylint: disable-msg=C6409 import datetime import logging import math import os from mapreduce.lib import simplejson import time from google.appengine.api import memcache from google.appengine.api.labs import taskqueue from google.appengine.ext import db from mapreduce import base_handler from mapreduce import context from mapreduce import quota from mapreduce import model from mapreduce import quota from mapreduce import util # TODO(user): Make this a product of the reader or in quotas.py _QUOTA_BATCH_SIZE = 20 # The amount of time to perform scanning in one slice. New slice will be # scheduled as soon as current one takes this long. _SLICE_DURATION_SEC = 15 # Delay between consecutive controller callback invocations. _CONTROLLER_PERIOD_SEC = 2
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 198, 2, 198, 2, 15069, 3050, 3012, 3457, 13, 198, 2, 198, 2, 49962, 739, 262, 24843, 13789, 11, 10628, 362, 13, 15, 357, 1169, 366, 34156, 15341, 198, 2, 345, 743, 407, 779, 428, 2393, ...
3.593674
411
""" This module is used to represent a CTSeries object from the DICOMSeries table in the database. Inherits SeriesWithImageSlices module. """ from logic.entities.series_with_image_slices import SeriesWithImageSlices
[ 37811, 198, 1212, 8265, 318, 973, 284, 2380, 257, 327, 4694, 10640, 2134, 422, 262, 360, 2149, 2662, 27996, 3084, 287, 262, 6831, 13, 198, 818, 372, 896, 7171, 3152, 5159, 50, 677, 274, 8265, 13, 198, 37811, 198, 6738, 9156, 13, 298...
3.5
62
import os import sys import tensorflow as tf import tf_utils.tf_util as tf_util from tf_utils.pointSIFT_util import pointSIFT_module, pointSIFT_res_module, pointnet_fp_module, pointnet_sa_module def get_model(point_cloud, is_training, num_class, bn_decay=None, feature=None): """ Semantic segmentation PointNet, input is B x N x 3, output B x num_class """ end_points = {} l0_xyz = point_cloud l0_points = feature end_points['l0_xyz'] = l0_xyz # c0: 1024*128 c0_l0_xyz, c0_l0_points, c0_l0_indices = pointSIFT_res_module(l0_xyz, l0_points, radius=0.15, out_channel=64, is_training=is_training, bn_decay=bn_decay, scope='layer0_c0', merge='concat') l1_xyz, l1_points, l1_indices = pointnet_sa_module(c0_l0_xyz, c0_l0_points, npoint=1024, radius=0.1, nsample=32, mlp=[64,128], mlp2=None, group_all=False, is_training=is_training, bn_decay=bn_decay, scope='layer1') # c1: 256*256 c0_l1_xyz, c0_l1_points, c0_l1_indices = pointSIFT_res_module(l1_xyz, l1_points, radius=0.25, out_channel=128, is_training=is_training, bn_decay=bn_decay, scope='layer1_c0') l2_xyz, l2_points, l2_indices = pointnet_sa_module(c0_l1_xyz, c0_l1_points, npoint=256, radius=0.2, nsample=32, mlp=[128,256], mlp2=None, group_all=False, is_training=is_training, bn_decay=bn_decay, scope='layer2') # c2: 256*512 c0_l2_xyz, c0_l2_points, c0_l2_indices = pointSIFT_res_module(l2_xyz, l2_points, radius=0.5, out_channel=256, is_training=is_training, bn_decay=bn_decay, scope='layer2_c0') c1_l2_xyz, c1_l2_points, c1_l2_indices = pointSIFT_res_module(c0_l2_xyz, c0_l2_points, radius=0.5, out_channel=512, is_training=is_training, bn_decay=bn_decay, scope='layer2_c1', same_dim=True) l2_cat_points = tf.concat([c0_l2_points, c1_l2_points], axis=-1) fc_l2_points = tf_util.conv1d(l2_cat_points, 512, 1, padding='VALID', bn=True, is_training=is_training, scope='layer2_conv_c2', bn_decay=bn_decay) # c3: 64*512 l3_xyz, l3_points, l3_indices = pointnet_sa_module(c1_l2_xyz, fc_l2_points, npoint=64, radius=0.4, nsample=32, mlp=[512,512], mlp2=None, group_all=False, is_training=is_training, bn_decay=bn_decay, scope='layer3') # FC layers:64*256->64*128---8192 net = tf_util.conv1d(l3_points, 256, 1, padding='VALID', bn=True, is_training=is_training, scope='layer4_conv', bn_decay=bn_decay) #net = tf_util.dropout(net, keep_prob=0.7, is_training=is_training, scope='dp1') net = tf_util.conv1d(net, 128, 1, padding='VALID', bn=True, is_training=is_training, scope='layer5_conv', bn_decay=bn_decay) ##flatten:B*8192 flat = tf.reshape(net, [-1,64*128]) ##dense layer:4096 dense = tf_util.fully_connected(flat,4096,scope='layer6_dense',bn=True,bn_decay=bn_decay,is_training=is_training) dense = tf_util.fully_connected(dense,4096,scope='layer7_dense',bn=True,bn_decay=bn_decay,is_training=is_training) dense = tf_util.dropout(dense, keep_prob=0.5, is_training=is_training, scope='dp') logits = tf_util.fully_connected(dense,num_class,scope='layer8_dense',activation_fn=None,bn=True,bn_decay=bn_decay,is_training=is_training)#logits return logits, end_points ''' l2_points = pointnet_fp_module(l2_xyz, l3_xyz, l2_points, l3_points, [512,512], is_training, bn_decay, scope='fa_layer2') _, l2_points_1, _ = pointSIFT_module(l2_xyz, l2_points, radius=0.5, out_channel=512, is_training=is_training, bn_decay=bn_decay, scope='fa_layer2_c0') _, l2_points_2, _ = pointSIFT_module(l2_xyz, l2_points, radius=0.5, out_channel=512, is_training=is_training, bn_decay=bn_decay, scope='fa_layer2_c1') _, l2_points_3, _ = pointSIFT_module(l2_xyz, l2_points, radius=0.5, out_channel=512, is_training=is_training, bn_decay=bn_decay, scope='fa_layer2_c2') l2_points = tf.concat([l2_points_1, l2_points_2, l2_points_3], axis=-1) l2_points = tf_util.conv1d(l2_points, 512, 1, padding='VALID', bn=True, is_training=is_training, scope='fa_2_fc', bn_decay=bn_decay) l1_points = pointnet_fp_module(l1_xyz, l2_xyz, l1_points, l2_points, [256,256], is_training, bn_decay, scope='fa_layer3') _, l1_points_1, _ = pointSIFT_module(l1_xyz, l1_points, radius=0.25, out_channel=256, is_training=is_training, bn_decay=bn_decay, scope='fa_layer3_c0') _, l1_points_2, _ = pointSIFT_module(l1_xyz, l1_points_1, radius=0.25, out_channel=256, is_training=is_training, bn_decay=bn_decay, scope='fa_layer3_c1') l1_points = tf.concat([l1_points_1, l1_points_2], axis=-1) l1_points = tf_util.conv1d(l1_points, 256, 1, padding='VALID', bn=True, is_training=is_training, scope='fa_1_fc', bn_decay=bn_decay) l0_points = pointnet_fp_module(l0_xyz, l1_xyz, l0_points, l1_points, [128,128,128], is_training, bn_decay, scope='fa_layer4') _, l0_points, _ = pointSIFT_module(l0_xyz, l0_points, radius=0.1, out_channel=128, is_training=is_training, bn_decay=bn_decay, scope='fa_layer4_c0') # FC layers net = tf_util.conv1d(l0_points, 128, 1, padding='VALID', bn=True, is_training=is_training, scope='fc1', bn_decay=bn_decay) net = tf_util.dropout(net, keep_prob=0.5, is_training=is_training, scope='dp1') net = tf_util.conv1d(net, num_class, 1, padding='VALID', activation_fn=None, scope='fc2') return net, end_points ''' def get_loss(logits,labels,num_class,smpws=1): """ :param logits: Bx(C*2)--Bx200(100*2) :param labels: BxCx2--Bx100x2 :param smpw: B ; sample weight :num_class:200 --class_number*2 """ labels=tf.cast(labels, tf.float32) part_logits=tf.reshape(logits,[-1,num_class//2,2]) classify_loss=tf.reduce_mean(tf.multiply(tf.reduce_sum(tf.nn.softmax_cross_entropy_with_logits(logits=part_logits, labels=labels),1),smpws)) #classify_loss0=classify_loss #tf.summary.scalar('classify loss 0', classify_loss0) ###attention!!! #regularization_loss=tf.reduce_mean(tf.contrib.slim.losses.get_regularization_losses()) #regularization_loss=tf.reduce_mean(tf.losses.get_regularization_losses(scope)) #reg=1;classify_loss+=reg*regularization_loss ##scalar #tf.summary.scalar('classify loss', classify_loss) tf.summary.scalar('part logits shape 0', part_logits.shape[0]) tf.summary.scalar('part logits shape 1', part_logits.shape[1]) tf.summary.scalar('part logits shape 2', part_logits.shape[2]) tf.summary.scalar('labels shape 0', labels.shape[0]) tf.summary.scalar('labels shape 1', labels.shape[1]) tf.summary.scalar('labels shape 2', labels.shape[2]) tf.add_to_collection('losses', classify_loss) return classify_loss def eval_pred(logits,input_labels,num_class,wt=1):# """ :param logits: Bx(C*2)--Bx200(100*2);>< age_thresh """ input_labels=tf.cast(input_labels, tf.float32) wt=tf.cast(wt, tf.float32) part_logits=tf.reshape(logits,[-1,num_class//2,2]) part_logits1=tf.map_fn(lambda x:x[:,0],tf.nn.softmax(part_logits)) pred=tf.cast(tf.reduce_sum(part_logits1,1),tf.float32) labb=tf.reduce_sum(tf.map_fn(lambda x:x[:,0],input_labels),1) #mae_wt=tf.cast(tf.reduce_mean(tf.multiply(tf.abs(pred-labb),wt)), tf.float64) mae_wt=tf.reduce_mean(tf.multiply(tf.abs(pred-labb),wt)) #mae=tf.cast(tf.reduce_mean(tf.abs(pred-labb)), tf.float64) mae=tf.reduce_mean(tf.abs(pred-labb)) #tf.summary.scalar('Test set MAE', mae) #tf.summary.scalar('Test set MAE_weighted', mae_wt) return pred,mae,mae_wt ''' def get_loss(pred, label, smpw): """ :param pred: BxNxC :param label: BxN :param smpw: BxN :return: """ classify_loss = tf.losses.sparse_softmax_cross_entropy(labels=label, logits=pred, weights=smpw) tf.summary.scalar('classify loss', classify_loss) tf.add_to_collection('losses', classify_loss) return classify_loss '''
[ 11748, 28686, 198, 11748, 25064, 198, 198, 11748, 11192, 273, 11125, 355, 48700, 198, 11748, 48700, 62, 26791, 13, 27110, 62, 22602, 355, 48700, 62, 22602, 198, 6738, 48700, 62, 26791, 13, 4122, 50, 32297, 62, 22602, 1330, 966, 50, 3229...
2.179184
3,555
from .cwljobdispatcher import CWLJobDispatcher from .cwljobgatherer import CWLJobGatherer
[ 6738, 764, 66, 40989, 21858, 6381, 8071, 2044, 1330, 24006, 43, 33308, 7279, 8071, 2044, 198, 6738, 764, 66, 40989, 21858, 41268, 48386, 1330, 24006, 43, 33308, 38, 265, 48386 ]
2.966667
30
print('='*50) print("Ol mundo!") print('='*50)
[ 4798, 10786, 11639, 9, 1120, 8, 198, 4798, 7203, 30098, 27943, 78, 2474, 8, 198, 4798, 10786, 11639, 9, 1120, 8 ]
2.190476
21
#!/usr/bin/env python2 #===- subzero/wasm-run-torture-tests.py - Subzero WASM Torture Test Driver ===// # # The Subzero Code Generator # # This file is distributed under the University of Illinois Open Source # License. See LICENSE.TXT for details. # #===-----------------------------------------------------------------------===// from __future__ import print_function import argparse import glob import multiprocessing import os import Queue import shutil import StringIO import sys import threading IGNORED_TESTS = set([ # The remaining tests are known waterfall failures '20010122-1.c.wasm', '20031003-1.c.wasm', '20071018-1.c.wasm', '20071120-1.c.wasm', '20071220-1.c.wasm', '20071220-2.c.wasm', '20101011-1.c.wasm', 'alloca-1.c.wasm', 'bitfld-3.c.wasm', 'bitfld-5.c.wasm', 'builtin-bitops-1.c.wasm', 'conversion.c.wasm', 'eeprof-1.c.wasm', 'frame-address.c.wasm', 'pr17377.c.wasm', 'pr32244-1.c.wasm', 'pr34971.c.wasm', 'pr36765.c.wasm', 'pr39228.c.wasm', 'pr43008.c.wasm', 'pr47237.c.wasm', 'pr60960.c.wasm', 'va-arg-pack-1.c.wasm', '20000717-5.c.wasm', # abort() (also works without emcc) '20001203-2.c.wasm', # assert fail (works without emcc) '20040811-1.c.wasm', # OOB trap '20070824-1.c.wasm', # abort() (also works without emcc) 'arith-rand-ll.c.wasm', # abort() (works without emcc) 'arith-rand.c.wasm', # abort() (works without emcc) 'pr23135.c.wasm', # OOB trap (works without emcc) 'pr34415.c.wasm', # (empty output?) 'pr36339.c.wasm', # abort() (works without emcc) 'pr38048-2.c.wasm', # abort() (works without emcc) 'pr42691.c.wasm', # abort() (works without emcc) 'pr43220.c.wasm', # OOB trap (works without emcc) 'pr43269.c.wasm', # abort() (works without emcc) 'vla-dealloc-1.c.wasm', # OOB trap (works without emcc) '20051012-1.c.wasm', # error reading binary '921208-2.c.wasm', # error reading binary '920501-1.c.wasm', # error reading binary 'call-trap-1.c.wasm', # error reading binary 'pr44942.c.wasm', # error reading binary '920625-1.c.wasm', # abort() (also fails without emcc) '931004-10.c.wasm', # abort() (also fails without emcc) '931004-12.c.wasm', # abort() (also fails without emcc) '931004-14.c.wasm', # abort() (also fails without emcc) '931004-6.c.wasm', # abort() (also fails without emcc) 'pr38051.c.wasm', # (empty output?) (fails without emcc) 'pr38151.c.wasm', # abort() (fails without emcc) 'pr44575.c.wasm', # abort() (fails without emcc) 'strct-stdarg-1.c.wasm', # abort() (fails without emcc) 'strct-varg-1.c.wasm', # abort() (fails without emcc) 'va-arg-22.c.wasm', # abort() (fails without emcc) 'stdarg-3.c.wasm', # abort() (fails without emcc) 'pr56982.c.wasm', # missing setjmp (wasm.js check did not catch) '20010605-2.c.wasm', # missing __netf2 '20020413-1.c.wasm', # missing __lttf2 '20030914-1.c.wasm', # missing __floatsitf '20040709-1.c.wasm', # missing __netf2 '20040709-2.c.wasm', # missing __netf2 '20050121-1.c.wasm', # missing __floatsitf '20080502-1.c.wasm', # missing __eqtf2 '920501-8.c.wasm', # missing __extenddftf2 '930513-1.c.wasm', # missing __extenddftf2 '930622-2.c.wasm', # missing __floatditf '960215-1.c.wasm', # missing __addtf3 '960405-1.c.wasm', # missing __eqtf2 '960513-1.c.wasm', # missing __subtf3 'align-2.c.wasm', # missing __eqtf2 'complex-6.c.wasm', # missing __subtf3 'complex-7.c.wasm', # missing __netf2 'pr49218.c.wasm', # missing __fixsfti 'pr54471.c.wasm', # missing __multi3 'regstack-1.c.wasm', # missing __addtf3 'stdarg-1.c.wasm', # missing __netf2 'stdarg-2.c.wasm', # missing __floatsitf 'va-arg-5.c.wasm', # missing __eqtf2 'va-arg-6.c.wasm', # missing __eqtf2 'struct-ret-1.c.wasm', # missing __extenddftf2 ]) parser = argparse.ArgumentParser() parser.add_argument('-v', '--verbose', action='store_true') parser.add_argument('--translate-only', action='store_true') parser.add_argument('tests', nargs='*') args = parser.parse_args() OUT_DIR = "./build/wasm-torture" results_lock = threading.Lock() compile_count = 0 compile_failures = [] run_count = 0 run_failures = [] verbose = args.verbose if len(args.tests) > 0: test_files = args.tests else: test_files = glob.glob("./emwasm-torture-out/*.wasm") if os.path.exists(OUT_DIR): shutil.rmtree(OUT_DIR) os.mkdir(OUT_DIR) tasks = Queue.Queue() for i in range(multiprocessing.cpu_count()): t = threading.Thread(target=worker) t.daemon = True t.start() for test_file in test_files: tasks.put(test_file) tasks.join() if len(compile_failures) > 0: print() print("Compilation failures:") print("=====================\n") for f in compile_failures: print(" \033[1;31m" + f + "\033[1;m") if len(run_failures) > 0: print() print("Run failures:") print("=============\n") for f in run_failures: print(" \033[1;33m" + f + "\033[1;m") print("\n\033[1;32m{}\033[1;m / \033[1;33m{}\033[1;m / {} tests passed" .format(run_count, compile_count - run_count, run_count + len(compile_failures) + len(run_failures)))
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 17, 198, 198, 2, 855, 10779, 850, 22570, 14, 86, 8597, 12, 5143, 12, 83, 419, 495, 12, 41989, 13, 9078, 532, 3834, 22570, 21725, 44, 28467, 495, 6208, 12434, 24844, 1003, 198, 2, 198, 2...
2.299191
2,226
import numpy as np import pygame import sys import math import random from board import Board from ai import Minimax_AI # function to draw the board in pygame if __name__ == '__main__': # colors for game colors = {"blue": (0, 0, 255), "black": (0, 0, 0), "red": (255, 0, 0), "yellow": (255, 255, 0)} # size of board ROW_COUNT = 6 COLUMN_COUNT = 7 # create board board = Board(ROW_COUNT, COLUMN_COUNT) # players players = [1, 2] # initialize AI ai_depth = 6 ai_player = random.choice(players) ai = Minimax_AI(ai_depth, ai_player, ROW_COUNT, COLUMN_COUNT) # decide turns; if turn is 0 player moves first if ai_player == 2: turn = 0 else: turn = 1 pygame.init() SQUARESIZE = 100 width = COLUMN_COUNT * SQUARESIZE height = (ROW_COUNT+1) * SQUARESIZE size = (width, height) RADIUS = int(SQUARESIZE/2 - 5) screen = pygame.display.set_mode(size) draw_board(board.status) pygame.display.update() myfont = pygame.font.SysFont("monospace", 75) game_over = False while not game_over: # Ask for Player 1 Input if turn == 0: turn_over = False while not turn_over: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() if event.type == pygame.MOUSEMOTION: pygame.draw.rect( screen, colors["black"], (0, 0, width, SQUARESIZE)) posx = event.pos[0] if turn == 0: pygame.draw.circle( screen, colors["red"], (posx, int(SQUARESIZE/2)), RADIUS) else: pygame.draw.circle( screen, colors["yellow"], (posx, int(SQUARESIZE/2)), RADIUS) pygame.display.update() if event.type == pygame.MOUSEBUTTONDOWN: pygame.draw.rect( screen, colors["black"], (0, 0, width, SQUARESIZE)) # print(event.pos) posx = event.pos[0] col = int(math.floor(posx/SQUARESIZE)) if board.is_valid_location(col): row = board.get_next_open_row(col) board.insert_piece(row, col, 1) turn_over = True if board.is_winning_position(1): label = myfont.render( "You win!!", 1, colors["red"]) screen.blit(label, (40, 10)) game_over = True draw_board(board.status) # Ask for Player 2 Input else: col = ai.make_move(board.status) if board.is_valid_location(col): row = board.get_next_open_row(col) board.insert_piece(row, col, 2) if board.is_winning_position(2): label = myfont.render( "AI win!!", 1, colors["red"]) screen.blit(label, (40, 10)) game_over = True draw_board(board.status) turn += 1 turn = turn % 2 if game_over: pygame.time.wait(3000)
[ 11748, 299, 32152, 355, 45941, 198, 11748, 12972, 6057, 198, 11748, 25064, 198, 11748, 10688, 198, 11748, 4738, 198, 6738, 3096, 1330, 5926, 198, 6738, 257, 72, 1330, 1855, 320, 897, 62, 20185, 628, 198, 2, 2163, 284, 3197, 262, 3096, ...
1.742253
2,033
# https://docs.djangoproject.com/en/dev/ref/settings/#secure-proxy-ssl-header SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https") # https://docs.djangoproject.com/en/dev/ref/settings/#secure-ssl-redirect SECURE_SSL_REDIRECT = True # https://docs.djangoproject.com/en/dev/ref/settings/#session-cookie-secure SESSION_COOKIE_SECURE = True # https://docs.djangoproject.com/en/dev/ref/settings/#csrf-cookie-secure CSRF_COOKIE_SECURE = True # https://docs.djangoproject.com/en/dev/topics/security/#ssl-https # https://docs.djangoproject.com/en/dev/ref/settings/#secure-hsts-preload SECURE_HSTS_PRELOAD = True # https://docs.djangoproject.com/en/dev/ref/settings/#secure-hsts-include-subdomains SECURE_HSTS_INCLUDE_SUBDOMAINS = True # https://docs.djangoproject.com/en/dev/ref/settings/#secure-hsts-seconds SECURE_HSTS_SECONDS = 31536000 # https://docs.djangoproject.com/en/dev/ref/middleware/#x-content-type-options-nosniff SECURE_CONTENT_TYPE_NOSNIFF = True
[ 2, 3740, 1378, 31628, 13, 28241, 648, 404, 305, 752, 13, 785, 14, 268, 14, 7959, 14, 5420, 14, 33692, 31113, 22390, 12, 36436, 12, 45163, 12, 25677, 198, 23683, 11335, 62, 31190, 34278, 62, 31127, 62, 37682, 1137, 796, 5855, 40717, ...
2.494819
386
#!/usr/bin/python # -*-coding: utf-8 -*- # Author: Joses Ho # Email : joseshowh@gmail.com from __future__ import division def jackknife_indexes(data): # Taken without modification from scikits.bootstrap package. """ From the scikits.bootstrap package. Given an array, returns a list of arrays where each array is a set of jackknife indexes. For a given set of data Y, the jackknife sample J[i] is defined as the data set Y with the ith data point deleted. """ import numpy as np base = np.arange(0,len(data)) return (np.delete(base,i) for i in base) def bca(data, alphas, statarray, statfunction, ostat, reps): ''' Subroutine called to calculate the BCa statistics. Borrowed heavily from scikits.bootstrap code. ''' import warnings import numpy as np import pandas as pd import seaborn as sns from scipy.stats import norm from numpy.random import randint # The bias correction value. z0 = norm.ppf( ( 1.0*np.sum(statarray < ostat, axis = 0) ) / reps ) # Statistics of the jackknife distribution jackindexes = jackknife_indexes(data[0]) jstat = [statfunction(*(x[indexes] for x in data)) for indexes in jackindexes] jmean = np.mean(jstat,axis = 0) # Acceleration value a = np.divide(np.sum( (jmean - jstat)**3, axis = 0 ), ( 6.0 * np.sum( (jmean - jstat)**2, axis = 0)**1.5 ) ) if np.any(np.isnan(a)): nanind = np.nonzero(np.isnan(a)) warnings.warn("Some acceleration values were undefined." "This is almost certainly because all values" "for the statistic were equal. Affected" "confidence intervals will have zero width and" "may be inaccurate (indexes: {})".format(nanind)) zs = z0 + norm.ppf(alphas).reshape(alphas.shape+(1,)*z0.ndim) avals = norm.cdf(z0 + zs/(1-a*zs)) nvals = np.round((reps-1)*avals) nvals = np.nan_to_num(nvals).astype('int') return nvals
[ 2, 48443, 14629, 14, 8800, 14, 29412, 198, 2, 532, 9, 12, 66, 7656, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 2, 6434, 25, 449, 4629, 9544, 198, 2, 9570, 1058, 474, 4629, 4919, 71, 31, 14816, 13, 785, 628, 198, 6738, 11593, 37443...
2.49
800
import math as ma # note all sizes in m^2 # all costs in pounds if __name__ == "__main__": vals = get_details() vals['tile_area'] = 0.04 #0.2m squared tiles print "\n > Total cost: %.2f\n" % get_cost(vals)
[ 11748, 10688, 355, 17266, 198, 198, 2, 3465, 477, 10620, 287, 285, 61, 17, 198, 2, 477, 3484, 287, 8059, 628, 628, 198, 361, 11593, 3672, 834, 6624, 366, 834, 12417, 834, 1298, 198, 220, 220, 220, 410, 874, 796, 651, 62, 36604, 34...
2.419355
93
#!/usr/bin/env python # # pyFlow - a lightweight parallel task engine # # Copyright (c) 2012-2017 Illumina, Inc. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in # the documentation and/or other materials provided with the # distribution. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY # WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # # # # demonstrate/test addTask() cwd option # import os.path import sys # add module path by hand # scriptDir=os.path.abspath(os.path.dirname(__file__)) sys.path.append(scriptDir+"/../../src") from pyflow import WorkflowRunner # all pyflow workflows are written into classes derived from # pyflow.WorkflowRunner: # # Instantiate the workflow # wflow = CwdWorkflow() # Run the worklow: # retval=wflow.run(mode="local") sys.exit(retval)
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 198, 2, 198, 2, 12972, 37535, 532, 257, 18700, 10730, 4876, 3113, 198, 2, 198, 2, 15069, 357, 66, 8, 2321, 12, 5539, 39256, 1437, 11, 3457, 13, 198, 2, 1439, 2489, 10395, 13, 198, 2, ...
3.2247
583