Exemple #1
0
def plot_SED(name, models_dir='./', unit='Jy'):
    Ms = pc.load_models('{0}/{1}'.format(models_dir, name), read_emis=False)
    plt.figure()
    plt.subplot(2, 1, 1)
    for M in Ms:
        plt.plot(M.get_cont_x(unit='eV'),
                 np.log10(M.get_cont_y(unit='esHz')),
                 label=M.model_name_s)
    plt.xlim((10., 60))
    plt.ylim((18, 24))
    plt.ylabel('log [erg.s-1.Hz-1]')
    plt.legend(loc=3)

    plt.subplot(2, 1, 2)
    for M in Ms:
        plt.plot(M.get_cont_x(unit='eV'),
                 np.log10(M.get_cont_y(unit='Q')),
                 label=M.model_name_s)
    plt.xlim((10., 60))
    plt.ylim((42., 50))
    plt.xlabel('E [eV]')
    plt.ylabel('QH0(E)')
    # TODO: avoid overlap
    for ip in IP:
        plt.plot([IP[ip], IP[ip]], [49, 50])
        plt.text(IP[ip], 48, ip)
Exemple #2
0
def print_Xi(name, models_dir = './'):
    Ms = pc.load_models('{0}/{1}'.format(models_dir, name), read_emis = False)
    names = [M.model_name_s for M in Ms]
    print(names)
    print('H0/H:   {0:.2e} {1:.2e} {2:.2e}'.format(Ms[0].get_ab_ion_vol('H', 0), 
                                                   Ms[1].get_ab_ion_vol('H', 0), 
                                                   Ms[2].get_ab_ion_vol('H', 0)))
    
    print('H1/H:   {0:.2e} {1:.2e} {2:.2e}'.format(Ms[0].get_ab_ion_vol('H', 1), 
                                                   Ms[1].get_ab_ion_vol('H', 1), 
                                                   Ms[2].get_ab_ion_vol('H', 1)))
    
    print('He0/H:  {0:.2e} {1:.2e} {2:.2e}'.format(Ms[0].get_ab_ion_vol('He', 0), 
                                                   Ms[1].get_ab_ion_vol('He', 0), 
                                                   Ms[2].get_ab_ion_vol('He', 0)))
    
    print('He1/H:  {0:.2e} {1:.2e} {2:.2e}'.format(Ms[0].get_ab_ion_vol('He', 1), 
                                                   Ms[1].get_ab_ion_vol('He', 1), 
                                                   Ms[2].get_ab_ion_vol('He', 1)))
    
    print('He2/H:  {0:.2e} {1:.2e} {2:.2e}'.format(Ms[0].get_ab_ion_vol('He', 2), 
                                                   Ms[1].get_ab_ion_vol('He', 2), 
                                                   Ms[2].get_ab_ion_vol('He', 2)))
    for elem in ['N', 'O', 'Ne', 'S', 'Ar']:
        for i in np.arange(4):
            print('{0:2s}{1}/H:  {2:.2e} {3:.2e} {4:.2e}'.format(elem, i, Ms[0].get_ab_ion_vol(elem, i), 
                                                             Ms[1].get_ab_ion_vol(elem, i), 
                                                             Ms[2].get_ab_ion_vol(elem, i)))
Exemple #3
0
 def __init__(self, model_dir, models):
     """
     if type(models) == type(''):
         models = [models]
     full_names = ['{0}/{1}'.format(model_dir, model) for model in models] 
     """
     self.Ms = pc.load_models('{0}/{1}'.format(model_dir, models))
     self.read_obs()
Exemple #4
0
def search_T(name, models_dir = './', SED = 'BB'):
    
    Ms = pc.load_models('{0}/{1}'.format(models_dir, name), read_emis = False)
    if SED == 'BB':
        T = np.array([float(pc.sextract(M.out['Blackbody'], 'dy ', '*')) for M in Ms])
    elif SED == 'WM':
        T = np.array([float(pc.sextract(M.out['table star'], 'mod" ', '4.0')) for M in Ms])
    QH0 = np.array([M.Q0 for M in Ms])
    QHe0 = np.array([M.Q[1::].sum() for M in Ms])
    
    plt.plot(T/1e3, QHe0/QH0)
    plt.xlabel('T [kK]')
    plt.ylabel('QHe0/QH0')
