Package ComboCode :: Package cc :: Package managers :: Module PlottingManager
[hide private]
[frames] | no frames]

Source Code for Module ComboCode.cc.managers.PlottingManager

  1  # -*- coding: utf-8 -*- 
  2   
  3  """ 
  4  Interface for plotting. 
  5   
  6  Author: R. Lombaert 
  7   
  8  """ 
  9   
 10  import os 
 11   
 12  import cc.path 
 13  from cc.plotting.objects import PlotGas 
 14  from cc.plotting.objects import PlotDust 
 15  from cc.plotting.objects import PlotChem 
 16   
 17   
18 -class PlottingManager():
19 20 """ 21 An interface for managing requested plots for a CC session. 22 23 """ 24
25 - def __init__(self,star_name,mcmax=False,gastronoom=False,\ 26 chemistry=False,pacs=None,\ 27 path_gastronoom='codeJun2010',path_mcmax='codeJun2010',\ 28 path_chemistry='OutputClumpy',\ 29 inputfilename='inputComboCode.dat',spire=None,fn_add_star=1,\ 30 plot_pars=dict(),sed=None):
31 32 """ 33 Initializing a PlottingManager instance. 34 35 @keyword star_name: name of the star from Star.dat, use default only 36 when never using any star model specific things 37 38 (default: "model") 39 @type star_name: string 40 @keyword inputfilename: name of inputfile that is also copied to the 41 output folder of the plots, 42 if None nothing is copied 43 44 (default: None) 45 @type inputfilename: string 46 @keyword mcmax: Running MCMax? 47 48 (default: 0) 49 @type mcmax: bool 50 @keyword gastronoom: Running GASTRoNOoM? 51 52 (default: 0) 53 @type gastronoom: bool 54 @keyword path_mcmax: modeling folder in MCMax home 55 56 (default: 'runTest') 57 @type path_mcmax: string 58 @keyword path_gastronoom: modeling folder in GASTRoNOoM home 59 60 (default: 'runTest') 61 @type path_gastronoom: string 62 @keyword pacs: A Pacs() object for managing data and model handling for 63 PACS spectra. None if not applicable 64 65 (default: None) 66 @type pacs: Pacs() 67 @keyword spire: A Spire() object for managing data and model handling 68 for SPIRE spectra. None if not applicable 69 70 (default: None) 71 @type spire: Spire() 72 @keyword sed: The SED for managing data and model handling 73 for SED spectra/photometry. None if not applicable 74 75 (default: None) 76 @type sed: Sed() 77 @keyword fn_add_star: Add the star name to the requested plot filename. 78 Only relevant if fn_plt is given in a sub method. 79 80 (default: 1) 81 @type fn_add_star: bool 82 @keyword plot_pars: dictionary with all the plotting parameters that 83 turn on or off plotting modules. By default they 84 are all turned off. 85 86 (default: dict()) 87 @type plot_pars: dict 88 89 """ 90 91 self.dust_pars = dict() 92 self.dust_cfg = dict() 93 self.gas_pars = dict() 94 self.gas_cfg = dict() 95 self.chem_pars = dict() 96 self.chem_cfg = dict() 97 for k,v in plot_pars.items(): 98 if k[0:9] == 'PLOT_GAS_' and v: 99 self.gas_pars[k.replace('_GAS','',1)] = v 100 elif k[0:8] == 'CFG_GAS_' and v: 101 self.gas_cfg[k.replace('_GAS','',1)] = v 102 elif k[0:10] == 'PLOT_DUST_' and v: 103 self.dust_pars[k.replace('_DUST','',1)] = v 104 elif k[0:9] == 'CFG_DUST_' and v: 105 self.dust_cfg[k.replace('_DUST','',1)] = v 106 elif k[0:15] == 'PLOT_CHEMISTRY_' and v: 107 self.chem_pars[k.replace('_CHEMISTRY','',1)] = v 108 elif k[0:14] == 'CFG_CHEMISTRY_' and v: 109 self.chem_cfg[k.replace('_CHEMISTRY','',1)] = v 110 self.mcmax = mcmax 111 self.gastronoom = gastronoom 112 self.chemistry = chemistry 113 if self.mcmax: 114 self.plotter_dust = PlotDust.PlotDust(star_name=star_name,\ 115 path_mcmax=path_mcmax,\ 116 inputfilename=inputfilename, 117 sed=sed,\ 118 fn_add_star=fn_add_star) 119 else: 120 self.plotter_dust = None 121 if self.gastronoom or self.gas_pars.has_key('PLOT_LINE_LISTS')\ 122 or 'PLOT_TRANSITIONS' in self.gas_pars: 123 self.plotter_gas = PlotGas.PlotGas(star_name=star_name,pacs=pacs,\ 124 path_gastronoom=path_gastronoom,\ 125 inputfilename=inputfilename,\ 126 spire=spire,\ 127 fn_add_star=fn_add_star) 128 else: 129 self.plotter_gas = None 130 if self.chemistry: 131 self.plotter_chem = PlotChem.PlotChem(star_name=star_name,\ 132 path_chemistry=path_chemistry,\ 133 inputfilename=inputfilename, 134 fn_add_star=fn_add_star) 135 else: 136 self.plotter_chem = None
137 138 139
140 - def startPlotting(self,star_grid,iterative=0):
141 142 """ 143 Start plotting PLOT_INPUT requests for those models that are available 144 (i.e. gastronoom and/or mcmax). 145 146 @param star_grid: list of stars to be plotted 147 @type star_grid: list[Star()] 148 149 @keyword iterative: if true the old grids are plotted on a 150 model_iteration per model_iteration basis, only 151 works for MCMax models for now. 152 153 (default: 0) 154 @type iterative: int 155 156 """ 157 158 if iterative: 159 if self.mcmax and self.dust_pars.has_key('PLOT_SED'): 160 self.plotter_dust.plotSed(star_grid=star_grid,\ 161 iterative=iterative,\ 162 cfg=self.dust_cfg.has_key('CFG_SED')\ 163 and self.dust_cfg['CFG_SED'] \ 164 or '') 165 return 166 if self.mcmax: 167 for k in self.dust_pars: 168 method_name = 'plot' + \ 169 ''.join([w.capitalize() 170 for w in k.replace('PLOT_','')\ 171 .split('_')]) 172 thisMethod = getattr(self.plotter_dust,method_name) 173 thisMethod(star_grid=star_grid,\ 174 cfg=self.dust_cfg.get(k.replace('PLOT_','CFG_'),'')) 175 if self.gastronoom or self.gas_pars.has_key('PLOT_LINE_LISTS') \ 176 or 'PLOT_TRANSITIONS' in self.gas_pars: 177 for k in self.gas_pars: 178 method_name = 'plot' + \ 179 ''.join([w.capitalize() 180 for w in k.replace('PLOT_','')\ 181 .split('_')]) 182 thisMethod = getattr(self.plotter_gas,method_name) 183 thisMethod(star_grid=star_grid,\ 184 cfg=self.gas_cfg.get(k.replace('PLOT_','CFG_'),'')) 185 if self.chemistry: 186 for k in self.chem_pars: 187 method_name = 'plot' + \ 188 ''.join([w.capitalize() 189 for w in k.replace('PLOT_','')\ 190 .split('_')]) 191 thisMethod = getattr(self.plotter_chem,method_name) 192 thisMethod(star_grid=star_grid,\ 193 cfg=self.chem_cfg.get(k.replace('PLOT_','CFG_'),''))
194 195
196 - def plotTransitions(self,star_grid,force=0,cfg='',fn_suffix=''):
197 198 ''' 199 Run the plotTransitions method in the PlotGas object of this manager. 200 201 If available, the cfg is taken from the plot input. 202 203 Only done if PLOT_GAS_TRANSITIONS is indeed 1 in the CC inputfile. This 204 can be forced through the keyword force. 205 206 This method is mainly used if you want to plot a sub selection of 207 models from the main input grid, for instance after statistical 208 selection. 209 210 @param star_grid: The collection of models to be plotted 211 @type star_grid: list[Star()] 212 213 @keyword force: Plot the transitions regardless of the 214 PLOT_GAS_TRANSITIONS keyword in cc input, e.g. when the 215 manager is ran outside a cc session. 216 217 (default: 0) 218 @type force: bool 219 @keyword cfg: The config file. If not given, the manager checks if a 220 cfg file is available in the CC input. 221 222 (default: None) 223 @type cfg: string 224 @keyword fn_suffix: A suffix that is appended to the filename. For 225 instance, when running the plot command for a 226 best fit subgrid of Star() models as to not 227 overwrite the plot of the full grid. 228 229 (default: '') 230 @type fn_suffix: string 231 232 233 ''' 234 235 if 'PLOT_TRANSITIONS' in self.gas_pars or force: 236 if not cfg: cfg = self.gas_cfg.get('CFG_TRANSITIONS','') 237 self.plotter_gas.plotTransitions(star_grid,cfg=cfg,\ 238 fn_suffix=fn_suffix)
239