コード例 #1
0
ファイル: PlotDust.py プロジェクト: FungKu01/ComboCode
    def plotVisibilities(self,star_grid=[],cfg='',no_models=0,\
                         fn_add_star=0):
        
        """ 
        Plot visibilities as a function of baseline.
        
        Wavelengths plotted are what is requested in the ray tracing

        Includes data preparation on the spot.
        
        Data location is that of correlated flux (for the visibilities), but 
        also requires an sed object to retrieve the MIDI spectrum. If one of 
        them is not available, models are be plotted without data.

        @keyword star_grid: list of Star() models to plot. If star_grid is [], 
                            only data are plotted.
                            
                            (default: [])
        @type star_grid: list[Star()]
        @keyword cfg: path to the Plotting2.plotCols config file. If default,
                      the hard-coded default plotting options are used.
                        
                      (default: '')
        @type cfg: string
        @keyword no_models: Only show data.
                                  
                            (default: 0)
        @type no_models: bool
        @keyword fn_add_star: Add the star name to the requested plot filename.
        
                              (default: 1)
        @type fn_add_star: bool
        
        """
        
        if not cc.path.dcflux:
            print 'No dcflux given in Path.dat. Aborting...'
            return
        if not self.sed or 'MIDI' not in self.sed.data_types:
            print 'No dsed given in Path.dat or no MIDI spectral data found. Aborting.'
            return
        
        print '***********************************'
        print '** Creating Visibilities plot.'
        cfg_dict = Plotting2.readCfg(cfg)
        if cfg_dict.has_key('no_models'):
            no_models = cfg_dict['no_models']
        if cfg_dict.has_key('fn_add_star'):
            fn_add_star = bool(cfg_dict['fn_add_star'])
        if cfg_dict.has_key('filename'):
            fn_plt = cfg_dict['filename']
            del cfg_dict['filename']
        else:
            fn_plt = ''
        
        #- filename settings and copying inputfiles to plot output folder
        if not fn_plt:
            fn_plt = os.path.join(self.pplot,'Visibilities')
        if fn_add_star:
            fn_plt = '_'.join([fn_plt,self.star_name])
        
        if self.inputfilename <> None:
            ipfn = os.path.split(self.inputfilename)[1]
            subprocess.call(['cp ' + self.inputfilename + ' ' + \
                             os.path.join(self.pplot,ipfn)],\
                            shell=True)

        #-- Read the models. Wavelengths are taken from the ray-tracing output
        models = []
        if not no_models:
            for s in star_grid:
                model_id = s['LAST_MCMAX_MODEL']
                dpath = os.path.join(cc.path.mout,'models',model_id)
                model = MCMax.readVisibilities(dpath=dpath,\
                                               fn_vis='basevis01.0.dat')
                models.append(model)
            real_models = [model for model in models if model]
            if not real_models: 
                no_models = 1 
            else:
                wavelengths = sorted(real_models[0]['wavelength'].keys())
        
        if no_models: wavelengths = (8.,10.,13.)
        
        #-- Grab the MIDI spectrum
        fn = self.sed.data_filenames[self.sed.data_types.index('MIDI')]
        midi_flux = self.sed.data[('MIDI',fn)][1]
        midi_err = self.sed.data[('MIDI',fn)][2]
        midi_relerr = (midi_err/midi_flux)**2
        
        #-- Select MIDI data. Assumes baseline at the end of the filename.
        ssd = os.path.join(cc.path.dcflux,self.star_name,\
                           '_'.join([self.star_name,'MIDI','*.fits']))
        files = [os.path.splitext(gi)[0] for gi in glob.glob(ssd)]
        ggd = dict([(float(gi.split('_')[-1].strip('m')),gi+'.fits') 
                    for gi in files])
        
        #-- Collect MIDI data from the fits file and calculate visibilities
        ddf = dict()
        for k,v in sorted(ggd.items()):
            ddf[k] = dict()
            dfits = pyfits.open(v)
            
            #-- Read the wavelength
            cwave = 1e6*dfits['OI_WAVELENGTH'].data['EFF_WAVE'][::-1]
            
            #-- Read flux + err and select the right range
            cflux = dfits['OI_VIS'].data['VISAMP'][0][::-1]
            cflux = cflux[(cwave<=13.)*(cwave>=8.)]
            cflux_err = dfits['OI_VIS'].data['VISAMPERR'][0][::-1]
            cflux_err = cflux_err[(cwave<=13.)*(cwave>=8.)]
            
            #-- The visibilities are correlated flux divided by real flux
            ddf[k]['y'] = cflux/midi_flux
            
            #-- Error propagation
            cflux_relerr = (cflux_err/cflux)**2
            yerr = np.sqrt(midi_relerr + cflux_relerr)*cflux/midi_flux
            ddf[k]['yerr'] = yerr
            
            #-- Wavelength grid
            ddf[k]['x'] = cwave[(cwave<=13.)*(cwave>=8.)]
            dfits.close()
        
        #-- prepare and collect plot data, keytags and line types
        data = []
        for w in wavelengths:
            ddict = dict()
            data.append(ddict)
            
            #-- Set the plot x and y
            bls = [k for k in sorted(ddf.keys())]
            ddict['x'] = [[bl for bl in bls]]
            ddict['y'] = [[ddf[bl]['y'][np.argmin(abs(ddf[bl]['x']-w))]
                           for bl in bls]]
            ddict['yerr'] = [[ddf[bl]['yerr'][np.argmin(abs(ddf[bl]['x']-w))]
                              for bl in bls]]
            #-- Set limits and labels
            ddict['labels'] = [('MIDI %s $\\mu$m'%w,0.85,0.9)]
            
            if no_models:
                continue
            
            #-- Extract models from the model folders
            for model in models:
                ddict['yerr'].append(None)
                if not model: 
                    ddict['x'].append(np.empty(0))
                    ddict['y'].append(np.empty(0))
                    continue
                ddict['x'].append(model['baseline'])
                ddict['y'].append(model['wavelength'][w])
                            
        kwargs = dict()
        kwargs['keytags'] = ['MIDI']
        if not no_models:
            kwargs['keytags'].extend([s['LAST_MCMAX_MODEL'].replace('_','\_') 
                                      for s in star_grid])
        kwargs['xaxis'] = 'Baseline (m)'
        kwargs['yaxis'] = 'Visibility'
        kwargs['dimensions'] = (1,len(data)+1)
        kwargs['figsize'] = (10,15)
        kwargs['fontsize_axis'] = 20
        kwargs['fontsize_ticklabels'] = 20
        kwargs['fontsize_key'] = 18
        kwargs['fontsize_label'] = 14
        kwargs['linewidth'] = 3
        kwargs['cfg'] = cfg_dict
        kwargs['extension'] = '.pdf'
        kwargs['hspace'] = 0.3
        kwargs['ws_bot'] = 0.01
        kwargs['ws_top'] = 0.99
        kwargs['ws_left'] = 0.10
        kwargs['ws_right'] = 0.98

        filename = Plotting2.plotTiles(data=data,filename=fn_plt,**kwargs)
        print '** Your Correlated Flux plots can be found at:'
        print filename
        print '***********************************'
