def setNoise(self,vexp=None): """ Calculate the noise of the dataset, by taking the standard deviation of the velocity range lower than v_lsr - 2*vexp. If this is not available, the velocity range is taken to be where it is smaller than 1.1*vexp. If the size of the above selection still is too small, None is returned. The gas terminal velocity has to have been set previously or passed to this method as a keyword. @keyword vexp: The terminal gas velocity, only required if vexp is not set yet for this LPDataReader object! (default: None) @type vexp: float @return: The noise of the dataset @rtype: float """ if not vexp is None and not self['contents'].has_key('vexp'): self['contents']['vexp'] = float(vexp) if not self['contents'].has_key('vexp'): print 'Cannot set noise without an estimate for the terminal gas'+\ ' velocity. Pass as keyword to this method!' return None vel = self['contents']['velocity'] flux = self['contents']['flux'] vlsr = self['contents']['vlsr'] vexp = self['contents']['vexp'] noise = Data.getStd(wave=vel,flux=flux,wmin=vlsr-5*vexp,\ wmax=vlsr-2*vexp,minsize=10) if noise is None: noise = Data.getStd(wave=vel,flux=flux,wmin=vlsr-3*vexp,\ wmax=vlsr-1.8*vexp,minsize=10) if noise is None: noise = Data.getStd(wave=vel,flux=flux,wmin=vlsr-3*vexp,\ wmax=vlsr-1.1*vexp,minsize=10) if noise is None: noise = Data.getStd(wave=vel,flux=flux,wmin=vlsr-3*vexp,\ wmax=vlsr-1.1*vexp,minsize=5) if noise is None: print 'WARNING! Noise cannot be determined, not enough data ' + \ 'points outside the emission line.' self['contents']['noise'] = noise
def doDataStats(self,method='clipping'): ''' Calculate mean, std, rms for the data files. They are saved in self.data_stats. @keyword method: Std/Mean/RMS determination method. Can be 'clipping' or 'preset'. The former 1-sigma clips based on mean/std/... of full spectrum, then takes mean/std/... of clipped spectrum. Latter takes preset values from Data.dat. (default: 'clipping') @type method: string ''' method = method.lower() if method not in ['preset','clipping']: method = 'clipping' self.data_stats = dict() if self.instrument: if not self.data_info: self.setDataInfo() for filename,data_wave,data_flux,band in \ zip(self.instrument.data_filenames,\ self.instrument.data_wave_list,\ self.instrument.data_flux_list,\ self.instrument.data_ordernames): these_stats = dict() iband = self.data_info['bands'].index(band) these_stats['sigma'] = self.data_info['sigmas'][iband] if method == 'preset': w_std_min = self.data_info['w_std_min'][iband] w_std_max = self.data_info['w_std_max'][iband] if w_std_min < data_wave[0] or w_std_max > data_wave[-1]: method = 'clipping' test_mean = Data.getMean(wave=data_wave,flux=data_flux,\ wmin=w_std_min,wmax=w_std_max) if test_mean is None: method = 'clipping' if method == 'clipping': totmean = Data.getMean(wave=data_wave,flux=data_flux) totstd = Data.getStd(wave=data_wave,flux=data_flux) limits = (-totstd,totstd) these_stats['mean'] = Data.getMean(flux=data_flux,\ limits=limits) these_stats['std'] = Data.getStd(flux=data_flux,\ limits=limits) these_stats['rms'] = Data.getRMS(flux=data_flux-\ these_stats['mean'],\ limits=limits) else: these_stats['mean'] = Data.getMean(wave=data_wave,\ flux=data_flux,\ wmin=w_std_min,\ wmax=w_std_max) these_stats['std'] = Data.getStd(wave=data_wave,\ flux=data_flux,\ wmin=w_std_min,\ wmax=w_std_max) these_stats['rms'] = Data.getRMS(wave=data_wave,\ flux=data_flux-\ these_stats['mean'],\ wmin=w_std_min,\ wmax=w_std_max) print '* Data statistics for %s using "%s" method:'\ %(filename,method) if method == 'preset': print '* Taken between %.2f and %.2f micron.'\ %(w_std_min,w_std_max) print 'mean = ',these_stats['mean'],' Jy' print 'std = ',these_stats['std'],' Jy' print 'RMS = ',these_stats['rms'],' Jy' self.data_stats[filename] = these_stats print '***********************************'