Пример #1
0
def p1():
    # Set restore to True if the emission maps have already been generated, False otherwise
    ### General settings
    # Setting verbosity level. Enter pn.my_logging? for details
    pn.log_.level = 3
    # Adopt an extinction law
    #extinction_law = 'CCM 89'
    # Define the data file
    obs_data = 'IC2165.dat'

    ### Read observational data
    # define an Observation object and assign it to name 'obs'
    obs = pn.Observation()
    # fill obs with data read from file obs_data, with lines varying across rows and a default percent error on line intensities
    obs.readData(obs_data,
                 fileFormat='lines_in_rows',
                 err_default=0.05,
                 corrected=True)

    ### Include the diagnostics of interest
    # instantiate the Diagnostics class
    diags = pn.Diagnostics()
    # include in diags the relevant line ratios
    diags.getAllDiagLabels()
    diags.getAllDiags()
    diags.addDiag([
        '[NI] 5198/5200',
        '[NII] 5755/6584',
        '[OI] 5579/6302',
        '[OII] 3726/3729',
        '[OII] 3727+/7325+',
        '[OIII] 4363/5007+',
        '[SII] 6731/6716',
        '[SII] 4072+/6720+',
        '[SIII] 6312/9069',
        '[ArIII] 5192/7136',
        '[ArIV] 4740/4711',
        '[ClIII] 5538/5518',
    ])

    diags.addDiag('[ClIV] 5323/7531',
                  ('Cl4', 'L(5323)/L(7531)', 'RMS([E(7531),E(5323)])'))

    # Create the emission maps to be compared to the observation data
    # To see the default parameters, do pn.getEmisGridDict? in ipython
    # The files go to ~/.pypics
    emisgrids = pn.getEmisGridDict(atomDict=diags.atomDict, den_max=1e6)

    ### Plot
    plt.figure(1)
    # Create the contour plot as the intersection of tem-den emission maps with dereddened line ratios
    diags.plot(emisgrids, obs)
    # Put the title
    plt.title('IC 2165 Optical diagnostics')
    # Display the plot
    plt.show()
    plt.savefig('IC2165-diag-opt.pdf')
Пример #2
0
def plot_2comp(tem1=1e4, tem2=1e4, dens1=3e2, dens2=5e5, mass1=1, mass2=5e-4):

    # List of diagnostics used to analyze the region
    diags = pn.Diagnostics()

    diags.addDiag([
        '[NI] 5198/5200', '[NII] 5755/6548', '[OII] 3726/3729',
        '[OII] 3727+/7325+', '[OIII] 4363/5007', '[ArIII] 5192/7136',
        '[ArIII] 5192/7300+', '[ArIV] 4740/4711', '[ArIV] 7230+/4720+',
        '[SII] 6731/6716', '[SII] 4072+/6720+', '[SIII] 6312/9069',
        '[ClIII] 5538/5518'
    ])
    """    
    for diag in pn.diags_dict:
        if diag[0:7] != '[FeIII]':
            diags.addDiag(diag)
            print('Adding', diag)
    diags.addClabel('[SIII] 6312/9069', '[SIII]A')
    diags.addClabel('[OIII] 4363/5007', '[OIII]A')
    """
    # Define all the ions that are involved in the diagnostics
    adict = diags.atomDict
    pn.log_.message('Atoms built')

    obs = pn.Observation(corrected=True)
    for atom in adict:
        # Computes all the intensities of all the lines of all the ions considered
        for line in pn.LINE_LABEL_LIST[atom]:
            if line[-1] == 'm':
                wavelength = float(line[:-1]) * 1e4
            else:
                wavelength = float(line[:-1])
            elem, spec = parseAtom(atom)
            intens1 = adict[atom].getEmissivity(
                tem1, dens1, wave=wavelength) * dens1 * mass1
            intens2 = adict[atom].getEmissivity(
                tem2, dens2, wave=wavelength) * dens2 * mass2
            obs.addLine(
                pn.EmissionLine(
                    elem,
                    spec,
                    wavelength,
                    obsIntens=[intens1, intens2, intens1 + intens2],
                    obsError=[0.0, 0.0, 0.0]))

    pn.log_.message('Virtual observations computed')
    emisgrids = pn.getEmisGridDict(atomDict=adict)

    pn.log_.message('EmisGrids available')

    # Produce a diagnostic plot for each of the two regions and another one for the
    # (misanalyzed) overall region
    f, axes = plt.subplots(2, 2)

    diags.plot(emisgrids, obs, i_obs=0, ax=axes[0, 0])
    diags.plot(emisgrids, obs, i_obs=1, ax=axes[0, 1])
    diags.plot(emisgrids, obs, i_obs=2, ax=axes[1, 0])
