Beispiel #1
0
 def __init__(self,inputfilename):
     
     '''
     Initializing a ComboCode instance. 
     
     Once this is done, you only need to run startSession(). Then all 
     methods in this class will be called according to your inputfile. Only
     run separate methods of the class if you know what you are doing!
     
     Input is read and parsed, and the parameter objects (Star()) are set 
     
     The instrument and data objects, and the plotting manager are set.
     
     The .spec file is updated here, if requested.
     
     The inputfile can be given on the command line as: 
     python ComboCode.py inputComboCode.dat
     
     In the python or ipython shell you can do:
     >>> import ComboCode
     >>> cc = ComboCode.ComboCode('/home/robinl/ComboCode/input/inputComboCode.dat')
     
     @param inputfilename: The name of the inputfile. 
     @type inputfilename: string
     
     '''
     
     self.inputfilename = inputfilename
     self.readInput()
     self.setGlobalPars()
     self.setOutputFolders()
     self.setStarName()
     self.setPacs()
     self.setSpire()
     self.setSed()
     self.setRadio()
     self.setPlotManager()
     self.setVarPars()
     self.createStarGrid()
     self.addRadioData()
     #- Only the extra transition pars will differ across the grid, so grab
     #- the transition list from one of the Star() objects
     if self.update_spec: 
         Transition.updateLineSpec(self.star_grid[0]['GAS_LINES'])
     self.finished = False
Beispiel #2
0
 def runStatistics(self):
     
     '''
     Run the statistics module.
     
     '''
     
     self.pacsstats = None
     self.spirestats = None
     self.resostats = None
     if self.statistics and self.pacs <> None:
         print '************************************************'
         print '**** Doing PACS statistics for %s.'%self.star_name
         print '************************************************'
         self.pacsstats = UnresoStats.UnresoStats(star_name=self.star_name,\
                                         path_code=self.path_gastronoom)
         self.pacsstats.setInstrument(instrument_name='PACS',\
                                      instrument_instance=self.pacs,\
                                      stat_method=self.stat_method)
         self.pacsstats.setModels(star_grid=self.star_grid)
         self.pacsstats.setRatios(chi2_type=self.stat_chi2)
         self.pacsstats.plotRatioWav(inputfilename=self.inputfilename)
     if self.statistics and self.spire <> None:
         print '************************************************'
         print '**** Doing SPIRE statistics for %s.'%self.star_name
         print '************************************************'
         self.spirestats = UnresoStats.UnresoStats(star_name=self.star_name,\
                                         path_code=self.path_gastronoom)
         self.spirestats.setInstrument(instrument_name='SPIRE',\
                                       instrument_instance=self.spire,\
                                       stat_method=self.stat_method)
         self.spirestats.setModels(star_grid=self.star_grid)
         self.spirestats.setRatios(chi2_type=self.stat_chi2)
         self.spirestats.plotRatioWav(inputfilename=self.inputfilename)
     if self.statistics:
         trans_sel = Transition.extractTransFromStars(self.star_grid,\
                                                      dtype='resolved')
         if not trans_sel:
             return
         print '************************************************'
         print '**** Doing statistics for spectrally resolved lines in %s.'\
               %self.star_name
         print '**** Use cc_session.resostats for more interactive tools.'
         print '************************************************'
         self.resostats = ResoStats.ResoStats(star_name=self.star_name,\
                                        path_code=self.path_gastronoom,\
                                        lll_p=self.stat_lll_p)
         self.resostats.setInstrument(trans_sel)
         self.resostats.setModels(star_grid=self.star_grid)
         self.resostats.setIntensities()
         if self.stat_print:
             self.resostats.printStats()
