def collection(self, value): if isinstance(value, Spectrum): # create new collection self._collection = Collection(name=Spectrum.name, spectra=[value]) if isinstance(value, Collection): self._collection = value else: self._collection = None
def update_artists(self, new_lim=False): if self.collection is None: return #update values being plotted -> redo statistics self.mean_line = None self.median_line = None self.max_line = None self.min_line = None self.std_line = None # save limits if new_lim == False: xlim = self.ax.get_xlim() ylim = self.ax.get_ylim() # plot self.ax.clear() # show statistics if self.spectrum_mode: idx = self.listbox.curselection() if len(idx) == 0: idx = [self.head] spectra = [self.collection.spectra[i] for i in idx] flags = [s.name in self.collection.flags for s in spectra] print("flags = ", flags) flag_style = ' ' if self.show_flagged: flag_style = 'r' artists = Collection(name='selection', spectra=spectra).plot( ax=self.ax, style=list(np.where(flags, flag_style, self.color)), picker=1) self.ax.set_title('selection') # c = str(np.where(spectrum.name in self.collection.flags, 'r', 'k')) # spectrum.plot(ax=self.ax, label=spectrum.name, c=c) else: # red curves for flagged spectra flag_style = ' ' if self.show_flagged: flag_style = 'r' flags = [ s.name in self.collection.flags for s in self.collection.spectra ] print("flags = ", flags) self.collection.plot(ax=self.ax, style=list(np.where(flags, flag_style, 'k')), picker=1) #self.ax.set_title(self.collection.name) keys = [s.name for s in self.collection.spectra] artists = self.ax.lines self.artist_dict = {key: artist for key, artist in zip(keys, artists)} self.colors = {key: 'black' for key in keys} self.ax.legend().remove() self.navbar.setHome(self.ax.get_xlim(), self.ax.get_ylim()) self.canvas.draw() self.sblabel.config(text="Showing: {}".format(len(artists)))
def _open_dataset(self, directory=None): directory = directory or \ QtWidgets.QFileDialog.getExistingDirectory(self, caption="Open Spectra Dataset") try: c = Collection(name="collection", directory=directory) self._directory = directory self._set_collection(c) except: pass
def filter_white(collection,wavelength0=0,wavelength1=10000,group='mean'): """Filter out white reference spectra from collection""" data = collection.data.loc[wavelength0:wavelength1] mean = data.mean(axis=0) std = data.std(axis=0) #a flat-ish spectrum at nearly 1 is probably white white = (mean > 0.9) & (mean < 1.1) & (std < .03) good = ~white if not good.all(): return split_good_bad(collection,good) return collection,Collection(collection.name+'_filtered')
def read_dir(self): try: directory = os.path.split( filedialog.askopenfilename(filetypes=( ("Supported types", "*.asd *.sed *.sig *.pico"), ("All files", "*"), )))[0] except: return if not directory: return c = Collection(name="collection", directory=directory) self.set_collection(c) self.dirLbl.config(text="Viewing: " + directory)
def filter_white(collection, wavelength0=0, wavelength1=10000, group='mean'): """Filter white reference spectra from collection Returns ------- good: specdal.containers.Collection A new collection made of the spectra that passed the filter bad: specdal.containers.Collection A new collection made of the spectra that failed the filter """ data = collection.data.loc[wavelength0:wavelength1] mean = data.mean(axis=0) std = data.std(axis=0) #a flat-ish spectrum at nearly 1 is probably white white = (mean > 0.9) & (mean < 1.1) & (std < .03) good = ~white if not good.all(): return split_good_bad(collection, good) return collection, Collection(collection.name + '_filtered')
def read_test_data(): path = '~/data/specdal/aidan_data2/ASD' c = Collection("Test Collection", directory=path) for i in range(30): c.flag(c.spectra[i].name)
def update(self): """ Update the plot """ if self.collection is None: return # show statistics if self.spectrum_mode: self.ax.clear() idx = self.listbox.curselection() if len(idx) == 0: idx = [self.head] spectra = [self.collection.spectra[i] for i in idx] flags = [s.name in self.collection.flags for s in spectra] print("flags = ", flags) flag_style = ' ' if self.show_flagged: flag_style = 'r' Collection(name='selection', spectra=spectra).plot( ax=self.ax, style=list(np.where(flags, flag_style, 'k')), picker=1) self.ax.set_title('selection') # c = str(np.where(spectrum.name in self.collection.flags, 'r', 'k')) # spectrum.plot(ax=self.ax, label=spectrum.name, c=c) else: # red curves for flagged spectra keys = [s.name for s in self.collection.spectra] for key in keys: if key in self.collection.flags: if self.show_flagged: self.artist_dict[key].set_visible(True) self.artist_dict[key].set_color('red') else: self.artist_dict[key].set_visible(False) else: self.artist_dict[key].set_color(self.colors[key]) self.artist_dict[key].set_visible(True) if self.show_flagged: self.sblabel.config( text="Showing: {}".format(len(self.artist_dict))) else: self.sblabel.config(text="Showing: {}".format( len(self.artist_dict) - len(self.collection.flags))) ''' self.collection.plot(ax=self.ax, style=list(np.where(flags, flag_style, 'k')), picker=1) self.ax.set_title(self.collection.name) ''' if self.spectrum_mode: #self.ax.legend() pass else: #self.ax.legend().remove() pass self.ax.set_ylabel(self.collection.measure_type) #toggle appearance of statistics if self.mean_line != None: self.mean_line.set_visible(self.mean) if self.median_line != None: self.median_line.set_visible(self.median) if self.max_line != None: self.max_line.set_visible(self.max) if self.min_line != None: self.min_line.set_visible(self.min) if self.std_line != None: self.std_line.set_visible(self.std) self.canvas.draw()