Exemple #5
0
def load_models(model_name="", path="", read_grains=False, **kwargs):
    """Load in models in path with model_name. Skip broken models or models with 1 zone."""
    models = pc.load_models('{0}{1}'.format(path, model_name),
                            read_grains=read_grains,
                            **kwargs)
    models_return = []
    for m in models:
        if m.n_zones > 1:
            models_return.append(m)
        else:
            # log failed model
            pass
    return models_return
        emis_tab
    )  # better use read_emis_file(file) for long list of lines, where file is an external file
    cloudy_model.print_input()
    return cloudy_model


# #Run cloudy
Te_interval = [9000.0, 9500.0, 10000.0, 10500.0]
# for Te in Te_interval:
#     model_i = make_vary_Te_ne(Te, 100.0, dir_)
#     pc.log_.timer('Starting Cloudy', quiet = True, calling = 'test1')
#     model_i.run_cloudy()
#     pc.log_.timer('Cloudy ended after seconds:', calling = 'test1')

#Loading simulation results
Ms = pc.load_models(dir_)

#Reading the physical parameters in vector form
Te_vector = np.empty(len(Ms))
ne_vector = np.empty(len(Ms))
emis_dict = dict.fromkeys(emis_tab, np.empty(len(Ms)))

print 'somos ', len(Ms), ' y deberiamos ser', len(Te_interval)

for i in range(len(Ms)):
    ne_vector[i] = Ms[i].ne
    Te_vector[i] = Ms[i].T0
    for j in range(len(emis_dict)):
        line_label = emis_tab[j].replace(' ', '_').replace('.', '')
        emis_dict[emis_tab[j]][i] = Ms[i].get_emis(line_label)
Exemple #7
0
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):
    ex6_1.make_mod(models_dir, name='M_61.1b_{0}'.format(i), Teff=Teff, qH=47, dens=3, r_in=17)
pc.run_cloudy(dir_=models_dir, n_proc=3, use_make=True,  model_name='M_61.1b_')
Exemple #8
0
# tables for the values of the density and the log(O/H)
tab_dens = [3, 4, 5, 6]
tab_ab_O = [-3.1, -3.25, -3.4, -3.55, -3.7]

# defining the models and writing 20 input files
for dens in tab_dens:
    for ab_O in tab_ab_O:
        make_model(dir_, model_name, dens, ab_O)

# Running the models using the makefile and n_proc processors
n_proc = 3
pc.log_.timer('models defined')
pc.run_cloudy(dir_=dir_, n_proc=n_proc, model_name=model_name, use_make=True)
pc.log_.timer('models run')
# reading the Cloudy outputs and putting them in a list of CloudyModel objects
Ms = pc.load_models('{0}{1}'.format(dir_, model_name), read_grains=False)
pc.log_.timer('models loaded')

#Computing line intensity ratios
rO3 = [
    np.log10(M.get_emis_vol('O__3__5007A') / M.get_emis_vol('TOTL__4363A'))
    for M in Ms
]
rO2 = [
    np.log10(M.get_emis_vol('O_II__3726A') / M.get_emis_vol('O_II__3729A'))
    for M in Ms
]
# defining the colors associated to the Oxygen abundances
col = [M.abund['O'] for M in Ms]
# defining the size as the density (at the first step, but in these models it's constant)
size = [np.log10(M.nH[0]) * 20 for M in Ms]
Exemple #9
0
# tables for the values of the density and the log(O/H)
tab_dens = [3, 4, 5, 6]
tab_ab_O = [-3.1, -3.25, -3.4, -3.55, -3.7]

# defining the models and writing 20 input files
for dens in tab_dens:
    for ab_O in tab_ab_O:
        make_model(dir_, model_name, dens, ab_O)

# Running the models using the makefile and n_proc processors
n_proc = 3
pc.log_.timer('models defined')
pc.run_cloudy(dir_ = dir_, n_proc = n_proc, model_name = model_name, use_make = True)
pc.log_.timer('models run')
# reading the Cloudy outputs and putting them in a list of CloudyModel objects
Ms = pc.load_models('{0}{1}'.format(dir_, model_name), read_grains = False)
pc.log_.timer('models loaded')

#Computing line intensity ratios 
rO3 = [np.log10(M.get_emis_vol('O__3__5007A')/M.get_emis_vol('TOTL__4363A')) for M in Ms]
rO2 = [np.log10(M.get_emis_vol('O_II__3726A')/M.get_emis_vol('O_II__3729A')) for M in Ms]
# defining the colors associated to the Oxygen abundances
col = [M.abund['O'] for M in Ms]
# defining the size as the density (at the first step, but in these models it's constant)
size = [np.log10(M.nH[0])*20 for M in Ms]