Пример #3
0
def get_OoH_3():

    obs = pn.Observation('NGC300.dat', corrected=True, errIsRelative=False)

    I = lambda label: obs.getLine(label=label).corrIntens
    O3N2 = np.log10((I('O3_5007A') / 100.) / (I('N2_6584A') / (286.)))

    OsH = 8.73 - 0.32 * O3N2
    return OsH
Пример #4
0
def plot_2comp(tem1=1e4, tem2=1e4, dens1=3e2, dens2=5e5, mass1=1, mass2=5e-4):

    # List of diagnostics used to analyze the region
    diags = pn.Diagnostics()

    for diag in pn.diags_dict:
        if diag[0:7] != '[FeIII]':
            diags.addDiag(diag)
    diags.addClabel('[SIII] 6312/9069', '[SIII]A')
    diags.addClabel('[OIII] 4363/5007', '[OIII]A')

    # Define all the ions that are involved in the diagnostics
    all_atoms = diags.atomDict

    pn.log_.message('Atoms built')

    obs = pn.Observation(corrected=True)
    for atom in all_atoms:
        # Computes all the intensities of all the lines of all the ions considered
        for wavelength in all_atoms[atom].lineList:
            elem, spec = parseAtom(atom)
            intens1 = all_atoms[atom].getEmissivity(
                tem1, dens1, wave=wavelength) * dens1 * mass1
            intens2 = all_atoms[atom].getEmissivity(
                tem2, dens2, wave=wavelength) * dens2 * mass2
            obs.addLine(
                pn.EmissionLine(
                    elem,
                    spec,
                    wavelength,
                    obsIntens=[intens1, intens2, intens1 + intens2],
                    obsError=[0.0, 0.0, 0.0]))

    pn.log_.message('Virtual observations computed')

    emisgrids = pn.getEmisGridDict(atomDict=all_atoms)

    pn.log_.message('EmisGrids available')

    # Produce a diagnostic plot for each of the two regions and another one for the (misanalyzed) overall region

    plt.subplot(2, 2, 1)
    diags.plot(emisgrids, obs, i_obs=0)

    plt.subplot(2, 2, 2)
    diags.plot(emisgrids, obs, i_obs=1)

    plt.subplot(2, 1, 2)
    pn.log_.level = 3
    diags.plot(emisgrids, obs, i_obs=2)
Пример #5
0
def get_OoH_2(error=None):

    obs = pn.Observation('NGC300.dat', corrected=True, errIsRelative=False)
    if error == '-':
        for i in np.arange(obs.n_lines):
            obs.lines[i].corrIntens *= 1. - obs.lines[i].corrError
    if error == '+':
        for i in np.arange(obs.n_lines):
            obs.lines[i].corrIntens *= 1. + obs.lines[i].corrError

    O3 = pn.Atom('O', 3)
    r_O3 = O3.getEmissivity(1e4, 1e3, wave=4959) / O3.getEmissivity(
        1e4, 1e3, wave=5007)

    I = lambda label: obs.getLine(label=label).corrIntens
    R23 = (I('O2_3727A+') + I('O3_5007A') * (1 + r_O3)) / 100.
    x = np.log10(R23)
    OsH = 9.265 - 0.33 * x - 0.202 * x**2 - 0.207 * x**3 - 0.333 * x**4
    return OsH
