Changeset 45


Ignore:
Timestamp:
Sep 19, 2014 4:52:22 PM (10 years ago)
Author:
JohnLightfoot
Message:

almost working

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/skygenerator.py

    r38 r45  
    5151
    5252
    53 class TestLine(object):
     53class linespectrum(object):
    5454    """Class to return spectrum with line at wn.
    5555    """
    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
    5859        self.frequency_axis = frequency_axis
    5960
    6061    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
    6367        return spectrum
    6468
     
    7882        fts = self.previous_results['fts']
    7983        fts_wn_truncated = fts['fts_wn_truncated']
     84        cutoffmin = fts['wnmin']
     85        cutoffmax = fts['wnmax']
    8086
    8187        beamsgenerator = self.previous_results['beamsgenerator']
     
    8894
    8995        sky = self.parameters['substages']['Sky']
    90         columns = sky['SourceNum'].keys()
     96        columns = sky['sourcenum'].keys()
    9197
    9298        self.result['sources'] = collections.OrderedDict()
    9399
    94100        for column in columns:
    95             temp = sky['SourceNum'][column]
     101            temp = sky['sourcenum'][column]
    96102            sourcenum = int(round(temp))
    97103            if sourcenum not in self.result['sources'].keys():
    98104                self.result['sources'][sourcenum] = {}
    99105
    100             type = sky['Type'][column]
     106            type = sky['type'][column]
    101107
    102108            temp = sky['x pos [asec]'][column]
     
    106112            ypos = float(temp)
    107113
    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]
    109129            temperature = float(temp)
    110130
    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
    116136
    117137            temp = sky['emissivity'][column]
    118138            emissivity = float(temp)
    119139
    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)
    127155
    128156            if type.upper().strip() == 'POINT':
    129157                source_spectrum = self._create_point_source(xpos, ypos,
    130158                  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)
    131163            else:
    132164                source_spectrum = None
     
    140172
    141173        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
    142202
    143203    def _create_point_source(self, xpos, ypos, skymodel, spatial_axis,
Note: See TracChangeset for help on using the changeset viewer.