def main(): file1 = pcap_time.get_time("40test_norm.txt") file2 = pcap_time.get_time("50test_norm.txt") diff = [] for i in xrange(min(len(file1), len(file2))): diff.append(abs(float(file1[i]) - float(file2[i])) * 1000) series = diff[:300] + holt_winters.holt_winters( diff[:3000], 26, 20, mode='additive')[0] plot.plotter(diff[:320], series)
def main(): try: values = set_input(sys.argv) if(validate_input(values)): loads = [] moments = [] positions = [] span = values.get('span') position = 0 reactions = get_support_reactions(values) if(len(reactions)==2): reaction1 = reactions[0] reaction2 = reactions[1] if(len(reactions)==1): reaction = reactions[0] while (position<=float(span)): load = 0 moment = 0 if(len(reactions)==2): if(position>=float(reaction1[2])): load += float(reaction1[1]) if(position<=float(reaction1[2])): moment += float(reaction1[1])*(float(reaction1[2])-position) if(position>=float(reaction2[2])): load += float(reaction2[1]) if(position<=float(reaction2[2])): moment += float(reaction2[1])*(float(reaction2[2])-position) elif(len(reactions)==1): if(position>=float(reaction[2])): load = get_sfd(values, float(values.get('span'))) if(position<=float(reaction[2])): moment = float(reaction[1]) loads.append(load-get_sfd(values, position)) moments.append(moment-get_bmd(values, position)) positions.append(position) position+=float(span)/100 solve_reactions(values) solve_sfd(values) plotter(loads, positions, 'Shear force') solve_bmd(values) plotter(moments, positions, 'Bending Moment') except: print(colored('Please give a valid input! Try again', 'red'))
def get(self): self.set_status(200) self.set_header("Content-Type", "image/svg+xml") db = TSDb('lego.xe.be',4242) det = ['ohain.temp','ohain.weight{id=1}','ohain.weight{id=2}','ohain.weight{id=0}'] query = qs_decode(self.request.query) print query['start'] data = db.query(query['start'][0],None,det,'sum','1h-avg') # print data self.finish(plotter(data)) del data del db
# get and configure the model import models model = getattr(models,model_name)(config=model_config) # iterate over rule data and analyze point-by-point saved_data_list = [] data = pickle.load(open(args.output_file_name)) for rule, rule_data in data.items(): logr.info(u"analyzing rule: {}".format(rule)) plotable_data = analyzer(rule_data,model,logr) # remove spaces in rule name rule_name = rule.replace(" ","-")[0:100] if args.do_plot: return_val = plotter(plotable_data,rule_name) # the plotter returns -1 if the counts data don't exist if return_val == -1: continue # save data if plotable_data != []: saved_data_list.append((rule_name,plotable_data)) def max_last_field_getter(tup): """ a function that acts on tuples like: ( [rule], [ (1_field_1, 1_field_2, 1_field_3 ... 1_field_n),(2_field_1,2_field_2,2_field_3...2_field_n)...] ) and returns the largest m_field_n value, where n is the (fixed) size of the tuple in the list, and m is the length of the list """ plotable_data = tup[1]
print "> Start generation of image, channel %s, time %s, mode %s." % (CHANNEL, TIME, mode) print "> Extracting file..." try: sourceFile = tar.extractfile(each) source = sourceFile.read() headerFile = tar.extractfile("hdr_%s_%s_001.txt" % (CHANNEL.lower(), TIME)) header = headerFile.read() convertTable = extractConvertTable(header) except Exception,e: print e print "Error! Cannot extract this file. Skip." continue print "> Configuring plotter..." p = plotter() if 'VIS' == CHANNEL: p.setColorScale(COLORSCALE_VIS) p.setConvertTable(convertTable) p.setSourceRegion(59.995, 85.005, -60.005, -154.995) p.setDataDimension(12000, 12000) p.setDK(DK) p.setDataResolution(0.01, 0.01) else: p.setColorScale(COLORSCALE_IR) p.setConvertTable(convertTable) p.setSourceRegion(59.98, 85.02, -60.02, -154.98) p.setDataDimension(3000, 3000) p.setDK(DK) p.setDataResolution(0.04, 0.04)
print "> Extracting file..." try: sourceFile = tar.extractfile(each) source = sourceFile.read() headerFile = tar.extractfile("hdr_%s_%s_001.txt" % (CHANNEL.lower(), TIME)) header = headerFile.read() convertTable = extractConvertTable(header) except Exception, e: print e print "Error! Cannot extract this file. Skip." continue print "> Configuring plotter..." p = plotter() if 'VIS' == CHANNEL: p.setColorScale(COLORSCALE_VIS) p.setConvertTable(convertTable) p.setSourceRegion(59.995, 85.005, -60.005, -154.995) p.setDataDimension(12000, 12000) p.setDK(DK) p.setDataResolution(0.01, 0.01) else: p.setColorScale(COLORSCALE_IR) p.setConvertTable(convertTable) p.setSourceRegion(59.98, 85.02, -60.02, -154.98) p.setDataDimension(3000, 3000) p.setDK(DK) p.setDataResolution(0.04, 0.04)
def sim(gType, depthF, slope, profile, wavelength, period, har, res, material, theta, phi, pTEM, loop): tests = np.size(locals()[loop]) loops = locals()[loop] depthFs = depthF slopes = slope wavelengths = wavelength periods = period hars = har ress = res depthF = depthFs[0] slope = slopes[0] wavelength = wavelengths[0] period = periods[0] har = hars[0] res = ress[0] print(f"\nSimulating a {gType} diffraction grating made of {material}....") ##refractive index vals at 400nm Si_n = 5.5674 #Si_n=6.4732 #Si_n=5.4754 #Si_n=4.9760 #Si_n=4.6784 Al_n = 0.48787 Ag_n = 0.05 Au_n = 1.4684 Ti_n = 2.0913 #extinction coefficient vals at 400nm Si_k = 0.38612 #Si_k=1.0686 #Si_k=3.0024 #Si_k=4.1990 #Si_k=0.14851 Al_k = 4.8355 Ag_k = 2.1035 Au_k = 1.9530 Ti_k = 2.9556 er_si = (Si_n)**2 - (Si_k)**2 + 2 * Si_n * Si_k * 1j if material == 'Silicon': er = er_si elif material == 'Aluminium': er = (Al_n)**2 - (Al_k)**2 + 2 * Al_n * Al_k * 1j elif material == 'Silver': er = (Ag_n)**2 - (Ag_k)**2 + 2 * Ag_n * Ag_k * 1j elif material == 'Gold': er = (Au_n)**2 - (Au_k)**2 + 2 * Au_n * Au_k * 1j elif material == 'Titanium': er = (Ti_n)**2 - (Ti_k)**2 + 2 * Ti_n * Ti_k * 1j print(f'Permittivity = {er}') #Creating basic layers reflectionLayer = Layer(er=1.0006, ur=1, L=100) baseLayer = Layer(er=er_si, ur=1, L=1) source = Source(wavelength=wavelength, theta=theta, phi=phi, pTEM=pTEM, layer=reflectionLayer) if gType == 'Checkerboard': print("Creating layers for checkerboard simulation...\n") nLayers = Check(res, er, material, gType) if gType == 'Rectangular' and slope == 0: print( "Creating layers for rectangular simulation with vertical sidewalls...\n" ) nLayers = Slopecsv(res, slope, depthF, material, gType, er) if gType == 'Square': print("Creating layers for square simulation...\n") nLayers = Square(res, er, material, gType) if gType == 'CoatedChecker': print("Creating layers for coated checkerboard simulation...\n") nLayers = CheckCoat(res, er, material, gType, er_si) if gType == 'CheckerError': err = input( "What percentage error would you like on the checkerboard? Please enter as a decimal, eg 0.3 for 30% error." ) print( f"Creating layers for checkerboard simulation with error {err}...\n" ) nLayers = CheckErr(res, er, material, gType, err) if gType == 'CheckDiag': print(f"Creating layers for checkerboard simulation on diagonal...\n") nLayers = CheckDiag(res, er, material, gType) if gType == 'CheckDiagErr': err = input( "What percentage error would you like on the checkerboard? Please enter as a decimal, eg 0.3 for 30% reduction in square size." ) print( f"Creating layers for checkerboard simulation with error {err}...\n" ) nLayers = CheckDiagErr(res, er, material, gType, err) if gType == 'Circ': print(f"Creating layers for circular grating simulation...\n") nLayers = Circ(res, er, material, gType) #setting up arrays to hold results of zeroth and first diffraction orders from simulation firstxs = np.zeros(tests) firstys = np.zeros(tests) zeros = np.zeros(tests) diags = np.zeros(tests) count = 0 while count < tests: depthF = depthFs.take([count], mode='clip')[0] slope = slopes.take([count], mode='clip')[0] wavelength = wavelengths.take([count], mode='clip')[0] period = periods.take([count], mode='clip')[0] har = hars.take([count], mode='clip')[0] res = ress.take([count], mode='clip')[0] depth = depthF * wavelength #generate csv files if slope != 0: if gType == "Rectangular": print( f"Creating layers for rectangular grating with sloped sidewalls, slope={slope} degrees...\n" ) nLayers = Slopecsv(res, slope, depthF, material, gType, er) elif gType == "Blazed": print( f"Creating layers for blazed grating of blaze angle {slope} degrees...\n" ) nLayers = Blazedcsv(res, slope, depthF, material, gType, er) #set period in each direction t1, t2 = complexArray([period, 0, 0]), complexArray([0, period, 0]) n = 0 layers = np.empty(nLayers, Layer) print( f"Performing simulation trial {count+1} of {tests}, with {loop}={loops[count]}..." ) print(f"This simulation requires {nLayers} layers... ") #slope=90-slope while n < nLayers: print(f"creating layer {n+1} of {nLayers}...") if slope != 0: eCellData = np.transpose( np.genfromtxt( f'{path}/csvs/{gType}_{material}_slope{slope}_{depthF}_layer{count}_{res}.csv', delimiter=',', dtype=complex)) else: eCellData = np.transpose( np.genfromtxt( f'{path}/csvs/{gType}_{material}_slope0_layer{n}_{res}.csv', delimiter=',', dtype=complex)) print( f'file used:{gType}_{material}_slope0_layer{n}_{res}.csv ') uCellData = np.transpose( np.genfromtxt(f'{path}/csvs/U{res}.csv', delimiter=',')) #setting depth of grating if gType == "Blazed": depth = period * np.tan(slope) crystalThickness = depth / nLayers if gType == "CoatedChecker": crystalThickness = depth numberHarmonics = (har, har) #numberHarmonics=(har,har) #creating crystal (grating) and grating layer deviceCrystal = Crystal(eCellData, uCellData, t1, t2) layers[n] = Layer(crystal=deviceCrystal, L=crystalThickness, numberHarmonics=numberHarmonics) n = n + 1 print(f"There are {nLayers} Layers of thickness {crystalThickness}") layerStack = LayerStack(reflectionLayer, *layers, baseLayer) print("Running simulation...\n") #perform simulation solver = Solver(layerStack, source, numberHarmonics) solver.Solve() sResults = solver.results rx = np.reshape(solver.rx, (har, har)) ry = np.reshape(solver.ry, (har, har)) rz = np.reshape(solver.rz, (har, har)) # np.savetxt(f"{path}/results/RX_{gType}_{loop}_tests({tests})_{wavelength}_{period}.csv",rx , delimiter=",") # np.savetxt(f"{path}/results/RY_{gType}_{loop}_tests({tests})_{wavelength}_{period}.csv",ry , delimiter=",") # np.savetxt(f"{path}/results/RZ_{gType}_{loop}_tests({tests})_{wavelength}_{period}.csv",rz , delimiter=",") RX = np.ones([3, 3], dtype='complex') RY = np.ones([3, 3], dtype='complex') RZ = np.ones([3, 3], dtype='complex') i, j = int(har / 2) - 1, int(har / 2) - 1 a, b = 0, 0 while i >= int(har / 2) - 1 and i <= int(har / 2) + 1: j = int(har / 2) - 1 b = 0 while j >= int(har / 2) - 1 and j <= int(har / 2) + 1: RX[a, b] = complex(rx[i, j]) RY[a, b] = complex(ry[i, j]) RZ[a, b] = complex(rz[i, j]) j = j + 1 b = b + 1 i = i + 1 a = a + 1 stokes = transform(RX, RY, RZ, wavelength, period, 'x', False) print("STOKES:\n") print(stokes) # Get the diffraction efficiencies R and T and overall reflection and transmission coefficients R and T (R, RTot) = (solver.R, solver.RTot) print(f"Total Reflection {RTot}") # if profile: # makeProf(slope,depthF,nLayers,res, material) firstx = R[int(har / 2)][int(har / 2 - 1)] firsty = R[int(har / 2 - 1)][int(har / 2)] zeroth = R[int(har / 2)][int(har / 2)] diag = R[int(har / 2 + count)][int(har / 2 + count)] diags[count] = diag firstxs[count] = firstx firstys[count] = firsty zeros[count] = zeroth print("Plotting...") plotter(firstxs, firstys, zeros, diags, R, loop, gType, tests, count, profile, slope, depthF, nLayers, res, material, wavelength, period, har, loops[count]) count = count + 1 plt.figure() plt.plot( loops, zeros, label="0th order efficiency") #simulated 0th orders at varying depths plt.plot(loops, firstxs, label="1st order efficiency - x direction" ) #simulated 1st orders at varying depths #plt.scatter(loops,firstys,label="1st order efficiency - y direction") plt.plot(loops, diags, label="diagonal efficiency modes") plt.ylabel("Intensity") plt.xlabel(f"{loop}") plt.legend(loc='upper left', bbox_to_anchor=(1.05, 1)) plt.title(f"Efficiency of {gType} {material} grating at different {loop} ") tuple = (loops, zeros, firstxs, firstys, diags) results = np.vstack(tuple) np.savetxt( f"{path}/results/{gType}_{loop}_tests({tests})_{wavelength}_{period}.csv", results, delimiter=",") return 0
#!/usr/bin/env python import tornado.ioloop import tornado.web from urlparse import parse_qs as qs_decode from urllib import urlencode as qs_encode from tornado import escape from plot import plotter from tsdb import TSDb import sys if __name__ == "__main__": print sys.argv db = TSDb('lego.xe.be',4242) det = ['ohain.temp','ohain.weight{id=1}','ohain.weight{id=2}','ohain.weight{id=0}','ohain.weight{id=3}'] data = db.query(sys.argv[1],None,det,'sum','10m-avg') plotter(data,sys.argv[2])
# get and configure the model import models model = getattr(models,model_name)(config=model_config) # iterate over rule data and analyze point-by-point saved_data = {} data = pickle.load(open(args.output_file_name)) for rule, rule_data in data.items(): logr.info(u"analyzing rule: {}".format(rule)) plotable_data = analyzer(rule_data,model,logr) # save data if plotable_data != []: saved_data.update([(rule,plotable_data)]) pickle.dump(saved_data,open(args.analyzed_data_file,"w")) if args.do_plot: # auto-generate this plotting param from re-bin params plot_config["x_unit"] = str(rebin_config["n_binning_unit"]) + " " + str(rebin_config["binning_unit"]) for rule, plotable_data in pickle.load(open(args.analyzed_data_file)).items(): logr.info(u"plotting results for rule: {}".format(rule)) # remove spaces in rule name rule_name = rule.replace(" ","-")[0:100] plot_config["plot_title"] = rule_name plotter(plotable_data,plot_config)
def search_places(query='', maxprice=4, radius='2000'): bot_response = [] query = process_input(query) if query == ERROR_MESSAGE: return ERROR_MESSAGE, True api_type = closest_type(query[0]) geocode = geocoder.Geocoder(query[1]) location = geocode.get_geocode() if location is None: return ERROR_MESSAGE, True formatted_location = [str(location['lat']) + ',' + str(location['lng'])] parameters = parser.urlencode( { 'keyword': query, 'location': formatted_location, 'region': 'gr', 'opennow': '', 'radius': radius, 'type': api_type, 'maxprice': maxprice, 'rankby': 'prominence', 'key': PLACES_API_KEY }, doseq=True) # performs a nearby on the specified query req = urllib.request.Request(BASE_PLACES_URL + parameters) response = urllib.request.urlopen(req).read() contents = json.loads(response.decode('utf-8')) check = checker.ApiChecker(contents, 'places') # check status for initial request check.check_response_status() if not check.get_status() or check.get_zero_res_query(): return None, True results = contents['results'] latitudes = [location['lat']] longitudes = [location['lng']] for result in results: # get price level price_level = PRICE_LEVELS[result['price_level']] # check if there is rating if 'rating' in result: bot_response.append( "Open now: {}, Place: {}, Address: {}, Price level: {} and Rating: {}" .format(str(result['opening_hours']['open_now']), result['name'], str(result['vicinity']), price_level, str(result['rating']))) else: bot_response.append( "Open now: {}, Place: {}, Address: {}, Price level: {}".format( str(result['opening_hours']['open_now']), result['name'], str(result['vicinity']), price_level)) # needed for plotter latitudes.append(result['geometry']['location']['lat']) longitudes.append(result['geometry']['location']['lng']) plotter(latitudes, longitudes) if not bot_response: # if bot_response is an empty list return None, True else: return bot_response, False
# get and configure the model import models model = getattr(models, model_name)(config=model_config) # iterate over rule data and analyze point-by-point saved_data_list = [] data = pickle.load(open(args.output_file_name)) for rule, rule_data in data.items(): logr.info(u"analyzing rule: {}".format(rule)) plotable_data = analyzer(rule_data, model, logr) # remove spaces in rule name rule_name = rule.replace(" ", "-")[0:100] if args.do_plot: return_val = plotter(plotable_data, rule_name) # the plotter returns -1 if the counts data don't exist if return_val == -1: continue # save data if plotable_data != []: saved_data_list.append((rule_name, plotable_data)) def max_last_field_getter(tup): """ a function that acts on tuples like: ( [rule], [ (1_field_1, 1_field_2, 1_field_3 ... 1_field_n),(2_field_1,2_field_2,2_field_3...2_field_n)...] ) and returns the largest m_field_n value, where n is the (fixed) size of the tuple in the list, and m is the length of the list """ plotable_data = tup[1]
# if no humans found, return false and do a random move if len(human) == 0: return (False, False) else: # if we found a human in the neighbourhoud, go to it return human[np.random.randint(len(human))] if __name__ == "__main__": with open("config.txt", "r") as inf: config = ast.literal_eval(inf.read()) sim = simulation(config) plotter = p.plotter(config) start = time.time() sim.initalizeGrid() end = time.time() print end - start startSteps = time.time() for i in xrange(config["steps"]): startSteps = time.time() sim.step() endSteps = time.time() startSteps2 = time.time()
beta_from_x = data['beta_from_x'] # ECOS cannot solve this to sufficient precision! # prob.solve(solver="ECOS", abstol=1e-14, reltol=1e-14, feastol=1e-14, # verbose=True) # prob.solve(solver="SCS", eps=1e-14) # betastar = np.array(beta.value).flatten() # fstar = prob.value baseline_out = newton_admm(data, data['dims'], maxiters=100, res_tol=1e-14, verbose=10) betastar = beta_from_x(baseline_out['x']) fstar = baseline_out['info']['fstar'] newton_out = newton_admm(data, data['dims'], benchmark=(beta_from_x, betastar), maxiters=100, ridge=1e-4, verbose=1) scs_out = newton_admm(data, data['dims'], benchmark=(beta_from_x, betastar), admm_maxiters=2000, maxiters=0, verbose=100) plotter(newton_out, scs_out, fstar, name, xmax=100, ymin=1e-12, ymax=1e2)
def __init__(self): self.data = data_obj.init() self.plot = plot.plotter(self.data)