コード例 #2
0
    def plotCorrflux(self, star_grid=[], cfg='', no_models=0, fn_add_star=0):
        """ 
        Plot correlated fluxes with 0, 1 or more models and data. 
        
        Includes data preparation on the spot.
        
        @keyword star_grid: list of Star() models to plot. If star_grid is [], 
                            only data are plotted.
                            
                            (default: [])
        @type star_grid: list[Star()]
        @keyword cfg: path to the Plotting2.plotCols config file. If default,
                      the hard-coded default plotting options are used.
                        
                      (default: '')
        @type cfg: string
        @keyword no_models: Only show data.
                                  
                            (default: 0)
        @type no_models: bool
        @keyword fn_add_star: Add the star name to the requested plot filename.
        
                              (default: 1)
        @type fn_add_star: bool

        
        """

        if not cc.path.dcflux:
            print 'No dcflux given in Path.dat. Cannot plot Correlated Fluxes. Aborting...'
            return
        print '***********************************'
        print '** Creating Correlated Fluxes plot.'

        cfg_dict = Plotting2.readCfg(cfg)
        if cfg_dict.has_key('no_models'):
            no_models = cfg_dict['no_models']
        if cfg_dict.has_key('fn_add_star'):
            fn_add_star = bool(cfg_dict['fn_add_star'])
        if cfg_dict.has_key('filename'):
            fn_plt = cfg_dict['filename']
            del cfg_dict['filename']
        else:
            fn_plt = ''

        #- filename settings and copying inputfiles to plot output folder
        if not fn_plt:
            fn_plt = os.path.join(self.pplot, 'CorrFlux')
        if fn_add_star:
            fn_plt = '_'.join([fn_plt, self.star_name])

        if self.inputfilename <> None:
            ipfn = os.path.split(self.inputfilename)[1]
            subprocess.call(['cp ' + self.inputfilename + ' ' + \
                             os.path.join(self.pplot,ipfn)],\
                            shell=True)

        #-- Select MIDI data. Assumes baseline at the end of the filename.
        ssd = os.path.join(cc.path.dcflux,self.star_name,\
                           '_'.join([self.star_name,'MIDI','*.fits']))
        files = [os.path.splitext(gi)[0] for gi in glob.glob(ssd)]
        ggd = dict([(float(gi.split('_')[-1].strip('m')), gi + '.fits')
                    for gi in files])

        #-- Read the models
        models = []
        if not no_models:
            for s in star_grid:
                model_id = s['LAST_MCMAX_MODEL']
                dpath = os.path.join(cc.path.mout, 'models', model_id)
                model = MCMax.readVisibilities(dpath=dpath,\
                                               fn_vis='visibility01.0.dat')
                models.append(model)
            real_models = [model for model in models if model]
            if not real_models:
                no_models = 1
                baselines = sorted(ggd.keys())
            else:
                baselines = sorted(real_models[0]['baseline'].keys())

        #-- prepare and collect data, keytags and line types
        data = []
        for bl in baselines:
            ddict = dict()
            data.append(ddict)

            #-- Extract data from the fits file
            if ggd.has_key(bl):
                dfits = pyfits.open(ggd[bl])
                x = 1e6 * dfits['OI_WAVELENGTH'].data['EFF_WAVE'][::-1]
                ddict['x'] = [x]
                ddict['y'] = [dfits['OI_VIS'].data['VISAMP'][0]][::-1]
                ddict['yerr'] = [dfits['OI_VIS'].data['VISAMPERR'][0]][::-1]
                dfits.close()
            else:
                ddict['x'] = []
                ddict['y'] = []
                ddict['yerr'] = []

            if no_models:
                continue

            #-- Extract models from the model folders
            for model in models:
                ddict['yerr'].append(None)
                if not model:
                    ddict['x'].append(np.empty(0))
                    ddict['y'].append(np.empty(0))
                    continue
                ddict['x'].append(model['wavelength'])
                ddict['y'].append(model['flux'] * model['baseline'][bl])

            #-- Set some plot limits
            ddict['xmin'] = 8
            ddict['xmax'] = 13
            ddict['ymin'] = -0.1
            ddict['labels'] = [('MIDI %.1f m' % bl, 0.05, 0.9)]
            #-- Wavelength limits between 8 and 13 micron, limits of the N band
            #   atmospheric transmission. Outside these ranges, the flux is not
            #   relevant
            ddict['ymax'] = 1.1 * max([
                max(iy[(ix <= 13.) * (ix >= 8.)])
                for ix, iy in zip(ddict['x'], ddict['y']) if iy.size
            ])
        kwargs = dict()
        kwargs['keytags'] = ['MIDI']
        if not no_models:
            kwargs['keytags'].extend(
                [s['LAST_MCMAX_MODEL'].replace('_', '\_') for s in star_grid])
        kwargs['xaxis'] = '$\lambda$ ($\mu$m)'
        kwargs['yaxis'] = 'Corr.~FLux (Jy)'
        kwargs['dimensions'] = (1, len(data) + 1)
        kwargs['figsize'] = (10, 15)
        kwargs['fontsize_axis'] = 20
        kwargs['fontsize_ticklabels'] = 20
        kwargs['fontsize_key'] = 18
        kwargs['fontsize_label'] = 14
        kwargs['linewidth'] = 3
        kwargs['cfg'] = cfg_dict
        kwargs['extension'] = '.pdf'
        kwargs['hspace'] = 0.3
        kwargs['ws_bot'] = 0.01
        kwargs['ws_top'] = 0.99
        kwargs['ws_left'] = 0.10
        kwargs['ws_right'] = 0.98
        filename = Plotting2.plotTiles(data=data, filename=fn_plt, **kwargs)
        print '** Your Correlated Flux plots can be found at:'
        print filename
        print '***********************************'
