def load_data(filename): file = open(filename) count =0 start_time = time.time() s1 = start_time time_slice = 5000 topics = np.array([topic4(600,400,15000)]) c_old = [0]*max_topics v_old = [0]*max_topics similarity = np.zeros(max_topics) plt.ion() fig = plt.figure() ax1 = fig.add_subplot(1,1,1) plt.get_current_fig_manager().window.wm_geometry("+0+0") for line in file: parsed_json = safe_parse(line) if(not parsed_json): continue tweet = regex.sub('', parsed_json["text"].lower()) hashtags = [x["text"].lower() for x in parsed_json['entities']['hashtags']] usernames = [x["screen_name"].lower() for x in parsed_json['entities']['user_mentions']] words = getwords(tweet.split()) count+=1 if(len(words) < 2): continue for i in range(topics.size): similarity[i] = topics[i].get_similarity(hashtags, usernames, words) if(np.max(similarity) == 0): if(topics.size < max_topics): topics = np.append(topics, topic4(600,400,15000)) max_ind = topics.size -1 else: max_ind = random.randrange(0,topics.size) else: max_ind = np.argmax(similarity) topics[max_ind].set_cluster(hashtags, usernames, words) if(count%time_slice ==0): current = time.time() print("--- %s seconds ---" % (current - start_time)) start_time=current count=0 counts_vector = [i.topic_count for i in topics] counts_vector += [0]*(max_topics-len(counts_vector)) delta = np.subtract(counts_vector,c_old) acc = np.subtract(delta,v_old) print(counts_vector) # print(similarity) ax1.plot(acc) c_old = counts_vector v_old = delta plt.grid() fig.canvas.draw() ax1.clear() # print_counts( counts_vector, topics) print("\n") print("---\n\n\nfinal time: %s seconds ---" % (time.time() - s1))
def plot_learning_curve(estimator, title, X, y, ylim=None, cv=None, n_jobs=-1, train_sizes=np.linspace(.1, 1.0, 5)): #to have a figure object, this can be done figure = plt.figure() then the figure object can be referenced subsequently plt.figure() plt.title(title) if ylim is not None: plt.ylim(*ylim) plt.xlabel("Training examples") plt.ylabel("Score") train_sizes, train_scores, test_scores = learning_curve(estimator, X, y, cv=cv, n_jobs=n_jobs, train_sizes=train_sizes, scoring='f1_weighted') train_scores_mean = np.mean(train_scores, axis=1) train_scores_std = np.std(train_scores, axis=1) test_scores_mean = np.mean(test_scores, axis=1) test_scores_std = np.std(test_scores, axis=1) plt.grid() plt.fill_between(train_sizes, train_scores_mean - train_scores_std, train_scores_mean + train_scores_std, alpha=0.1, color="r") plt.fill_between(train_sizes, test_scores_mean - test_scores_std, test_scores_mean + test_scores_std, alpha=0.1, color="g") plt.plot(train_sizes, train_scores_mean, 'o-', color="r", label="Training score") plt.plot(train_sizes, test_scores_mean, 'o-', color="g", label="Cross-validation score") plt.legend(loc="best") plt.get_current_fig_manager().window.raise_() plt.show() return plt
def main_test_global(): """Test of global methods only """ fig, axes, imsh = generate_test_image() plt.get_current_fig_manager().window.geometry('+50+10') #move(50, 10) plt.show()
def _plot_histogram(self, data, number_of_devices=1, preamp_timeout=1253): if number_of_devices == 0: return data = np.array(data) plt.figure(3) plt.ioff() plt.get_current_fig_manager().window.wm_geometry("800x550+700+25") plt.clf() if number_of_devices == 1: plt.hist(data[0,:], bins=preamp_timeout, range=(1, preamp_timeout-1), color='b') elif number_of_devices == 2: plt.hist(data[0,:], bins=preamp_timeout, range=(1, preamp_timeout-1), color='r', label='JPM A') plt.hist(data[1,:], bins=preamp_timeout, range=(1, preamp_timeout-1), color='b', label='JPM B') plt.legend() elif number_of_devices > 2: raise Exception('Histogram plotting for more than two ' + 'devices is not implemented.') plt.xlabel('Timing Information [Preamp Time Counts]') plt.ylabel('Counts') plt.xlim(0, preamp_timeout) plt.draw() plt.pause(0.05)
def plot_compare_states(x_idx,data_dict,X_Time,X_Feature,X_STATE,X_names): if X_STATE.shape!=X_Feature.shape: raise NameError('the size of state and feature matrix must be same') if (X_STATE.shape[0]!=X_Time.shape[0]): raise NameError('the row length of state /feature matrix and time array must be same') if (X_STATE.shape[1]!=len(X_names)): raise NameError('the column length of state and name array must be same') sensor_name=X_names[x_idx] fig = plt.figure('Regualar Event Classification') fig.suptitle('Regualar Event Classification'); plt.subplot(3,1,1); plt.plot(unix_to_dtime(data_dict[sensor_name][2][0]),data_dict[sensor_name][2][1]) plt.ylabel('Power, KWatt') plt.title(sensor_name+' - Measurements'); plt.subplot(3,1,2); plt.plot(X_Time,X_Feature[:,x_idx]); plt.title(X_names[x_idx]+' - Hourly Average'); plt.ylabel('Normalized Measurement') plt.subplot(3,1,3); low_peak_idx=np.nonzero(X_STATE[:,x_idx]==-1)[0] no_peak_idx=np.nonzero(X_STATE[:,x_idx]==0)[0] high_peak_idx=np.nonzero(X_STATE[:,x_idx]==1)[0] plt.plot(X_Time[low_peak_idx],X_STATE[low_peak_idx,x_idx],'rv'); plt.plot(X_Time[high_peak_idx],X_STATE[high_peak_idx,x_idx],'b^'); plt.plot(X_Time[no_peak_idx],X_STATE[no_peak_idx,x_idx],'g.'); plt.plot(X_Time,X_STATE[:,x_idx]); plt.title(sensor_name+' - Classified States '); plt.ylabel('States'); plt.xlabel('Dates'); plt.ylim([-1.2,1.2]) plt.yticks([-1, 0, 1], ['Low Peak', 'No Peak', 'High Peak']) plt.get_current_fig_manager().window.showMaximized()
def __init__(self, port, baud, check = False): """ Initialize the main display: a single figure :port: serial port index or name (eg.: COM4) :paud: baud rate (eg.: 115200) """ self.frame = IM_Frame() self.new_frame = False self.lock = threading.Lock() self.check = check # disable figure toolbar, bind close event and open serial port with mpl.rc_context({'toolbar':False}): self.fig = plt.figure() self.serial_port = serial.Serial(port, baud, timeout=0.25,bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, xonxoff=False) self.serial_port.flush() self.fig.canvas.mpl_connect('close_event', self.close_display) self.fig.canvas.mpl_connect('resize_event', self.resize_display) self.fig.canvas.set_window_title('pyIM') # window position is set before state to maximized in update_graph w,h=getVirtualScreenSize() plt.get_current_fig_manager().window.wm_geometry(("+%d+%d"%(w-1,0))) # create timer for updating display using a rs232 polling callback timer = self.fig.canvas.new_timer(interval=250) timer.add_callback(self.update_graphs) # then arg if needed timer.start() # launch figure plt.show(block = True) # close correctly serial port self.close_display()
def splay_figures(): """Get all figures and spread them across my secondary monitor""" fig_list = plt.get_fignums() wx = 640 h = 500 x1, x2, x3 = 1367, 1367 + wx, 1367 + wx*2 y0 = 30 y1 = 570 points = np.array([[x1,y0,wx,h], [x2,y0,wx,h], [x3,y0,wx,h], [x1,y1,wx,h], [x2,y1,wx,h], [x3,y1,wx,h]]) if len(fig_list) == 2: points = points[[2, 5]] if len(fig_list) == 3: points = points[[2, 4, 5]] if len(fig_list) == 4: points = points[[1, 2, 4, 5]] for i in range(len(fig_list)): plt.figure(fig_list[i]) plt.get_current_fig_manager().window.setGeometry( points[i,0],points[i,1], points[i,2], points[i,3])
def plot_su_mu_count_per_addr(self): for i in self.MU_groups: macs = i['addrs'].strip("[").replace("]", "").replace(" ", "").split(",") if len(macs) > 1: for m in macs: self.mu_tx_counter[m] += 1 elif len(macs) == 1: self.su_tx_counter[macs[0]] += 1 plt.style.use("ggplot") plt.clf() N = len(self.mu_tx_counter) ind = np.array(range(0,N)) # the x locations for the groups width = 4.0/N # the width of the bars: can also be len(x) sequence space = 0.01 plt.xlim(0-2*width, N+2*width) p1 = plt.bar(ind, [self.su_tx_counter[j] for j in self.mu_tx_counter], width, color='c') p2 = plt.bar(ind+width+space, [self.mu_tx_counter[j] for j in self.mu_tx_counter], width, color='#ee7722') plt.xticks(ind + space/2.0 + width, ([mac[len(mac)-6:len(mac)-1] for mac in self.mu_tx_counter])) plt.legend((p1, p2), ("SU", "MU")) plt.xlabel("Mac Address") plt.ylabel("Number of NDPAs") try: plt.get_current_fig_manager().window.showMaximized() except: pass plt.show()
def iplot(x, y): """ A simple no-fuss or features interctive plot for debugging. Arguments: - `x`: x value - `y`: y value """ # interactive quick plot plt.figure() plt.ion() plt.clf() plt.plot(x, y, color='black', linestyle='-', # -/--/-./: linewidth=1, # linewidth=1 marker='', # ./o/*/+/x/^/</>/v/s/p/h/H markerfacecolor='black', markersize=0, # markersize=6 label=r"data" # '__nolegend__' ) plt.xscale("linear") plt.yscale("linear") plt.show() plotPosition="+1100+0" # large_screen="+1100+0"; lap="+640+0" plt.get_current_fig_manager().window.wm_geometry(plotPosition)
def test_profile_dirac(): """ Load and plot a 2D dirac """ imname = 'dirac-100.fits' hdu = pyfits.open(imname) im_dirac = hdu[0].data hdr = hdu[0].header xsize = im_dirac.shape[0] ysize = im_dirac.shape[1] xcen = xsize/2 ycen = ysize/2 (r, profile, geometric_area) = extract_profile_generic(im_dirac, xcen, ycen) MAKE_PLOT=True if MAKE_PLOT: print "plotting dirac" plt.figure() plt.ion() plt.clf() plt.plot(r-0.5, profile/geometric_area) plt.xscale("linear") plt.yscale("linear") plt.draw() plt.show() plt.get_current_fig_manager().window.wm_geometry("+1100+0") plt.show()
def my_qunt_plot(qx): fig = plt.figure(figsize=(10, 6)) mpl_agg = plt.get_backend().lower() if 'tk' in mpl_agg: # Option 2 # TkAgg backend manager = plt.get_current_fig_manager() manager.resize(*manager.window.maxsize()) elif 'qt' in mpl_agg: # Option 1 # QT backend manager = plt.get_current_fig_manager() manager.window.showMaximized() elif 'wx' in mpl_agg: # Option 3 # WX backend manager = plt.get_current_fig_manager() manager.frame.Maximize(True) df = pd.read_csv(qx.fn_qxLib, index_col=0, parse_dates=[0]) # ---top.plt # fig = plt.figure(figsize=(20, 15)) ax1 = fig.add_subplot(111) ax1.plot(df['dret'],color='green',label='dret',linewidth=0.5) ax1.legend(loc='upper left') ax2 = ax1.twinx() ax2.plot(df['val'], color='red', label='val', linewidth=2) ax2.legend(loc='upper right') plt.tight_layout() plt.show()
def system_false_alarm_threshold_plot( plotdata, operation_time, threshold, xmin_time, xmax_time, xmajortick_time, xminortick_time, grid_parameter ): ### # # set up for two y axis fig, left_axis = plot.subplots() # right_axis=left_axis.twinx() ### # plot text title = "System false alarm threshold tests" xtitle = "Facility operation time (d)" ytitle = "Threshold (kg)" ### plot.title(title) left_axis.set_xlabel(xtitle) left_axis.set_ylabel(ytitle) # right_axis.set_ylabel() ### # axis xmin = xmin_time xmax = xmax_time # ymin = -0.03 ymax = threshold + 0.03 # xmajortick = xmajortick_time ymajortick = 0.05 # xminortick = xminortick_time yminortick = 0.025 ### plot.xlim(xmin, xmax) left_axis.axis(ymin=ymin, ymax=ymax) # left_axis.xaxis.set_major_locator(MultipleLocator(xmajortick)) left_axis.xaxis.set_minor_locator(MultipleLocator(xminortick)) left_axis.yaxis.set_major_locator(MultipleLocator(ymajortick)) left_axis.yaxis.set_minor_locator(MultipleLocator(yminortick)) # left_axis.tick_params(axis="both", which="major", direction="inout", length=7) ### # grid if grid_parameter == 1: left_axis.grid(which="major", axis="both", linewidth="1.1") # left_axis.grid(which='minor',axis='both') ### # plot left_axis.plot(plotdata[:, 0], plotdata[:, 1], plotdata[:, 0], plotdata[:, 2]) plot.get_current_fig_manager().resize(1024, 800) plot.show() ### # ### save plot.savefig(title) ### return ()
def campaign_plot( plotdata, operation_time, total_campaign, xmin_time, xmax_time, xmajortick_time, xminortick_time, grid_parameter ): ### # # set up for two y axis fig, left_axis = plot.subplots() # right_axis=left_axis.twinx() ### # plot text title = "Total campaigns processed" xtitle = "Facility operation time (d)" ytitle = "Campaigns processed" ### plot.title(title) left_axis.set_xlabel(xtitle) left_axis.set_ylabel(ytitle) # right_axis.set_ylabel() ### # axis xmin = xmin_time xmax = xmax_time # ymin = 0.50 ymax = (total_campaign - 1) + 0.50 # xmajortick = xmajortick_time ymajortick = 2 # xminortick = xminortick_time yminortick = 1 ### plot.xlim(xmin, xmax) left_axis.axis(ymin=ymin, ymax=ymax) # left_axis.xaxis.set_major_locator(MultipleLocator(xmajortick)) left_axis.xaxis.set_minor_locator(MultipleLocator(xminortick)) left_axis.yaxis.set_major_locator(MultipleLocator(ymajortick)) left_axis.yaxis.set_minor_locator(MultipleLocator(yminortick)) # left_axis.tick_params(axis="both", which="major", direction="inout", length=7) ### # grid if grid_parameter == 1: left_axis.grid(which="major", axis="both", linewidth="1.1") # left_axis.grid(which='minor',axis='both') ### # plot left_axis.plot(plotdata[:, 0], plotdata[:, 1]) plot.get_current_fig_manager().resize(1024, 800) plot.show() ### # ### save plot.savefig(title) ### return ()
def system_false_alarm_plot(plotdata, total_campaign, system_false_alarm_counter, grid_parameter): ### # ### This is for the false alarms trigger due to system inspection, not at KMPs # set up for two y axis fig, left_axis = plot.subplots() # right_axis=left_axis.twinx() ### # plot text title = "System false alarms due to inspection" xtitle = "Campaigns processed" ytitle = "False alarms" ### plot.title(title) left_axis.set_xlabel(xtitle) left_axis.set_ylabel(ytitle) # right_axis.set_ylabel() ### # axis xmin = 0.50 xmax = (total_campaign - 1) + 0.50 # ymin = -0.50 ymax = system_false_alarm_counter + 0.50 # xmajortick = 2 ymajortick = 2 # xminortick = 1 yminortick = 1 ### plot.xlim(xmin, xmax) left_axis.axis(ymin=ymin, ymax=ymax) # left_axis.xaxis.set_major_locator(MultipleLocator(xmajortick)) left_axis.xaxis.set_minor_locator(MultipleLocator(xminortick)) left_axis.yaxis.set_major_locator(MultipleLocator(ymajortick)) left_axis.yaxis.set_minor_locator(MultipleLocator(yminortick)) # left_axis.tick_params(axis="both", which="major", direction="inout", length=7) ### # grid if grid_parameter == 1: left_axis.grid(which="major", axis="both", linewidth="1.1") # left_axis.grid(which='minor',axis='both') ### # plot left_axis.plot(plotdata[:, 0], plotdata[:, 1]) plot.get_current_fig_manager().resize(1024, 800) plot.show() ### # ### save plot.savefig(title) ### return ()
def plot_compare_sensors(sensor_names,X_Time,X_Feature,X_names): num_sensors=len(sensor_names) #sensor_name=data_used[k] fig = plt.figure('Compare') fig.suptitle('Compare') for k,sensor_name in enumerate(sensor_names): plt.subplot(num_sensors,1,k+1); plt.plot(X_Time,X_Feature[:,X_names.index(sensor_name)]) plt.title(sensor_name) plt.get_current_fig_manager().window.showMaximized()
def fg(fig=None): """Raise figure to foreground.""" plt.figure((fig or plt.gcf()).number) if plt.get_backend()[0:2].lower() == 'qt': plt.get_current_fig_manager().window.hide() plt.get_current_fig_manager().window.show() plt.get_current_fig_manager().window.activateWindow() plt.get_current_fig_manager().window.raise_() elif plt.get_backend()[0:2].lower() == 'wx': plt.get_current_fig_manager().window.Raise()
def example3(): reader = HDFReader(); [mat, frequencies] = reader.read(TEST_FILE_2) data = np.asarray(mat[CHANNEL_1][EEGA]) # Get EEGA data from selected channel -> unfiltered data from headset # Number of total samplepoints N = data.size # Sample rate # NOTE: When f is obtained from the record (frequencies[EEGA]) this gives ~240 samples/s, # which was calculated at writing the record, but the real fs is 256 samples/s f = 256 T = 1.0 / f # sample interval T = 1/256 = 0.0039 s x = np.linspace(0.0, (N*T), N) # OR: x = np.arange(0, N*T, T) y = signal.detrend(data) fig, ax = plt.subplots(1, 1, squeeze=True, figsize=(16, 5)) mngr = plt.get_current_fig_manager() geom = mngr.window.geometry() left, top, width, height = geom.getRect() mngr.window.setGeometry(200, 30, width, height) ax.set_title('Time domain', fontsize=18) ax.plot(x, y, 'b', linewidth=2) ax.set_xlabel('t [s]') ax.set_ylabel('y') ax.locator_params(axis = 'both', nbins = 5) # frequency content yfft = fft(y, N) # let's take only the positive frequencies and normalize the amplitude yfft = np.abs(yfft) / N freqs = fftfreq(N, 1.0/f) freqs = freqs[0:np.floor(N/2)/2] yfft = yfft[0:np.floor(N/2)/2] fig, ax = plt.subplots(1, 1, squeeze=True, figsize=(16, 4)) mngr = plt.get_current_fig_manager() geom = mngr.window.geometry() left, top, width, height = geom.getRect() mngr.window.setGeometry(200, 520, width, height) ax.set_title('Frequency domain', fontsize=18) ax.plot(freqs, yfft, 'r', linewidth=2) ax.set_xlabel('f [Hz]') ax.set_ylabel('FFT(y)') ax.locator_params(axis = 'both', nbins = 5) plt.tight_layout() plt.grid() plt.show()
def showfig( block=False ): #fig = plt.figure( idx ) fig = plt.gcf() fig.canvas.draw() #fig.canvas.manager.window.move(1200,(idx-1) * 544) #plt.ion() #plt.get_current_fig_manager().window.activateWindow() plt.get_current_fig_manager().window.raise_() if showfigs: if block: plt.show() else: fig.show()
def main_simple_test(): """Simple test of the class DragWedge. 1. make a 2-d plot 2. make a list of random objects and add them to the plot 3. add one more object with initialization at 1st click-and-drag of mouse-left button """ fig, axes, imsh = generate_test_image() list_of_objs = generate_list_of_objects(imsh.get_extent()) obj = DragWedge() # call W/O parameters => object will be initialized at first mouse click add_obj_to_axes(obj, axes, list_of_objs) plt.get_current_fig_manager().window.geometry('+50+10') plt.show()
def do_main() : fname, ampRange = get_input_parameters() arr = get_array_from_file(fname) print 'arr:\n', arr print 'arr.shape=', arr.shape plot_image(arr, zrange=ampRange) plt.get_current_fig_manager().window.move(10,10) plot_histogram(arr,range=ampRange) plt.get_current_fig_manager().window.move(950,10) plt.show()
def main_full_test(): """Full test of the class DragWedge, using the class DragObjectSet 1. make a 2-d plot 2. make a list of random objects and add them to the plot 3. use the class DragObjectSet to switch between Add/Move/Remove modes for full test of the object """ fig, axes, imsh = generate_test_image() list_of_objs = generate_list_of_objects(imsh.get_extent()) t = DragObjectSet(fig, axes, DragWedge, useKeyboard=True) t .set_list_of_objs(list_of_objs) plt.get_current_fig_manager().window.geometry('+50+10') plt.show()
def __init__(self, ifx): self.ifx = ifx # comms interface plt.ion() # allow continuing after show() called drivetrain_img_path = os.path.join( \ os.path.dirname(os.path.abspath(__file__)), \ 'img', 'drivetrain.png') steerwheel_img_path = os.path.join( \ os.path.dirname(os.path.abspath(__file__)), \ 'img', 'steeringwheel_arrow.png') self.drivetrain_img = mpimg.imread(drivetrain_img_path) self.fig, _ = plt.subplots() self.fig.set_facecolor('w') self.steerwheel_img = ndimage.imread(steerwheel_img_path) plt.get_current_fig_manager().resize(1500,750) plt.show()
def StartScope(self, scope): '''Start the scope and define the enviroment.''' self.__fig = plt.figure(); self.__lines = [plt.plot([],[])[0] for i in range(len(self.data))]; plt.xlim(self.__xrange); plt.ylim(self.__yrange); plt.xlabel('x'); plt.title('test'); plt.get_current_fig_manager().window.showMaximized(); __ani = animation.FuncAnimation(self.__fig, UpdateLine, fargs=(self.__lines, scope,), interval=self.interval, blit=True); plt.show();
def show_channels(chmaps, n_cols=8, normalize=None, ofpath=None): """Display multiple channels of 2D images. Parameters ---------- chmaps : numpy.ndarray like The channel maps to be displayed. The shape of `chmaps` should be (n_channels, height, width). n_cols : int, optional The number of channels to be displayed in each row. Default is 8. normalize : None or list/tuple of int, optional If None, each channel will be normalized itself, otherwise all the channels will be uniformly normalized according to this argument, which should be (vmin, vmax). Default is None. ofpath : None or str, optional If None, then the figure will be plotted to a window. Otherwise the figure will be saved to `ofpath`. Default is None. """ n_rows = (chmaps.shape[0] - 1) // n_cols + 1 if n_rows == 1: n_cols = chmaps.shape[0] if normalize is None: vmin, vmax = None, None else: vmin, vmax = normalize fig = plt.figure() grid = AxesGrid(fig, 111, nrows_ncols=(n_rows, n_cols), axes_pad=0.0, share_all=True) for i, chmap in enumerate(chmaps): grid[i].imshow(chmap, vmin=vmin, vmax=vmax) grid.axes_llc.get_xaxis().set_ticks([]) grid.axes_llc.get_yaxis().set_ticks([]) if ofpath is None: plt.get_current_fig_manager().window.showMaximized() plt.show() else: fig.savefig(ofpath) plt.close(fig)
def plot_bar_chart(x_axis,freq,unit,category,rota,font,path): plt.figure(figsize=(26,15)) plt.bar(range(len(freq)),freq, align='center',width=1,color='r') plt.xticks(range(len(x_axis)),x_axis,size='small',fontsize=font,rotation=rota)#size='small' plt.yticks(fontsize=font) if unit=="Ratio": plt.xlabel("VIDEO") plt.ylabel('RATIO (%)') axes = plt.gca() axes.set_ylim([0,100]) else: plt.xlabel(unit) plt.ylabel('Frequency (# Videos)') plt.title("Histogram of "+category+" : "+unit) plt.autoscale(True) plt.get_scale_names() plt.grid(True) figManager = plt.get_current_fig_manager() figManager.window.showMaximized() plt.savefig(path,papertype='letter',orientation='landscape') plt.show() plt.close() return
def show_chart(): mng = mp.get_current_fig_manager() if 'Windows' in platform.system(): mng.window.state('zoomed') else: mng.resize(*mng.window.maxsize()) mp.show()
def ShowLastPos(plt): # Call plt.show but pickles the plot position on window close. When called a second time # it loads the figure to the last position. So matplotlib now remembers figure positions! # This version works for QT and WX backends. backend = matplotlib.get_backend() FigNums = plt.get_fignums() for FigNum in FigNums: plt.figure(FigNum) fig=plt.gcf() fig.canvas.mpl_connect('close_event', RecordLastPos) mgr = plt.get_current_fig_manager() # WX backend if 'WX' in backend: try: with open('CurrentWindowPos%d.pkl'%FigNum, 'r') as f: CurPos = pickle.load(f) mgr.window.SetPosition((CurPos[0], CurPos[1])) mgr.window.SetSize((CurPos[2], CurPos[3])) except: pass # QT backend. elif 'QT' in backend: try: with open('CurrentWindowPos%d.pkl'%FigNum, 'r') as f: CurPos = pickle.load(f) mgr.window.setGeometry(CurPos[0], CurPos[1], CurPos[2], CurPos[3]) except: pass else: print 'Backend ' + backend + ' not supported. Plot figure position will not be sticky.' plt.show()
def __init__(self, *args, **kwargs): super(NuPICPlotOutput, self).__init__(*args, **kwargs) # Turn matplotlib interactive mode on. plt.ion() self.dates = [] self.convertedDates = [] self.value = [] self.allValues = [] self.predicted = [] self.anomalyScore = [] self.anomalyLikelihood = [] self.actualLine = None self.predictedLine = None self.anomalyScoreLine = None self.anomalyLikelihoodLine = None self.linesInitialized = False self._chartHighlights = [] fig = plt.figure(figsize=(16, 10)) gs = gridspec.GridSpec(2, 1, height_ratios=[3, 1]) self._mainGraph = fig.add_subplot(gs[0, 0]) plt.title(self.name) plt.ylabel('KW Energy Consumption') plt.xlabel('Date') self._anomalyGraph = fig.add_subplot(gs[1]) plt.ylabel('Percentage') plt.xlabel('Date') # Maximizes window mng = plt.get_current_fig_manager() mng.resize(*mng.window.maxsize()) plt.tight_layout()
def set_figure_geometry(index): window, n = plt.get_current_fig_manager().window, index+1 ###################################################################### xmax, ymax, dx, dy=5120, 1440, 840, 670 window.setGeometry(xmax-n*dx,ymax-dy,dx,dy) return ###################################################################### try: # attempt to fetch size of monitor from screeninfo import get_monitors xmax, ymax=get_monitors()[0].width, get_monitors()[0].height except: warnings.warn('could not find screeninfo module; run % pip install screeninfo') return # failed to fetch current monitor size # attempt to fetch size of current window if callable(getattr(window,'winfo_width',None)): # Tkagg dx,dy=window.winfo_width(),window.winfo_height() window.wm_geometry('+{}+{}'.format(xmax-n*dx,ymax-dy)) elif callable(getattr(window,'width',None)): # qt{4,5}agg dx,dy=window.width(), window.height() window.setGeometry(xmax-n*dx,ymax-dy,dx,dy) elif getattr(window,'Size',None): # works for wxagg dx,dy=window.Size window.Move(xmax-n*dx, ymax-dy) else: warnings.warn('failed to auto-position matplotlib windows: unknown backend')
def mapEmbeddings2LowDim(indexMap, embeddingsList): filePaths = indexMap.keys() fileNames = [os.path.basename(filePath).split('.')[0] for filePath in filePaths] labels = set(fileNames) labels = zip(labels, numpy.arange(0, len(labels))) labels = [(label, index) for label, index in labels] labels = dict(labels) labels = [labels[fileName] for fileName in fileNames] figure, axises = plt.subplots(1, len(embeddingsList)) for embeddings, axis in zip(embeddingsList, axises): embeddingsCount, embeddingSize = embeddings.shape embeddings = numpy.asarray(embeddings, 'float64') lowDimEmbeddings = tsne.tsne(embeddings, 2, embeddingSize, 20.0, 1000) lowDimEmbeddingsX, lowDimEmbeddingsY = lowDimEmbeddings[:,0], lowDimEmbeddings[:,1] axis.grid() axis.scatter(lowDimEmbeddingsX, lowDimEmbeddingsY, 20, labels) for index, fileName in enumerate(fileNames): axis.annotate(fileName, (lowDimEmbeddingsX[index], lowDimEmbeddingsY[index])) figureManager = plt.get_current_fig_manager() figureManager.resize(*figureManager.window.maxsize()) plt.show()
def show(): wm = plt.get_current_fig_manager() # wm.window.wm_geometry("+0+0") plt.show(block=False)
def makeMap(lonStart=1, lonEnd=5, \ latStart=37, latEnd=47, \ m=None, name='etopo1map', contour=None, cb=None): # Get the etopo1 data etopo1name = '/media/SOLabNFS/store/auxdata/dem/ETOPO1/data/bedrock/grid_registered/netcdf/ETOPO1_Bed_g_gmt4.grd' etopo1 = Dataset(etopo1name, 'r') lons = etopo1.variables["x"][:] lats = etopo1.variables["y"][:] res = findSubsetIndices(latStart, latEnd, lonStart, lonEnd, lats, lons) lon, lat = np.meshgrid(lons[res[0]:res[1]], lats[res[2]:res[3]]) print "Extracted data for area %s : (%s,%s) to (%s,%s)" % ( name, lon.min(), lat.min(), lon.max(), lat.max()) bathy = etopo1.variables["z"][int(res[2]):int(res[3]), int(res[0]):int(res[1])] bathy = laplaceFilter.laplace_filter(bathy, M=None) if lonStart < 0 and lonEnd < 0: lon_0 = -(abs(lonEnd) + abs(lonStart)) / 2.0 else: lon_0 = (abs(lonEnd) + abs(lonStart)) / 2.0 if latStart < 0 and latEnd < 0: lat_0 = -(abs(latEnd) + abs(latStart)) / 2.0 else: lat_0 = (abs(latEnd) + abs(latStart)) / 2.0 print 'Center longitude ', lon_0 print 'Center latitude ', lat_0 if m is None: print("Using default NSPER Basemap \n") # m = Basemap(llcrnrlat=latStart,urcrnrlat=latEnd,\ # llcrnrlon=lonStart,urcrnrlon=lonEnd,\ # rsphere=(6378137.00,6356752.3142),\ # resolution='h',area_thresh=1000.,projection='lcc',\ # lat_1=latStart,lon_0=lon_0) m = Basemap(llcrnrlat=latStart,urcrnrlat=latEnd,\ llcrnrlon=lonStart,urcrnrlon=lonEnd,\ satellite_height=798000, \ resolution='h',area_thresh=1000.,projection='nsper',\ lat_1=latStart,lon_0=lon_0,lat_0=lat_0) x, y = m(lon, lat) if contour is None: levels = [-6000,-5000,-3000, -2000, -1500, -1000, -500, \ -400, -300, -250, -200, -150, -100, -75, -65, -50, -35, \ -25, -15, -10, -5, \ 0, 5, 10, 15, 25, 35, 50, 65, 75, 100, \ 150, 200, 250, 300, 400, 500, 1000, \ 2000, 3000, 5000, 6000] cm = gmtColormap(fileName='GMT_globe', \ GMTPath='/home/mag/Documents/repos/solab/PySOL/cmap_data/') cs = m.contourf(x, y, bathy, levels, cmap=LevelColormap(levels, cmap=cm), alpha=1.0, extend='both') cs.axis = 'tight' # new axis for colorbar. ax = plt.gca() l, b, w, h = ax.get_position().bounds if cb is not None: cax = plt.axes([l - 0.25, b + h * 0.1, 0.025, h * 0.8]) # setup colorbar axes cb = plt.colorbar(cs, cax, orientation='vertical') cb.set_label('Height [m]') # cax = plt.axes([l+w*0.1, b-0.05, w*0.8, 0.025]) # setup colorbar axes # cb = plt.colorbar(cs, cax, orientation='horizontal') plt.axes(ax) # make the original axes current again elif contour is 'land': levels = [0, 5, 10, 15, 25, 35, 50, 65, 75, 100, \ 150, 200, 250, 300, 400, 500, 1000, \ 2000, 3000, 5000, 6000] cm = gmtColormap(fileName='PySOL_land', \ GMTPath='/home/mag/Documents/repos/solab/PySOL/cmap_data/', \ frm='mid') cs = m.contourf(x, y, bathy, levels, cmap=LevelColormap(levels, cmap=cm), alpha=1.0, extend='max') cs.axis = 'tight' # new axis for colorbar. ax = plt.gca() if cb is not None: l, b, w, h = ax.get_position().bounds cax = plt.axes([l - 0.25, b + h * 0.1, 0.025, h * 0.8]) # setup colorbar axes cb = plt.colorbar(cs, cax, orientation='vertical') cb.set_label('Height [m]') # cax = plt.axes([l+w*0.1, b-0.05, w*0.8, 0.025]) # setup colorbar axes # cb = plt.colorbar(cs, cax, orientation='horizontal') plt.axes(ax) # make the original axes current again # cb.ax.yaxis.set_ylabel_position('left') elif contour is 'ocean': levels = [-6000,-5000,-3000, -2000, -1500, -1000, -500, \ -400, -300, -250, -200, -150, -100, -75, -65, -50, -35, \ -25, -15, -10, -5, 0] levels = [-2000, -1600, -1200, -800, -100] cm = gmtColormap(fileName='GMT_ocean', \ GMTPath='/home/mag/Documents/repos/solab/PySOL/cmap_data/', \ to='mid') cs2 = m.contour(x, y, bathy, levels, cmap=LevelColormap(levels, cmap=cm), alpha=1.0, extend='min') cs2.axis = 'tight' plt.clabel(cs2, levels, fmt = '%i', colors = 'k', \ manual=0, inline=0) # m.fillcontinents(color='coral',lake_color='aqua') # m.drawmeridians(arange(round(lons.min(),1),round(lons.max(),1), 0.5), \ # labels=[0,0,0,1], color='k') # m.drawparallels(arange(round(lats.min(),1),round(lats.max(),1), 0.5), \ # labels=[1,0,0,0], color='k') m.drawcoastlines(linewidth=1.25, color='k') m.drawcountries(linewidth=1.25, color='k') # maximizing figure mng = plt.get_current_fig_manager() mng.resize(1920, 1080) plt.draw() #~ plt.show() #~ ipdb.set_trace() name = name.split(' ')[0] # split the name if it has spaces plotfile = '/home/mag/' + str(name) + '_ETOPO1.tiff' plt.savefig(plotfile, facecolor='w', edgecolor='w', \ dpi=300, bbox_inches="tight", pad_inches=0.1)
def main(): # Parse flags config = forge.config() # Restore flags of pretrained model flag_path = osp.join(config.model_dir, 'flags.json') fprint(f"Restoring flags from {flag_path}") pretrained_flags = AttrDict(fet.json_load(flag_path)) pretrained_flags.batch_size = 1 pretrained_flags.gpu = False pretrained_flags.debug = True fet.print_flags() # Fix seeds. Always first thing to be done after parsing the config! torch.manual_seed(0) np.random.seed(0) random.seed(0) # Make CUDA operations deterministic torch.backends.cudnn.deterministic = True torch.backends.cudnn.benchmark = False # Load model model = fet.load(config.model_config, pretrained_flags) model_path = osp.join(config.model_dir, config.model_file) fprint(f"Restoring model from {model_path}") checkpoint = torch.load(model_path, map_location='cpu') model_state_dict = checkpoint['model_state_dict'] model_state_dict.pop('comp_vae.decoder_module.seq.0.pixel_coords.g_1', None) model_state_dict.pop('comp_vae.decoder_module.seq.0.pixel_coords.g_2', None) model.load_state_dict(model_state_dict) fprint(model) # Visualise model.eval() for _ in range(100): y, stats = model.sample(1, pretrained_flags.K_steps) fig, axes = plt.subplots(nrows=4, ncols=1 + pretrained_flags.K_steps) # Generated plot(axes, 0, 0, y, title='Generated scene', fontsize=12) # Empty plots plot(axes, 1, 0, fontsize=12) plot(axes, 2, 0, fontsize=12) plot(axes, 3, 0, fontsize=12) # Put K generation steps in separate subfigures for step in range(pretrained_flags.K_steps): x_step = stats['x_k'][step] m_step = stats['log_m_k'][step].exp() mx_step = stats['mx_k'][step] if 'log_s_k' in stats: s_step = stats['log_s_k'][step].exp() pre = 'Mask x RGB ' if step == 0 else '' plot(axes, 0, 1 + step, mx_step, pre + f'k={step+1}', fontsize=12) pre = 'RGB ' if step == 0 else '' plot(axes, 1, 1 + step, x_step, pre + f'k={step+1}', fontsize=12) pre = 'Mask ' if step == 0 else '' plot(axes, 2, 1 + step, m_step, pre + f'k={step+1}', True, fontsize=12) if 'log_s_k' in stats: pre = 'Scope ' if step == 0 else '' plot(axes, 3, 1 + step, s_step, pre + f'k={step+1}', True, axis=step == 0, fontsize=12) # Beautify and show figure plt.subplots_adjust(wspace=0.05, hspace=0.05) manager = plt.get_current_fig_manager() manager.resize(*manager.window.maxsize()) plt.show()
# gauss_prob.run() # gauss_AEP[i] = gauss_prob['AEP'] # gauss_P1[i] = gauss_prob['wtPower0'][0] # gauss_P2[i] = gauss_prob['wtPower0'][1] # # floris_prob['turbineY'] = np.array([d, 0.]) # floris_prob.run() # floris_AEP[i] = floris_prob['AEP'] # floris_P1[i] = floris_prob['wtPower0'][0] # floris_P2[i] = floris_prob['wtPower0'][1] # i += 1 fig = plt.figure() ax1 = fig.add_subplot(121) ax1.plot(directions, gauss_AEP) ax1.plot(directions, floris_AEP) ax1.legend(labels=['gAEP', 'fAEP'], loc='lower center') ax2 = fig.add_subplot(122) ax2.plot(directions, gauss_P1) ax2.plot(directions, floris_P1) ax3 = fig.add_subplot(122) ax3.plot(directions, gauss_P2) ax3.plot(directions, floris_P2) ax2.legend(['gP1', 'fP1', 'gP2', 'fP2'], loc='lower center') plt.plot() plt.get_current_fig_manager().show() plt.show()
def plot_signals(self): # Create figure self.fig, self.ax = plt.subplots() self.signal = hb.normalize(self.peaks.signal[range(self.peaks.P.data[self.index], self.peaks.T.data[self.index + 1])]) # Determine what cutoff freq to use self.cutoff_freq = 15 if np.mean(np.diff(self.peaks.R.data)) > 2500 else 10 # Pass through a Low pass self.smoothed_signal = hb.lowpass_filter(signal = self.signal, cutoff_freq = self.cutoff_freq) # Calculate first derivative self.first, _ = hb.get_derivatives(self.smoothed_signal) # Plot ECG, Phono and Seismo self.signal_line, = self.ax.plot(range(len(self.signal)), self.signal, linewidth = 0.75, c = "r", label = "ECG") self.smooth_signal_line, = self.ax.plot(range(len(self.signal)), self.smoothed_signal, linewidth = 1, c = "b", label = "Low Pass ECG") self.first_line, = self.ax.plot(range(len(self.signal)), 1 + 5*self.first, '--', linewidth = 0.5, c = 'k', label = "ECG 1st Derv.") self.ax.set_xlim(0, len(self.signal)) sig_min = min(self.signal) sig_max = max(self.signal) self.ax.set_ylim(sig_min - 0.2*(sig_max - sig_min), sig_max + 0.2*(sig_max - sig_min)) plt.legend(loc='upper right') # T Peak self.T_point = self.ax.scatter(self.peaks.T.data[self.index] - self.peaks.P.data[self.index], self.smoothed_signal[self.peaks.T.data[self.index] - self.peaks.P.data[self.index]], c = '#9467bd') self.T_text = self.ax.text(self.peaks.T.data[self.index] - self.peaks.P.data[self.index], self.smoothed_signal[self.peaks.T.data[self.index] - self.peaks.P.data[self.index]] + 0.2, "T", fontsize=9, horizontalalignment = 'center') # ST Start Peak self.ST_start_point = self.ax.scatter(self.peaks.ST_start.data[self.index] - self.peaks.P.data[self.index], self.smoothed_signal[self.peaks.ST_start.data[self.index] - self.peaks.P.data[self.index]], c = 'y') self.ST_start_text = self.ax.text(self.peaks.ST_start.data[self.index] - self.peaks.P.data[self.index], self.smoothed_signal[self.peaks.ST_start.data[self.index] - self.peaks.P.data[self.index]] + 0.2, "ST Start", fontsize=9, horizontalalignment = 'center') # T'max Peak self.dT_point = self.ax.scatter(self.peaks.dT.data[self.index] - self.peaks.P.data[self.index], self.smoothed_signal[self.peaks.dT.data[self.index] - self.peaks.P.data[self.index]], c = '#2ca02c') self.dT_text = self.ax.text(self.peaks.dT.data[self.index] - self.peaks.P.data[self.index], self.smoothed_signal[self.peaks.dT.data[self.index] - self.peaks.P.data[self.index]] + 0.2, "T'max", fontsize=9, horizontalalignment = 'center') # # T''max Peak # self.ddT_point = self.ax.scatter(self.peaks.ddT.data[self.index] - self.peaks.P.data[self.index], self.smoothed_signal[self.peaks.ddT.data[self.index] - self.peaks.P.data[self.index]], c = '#2ca02c') # self.ddT_text = self.ax.text(self.peaks.ddT.data[self.index] - self.peaks.P.data[self.index], self.smoothed_signal[self.peaks.ddT.data[self.index] - self.peaks.P.data[self.index]] + 0.2, "T''max", fontsize=9, horizontalalignment = 'center') # Initalize axes and data points self.x = range(len(self.signal)) self.y = self.smoothed_signal # Cross hairs self.lx = self.ax.axhline(color='k', linewidth=0.2) # the horiz line self.ly = self.ax.axvline(color='k', linewidth=0.2) # the vert line # Add data left_shift = 0.45 start = 0.96 space = 0.04 self.ax.text(0.01, start, transform = self.ax.transAxes, s = "Folder: " + self.folder_name, fontsize=12, horizontalalignment = 'left') self.ax.text(0.01, start - space, transform = self.ax.transAxes, s = "Dosage: " + str(self.dosage), fontsize=12, horizontalalignment = 'left') self.i_text = self.ax.text(0.60 - left_shift, 1.1 - space, transform = self.ax.transAxes, s = "Heartbeat: " + str(self.index + 1) + "/" + str(len(self.peaks.R.data) - 1), fontsize=12, horizontalalignment = 'left') # Add index buttons ax_prev = plt.axes([0.575 - left_shift, 0.9, 0.1, 0.075]) self.bprev = Button(ax_prev, 'Previous') self.bprev.on_clicked(self.prev) ax_next = plt.axes([0.8 - left_shift, 0.9, 0.1, 0.075]) self.b_next = Button(ax_next, 'Next') self.b_next.on_clicked(self.next) self.fig.canvas.mpl_connect('motion_notify_event', self.mouse_move) self.fig.canvas.mpl_connect('button_press_event', self.on_click) self.fig.canvas.mpl_connect('button_release_event', self.off_click) # Add Sliders start = 0.91 slider_width = 0.0075 slider_height = 0.47 self.cutoff_amp_slider = Slider(plt.axes([0.05, 0.15, 2*slider_width, slider_height]), label = "Cutoff (Hz)", valmin = 1, valmax = 50, valinit = self.cutoff_freq, orientation = 'vertical', valfmt='%0.0f') self.cutoff_amp_slider.label.set_size(8) self.cutoff_amp_slider.on_changed(self.switch_signal) self.signal_amp_slider = Slider(plt.axes([start, 0.15, slider_width, slider_height]), label = "ECG\n\nA", valmin = 0.01, valmax = 10, valinit = 1, orientation = 'vertical') self.signal_amp_slider.label.set_size(8) self.signal_amp_slider.on_changed(self.switch_signal) self.signal_amp_slider.valtext.set_visible(False) self.first_height_slider = Slider(plt.axes([start + 2*slider_width, 0.15, slider_width, slider_height]), label = " 1st\n Derv.\nH", valmin = 1.5 * min(self.signal), valmax = 1.5 * max(self.signal), valinit = 0, orientation = 'vertical') self.first_height_slider.label.set_size(8) self.first_height_slider.on_changed(self.switch_signal) self.first_height_slider.valtext.set_visible(False) self.first_amp_slider = Slider(plt.axes([start + 3*slider_width, 0.15, slider_width, slider_height]), label = "\nA", valmin = 0.01, valmax = 10, valinit = 1, orientation = 'vertical') self.first_amp_slider.label.set_size(8) self.first_amp_slider.on_changed(self.switch_signal) self.first_amp_slider.valtext.set_visible(False) # Maximize frame mng = plt.get_current_fig_manager() mng.full_screen_toggle() plt.show()
########################################################################### if saveFigs: complexIQ_V = Idata + 1j * Qdata # FFT to the frequency domain N = len(complexIQ_V) nextpow2 = int(np.log2(N)) + 1 NFFT = 2**nextpow2 powerComplexFreq_W = np.abs( np.fft.fftshift(np.fft.fft(complexIQ_V, NFFT)))**2 / NFFT / 100.0 freqPower = np.fft.fftshift(np.fft.fftfreq(NFFT, dt_s)) # Produce an amplitude plot powerComplexFreq_dBm = 10.0 * np.log10(powerComplexFreq_W) + 30.0 fig = plt.figure() mngr = plt.get_current_fig_manager() mngr.window.setGeometry(10, 35, 10.73 * fig.dpi, 9.9 * fig.dpi) plt.plot(freqPower, powerComplexFreq_dBm, 'b-') plt.title('Power Spectrum\n' + 'Setting = ' + str(setting_dB) + ' dB', fontsize=24) plt.xlabel('frequency (Hz)', fontsize=20) plt.ylabel('amplitude (dBV)', fontsize=20) plt.tick_params(axis='both', which='major', labelsize=18) plt.tick_params(axis='both', which='minor', labelsize=16) # plt.ylim([-90, -40]) plt.grid() figName = str(int(setting_dB)) + '_Amplitude_Spectra.png' path = os.path.split(basename)[0] path = os.path.split(path)[0] fig.savefig(os.path.join(path, figName), dpi=600)
def plot_tracks(fig, ax, ax2, track_list, meas_list_cam, meas_list, lidar_labels, lidar_labels_valid, image, camera, configs_det, state=None): # plot image ax.cla() ax2.cla() ax2.imshow(image) # plot tracks, measurements and ground truth in birds-eye view for track in track_list: if state == None or track.state == state: # plot e.g. only confirmed tracks # choose color according to track state if track.state == 'confirmed': col = 'green' elif track.state == 'tentative': col = 'orange' else: col = 'red' # get current state variables w = track.width h = track.height l = track.length x = track.x[0] y = track.x[1] z = track.x[2] yaw = track.yaw # plot boxes in top view point_of_rotation = np.array([w / 2, l / 2]) rec = plt.Rectangle( -point_of_rotation, width=w, height=l, color=col, alpha=0.2, transform=Affine2D().rotate_around(*(0, 0), -yaw) + Affine2D().translate(-y, x) + ax.transData) ax.add_patch(rec) # write track id for debugging ax.text(float(-track.x[1]), float(track.x[0] + 1), str(track.id)) if track.state == 'initialized': ax.scatter(float(-track.x[1]), float(track.x[0]), color=col, s=80, marker='x', label='initialized track') elif track.state == 'tentative': ax.scatter(float(-track.x[1]), float(track.x[0]), color=col, s=80, marker='x', label='tentative track') elif track.state == 'confirmed': ax.scatter(float(-track.x[1]), float(track.x[0]), color=col, s=80, marker='x', label='confirmed track') # project tracks in image # transform from vehicle to camera coordinates pos_veh = np.ones((4, 1)) # homogeneous coordinates pos_veh[0:3] = track.x[0:3] pos_sens = camera.veh_to_sens * pos_veh # transform from vehicle to sensor coordinates x = pos_sens[0] y = pos_sens[1] z = pos_sens[2] # compute rotation around z axis R = np.matrix([[np.cos(yaw), np.sin(yaw), 0], [-np.sin(yaw), np.cos(yaw), 0], [0, 0, 1]]) # bounding box corners x_corners = [ -l / 2, l / 2, l / 2, l / 2, l / 2, -l / 2, -l / 2, -l / 2 ] y_corners = [ -w / 2, -w / 2, -w / 2, w / 2, w / 2, w / 2, w / 2, -w / 2 ] z_corners = [ -h / 2, -h / 2, h / 2, h / 2, -h / 2, -h / 2, h / 2, h / 2 ] # bounding box corners_3D = np.array([x_corners, y_corners, z_corners]) # rotate corners_3D = R * corners_3D # translate corners_3D += np.array([x, y, z]).reshape((3, 1)) # print ( 'corners_3d', corners_3D) # remove bounding boxes that include negative x, projection makes no sense if np.any(corners_3D[0, :] <= 0): continue # project to image in_fov = True corners_2D = np.zeros((2, 8)) for k in range(8): if not camera.in_fov(corners_3D[:, k]): in_fov = False corners_2D[0, k] = camera.c_i - camera.f_i * corners_3D[ 1, k] / corners_3D[0, k] corners_2D[1, k] = camera.c_j - camera.f_j * corners_3D[ 2, k] / corners_3D[0, k] # print ( 'corners_2d', corners_2D) # edges of bounding box in vertex index from above, e.g. index 0 stands for [-l/2, -w/2, -h/2] draw_line_indices = [ 0, 1, 2, 3, 4, 5, 6, 7, 0, 5, 4, 1, 2, 7, 6, 3 ] paths_2D = np.transpose(corners_2D[:, draw_line_indices]) # print ( 'paths_2D', paths_2D) codes = [Path.LINETO] * paths_2D.shape[0] codes[0] = Path.MOVETO path = Path(paths_2D, codes) # plot bounding box in image p = patches.PathPatch(path, fill=False, color=col, linewidth=3) if in_fov: ax2.add_patch(p) # plot labels for label, valid in zip(lidar_labels, lidar_labels_valid): if valid: ax.scatter(-1 * label.box.center_y, label.box.center_x, color='gray', s=80, marker='+', label='ground truth') # plot measurements for meas in meas_list: ax.scatter(-1 * meas.z[1], meas.z[0], color='blue', marker='.', label='measurement') # PLOT MEAS LIST CAM for meas in meas_list_cam: x = meas.z[0] y = meas.z[1] ax2.scatter(x, y, color='yellow', marker='.', label='measurement') # maximize window mng = plt.get_current_fig_manager() #mng.resize(*mng.window.maxsize()) mng.resize(1280, 720) #mng.window.showMaximized() #mng.frame.Maximize(True) # axis ax.set_xlabel('y [m]') ax.set_ylabel('x [m]') ax.set_aspect('equal') ax.set_ylim( configs_det.lim_x[0], configs_det.lim_x[1]) # x forward, y left in vehicle coordinates ax.set_xlim(-configs_det.lim_y[1], -configs_det.lim_y[0]) # correct x ticks (positive to the left) ticks_x = ticker.FuncFormatter(lambda x, pos: '{0:g}'.format(-x) if x != 0 else '{0:g}'.format(x)) ax.xaxis.set_major_formatter(ticks_x) # remove repeated labels handles, labels = ax.get_legend_handles_labels() handle_list, label_list = [], [] for handle, label in zip(handles, labels): if label not in label_list: handle_list.append(handle) label_list.append(label) ax.legend(handle_list, label_list, loc='center left', shadow=True, fontsize='x-large', bbox_to_anchor=(0.8, 0.5)) plt.pause(0.01) return fig, ax, ax2
# load the start state from a file fin = open(argv[1]) row = 0 for line in fin: if row is 0: NROWS = int(line.split(' ')[0]) NCOLS = int(line.split(' ')[1]) S = np.zeros((NROWS, NCOLS)) else: for i in range(0, NCOLS): if line[i] != '0': S[row, i] = 1 if row is NROWS: break row += 1 # set up the visualization fig = pyplot.figure() cmap = mpl.colors.ListedColormap(['white', 'black']) bounds = [0, 0, 1, 1] norm = mpl.colors.BoundaryNorm(bounds, cmap.N) mng = pyplot.get_current_fig_manager() mng.resize(*mng.window.maxsize()) #begin the game loop pyplot.imshow(S, interpolation='nearest', cmap=cmap, norm=norm) G_MAX = int(argv[2]) a = animation.FuncAnimation(fig, generation, repeat=True, interval=10) pyplot.show()
def visualize_map(self): fig = plt.figure() # plt.switch_backend('TkAgg') mng = plt.get_current_fig_manager(); mng.resize(*mng.window.maxsize()) plt.ion(); plt.imshow(self._occupancy_map, cmap='Greys'); plt.axis([0, 800, 0, 800]); plt.draw() plt.pause(0)
def drawPTBox(datapoints, figName='', markings={}, maximized=True, saveFiguresToFile=False): ''' Draws time/stops figure. All datapoints MUST be from the same date! :param datapoints: list :param figName: :param markings: dictionary {unique_key: cluster} dictionary {cluster_num: [unique_keys_of_datapoints]} # when empty clusters will not be shown :return: ''' estavl = 'est' #print('Total data points:', len(datapoints)) datapoints = sorted(datapoints, key=lambda x: (x['gtfsTripID'], x['sequence'])) lines_planned = [] lines_actual = [] minseq = sys.maxsize maxseq = 0 mintime = sys.maxsize maxtime = 0 maxload = 60 #getMaxLoad(datapoints) #60 #np.percentile([dp['load'] for dp in datapoints], 98) #print('Max load:', maxload) tripIds = set() clustered_dots = {} for i, g in itertools.groupby(datapoints, key=lambda x: x['gtfsTripID']): tripIds.add(i) lineP = [] lineA = [] for dp in g: key = unique_key(dp) if key in markings: cluster = markings[key] curdots = clustered_dots.get(cluster, []) curdots.append( (dp['{}Arrival'.format(estavl)] / 3600, dp['sequence'])) clustered_dots[cluster] = curdots if minseq > dp['sequence']: minseq = dp['sequence'] if maxseq < dp['sequence']: maxseq = dp['sequence'] mintime = min(mintime, dp['{}Arrival'.format(estavl)], dp['{}Departure'.format(estavl)], dp['gtfsArrival']) maxtime = max(maxtime, dp['{}Arrival'.format(estavl)], dp['{}Departure'.format(estavl)], dp['gtfsArrival']) #checks: # if dp['estArrival'] - dp['gtfsArrival'] != dp['estArrivalDelay']: # print('UNEQUAL ARRIVAL:', dp) # if dp['estDeparture'] - dp['gtfsDeparture'] != dp['estDepartureDelay']: # print('UNEQUAL DEPARTURE:', dp) load = min(1.0, dp['load'] / maxload) lineA.append( (dp['{}Arrival'.format(estavl)] / 3600, dp['sequence'], load)) lineA.append((dp['{}Departure'.format(estavl)] / 3600, dp['sequence'], load)) lineP.append((dp['gtfsArrival'] / 3600, dp['sequence'], 0.8)) lines_actual.append(lineA) lines_planned.append(lineP) #print('Trip IDs:', tripIds) #======================================== #===== plotting #======================================== def tocmap( c ): # readjusting the colors to fit half of the scale of 'brg' colormap in mpl return 0.5 + (1 - c) / 2 fig, axs = plt.subplots(figsize=(16.0, 10.0)) norm = plt.Normalize(0, 1) def getClusterColors(cluster): ''' :param cluster: either just cluster marking as integer, or (marking, blob_number) :return: (color, marker) ''' if isinstance(cluster, int): cluster_colors = { -1: 'cx', 0: 'g+', 1: 'k^', 2: 'bo', 3: 'ms', 4: 'r*' } #, 3: 'cx', 4: 'm^', 5: 'y^', 6: 'r^'} # 'c', 'm', 'y', 'k' #cluster_colors = {0: 'g+', 1: 'bo', 2: 'ks'} cc = cluster_colors[cluster] return cc[0], cc[1] elif len(cluster) == 2: markers = {-1: 'x', 0: '+', 1: 's', 2: 'o', 3: '^', 4: '*'} marker = markers[cluster[0]] colors = { -1: 'g', 0: 'k', 1: 'b', 2: 'm', 3: 'y', 4: 'r', 5: 'xkcd:violet', 6: 'tab:orange', 7: 'tab:pink', 8: 'xkcd:gold', 9: 'xkcd:chartreuse', 10: 'xkcd:azure', 11: 'xkcd:pastel blue', 12: 'xkcd:aqua blue', 13: 'xkcd:greyish purple', 14: 'xkcd:bland' } color = colors[cluster[1] if cluster[1] < 0 else cluster[1] % (len(colors) - 1)] return color, marker else: print( 'ERROR! Wrong cluster assignment for htmPlotting.drawPTBox: ', cluster) exit(-1) for cluster, dots in clustered_dots.items(): color, marker = getClusterColors(cluster) x, y = zip(*dots) axs.plot(x, y, color=color, marker=marker, linestyle='None') for color, cmap, width, lines in [ \ ('b','Blues', 1, lines_planned), \ ('r', 'brg', 2, lines_actual) \ ]: for line in lines: x, y, colors = list(zip(*line)) colors = [tocmap(c) for c in colors] # plt.plot(x, y, color=color) points = np.array([x, y]).T.reshape(-1, 1, 2) segments = np.concatenate([points[:-1], points[1:]], axis=1) lc = LineCollection(segments, cmap=cmap, norm=norm) # 'viridis' lc.set_array(np.array(colors)) lc.set_linewidth(width) axs.add_collection(lc) def calctime(mintime, maxtime, step): '''calculates good time window to show in graph''' mint_tmp = mintime / 3600 maxt_tmp = maxtime / 3600 mint = int(mint_tmp / step) * step maxt = int(maxt_tmp / step) * step if (mint + step - mint_tmp < step * 0.06): mint = mint + step if maxt_tmp - maxt > step * 0.06: maxt += step return mint, maxt, step # #full # xst, xfin, xstep = 5.5, 25, 0.5 #yst, yfin, ystep = 1, 20, 1 xst, xfin, xstep = calctime(mintime, maxtime, 0.5) yst, yfin, ystep = minseq, maxseq, 1 plt.axis([xst, xfin, yst, yfin]) plt.xticks(np.arange(xst, xfin, xstep)) xticks = axs.get_xticks().tolist() for i in range(len(xticks)): xticks[i] = '{}:{}'.format( int(xticks[i] % 24), '30' if (abs(xticks[i] - int(xticks[i])) > 0.4) else '00') axs.set_xticklabels(xticks) plt.yticks(np.arange(yst, yfin, ystep)) plt.grid(axis='y', linestyle='-', linewidth=0.3) plt.xlabel('Time') plt.ylabel('Stops sequence') plt.title(figName) if saveFiguresToFile: filename = "./resources/figures/{}.png".format(figName) if not os.path.exists(os.path.dirname(filename)): os.makedirs(os.path.dirname(filename)) plt.savefig(filename) plt.close() else: fig = plt.gcf() fig.canvas.set_window_title(figName) if maximized: figManager = plt.get_current_fig_manager() figManager.window.showMaximized() plt.show(block=True)
def plot_max(): figManager = plt.get_current_fig_manager() figManager.window.showMaximized() plt.show()
z2D = np.column_stack( (temp == 0, temp == 1, temp == 2)) # One-hot encoding (.astype(int)) #plt.figure() #plt.get_current_fig_manager().window.wm_geometry("1400x760+20+20") #disp2DResult(x2D, z2D,0) #w_factor = 0.1 #draw_ellipse(m0, C0, alpha=pi0 * w_factor, color='r') #draw_ellipse(m1, C1, alpha=pi1 * w_factor, color='g') #draw_ellipse(m2, C2, alpha=pi2 * w_factor, color='b') #plt.show() #----------------------------------------------------------------------------------------------------------------------- # 1) K-means algorithm plt.figure() plt.get_current_fig_manager().window.wm_geometry("1400x760+20+20") gs = gridspec.GridSpec(2, 2) gs.update(wspace=0.05, hspace=0.3) print("------------------------- K-means algorithm -------------------------") clust_center = [] for k in range(2, 6): print("k = ", k) colors = iter(cm.rainbow(np.linspace(0, 1, k))) kmean_h = KMeans(n_clusters=k, n_init=10).fit(x2D) clust_center.append(kmean_h.cluster_centers_) curr_clust = getEmpProbTable(3, k, z2D, kmean_h.labels_, prob_z) plt.subplot(gs[k - 2]) disp2DResult(x2D, curr_clust, 0)
cax[1].set_array(p[:-1, :-1].flatten()) # update main text # txt.set_text('step = %4d' % (n)) # txt.set_text('n = %4d \ndt = %.8f' % (n, dt)) txt.set_text('n = %4d \nL = %.8f' % (n, L)) # animation # ------------------------------------------------------ anim = FuncAnimation(fig, animate, frames=1000, interval=10, repeat=False) # show maximized figure # ------------------------------------------------------ figManager = plt.get_current_fig_manager() figManager.window.showMaximized() plt.show() # # 3D projection (only final step) # # ------------------------------------------------------ # from mpl_toolkits.mplot3d import Axes3D # X, Y = np.meshgrid(x, y) # fig3d = plt.figure(figsize=(11, 7), dpi=100) # axs3d = fig3d.gca(projection='3d') # surf = axs3d.plot_surface(X, Y, p, rstride=1, cstride=1, cmap=cm.viridis, linewidth=0, antialiased=False) # # for array testing # # ------------------------------------------------------
def on_pushButton_Lambda1_clicked(self): self.figBlue() # Set the absolute position of the figure on the screen: # plt.get_current_fig_manager().window.setGeometry(<x-pos>,<y-pos>,<width>,<height>) plt.get_current_fig_manager().window.setGeometry(0, 0, 300, 300) plt.show(self.figB)
def plot_rmse(manager, all_labels): fig, ax = plt.subplots() plot_empty = True # loop over all tracks for track_id in range(manager.last_id + 1): rmse_sum = 0 cnt = 0 rmse = [] time = [] # loop over timesteps for i, result_dict in enumerate(manager.result_list): label_list = all_labels[i] if track_id not in result_dict: continue track = result_dict[track_id] if track.state != 'confirmed': continue # find closest label and calculate error at this timestamp min_error = np.inf for label, valid in zip(label_list[0], label_list[1]): error = 0 if valid: error += (label.box.center_x - float(track.x[0]))**2 error += (label.box.center_y - float(track.x[1]))**2 error += (label.box.center_z - float(track.x[2]))**2 if error < min_error: min_error = error if min_error < np.inf: error = np.sqrt(min_error) time.append(track.t) rmse.append(error) rmse_sum += error cnt += 1 # calc overall RMSE if cnt != 0: plot_empty = False rmse_sum /= cnt # plot RMSE ax.plot(time, rmse, marker='x', label='RMSE track ' + str(track_id) + '\n(mean: ' + '{:.2f}'.format(rmse_sum) + ')') # maximize window mng = plt.get_current_fig_manager() #mng.window.showMaximized() mng.resize(1280, 720) #mng.frame.Maximize(True) ax.set_ylim(0, 1) if plot_empty: print('No confirmed tracks found to plot RMSE!') else: plt.legend(loc='center left', shadow=True, fontsize='x-large', bbox_to_anchor=(0.9, 0.5)) plt.xlabel('time [s]') plt.ylabel('RMSE [m]') plt.show()
for dataset_label in dataset_labels: fname_data = os.path.join(dirREPO, 'Data', 'ExperimentalData', '%s.csv' % dataset_label) y0, y1 = load_csv(fname_data) s0, s1 = y0.std(axis=0, ddof=1), y1.std(axis=0, ddof=1) n0, n1 = y0.shape[0], y1.shape[0] s = np.sqrt(((n0 - 1) * s0**2 + (n1 - 1) * s1**2) / (n0 + n1 - 2)) # s = np.sqrt(s0**2 + s1**2) # s = (s - s.min()) / (s.max()-s.min()) sd0.append(s0) sd1.append(s1) sdp.append(s) plt.close('all') fig, AX = plt.subplots(2, 3, figsize=(10, 5)) plt.get_current_fig_manager().window.move(0, 0) for i, (ax, s0, s1, sp) in enumerate(zip(AX.flatten(), sd0, sd1, sdp)): x = np.linspace(0, 1, sp.size) h0 = ax.plot(x, s0, color='0.5', lw=0.5)[0] h1 = ax.plot(x, s1, color='0.5', lw=0.5)[0] hp = ax.plot(x, sp, color='0.0', lw=2)[0] ax.text(0.05, 0.92, '(%s) %s' % (chr(97 + i), dataset_labels[i]), transform=ax.transAxes) ax.set_ylabel(f'SD ({unitstrs[i]})') ax.set_facecolor('1.0') ax.grid(False) AX[0, 0].legend([h0, hp], ['Sample', 'Pooled'])
def __init__(self, f1, f2, title = None, figsize = None): print(f1.filename()) print(f2.filename()) self._choice = None assert isinstance(f1, Photo) assert isinstance(f2, Photo) if figsize is None: figsize = [20, 12] fig = plt.figure(figsize=figsize) h = 10 ax11 = plt.subplot2grid((h,2), (0,0), rowspan = h - 1) ax12 = plt.subplot2grid((h,2), (0,1), rowspan = h - 1) ax21 = plt.subplot2grid((h,6), (h - 1, 1)) ax22 = plt.subplot2grid((h,6), (h - 1, 4)) kwargs = dict(s = f1.filename(), ha = 'center', va = 'center', fontsize=20) kwargs2 = dict(s = f2.filename(), ha = 'center', va = 'center', fontsize=20) ax21.text(0.5, 0.5, **kwargs) ax22.text(0.5, 0.5, **kwargs2) self._fig = fig self._ax_select_left = ax21 self._ax_select_right = ax22 fig.subplots_adjust( left = 0.02, bottom = 0.02, right = 0.98, top = 0.98, wspace = 0.05, hspace = 0, ) f1._read_and_downsample() f2._read_and_downsample() ax11.imshow(f1.data()) ax12.imshow(f2.data()) for ax in [ax11, ax12, ax21, ax22]: ax.set_xticklabels([]) ax.set_yticklabels([]) ax.set_xticks([]) ax.set_yticks([]) self._attach_callbacks() if title: fig.suptitle(title, fontsize=20) mng = plt.get_current_fig_manager() mng.full_screen_toggle() plt.show()
left_axis.annotate(annotate_title,xy=(annotate_x,annotate_y),xytext=(annotate_x,annotate_y),fontsize=annotate_fontsize) left_axis.annotate(annotate_title2,xy=(annotate_x2,annotate_y2),xytext=(annotate_x2,annotate_y2),fontsize=annotate_fontsize) left_axis.annotate(annotate_title3,xy=(annotate_x3,annotate_y3),xytext=(annotate_x3,annotate_y3),fontsize=annotate_fontsize) left_axis.annotate(annotate_title4,xy=(annotate_x4,annotate_y4),xytext=(annotate_x4,annotate_y4),fontsize=annotate_fontsize) # ####### # # plot data # left_axis.plot(plot_data[:,0],plot_data[:,1],marker='o',color=line_color0,label=curve_text0,linewidth=curve_linewidth,markersize=20) left_axis.plot(plot_data[:,0],plot_data[:,3],marker='o',color=line_color1,label=curve_text1,linewidth=curve_linewidth,markersize=20) left_axis.plot(plot_data[:,0],plot_data[:,5],marker='o',color=line_color2,label=curve_text2,linewidth=curve_linewidth,markersize=20) left_axis.plot(plot_data[:,0],plot_data[:,7],marker='o',color=line_color3,label=curve_text3,linewidth=curve_linewidth,markersize=20) left_axis.plot(plot_data[:,0],plot_data[:,9],marker='o',color=line_color4,label=curve_text4,linewidth=curve_linewidth,markersize=20) left_axis.legend(loc=legend_location,fontsize=legend_font) #legend needs to be after all the plot data plot.get_current_fig_manager().resize(width,height) plot.gcf().set_size_inches((0.01*width),(0.01*height)) # ####### # # save # plot.savefig(title,dpi=current_dpi) # ####### # # plot to screen # # plot.show() # ########################################################################
def plot(self, variable=None, vmin=None, vmax=None, filename=None, title=None): """Plot geographical coverage of reader.""" try: from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt from matplotlib.patches import Polygon except: sys.exit('Basemap is needed to plot coverage map.') corners = self.xy2lonlat([self.xmin, self.xmin, self.xmax, self.xmax], [self.ymax, self.ymin, self.ymax, self.ymin]) latspan = np.max(corners[1]) - np.min(corners[1]) # Initialise map if latspan < 90: # Stereographic projection centred on domain, if small domain x0 = (self.xmin + self.xmax) / 2 y0 = (self.ymin + self.ymax) / 2 lon0, lat0 = self.xy2lonlat(x0, y0) width = np.max([self.xmax - self.xmin, self.ymax - self.ymin ]) * 1.5 geod = pyproj.Geod(ellps='WGS84') # Calculate length of dialogs to determine map size d1 = geod.inv(corners[0][0], corners[1][0], corners[0][1], corners[1][1], radians=False)[2] d2 = geod.inv(corners[0][2], corners[1][2], corners[0][3], corners[1][3], radians=False)[2] width = np.max((d1, d2)) * 3 map = Basemap(projection='stere', resolution='i', lat_ts=lat0, lat_0=lat0, lon_0=lon0, width=width, height=width) else: # Global map if reader domain is large map = Basemap(np.array(corners[0]).min(), -89, np.array(corners[0]).max(), 89, resolution='c', projection='cyl') map.drawcoastlines() if variable is None: map.fillcontinents(color='coral') map.drawparallels(np.arange(-90., 90., 5.)) map.drawmeridians(np.arange(-180., 181., 5.)) # Get boundary npoints = 10 # points per side x = np.array([]) y = np.array([]) x = np.concatenate((x, np.linspace(self.xmin, self.xmax, npoints))) y = np.concatenate((y, [self.ymin] * npoints)) x = np.concatenate((x, [self.xmax] * npoints)) y = np.concatenate((y, np.linspace(self.ymin, self.ymax, npoints))) x = np.concatenate((x, np.linspace(self.xmax, self.xmin, npoints))) y = np.concatenate((y, [self.ymax] * npoints)) x = np.concatenate((x, [self.xmin] * npoints)) y = np.concatenate((y, np.linspace(self.ymax, self.ymin, npoints))) # from x/y vectors create a Patch to be added to map lon, lat = self.xy2lonlat(x, y) mapproj = pyproj.Proj(map.proj4string) # Cut at 89 deg N/S to avoid singularity at poles lat[lat > 89] = 89 lat[lat < -89] = -89 xm, ym = mapproj(lon, lat) xm, ym = map(lon, lat) #map.plot(xm, ym, color='gray') if variable is None: boundary = Polygon(zip(xm, ym), alpha=0.5, ec='k', fc='b') plt.gca().add_patch(boundary) # add patch to the map if title is None: plt.title(self.name) else: plt.title(title) plt.xlabel('Time coverage: %s to %s' % (self.start_time, self.end_time)) if variable is not None: rx = np.array([self.xmin, self.xmax]) ry = np.array([self.ymin, self.ymax]) data = self.get_variables(variable, self.start_time, rx, ry, block=True) rx, ry = np.meshgrid(data['x'], data['y']) rlon, rlat = self.xy2lonlat(rx, ry) map_x, map_y = map(rlon, rlat, inverse=False) data[variable] = np.ma.masked_invalid(data[variable]) if hasattr(self, 'convolve'): from scipy import ndimage N = self.convolve if isinstance(N, (int, np.integer)): kernel = np.ones((N, N)) kernel = kernel / kernel.sum() else: kernel = N logging.debug('Convolving variables with kernel: %s' % kernel) data[variable] = ndimage.convolve(data[variable], kernel, mode='nearest') map.pcolormesh(map_x, map_y, data[variable], vmin=vmin, vmax=vmax) cbar = map.colorbar() cbar.set_label(variable) try: # Activate figure zooming mng = plt.get_current_fig_manager() mng.toolbar.zoom() except: pass if filename is not None: plt.savefig(filename) plt.close() else: plt.show()
def store_library(file, sample, gdl1, gdl2, spec, ref, thickness, gdl_age, comment, frame): # read datafile df_input = pd.read_csv(file, sep='\t', decimal=',', encoding='cp1252', error_bad_lines=False) # round dataframa values df_input.round(6) # format dataframe # deleting unnecessary columns df_input.drop(df_input.columns[[ -1, ]], axis=1, inplace=True) # rename columns of remaining dataframe df_input.rename(columns={ df_input.iloc[0, 0]: 'date', 'Uhrzeit': 'time', 'Kommentar': 'measurement', 'p_Probe_Ist / bar': 'pressure_sample[bar]', 'I_Ist / mA': 'current[mA]', 'U_ges / mV': 'voltage[mV]', 'U_Nadel / mV': 'voltage_needle[mV]', 'U_ges-Th_U': 'voltage_th[mV]', 'U_Nadel-Th_U': 'voltage_needle_th[mV]', 'Anpressfläche / cm²': 'contact_area[cm2]', 'p_Ist / bar': 'pressure[bar]' }, inplace=True) # clear measurement artefacts (no current) df_input = df_input[df_input['current[mA]'] != 0] # fill empty/NaN celss with numerics (0) df_input.fillna(0, inplace=True) # round pressures and append to df in seperate column pressure_ref = [1, 2, 3, 5, 6, 9, 10, 12, 15, 18, 20, 21, 24, 27, 30] pressure_rounded = df_input['pressure_sample[bar]'].round(decimals=0) #df_input = df_input[df_input['pressure_sample[bar]'] in pressure_ref] # current_rounded = df_input['current[mA]'].round(decimals=-2) # define additional columns for calculations result df_input.insert(len(df_input.columns), column='pressure_rounded[bar]', value=pressure_rounded) for i in range(1, 31): if (i in pressure_ref) == False: df_input = df_input[df_input['pressure_rounded[bar]'] != i] df_input.reset_index(drop=True) # df_input.insert(len(df_input.columns), column='current_rounded[mA]', # value=current_rounded) #Probendicke sample_thickness = 'sample_thickness[cm]' df_input.insert(len(df_input.columns), sample_thickness, 0.0) parameters = 'parameters' df_input.insert(len(df_input.columns), parameters, 0.0) #mv in V mV_in_V = '[mV]_in_[V]' df_input.insert(len(df_input.columns), mV_in_V, 0.0) #Gesamtwiderstand res_main_col = 'main_resistance[mOhm]' df_input.insert(len(df_input.columns), res_main_col, 0.0) res_main_mean_col = 'main_resistance_mean[mOhm]' df_input.insert(len(df_input.columns), res_main_mean_col, 0.0) res_main_error_col = 'main_resistance_error[mOhm]' df_input.insert(len(df_input.columns), res_main_error_col, 0.0) #Durchgangswiderstand res_through_col = 'flow_resistance[mOhm]' df_input.insert(len(df_input.columns), res_through_col, 0.0) res_through_mean_col = 'flow_resistance_mean[mOhm]' df_input.insert(len(df_input.columns), res_through_mean_col, 0.0) res_through_error_col = 'flow_resistance_error[mOhm]' df_input.insert(len(df_input.columns), res_through_error_col, 0.0) #Bulkwiderstand res_bulk_col = 'bulk_resistance[mOhm]' df_input.insert(len(df_input.columns), res_bulk_col, 0.0) res_bulk_mean_col = 'bulk_resistance_mean[mOhm]' df_input.insert(len(df_input.columns), res_bulk_mean_col, 0.0) res_bulk_error_col = 'bulk_resistance_error[mOhm]' df_input.insert(len(df_input.columns), res_bulk_error_col, 0.0) res_bulk_sub_col = 'bulk_resistance_sub[mOhm]' df_input.insert(len(df_input.columns), res_bulk_sub_col, 0.0) #Kontaktwiderstand res_contact_col = 'contact_resistance[mOhm]' df_input.insert(len(df_input.columns), res_contact_col, 0.0) res_contact_mean_col = 'contact_resistance_mean[mOhm]' df_input.insert(len(df_input.columns), res_contact_mean_col, 0.0) res_contact_error_col = 'contact_resistance_error[mOhm]' df_input.insert(len(df_input.columns), res_contact_error_col, 0.0) #vs-Gesamtwiderstand res_main_vs_col = 'vs_main_resistance[mOhm*cm]' df_input.insert(len(df_input.columns), res_main_vs_col, 0.0) res_main_vs_mean_col = 'vs_main_resistance_mean[mOhm*cm]' df_input.insert(len(df_input.columns), res_main_vs_mean_col, 0.0) res_main_vs_error_col = 'vs_main_resistance_error[mOhm*cm]' df_input.insert(len(df_input.columns), res_main_vs_error_col, 0.0) #vs-Durchgangswiderstand res_through_vs_col = 'vs_flow_resistance[mOhm*cm]' df_input.insert(len(df_input.columns), res_through_vs_col, 0.0) res_through_vs_mean_col = 'vs_flow_resistance_mean[mOhm*cm]' df_input.insert(len(df_input.columns), res_through_vs_mean_col, 0.0) res_through_vs_error_col = 'vs_flow_resistance_error[mOhm*cm]' df_input.insert(len(df_input.columns), res_through_vs_error_col, 0.0) #vs-Bulkwiderstand res_bulk_vs_col = 'vs_bulk_resistance[mOhm*cm]' df_input.insert(len(df_input.columns), res_bulk_vs_col, 0.0) res_bulk_vs_mean_col = 'vs_bulk_resistance_mean[mOhm*cm]' df_input.insert(len(df_input.columns), res_bulk_vs_mean_col, 0.0) res_bulk_vs_error_col = 'vs_bulk_resistance_error[mOhm*cm]' df_input.insert(len(df_input.columns), res_bulk_vs_error_col, 0.0) #as-Gesamtwiderstand res_main_as_col = 'as_main_resistance[mOhm*cm2]' df_input.insert(len(df_input.columns), res_main_as_col, 0.0) res_main_as_mean_col = 'as_main_resistance_mean[mOhm*cm2]' df_input.insert(len(df_input.columns), res_main_as_mean_col, 0.0) res_main_as_error_col = 'as_main_resistance_error[mOhm*cm2]' df_input.insert(len(df_input.columns), res_main_as_error_col, 0.0) #as-Durchgangswiderstand res_through_as_col = 'as_flow_resistance[mOhm*cm2]' df_input.insert(len(df_input.columns), res_through_as_col, 0.0) res_through_as_mean_col = 'as_flow_resistance_mean[mOhm*cm2]' df_input.insert(len(df_input.columns), res_through_as_mean_col, 0.0) res_through_as_error_col = 'as_flow_resistance_error[mOhm*cm2]' df_input.insert(len(df_input.columns), res_through_as_error_col, 0.0) #as-Bulkwiderstand res_bulk_as_col = 'as_bulk_resistance[mOhm*cm2]' df_input.insert(len(df_input.columns), res_bulk_as_col, 0.0) res_bulk_as_mean_col = 'as_bulk_resistance_mean[mOhm*cm2]' df_input.insert(len(df_input.columns), res_bulk_as_mean_col, 0.0) res_bulk_as_error_col = 'as_bulk_resistance_error[mOhm*cm2]' df_input.insert(len(df_input.columns), res_bulk_as_error_col, 0.0) #as-Kontaktwiderstand res_contact_as_col = 'as_contact_resistance[mOhm*cm2]' df_input.insert(len(df_input.columns), res_contact_as_col, 0.0) res_contact_as_mean_col = 'as_contact_resistance_mean[mOhm*cm2]' df_input.insert(len(df_input.columns), res_contact_as_mean_col, 0.0) res_contact_as_error_col = 'as_contact_resistance_error[mOhm*cm2]' df_input.insert(len(df_input.columns), res_contact_as_error_col, 0.0) #vs-Gesamtleitwert con_main_vs_col = 'vs_main_conductance[S/cm]' df_input.insert(len(df_input.columns), con_main_vs_col, 0.0) con_main_vs_mean_col = 'vs_main_conductance_mean[S/cm]' df_input.insert(len(df_input.columns), con_main_vs_mean_col, 0.0) con_main_vs_error_col = 'vs_main_conductance_error[S/cm]' df_input.insert(len(df_input.columns), con_main_vs_error_col, 0.0) #vs-Durchgangsleitwert con_through_vs_col = 'vs_flow_conductance[S/cm]' df_input.insert(len(df_input.columns), con_through_vs_col, 0.0) con_through_vs_mean_col = 'vs_flow_conductance_mean[S/cm]' df_input.insert(len(df_input.columns), con_through_vs_mean_col, 0.0) con_through_vs_error_col = 'vs_flow_conductance_error[S/cm]' df_input.insert(len(df_input.columns), con_through_vs_error_col, 0.0) #vs-Bulkleitwert con_bulk_vs_col = 'vs_bulk_conductance[S/cm]' df_input.insert(len(df_input.columns), con_bulk_vs_col, 0.0) con_bulk_vs_mean_col = 'vs_bulk_conductance_mean[S/cm]' df_input.insert(len(df_input.columns), con_bulk_vs_mean_col, 0.0) con_bulk_vs_error_col = 'vs_bulk_conductance_error[S/cm]' df_input.insert(len(df_input.columns), con_bulk_vs_error_col, 0.0) #spez. GDL-Korrektur corr = 'degradation_corr[mOhm]' df_input.insert(len(df_input.columns), corr, 0.0) as_corr = 'as_degradation_corr[mOhm*cm2]' df_input.insert(len(df_input.columns), as_corr, 0.0) #Messzyklus cycle = 'cycle' df_input.insert(len(df_input.columns), cycle, 0.0) # seperate measurements by cycles z = int(gdl_age) df_input['current[mA]'].round(-2) rec = 0 # for i, v in df_input['pressure_rounded[bar]'].items(): # print(i) # if v >= rec: # # df_input[cycle].loc[i] = z # # if df_input.loc[v, 'current[mA]'] < 600: # rec = v # else: # z += 1 # rec = 0 # print(i) # df_input[cycle].loc[i] = z for i, v in df_input['pressure_rounded[bar]'].items(): print(list(df_input['pressure_rounded[bar]'].items())) if v >= rec: df_input[cycle].loc[i] = z #df_input.loc[i, cycle] = z if df_input.loc[v, 'current[mA]'] < 600: rec = v else: z += 1 rec = 0 df_input[cycle].iloc[i] = z #get unique values as lists --> measurements / pressures / cycles measurements = np.unique(df_input['measurement'].to_numpy()) pressures = np.unique(pressure_rounded.to_numpy(dtype=int)) cycles = np.unique(df_input['cycle'].to_numpy(dtype=int)) #currents = np.unique(df_input[current_rounded]) #Durchschnittliche Probendicke df_input['sample_thickness[cm]'] = int(thickness) / 10 df_input['[mV] in [V]'] = 1000 df_input[parameters] = gdl1 + gdl2 + '' + spec #H23 Widerstands und Zyklenkorrektur if ref is not 'Referenz' and gdl1 == 'H23': df_corr_list = [] h23_ref = 'h23_reference.csv' df_h23 = pd.read_csv(h23_ref, sep='\t') for c in cycles: df_input_1 = df_input[df_input['cycle'] == c] pd.option_context('display.max_columns', None) df_h23_1 = df_h23[df_h23['cycle'] == c - 1] for p in pressures: if p in pressure_ref: df_input_2 = df_input_1[df_input_1['pressure_rounded[bar]'] == p] df_h23_2 = df_h23_1[df_h23_1['pressure_rounded[bar]'] == p] correction_value = df_h23_2[ 'as_main_resistance[mOhm*cm2]'].mean( ) / df_h23_2['contact_area[cm2]'].mean() df_input_2.loc[df_input_2['pressure_rounded[bar]'] == p, corr] = correction_value df_input_2.loc[df_input_2['pressure_rounded[bar]'] == p, as_corr] = df_h23_2[ 'as_main_resistance[mOhm*cm2]'].mean() df_corr_list.append(df_input_2) else: p_nearest = min(pressure_ref, key=lambda x: abs(x - p)) df_input_2 = df_input_1[df_input_1['pressure_rounded[bar]'] == p_nearest] df_h23_2 = df_h23_1[df_h23_1['pressure_rounded[bar]'] == p_nearest] correction_value = df_h23_2[ 'as_main_resistance[mOhm*cm2]'].mean( ) / df_h23_2['contact_area[cm2]'].mean() df_input_2.loc[df_input_2['pressure_rounded[bar]'] == p_nearest, corr] = correction_value df_input_2.loc[df_input_2['pressure_rounded[bar]'] == p_nearest, as_corr] = df_h23_2[ 'as_main_resistance[mOhm*cm2]'].mean() df_corr_list.append(df_input_2) df_input = pd.concat(df_corr_list) elif ref is not 'Referenz' and gdl2 == '29BC': df_corr_list = [] sgl29_ref = 'sgl29bc_reference.csv' df_sgl29 = pd.read_csv(sgl29_ref) for c in cycles: df_input_1 = df_input[df_input['cycle'] == c] pd.option_context('display.max_columns', None) df_sgl29_1 = df_sgl29[df_sgl29['cycle'] == c] for p in pressures: if p in pressure_ref: df_input_2 = df_input_1[df_input_1['pressure_rounded[bar]'] == p] df_sgl29_2 = df_sgl29_1[df_sgl29_1['pressure_rounded[bar]'] == p] correction_value = df_sgl29_2[ 'as_main_resistance[mOhm*cm2]'].mean( ) / df_sgl29_2['contact_area[cm2]'].mean() df_input_2.loc[df_input_2['pressure_rounded[bar]'] == p, corr] = correction_value df_input_2.loc[df_input_2['pressure_rounded[bar]'] == p, as_corr] = df_sgl29_2[ 'as_main_resistance[mOhm*cm2]'].mean() df_corr_list.append(df_input_2) else: p_nearest = min(pressure_ref, key=lambda x: abs(x - p)) df_input_2 = df_input_1[df_input_1['pressure_rounded[bar]'] == p_nearest] df_sgl29_2 = df_sgl29_1[df_sgl29_1['pressure_rounded[bar]'] == p_nearest] correction_value = df_sgl29_2[ 'as_main_resistance[mOhm*cm2]'].mean( ) / df_sgl29_2['contact_area[cm2]'].mean() df_input_2.loc[df_input_2['pressure_rounded[bar]'] == p_nearest, corr] = correction_value df_input_2.loc[df_input_2['pressure_rounded[bar]'] == p_nearest, as_corr] = df_sgl29_2[ 'as_main_resistance[mOhm*cm2]'].mean() df_corr_list.append(df_input_2) df_input = pd.concat(df_corr_list) else: df_input.loc[(df_input['pressure_rounded[bar]']) < 31 & (df_input['cycle'] <= 100), corr] = 0 # create variable for storage in library --> file_identifier #file_identifier = ref + ' ' + sample + ' ' + gdl1 + gdl2 + spec file_identifier = sample # create empty df which will be filled with storage data df_list = [] fig, a = plt.subplots(2, 3) # seperate datafile into different measurements for m in measurements: # df-slice with single measurement df_t1 = df_input[df_input['measurement'] == m] # specify file-identifer and add measurement measurement_identifier = ref + ' ' + file_identifier + ' ' + comment # add measurement_identifer / cr / cr_error / cr_mean to df df_t1.insert(2, 'measurement', measurement_identifier, True) cycles = np.unique(df_t1['cycle'].to_numpy(dtype=int)) # seperate measurement-df into different cycles for c in cycles: # df-slice of measurement-df with single 'cycle' df_t2_c = df_t1[df_t1[cycle] == c] # declare empty y / y-error-value list for plotting --> contact res res_main_mean_list = [] #Gesamtwiderstand res_main_error_list = [] res_through_mean_list = [] #Durchgangswiderstand res_through_error_list = [] res_bulk_mean_list = [] #Bulkwiderstand res_bulk_error_list = [] res_contact_mean_list = [] #Kontaktwiderstand res_contact_error_list = [] res_main_vs_mean_list = [] #vs-Gesamtwiderstand res_main_vs_error_list = [] res_through_vs_mean_list = [] #vs-Durchgangswiderstand res_through_vs_error_list = [] res_bulk_vs_mean_list = [] #vs-Bulkwiderstand res_bulk_vs_error_list = [] res_main_as_mean_list = [] #as-Gesamtwiderstand res_main_as_error_list = [] res_through_as_mean_list = [] #as-Durchngangswiderstand res_through_as_error_list = [] res_bulk_as_mean_list = [] #as-Bulkwiderstand res_bulk_as_error_list = [] res_contact_as_mean_list = [] #as-Kontaktwiderstand res_contact_as_error_list = [] con_main_vs_mean_list = [] #vs-Gesamtleitwert con_main_vs_error_list = [] con_through_vs_mean_list = [] #vs-Durchgangsleitwert con_through_vs_error_list = [] con_bulk_vs_mean_list = [] #vs-Bulkleitwert con_bulk_vs_error_list = [] # seperate 'cycle'-df into different pressures for p in pressures: #print('measurement: ' + str(m), 'cycle: ' + str(c), 'pressure: ' + str(p)) # df-slice of 'cycle'-df with single pressure df_t3_p = df_t2_c[df_t2_c['pressure_rounded[bar]'] == p] #print(df_t3_p) #df_t4_i = df_t3_p[df_t3_p[current_rounded] == i] # calculate --> overall resistance #Gesamtwiderstand [mOhm] res_main = (df_t3_p['voltage_th[mV]'] / df_t3_p['current[mA]']) * 1000 #4W #! Korrekturwert s. Korrekturschleife -->[corr] in [mOhm] #Durchgangswiderstand [mOhm] res_through = res_main - df_t3_p[corr] #Bulkwiderstand [mOhm] if spec == "m. Nadel": res_bulk = (df_t3_p['voltage_needle_th[mV]'] / df_t3_p['current[mA]']) * 1000 else: res_bulk = res_main - res_main #Kontaktwiderstand [mOhm] res_contact = (res_through - res_bulk) / 2 #volumenspezifischer Gesamtwiderstand [mOhm*cm] res_main_vs = res_main * df_t3_p[ 'contact_area[cm2]'] / df_t3_p['sample_thickness[cm]'] #volumenspezifischer Durchgangswiderstand [mOhm*cm] res_through_vs = res_through * df_t3_p[ 'contact_area[cm2]'] / df_t3_p['sample_thickness[cm]'] #volumenspezifischer Bulkwiderstand [mOhm*cm] res_bulk_vs = res_bulk * df_t3_p[ 'contact_area[cm2]'] / df_t3_p['sample_thickness[cm]'] # flächenspezifischer Gesamtwiderstand [mOhm*cm2] res_main_as = res_main * df_t3_p['contact_area[cm2]'] # flächenspezifscher Durchgangswiderstand [mOhm*cm2] res_through_as = res_through * df_t3_p['contact_area[cm2]'] # flächenspezifischer Bulkwiderstand [mOhm*cm2] res_bulk_as = res_bulk * df_t3_p['contact_area[cm2]'] # flächenspezifischer Kontaktwiderstand [mOhm*cm2] res_contact_as = res_contact * df_t3_p['contact_area[cm2]'] # volumenspezifischer Gesamtleitwert [S/cm] con_main_vs = df_input['[mV] in [V]'] / res_main_vs # volumenspezifischer Durchgangsleitwert [S/cm] con_through_vs = df_input['[mV] in [V]'] / res_through_vs #volumenspezifischer Bulk-Leitwert [S/cm] con_bulk_vs = df_input['[mV] in [V]'] / res_bulk_vs # get mean- and sem-value of calculated resistance res_main_mean = res_main.mean() res_main_error = res_main.sem() res_through_mean = res_through.mean() res_through_error = res_through.sem() res_bulk_mean = res_bulk.mean() res_bulk_error = res_bulk.sem() res_contact_mean = res_contact.mean() res_contact_error = res_contact.sem() res_main_vs_mean = res_main_vs.mean() res_main_vs_error = res_main_vs.sem() res_through_vs_mean = res_through_vs.mean() res_through_vs_error = res_through_vs.sem() res_bulk_vs_mean = res_bulk_vs.mean() res_bulk_vs_error = res_bulk_vs.sem() res_main_as_mean = res_main_as.mean() res_main_as_error = res_main_as.sem() res_through_as_mean = res_through_as.mean() res_through_as_error = res_through_as.sem() res_bulk_as_mean = res_bulk_as.mean() res_bulk_as_error = res_bulk_as.sem() res_contact_as_mean = res_contact_as.mean() res_contact_as_error = res_contact_as.sem() con_main_vs_mean = con_main_vs.mean() con_main_vs_error = con_main_vs.sem() con_through_vs_mean = con_through_vs.mean() con_through_vs_error = con_through_vs.sem() con_bulk_vs_mean = con_bulk_vs.mean() con_bulk_vs_error = con_bulk_vs.sem() pd.set_option('display.max_columns', None) #print(df_t3_p) # write data --> cr-mean and cr-sem in df-slice df_t3_p.loc[df_t3_p['pressure_rounded[bar]'] == p, res_main_col] = res_main df_t3_p.loc[df_t3_p['pressure_rounded[bar]'] == p, res_main_mean_col] = res_main_mean df_t3_p.loc[df_t3_p['pressure_rounded[bar]'] == p, res_main_error_col] = res_main_error df_t3_p.loc[df_t3_p['pressure_rounded[bar]'] == p, res_through_col] = res_through df_t3_p.loc[df_t3_p['pressure_rounded[bar]'] == p, res_through_mean_col] = res_through_mean df_t3_p.loc[df_t3_p['pressure_rounded[bar]'] == p, res_through_error_col] = res_through_error df_t3_p.loc[df_t3_p['pressure_rounded[bar]'] == p, res_bulk_col] = res_bulk df_t3_p.loc[df_t3_p['pressure_rounded[bar]'] == p, res_bulk_mean_col] = res_bulk_mean df_t3_p.loc[df_t3_p['pressure_rounded[bar]'] == p, res_bulk_error_col] = res_bulk_error df_t3_p.loc[df_t3_p['pressure_rounded[bar]'] == p, res_contact_col] = res_contact df_t3_p.loc[df_t3_p['pressure_rounded[bar]'] == p, res_contact_mean_col] = res_contact_mean df_t3_p.loc[df_t3_p['pressure_rounded[bar]'] == p, res_contact_error_col] = res_contact_error df_t3_p.loc[df_t3_p['pressure_rounded[bar]'] == p, res_main_vs_col] = res_main_vs df_t3_p.loc[df_t3_p['pressure_rounded[bar]'] == p, res_main_vs_mean_col] = res_main_vs_mean df_t3_p.loc[df_t3_p['pressure_rounded[bar]'] == p, res_main_vs_error_col] = res_main_vs_error df_t3_p.loc[df_t3_p['pressure_rounded[bar]'] == p, res_through_vs_col] = res_through_vs df_t3_p.loc[df_t3_p['pressure_rounded[bar]'] == p, res_through_vs_mean_col] = res_through_vs_mean df_t3_p.loc[df_t3_p['pressure_rounded[bar]'] == p, res_through_vs_error_col] = res_through_vs_error df_t3_p.loc[df_t3_p['pressure_rounded[bar]'] == p, res_bulk_as_col] = res_bulk_vs df_t3_p.loc[df_t3_p['pressure_rounded[bar]'] == p, res_bulk_as_mean_col] = res_bulk_vs_mean df_t3_p.loc[df_t3_p['pressure_rounded[bar]'] == p, res_bulk_as_error_col] = res_bulk_vs_error df_t3_p.loc[df_t3_p['pressure_rounded[bar]'] == p, res_main_as_col] = res_main_as df_t3_p.loc[df_t3_p['pressure_rounded[bar]'] == p, res_main_as_mean_col] = res_main_as_mean df_t3_p.loc[df_t3_p['pressure_rounded[bar]'] == p, res_main_as_error_col] = res_main_as_error df_t3_p.loc[df_t3_p['pressure_rounded[bar]'] == p, res_through_as_col] = res_through_as df_t3_p.loc[df_t3_p['pressure_rounded[bar]'] == p, res_through_as_mean_col] = res_through_as_mean df_t3_p.loc[df_t3_p['pressure_rounded[bar]'] == p, res_through_as_error_col] = res_through_as_error df_t3_p.loc[df_t3_p['pressure_rounded[bar]'] == p, res_bulk_as_col] = res_bulk_as df_t3_p.loc[df_t3_p['pressure_rounded[bar]'] == p, res_bulk_as_mean_col] = res_bulk_as_mean df_t3_p.loc[df_t3_p['pressure_rounded[bar]'] == p, res_bulk_as_error_col] = res_bulk_as_error df_t3_p.loc[df_t3_p['pressure_rounded[bar]'] == p, res_contact_as_col] = res_contact_as df_t3_p.loc[df_t3_p['pressure_rounded[bar]'] == p, res_contact_as_mean_col] = res_contact_as_mean df_t3_p.loc[df_t3_p['pressure_rounded[bar]'] == p, res_contact_as_error_col] = res_contact_as_error print(p) print(df_t3_p[df_t3_p['pressure_rounded[bar]'] == p]) df_t3_p.loc[df_t3_p['pressure_rounded[bar]'] == p, con_main_vs_col] = con_main_vs df_t3_p.loc[df_t3_p['pressure_rounded[bar]'] == p, con_main_vs_mean_col] = con_main_vs_mean df_t3_p.loc[df_t3_p['pressure_rounded[bar]'] == p, con_main_vs_error_col] = con_main_vs_error df_t3_p.loc[df_t3_p['pressure_rounded[bar]'] == p, con_through_vs_col] = con_through_vs df_t3_p.loc[df_t3_p['pressure_rounded[bar]'] == p, con_through_vs_mean_col] = con_through_vs_mean df_t3_p.loc[df_t3_p['pressure_rounded[bar]'] == p, con_through_vs_error_col] = con_through_vs_error df_t3_p.loc[df_t3_p['pressure_rounded[bar]'] == p, con_bulk_vs_col] = con_bulk_vs df_t3_p.loc[df_t3_p['pressure_rounded[bar]'] == p, con_bulk_vs_mean_col] = con_bulk_vs_mean df_t3_p.loc[df_t3_p['pressure_rounded[bar]'] == p, con_bulk_vs_error_col] = con_bulk_vs_error # append cr-mean and cr-sem values of single pressure to x,y plotdata #Gesamtwiderstand res_main_mean_list.append(res_main_mean) res_main_error_list.append(res_main_error) #Durchgangswiderstand res_through_mean_list.append(res_through_mean) res_through_error_list.append(res_through_error) #Bulkwiderstand res_bulk_mean_list.append(res_bulk_mean) res_bulk_error_list.append(res_bulk_error) #Kontaktwiderstand res_contact_mean_list.append(res_contact_mean) res_contact_error_list.append(res_contact_error) #vs-Gesamtwiderstand res_main_vs_mean_list.append(res_contact_as_mean) res_main_vs_error_list.append(res_contact_as_error) #vs-Durchgangswiderstand res_through_vs_mean_list.append(res_through_vs_mean) res_through_vs_error_list.append(res_through_vs_error) #vs-Bulkwiderstand res_bulk_mean_list.append(res_bulk_vs_mean) res_bulk_error_list.append(res_bulk_vs_error) #as-Gesamtwiderstand res_main_as_mean_list.append(res_main_as_mean) res_main_as_error_list.append(res_main_as_error) #as-Durchgangswiderstand res_through_as_mean_list.append(res_through_as_mean) res_through_as_error_list.append(res_through_as_error) #as-Bulkwiderstand res_bulk_as_mean_list.append(res_bulk_as_mean) res_bulk_as_error_list.append(res_bulk_as_error) #as-Kontaktwiderstand res_contact_as_mean_list.append(res_contact_as_mean) res_contact_as_error_list.append(res_contact_as_error) #vs-Gesamtleitwert con_main_vs_mean_list.append(con_main_vs_mean) con_main_vs_error_list.append(con_main_vs_error) #vs-Durchgangsleitwert con_through_vs_mean_list.append(con_through_vs_mean) con_through_vs_error_list.append(con_through_vs_error) #vs-Bulkleitwert con_bulk_vs_mean_list.append(con_bulk_vs_mean) con_bulk_vs_error_list.append(con_bulk_vs_error) df_list.append(df_t3_p) # forming x,y-value-lists into array # TODO: implement error-bars in graphs res_main_mean = np.asarray(res_main_mean_list) res_main_error = np.asarray(res_main_error_list) res_through_mean = np.asarray(res_through_mean_list) res_through_error = np.asarray(res_through_error_list) res_bulk_mean = np.asarray(res_bulk_mean_list) res_bulk_error = np.asarray(res_bulk_error_list) res_contact_mean = np.asarray(res_contact_mean_list) res_contact_error = np.asarray(res_contact_error_list) res_main_vs_mean = np.asarray(res_main_vs_mean_list) res_main_vs_error = np.asarray(res_main_vs_error_list) res_through_vs_mean = np.asarray(res_through_vs_mean_list) res_through_vs_error = np.asarray(res_through_vs_error_list) res_bulk_vs_mean = np.asarray(res_bulk_vs_mean_list) res_bulk_vs_error = np.asarray(res_bulk_vs_error_list) res_main_as_mean = np.asarray(res_main_as_mean_list) res_main_as_error = np.asarray(res_main_as_error_list) res_through_as_mean = np.asarray(res_through_as_mean_list) res_through_as_error = np.asarray(res_through_as_error_list) res_bulk_as_mean = np.asarray(res_bulk_as_mean_list) res_bulk_as_error = np.asarray(res_bulk_as_error_list) res_contact_as_mean = np.asarray(res_contact_as_mean_list) res_contact_as_error = np.asarray(res_contact_as_error_list) con_main_vs_mean = np.asarray(con_main_vs_mean_list) con_main_vs_error = np.asarray(con_main_vs_error_list) con_through_vs_mean = np.asarray(con_through_vs_mean_list) con_through_vs_error = np.asarray(con_through_vs_error_list) con_bulk_vs_mean = np.asarray(con_bulk_vs_mean_list) con_bulk_vs_error = np.asarray(con_bulk_vs_error_list) # graph --> res_mean over p (every 'cycle' seperate) # plt.errorbar(pressures, resistance_mean, yerr=resistance_error, elinewidth=None, capsize=2, label=m + str(c)) a[0][0].plot(pressures, res_main_mean, label=c) a[0][0].set_title('Resistance / Pressure') a[0][0].set_xlabel('Pressure [bar]') a[0][0].set_ylabel('Resistance [mOhm*cm²]') a[0][0].set_xlim([0, max(pressures)]) print(res_main_mean) a[0][0].set_ylim([0, max(res_main_mean)]) a[0][0].legend(bbox_to_anchor=(-0.55, 1, 0.4, 0), loc='upper left', mode='expand', ncol=3, fontsize='xx-small', title='Cycle') a[0][1].plot(pressures, res_through_mean) a[0][1].set_title('Volume Resistance / Pressure') a[0][1].set_xlabel('Pressure [bar]') a[0][1].set_ylabel('Volume Resistance [mOhm*cm²]') a[0][1].set_xlim([0, max(pressures)]) a[0][1].set_ylim([0, max(res_main_mean)]) a[0][2].plot(pressures, res_contact_mean) a[0][2].set_title('Contact Resistance / Pressure') a[0][2].set_xlabel('Pressure [bar]') a[0][2].set_ylabel('Contact Resistance [mOhm*cm²]') a[0][2].set_xlim([0, max(pressures)]) a[0][2].set_ylim([0, max(res_main_mean)]) for p in pressures: # declare empty y-value list for plotting --> gdl degradation ref_res_main_as_mean = [] ref_res_through_as_mean = [] ref_res_bulk_as_mean = [] ref_res_contact_as_mean = [] df_t2_p = df_t1[df_t1['pressure_rounded[bar]'] == p] for c in cycles: df_t3_c = df_t2_p[df_t2_p[cycle] == c] # calculate --> overall resistance cycle_res_main_as = (df_t3_c['voltage_th[mV]'] / df_t3_c['current[mA]'] ) * 1000.0 * df_t2_p['contact_area[cm2]'] # calculate --> contact resistance cycle_res_through_as = ( (df_t3_c['voltage_th[mV]'] / df_t3_c['current[mA]']) * 1000.0 - df_t3_c[corr]) * df_t2_p['contact_area[cm2]'] if spec == "m. Nadel": cycle_res_bulk_as = ( df_t3_c['voltage_needle_th[mV]'] / df_t3_c['current[mA]'] ) * 1000 * df_t3_c['contact_area[cm2]'] else: cycle_res_bulk_as = cycle_res_main_as - cycle_res_main_as cycle_res_contact_as = (cycle_res_through_as - cycle_res_bulk_as) / 2.0 # get mean resistance of 'cycle' for specific pressure ref_res_main_as = cycle_res_main_as.mean() ref_res_bulk_as = cycle_res_bulk_as.mean() ref_res_through_as = cycle_res_through_as.mean() ref_res_contact_as = cycle_res_contact_as.mean() # append ref_res of 'cycle' to y-value list ref_res_main_as_mean.append(ref_res_main_as) ref_res_through_as_mean.append(ref_res_through_as) ref_res_bulk_as_mean.append(ref_res_bulk_as) ref_res_contact_as_mean.append(ref_res_contact_as) ref_res_main_as_mean = np.asarray(ref_res_main_as_mean) ref_res_through_as_mean = np.asarray(ref_res_through_as_mean) ref_res_bulk_as_mean = np.asarray(ref_res_bulk_as_mean) ref_res_contact_as_mean = np.asarray(ref_res_contact_as_mean) if p == 1: ymax = max(ref_res_main_as_mean) elif p == 2: ymax = max(ref_res_main_as_mean) elif p == 3: ymax = max(ref_res_main_as_mean) elif p == 5: ymax = max(ref_res_main_as_mean) # graph --> res_mean over cylces (one specific pressure) a[1][0].plot(cycles, ref_res_main_as_mean, label=p) a[1][0].set_title('Main-Resistance / Cycles') a[1][0].set_xlabel('Measurement Cycle') a[1][0].set_ylabel('Main-Resistance [mOhm*cm²]') a[1][0].set_xlim([min(cycles), max(cycles)]) a[1][0].set_ylim([0, ymax]) a[1][0].legend(bbox_to_anchor=(-0.55, 1, 0.2, 0), loc='upper left', mode='expand', fontsize='small', title='p [bar]') a[1][1].plot(cycles, ref_res_through_as_mean) a[1][1].set_title('Flow-Resistance / Cycles') a[1][1].set_xlabel('Measurement Cycle') a[1][1].set_ylabel('Flow Resistance [mOhm*cm²]') a[1][1].set_xlim([min(cycles), max(cycles)]) a[1][1].set_ylim([0, ymax]) a[1][2].plot(cycles, ref_res_contact_as_mean) a[1][2].set_title('Contact Resistance / Cycles') a[1][2].set_xlabel('Measurement Cycle') a[1][2].set_ylabel('Contact- Resistance [mOhm*cm²]') a[1][2].set_xlim([min(cycles), max(cycles)]) a[1][2].set_ylim([0, ymax]) df_result = pd.concat(df_list) df_import = df_result.sort_values(by=['time']) df_import2 = df_import.round(8) library_name = 'cr_library.csv' #TODO: implementation of value table export in excelfile #create table-df df_import2.sort_values(by=['cycle']) summary = {#'Zyklen':df_import2['cycle'].apply(lambda x: x+1-int(gdl_age)), 'Gesamtwiderstand @5bar [mOhm*cm2]':df_import2[df_import2['pressure_rounded[bar]'] == 5]['as_main_resistance[mOhm*cm2]'], 'Bulkwiderstand @5bar [mOhm*cm2]':df_import2[df_import2['pressure_rounded[bar]'] == 5]['as_bulk_resistance[mOhm*cm2]'], 'Durchgangswiderstand @5bar [mOhm*cm2]':df_import2[df_import2['pressure_rounded[bar]'] == 5]['as_flow_resistance[mOhm*cm2]'], 'Kontaktwiderstand @5bar [mOhm*cm2]':df_import2[df_import2['pressure_rounded[bar]'] == 5]['as_contact_resistance[mOhm*cm2]'], 'Korrekturwert GDL @5bar/cycle [mOhm*cm2]':df_import2[df_import2['pressure_rounded[bar]'] == 5]['as_degradation_corr[mOhm*cm2]'], 'Gesamtwiderstand @10bar [mOhm*cm2]':df_import2[df_import2['pressure_rounded[bar]'] == 10]['as_main_resistance[mOhm*cm2]'], 'Bulkwiderstand @10bar [mOhm*cm2]':df_import2[df_import2['pressure_rounded[bar]'] == 10]['as_bulk_resistance[mOhm*cm2]'], 'Durchgangswiderstand @10bar [mOhm*cm2]':df_import2[df_import2['pressure_rounded[bar]'] == 10]['as_flow_resistance[mOhm*cm2]'], 'Kontaktwiderstand @10bar [mOhm*cm2]':df_import2[df_import2['pressure_rounded[bar]'] == 10]['as_contact_resistance[mOhm*cm2]'], 'Korrekturwert GDL @10bar/cycle [mOhm*cm2]':df_import2[df_import2['pressure_rounded[bar]'] == 10]['as_degradation_corr[mOhm*cm2]'], 'Gesamtwiderstand @20bar [mOhm*cm2]':df_import2[df_import2['pressure_rounded[bar]'] == 20]['as_main_resistance[mOhm*cm2]'], 'Bulkwiderstand @20bar [mOhm*cm2]':df_import2[df_import2['pressure_rounded[bar]'] == 20]['as_bulk_resistance[mOhm*cm2]'], 'Durchgangswiderstand @20bar [mOhm*cm2]':df_import2[df_import2['pressure_rounded[bar]'] == 20]['as_flow_resistance[mOhm*cm2]'], 'Kontaktwiderstand @20bar [mOhm*cm2]':df_import2[df_import2['pressure_rounded[bar]'] == 20]['as_contact_resistance[mOhm*cm2]'], 'Korrekturwert GDL @20bar/cycle [mOhm*cm2]':df_import2[df_import2['pressure_rounded[bar]'] == 20]['as_degradation_corr[mOhm*cm2]'], 'Gesamtwiderstand @30bar [mOhm*cm2]':df_import2[df_import2['pressure_rounded[bar]'] == 30]['as_main_resistance[mOhm*cm2]'], 'Bulkwiderstand @30bar [mOhm*cm2]':df_import2[df_import2['pressure_rounded[bar]'] == 30]['as_bulk_resistance[mOhm*cm2]'], 'Durchgangswiderstand @30bar [mOhm*cm2]':df_import2[df_import2['pressure_rounded[bar]'] == 30]['as_flow_resistance[mOhm*cm2]'], 'Kontaktwiderstand @30bar [mOhm*cm2]':df_import2[df_import2['pressure_rounded[bar]'] == 30]['as_contact_resistance[mOhm*cm2]'], 'Korrekturwert GDL @30bar/cycle [mOhm*cm2]':df_import2[df_import2['pressure_rounded[bar]'] == 30]['as_degradation_corr[mOhm*cm2]'], } df_summary = pd.DataFrame(data=summary) #export table-df to excel rootpath = pathlib.Path(__file__).parent.absolute() df_summary.to_csv(str(rootpath) + '/ECR_data/CSV/' + sample + '.csv', mode='w', header=True, index=False, sep='\t') # save eis data to excel wb_path = str(rootpath) + '/ECR_data/ecr_data_library.xlsx' book = load_workbook(wb_path) writer = pd.ExcelWriter(wb_path, engine='openpyxl') writer.book = book df_summary.to_excel(writer, sheet_name=sample, index=False) writer.save() writer.close() if os.path.isfile(library_name): with open(library_name, newline='') as file: if file.read().find(file_identifier) == -1: df_import2.to_csv(library_name, mode='a', header=False, sep='\t') else: tk.messagebox.showinfo(title='Redundanz', message='Datei bereits im Archiv') else: df_import2.to_csv(library_name, mode='w', header=True, sep='\t') # Formatiere Plot table_data = [["Sample", sample], ["GDL", gdl1 + gdl2], ["Method", spec]] table = a[0][0].table(cellText=table_data, colWidths=[.2, .5], loc='bottom', bbox=[0.45, 0.75, 0.5, 0.2]) for (row, col), cell in table.get_celld().items(): if col == 0: cell.set_height(1.3) cell._loc = 'left' cell.set_text_props(ma='left', color='b', fontweight=50) elif col == 1: cell.set_height(1.3) cell._loc = 'right' cell.set_text_props(ma='right') frame.destroy() mng = plt.get_current_fig_manager() mng.full_screen_toggle() fig1 = plt.gcf() plt.show() png_path = str(rootpath) + '/ECR_data/PNG/' + sample.strip(' ') + '.png' fig1.savefig(png_path, bbox_inches='tight')
def create_figures(subfigure_width=480, subfigure_height=600, starting_figure_no=1, \ starting_col_index = 0, starting_row_index=0, plot_configuration=PLOT_HORIZONTALLY): figure_number = starting_figure_no col_index = starting_col_index row_index = starting_row_index ## read files -------------------------------------------------------------------- file_path = os.getcwd() + "/../../../experiment_data_check/" data_motor_current = \ np.genfromtxt(file_path+'torque.txt', delimiter=None, dtype=(float)) # np.genfromtxt(file_path+'motor_current.txt', delimiter=None, dtype=(float)) data_temperature = \ np.genfromtxt(file_path+'temperature.txt', delimiter=None, dtype=(float)) data_x = np.genfromtxt(file_path + 'time.txt', delimiter='\n', dtype=(float)) num_leg_joint = 5 # st_idx = 1; st_idx = 1300 end_idx = len(data_x) - 1 data_x = data_x[st_idx:end_idx] ##-------------------------------------------------------------------------------- # PHASE MARKER # data_phse = np.genfromtxt(file_path + 'phase.txt', delimiter=None, dtype=(float)) # get phase.txt data # phseChange = [] for i in range(0, len(data_x) - 1): if data_phse[i] != data_phse[i + 1]: phseChange.append(i - st_idx) else: pass # Plot Figure -------------------------------------------------------------------- ## plot command/jpos fig = plt.figure(figure_number) plt.get_current_fig_manager().window.wm_geometry( str(subfigure_width) + "x" + str(subfigure_height) + "+" + str(subfigure_width * col_index) + "+" + str(subfigure_height * row_index)) fig.canvas.set_window_title('motor current (left leg)') for i in range(1, num_leg_joint + 1, 1): ax1 = plt.subplot(num_leg_joint, 1, i) plt.plot(data_x, data_motor_current[st_idx:end_idx, i - 1], "b-") # phase marker # for j in phseChange: # phase line plt.axvline(x=data_x[j], color='indigo', linestyle='-') plt.grid(True) plt.xlabel('time (sec)') ## increment figure number and index figure_number += 1 if plot_configuration == PLOT_HORIZONTALLY: col_index += 1 elif plot_configuration == PLOT_VERTICALLY: row_index += 1 #---------------------------------------------------------------------------------- # Plot Figure -------------------------------------------------------------------- fig = plt.figure(figure_number) plt.get_current_fig_manager().window.wm_geometry( str(subfigure_width) + "x" + str(subfigure_height) + "+" + str(subfigure_width * col_index) + "+" + str(subfigure_height * row_index)) fig.canvas.set_window_title('motor current (right leg)') for i in range(1, num_leg_joint + 1, 1): ax1 = plt.subplot(num_leg_joint, 1, i) plt.plot(data_x, data_motor_current[st_idx:end_idx, i - 1 + num_leg_joint], "b-") # phase marker # for j in phseChange: # phase line plt.axvline(x=data_x[j], color='indigo', linestyle='-') plt.grid(True) plt.xlabel('time (sec)') ## increment figure number and index figure_number += 1 if plot_configuration == PLOT_HORIZONTALLY: col_index += 1 elif plot_configuration == PLOT_VERTICALLY: row_index += 1 #---------------------------------------------------------------------------------- # Plot Figure -------------------------------------------------------------------- ## plot jvel fig = plt.figure(figure_number) plt.get_current_fig_manager().window.wm_geometry( str(subfigure_width) + "x" + str(subfigure_height) + "+" + str(subfigure_width * col_index) + "+" + str(subfigure_height * row_index)) fig.canvas.set_window_title('motor temperature (left_leg)') for i in range(1, num_leg_joint + 1, 1): ax1 = plt.subplot(num_leg_joint, 1, i) plt.plot(data_x, data_temperature[st_idx:end_idx, i - 1], "b-") # phase marker # for j in phseChange: # phase line plt.axvline(x=data_x[j], color='indigo', linestyle='-') plt.grid(True) plt.xlabel('time (sec)') ## increment figure number and index figure_number += 1 if plot_configuration == PLOT_HORIZONTALLY: col_index += 1 elif plot_configuration == PLOT_VERTICALLY: row_index += 1 #---------------------------------------------------------------------------------- # Plot Figure -------------------------------------------------------------------- fig = plt.figure(figure_number) plt.get_current_fig_manager().window.wm_geometry( str(subfigure_width) + "x" + str(subfigure_height) + "+" + str(subfigure_width * col_index) + "+" + str(subfigure_height * row_index)) fig.canvas.set_window_title('motor temperature (right_leg)') for i in range(1, num_leg_joint + 1, 1): ax1 = plt.subplot(num_leg_joint, 1, i) plt.plot(data_x, data_temperature[st_idx:end_idx, i - 1 + num_leg_joint], "b-") # phase marker # for j in phseChange: # phase line plt.axvline(x=data_x[j], color='indigo', linestyle='-') plt.grid(True) plt.xlabel('time (sec)') ## increment figure number and index figure_number += 1 if plot_configuration == PLOT_HORIZONTALLY: col_index += 1 elif plot_configuration == PLOT_VERTICALLY: row_index += 1
def show(x_y_z, labels, style=0, mark_len=0): color_list = [ 'blue', 'purple', 'orange', 'darkgreen', 'darkgoldenrod', 'darkorange' ] fig = plt.figure() # ax = fig.add_subplot(1, 1, 1) vertical_line = plt.axvline(x=0, color='purple', ls='--') horizontal_line = plt.axhline(y=0, color='purple', ls='--') def update_labels_line(label_lines): for cl in range(1, 7): _new_x = [i for i in range(len(labels)) if labels[i] == cl] label_lines[cl - 1].set_xdata(_new_x) label_lines[cl - 1].set_ydata([15 for _ in range(len(_new_x))]) fig.canvas.draw_idle() label_lines = [] for cl in range(1, 7): label_line = plt.plot([], [], 's', color=color_list[cl - 1])[0] label_lines.append(label_line) update_labels_line(label_lines) def on_key_press(event): if event.key == 'a' or event.key == 'd': try: change_index = int(vertical_line.get_xdata()) labels[change_index:change_index + mark_len] = style if event.key == 'a' else 0 # ax.lines.remove(ax.lines[-1]) except (TypeError, Exception): pass update_labels_line(label_lines) elif event.key == '1' or event.key == '2' or event.key == '3' or event.key == '4': try: change_index = int(vertical_line.get_xdata()) labels[change_index:change_index + mark_len] = int(event.key) # ax.lines.remove(ax.lines[-1]) except (TypeError, Exception): pass update_labels_line(label_lines) elif event.key == 'q' or event.key == 'e': try: cur_index = int(vertical_line.get_xdata()) move_len = -1 if event.key == 'q' else 1 vertical_line.set_xdata(cur_index + move_len) if labels[cur_index] > 0: head_index = cur_index rear_index = cur_index while labels[head_index] > 0: head_index = head_index - 1 head_index = head_index + 1 while labels[rear_index] > 0: rear_index = rear_index + 1 labels[head_index:rear_index] = 0 labels[head_index + move_len:rear_index + move_len] = style vertical_line.set_xdata(head_index + move_len) update_labels_line(label_lines) except TypeError: pass def on_scroll(event): try: ax_temp = event.inaxes x_min, x_max = ax_temp.get_xlim() delta = (x_max - x_min) / 10 if event.button == 'up': ax_temp.set(xlim=(x_min + delta, x_max - delta)) elif event.button == 'down': ax_temp.set(xlim=(x_min - delta, x_max + delta)) fig.canvas.draw_idle() except (TypeError, AttributeError): pass def motion(event): try: vertical_line.set_xdata(int(event.xdata)) horizontal_line.set_ydata(event.ydata) fig.canvas.draw_idle() except TypeError: pass fig.canvas.mpl_disconnect( fig.canvas.manager.key_press_handler_id) # 取消默认快捷键的注册 fig.canvas.mpl_connect('scroll_event', on_scroll) fig.canvas.mpl_connect('motion_notify_event', motion) fig.canvas.mpl_connect('key_press_event', on_key_press) new_x_y_z = x_y_z.T xyz = np.sqrt(new_x_y_z[0]**2 + new_x_y_z[1]**2 + new_x_y_z[2]**2) plt.plot(new_x_y_z[0], color='r', label='ax') plt.plot(new_x_y_z[1], color='y', label='ay') plt.plot(new_x_y_z[2], color='skyblue', label='az') plt.plot(xyz, color='black', label='xyz') figManager = plt.get_current_fig_manager() figManager.window.showMaximized() figManager.toolbar.pan() plt.tight_layout() plt.grid() plt.rcParams['figure.dpi'] = 100 plt.legend(loc='upper left') plt.show()
def interactive(key, executions, chosen_exec_nums): # XXX one exec for now # clear old sliders del(LAG_SLIDERS[:]) del(DECOMP_SLIDERS[:]) n_execs = len(chosen_exec_nums) fig, axes = plt.subplots(n_execs, 6, squeeze=False) buttons = [] # must hold refs, or they die col = 0 def mk_runseq_cb(data): def f(label): zoom_on_runseq(data, extra_title=key) return f def mk_lag_cb(data, lag): def f(label): zoom_on_lag(data, lag, extra_title=key) return f def mk_hist_cb(data): def f(label): zoom_on_hist(data, extra_title=key) return f def mk_acr_cb(data): def f(label): zoom_on_acr(data, extra_title=key) return f def mk_decomp_cb(data, freq, which): def f(label): zoom_on_decomp(data, freq, which, extra_title=key) return f # run seq for idx in range(n_execs): data = executions[idx] but = Button(axes[idx, col], "") axes[idx, col].axis(aspect="equal") buttons.append(but) but.on_clicked(mk_runseq_cb(data)) draw_runseq_subplot(axes[idx, col], data) col += 1 # lag for idx in range(n_execs): data = executions[idx] draw_lag_subplot(axes[idx, col], data, INITIAL_LAG) but = Button(axes[idx, col], "") buttons.append(but) but.on_clicked(mk_lag_cb(data, INITIAL_LAG)) col += 1 # histogram for idx in range(n_execs): data = executions[idx] but = Button(axes[idx, col], "") buttons.append(but) but.on_clicked(mk_hist_cb(data)) draw_hist_subplot(axes[idx, col], data) col += 1 # ACR for idx in range(n_execs): data = executions[idx] but = Button(axes[idx, col], "") buttons.append(but) but.on_clicked(mk_acr_cb(data)) draw_acr_subplot(axes[idx, col], data) col += 1 freq = INITIAL_DECOMP_FREQ # seasonal decomposition: seasons for idx in range(n_execs): data = executions[idx] but = Button(axes[idx, col], "") buttons.append(but) but.on_clicked(mk_decomp_cb(data, freq, DECOMP_TYPE_SEASONS)) draw_decomp_subplot(axes[idx, col], data, freq, DECOMP_TYPE_SEASONS) col += 1 # seasonal decomposition: trend for idx in range(n_execs): data = executions[idx] but = Button(axes[idx, col], "") buttons.append(but) but.on_clicked(mk_decomp_cb(data, freq, DECOMP_TYPE_TREND)) draw_decomp_subplot(axes[idx, col], data, freq, DECOMP_TYPE_TREND) col += 1 fig.suptitle("Overview -- %s -- executions %s" % (key, repr(chosen_exec_nums))) mng = plt.get_current_fig_manager() mng.resize(*mng.window.maxsize()) plt.show()
def __init__(self, desk): self.desk = desk self.failure = True self.error_msg = '' try: desk.get_params() except: self.error_msg = 'Could not get parameters.' return mbs = mb.mrBayesClass(desk) if not mbs.read_runPs(): self.error_msg = 'Problems reading Mr.Bayes files' return if not mbs.stat_files_to_dic(): self.error_msg = 'Could not read Mr.Bayes statistic files' return mbs.summary = {} params = [] if desk.piA_var.get(): params.append("pi(A)") if desk.piC_var.get(): params.append("pi(C)") if desk.piG_var.get(): params.append("pi(G)") if desk.piT_var.get(): params.append("pi(T)") if desk.rAC_var.get(): params.append("r(A<->C)") if desk.rAG_var.get(): params.append("r(A<->G)") if desk.rAT_var.get(): params.append("r(A<->T)") if desk.rCG_var.get(): params.append("r(C<->G)") if desk.rCT_var.get(): params.append("r(C<->T)") if desk.rGT_var.get(): params.append("r(G<->T") if desk.LnL_var.get(): params.append("LnL") if desk.LnPr_var.get(): params.append("LnPr") if desk.TL_var.get(): params.append("TL") if desk.alpha_var.get(): params.append("alpha") if desk.off_on_var.get(): params.append("s(off->on)") if desk.on_off_var.get(): params.append("s(on->off)") if desk.pinvar_var.get(): params.append("pinvar") if not params: self.error_msg = 'Define at least one param.' return iPar = 0 numCols = 46 numLines = 16 self.myPlot = graphPac.Plot() for par in params: iPar += 1 mbs.summary[par] = {} #fig = figList[iPar] fig = plt.figure(iPar) plt.subplots_adjust(left=0.05, right=0.95, bottom=0.05, top=0.90) # print plt.get_backend() mng = plt.get_current_fig_manager() mng.window.wm_geometry("1400x900+50+50") seqXs = [] mini, maxi = float('inf'), -float('inf') for min_max in mbs.min_maxs: for alig_cons in mbs.alig_conss: for std_covar in mbs.std_covars: study = min_max + '-' + alig_cons + '-' + std_covar try: vals = np.array(mbs.dic_detaild_params[study][par]) if np.min(vals) < mini: mini = min(vals) elif np.max(vals) > maxi: maxi = max(vals) except: pass if par != "LnL" and par != "LnPr": if par == "alpha": mini = 0 else: if mini < 0: mini = 0 if par in ["pi(A)", "pi(C)", "pi(G)", "pi(T)"]: if maxi > 1: maxi = 1 ticks = [] ticks0 = [] div = 5 delta = (maxi - mini) / float(div - 1) for i in range(div): ticks.append(round(mini + delta * i, 2)) ticks0.append(0) cntCols = 0 stri_summary = " \tAligned\tConsensus\n" for min_max in mbs.min_maxs: for alig_cons in mbs.alig_conss: listData = [] cntLine = 0 for std_covar in mbs.std_covars: try: _ = mbs.mb_filenames[min_max][alig_cons][std_covar] didFind = True except: didFind = False continue study = min_max + '-' + alig_cons + '-' + std_covar ''' try: dic = mbs.dic_detaild_params[study] except: # if file not found or could not read: it is not in dic_detailed_params continue ''' mbs.summary[par][study] = {} try: vals = np.array(mbs.dic_detaild_params[study][par]) mbs.summary[par][study] = {} N = len(vals) seqXs.append(np.array(vals)) mu, sigma, hmu, hsigma, q025, _, q2, _, q975 = mbs.stat_ppf_decimal( vals, par) mbs.summary[par][study]["N"] = N mbs.summary[par][study]["mu"] = mu mbs.summary[par][study]["sigma"] = sigma SE = sigma / np.sqrt(N) mbs.summary[par][study]["SE"] = SE mbs.summary[par][study]["N"] = N mbs.summary[par][study]["median"] = q2 mbs.summary[par][study]["q025"] = q025 mbs.summary[par][study]["q975"] = q975 if hmu: mbs.summary[par][study]["hmu"] = hmu mbs.summary[par][study]["hsigma"] = hsigma hSE = hsigma / np.sqrt(N) mbs.summary[par][study]["hSE"] = hSE mbs.summary[par][study]["min"] = np.min(vals) mbs.summary[par][study]["max"] = np.max(vals) try: ''' LnL doesn't have ESS and PSRF - adopted from TL total tree length (the sum of all branch lengths, TL) ''' if par == "LnL": mbs.summary[par][study][ "avgESS"] = mbs.dic_pstat[study]["TL"][ 'avgESS'] else: mbs.summary[par][study][ "avgESS"] = mbs.dic_pstat[study][par][ 'avgESS'] except: mbs.summary[par][study]["avgESS"] = 0 try: if par == "LnL": mbs.summary[par][study][ "PSRF"] = mbs.dic_pstat[study]["TL"][ 'PSRF'] else: mbs.summary[par][study][ "PSRF"] = mbs.dic_pstat[study][par][ 'PSRF'] except: mbs.summary[par][study]["PSRF"] = 10000 if mbs.summary[par][study]["avgESS"] < 90: sAvgESS = "avgESS=%3.1f **" % mbs.summary[par][ study]["avgESS"] else: sAvgESS = "avgESS=%3.1f" % mbs.summary[par][ study]["avgESS"] if (mbs.summary[par][study]["PSRF"] - 1) > .1: sPSRF = " PSRF=%1.2f ***" % mbs.summary[par][ study]["PSRF"] else: sPSRF = " PSRF=%1.2f" % mbs.summary[par][ study]["PSRF"] if cntLine == 0: ax = plt.subplot2grid((numLines, numCols), (0, cntCols), rowspan=4, colspan=10) else: ax = plt.subplot2grid((numLines, numCols), (6, cntCols), rowspan=4, colspan=10) if par == "LnL": print par, study, mu, sigma, hmu, hsigma stri_summary = mbs.show_lnl( desk, plt, ax, study, sAvgESS, sPSRF, cntLine, cntCols, min_max, alig_cons, stri_summary) else: print par, study, mu, sigma mbs.show_distrib(plt, ax, par, study, sAvgESS, sPSRF, ticks, desk.colors, iPar, mini, maxi, cntCols) listData.append(vals) cntLine += 1 except: pass if didFind: if len(listData) == 2: if par == "LnL": mbs.show_LRT(alig_cons, par, plt, numLines, numCols, cntCols) else: mbs.show_conf_interval(min_max, alig_cons, par, plt, numLines, numCols, cntCols, ticks, ticks0, mini, maxi, listData) mbs.show_qqplot2(min_max, alig_cons, par, plt, numLines, numCols, cntCols, listData) else: pass cntCols += 12 if par == "LnL": stri = "" else: f_value, p_value = mbs.calc_anova(seqXs) if p_value <= 0.05: stri = ', at least one distribution is statistically different.' else: stri = ', the distributions are statistically similar.' stri += 'ANOVA: f-value %2.3e p_value %2.3e' % (f_value, p_value) left = .05 top = .97 fig.text(left, top, par + stri, color="red") stri = mbs.ttest_summary(par) print stri sPar = par.replace(">", "").replace("<", "") pictureName = "%s_%s_mr_bayes_analisis_param_%s" % ( desk.organism, desk.gene_title, sPar) self.myPlot.print_graph(self.desk, fig, pictureName, frame=self.desk.tk_root, stay=False) print stri_summary if desk.saveData: mbs.save_params(params) self.failure = False return
count = 0 for d in data: for line in d: idx = stats.mode(np.where(policies == line[0:-1])[0])[0][0] if lifetimes[idx] == 0: lifetimes[idx] = line[-1] count += 1 if count > 184: break ## INITIALIZE CONTOUR PLOT # SETTINGS fig = plt.figure() plt.style.use('classic') plt.set_cmap(colormap) manager = plt.get_current_fig_manager() # Make full screen manager.window.showMaximized() minn, maxx = min_lifetime, max_lifetime # Calculate C4(CC1, CC2) values for contour lines C1_grid = np.arange(min_policy_bound - margin, max_policy_bound + margin, 0.01) C2_grid = np.arange(min_policy_bound - margin, max_policy_bound + margin, 0.01) [X, Y] = np.meshgrid(C1_grid, C2_grid) ## MAKE SUBPLOTS for k, c3 in enumerate(C3list): plt.subplot(2, 3, k + 1) plt.axis('square') plt.suptitle('Batch ' + str(1))
def phase_hist_gen(samplerate, samplerate_name, shaping, datadate, n_box, n_delay, n_att, numhead): phase_time = 1 / 20000000000 maxphase = int(20000000000 / samplerate + 0.5) filedir = 'G:/data/watchman/' + str( datadate ) + '_watchman_spe/studies/phase/' + samplerate_name + '/phase=0/phase_' + shaping + '/' Nloops = len(os.listdir(filedir)) filedir = 'G:/data/watchman/' + str( datadate ) + '_watchman_spe/studies/phase/' + samplerate_name + '/array_data/' median_array = np.loadtxt(filedir + 'median_array.csv', delimiter=',') correction_median_array = np.loadtxt(filedir + 'correction_median_array.csv', delimiter=',') difference_list = [] corrected_difference_list = [] for j in range(Nloops): print(j) i = random.randint(0, maxphase - 1) filedir = 'G:/data/watchman/' + str( datadate ) + '_watchman_spe/studies/phase/' + samplerate_name + '/phase=' + str( i) + '/phase_' + shaping + '/' filename = filedir + 'Phase--waveforms--%05d.txt' % j (t, v, _) = rw(filename, numhead) t_avg, v_avg = boxcar_wf(t, v, n_box) v_delay = delay_wf(v_avg, n_delay) v_att = attenuate_wf(v_avg, n_att) v_sum = sum_wf(v_att, v_delay) t_cross, _, _ = zc_locator(t_avg, v_sum) t_cross = t_cross - median_array[0] difference_list.append(-1 * i * phase_time - t_cross) corrected_difference_list.append(-1 * i * phase_time - (t_cross + correction_median_array[i])) difference_list = np.asarray(difference_list) corrected_difference_list = np.asarray(corrected_difference_list) FontSize = 32 plt.rcParams.update({'font.size': FontSize}) histo_mean, histo_std = gauss_histogram(difference_list) difference_list = difference_list[ (difference_list >= histo_mean - 5 * histo_std) & (difference_list <= histo_mean + 5 * histo_std)] true_mean = '%5g' % (np.mean(difference_list) * 1e12) true_std = '%5g' % (np.std(difference_list) * 1e12) bins = np.linspace(-2.2e-9, 2.2e-9, num=100) histo_data, bins_data = np.histogram(difference_list, bins=bins) binwidth = (bins_data[1] - bins_data[0]) binscenters = np.array([ 0.5 * (bins_data[i] + bins_data[i + 1]) for i in range(len(bins_data) - 1) ]) _, ax = plt.subplots() ax.bar(binscenters, histo_data, width=binwidth) ax.set_xlabel('True Timing - Recovered Timing') ax.set_ylabel('Count') ax.set_title(samplerate_name + ' - CFD Timings, Uncorrected') ax.text(0.025, 0.95, 'Distribution Parameters:\nMean: ' + true_mean + ' ps\nStandard Deviation: ' + true_std + ' ps', transform=ax.transAxes, fontsize=FontSize, verticalalignment='top', bbox=dict(boxstyle='round', facecolor='White', alpha=0.5)) plt.get_current_fig_manager().window.showMaximized() plt.show() histo_mean, histo_std = gauss_histogram(corrected_difference_list) corrected_difference_list = corrected_difference_list[ (corrected_difference_list >= histo_mean - 10 * histo_std) & (corrected_difference_list <= histo_mean + 10 * histo_std)] true_mean = '%5g' % (np.mean(corrected_difference_list) * 1e12) true_std = '%5g' % (np.std(corrected_difference_list) * 1e12) bins = np.linspace(-2.2e-9, 2.2e-9, num=100) histo_data, bins_data = np.histogram(corrected_difference_list, bins=bins) binwidth = (bins_data[1] - bins_data[0]) binscenters = np.array([ 0.5 * (bins_data[i] + bins_data[i + 1]) for i in range(len(bins_data) - 1) ]) _, ax = plt.subplots() ax.bar(binscenters, histo_data, width=binwidth) ax.set_xlabel('True Timing - Recovered Timing') ax.set_ylabel('Count') ax.set_title(samplerate_name + ' - CFD Timings') ax.text(0.025, 0.95, 'Distribution Parameters:\nMean: ' + true_mean + ' ps\nStandard Deviation: ' + true_std + ' ps', transform=ax.transAxes, fontsize=FontSize, verticalalignment='top', bbox=dict(boxstyle='round', facecolor='White', alpha=0.5)) plt.get_current_fig_manager().window.showMaximized() plt.show()
def on_pushButton_Lambda2_clicked(self): self.figGreen() plt.get_current_fig_manager().window.setGeometry(0, 300, 300, 300) plt.show(self.figG)
print(f'Logs.csv file found !') time.sleep(1) print(f'Start plotting ...') def split_at_value(list, value): indices = [i for i, x in enumerate(list) if x['Key'] == value] for start, end in zip([0, *indices], [*indices, len(list)]): yield list[start+1:end] fig = plt.figure(figsize=[8,4]) fig.subplots_adjust(left=0, bottom=0, right=1, top=1) plt.get_current_fig_manager().window.wm_iconbitmap(r"Images/icon.ico") plt.gcf().canvas.manager.set_window_title('Navigation Map') m = Basemap(projection='cyl', resolution=None, llcrnrlat=-90, urcrnrlat=90, llcrnrlon=-180, urcrnrlon=180) old_data = [] def animate (i): global old_data new_data = [] with open(r'Logs/Logs.csv', 'rt') as csv_file: reader = csv.DictReader(csv_file) row_index = 0
def on_pushButton_Lambda123_clicked(self): self.figWight() plt.get_current_fig_manager().window.setGeometry(300, 300, 300, 300) plt.show(self.figW)
# PHASE MARKER # data_phse = np.genfromtxt(file_path + 'phase.txt', delimiter=None, dtype=(float)) # get phase.txt data # phseChange = [] for i in range(0, len(data_x) - 1): if data_phse[i] != data_phse[i + 1]: phseChange.append(i + 1 - st_idx) else: pass axes = plt.gca() ## plot command/jpos fig = plt.figure(1) plt.get_current_fig_manager().window.wm_geometry("480x600+0+0") fig.canvas.set_window_title('reaction_force (right_leg)') for i in range(1, 4, 1): ax1 = plt.subplot(3, 1, i) plt.plot(data_x, data_rf_cmd[st_idx:end_idx,i-1], "r-", \ data_x, data_rf_sense[st_idx:end_idx,i-1], "b-") # plt.legend(('command', 'pos'), loc='upper left') # phase marker # for j in phseChange: # phase line plt.axvline(x=data_x[j], color='indigo', linestyle='-') # phase number plt.text(data_x[j], ax1.get_ylim()[1], '%d' % (data_phse[j]), color='indigo')