def plotUpperLowerAndMeanLines(ls_line_specs): # logger.debug("plotting upper and lower 1") # Initialize upper and lower bounds: Create new columns with maximum and minimum values of variables lower_line = {'df': None, 'x_var': 'time', 'y_var': 'minimum', 'linestyle': '-', 'linewidth': 2, 'markersize': 0, 'marker': 'o', 'label': 'Lower', 'color': 'blue'} upper_line = {'df': None, 'x_var': 'time', 'y_var': 'maximum', 'linestyle': '-', 'linewidth': 2, 'markersize': 0, 'marker': 'o', 'label': 'Upper', 'color': 'red'} mean_line = {'df': None, 'x_var': 'time', 'y_var': 'mean', 'linestyle': '-', 'linewidth': 1.5, 'markersize': 0, 'marker': 'o', 'label': 'Mean', 'color': 'black'} # logger.debug("plotting upper and lower 2") df = None # Update / Initialize upper and lower line specs for i, line_spec in enumerate(ls_line_specs): # Continue if df is None: df = line_spec.df[['time', line_spec.y_var]].copy().rename(columns={line_spec.y_var: line_spec.y_var + '_' + str(i)}) else: df = pd.merge(df, line_spec.df[['time', line_spec.y_var]], on='time', how='left').rename(columns={line_spec.y_var: line_spec.y_var + '_' + str(i)}) # debug cols = [c for c in df.columns if c not in ['time']] # logger.debug("plotting upper and lower 3") # logger.debug("cols: %s" % str(cols)) def get_statistics(row): vals = row.values return pd.Series([min(vals), np.mean(vals), max(vals)]) # logger.debug(df.columns.tolist()) # logger.debug(df.head()) df[['minimum', 'mean', 'maximum']] = df[cols].apply(get_statistics, 1) # logger.debug(df[['minimum', 'mean', 'maximum']].head()) # logger.debug("plotting upper and lower 4") mean_line['df'] = df[['time', 'mean']] lower_line['df'] = df[['time', 'minimum']] upper_line['df'] = df[['time', 'maximum']] # logger.debug("plotting upper and lower 5") # Generate Upper/Lower Lines and plot. lower_line_spec = plot_specs.PlotLineSpecs(**lower_line) plotLineSpec(lower_line_spec) upper_line_spec = plot_specs.PlotLineSpecs(**upper_line) plotLineSpec(upper_line_spec) mean_line_spec = plot_specs.PlotLineSpecs(**mean_line) plotLineSpec(mean_line_spec) logger.debug("plotting upper and lower 6") return 0
def lineSpecForPerturbedRun(self, colors_iter, sweep_iter_results, var_name): # Prepare information # Get simulation specs for std run simu_results = sweep_iter_results.simulation_results file_path = simu_results.output_path # Read simulation results from disk df_run = pandas.read_csv(file_path) # Define conventions x_var = "time" linewidth = 1 linestyle = "-" markersize = 0 marker = 'o' label = self.labelForPerturbedRun(sweep_iter_results) color = next(colors_iter) # Initialize plot line specs line_specs = plot_specs.PlotLineSpecs( df=df_run, x_var=x_var, y_var=var_name, linewidth=linewidth, linestyle=linestyle, markersize=markersize, marker=marker, label=label, color=color, ) return line_specs
def standardRunLineSpecs(self, var_name): # Prepare information # Get simulation specs for std run std_run_specs = self.sweep_results.std_run # Read simulation results from disk df_simu = pandas.read_csv(std_run_specs.output_path) # Define conventions x_var = "time" linewidth = 4 linestyle = ":" markersize = 0 marker = 'o' label = "STD_RUN" color = "black" # Initialize plot line specs line_specs = plot_specs.PlotLineSpecs( df=df_simu, x_var=x_var, y_var=var_name, linewidth=linewidth, linestyle=linestyle, markersize=markersize, marker=marker, label=label, color=color, ) return line_specs
def test_class_creation(self): lower_line_spec = plot_specs.PlotLineSpecs(df=pd.DataFrame(), x_var='time', y_var='value', linewidth=1, linestyle='-', markersize=1, marker='o', label='label', color='c') self.assertEquals(1, 1)
def regular_run_line_specs(self, df, axis_name, variable_name, linestyle): # Prepare info x_var = "time" y_var = variable_name linewidth = 1 markersize = 0 marker = 'o' label = axis_name color = "black" # Initialize plot line specs std_run_specs = plot_specs.PlotLineSpecs( df = df, x_var = x_var, y_var = y_var, linewidth = linewidth, linestyle = linestyle, markersize = markersize, marker = marker, label = label, color = color ) return std_run_specs
def standardRunLineSpecs(self): # Prepare info df = self.df_x0_run x_var = "" y_var = self.optim_result.variable_name linewidth = 1 linestyle = "-" markersize = 0 marker = 'o' label = "STD_RUN" color = "black" # Initialize plot line specs std_run_specs = plot_specs.PlotLineSpecs(df=df, x_var=x_var, y_var=y_var, linewidth=linewidth, linestyle=linestyle, markersize=markersize, marker=marker, label=label, color=color) return std_run_specs
def perturbedRunSpecs(self): # Prepare info df = self.df_x_opt_run x_var = "" y_var = self.optim_result.variable_name linewidth = 1 linestyle = "-" markersize = 0 marker = 'o' label = "optimum" color = "red" # Initialize plot line specs std_run_specs = plot_specs.PlotLineSpecs(df=df, x_var=x_var, y_var=y_var, linewidth=linewidth, linestyle=linestyle, markersize=markersize, marker=marker, label=label, color=color) return std_run_specs