Beispiel #3
0
    def setRatios(self, chi2_type='normal'):
        ''' 
        Find the peak to peak ratios of data versus model.
        
        The result are saved in the self.peak_ratios dictionary, see 
        __init__.__doc__()
        
        @keyword chi2_type: The type of chi-squared calculated for integrated 
                            fluxes. 'normal' for the usual kind, 'log' for chi2
                            of the log of the integrated fluxes and noise. 
                            
                            (default: normal)
        @type chi2_type: string
        
        '''

        inst = self.instrument
        print '***********************************'
        print '** Calculating integrated/peak intensity ratios for %s.'\
              %inst.instrument

        #-- Make a sample selection of Transition()s.
        sample_trans = Transition.extractTransFromStars(self.star_grid,\
                                                        dtype=inst.instrument)

        #-- Set the tolerance: a factor that is multiplied with half the
        #   wavelength resolution of data when looking for the peak value
        #   around a central wavelength in the data. As a default, this is
        #   equal to the PACS_OVERSAMPLING. No point in changing this.
        self.tolerance = inst.oversampling

        for ifn,(fn,dwav) in enumerate(zip(inst.data_filenames,\
                                           inst.data_wave_list)):
            #-- Create a list of sample transitions
            self.sample_trans[fn] = [trans
                                     for trans in sample_trans
                                     if trans.wavelength*10**4 >= dwav[0]\
                                        and trans.wavelength*10**4 <= dwav[-2]]
            #-- Get the central wavelength of the lines, corrected for
            #   Doppler shift due to vlsr of the central source. In micron.
            self.central_mwav[fn] = [
                t.wavelength * 10**4 * 1. / (1 - inst.vlsr / t.c)
                for t in self.sample_trans[fn]
            ]

            self.__setPeakRatios(ifn, fn)
            if inst.linefit <> None:
                self.__setIntRatios(ifn, fn, chi2_type=chi2_type)

        self.calcChiSquared()
        print '***********************************'
Beispiel #4
0
 def setRatios(self,chi2_type='normal'):
     
     ''' 
     Find the peak to peak ratios of data versus model.
     
     The result are saved in the self.peak_ratios dictionary, see 
     __init__.__doc__()
     
     @keyword chi2_type: The type of chi-squared calculated for integrated 
                         fluxes. 'normal' for the usual kind, 'log' for chi2
                         of the log of the integrated fluxes and noise. 
                         
                         (default: normal)
     @type chi2_type: string
     
     '''
     
     inst = self.instrument
     print '***********************************'
     print '** Calculating integrated/peak intensity ratios for %s.'\
           %inst.instrument
     
     #-- Make a sample selection of Transition()s.
     sample_trans = Transition.extractTransFromStars(self.star_grid,\
                                                     dtype=inst.instrument)
     
     #-- Set the tolerance: a factor that is multiplied with half the 
     #   wavelength resolution of data when looking for the peak value 
     #   around a central wavelength in the data. As a default, this is 
     #   equal to the PACS_OVERSAMPLING. No point in changing this.
     self.tolerance = inst.oversampling
     
     for ifn,(fn,dwav) in enumerate(zip(inst.data_filenames,\
                                        inst.data_wave_list)):
         #-- Create a list of sample transitions
         self.sample_trans[fn] = [trans
                                  for trans in sample_trans
                                  if trans.wavelength*10**4 >= dwav[0]\
                                     and trans.wavelength*10**4 <= dwav[-2]]
         #-- Get the central wavelength of the lines, corrected for 
         #   Doppler shift due to vlsr of the central source. In micron.
         self.central_mwav[fn] = [t.wavelength*10**4*1./(1-inst.vlsr/t.c)
                                  for t in self.sample_trans[fn]]
         
         self.__setPeakRatios(ifn,fn)
         if inst.linefit <> None:
             self.__setIntRatios(ifn,fn,chi2_type=chi2_type)
     
     self.calcChiSquared()
     print '***********************************'
Beispiel #5
0
    def setLineStrengths(self):
        ''' 
        Find the peak to peak ratios of data versus model.
        
        The result are saved in the self.peak_ratios dictionary, see 
        __init__.__doc__()
        
        '''

        inst = self.instrument
        print '***********************************'
        print '** Gathering model and observed line strengths for %s.'\
              %inst.instrument

        #-- Make a sample selection of Transition()s.
        sample_trans = Transition.extractTransFromStars(self.star_grid,\
                                                        dtype=inst.instrument)

        #-- Set the tolerance: a factor that is multiplied with half the
        #   wavelength resolution of data when looking for the peak value
        #   around a central wavelength in the data. As a default, this is
        #   equal to the PACS_OVERSAMPLING. No point in changing this.
        self.tolerance = inst.oversampling

        for ifn,(fn,dwav) in enumerate(zip(inst.data_filenames,\
                                           inst.data_wave_list)):
            #-- Create a list of sample transitions
            self.sample_trans[fn] = [trans
                                     for trans in sample_trans
                                     if trans.wavelength*10**4 >= dwav[0]\
                                        and trans.wavelength*10**4 <= dwav[-2]]
            #-- Get the central wavelength of the lines, corrected for
            #   Doppler shift due to vlsr of the central source. In micron.
            self.central_mwav[fn] = [
                t.wavelength * 10**4 * 1. / (1 - inst.vlsr / t.c)
                for t in self.sample_trans[fn]
            ]

            self.__setPeakRatios(ifn, fn)
            if not inst.linefit is None:
                self.__setIntRatios(ifn, fn)

        print '***********************************'