Пример #6
0
def get_OoH_4(Tlow, Thigh, Ne):

    obs = pn.Observation('NGC300.dat', corrected=True, errIsRelative=False)
    O3 = pn.Atom('O', 3)
    r_O3 = O3.getEmissivity(1e4, 1e3, wave=4959) / O3.getEmissivity(
        1e4, 1e3, wave=5007)
    t2 = Tlow / 1e4
    t3 = Thigh / 1e4

    I = lambda label: obs.getLine(label=label).corrIntens
    R2 = I('O2_3727A+') / 100
    R3 = I('O3_5007A') * (1 + r_O3) / 100.
    R = I('O3_4363A') / 100
    R23 = R2 + R3
    X23 = np.log10(R23)
    x2 = 1e-4 * Ne * t2**(-0.5)
    Opp = np.log10(R3) + 6.174 + 1.251 / t3 - 0.55 * np.log10(t3)
    Op = np.log10(R2) + 5.890 + 1.676 / t2 - 0.40 * np.log10(t2) + np.log10(
        1 + 1.35 * x2)

    OsH = np.log10(10**Op + 10**Opp)
    return OsH
Пример #7
0
# Object to be analyzed (could be a list with more than one element)
ngc_list = ['ngc650_R1']

# Loops over items in list (only one in this example)
for ngc in ngc_list:
	
	# Define the data file
	obs_data = ngc +'.dat'
	# Define title
	title = ngc.upper()
	 
	### Read and deredden observational data

	# Define an Observation object and assign it to name 'obs'
	obs = pn.Observation()
	# Fill obs with data read from file obs_data, with lines varying across rows and 
	# a default percent error on line intensities
	obs.readData(obs_data, fileFormat='lines_in_rows', err_default=0.05)
	# Deredden data with Cardelli's law
	obs.extinction.law = extinction_law
	# Apply correction
	obs.correctData()

	#Create file path for data if it does not already exist
	filepath = './'+str(ngc)+'/'
	if not os.path.exists(filepath):
		os.mkdir(filepath)
		
	### Plot
	# Create the contour plot as the intersection of tem-den emission maps with dereddened line ratios
Пример #8
0
"""
Question 5
"""
pn.atomicData.setDataFileDict('IRAF_09')
ion_ab_dic_IRAF = ex3_1.getIonAb('IC2165_IR.dat', Ne_O2, Ne_Ar4, T_N2, T_O3, printIonAb = True)
elem_abun_IRAF = ex3_1.getElemAb(ion_ab_dic_IRAF, printAb = True)
pn.atomicData.resetDataFileDict()
for icf in elem_abun_UVIR:
    print('{0}: {1:.3f} {2:.3f}'.format(icf, np.log10(elem_abun_UVIR[icf])+12, np.log10(elem_abun_IRAF[icf])+12))
#-------------------------------------- ex3_2 ----------------------------------------------
import ex3_2
import atpy
import asciitable

#Read the observations. Notice that in this file the errors are absolutes
obs = pn.Observation('NGC300.dat', corrected=True, errIsRelative=False)
# the galactocentric distance has been also read and the values are in "obsIntens"
Rgal = obs.getLine(label='DIST').obsIntens
# Compute the densities and temperatures
mean_dens, temp_O2, temp_S2, temp_N2, temp_O3, temp_S3 = ex3_2.p1(obs)

