def plotAbundanceProfiles(self,star_grid=[],models=[],force_plot=0,cfg='',\ fn_plt='',molecules=[],per_molecule=0,frac=1): ''' Plot abundance profiles for all molecules in every model. @keyword star_grid: List of Star() instances. If default, model ids have to be given. (default: []) @type star_grid: list[Star()] @keyword models: The model ids, only required if star_grid is [] (default: []) @type models: list[string] @keyword force_plot: force a plotting if more than models are requested (default: 0) @type force_plot: bool @keyword cfg: path to the Plotting2.plotCols config file. If default, the hard-coded default plotting options are used. (default: '') @type cfg: string @keyword fn_plt: A base plot filename. Includes folder. If not, a default is added (default: '') @type fn_plt: string @keyword molecules: Molecules to be plotted. (default: []) @type molecules: bool @keyword per_molecule: Plot one molecule for all models in one figure. (default: 0) @type per_molecule: bool @keyword per_model: Plot all molecules for one model in one figure. (default: 0) @type per_model: bool @keyword frac: Plot the fractional abundances. If not frac, plot number densities. (default: 1) @type frac: bool ''' print '***********************************' print '** Plotting Abundance Profiles' if not star_grid and models: star_grid = self.makeStars(models=models) elif (not models and not star_grid) or (models and star_grid): print '** Input is undefined or doubly defined. Aborting.' return pfns = [] cfg_dict = Plotting2.readCfg(cfg) if cfg_dict.has_key('filename'): fn_plt = cfg_dict.pop('filename') if cfg_dict.has_key('molecules'): molecules = cfg_dict.pop('molecules') if cfg_dict.has_key('per_molecule'): per_molecule = cfg_dict['per_molecule'] if cfg_dict.has_key('per_model'): per_model = cfg_dict['per_model'] #-- Some general plot settings extra_pars = dict() extra_pars['ymin'] = 1e-9 extra_pars['ymax'] = 1e-3 extra_pars['ylogscale'] = 1 extra_pars['xlogscale'] = 1 extra_pars['figsize'] = (12.5, 8.5) extra_pars['xaxis'] = 'cm' #-- Dict to keep track of all data ddata = dict() for istar, star in enumerate(star_grid): if not star['LAST_CHEMISTRY_MODEL']: continue ddata[istar] = dict() folder = os.path.join(cc.path.cout,'models',\ star['LAST_CHEMISTRY_MODEL'])+'/' ddata[istar]['rad'] = DataIO.getChemistryPhysPar(folder+\ 'csphyspar.out', 'RADIUS') ddata[istar]['id'] = star['LAST_CHEMISTRY_MODEL'] if frac: species = DataIO.getChemistryAbundances(folder + 'csfrac.out') else: species = DataIO.getChemistryAbundances(folder + 'csnum.out') for molec in molecules: ddata[istar][molec] = species[molec] if not per_molecule: #-- Collect all data radii = [ddata[istar]['rad']] * len(molecules) abuns = [ddata[istar][molec] for molec in molecules] keytags = molecules #ids = star['LAST_CHEMISTRY_MODEL'] ids = ddata[istar]['id'] #-- Set the yaxis tag yaxis = '$n_\mathrm{molec}/n_{\mathrm{H}_2}$' #-- Set filename pfn = fn_plt if fn_plt else 'abundance_profiles' suff = '_'.join(list(set(ids))) pfn = self.setFnPlt(pfn, fn_suffix=suff) pfns.append(Plotting2.plotCols(x=radii,y=abuns,cfg=cfg_dict,\ filename=pfn,keytags=keytags,\ plot_title=ids.replace('_','\_'),\ yaxis=yaxis,**extra_pars)) if per_molecule: #-- Collect all data #molecs = list(set([molec for istar in ddata.keys() #for molec in ddata[istar].keys()])) for molec in molecules: #-- Collect data radii = [dstar['rad'] for istar, dstar in ddata.items()] abuns = [dstar[molec] for istar, dstar in ddata.items()] keytags = [ dstar['id'].replace('_', '\_') for istar, dstar in ddata.items() ] #-- Set the y axis tag #strmolec = ddata[0][molec]['key'] yaxis = '$n_\mathrm{%s}/n_{\mathrm{H}_2}$' % str(molec) #-- Make filename pfn = fn_plt if fn_plt else 'abundance_profiles' pfn = self.setFnPlt(pfn, fn_suffix=molec) pfns.append(Plotting2.plotCols(x=radii,y=abuns,yaxis=yaxis,\ filename=pfn,keytags=keytags,\ cfg=cfg_dict,**extra_pars)) if not per_molecule and pfns and pfns[0][-4:] == '.pdf': pfn = fn_plt if fn_plt else 'abundance_profiles' pfn = self.setFnPlt(pfn) + '.pdf' DataIO.joinPdf(old=pfns, new=pfn) print '** Plots can be found at:' print pfn print '***********************************' else: print '** Plots can be found at:' print '\n'.join(pfns) print '***********************************'