Beispiel #6
0
 def setLineStrengths(self):
     
     ''' 
     Find the peak to peak ratios of data versus model.
     
     The result are saved in the self.peak_ratios dictionary, see 
     __init__.__doc__()
     
     '''
     
     inst = self.instrument
     print '***********************************'
     print '** Gathering model and observed line strengths for %s.'\
           %inst.instrument
     
     #-- Make a sample selection of Transition()s.
     sample_trans = Transition.extractTransFromStars(self.star_grid,\
                                                     dtype=inst.instrument)
     
     #-- Set the tolerance: a factor that is multiplied with half the 
     #   wavelength resolution of data when looking for the peak value 
     #   around a central wavelength in the data. As a default, this is 
     #   equal to the PACS_OVERSAMPLING. No point in changing this.
     self.tolerance = inst.oversampling
     
     for ifn,(fn,dwav) in enumerate(zip(inst.data_filenames,\
                                        inst.data_wave_list)):
         #-- Create a list of sample transitions
         self.sample_trans[fn] = [trans
                                  for trans in sample_trans
                                  if trans.wavelength*10**4 >= dwav[0]\
                                     and trans.wavelength*10**4 <= dwav[-2]]
         #-- Get the central wavelength of the lines, corrected for 
         #   Doppler shift due to vlsr of the central source. In micron.
         self.central_mwav[fn] = [t.wavelength*10**4*1./(1-inst.vlsr/t.c)
                                  for t in self.sample_trans[fn]]
         
         self.__setPeakRatios(ifn,fn)
         if not inst.linefit is None:
             self.__setIntRatios(ifn,fn)
     
     print '***********************************'
Beispiel #7
0
    def makeTransitions(self,molecule,telescope=None,offset=0.0,n_quad=100,\
                        fraction_tau_step=1e-2,min_tau_step=1e-4,\
                        write_intensities=0,tau_max=12.,tau_min=-6.,\
                        check_tau_step=1e-2,):
        '''
        Make a list of transitions from the line list that was read.
        
        Default transitions parameters are the same as those used in
        Transition.Transition.__init__().
        
        Requires a Molecule() object to be passed to the method call. 
        
        @param molecule: The molecule for these transitions
        @type molecule: Molecule()
        
        @keyword telescope: The telescope that observed given line 
        
                            (default: None)
        @type telescope: string
        @keyword offset: The offset from center pixel of observed transition
                         
                         (default: None)
        @type offset: float
        @keyword n_quad: The number of grid points in the formal integration 
                         when calculating the line profile in sphinx.
                         
                         (default: 100)
        @type n_quad: int
        @keyword fraction_tau_step: tau_total*fraction_tau_step gives min. 
                                    delta_tau in strahl.f. If too low, 
                                    min_tau_step will be used.
        
                                    (default: 1e-2)
        @type fraction_tau_step: float
        @keyword min_tau_step: minimum of delta_tau in strahl.f
        
                               (default: 1e-4)
        @type min_tau_step: float
        @keyword write_intensities: set to 1 to write the intensities of first 
                                    50 impact-parameters at the end of sphinx
        
                                    (default: 0)
        @type write_intensities: bool
        @keyword tau_max: maximum optical depth used for the calculation of the 
                          formal integral
        
                          (default: 12.)
        @type tau_max: float
        @keyword tau_min: maximum optical depth used for the calculation of the
                          formal integral
        
                          (default: -6.)
        @type tau_min: float
        @keyword check_tau_step: check.par.in sphinx if step in tau not too 
                                 large
        
                                 (default: 0.01)
        @type check_tau_step: float
        
        @return: The transitions
        @rtype: list[Transition]
        
        '''

        pars = {'fraction_tau_step':fraction_tau_step,\
                'min_tau_step':min_tau_step,'tau_max':tau_max,\
                'write_intensities':write_intensities,'tau_min':tau_min,\
                'check_tau_step':check_tau_step,'n_quad':n_quad,\
                "offset":offset,'telescope':telescope}
        if molecule.spec_indices == 0:
            trans_list = [Transition.Transition(molecule=molecule,\
                                        frequency=float(trans[0])*10**6,\
                                        exc_energy=float(trans[12]),\
                                        int_intensity_log=float(trans[11]),\
                                        vup=int(trans[3]),\
                                        jup=int(trans[2]),\
                                        vlow=int(trans[7]),\
                                        jlow=int(trans[6]),\
                                        vibrational=trans[9],\
                                        **pars)
                          for trans in self.getLineList()]
        else:
            trans_list = [Transition.Transition(molecule=molecule,\
                                        frequency=float(trans[0])*10**6,\
                                        exc_energy=float(trans[12]),\
                                        int_intensity_log=float(trans[11]),\
                                        vup=int(trans[1]),\
                                        jup=int(trans[2]),\
                                        kaup=int(trans[3]),\
                                        kcup=int(trans[4]),\
                                        vlow=int(trans[5]),\
                                        jlow=int(trans[6]),\
                                        kalow=int(trans[7]),\
                                        kclow=int(trans[8]),\
                                        vibrational=trans[9],\
                                        **pars)
                          for trans in self.getLineList()]

        return trans_list
