コード例 #1
0
 def cloudy(self):
     '''
     Computes a Cloudy Model for the parameters specified in 
     '''
     pc.log_.message('Running {0}'.format(self.model_name), calling='test1')
     pc.config.cloudy_exe = '~/cloudy/source/sys_gcc/cloudy.exe'
     pc.log_.timer('Starting Cloudy', quiet=True, calling='test1')
     self.c_input.run_cloudy()
     self.Mod = pc.CloudyModel(self.full_model_name)
     pc.log_.timer('Cloudy ended after seconds:', calling='test1')
コード例 #2
0
def plot_model(name, models_dir='./', style='-', fig_num=1):
    pc.log_.level = 3

    M = pc.CloudyModel('{0}/{1}'.format(models_dir, name), read_emis=False)
    X = M.radius / 1e19
    colors = ['r', 'g', 'b', 'y', 'm', 'c']
    plt.figure(fig_num)

    plt.subplot(3, 3, 1)
    plt.plot(X, M.get_ionic('H', 0), label='H0', linestyle=style, c=colors[0])
    plt.plot(X, M.get_ionic('H', 1), label='H+', linestyle=style, c=colors[1])
    plt.plot(X,
             M.get_ionic('He', 0),
             label='He0',
             linestyle=style,
             c=colors[2])
    plt.plot(X,
             M.get_ionic('He', 1),
             label='He+',
             linestyle=style,
             c=colors[3])
    plt.plot(X,
             M.get_ionic('He', 2),
             label='He++',
             linestyle=style,
             c=colors[4])
    if style == '-':
        plt.legend()
    plt.title(name)

    for i_plot, elem in enumerate(['N', 'O', 'Ne', 'S', 'Ar']):
        plt.subplot(3, 3, i_plot + 2)
        for i in np.arange(4):
            plt.plot(X, M.get_ionic(elem, i), linestyle=style, c=colors[i])
        plt.text(np.max(X) / 2, 0.9, elem)
        if i_plot == 0:
            plt.title(M.date_model)

    plt.subplot(3, 3, 7)
    plt.plot(X, M.ne, label=r'N$_e$', linestyle=style, c='blue')
    plt.plot(X, M.nH, label='N$_H$', linestyle=style, c='red')
    if style == '-':
        plt.legend(loc=3)
    plt.xlabel(r'R [10$^{19}$cm]')

    plt.subplot(3, 3, 8)
    plt.plot(X, M.te, label=r'T$_e$', linestyle=style, c='blue')
    if style == '-':
        plt.legend(loc=3)

    plt.subplot(3, 3, 9)
    plt.plot(X, M.log_U, label='log U', c='blue')
    if style == '-':
        plt.legend()
コード例 #3
0
ファイル: pyCloudy_scriptCM.py プロジェクト: cfin6/Tc1
    def read_model(self,
                   doplot=False,
                   HeI_cut=None,
                   verbose=True,
                   cube_size=None,
                   r_out_cut=None):

        self.Mod = pc.CloudyModel('{0}{1}'.format(self.dir_, self.model_name),
                                  read_grains=True)
        if "CA_B_587564A" in self.Mod.emis_labels:
            i_line = np.where(self.Mod.emis_labels == 'CA_B_587564A')[0][0]
            self.Mod.emis_full[i_line] *= correc_He1(self.Mod.te_full,
                                                     self.Mod.ne_full, 5876)
        if "CA_B_447149A" in self.Mod.emis_labels:
            i_line = np.where(self.Mod.emis_labels == 'CA_B_447149A')[0][0]
            self.Mod.emis_full[i_line] *= correc_He1(self.Mod.te_full,
                                                     self.Mod.ne_full, 4471)

        self.Mod.distance = self.distance

        if HeI_cut is not None:
            if cube_size is None:
                print('Needs a cube_size to compute the HeI cut')
                self.Mod = None
                return
            for radius in self.Mod.radius[::-1]:
                self.Mod.r_out_cut = radius
                self.make_3D(cube_size, doplot=False, verbose=False)
                if verbose:
                    print('R = {:8.2e} HeI dif = {:.2f}'.format(
                        radius, self.difs['CA_B_587564A']))
                if self.difs['CA_B_587564A'] > HeI_cut:
                    break
        elif r_out_cut is not None:
            self.Mod.r_out_cut = r_out_cut

        if verbose:
            self.Mod.print_stats()

        if doplot:
            f, ax = plt.subplots(figsize=(10, 7))
            ax.plot(self.Mod.radius, self.Mod.te, label='Te')
            ax.legend(loc=3)

            #Show on the screen
            #plt.show()

            #print to file
            #plt.tight_layout(pad=0.2)
            name = self.dir_ + self.model_name + '_Te.png'
            f.savefig(name, dpi=200)
