Package chianti :: Module filters
[hide private]
[frames] | no frames]

Source Code for Module chianti.filters

 1  ''' line profile filters from creating synthetic spectra 
 2   
 3  Copyright 2009, 2010 Kenneth P. Dere 
 4   
 5  This software is distributed under the terms of the GNU General Public License 
 6  that is found in the LICENSE file 
 7   
 8  ''' 
 9  import numpy as np 
10 -def gaussianR(wvl,wvl0, factor=1000.):
11 ''' 12 a gaussian filter where factor is the resolving power, so that the gaussian width (standard deviation) 13 is given by wvl0/factor''' 14 if factor: 15 std = wvl0/factor 16 else: 17 print(' the resolving power of the gaussianR filter is undefined') 18 return None 19 wvl = np.asarray(wvl, 'float64') 20 return np.exp(-0.5*((wvl - wvl0)/std)**2)/(np.sqrt(2.*np.pi)*std)
21
22 -def gaussian(wvl,wvl0, factor=0):
23 ''' 24 a gaussian filter where factor is the gaussian width (standard deviation) 25 ''' 26 if factor: 27 std = factor 28 else: 29 print(' the width of the gaussian filter is undefined') 30 return None 31 wvl = np.asarray(wvl, 'float64') 32 dwvl = wvl - np.roll(wvl, 1) 33 dwvl[0] = dwvl[1] 34 return np.exp(-0.5*((wvl - wvl0)/std)**2)/(np.sqrt(2.*np.pi)*std)
35 #
36 -def boxcar(wvl, wvl0, factor=0):
37 ''' box-car filter, factor is the full width of the box filter''' 38 wvl = np.asarray(wvl, 'float64') 39 dwvl = wvl - np.roll(wvl, 1) 40 dwvl[0] = dwvl[1] 41 one = np.ones_like(wvl) 42 zed = np.zeros_like(wvl) 43 if factor: 44 # width must be at least equal to the wavelength step 45 width = max(factor, dwvl.min()) 46 print((' width = %10.2e'%(width))) 47 else: 48 print(' the width of the box filter is undefined') 49 return None 50 good1 = (wvl > wvl0 - width/2.) 51 good2 = (wvl < wvl0 + width/2.) 52 realgood = np.logical_and(good1, good2) 53 return np.where(realgood, one, zed)/(width)
54 #
55 -def lorentz(wvl, wvl0, factor=0):
56 '''the lorentz profile with the exception that all factors are in wavelength units 57 rather than frequency as the lorentz profile is usually defined. 58 factor is the value of the so-called constant gamma''' 59 if factor: 60 gamma = factor 61 else: 62 print(' the factor gamma of the lorentz filter is undefined') 63 return None 64 wvl = np.asarray(wvl, 'float64') 65 dwvl = wvl - np.roll(wvl, 1) 66 dwvl[0] = dwvl[1] 67 ltz = (gamma/(2.*np.pi)**2)/((wvl - wvl0)**2 + (gamma/(4.*np.pi))**2) 68 return np.abs(ltz/(dwvl*ltz.sum()))
69 #
70 -def moffat(wvl, wvl0, factor=2.5):
71 ''' 72 the moffat profile with parameters suited to Chandra Letg spectra 73 ''' 74 wvl = np.asarray(wvl, 'float64') 75 dwvl = np.abs(wvl[1] - wvl[0]) 76 moffat = 1./(1.+((wvl - wvl0)/0.0275)**2)**factor 77 return moffat/(dwvl*moffat.sum())
78