# Instantiate a table to write the results in anm ascii file
T = atpy.Table()
# Adding the columns with their names into T
T.add_column('NAME', obs.names)
T.add_column('T_O2', temp_O2)
T.add_column('T_S2', temp_S2)
T.add_column('T_N2', temp_N2)
T.add_column('T_O3', temp_O3)
# writing to a file
T.write('temperatures.ascii', type='ascii',
Пример #9
0
def p3(restore=True, fignum=3, pypic_path=pn.config.pypic_path):
    # --- pregunta 3 Adding IR lines-------------------------------
    # Define where emission maps are to be stored (restore = False) or read from (restore = True)
    # Create the directory before running this program
    obs_data = 'IC2165_IR.dat'
    obs = pn.Observation()
    # fill obs with data read from file obs_data, with lines varying across rows and a default percent error on line intensities
    obs.readData(obs_data,
                 fileFormat='lines_in_rows',
                 err_default=0.05,
                 corrected=True)
    temp = 14000
    dens = 10**3.5
    # Compute theoretical H5-4/Hbeta ratio from Hummer and Storey
    IR2Opt_theo = pn.getRecEmissivity(temp, dens, 5, 4) / pn.getRecEmissivity(
        temp, dens, 4, 2)
    IR2Opt_obs = obs.getLine(label='H1_4.1m').corrIntens / obs.getLine(
        label='H1_4861A').corrIntens
    for line in obs.lines:
        if line.label[-1] == 'm':
            line.corrIntens *= IR2Opt_theo / IR2Opt_obs

    diags = pn.Diagnostics()

    diags.addDiag([
        '[NI] 5198/5200',
        '[NII] 5755/6584',
        '[OI] 5579/6302',
        '[OII] 3726/3729',
        '[OII] 3727+/7325+',
        '[OIII] 4363/5007',
        '[SII] 6731/6716',
        '[SII] 4072+/6720+',
        '[SIII] 6312/9069',
        '[ArIII] 5192/7136',
        '[ArIV] 4740/4711',
        '[ClIII] 5538/5518',
        '[CIII] 1909/1907',
        '[OIII] 1666/5007',
        '[NeV] 1575/3426',
        '[OIII] 51m/88m',
        '[NeIII] 15.6m/36.0m',
        '[NeV] 14.3m/24.2m',
        '[SIII] 18.7m/33.6m',
        '[NeIII] 3869/15.6m',
        '[OIII] 5007/88m',
        '[ArIII] 7136/9m',
        '[SIII] 6312/18.7m',
    ])
    diags.addDiag('[ClIV] 5323/7531',
                  ('Cl4', 'L(5323)/L(7531)', 'RMS([E(7531),E(5323)])'))

    # Create the emission maps to be compared to the observation data
    # To see the default parameters, do pn.getEmisGridDict? in ipython
    emisgrids = pn.getEmisGridDict(atomDict=diags.atomDict,
                                   den_max=1e6,
                                   pypic_path=pypic_path)

    ### Plot
    plt.figure(fignum)
    # Create the contour plot as the intersection of tem-den emission maps with dereddened line ratios
    diags.plot(emisgrids, obs)
    # Put the title
    plt.title('IC 2165 Optical + UV + IR diagnostics')

    # Display the plot
    plt.show()
    plt.savefig('IC6165-diag-opt+UV+IR.pdf')
Пример #10
0
# Sort lines of an observational dataset in alphabetical order
import pyneb as pn

# Read data
obs_data = 'pne.dat'
obs = pn.Observation(obs_data, fileFormat='lines_in_rows', corrected=True)

out_file = open('out.dat', 'w')

# getSortedLines returns lines in sorted order
for line in obs.getSortedLines():
    row = line.label
    for item in line.corrIntens:
        row += ' {0:10.3e}'.format(item)
    out_file.write(row + '\n')

out_file.close()
Пример #11
0
# plot_Fe3 example script
# Plots diagnostic diagrams from several Fe III lines, using two different sets of atomic data

import numpy as np
import pyneb as pn
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import make_axes_locatable

pn.config.set_noExtrapol(True)
pn.log_.level = 3
# Read the observed intensities, reddening corrected, from a file
obs = pn.Observation('Fe3.dat',
                     fileFormat='lines_in_rows',
                     err_default=0.01,
                     corrected=True)

# Build an atom with default values from Quinet 1996, two kinds of interpolation
pn.atomicData.setDataFile('fe_iii_atom_Q96_J00.dat')
pn.atomicData.setDataFile('fe_iii_coll_Z96.dat')
Fe3_Z = pn.Atom('Fe', 3)

Fe3EM_Q_C = {
    'Fe3':
    pn.EmisGrid(n_tem=100,
                n_den=100,
                tem_min=5000.,
                tem_max=15000.,
                den_min=100.,
                den_max=1.e5,
                atomObj=Fe3_Z)
}