#plotting the result
plt.figure()
plt.scatter(rO2, rO3, c=col, s=size, edgecolors = 'none')
plt.xlabel('log [OII] 3726/3729')
plt.ylabel('log [OIII] 5007/4363')
Exemple #10
0

model_name = "M3D_5"
pc.log_.calling = 'Model3D : ' + model_name
pc.log_.level = 3

dim = 101
n_cut = (dim - 1) / 2
proj_axis = 0

set_models(dir_, model_name)
pc.run_cloudy(dir_=dir_, n_proc=3, model_name=model_name, use_make=True)

liste_of_models = pc.load_models(
    '{0}/{1}'.format(dir_, model_name),
    list_elem=['H', 'He', 'C', 'N', 'O', 'Ar', 'Ne'],
    read_cont=False,
    read_grains=False)

m3d = pc.C3D(liste_of_models,
             dims=[dim, dim, dim],
             angles=[45, 45, 0],
             plan_sym=True)

def_profiles(m3d)

im = m3d.get_RGB(list_emis=[0, 3, 7])
plt.imshow(im, origin='lower')
m3d.plot_profiles(ref=3, i_fig=1, Nx=20, Ny=20)

plot_profiles(m3d, 55, 55)
if start_simulation_check:
    for Te in Te_interval:
        for ne in ne_interval:
            model_name = 'M_i_Te{}_ne{}'.format(Te, ne)
            model_i = large_H_He_orders_grid(Te, ne, dir_results + model_name,
                                             labels_list)
            print '\nRunning model: ', model_name
            model_i.run_cloudy()
            pc.log_.timer(
                '-Cloudy script run @ {}. Process ended after:'.format(
                    dir_results),
                calling='log')

# --This code section generates some plots on the results to compare the results with the emissivities from Porter et al 2012-13
#Loading simulation results
Ms = pc.load_models(dir_results, verbose=False)

#Reading the physical parameters in vector form
Te_vector = np.empty(len(Ms))
ne_vector = np.empty(len(Ms))
emis_dict = {label: np.empty(len(Ms)) for label in labels_list}

for i in range(len(Ms)):
    Te_vector[i] = Ms[i].T0
    ne_vector[i] = Ms[i].ne
    for j in range(len(emis_dict)):
        line_label = labels_list[j].replace(' ', '_').replace('.', '')
        emis_dict[labels_list[j]][i] = Ms[i].get_emis(line_label)
    print '\nStats', Ms[i].T0, Ms[i].ne
    print Ms[i].print_stats()
Exemple #12
0

# In[11]:

set_models(dir_, model_name)


# In[12]:

#pc.print_make_file(dir_ = dir_)
#pc.run_cloudy(dir_ = dir_, n_proc = 3, model_name = model_name, use_make = True)


# In[13]:

liste_of_models = pc.load_models('{0}/{1}'.format(dir_, model_name), list_elem=['H', 'He', 'C', 'N', 'O', 'Ar', 'Ne'],  
                                           read_cont = False, read_grains = False)


# In[14]:

m3d = pc.C3D(liste_of_models, dims = [dim, dim, dim], angles = [45,45,0], plan_sym = True)


# In[15]:

def_profiles(m3d)


# In[16]:

plt.figure(figsize=(10,10))
Exemple #13
0
import numpy as np
from astropy.io import fits
import pyCloudy as pc


#define some constants
light=2.99792458E+18   # in Ang/s
pi=3.141592653589793

# Read the file with the list name
#lines_names,wl_lines,pyCl_names = np.loadtxt('../data/linelist_fits_AGN_test.txt', dtype='str',usecols=(0,2,4), unpack=True)

### this is in case to test the routine####
lines_names,wl_lines,pyCl_names = np.loadtxt('../data/linelist_fits_AGN.txt', dtype='str',usecols=(0,2,4), unpack=True)

Ms_UZ = pc.load_models('/Users/feltre/NEOGAL/NLR/nlr_mod_BEAGLE/nlr_u*Z*xi05_n4_al2.0', read_lin = True, read_emis = False, list_elem = [], read_phy = False, read_rad =
True)

logU = list()
metallicity = list()
xi = list()
loghden = list()
pwl_ind = list()

# We use a dictionary to store the line luminosities
lines_luminosity = {}
cont_luminosity = {}

for M in Ms_UZ:

    # extract lines
    extract_line = lambda label:np.array([M.get_line(label)])