Beispiel #8
0
    def makeTransitions(self,telescope=None,offset=None,n_quad=None,\
                        use_maser_in_sphinx=None):
        '''
        Make a list of transitions from the line list that was read.
        
        If any of the extra transition parameters is None, the default in 
        Transition.Transition.__init__() is used.
        
        @keyword telescope: The telescope that observed given line 
        
                            (default: None)
        @type telescope: string
        @keyword offset: The offset from center pixel of observed transition
                         
                         (default: None)
        @type offset: float
        @keyword n_quad: The number of grid points in the formal integration 
                         when calculating the line profile in sphinx.
                         
                         (default: None)
        @type n_quad: int
        @keyword use_maser_in_sphinx: Allow masering in sphinx calculations
        
                                      (default: None)
        @type use_maser_in_sphinx: bool
        @return: The transitions
        @rtype: list[Transition]
        
        '''
        pars = dict([(parname,par)
                     for par,parname in zip([telescope,offset,\
                                             n_quad,use_maser_in_sphinx],\
                                            ['telescope','offset',\
                                             'n_quad','use_maser_in_sphinx'])
                     if par <> None])
        if self.molecule.spec_indices == 0 and self.cdms == 1:
            trans_list = [Transition.Transition(molecule=self.molecule,\
                                        frequency=float(trans[0])*10**6,\
                                        exc_energy=self.include_extra \
                                                        and float(trans[12]) \
                                                        or None,\
                                        int_intensity_log=self.include_extra \
                                                           and float(trans[11])\
                                                           or None,\
                                        vup=int(trans[3]),\
                                        jup=int(trans[2]),\
                                        vlow=int(trans[7]),\
                                        jlow=int(trans[6]),\
                                        vibrational=trans[9],\
                                        **pars)
                          for trans in self.getLineList()]
        else:
            trans_list = [Transition.Transition(molecule=self.molecule,\
                                        frequency=float(trans[0])*10**6,\
                                        exc_energy=self.include_extra \
                                                        and float(trans[12]) \
                                                        or None,\
                                        int_intensity_log=self.include_extra \
                                                           and float(trans[11])\
                                                           or None,\
                                        vup=int(trans[1]),\
                                        jup=int(trans[2]),\
                                        kaup=int(trans[3]),\
                                        kcup=int(trans[4]),\
                                        vlow=int(trans[5]),\
                                        jlow=int(trans[6]),\
                                        kalow=int(trans[7]),\
                                        kclow=int(trans[8]),\
                                        vibrational=trans[9],\
                                        **pars)
                          for trans in self.getLineList()]

        return trans_list