Changeset 38
- Timestamp:
- Jun 10, 2014 10:40:25 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/skygenerator.py
r33 r38 14 14 """ 15 15 freq = wavenumber * sc.c * 100.0 16 jnu = 2.0 * sc.h * pow(freq,3) / (pow(sc.c,2) * 17 (math.exp((sc.h * freq) / (sc.k * temperature)) - 1.0)) 16 if freq > 0: 17 jnu = 2.0 * sc.h * pow(freq,3) / (pow(sc.c,2) * 18 (math.exp((sc.h * freq) / (sc.k * temperature)) - 1.0)) 19 else: 20 jnu = 0.0 18 21 19 22 return jnu 23 24 class BB_spectrum(object): 25 """Class to generate BB spectrum. 26 """ 27 def __init__(self, temperature, frequency_axis, cutoffmin, cutoffmax, 28 emissivity): 29 self.temperature = temperature 30 self.frequency_axis = frequency_axis 31 self.cutoffmin = cutoffmin 32 self.cutoffmax = cutoffmax 33 self.emissivity = emissivity 34 35 def calculate(self): 36 spectrum = np.zeros(np.shape(self.frequency_axis)) 37 # ignore floating point errors 38 old_settings = np.seterr(all='ignore') 39 40 for iwn,wn in enumerate(self.frequency_axis): 41 # simulate real-life 'rounded' cutoffs numerically 42 f1 = 1.0 / (1.0 + pow(self.cutoffmin/wn, 18) + 43 pow(wn/self.cutoffmax, 24)) 44 spectrum[iwn] = black_body(self.temperature, wn) * f1 * \ 45 self.emissivity 46 47 # restore fp behaviour 48 ignore = np.seterr(**old_settings) 49 50 return spectrum 51 52 53 class TestLine(object): 54 """Class to return spectrum with line at wn. 55 """ 56 def __init__(self, line_wn, frequency_axis): 57 self.line_wn = line_wn 58 self.frequency_axis = frequency_axis 59 60 def calculate(self): 61 spectrum = np.zeros(np.shape(self.frequency_axis)) 62 spectrum[self.frequency_axis==self.line_wn] = 1.0e-15 63 return spectrum 20 64 21 65 … … 33 77 34 78 fts = self.previous_results['fts'] 35 frequency_axis = fts['fts_wn'] 36 nspec = len(frequency_axis) 79 fts_wn_truncated = fts['fts_wn_truncated'] 37 80 38 81 beamsgenerator = self.previous_results['beamsgenerator'] … … 42 85 # skymodel is complex so that its fft can hold truncated version 43 86 # of infinitesimally sampled map - does that make sense? 44 skymodel = np.zeros([npix, npix, nspec], np.complex)87 skymodel = np.zeros([npix, npix, len(fts_wn_truncated)], np.complex) 45 88 46 89 sky = self.parameters['substages']['Sky'] … … 79 122 emissivity) 80 123 124 spectrum_func = BB_spectrum(temperature, fts_wn_truncated, 125 cutoffmin, cutoffmax, emissivity) 126 # spectrum_func = TestLine(50.0, fts_wn_truncated) 127 81 128 if type.upper().strip() == 'POINT': 82 129 source_spectrum = self._create_point_source(xpos, ypos, 83 temperature, 84 cutoffmin, cutoffmax, emissivity, skymodel, 85 spatial_axis, frequency_axis) 130 skymodel, spatial_axis, fts_wn_truncated, spectrum_func) 86 131 else: 87 132 source_spectrum = None … … 92 137 self.result['sky model'] = skymodel 93 138 self.result['spatial axis'] = spatial_axis 94 self.result['frequency axis'] = f requency_axis139 self.result['frequency axis'] = fts_wn_truncated 95 140 96 141 return self.result 97 142 98 def _create_point_source(self, xpos, ypos, temperature, cutoffmin,99 cutoffmax, emissivity, skymodel, spatial_axis, frequency_axis):143 def _create_point_source(self, xpos, ypos, skymodel, spatial_axis, 144 frequency_axis, spectrum_function): 100 145 """Create a point source. 101 146 """ … … 128 173 shift[:,i] *= shifty 129 174 130 # calculate black-body spectrum, modified for cutoffs in 131 # sensitivity and source emissivity 132 bbmod = np.zeros(np.shape(frequency_axis)) 133 # ignore floating point errors 134 old_settings = np.seterr(all='ignore') 135 for iwn,wn in enumerate(frequency_axis): 136 # simulate real-life 'rounded' cutoffs numerically 137 f1 = 1.0 / (1.0 + pow(cutoffmin/wn, 18) + pow(wn/cutoffmax, 24)) 138 bbmod[iwn] = black_body(temperature, wn) * f1 * emissivity 139 # restore fp behaviour 140 ignore = np.seterr(**old_settings) 175 # calculate spectrum 176 spectrum = spectrum_function.calculate() 141 177 142 178 # go through freq planes and add point source to each … … 144 180 # create point in frequency space 145 181 temp = np.zeros([nx,nx]) 146 temp[0,0] = bbmod[iwn]182 temp[0,0] = spectrum[iwn] 147 183 # 2d fft 148 184 temp = np.fft.fft2(temp) … … 151 187 # transform back 152 188 temp = np.fft.ifft2(temp) 153 temp = np.real(temp)154 189 155 190 # add to sky model … … 158 193 # return spectrum 159 194 axis = co.Axis(data=frequency_axis, title='wavenumber', units='cm-1') 160 spectrum = co.Spectrum(data= bbmod, axis=axis, title='Source spectrum',161 units='W sr-1 m-2 Hz-1')195 spectrum = co.Spectrum(data=spectrum, axis=axis, 196 title='Source spectrum', units='W sr-1 m-2 Hz-1') 162 197 163 198 return spectrum
Note:
See TracChangeset
for help on using the changeset viewer.