def get_data(self, lims=[5E-6, 295E-6], wantOffset=False): if "yoko" in self.scope_type.lower(): self.read_yoko(wantOffset) elif "lecroy" in self.scope_type.lower(): self.read_lecroy(wantOffset) else: raise IOError('Unknown scope type.') # Smooth out LOG and GOLF data if "log" in self.measurement_name.lower() or \ "golf" in self.measurement_name.lower(): window_length = 5.0 sma = filters.moving_average(self.data, window_length) self.data = sma # Integrate desired dE/dt waveforms if "int" in self.measurement_name.lower(): self.data = integrators.integrate_cumtrapz(y=self.data, x=self.dataTime, initial=0) self.get_plot(lims)
def plot_data_set(self, rs='all', meass='all', lim=20, window=1.0, norm=False): #~ mpl.rcdefaults() os.chdir('/home/jaime/Documents/ResearchTopics/Publications/Current Reflections/Data Sets/') for rss in self.root.iter('return_stroke'): r_s = int(rss.find('number').text) if rs == -1: pass elif 'all' in rs.lower(): pass elif r_s == int(rs): pass else: continue fileSave = "./DataFiles/%s_data_%s_rs%d.p" % (self.eventNamef, self.eventDate, r_s) data = pickle.load(open(fileSave, "rb")) data_only = {} if "all" in meass: ignore = [] E = ['E_5', 'E_18', 'E_23', 'E_12F', 'E_12', 'E_NW60', 'E_NW100'] dE = ['dE_1', 'dE_3', 'dE_4', 'dE_5', 'dE_7', 'dE_8', 'dE_9', 'dE_11', 'dE_17', 'dE_25', 'dE_OB'] intt = ['intE_1', 'intE_3', 'intE_4', 'intE_5', 'intE_7', 'intE_8', 'intE_9', 'intE_11', 'intE_17', 'intE_25', 'intE_OB'] ignore.extend(intt) ignore.extend(E) ignore.extend(['II_HI']) # ignore.extend(dE) for key in data: if key in ignore: pass else: data_only[key] = data[key] keys = data_only.keys() sort_data = {} for i, key in enumerate(keys): value = data[key].ax.get_title().split() if len(value) == 4: s = value[3] ind = s.find('km') if ind > 0: temp = float(value[3][:ind]) s = '%d' % (temp*1E3) ind = s.find('m') if ind > 0: s = value[3][:ind] sort_data[key] = float(s) else: s = value[4] ind = s.find('km') if ind > 0: temp = float(value[4][:ind]) s = '%d' % (temp*1E3) ind = s.find('m') if ind > 0: s = value[4][:ind] sort_data[key] = float(s) sorted_data = sorted(sort_data.items(), key=operator.itemgetter(1)) """ Print all in individual figures """ mpl.rcParams['savefig.directory'] = '/home/jaime/Documents/My Papers/Ongoing/Current Reflections/LaTex/Pictures/Temp/' for i in range(len(sorted_data)): fig, ax = plt.subplots(1, 1) #~ fig.suptitle('%s (%s/%s/%s)' % (event, eventDate[:2],eventDate[2:4], eventDate[4:]), fontsize=16) #~ fig.suptitle(event)#, fontsize=16) temp_data = data[sorted_data[i][0]].data # print(sorted_data[i], len(data[sorted_data[i][0]]), len(temp_data), len(data['time']), np.max(temp_data)) zoom_lim = [-1, int(lim)] # print(zoom_lim) factor = 1E-3 l_width = 2.5 if 'dE_' in sorted_data[i][0]: factor = 1E-9 l_width = 1.5 ax.plot(data[sorted_data[i][0]].dataTime, factor*temp_data, linewidth=l_width) ax.set_title(data[sorted_data[i][0]].ax.get_title()) if "ii_hi" in sorted_data[i][0].lower(): ylabel = '(kA)' elif "int" in sorted_data[i][0].lower(): ylabel = '(kV/m)' elif "de" in sorted_data[i][0].lower(): ylabel = '(kV/m/$\mu$s)' elif "e_" in sorted_data[i][0].lower(): ylabel = '(kV/m)' else: ylabel = data[sorted_data[i][0]].ax.get_ylabel() if '/us' in ylabel: ylabel = ylabel[:-3] + ylabel[-1] #~ ax.set_ylabel(ylabel) ax.set_xlim(zoom_lim) ax.xaxis.set_minor_locator(mpl.ticker.AutoMinorLocator()) ax.grid(True, which='both') ax.xaxis.set_tick_params(width=1.5) #~ ax.autoscale(True,'y') #~ ax.set_xlabel('Time ($\mu$s)') p = df.pickerPlot(fig, ax) p.plot() else: mpl.rcParams['savefig.directory'] = '/home/jaime/Documents/My Papers/Ongoing/Current Reflections/LaTex/Pictures/Temp/' x = data[meass].dataTime y = data[meass].data y_filtered = filters.moving_average(y, window) #~ plt.plot(x, y, '-', x,y_filtered, '--') norm_factor = 1.0 factor = 1E-3 l_width = 2.5 if 'dE_' in meass: factor = 1E-9 l_width = 1.5 ### Normalize waveform if norm: p = df.RelativeTimePlot(x,y) p.plot() plt.show() zero = y[p.zero_ind] p = df.RelativeTimePlot(x, y) p.plot() plt.show() peak = y[p.zero_ind] norm_factor = float(peak - zero)*factor fig = plt.figure() ax = fig.add_subplot(111) zoom_lim = [-1, int(lim)] title = '%s (RS #%d)' % (self.eventName, r_s) # title = '%s (ICC)' % self.eventName # title = data[meass].ax.get_title() # if factor == 1E-3: # ylabel = '(k%s' % (data[meass].ax.get_ylabel()[1:]) # else: # ylabel = data[meass].ax.get_ylabel() xlabel = 'Time ($\mu$s)' ax.plot(x*1e6, y_filtered*factor/norm_factor, linewidth=l_width) ax.set_title(title) #~ ax.set_ylabel(ylabel) #~ ax.set_xlabel(xlabel) ax.xaxis.set_minor_locator(mpl.ticker.AutoMinorLocator()) ax.grid(True, which='both') ax.xaxis.set_tick_params(width=1.5) #~ ax.autoscale(True,'y') ax.set_xlim(zoom_lim) #~ ax.yaxis.set_minor_locator(mpl.ticker.AutoMinorLocator()) p = df.pickerPlot(fig, ax) p.plot() plt.show()
for root, dir, file in os.walk(parent): if root == parent: files = file for file in files: print(file) data = pickle.load(open(parent+file, 'rb'))['II_HI'] t = data.dataTime * 1E-6 i = data.data __, di, __ = diff.differentiate(t, i) i = i / np.max(i) di = di / np.max(di) di_filtered = filters.moving_average(di) fig = plt.figure() ax = fig.add_subplot(111) ax.plot(t, i, t, di_filtered) ax.set_title(file[0:6] + '_'+ file[-8:-5] + ' - Normalized and filtered dI/dt (5 pt MA)') p = df.pickerPlot(fig, ax) p.plot() fig1 = plt.figure() ax1 = fig1.add_subplot(111) ax1.plot(t, i, t, di) ax1.set_title(file[0:6] + '_'+ file[-8:-5] + '- Normalized raw data') p1 = df.pickerPlot(fig1, ax1) p1.plot() plt.show()