def main(): GPIO.setmode(GPIO.BCM) #GPIO.setwarnings(False) GPIO.setup(sensors.SOIL_PWR, GPIO.OUT) GPIO.output(sensors.SOIL_PWR, GPIO.LOW) GPIO.setup(sensors.MOTOR_PWM, GPIO.OUT) GPIO.output(sensors.MOTOR_PWM, GPIO.LOW) #p = GPIO.PWM(sensors.MOTOR_PWM, 1) #p.start(0) GPIO.setup(BTN_PWR, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.add_event_detect(BTN_PWR, GPIO.FALLING, callback=btnMode, bouncetime=200) GPIO.setup(BTN_WATER, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.add_event_detect(BTN_WATER, GPIO.FALLING, callback=manualWater, bouncetime=200) worker = WorkerThread(None) worker.setName("Worker") worker.start() plotter.plotter(lock) worker.join() plotter.endPlotter() #p.stop() GPIO.cleanup() return
def create_thresholds(): df_manhattan = data_loader() print(df_manhattan.columns) df_total_avg = df_manhattan[[ 'dropoff_latitude', 'dropoff_longitude', 'passenger_count' ]].groupby(['dropoff_longitude', 'dropoff_latitude'], as_index=False).sum() df_total_avg['passenger_count'] /= 90 df_total_avg.to_csv('threshold_overall.csv', index=False) df_day_avg = df_manhattan[[ 'dropoff_latitude', 'dropoff_longitude', 'passenger_count', 'week_day' ]].groupby(['dropoff_longitude', 'dropoff_latitude', 'week_day'], as_index=False).sum() df_day_avg['passenger_count'] /= 12 df_day_avg.to_csv('threshold_day_avg.csv', index=False) choice = input('Do you want to create plots.Enter y/n ') if choice == 'y': lat, lon = [ round(float(i), 3) for i in (input( 'Enter latitude,longitude (separate by comma or enter 0,0 for Goldmna Sachs) ' )).split(',') ] if lat == 0 and lon == 0: plotter(df_manhattan) else: plotter(df_manhattan, lat, lon) files.download('threshold_day_avg.csv') files.download('threshold_overall.csv') print('Data Load Succesfull') return ('Data Load successful')
def task_1(): #initialize the model paramters batch_size = 16 units = 40 drop_rate = 0.2 LR = 0.001 epochs = 100 input_dimension = 1 #load the training and test data X_train, y_train, X_val, y_val = data_loader() #generate the model and compile it model = model_LSTM(drop_rate, units, X_train.shape[1]) model.compile(loss='mean_squared_error', optimizer=Adam(lr=LR), metrics=['mean_absolute_error']) #train the model History = model.fit(X_train, y_train, epochs=epochs, batch_size=batch_size, validation_data=(X_val, y_val), verbose=2) #predict the prices predicted_stock_price = model.predict(X_val) #plot the loss, mae curve and stock_price curve plotter(History, '1', predicted_stock_price)
def plot_resid_vs_matmuls(): inverters = ["GMRES", "FGMRES"] #matrices = ["laplace", "laplace_2"] # Sizes for each matrix type #matrices = dict() #matrices['cz'] = [148, 308, 628, 1268, 2548, 5108] matrices = dict() matrices['cz'] = 148 # Solver object - can be used for any matrix sol_params = dict() sol = Solver(sol_params) for mat_label in matrices: # Construct the matrix mat_params = dict() mat_params['fromSuiteSparse'] = True mat_params['whichMatrix'] = mat_label mat_size = matrices[mat_label] mat_params['dims'] = [mat_size,mat_size] M = Matrix(mat_params) # Build a rhs for this matrix matDims = M.getDims() b = np.ones(matDims[0]) for inv in inverters: x,residuals,it_count,nr_matvec_muls = sol.solve(inv, M, b) filename = 'test002_' + inv + '_' + mat_label + '_' + str(mat_size) + '.png' plotter(residuals, nr_matvec_muls, "nr mat vec multipls", "residual", filename)
def post(self): print "got request to compare files" # get arguments files_to_compare = self.get_argument('files', default=None) num_selects = self.get_argument('num_selects', default=0) if not files_to_compare: data = json.dumps({'html': '<div> no files selected</div>'}) self.write(data) return files_to_compare = [i.strip() for i in files_to_compare.split(',')] files_to_compare = [i for i in files_to_compare if i != ''] documents = [] for _file in files_to_compare: files_with_prefix = glob.glob('uploads/%s' % _file) if not files_with_prefix: documents.append(file_not_found(_file)) continue if not renderable_as_graph(_file): documents.append(file_not_supported(_file)) continue documents.append(file_supported(_file)) # generate images for them for document in documents: if not document['compatiable']: document['image_link'] = '/images/not_found.jpg' continue images = map(os.path.basename, glob.glob('images/*.png')) images = [i[:-4] for i in images] name, ext = os.path.splitext(document['name']) if name not in images: # plotting it plotter.plotter('uploads/%s' % document['name'], 'images/%s' % (name + '.png')) document['image_link'] = '/images/%s' % (name + '.png') operations = AVAILABLE_TRANSFORMATIONS col_width = 90.0 / len(documents) html = self.loader.load('compare.html').generate( documents=documents, operations=operations, col_width=col_width, num_selects=num_selects) data = json.dumps({'html': html}) self.write(data)
def conclude(self) : for configId, tag in enumerate(self.sideBySideAnalysisTags()) : org=organizer.organizer( self.sampleSpecs(tag) ) org.mergeSamples(targetSpec = {"name":"g_jets_mg", "color":r.kGreen}, sources = ["g_jets_mg_pt%s"%bin for bin in ["40_100","100_200","200"] ]) org.scale(10) pl = plotter.plotter(org, psFileName = self.psFileName(tag)) pl.plotAll() def drawCut(hist,cut) : line = r.TLine(cut,0,cut,hist.GetMaximum()) line.SetLineColor(r.kBlue) line.SetLineStyle(r.kDashed) r.SetOwnership( line, False ) line.Draw("same") def drawOne() : one = r.TF1("one","1",0,5) one.SetLineColor(r.kRed) one.SetLineStyle(r.kDashed) one.SetLineWidth(1) r.SetOwnership(one,False) one.Draw("same") import utils r.gStyle.SetOptStat(0) c = r.TCanvas("c","",800,1000) outDir = self.outputDirectory(configId)+"/" for s in org.samples : c.Print(outDir+s["name"]+".ps[") iSelection = -4 for key in sorted(org.selections[iSelection]): if key == "counts" : continue for hist,sample in zip(org.selections[iSelection][key],org.samples) : if not hist : continue ctr = hist.ProjectionX(hist.GetName()+"_ctr",0,2) fwd = hist.ProjectionX(hist.GetName()+"_fwd",3) if min(ctr.GetEntries(),fwd.GetEntries()) < 10: continue leg = r.TLegend(0.52,0.7,0.9,0.9); ctr.Scale(1/ctr.Integral()); ctr.SetLineColor(r.kBlack); ctr.SetMarkerColor(r.kBlack); leg.AddEntry(ctr,"Central","lp") fwd.Scale(1/fwd.Integral()); fwd.SetLineColor(r.kRed); fwd.SetMarkerColor(r.kRed); leg.AddEntry(fwd,"Forward","lp") ratio = utils.ratioHistogram(fwd,ctr) m = 2*max(fwd.GetMaximum(),ctr.GetMaximum()) fwd.SetMaximum(m) ctr.SetMaximum(m) ratio.SetMinimum(0); ratio.SetMaximum(2) ratio.SetTitle("fwd/ctr") c.Clear(); c.Divide(1,2); c.cd(1).SetLogy(); ctr.Draw(); fwd.Draw("same"); drawCut(ctr,0.55); leg.Draw() c.cd(2); ratio.Draw(); drawOne(); drawCut(ratio,0.55) c.Print(outDir+sample["name"]+".ps") for s in org.samples : fileName = outDir+s["name"]+".ps]" c.Print(fileName) fileNamePDF = fileName.replace(".ps]",".pdf") os.system("ps2pdf "+fileName[:-1] + " " + fileNamePDF) print fileNamePDF, "has been printed."
def __init__(self, set_point, dt = 0.1, Teval = 1., simulation = True): self.position = np.zeros(3) self.vel_v = np.zeros(3) self.vel_w = np.zeros(3) self.velocity = np.zeros(2) self.euler = np.zeros(3) self.Quater = np.zeros(4) self.dt = dt self.Teval = Teval self.error = np.zeros((3,2)) self.u0 = np.zeros(2) self.u = np.zeros(2) self.set_point = set_point self.node = rospy.init_node('DQPID', anonymous=False) if simulation: self.Publisher = rospy.Publisher("/sim_p3at/cmd_vel", Twist, queue_size=1) self.Subscriber = rospy.Subscriber("/sim_p3at/odom", Odometry, self.callback_pose, queue_size=1) else: self.Publisher = rospy.Publisher("/RosAria/cmd_vel", Twist, queue_size=1) self.Subscriber = rospy.Subscriber("/RosAria/pose", Odometry, self.callback_pose, queue_size=1) self.rate = rospy.Rate(10.) # 10hz self.msg = Twist() self.action_vx = np.zeros(2) self.action_wz = np.zeros(2) self.reward = -1. self.execution = np.divide(self.Teval,self.dt).astype(int) self.temporal_vx = np.zeros(self.execution) self.temporal_wz = np.zeros(self.execution) # to plot self.plotter = plotter('Velocities', 'u', 'positions', 'action_vx' , 'action_wz') self.time = 0.
def __init__( self, action_space, discount_factor=.99, # gamma ): self.rpm = rpm(100000) # 10k history self.plotter = plotter(num_lines=2) self.render = True self.training = True num_of_actions = 8 self.outputdims = num_of_actions self.discount_factor = discount_factor ids, ods = None, num_of_actions self.actor = self.create_actor_network(ids, ods) self.critic = self.create_critic_network(ids, ods) self.actor_target = self.create_actor_network(ids, ods) self.critic_target = self.create_critic_network(ids, ods) self.feed, self.joint_inference, sync_target = self.train_step_gen() sess = ct.get_session() sess.run(tf.global_variables_initializer()) sync_target()
def __init__(self,filename,id,display=False): # if filename[-6:] == "1.root": if display: self.plotter = plotter.plotter(id) self.plotter.start() logger.info("Plotter Created") self.outputfile = ROOT.TFile(filename,'create') self.tree = ROOT.TTree("gridpix","gridpix") self.time = numpy.zeros(1,dtype=numpy.uint32) self.hits = numpy.zeros(1,dtype=numpy.uint32) self.x=numpy.zeros(512*256,dtype=numpy.uint16) self.y=numpy.zeros(512*256,dtype=numpy.uint16) self.z=numpy.zeros(512*256,dtype=numpy.uint16) self.tree.Branch('hits',self.hits,'hits/i') self.tree.Branch('x',self.x,'x[hits]/s') self.tree.Branch('y',self.y,'y[hits]/s') self.tree.Branch('z',self.z,'z[hits]/s') self.tree.Branch('time',self.time,'time/i') self.lock = Lock() self.writeList = [] self.counter = 0 self.thread = Thread(target=self.threadLoop) self.thread_active=True logger.info("writing data to: " + filename) self.thread.start()
def main(*args): #buildingreader = Jsonreader("Conso_appartements.csv") apartmentreader = Csvreader("Conso_appartements.csv") apartmentdict = apartmentreader.dictOfAllApartments() print apartmentdict xpoints = [] ypoints = [] for a in apartmentdict: ap = apartmentdict[a] buildingnumber = ap["building"] buildingdict = Jsonreader(buildingnumber).GetBuildingDict() print buildingdict aptype = "secondaire" if ap["type"] == aptype: continue #xpoints.append(ap["rooms"]) xpoints.append(buildingdict["Annee"]) ypoints.append(ap["conso_2017"]) plotting = plotter() plotting.scatterplot_onevariable(xpoints, ypoints, aptype) # plotWithGroups(plotting, apartmentdict, "rooms", "conso_2017", "EfficaciteGlobale", True, ["type", "principale"]) plotWithGroups(plotting, apartmentdict, "rooms", "conso_2017", "building", False, ["type", "principale"]) plotWithGroups(plotting, apartmentdict, "rooms", "conso_2017", "Annee", True, ["type", "principale"])
def conservation_of_energy_df(self, timesteps, approximations, densities): ''' return a dataframe showing the difference between the minimum and maximum of total energy for each system configuration used to compare system configurations ''' first_column = True #changes to false after first column has been made for timestep in timesteps: for approximation in approximations: for density in densities: #for every possible simulation permutation calculating = calculator(timestep=timestep, iterations=self.iterations) #initialise the calculator for current permutation and get all the required balls calculating.get_balls(number = self.number, positions = self.start_positions, velocities= self.start_velocities, radii = self.radii, masses= self.masses, anchors= self.anchors) calculating.time_to_run(approximation, density) #run the calculator class plot_class_call = plotter('system_states_over_time.npy', self.number) #initialise the plot class to the energy list can be read energy_list = plot_class_call.total_energy() #use the plotter class function to get the energy list ''' from the energy list, find the minimum, maximum, and variation of the energy''' energy_min= min(energy_list) energy_max= max(energy_list) energy_diff= energy_max - energy_min energy_start = energy_list[0] energy_variation_as_fraction = energy_diff/energy_start energy_variation_as_percentage = energy_variation_as_fraction * 100 if first_column: #initialise the dataframe conservation_df = pd.DataFrame(data=[timestep, approximation, density, energy_diff, energy_variation_as_percentage], columns=['timstep','approximation', 'density', 'difference in minimum and maximum energy', 'energy difference as a oercentage of initial energy']) first_column = False continue '''generate new row of dataframe and append it to the previously initialised df''' conservation_df_new_row = pd.DataFrame(data=[timestep, approximation, density, energy_diff, energy_variation_as_percentage], columns=['timstep','approximation', 'density', 'difference in minimum and maximum energy', 'energy difference as a oercentage of initial energy']) conservation_df.append(conservation_df_new_row, ignore_index = True) conservation_df.to_csv('conservation.csv') #save to disk as a csv
def __init__(self, filename, id, display=False): # if filename[-6:] == "1.root": if display: self.plotter = plotter.plotter(id) self.plotter.start() logger.info("Plotter Created") self.outputfile = ROOT.TFile(filename, 'create') self.tree = ROOT.TTree("gridpix", "gridpix") self.time = numpy.zeros(1, dtype=numpy.uint32) self.hits = numpy.zeros(1, dtype=numpy.uint32) self.x = numpy.zeros(512 * 256, dtype=numpy.uint16) self.y = numpy.zeros(512 * 256, dtype=numpy.uint16) self.z = numpy.zeros(512 * 256, dtype=numpy.uint16) self.tree.Branch('hits', self.hits, 'hits/i') self.tree.Branch('x', self.x, 'x[hits]/s') self.tree.Branch('y', self.y, 'y[hits]/s') self.tree.Branch('z', self.z, 'z[hits]/s') self.tree.Branch('time', self.time, 'time/i') self.lock = Lock() self.writeList = [] self.counter = 0 self.thread = Thread(target=self.threadLoop) self.thread_active = True logger.info("writing data to: " + filename) self.thread.start()
def plot_log(self, symbol, engine='plotly', notebook=False): data = plotter(latest_bar_dict=self.Feed.latest_bar_dict, enquity_curve=self.get_equity_curve(), tlog=self.get_log(), positions=self.get_all_positions(), holdings=self.get_all_holdings()) data.plot_log(symbol=symbol, engine=engine, notebook=notebook)
def simulate_test(is_rabin, is_fixed_pattern, filename): data_dict = readfile(filename) p = plotter() tracemalloc.start() for data in data_dict: t1_start = process_time() text = data["text"] pattern = data["pattern"] p.add_pattern(pattern) p.add_txt(text) print("Text size {}, Pattern size {}".format(len(text), len(pattern))) if (is_rabin): rabin_karp(pattern, text) else: kmp_pattern_match(pattern, text) current, peak = tracemalloc.get_traced_memory() p.add_usage(current / 10**6) print( f"Current memory usage is {current / 10**6}MB; Peak was {peak / 10**6}MB" ) t1_stop = process_time() time = t1_stop - t1_start print(f"Time taken to complete {time}ms") p.add_time(time) tracemalloc.stop() if is_fixed_pattern: p.plot_txt_time() p.plot_txt_size() else: p.plot_pat_time() p.plot_pat_size()
def get_results(self, runs): """get plots and results for a list of runs""" plots = [ "TrackPos", "FidCut", "PulseHeight", "Noise", "PulseHeight_BiggestSignalSNRDia", "PulseHeight_BiggestAdjacentSNRDia", "PulseHeight_ClusterSize", "ClusterSize", ] results = {} for run in runs: results[run["number"]] = {} for plot in plots: pl = plotter( self.config_file, self.path, self.output_path, run["number"], run["position"], plot, self.run_config_file, ) results[run["number"]][plot] = pl.plot() results[run["number"]]["Voltage"] = self.runlog.get_voltage(run["number"]) tables.make_NoisePulseHeightTable(self.output_path, results, self.suffix)
def conclude(self) : for tag in self.sideBySideAnalysisTags() : org=organizer.organizer( self.sampleSpecs(tag) ) pl = plotter.plotter(org, psFileName = self.psFileName(tag), blackList = ["lumiHisto","xsHisto","nJobsHisto"] ) pl.plotAll()
def conclude(self) : for tag in self.sideBySideAnalysisTags() : #organize org=organizer.organizer( self.sampleSpecs(tag) ) org.mergeSamples(targetSpec = {"name":"g_jets_mg", "color":r.kGreen}, sources = ["g_jets_mg_pt%s"%bin for bin in ["40_100","100_200","200"] ]) #org.mergeSamples(targetSpec = {"name":"qcd_py" , "color":r.kBlue}, sources = ["qcd_py_pt%d"%i for i in [30,80,170,300,470,800,1400] ]) #org.mergeSamples(targetSpec = {"name":"standard_model","color":r.kGreen+3}, # sources = ["g_jets_mg","qcd_py","tt_tauola_mg","z_inv_mg_skim","z_jets_mg_skim","w_jets_mg_skim"], keepSources = True # ) org.scale(100) #plot pl = plotter.plotter(org, psFileName = self.psFileName(tag), samplesForRatios=("JetMET_skim","standard_model"), sampleLabelsForRatios=("ctr","fwd"), ) pl.plotAll() import utils c = r.TCanvas("c","",800,1000) for key in org.selections[-1]: if key == "counts" : continue for hist,sample in zip(org.selections[-1][key],org.samples) : if not hist : continue c.Clear() c.Divide(1,2) c.cd(1).SetLogy() div = 1 if "z" in key else 2 ctr = hist.ProjectionX(hist.GetName()+"_ctr",0,div) fwd = hist.ProjectionX(hist.GetName()+"_fwd",div+1) if max(ctr.GetEntries(),fwd.GetEntries()) < 10: continue ctr.Scale(1/ctr.Integral()) fwd.Scale(1/fwd.Integral()) ctr.SetLineColor(r.kBlack); ctr.SetMarkerColor(r.kBlack) fwd.SetLineColor(r.kRed); fwd.SetMarkerColor(r.kRed) leg = r.TLegend(0.52,0.7,0.9,0.9); leg.AddEntry(ctr,"Central","lp") leg.AddEntry(fwd,"Forward","lp") m = 2*max(fwd.GetMaximum(),ctr.GetMaximum()) fwd.SetMaximum(m) ctr.SetMaximum(m) ctr.Draw("") fwd.Draw("same") leg.Draw() c.cd(2) ratio = utils.ratioHistogram(fwd,ctr) ratio.SetMaximum(2) one = r.TF1("one","1",0,5) one.SetLineColor(r.kRed) one.SetLineStyle(r.kDashed) one.SetLineWidth(1) ratio.Draw() one.Draw("same") c.Print(sample["name"]+'_'+key+"normSlice.eps")
def conclude(self) : org=organizer.organizer( self.sampleSpecs() ) org.mergeSamples(targetSpec = {"name":"qcd_py6","color":r.kBlue}, sources = ["qcd_py6_pt%d"%i for i in [15,30,80] ]) org.scale(100.0) pl = plotter.plotter(org, psFileName = self.psFileName(""), ) pl.plotAll()
def __init__( self, ob_space, ac_space, horizon=2048, gamma=0.99, lam=0.95, train_epochs=10, batch_size=64, buffer_length=10, policy=None ): if policy is None: print('no policy designated, use default Policy') policy = Policy self.current_policy = policy(ob_space, ac_space) self.old_policy = policy(ob_space, ac_space) self.current_policy.actor.summary() self.current_policy.critic.summary() self.gamma, self.lam, self.horizon = gamma, lam, horizon self.train_epochs, self.batch_size = train_epochs, batch_size self.traj_buffer = traj_buffer(buffer_length) self.act, self.predict_value, self.train_for_one_step, self.assign_old_eq_new = self.build_functions() low, high = ac_space.low, ac_space.high self.action_bias = (high + low)/2. self.action_multiplier = high - self.action_bias # limit action into the range specified by environment. def action_limiter(action): # assume input mean 0 std 1 return np.tanh(action) * self.action_multiplier + self.action_bias def action_limiter(action): # assume input uniform [0,1] return (action * 2 - 1) * self.action_multiplier + self.action_bias self.action_limiter = action_limiter # logging of episodic reward. from plotter import interprocess_plotter as plotter self.plotter = plotter(2) # logging of actions. comment out if you don't have opencv if not hasattr(self,'wavegraph'): from winfrey import wavegraph # num_waves = self.outputdims*2+1 num_waves = self.current_policy.ac_dims*2+1 def rn(): r = np.random.uniform() return 0.3+r*0.4 colors = [] for i in range(num_waves-1): color = [rn(),rn(),rn()] colors.append(color) colors.append([0.2,0.5,0.9]) self.wavegraph = wavegraph(num_waves,'ac_mean/ac_sto/vf',np.array(colors)) def loggraph(waves): wg = self.wavegraph wg.one(waves.reshape((-1,))) self.loggraph = loggraph
def conclude(self) : for tag in self.sideBySideAnalysisTags() : #organize org=organizer.organizer( self.sampleSpecs(tag) ) org.mergeSamples(targetSpec = {"name":"g_jets_mg", "color":r.kGreen}, sources = ["g_jets_mg_pt%s"%bin for bin in ["40_100","100_200","200"] ]) smSources = ["g_jets_mg","tt_tauola_mg","z_inv_mg_skim","z_jets_mg_skim","w_jets_mg_skim"] if "pythia6" in tag : org.mergeSamples(targetSpec = {"name":"qcd_py6", "color":r.kBlue}, sources = ["qcd_py6_pt%d"%i for i in [80,170,300] ]) smSources.append("qcd_py6") if "pythia8" in tag : lowerPtList = [0,15,20,30,50,80, 120,170,230,300,380,470,600,800, 1000,1400,1800,2200,2600,3000,3500] org.mergeSamples(targetSpec = {"name":"qcd_py8","color":r.kBlue}, sources = ["qcd_py8_pt%dto%d"%(lowerPtList[i],lowerPtList[i+1]) for i in range(len(lowerPtList)-1)] ) smSources.append("qcd_py8") if "madgraph" in tag : org.mergeSamples(targetSpec = {"name":"qcd_mg", "color":r.kBlue}, sources = ["qcd_mg_ht_%s"%bin for bin in ["50_100","100_250","250_500","500_1000","1000_inf"] ]) smSources.append("qcd_mg") org.mergeSamples(targetSpec = {"name":"standard_model","color":r.kGreen+3}, sources = smSources, keepSources = True) org.scale() def makeRate(hist,total,name) : if (not hist) or (not total): return 0 hist.Scale(1./total) hist.SetMaximum(0.91) hist.GetXaxis().SetTitle("") if hist.GetYaxis().GetNbins()>1: hist.GetYaxis().SetTitle("") hist.GetZaxis().SetTitle("rate") else: hist.GetYaxis().SetTitle("rate") hist.SetTitle(name) return 1 for iSel,selection in enumerate(org.selections) : if len(selection)>1 : totals = tuple(map(lambda h: h.GetBinContent(2) if h else 0, selection["counts"])) totals2 = tuple(map(lambda h: h.GetBinContent(1)+h.GetBinContent(2) if h else 0, org.selections[iSel+1]["counts"])) if \ iSel+1<len(org.selections) else [0]*len(totals) totals = map(max,totals,totals2) for name in selection: if "VetoCounts" in name : result = map(makeRate, selection[name],totals, [name]*len(totals)) pl = plotter.plotter(org, psFileName = self.psFileName(tag), samplesForRatios=("JetMET_skim","standard_model"), sampleLabelsForRatios=("data","s.m."), #compactOutput=True ) pl.plotAll()
def two_ball_init(): ''' some of the results rely on the tota energy of the system, and therefore this is to check that these things are caluclated correctly with a more complicated system ''' theta = math.pi/6 #initial starting angle! get_results = calculator(0.0001,50000) get_results.get_balls(number = 2,positions= [[1 * math.sin(theta), -1 * math.cos(theta)], [0,-0.4]], velocities= [[0,0], [0,0]], radii=[0.02,0.02], masses=[1,1], anchors= [[0,0], [0.4]]) get_results.calculate(approximation='rk2', density=0) plot = plotter('system_states_over_time', 2) return plot
def plotter_init(): theta = math.pi/6 #initial starting angle! get_results = calculator(0.0001,50000) get_results.get_balls(number = 1,positions= [[1 * math.sin(theta), -1 * math.cos(theta)]], velocities= [[0,0]], radii=[0.02], masses=[1], anchors= [[0,0]]) get_results.calculate(approximation='rk2', density=0) plot = plotter('system_states_over_time', 1) ke_by_time = plot.total_kinetic_energy() pe_by_time = plot.total_potential_energy() total_e_by_time = plot.total_energy() return [ke_by_time, pe_by_time, total_e_by_time]
def runAllModels(X_train,X_test,y_test,y_train): y_pred= xgb(X_train,y_train,X_test) plotter(y_test,y_pred) cm,fscore,a=evaluate(y_test,y_pred) y_pred = rf(X_train,y_train,X_test) plotter(y_test,y_pred) cm,fscore,a=evaluate(y_test,y_pred) y_pred = nn(X_train,y_train,X_test) plotter(y_test,y_pred) cm,fscore,a=evaluate(y_test,y_pred) y_pred = svm(X_train,y_train,X_test) plotter(y_test,y_pred) cm,fscore,a=evaluate(y_test,y_pred)
def plot_itercount_vs_matsize(): inverters = ["GMRES", "FGMRES"] #matrices = ["laplace", "laplace_2"] # Sizes for each matrix type matrices = dict() matrices['cz'] = [148, 308, 628, 1268, 2548, 5108] # Solver object - can be used for any matrix sol_params = dict() sol = Solver(sol_params) for inv in inverters: for mat_label in matrices: it_counts = list() matsizes = list() for mat_size in matrices[mat_label]: # Construct the matrix mat_params = dict() mat_params['fromSuiteSparse'] = True mat_params['whichMatrix'] = mat_label mat_params['dims'] = [mat_size, mat_size] M = Matrix(mat_params) # Build a rhs for this matrix #b = np. matDims = M.getDims() b = np.ones(matDims[0]) x, residuals, it_count, nr_matvec_muls = sol.solve(inv, M, b) it_counts.append(it_count) matsizes.append(mat_size) filename = 'test001_' + inv + '_' + mat_label + '.png' plotter(it_counts, matsizes, "matrix size", "iteration count", filename)
def main(argv): client = Client("", "") strategy = sMACD() #get data from binnace data = client.get_historical_klines(symbol='BTCUSDT', interval='1h', start_str='2017.08.17', end_str='2018.08.27') #format data_df = pd.DataFrame(data, columns=[ 'Open time', 'Open', 'High', 'Low', 'Close', 'Volume', 'Close time', 'Quote asset volume', 'Number of trades', 'Taker buy base asset volume', 'Taker buy quote asset volume', 'Ignore' ]) #init variables this = 0 bestX = 0 bestY = 0 bestZ = 0 bestReturn = 0 #start trying all combos for x in xrange(1, 40): for y in xrange(1, 40): for z in xrange(1, 60): print "running......" + str(x) + " " + str(y) + " " + str(z) #run the series this = strategy.run(x, y, z, data_df) #update new best performance if this > bestReturn: bestX = x bestY = y bestZ = z bestReturn = this print "new Best: " + str(bestReturn) #run plotting plt = plotter() plt.plot(bestX, bestY, bestZ, data_df) #at the end print best result print "best return: " + str(bestReturn) print "best x: " + str(bestX) print "best y: " + str(bestY) print "best z: " + str(bestZ)
def get_results(self, runs) : '''get plots and results for a list of runs''' plots = ['FidCut', 'PulseHeight', 'Noise'] results = {} for run in runs : results[run['number']] = {} for plot in plots : pl = plotter(self.config_file, self.path, self.output_path, run['number'], run['position'], plot) results[run['number']][plot] = pl.plot() results[run['number']]['Voltage'] = self.runlog.get_voltage(run['number']) tables.make_NoisePulseHeightTable(self.output_path, results)
def fancy_output(): features = ['actor1code', 'actor1countrycode', 'actor1knowngroupcode', 'actor1ethniccode', 'actor1religion1code', 'actor1religion2code', 'actor1type1code', 'actor1type2code', 'actor1type3code', 'actor2code', 'actor2countrycode', 'actor2knowngroupcode', 'actor2ethniccode', 'actor2religion1code', 'actor2religion2code', 'actor2type1code', 'actor2type2code', 'actor2type3code', 'isrootevent', 'eventcode', 'eventbasecode', 'eventrootcode', 'actor1geo_countrycode', 'actor2geo_countrycode', 'actiongeo_countrycode'] #new = {} #new['[0-9]type'] = print request.args formatted = format_input(db, request.args.get('name').upper(),features) if formatted is None: return render_template('index.html', error="No results found for {}, try searching something else".format(request.args.get('name'))) newRows,df_m = formatted preds = [] targs = [] targs_c = [] for f in files: print f targ = f.split('/')[-1].split('_')[0] targs.append(targetsTrans[targ]) targs_c.append(targetsCol[targ]) with open(f, 'rb') as infile: target_m = cPickle.load(infile) preds.append(np.mean(target_m.predict_proba(newRows)[:,1])) #Create ranking list ranks = sorted(zip(preds,targs,targs_c),reverse=True) img = StringIO.StringIO() #vplot = plt.figure(tight_layout=True) plots = plotter(df_m,request.args.get('name')) plots.savefig(img, format='png', transparent=True) img.seek(0) plot_url = base64.b64encode(img.getvalue()) #img = StringIO.StringIO() #tplot = plt.figure(tight_layout=True) #tplot = toneplot(df_m, request.args.get('name')) #tplot.figure.savefig(img, format='png', transparent=True) #img.seek(0) #tplot_url = base64.b64encode(img.getvalue()) return render_template('output.html', plot_url=plot_url, name=request.args.get('name'), ranks = ranks)
def conclude(self) : for tag in self.sideBySideAnalysisTags() : #organize org=organizer.organizer( self.sampleSpecs(tag) ) self.mergeSamples(org, tag) org.scale() pl = plotter.plotter(org, psFileName = self.psFileName(tag), samplesForRatios=("2010 Data","standard_model"), sampleLabelsForRatios=("data","s.m."), ) pl.plotAll()
def main(): otp_data = pd.read_csv('data.csv') indicators = [ ind.macd(otp_data), ] plotter = plt.plotter(otp_data) for i in indicators: plotter.add_plot(i) plotter.plot()
def conclude(self,pars) : import plotter org = self.organizer(pars) org.scale(toPdf=True) pl = plotter.plotter(org, psFileName = self.psFileName(org.tag), doLog = False, #noSci = True, #pegMinimum = 0.1, detailedCalculables = True, blackList = ["lumiHisto","xsHisto","nJobsHisto"], ).plotAll()
def post(self): documents = self.get_argument('documents', None) transformation = self.get_argument('transformation', None) num_selects = self.get_argument('num_selects', None) if not documents: self.finish(json.dumps({"error": "missing docs"})) return recieved_documents = json.loads(documents) if transformation not in AVAILABLE_TRANSFORMATIONS: self.finish(json.dumps({"error": "unknown transformation"})) return transform = getattr(transformations, transformation) documents = [] for document in recieved_documents: doc = glob.glob('uploads/%s' % document['name']) if not doc: documents.append(file_not_found(document['name'])) continue if not renderable_as_graph(document['name']): documents.append(file_not_supported(document['name'])) continue filename = document['name'] transformed_name = transform('uploads/%s' % filename) image_name, ext = os.path.splitext(os.path.basename(transformed_name)) plotter.plotter(transformed_name, 'images/%s.png' % image_name) data = {'name': os.path.basename(transformed_name), 'image_link': 'images/%s.png' % image_name, 'compatiable': True} documents.append(data) data = self.loader.load('transformed_rows.html').generate(documents=documents, operations=AVAILABLE_TRANSFORMATIONS, num_selects=num_selects) data = json.dumps({'html': data}) self.finish(data)
def conclude(self) : for tag in self.sideBySideAnalysisTags() : org=organizer.organizer( self.sampleSpecs(tag) ) org.mergeSamples(targetSpec = {"name":"qcd_py8", "color":r.kBlue}, allWithPrefix="qcd_py8") org.mergeSamples(targetSpec = {"name":"2010 Data", "color":r.kBlack, "markerStyle":20}, allWithPrefix="Run2010") org.scale() pl = plotter.plotter(org, psFileName = self.psFileName(tag), samplesForRatios=("2010 Data","qcd_py8"), sampleLabelsForRatios=("data","qcd"), ) pl.plotAll()
def __init__(self, set_point, dt=0.1, Teval=1., simulation=True): self.position_ned = np.zeros(3) self.position = np.zeros(3) self.vel_v_ned = np.zeros(3) self.vel_w_ned = np.zeros(3) self.velocity = np.zeros(2) self.euler = np.zeros(3) self.Quater = np.zeros(4) self.dt = dt self.Teval = Teval self.error = np.zeros((3, 2)) self.u0 = np.zeros(2) self.u = np.zeros(2) self.set_point = set_point self.node = rospy.init_node('DQPID', anonymous=False) if simulation: self.Publisher = rospy.Publisher("/cmd_vel", Twist, queue_size=1) self.Subscriber = rospy.Subscriber("/ground_truth/state", Odometry, self.callback_pose, queue_size=1) else: self.Publisher = rospy.Publisher("/cmd_vel", Twist, queue_size=1) self.Subscriber = rospy.Subscriber("/ground_truth/state", Odometry, self.callback_pose, queue_size=1) self.rate = rospy.Rate(10.) # 10hz self.msg = Twist() self.action_vx = np.zeros(2) self.action_wz = np.zeros(2) self.reward = -1. self.execution = np.divide(self.Teval, self.dt).astype(int) self.temporal_vx = np.zeros(self.execution) self.temporal_wz = np.zeros(self.execution) # to plot self.plotter = plotter('Velocities', 'u', 'positions', 'action_vx', 'action_wz') self.time = 0. # transformations self.body_velocities = np.zeros(6) self.tot_vel_ned = np.zeros(6) # since the drone starts up from the floor I will make it go up a bit # I could change the launch file but then I have to change it for # everyone that uses this. self.start_up(10)
def get_plots(self): ''' generates plots for all of the possible configurations in the config file using the plotter and calculator class two plots are generated for each configuration, one of the individual ball paths and one of the potential, kinetic, and total energy of the system [not individual balls] plots are saved using the following naming convention: energy plots: energy_plot_timestep_{}_approximation_{}_density_{} path plots: energy_plot_timestep_{}_approximation_{}_density_{} where {} contains the system configuration for that variable. ''' timesteps = self.system[ 'timesteps'] #extract the list of timestep configs approximations = self.system[ 'approximations'] #extract the list of approximation congifs densities = self.system[ 'densities'] #extract the list of density configs '''loop of each of the individual aspect lists in order to iterate over every possible config ''' for timestep in timesteps: for approximation in approximations: for density in densities: calculating = calculator( timestep=timestep, iterations=self.initialisation['iterations'] ) #initialise the calculator class using the selected timestep calculating.get_balls( self.initialisation['number'], self.initialisation['StartPositions'], self.initialisation['StartVelocities'], self.initialisation['radii'], self.initialisation['masses'], self.initialisation['anchors'] ) #set up the calculator with the correct conditions defined by the initialisation config calculating.calculate( approximation, density ) #calculate the movement using the current approximation and density plots = plotter( 'system_states_over_time', self.number ) #read in the calculated data so that it can be plotted plots.plot_x_vs_y( [timestep, approximation, density], show=False ) #ploy the paths of the balls, just save the plot instead of showing it plots.energy_plot( [timestep, approximation, density], show=False, kinetic=True, total=True, potential=True ) #plot the energy of the balls, just save the plot instead of showing it
def conclude(self,pars) : org = self.organizer(pars) #plot pl = plotter.plotter(org, psFileName = self.psFileName(org.tag), #samplesForRatios = ("2010 Data","standard_model"), #sampleLabelsForRatios = ("data","s.m."), #whiteList = ["lowestUnPrescaledTrigger"], doLog = False, #compactOutput = True, #noSci = True, #pegMinimum = 0.1, blackList = ["lumiHisto","xsHisto","nJobsHisto"], ) pl.plotAll()
def conclude(self,pars) : org = self.organizer(pars) org.scale(toPdf=True) self.signalChi2(org,("tt_tauola_fj_mg.wTopAsymN30","tt_tauola_fj_mg.wTopAsymP30"), org.keysMatching(["genTopBeta", "genTopDeltaAbsYttbar", "genTopTrue", "genTopMez" ])) pl = plotter.plotter(org, psFileName = self.psFileName(org.tag), doLog = False, #compactOutput = True, #noSci = True, pegMinimum = 0.1, blackList = ["lumiHisto","xsHisto","nJobsHisto"], ).plotAll()
def conclude(self) : for tag in self.sideBySideAnalysisTags() : #organize org=organizer.organizer( self.sampleSpecs(tag) ) org.mergeSamples(targetSpec = {"name":"g_jets_mg", "color":r.kGreen}, sources = ["g_jets_mg_pt%s"%bin for bin in ["40_100","100_200","200"] ]) smSources = ["g_jets_mg","tt_tauola_mg","z_inv_mg_skim","z_jets_mg_skim","w_jets_mg_skim"] if "pythia6" in tag : org.mergeSamples(targetSpec = {"name":"qcd_py6", "color":r.kBlue}, sources = ["qcd_py6_pt%d"%i for i in [80,170,300] ]) smSources.append("qcd_py6") if "pythia8" in tag : lowerPtList = [0,15,20,30,50,80, 120,170,230,300,380,470,600,800, 1000,1400,1800,2200,2600,3000,3500] org.mergeSamples(targetSpec = {"name":"qcd_py8","color":r.kBlue}, sources = ["qcd_py8_pt%dto%d"%(lowerPtList[i],lowerPtList[i+1]) for i in range(len(lowerPtList)-1)] ) smSources.append("qcd_py8") if "madgraph" in tag : org.mergeSamples(targetSpec = {"name":"qcd_mg", "color":r.kBlue}, sources = ["qcd_mg_ht_%s"%bin for bin in ["50_100","100_250","250_500","500_1000","1000_inf"] ]) smSources.append("qcd_mg") org.mergeSamples(targetSpec = {"name":"standard_model","color":r.kGreen+3}, sources = smSources, keepSources = True) org.scale() ##other #import deltaPhiLook #numers = ["JetMET_skim","standard_model"] #if "pythia" in tag : qcdLabel = "qcd_py" #if "madgraph" in tag : qcdLabel = "qcd_mg" # #for numer,denom in zip(numers,[qcdLabel]*len(numers)) : # d = deltaPhiLook.deltaPhiLooker(org,tag,(numer,denom)) # d.makeSlicePlots() # if numer==numers[0] : # d.makeSliceComparisonPlots(qcdLabel) #plot pl = plotter.plotter(org, psFileName = self.psFileName(tag), samplesForRatios=("JetMET_skim","standard_model"), sampleLabelsForRatios=("data","s.m."), ) pl.plotAll()
def main(): adxcross = MyStrategy() btest = bt.Backtest(500000.0, OTP_DATA, adxcross) btest.run() indicators = [ ind.cci(OTP_DATA, span=10), ind.cci(OTP_DATA, span=20), ] plotter = plt.plotter(OTP_DATA) for i in indicators: plotter.add_plot(i) plotter.plot()
def plot_results(self, w): from_, to = w.get_interesting() surtitle = [('Population', w.population), ('Infectiousness', w.get_infectiousness()), ('Auto-Immunity', w.get_auto_immunity()), ('Max Days to Double', f'{w.days_to_double:.1f}')] plotfile = f'{self.log_path}{self.log_filename}' if self.log_path else None p = plotter(surtitle=surtitle, file=plotfile, show=self.args.plot, format=self.args.format, props=self.props, legend=False) x = w.get_days()[from_:to] data = [{ 'label': var_to_title(v), 'data': w.get_data(v)[from_:to] } for v in ('total', 'infected')] p.plot([w], ('total', 'infected'))
def test_list_lengths(): ''' lots of lists are created by the plotter class, and the length of them should be known, as it should be the number of iterations in a lot of case ''' ''' as testing class attributes, not results, need to call a new class instance''' theta = math.pi/6 #initial starting angle! get_results = calculator(0.0001,50000) get_results.get_balls(number = 1,positions= [[1 * math.sin(theta), -1 * math.cos(theta)]], velocities= [[0,0]], radii=[0.02], masses=[1], anchors= [[0,0]]) get_results.calculate(approximation='rk2', density=0) plot = plotter('system_states_over_time', 1) assert len(plot.timelist) == 50000 assert len(plot.total_ke_list) == 50000 assert len(plot.total_pe_list) == 50000 assert len(plot.total_energy_by_time) == 50000 assert len(plot.potential_energy_by_time) == 50000 assert len(plot.kinetic_energy_by_time) == 50000 assert len(plot.list_position_by_time) == 50000
def conclude(self) : smSources = ["g_jets_mg","tt_tauola_mg","z_inv_mg_skim","z_jets_mg_skim","w_jets_mg_skim"] for tag in self.sideBySideAnalysisTags() : org = organizer.organizer( self.sampleSpecs(tag) ) org.mergeSamples(targetSpec = {"name":"g_jets_mg", "color":r.kGreen}, allWithPrefix = "g_jets_mg") for color,qcd in zip([r.kRed,r.kBlue,r.kGreen],["qcd_py6", "qcd_py8", "qcd_mg"]) : org.mergeSamples(targetSpec = {"name":qcd, "color":r.kBlue}, allWithPrefix = qcd) if qcd in [sample["name"] for sample in org.samples]: org.mergeSamples(targetSpec = {"name":"sm_w_"+qcd,"color":color}, sources = smSources+[qcd], keepSources = True) org.drop(qcd) for sample in smSources: org.drop(sample) org.scale() pl = plotter.plotter(org, psFileName = self.psFileName(tag), samplesForRatios=("JetMET_skim", filter(lambda name: "sm_w_qcd" in name, [sample["name"] for sample in org.samples])), sampleLabelsForRatios=("data","s.m.") ) pl.plotAll()
def main(argv): strategy = HeikinStrategy() timeframes = ["2h"] bestReturn = 0 currentReturn = 0 StartingCaptal = 1000.0 for time in timeframes: #get Heikin-Ashi candles data_df = getDataAndComputeHeikinAshi(time) #pritn curent timeframe print "running...... " + str(time) #run the series currentReturn = strategy.run(StartingCaptal, data_df) #print result print "return: " + str(currentReturn) #update new best performance if currentReturn > bestReturn: bestReturn = currentReturn bestTime = time print "New Best: " + str(bestReturn) + " " + str(time) #run plotting #get Heikin-Ashi candles of best timeframe data_df = getDataAndComputeHeikinAshi(bestTime) plt = plotter() plt.plot(bestTime, StartingCaptal, data_df)
def conclude(self) : for tag in self.sideBySideAnalysisTags() : ##for skimming only #org = organizer.organizer( self.sampleSpecs(tag) ) #utils.printSkimResults(org) #organize org=organizer.organizer( self.sampleSpecs(tag) ) org.mergeSamples( targetSpec = {"name":"2010 Data", "color":r.kBlack, "markerStyle":20}, allWithPrefix="Run2010" ) #self.mergeSamples(org, tag) org.scale() #plot pl = plotter.plotter(org, psFileName = self.psFileName(tag), #samplesForRatios = ("2010 Data","standard_model"), #sampleLabelsForRatios = ("data","s.m."), #whiteList = ["xcak5JetAlphaTPat","xcak5JetAlphaTZoomPat"], blackList = ["nJobsHisto","lumiHisto"] #compactOutput = True ) pl.plotAll()
def task_3(): image_size = 128 #both width and height of image are the same img_ch = 1 batch_size = 2 LR = 0.0001 SDRate = 0.5 spatial_dropout = True epochs = 150 base = 16 batch_normalization = True p = 0.2 #percentage of training and test data path = '/Lab1/Lab3/X_ray/' fold1 = 'Image' fold2 = 'Mask' number_of_labels = 1 #Data Augmentation rotation_range = 10 width_shift = 0.1 height_shift = 0.1 rescale = 0.2 horizontal_flip = True #train_datagen, val_datagen = DataAugmentation(rotation_range,width_shift,height_shift,rescale,horizontal_flip) train_img, train_mask, test_img, test_mask = get_train_test_data(fold1, fold2, path, p,image_size, image_size) model = u_net(base,image_size, image_size, img_ch, batch_normalization, SDRate, spatial_dropout, number_of_labels) model.compile(optimizer = Adam(lr=LR), loss = dice_coef_loss, metrics =[dice_coef]) #Fit the data into the model History = model.fit(train_img, train_mask, epochs = epochs, batch_size = batch_size, verbose = 1, # validation_data = (test_img,test_mask)) # History = model.fit_generator(train_datagen.flow(train_img, train_mask,batch_size = batch_size), validation_data = val_datagen.flow(test_img, test_mask), epochs = epochs, verbose = 1) plotter(History, '3')
def conclude(self) : for tag in self.sideBySideAnalysisTags() : org=organizer.organizer( self.sampleSpecs(tag) ) org.mergeSamples(targetSpec = {"name":"2010 Data", "color":r.kBlack, "markerStyle":20}, allWithPrefix = "Run2010" ) pl = plotter.plotter(org, psFileName = self.psFileName(tag)) pl.plotAll()
def __init__(self,data_gen,sum,n,traits,batchmode=True): if batchmode: self.dataviewer=datacollector.datacollector(data_gen,sum,n,traits) else: self.dataviewer=plotter.plotter(data_gen,sum,n,traits)
graph_parameters_list = graph.split("|") graph_parameters = dict() for parameter in graph_parameters_index.items( ): #Set graph parameter list in a named dict graph_parameters[parameter[0]] = graph_parameters_list[parameter[1]] x = config.get_data_method_from_name(graph_parameters["x_method"])(columns) y = config.get_data_method_from_name(graph_parameters["y_method"])(columns) annotate = True if graph_parameters["annotate"] == 1 else False plotter( x, y, graphs_pdf_path + graph_parameters["title"] + ".pdf", #pdf file path graph_parameters["x_legend"], graph_parameters["y_legend"], graph_parameters["title"], graph_parameters["x_unit"], graph_parameters["y_unit"], annotate) png_file_list.append("\"" + graphs_png_path + graph_parameters["title"] + ".png" + "\"") pdf_file_list.append("\"" + graphs_pdf_path + graph_parameters["title"] + ".pdf" + "\"") ending_commands.append("convert -density 250 " + "\"" + graphs_pdf_path + graph_parameters["title"] + ".pdf" + "\"" + " -quality 90 \"" + graphs_png_path + graph_parameters["title"] + ".png\"") lcd.prompt("GRAPH GENERATION",
def conclude(self, conf) : org = self.organizer(conf) pl = plotter.plotter(org, psFileName = self.psFileName(org.tag), blackList = ["lumiHisto","xsHisto","nJobsHisto"]) pl.plotAll()
def main(argv): task = argv #Model parameters base = 16 image_size = 256 img_ch = 1 batch_size = 8 LR = 0.0001 SDRate = 0.5 batch_normalization = True spatial_dropout = True epochs = 150 #Data loader parameters p = 0.2 fold1 = 'Image' fold2 = 'Mask' #Data augmentation parameters rotation_range = 10 width_shift = 0.1 height_shift_range = 0.1, rescale = 1. / 255 horizontal_flip = True if task == '5a': number_of_labels = 1 path = '/Lab1/Lab3/CT/' train_img, train_mask, test_img, test_mask = get_train_test_data( fold1, fold2, path, p, image_size, image_size) model = u_net(base, image_size, image_size, img_ch, batch_normalization, SDRate, spatial_dropout, number_of_labels) model.compile(optimizer=Adam(lr=LR), loss=dice_coef_loss, metrics=[dice_coef]) History = model.fit(train_img, train_mask, epochs=epochs, batch_size=batch_size, verbose=1, validation_data=(test_img, test_mask)) plotter(History, task) elif task == '5b': number_of_labels = 1 path = '/Lab1/Lab3/CT/' #Load the data train_img, train_mask, test_img, test_mask = get_train_test_data( fold1, fold2, path, p, image_size, image_size) #Data augmentation train_datagen, val_datagen = DataAugmentation(rotation_range, width_shift, height_shift_range, rescale, horizontal_flip) #Build the model model = u_net(base, image_size, image_size, img_ch, batch_normalization, SDRate, spatial_dropout, number_of_labels) #Compile the model model.compile(optimizer=Adam(lr=LR), loss=dice_coef_loss, metrics=[dice_coef, Recall(), Precision()]) #Fit the data into the model History = model.fit_generator( train_datagen.flow(train_img, train_mask, batch_size=batch_size), validation_data=val_datagen.flow(test_img, test_mask), epochs=epochs, verbose=1) #Plot results plotter(History, task, recall=True, precision=True) elif task == '6': number_of_labels = 3 path = '/Lab1/Lab3/CT/' #Load the data train_img, train_mask, test_img, test_mask = get_train_test_data( fold1, fold2, path, p, image_size, image_size) #To one-hot-encoding train_mask = to_categorical(train_mask, num_classes=3) test_mask = to_categorical(test_mask, num_classes=3) #Data augmentation train_datagen, val_datagen = DataAugmentation(rotation_range, width_shift, height_shift_range, rescale, horizontal_flip) #Build the multi-classification model model = u_net(base, image_size, image_size, img_ch, batch_normalization, SDRate, spatial_dropout, number_of_labels) #Compile the model model.compile(optimizer=Adam(lr=LR), loss=dice_coef_loss, metrics=[dice_coef, Recall(), Precision()]) #Fit the data into the model History = model.fit_generator( train_datagen.flow(train_img, train_mask, batch_size=batch_size), validation_data=val_datagen.flow(test_img, test_mask), epochs=epochs, verbose=1) #Plot results plotter(History, task, recall=True, precision=True) elif task == '7': path = '/Lab1/Lab3/MRI/' number_of_labels = 1 #Load the data train_img, train_mask, test_img, test_mask = get_train_test_data( fold1, fold2, path, p, image_size, image_size) #Data augmentation train_datagen, val_datagen = DataAugmentation(rotation_range, width_shift, height_shift_range, rescale, horizontal_flip) #Build the multi-classification model model = u_net(base, image_size, image_size, img_ch, batch_normalization, SDRate, spatial_dropout, number_of_labels) #Compile the model model.compile(optimizer=Adam(lr=LR), loss=dice_coef_loss, metrics=[dice_coef, Recall(), Precision()]) #Fit the data into the model History = model.fit_generator( train_datagen.flow(train_img, train_mask, batch_size=batch_size), validation_data=val_datagen.flow(test_img, test_mask), epochs=epochs, verbose=1) #Plot results plotter(History, task, recall=True, precision=True) else: print('Wrong task number')
d.set('zoom 4') duration = time.time()-st logger.debug(" This simulation completed in " + str(sf(duration, 4)) + "s.") if __name__== "__main__": parser = argparse.ArgumentParser() parser.add_argument("-i", help="simulation configuration file path (.ini)", default="etc/default.ini", type=str) parser.add_argument("-f", help="output filename", action="store", default="cube.fits") parser.add_argument("-c", help="clobber output file?", action="store_true") parser.add_argument("-d", help="display fits datacube? (-f must be set)", action="store_true") parser.add_argument("-v", help="verbose", action="store_true") args = parser.parse_args() # Setup logger and plotter. # logger = logging.getLogger(args.f) logger.setLevel(logging.DEBUG) ch = logging.StreamHandler() ch.setLevel(logging.DEBUG) formatter = logging.Formatter("(" + str(os.getpid()) + \ ") %(asctime)s:%(levelname)s: %(message)s") ch.setFormatter(formatter) logger.addHandler(ch) plotter = plotter.plotter() run(args, logger, plotter)
def visualise(self, title = '', x_label = None, y_label = None, style = 'ggplot', figsize = (8, 4), save = False, legend_pos = 'best', reverse_legend = 'guess', num_to_plot = 7, tex = 'try', colours = 'Accent', cumulative = False, pie_legend = True, partial_pie = False, show_totals = False, transparent = False, output_format = 'png', interactive = False, black_and_white = False, show_p_val = False, indices = False, **kwargs): """Visualise corpus interrogations. >>> data.visualise('An example plot', kind = 'bar', save = True) :param title: A title for the plot :type title: str :param x_label: A label for the x axis :type x_label: str :param y_label: A label for the y axis :type y_label: str :param kind: The kind of chart to make :type kind: str ('line'/'bar'/'barh'/'pie'/'area') :param style: Visual theme of plot :type style: str ('ggplot'/'bmh'/'fivethirtyeight'/'seaborn-talk'/etc) :param figsize: Size of plot :type figsize: tuple (int, int) :param save: If bool, save with *title* as name; if str, use str as name :type save: bool/str :param legend_pos: Where to place legend :type legend_pos: str ('upper right'/'outside right'/etc) :param reverse_legend: Reverse the order of the legend :type reverse_legend: bool :param num_to_plot: How many columns to plot :type num_to_plot: int/'all' :param tex: Use TeX to draw plot text :type tex: bool :param colours: Colourmap for lines/bars/slices :type colours: str :param cumulative: Plot values cumulatively :type cumulative: bool :param pie_legend: Show a legend for pie chart :type pie_legend: bool :param partial_pie: Allow plotting of pie slices only :type partial_pie: bool :param show_totals: Print sums in plot where possible :type show_totals: str -- 'legend'/'plot'/'both' :param transparent: Transparent .png background :type transparent: bool :param output_format: File format for saved image :type output_format: str -- 'png'/'pdf' :param black_and_white: Create black and white line styles :type black_and_white: bool :param show_p_val: Attempt to print p values in legend if contained in df :type show_p_val: bool :param indices: To use when plotting "distance from root" :type indices: bool :param stacked: When making bar chart, stack bars on top of one another :type stacked: str :param filled: For area and bar charts, make every column sum to 100 :type filled: str :param legend: Show a legend :type legend: bool :param rot: Rotate x axis ticks by *rot* degrees :type rot: int :param subplots: Plot each column separately :type subplots: bool :param layout: Grid shape to use when *subplots* is True :type layout: tuple -- (int, int) :param interactive: Experimental interactive options :type interactive: list -- [1, 2, 3] :returns: matplotlib figure """ locs = locals() locs.pop('title', None) locs.pop('self', None) if kwargs: for k, v in kwargs.items(): locs[k] = v locs.pop('kwargs', None) from plotter import plotter branch = kwargs.pop('branch', 'results') if branch.lower().startswith('r'): plotter(title, self.results, **locs) elif branch.lower().startswith('t'): plotter(title, self.totals, **locs)
def _plot(self, *args, **kwargs): from corpkit import plotter plotter(self, *args, **kwargs)
def visualise(self, title, *args, **kwargs): """calls corpkit.plotter.plotter()""" from plotter import plotter plotter(title, self, *args, **kwargs)
def conclude(self): org = organizer.organizer(self.sampleSpecs()) pl = plotter.plotter( org, psFileName=self.psFileName(), doLog=False, blackList=["lumiHisto", "xsHisto", "nJobsHisto"] ) pl.plotAll()
def plotfunc(self, title, *args, **kwargs): from corpkit import plotter plotter(title, self, *args, **kwargs)