def get(self): global gl # return gl file_id = request.args.get('id') ch1 = request.args.get('ch1') ch2 = request.args.get('ch2') transformation = request.args.get('transformation') bins = request.args.get('bins') gl = { 'server_start_ts': dt.microsecond, 'id': file_id, 'ch1': ch1, 'bins': bins, 'transformation': transformation } if not file_id or not ch1 or not ch2: file_id = 'default' ch1 = 'HDR-T' ch2 = 'FSC-A' print('PLOTTING Default FCS and chs', ch1, ch2) else: print('PLOTTING RECEIVED FCS and chs', file_id, ch1, ch2) plotting = Plotting(file_id, ch1, ch2, transformation, bins) plots = plotting.get_plots() gl.update(plots) return plots
def play(): ( controller_parameters, visual, parameters, history, ) = process_game_parameters() controllers = Controllers( parameters, history, controller_parameters, ) result = Result(parameters, history, controllers) plotting = Plotting( visual, parameters, history, controllers, result, ) animation = Animation( visual, parameters, history, controllers, plotting, result, ) animation.run()
def main(): settings = Settings() settings.Initalize_Global_Settings() preprocess = Preprocess(settings) preprocess.Load_Into_Dataframes() analysis = Analysis(preprocess) experiments = Experiments(analysis) data = analysis.Core(experiments) data_experimentals = experiments.Run_Experiments() models, best_fit, gals_df = analysis.Mocks_And_Models(experiments) plotting = Plotting(preprocess) plotting.Plot_Core(data, models, best_fit) plotting.Plot_Experiments(data, data_experimentals, models, best_fit)
def __init__(self, filename, number_of_resamples=10000): """ Initializing the Bootstrapit class executes the resampling of the imported dataset. :param filename: The filename including filepath to the import data file. :param number_of_resamples: The number of resamples to perform. """ self.number_of_resamples = number_of_resamples # import dataset from file self.__fh = FileHandling() self.original_data_dict = self.__fh.import_spreadsheet(filename) # resample dataset self.__bootstrapper = Bootstrapper(self.original_data_dict, number_of_resamples) #init bootstrap analysis tools self.__analysis = BootstrapAnalysis(self.__bootstrapper) #init plotter self.__plotter = Plotting(self.__fh.export_order)
def set_up_all(self): """ Run at the start of each test suite. L2fwd prerequisites. """ self.frame_sizes = [64, 65, 128, 256, 512, 1024, 1280, 1518] self.test_queues = [{'queues': 1, 'Mpps': {}, 'pct': {}}, {'queues': 2, 'Mpps': {}, 'pct': {}}, {'queues': 4, 'Mpps': {}, 'pct': {}}, {'queues': 8, 'Mpps': {}, 'pct': {}} ] self.core_config = "1S/4C/1T" self.number_of_ports = 2 self.headers_size = HEADER_SIZE['eth'] + HEADER_SIZE['ip'] + \ HEADER_SIZE['udp'] self.dut_ports = self.dut.get_ports_performance() self.verify(len(self.dut_ports) >= self.number_of_ports, "Not enough ports for " + self.nic) self.ports_socket = self.dut.get_numa_id(self.dut_ports[0]) # compile out = self.dut.build_dpdk_apps("./examples/l2fwd") self.verify("Error" not in out, "Compilation error") self.verify("No such" not in out, "Compilation error") self.table_header = ['Frame'] for queue in self.test_queues: self.table_header.append("%d queues Mpps" % queue['queues']) self.table_header.append("% linerate") dts.results_table_add_header(self.table_header) self.plotting = Plotting(self.dut.crb['name'], self.target, self.nic)
def __init__(self, hist_path: str, varname="b", video_path=None, visible=True): """Open the history file and load parts of it.""" # Initialize self.hist_file to prevent the destructor from failing self.hist_file = None self.tracers = False # Set parameters needed for Plotting that cannot be determined # so far; maybe make them command line arguments in the future param = { "figsize": (RESOLUTION[0] / DPI, RESOLUTION[1] / DPI), "aspect": "equal", "rotation_speed": 3, } if varname == "b": param["style"] = "b-interface" param["stable_stratification"] = True # TODO make this a command line argument elif varname == "t0": # This option is to plot only the first tracer and also a # shorter notation in the common case with only one tracer param["style"] = "tracer" param["n_tracers"] = 1 elif varname == "tracer": param["style"] = "tracer" self.tracers = True else: raise NotImplementedError("The given variable is not yet supported.") # Save necessary arguments self.video_path = video_path self.visible = visible # Create the metadata for the video if self.video_path: # Extract the name of the experiment exp_name = os.path.basename( hist_path[:-8] if hist_path.endswith("_hist.nc") else hist_path ) self.metadata = { "title": "Nyles experiment {}".format(exp_name), "artist": CREATOR, "genre": "Computational Fluid Dynamics (CFD)", "comment": "Created on {} with Nyles. Nyles is a Large Eddy " "Simulation written in Python. For more information" " visit https://github.com/pvthinker/Nyles." .format(time.strftime('%d %b %Y')), "date": time.strftime("%Y-%m-%d"), } # Open the history file and keep it open to allow sequential reading print("Loading history file {!r}:".format(hist_path)) self.hist_file = nc.Dataset(hist_path) print(self.hist_file) # Load the needed data if self.tracers: param["n_tracers"] = self.hist_file.n_tracers self.tracers_data = [ self.hist_file["t{}".format(i)] for i in range(self.hist_file.n_tracers) ] else: self.vardata = self.hist_file[varname] self.t = self.hist_file["t"] self.n = self.hist_file["n"] self.n_frames = self.n.size # Load parameters needed for Grid param["Lx"] = self.hist_file.Lx param["Ly"] = self.hist_file.Ly param["Lz"] = self.hist_file.Lz param["nx"] = self.hist_file.global_nx param["ny"] = self.hist_file.global_ny param["nz"] = self.hist_file.global_nz # Set parameters needed for Scalar param["nh"] = 0 param["neighbours"] = {} grid = Grid(param) # Create one or several Scalar variables as an interface for # passing data to the plotting module. Note: Scalar takes # actually a dimension instead of a unit, but that does not # matter because this information is not processed here. if self.tracers: tracer_list = [] self.arrays = [] for data in self.tracers_data: tracer = Scalar(param, data.long_name, data.name, data.units) tracer_list.append(tracer) self.arrays.append(tracer.view("i")) state = State(tracer_list) else: scalar = Scalar(param, self.vardata.long_name, varname, self.vardata.units) self.array = scalar.view("i") state = State([scalar]) self.p = Plotting(param, state, grid)
flux = P.c * f_c * g - P.D * dCdx flux[boundary] = 0 return flux #, boundary def increment_grainsize(P, G): return KT(P, G, 0) + KT(P, G, 1) # return NT(P,G,0) + NT(P,G,1) if __name__ == "__main__": import initialise from numpy import random, maximum, ones from plotting import Plotting plot = Plotting() P, G, L = initialise.get_parameters(['bi_seg_test', '22', '2']) G.wipe(P) L.get_reference_node(P, G) # Find node down and left L.get_basis_functions(P, G) # Make basis functions L.get_nodal_mass_momentum(P, G) # Initialise from grid state plot.draw_gsd_grid(L, P, G) G.grad_gammadot = -1. * ones([P.G.ny * P.G.nx, 3]) # G.grad_gammadot[:,1] = 0 # P.dt *= 10 # G.phi = zeros_like(G.phi) # G.phi[40:120,0] = 0.5 # G.phi[:,1] = 1- G.phi[:,0] # G.phi[40:100,1] = 0 # P.c *= 100
def training(self, episodes): self.env.set_speed_mode(self.env.my_car_id, 0) state = None steps = 0 # reward_type = "collision" # reward_type = "horizon" reward_type = "security_distance" speed_limit = True plt_data = { "collisions": [], "space_headway": [], "relative_speed": [], "speed": [], "steps": 0 } while True: print(state) if state: plt_data["space_headway"].append(state.get("space_headway")) plt_data["relative_speed"].append( round(state.get("relative_speed") * 3.6, 0)) plt_data["speed"].append(round(state.get("speed") * 3.6, 0)) d_t, ds_t, s_t = \ self.framing(state.get('space_headway'), self.i_dict_space_headway), \ self.framing(state.get('relative_speed'), self.i_dict_relative_speed), \ self.framing(state.get('speed'), self.i_dict_speed) a = self.e_greedy_policy(d_t, ds_t, s_t) q_t = self.q[self.i_dict_space_headway.get(d_t), self.i_dict_relative_speed.get(ds_t), self.i_dict_speed.get(s_t), self.i_dict_action.get(self.action[a])] new_speed = self.new_speed(self.action[a], state.get('speed')) self.env.set_speed(self.env.my_car_id, new_speed) self.env.simulation_step() next_state = self.env.get_state(self.env.my_car_id) q_max_t1 = None if self.env.is_collided(self.env.my_car_id): self.set_reward_collision(reward_type) self.env.set_speed(self.env.my_car_id, 0) q_max_t1 = 0 state = None plt_data["collisions"].append(steps) elif next_state: """REWARD""" """ if reward_type == "horizon": self.set_reward_horizon_speed(next_state.get('space_headway'), next_state.get('speed'), speed_limit) """ if reward_type == "security_distance": self.set_reward_security_dist_speed( next_state.get('space_headway'), next_state.get('speed'), speed_limit) print(f"reward {self.reward}") d_t1, ds_t1, s_t1 = \ self.framing(next_state.get('space_headway'), self.i_dict_space_headway), \ self.framing(next_state.get('relative_speed'), self.i_dict_relative_speed), \ self.framing(next_state.get('speed'), self.i_dict_speed) q_max_t1 = np.max( self.q[self.i_dict_space_headway.get(d_t1), self.i_dict_relative_speed.get(ds_t1), self.i_dict_speed.get(s_t1)]) state = next_state if q_max_t1 is not None: self.q[ self.i_dict_space_headway.get(d_t), self.i_dict_relative_speed.get(ds_t), self.i_dict_speed.get(s_t), self.i_dict_action.get(self.action[a])] = \ (1 - self.alpha) * q_t + self.alpha * (self.reward + self.gamma * q_max_t1) """ PRINT Q""" print( f"q: {self.q[self.i_dict_space_headway.get(d_t), self.i_dict_relative_speed.get(ds_t), self.i_dict_speed.get(s_t)]}" ) steps += 1 self.epsilon_decay(steps) # print(steps) # print(f"time: {self.env.get_current_time()}") else: self.env.simulation_step() state = self.env.get_state(self.env.my_car_id) self.env.set_speed(self.env.my_car_id, 0) if steps > (episodes * 10000): time.sleep(.1) if steps == episodes * 10000: plt_data["steps"] = steps plotting = Plotting(self, plt_data) plotting.plot_()
def sweep_s11(log, f1, f2, nums, rstart, angle, rstop, tpolar, cpolar): # -------------------------------------------------------------------------- # Initialize values # ant_no = int( numpy.floor((rstop - rstart) / angle) + 1) # Number of degree steps # If meas 0-360, don't take measurement at 360 if (rstop == 360) and (rstart == 0): ant_no = ant_no - 1 # # End initialize values # -------------------------------------------------------------------------- # -------------------------------------------------------------------------- # Reset motor positions # motorSet[STAND_ROTATION].goto_zero() set_polarization(log, motorSet, tpolar, cpolar, mycursor) # # End reset motor positions # -------------------------------------------------------------------------- # -------------------------------------------------------------------------- # Move test antenna to start degree position # log.info("Start Position: " + str(rstart)) motorSet[M1].rot_deg(rstart) log.info("Motor setup complete") # # End move test antenna to start position # -------------------------------------------------------------------------- # -------------------------------------------------------------------------- # Load state # analyzer.load_state() # # End load state # -------------------------------------------------------------------------- # -------------------------------------------------------------------------- # Set network analyzer parameters # channel = 1 trace = 1 analyzer.setup(channel, trace) # analyzer.enable_display(False) # Set start frequency start = float(analyzer.set_start(channel, f1)) if f1 != start: msg = "WARNING: Invalid start frequency, using " + str(start) print(msg) log.warning(msg) # f1_old = f1 f1 = start # Set stop frequency stop = float(analyzer.set_stop(channel, f2)) if f2 != stop: msg = "WARNING: Invalid stop frequency, using " + str(stop) print(msg) log.warning(msg) # f2_old = f2 f2 = stop # Set number of points points = int(analyzer.set_points(channel, nums)) if nums != points: msg = "WARNING: Invalid number of steps, using " + str(points) print(msg) log.warning(msg) # nums_old = nums nums = points # Create csv files # d = datetime.today() # file_name = os.path.join(DATA_PATH, d.strftime("%Y%m%d%H%M%S")) # s11_filename = file_name + "_s11.csv" s11_filename = os.path.join(DATA_PATH, "S11.csv") s11File = open(s11_filename, "w") # # End set network analyzer parameters # -------------------------------------------------------------------------- # -------------------------------------------------------------------------- # Check for network analyzer errors log.info("Checking network analyzer error queue") err_nums, err_msgs = analyzer.get_errors() if len(err_nums) > 0: msg = "Error in setting network analyzer parameters" print(msg) log.warning(msg) else: # No errors log.info("No network analyzer errors detected") # # -------------------------------------------------------------------------- # -------------------------------------------------------------------------- # Measure S11 (actually S22) # log.info("Measuring S11") print("Starting S11 Measurement") print("Start Frequency: " + str(f1 / 1e9) + " GHz") print("Stop Frequency: " + str(f2 / 1e9) + " GHz") print("Number of Points: " + str(nums)) analyzer.set_measurement(channel, trace, 2, 2) analyzer.trigger() analyzer.update_display() analyzer.auto_scale(channel, trace) s11Freq = analyzer.get_x(channel) s11Data = analyzer.get_corr_data(channel) # s11Data = analyzer.get_form_data(channel) # Write to csv file log.info("Writing s11 data to file") s11File.write(s11Freq) s11File.write(s11Data) # # -------------------------------------------------------------------------- # -------------------------------------------------------------------------- # Check for network analyzer errors log.info("Checking network analyzer error queue") err_nums, err_msgs = analyzer.get_errors() if len(err_nums) > 0: msg = "Error measuring S11" print(msg) log.warning(msg) else: # No errors msg = "S11 Measurement Successful" print(msg) log.info(msg) # # -------------------------------------------------------------------------- # -------------------------------------------------------------------------- # Reset motor positions # motorSet[STAND_ROTATION].goto_zero() # # End reset motor positions # -------------------------------------------------------------------------- # -------------------------------------------------------------------------- # Close csv files # s11File.close() # # -------------------------------------------------------------------------- # -------------------------------------------------------------------------- # Update database # if db.is_connected(): fstart = f1 / 1e9 fstop = f2 / 1e9 rowcount = mycursor.rowcount # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Antenna polarization # log.info("Updating tpolar and cpolar in sql database") update_config_db(log, mycursor, 0, "'antenna_polarization'") update_config_db(log, mycursor, 0, "'chamber_polarization'") # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Network analyzer parameters # log.info("Updating fstart, fstop, and nums in sql database") update_config_db(log, mycursor, fstart, "'frequency_start'") update_config_db(log, mycursor, fstop, "'frequency_stop'") update_config_db(log, mycursor, nums, "'num_steps'") # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Commit changes log.info("Committing changes") db.commit() if rowcount == mycursor.rowcount: log.warning("Failed to store updated antenna polarization data") # # End update database # -------------------------------------------------------------------------- # -------------------------------------------------------------------------- # Call plotting function and write zip file # Plotting(f1, f2, nums, rstart, angle, rstop, 0, 0, 0, 0, 0, 0, "s11")