コード例 #3
0
ファイル: PlotDust.py プロジェクト: FungKu01/ComboCode
    def plotCorrflux(self,star_grid=[],cfg='',no_models=0,fn_add_star=0):
        
        """ 
        Plot correlated fluxes with 0, 1 or more models and data. 
        
        Includes data preparation on the spot.
        
        @keyword star_grid: list of Star() models to plot. If star_grid is [], 
                            only data are plotted.
                            
                            (default: [])
        @type star_grid: list[Star()]
        @keyword cfg: path to the Plotting2.plotCols config file. If default,
                      the hard-coded default plotting options are used.
                        
                      (default: '')
        @type cfg: string
        @keyword no_models: Only show data.
                                  
                            (default: 0)
        @type no_models: bool
        @keyword fn_add_star: Add the star name to the requested plot filename.
        
                              (default: 1)
        @type fn_add_star: bool

        
        """
        
        if not cc.path.dcflux:
            print 'No dcflux given in Path.dat. Cannot plot Correlated Fluxes. Aborting...'
            return
        print '***********************************'
        print '** Creating Correlated Fluxes plot.'
        
        cfg_dict = Plotting2.readCfg(cfg)
        if cfg_dict.has_key('no_models'):
            no_models = cfg_dict['no_models']
        if cfg_dict.has_key('fn_add_star'):
            fn_add_star = bool(cfg_dict['fn_add_star'])
        if cfg_dict.has_key('filename'):
            fn_plt = cfg_dict['filename']
            del cfg_dict['filename']
        else:
            fn_plt = ''
        
        #- filename settings and copying inputfiles to plot output folder
        if not fn_plt:
            fn_plt = os.path.join(self.pplot,'CorrFlux')
        if fn_add_star:
            fn_plt = '_'.join([fn_plt,self.star_name])
        
        if self.inputfilename <> None:
            ipfn = os.path.split(self.inputfilename)[1]
            subprocess.call(['cp ' + self.inputfilename + ' ' + \
                             os.path.join(self.pplot,ipfn)],\
                            shell=True)

        #-- Select MIDI data. Assumes baseline at the end of the filename.
        ssd = os.path.join(cc.path.dcflux,self.star_name,\
                           '_'.join([self.star_name,'MIDI','*.fits']))
        files = [os.path.splitext(gi)[0] for gi in glob.glob(ssd)]
        ggd = dict([(float(gi.split('_')[-1].strip('m')),gi+'.fits') 
                    for gi in files])

        #-- Read the models
        models = []
        if not no_models:
            for s in star_grid:
                model_id = s['LAST_MCMAX_MODEL']
                dpath = os.path.join(cc.path.mout,'models',model_id)
                model = MCMax.readVisibilities(dpath=dpath,\
                                               fn_vis='visibility01.0.dat')
                models.append(model)
            real_models = [model for model in models if model]
            if not real_models: 
                no_models = 1 
                baselines = sorted(ggd.keys())
            else:
                baselines = sorted(real_models[0]['baseline'].keys())
        
        #-- prepare and collect data, keytags and line types
        data = []
        for bl in baselines:
            ddict = dict()
            data.append(ddict)

            #-- Extract data from the fits file
            if ggd.has_key(bl): 
                dfits = pyfits.open(ggd[bl])
                x = 1e6*dfits['OI_WAVELENGTH'].data['EFF_WAVE'][::-1]
                ddict['x'] = [x]
                ddict['y'] = [dfits['OI_VIS'].data['VISAMP'][0]][::-1]
                ddict['yerr'] = [dfits['OI_VIS'].data['VISAMPERR'][0]][::-1]
                dfits.close()
            else:
                ddict['x'] = []
                ddict['y'] = []
                ddict['yerr'] = []
                                
            if no_models:
                continue
           
            #-- Extract models from the model folders
            for model in models:
                ddict['yerr'].append(None)
                if not model: 
                    ddict['x'].append(np.empty(0))
                    ddict['y'].append(np.empty(0))
                    continue
                ddict['x'].append(model['wavelength'])
                ddict['y'].append(model['flux']*model['baseline'][bl])
            
            #-- Set some plot limits
            ddict['xmin'] = 8
            ddict['xmax'] = 13
            ddict['ymin'] = -0.1
            ddict['labels'] = [('MIDI %.1f m'%bl,0.05,0.9)]
            #-- Wavelength limits between 8 and 13 micron, limits of the N band
            #   atmospheric transmission. Outside these ranges, the flux is not
            #   relevant
            ddict['ymax'] = 1.1*max([max(iy[(ix<=13.)*(ix>=8.)]) 
                                     for ix,iy in zip(ddict['x'],ddict['y'])
                                     if iy.size])
        kwargs = dict()
        kwargs['keytags'] = ['MIDI']
        if not no_models:
            kwargs['keytags'].extend([s['LAST_MCMAX_MODEL'].replace('_','\_') 
                                      for s in star_grid])
        kwargs['xaxis'] = '$\lambda$ ($\mu$m)'
        kwargs['yaxis'] = 'Corr.~FLux (Jy)'
        kwargs['dimensions'] = (1,len(data)+1)
        kwargs['figsize'] = (10,15)
        kwargs['fontsize_axis'] = 20
        kwargs['fontsize_ticklabels'] = 20
        kwargs['fontsize_key'] = 18
        kwargs['fontsize_label'] = 14
        kwargs['linewidth'] = 3
        kwargs['cfg'] = cfg_dict
        kwargs['extension'] = '.pdf'
        kwargs['hspace'] = 0.3
        kwargs['ws_bot'] = 0.01
        kwargs['ws_top'] = 0.99
        kwargs['ws_left'] = 0.10
        kwargs['ws_right'] = 0.98
        filename = Plotting2.plotTiles(data=data,filename=fn_plt,**kwargs)
        print '** Your Correlated Flux plots can be found at:'
        print filename
        print '***********************************'