コード例 #4
0
ファイル: ex6_5.py プロジェクト: kakirastern/PyNeb_devel
    def __init__(self, name):
        """
        Creating an object to manage the Cloudy output and compare to the observations
        """

        self.model = pc.CloudyModel(name)
        self.set_3D(use=False)
        self.m3d = None
        self.mask = None
        self.profile_defined = False
        self.dim_3D = 101
        self.mask_ap_center = (0., 3.5)
        self.mask_ap_size = (12., 1)
        # define a RedCorr object
        self.RC = pn.RedCorr(E_BV=0.26, R_V=3.6, law='Fitz 99')
コード例 #5
0
    def _pc_load_models(model_name=None,
                        mod_list=None,
                        n_sample=None,
                        verbose=False,
                        **kwargs):
        """
            Return a list of CloudyModel correspondig to a generic name

            Parameters:
                - model_name:    generic name. The method is looking for any "model_name*.out" file.
                - mod_list:      in case model_name=None, this is the list of model names (something.out or something)
                - n_sample:      randomly select n_sample from the model list
                - verbose:       print out the name of the models read
                - **kwargs:      arguments passed to CloudyModel
            """

        if model_name is not None:
            mod_list = glob.glob(model_name + '*.out')
        if mod_list is None or mod_list == []:
            pc.log_.error('No model found', calling='load models')
            return None
        if n_sample is not None:
            if n_sample > len(mod_list):
                pc.log_.error('less models {0:d} than n_sample {1:d}'.format(
                    len(mod_list), n_sample),
                              calling='load models')
                return None
            mod_list = random.sample(mod_list, n_sample)
        m = []
        for outfile in mod_list:
            if outfile[-4::] == '.out':
                model_name = outfile[0:-4]
            else:
                model_name = outfile
            try:
                cm = pc.CloudyModel(model_name, verbose=0, **kwargs)
                if not cm.aborted:
                    m.append(cm)
                if verbose:
                    print('{0} model read'.format(outfile[0:-4]))
            except:
                pass
        pc.log_.message('{0} models read'.format(len(m)),
                        calling='load_models')
        return m
コード例 #6
0
def get_Q02Lum(SED, logg):
    """
    Usage: get_Q02Lum('TL', 4)
    """
    if SED not in tabs_T:
        print('{0} is not in {1}'.format(SED, tabs_T.keys()))
        return None
    Q02l = {}
    lumi = 3
    for Teff in tabs_T[SED]:
        In = pc.CloudyInput('./M1')
        In.set_cste_density(2)
        In.set_radius(19)
        if SED[0:2] != 'BB':
            In.set_star('table star "{0}"'.format(dic_SEDs[SED]),
                        (Teff, logg, 0), 'luminosity total solar', lumi)
        else:
            In.set_BB(Teff, 'luminosity total solar', lumi)
        In.set_stop('zone 2')
        In.print_input()
        In.run_cloudy()
        Out = pc.CloudyModel('./M1', read_emis=False)
        print('{0} : {1:.2f},'.format(Teff, np.log10(Out.Q0) - lumi))
        Q02l[Teff] = np.log10(Out.Q0) - lumi
