def set_order(self,i): """ This modifies the currently active order to be plotted. """ import numpy as np import tayph.functions as fun import warnings import tayph.util as ut import copy from tayph.vartests import typetest typetest(i,int,'i in mask_maker.set_order()',) self.wl = self.list_of_wls[i] self.order = self.list_of_orders[i] #Measure the shape of the current order self.nexp = np.shape(self.order)[0] self.npx = np.shape(self.order)[1] #Compute the meanspec and the residuals, ignoring runtime warnings related to NaNs: with warnings.catch_warnings(): warnings.simplefilter("ignore", category=RuntimeWarning) self.meanspec = np.nanmean(self.list_of_orders[i],axis=0) self.residual = self.order / self.meanspec self.img_max = np.nanmean(self.meanspec[fun.selmax(self.meanspec,0.02,s=0.02)])*1.3 self.vmin = np.nanmedian(self.residual)-3.0*np.nanstd(self.residual) self.vmax = np.nanmedian(self.residual)+3.0*np.nanstd(self.residual)
def envelope(wlm, fxm, binsize, selfrac=0.05, mode='top', threshold=''): """ This program measures the top or bottom envelope of a spectrum (wl,fx), by chopping it up into bins of size binsze (unit of wl), and measuring the mean of the top n % of values in that bin. Setting the mode to 'bottom' will do the oppiste: The mean of the bottom n% of values. The output is the resulting wl and flux points of these bins. Example: wle,fxe = envelope(wl,fx,1.0,selfrac=3.0,mode='top') """ import numpy as np import tayph.util as ut import tayph.functions as fun from tayph.vartests import typetest, dimtest, nantest, postest from matplotlib import pyplot as plt typetest(wlm, np.ndarray, 'wlm in ops.envelope()') typetest(fxm, np.ndarray, 'fxm in ops.envelope()') dimtest(wlm, [len(fxm)]) typetest(binsize, [int, float], 'binsize in ops.envelope()') typetest(selfrac, float, 'percentage in ops.envelope()') typetest(mode, str, 'mode in envelope') nantest(fxm, 'fxm in ops.envelope()') nantest(wlm, 'wlm in ops.envelope()') postest(wlm, 'wlm in ops.envelope()') postest(binsize, 'binsize in ops.envelope()') if mode not in ['top', 'bottom']: raise Exception( f'RuntimeError in ops.envelope(): Mode should be set to "top" or "bottom" ({mode}).' ) binsize = float(binsize) if mode == 'bottom': fxm *= -1.0 wlcs = np.array([]) #Center wavelengths fxcs = np.array([]) #Flux at center wavelengths i_start = 0 wlm_start = wlm[i_start] for i in range(0, len(wlm) - 1): if wlm[i] - wlm_start >= binsize: wlsel = wlm[i_start:i] fxsel = fxm[i_start:i] maxsel = fun.selmax(fxsel, selfrac) wlcs = np.append(wlcs, np.mean(wlsel[maxsel])) fxcs = np.append(fxcs, np.mean(fxsel[maxsel])) i_start = i + 1 wlm_start = wlm[i + 1] if isinstance(threshold, float) == True: #This means that the threshold value is set, and we set all bins less than #that threshold to the threshold value: if mode == 'bottom': threshold *= -1.0 fxcs[(fxcs < threshold)] = threshold if mode == 'bottom': fxcs *= -1.0 fxm *= -1.0 return wlcs, fxcs
def set_spectrum(self, i): """This modifies the currently active spectrum to be plotted.""" import numpy as np import tayph.functions as fun from tayph.vartests import typetest import matplotlib.pyplot as plt typetest(i, int, 'i in molecfit_gui/set_order') self.wl = self.wls[i] self.spectrum = self.fxc[i] self.Tspectrum = self.trans[i] self.img_max = np.nanmean(self.spectrum[fun.selmax( self.spectrum, 0.02, s=0.02)]) * 1.3