Changeset 45
- Timestamp:
- Sep 19, 2014 4:52:22 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/skygenerator.py
r38 r45 51 51 52 52 53 class TestLine(object):53 class linespectrum(object): 54 54 """Class to return spectrum with line at wn. 55 55 """ 56 def __init__(self, line_wn, frequency_axis): 57 self.line_wn = line_wn 56 def __init__(self, temperature, linefreq, frequency_axis): 57 self.temperature = temperature 58 self.linefreq = linefreq 58 59 self.frequency_axis = frequency_axis 59 60 60 61 def calculate(self): 61 spectrum = np.zeros(np.shape(self.frequency_axis)) 62 spectrum[self.frequency_axis==self.line_wn] = 1.0e-15 62 # spectrum is a sync function centred on the specified line freq 63 x = (self.frequency_axis - self.linefreq) / \ 64 (self.frequency_axis[1] - self.frequency_axis[0]) 65 spectrum = np.sinc(x) * self.temperature 66 63 67 return spectrum 64 68 … … 78 82 fts = self.previous_results['fts'] 79 83 fts_wn_truncated = fts['fts_wn_truncated'] 84 cutoffmin = fts['wnmin'] 85 cutoffmax = fts['wnmax'] 80 86 81 87 beamsgenerator = self.previous_results['beamsgenerator'] … … 88 94 89 95 sky = self.parameters['substages']['Sky'] 90 columns = sky[' SourceNum'].keys()96 columns = sky['sourcenum'].keys() 91 97 92 98 self.result['sources'] = collections.OrderedDict() 93 99 94 100 for column in columns: 95 temp = sky[' SourceNum'][column]101 temp = sky['sourcenum'][column] 96 102 sourcenum = int(round(temp)) 97 103 if sourcenum not in self.result['sources'].keys(): 98 104 self.result['sources'][sourcenum] = {} 99 105 100 type = sky[' Type'][column]106 type = sky['type'][column] 101 107 102 108 temp = sky['x pos [asec]'][column] … … 106 112 ypos = float(temp) 107 113 108 temp = sky['Temp'][column] 114 temp = sky['xwidth'][column] 115 try: 116 xwidth = float(temp) 117 except: 118 xwidth = None 119 120 temp = sky['ywidth'][column] 121 try: 122 ywidth = float(temp) 123 except: 124 ywidth = None 125 126 spectrum = sky['spectrum'][column] 127 128 temp = sky['temperature'][column] 109 129 temperature = float(temp) 110 130 111 temp = sky[' cutoffmin'][column]112 cutoffmin = float(temp)113 114 temp = sky['cutoffmax'][column]115 cutoffmax = float(temp)131 temp = sky['linefreq'][column] 132 try: 133 linefreq = float(temp) 134 except: 135 linefreq = None 116 136 117 137 temp = sky['emissivity'][column] 118 138 emissivity = float(temp) 119 139 120 print 'generating source:%s type:%s xpos:%s ypos:%s temperature:%s cutoffmin:%s cutoffmax:%s e:%s' % ( 121 sourcenum, type, xpos, ypos, temperature, cutoffmin, cutoffmax, 122 emissivity) 123 124 spectrum_func = BB_spectrum(temperature, fts_wn_truncated, 125 cutoffmin, cutoffmax, emissivity) 126 # spectrum_func = TestLine(50.0, fts_wn_truncated) 140 print 'generating source:%s type:%s xpos:%s ypos:%s' % (sourcenum, 141 type, xpos, ypos) 142 if type.upper().strip() == 'GAUSSIAN': 143 print ' fwhmx:%s fwhmy:%s' % (xwidth, ywidth) 144 145 if spectrum.upper().strip() == 'BLACKBODY': 146 print ' blackbody spectrum temperature:%s cutoffmin:%s cutoffmax:%s e:%s' % ( 147 temperature, cutoffmin, cutoffmax, emissivity) 148 spectrum_func = BB_spectrum(temperature, fts_wn_truncated, 149 cutoffmin, cutoffmax, emissivity) 150 151 elif spectrum.upper().strip() == 'LINE': 152 print ' line spectrum brightness temperature:%s cutoffmin:%s cutoffmax:%s e:%s' % ( 153 temperature, cutoffmin, cutoffmax, emissivity) 154 spectrum_func = linespectrum(temperature, linefreq, fts_wn_truncated) 127 155 128 156 if type.upper().strip() == 'POINT': 129 157 source_spectrum = self._create_point_source(xpos, ypos, 130 158 skymodel, spatial_axis, fts_wn_truncated, spectrum_func) 159 elif type.upper().strip() == 'GAUSSIAN': 160 source_spectrum = self._create_gaussian_source(xpos, ypos, 161 xwidth, ywidth, skymodel, spatial_axis, fts_wn_truncated, 162 spectrum_func) 131 163 else: 132 164 source_spectrum = None … … 140 172 141 173 return self.result 174 175 def _create_gaussian_source(self, xpos, ypos, xwidth, ywidth, 176 skymodel, spatial_axis, frequency_axis, spectrum_function): 177 """Create a point source. 178 """ 179 # calculate spectrum 180 spectrum = spectrum_function.calculate() 181 182 # calculate Gaussian profile - a cunning use of array slicing found 183 # on the web 184 x = spatial_axis 185 y = x[:,np.newaxis] 186 profile = np.exp(-4*np.log(2) * ((x-xpos)**2/xwidth**2 + (y-ypos)**2/ywidth**2)) 187 188 # # apodise 189 # profile[((x-xpos)**2 + (y-ypos)**2) < 4] = 1.0 190 191 # go through freq planes and add source to each 192 for iwn,wn in enumerate(frequency_axis): 193 # add to sky model 194 skymodel[:,:,iwn] += profile * spectrum[iwn] 195 196 # return spectrum 197 axis = co.Axis(data=frequency_axis, title='wavenumber', units='cm-1') 198 spectrum = co.Spectrum(data=spectrum, axis=axis, 199 title='Source spectrum', units='W sr-1 m-2 Hz-1') 200 201 return spectrum 142 202 143 203 def _create_point_source(self, xpos, ypos, skymodel, spatial_axis,
Note:
See TracChangeset
for help on using the changeset viewer.