コード例 #7
0
ファイル: run_ex.py プロジェクト: kakirastern/PyNeb_devel
Question 6.1.1
"""
models_dir = 'CloudyModels' #Create this directory if necessary
pc.config.cloudy_exe = '/usr/local/Cloudy/c10.00/cloudy.exe' # point to the location of Cloudy.exe

# Print the Makefile in th emodels_dir directory (only needed one time)
pc.print_make_file(models_dir)
# Print a file containing the line for intensities
ex6_1.print_line_file(models_dir)

# prepare models with different Q(H)
for qH in [43, 44, 45, 46, 47, 48]:
    ex6_1.make_mod(models_dir, name='M_61.1_{0}'.format(qH), Teff=5e4, qH=qH, dens=3, r_in=17)
# run all the models in models_dirs starting with M_61.1
pc.run_cloudy(dir_=models_dir, n_proc=3, use_make=True,  model_name='M_61.1')
M43 = pc.CloudyModel('{0}/M_61.1_43'.format(models_dir), read_lin = True)
# load all the models in the models list
models = pc.load_models('{0}/M_61.1_'.format(models_dir), read_lin = True)

# make some plots
ex6_1.plot_Hb(models)

for m in models:
    # A posteriori cut of the model
    # Line intensities are not changed. Integral of Emissivities are changed.
    m.r_out_cut = 1.5e17
# make the same plots
ex6_1.plot_Hb(models)

# prepare models with different Teff
for i, Teff in enumerate(np.array([40, 50, 80, 130, 200]) * 1e3):
コード例 #8
0
ファイル: Using_pyCloudy_1.py プロジェクト: indiajoe/pyCloudy
# Printing some message to the screen
pc.log_.message('Running {0}'.format(model_name), calling = 'test1')


# In[15]:

# Running Cloudy with a timer. Here we reset it to 0.
pc.log_.timer('Starting Cloudy', quiet = True, calling = 'test1')
c_input.run_cloudy()
pc.log_.timer('Cloudy ended after seconds:', calling = 'test1')


# In[16]:

# Reading the Cloudy outputs in the Mod CloudyModel object
Mod = pc.CloudyModel(full_model_name)


# In[17]:

# Use TAB to know all the methods and variables for CloudyModel class
# Mod.TAB
dir(Mod) # This is the online answering way
# Description of this class is available here: http://pythonhosted.org//pyCloudy/classpy_cloudy_1_1c1d_1_1cloudy__model_1_1_cloudy_model.html


# In[18]:

Mod.print_stats()

コード例 #9
0
ファイル: make_3MdB_17.py プロジェクト: premvijay/pyCloudy
def run_test_labels(model_name='model_1'):
    test_labels(model_name)
    M = pc.CloudyModel('{0}{1}'.format(dir_, model_name), read_cont=True)
    M.print_lines(norm='CA_B_486133A')
コード例 #10
0
 bigCloud_sim.set_other(('cosmic rays background'))
 bigCloud_sim.set_other(('CMB'))
 bigCloud_sim.set_iterate(2)
 bigCloud_sim.set_other(('save last transmitted continuum file = "{}"'.format(transmitted_ext)))
 bigCloud_sim.read_emis_file('lines.dat')
 
 bigCloud_sim.print_input(to_file = True, verbose = False)
                        
 #Display input code
 bigCloud_sim.print_input(verbose=False)
 
 #Run the model
 #bigCloud_sim.run_cloudy(dir_=simu_folder)
 
 #Read the simulation data
 bigCloud_output = pc.CloudyModel(simu_folder + name_big, read_emis=True)
 #bigCloud_output.print_stats()
 
 #Generate 3D grid
 bigCloud_sphere = pc.C3D(bigCloud_output, dims=cube_size, center=True, n_dim=1)
  
 arcsec          = lambda cm: conv_arc(dist=dist_big/pc_to_cm/1000, dist_proj=cm)
 mask            = make_mask_slit(arcsec, bigCloud_sphere, ap_center=[0, 0], ap_size=[50, 1.5]) #ap_size=[50, 1.5]
 mask_cirleB     = make_mask_circle(arcsec, bigCloud_sphere) #ap_size=[50, 1.5]
 mask_big        = ~np.logical_not(mask) & np.logical_not(mask_cirleB)
 mask_small      = ~np.logical_not(mask_cirleB)
 
 #plotting_the_mask(mask_big, arcsec, bigCloud_sphere)
 
 #Calculate abundance
 big_lines_dict = extract_fluxes_pure_slits(bigCloud_sphere, mask_big)