Example #1
0
def test_w03Temp_vs_pressureTemp():

    import matplotlib.pyplot as plt
    from myscience import wolfire03 as w03
    from myscience import calc_temperature
    import numpy as np

    # range of densities to compare
    n = np.logspace(0,2,100)

    # get Wolfire+03 temperatures for several rad fields
    G_0_list = [0.6,  0.8, 0.64,]
    cloud_list = ['California', 'Perseus', 'Taurus']
    temp_w03_list = []
    for G_0 in G_0_list:
        temp_w03_list.append(w03.calc_T(n, G_0=G_0))

    # get temperatures assumes regular pressure equilibrium
    temp_pressure = calc_temperature(n_H=n, calc_error=False)

    # Plot the figure
    # -----------------------------------------------------------------------------
    figure = plt.figure(figsize=(5,5))
    for i in xrange(len(G_0_list)):
        G_0 = G_0_list[i]
        cloud = cloud_list[i]
        temp_w03 = temp_w03_list[i]
        plt.plot(n, temp_w03,
                 linestyle='--',
                 linewidth='2',
                 label='W+03, $G_0$={0:.2f}, {1:s}'.format(G_0, cloud),
                 )

    plt.plot(n, temp_pressure,
             linestyle='-',
             linewidth=2,
             label='Ideal Gas Law',
             )

    plt.xlabel(r'$n$ [cm$^{-3}$]')
    plt.ylabel(r'$T$ [K]')
    plt.xscale('log')
    plt.yscale('log')
    plt.legend(loc='best')
    plt.savefig('test_plots/myscience_test.test_w03Temp_vs_pressureTemp.png')
def add_model_params(core_dict):

    from myscience import calc_radiation_field, calc_temperature
    import myscience.sternberg14 as mys14
    import myscience.krumholz09 as myk09

    ''' need the following parameters

    Cloud Name} &
        Core Name} &
        Alternate Name} &
        $T_{\rm dust}$} &
        $U$} &
        \aG} &
        \phicnm} &
        \hisd\ Threshold} &
        $n$} &
        $T_{\rm CNM}$} \\
    '''

    clouds_printed = []
    for core_name in core_dict:
        core = core_dict[core_name]

        temp = core['dust_temp_median']
        temp_error = core['dust_temp_median_error']
        core['rad_field'], core['rad_field_error'] = \
                calc_radiation_field(temp,
                                     T_dust_error=temp_error)

        cloud = core_dict[core_name]['cloud']

        #rad_error = np.sort((calc_radiation_field(temp + temp_error),
        #                     calc_radiation_field(temp - temp_error)))
        #core['rad_field_error'] = rad_error
        for param in core['sternberg']:
            if type(core['sternberg'][param]) is tuple:
                core['sternberg'][param] = np.array(core['sternberg'][param])
        for param in core['krumholz']:
            if type(core['krumholz'][param]) is tuple:
                core['krumholz'][param] = np.array(core['krumholz'][param])

        # Sternberg params
        # =======================================================================
        # calculate n_H and error
        # -----------------------------------------------------------------------
        core['n_H'], core['n_H_error'] = \
                mys14.calc_n_H(I_UV=core['rad_field_draine_median'],
                         alphaG=core['sternberg']['alphaG'],
                         phi_g=core['sternberg']['phi_g'],
                         Z_g=core['sternberg']['Z'],
                         I_UV_error=core['rad_field_draine_median_error'],
                         alphaG_error=core['sternberg']['alphaG_error'],
                         Z_g_error=core['sternberg']['Z_error'],
                         )

        core['w'], core['w_error'] = \
                mys14.calc_w(phi_g=core['sternberg']['phi_g'],
                       phi_g_error=core['sternberg']['phi_g_error'],
                       Z_g=core['sternberg']['Z'],
                       Z_g_error=core['sternberg']['Z_error'],
                       )

        core['chi_s14'], core['chi_s14_error'] = \
                mys14.calc_chi(alphaG=core['sternberg']['alphaG'],
                               alphaG_error=core['sternberg']['alphaG_error'],
                               w=core['w'],
                               w_error=core['w_error'],
                               )

        #if core['n_H'] <= 0:
        #    core['n_H'] = 10

        #core['n_H_error'] = [0.1 * core['n_H'], 0.1 * core['n_H']]

        if 0:
            core['T_H'] = calc_temperature(n_H=core['n_H'],
                                           pressure=3000.0) / 1000.0
            core['T_H_error'] = np.array([0.1 * core['T_H'], 0.1 * core['T_H']])
            T_H_error = np.sort((calc_temperature(core['n_H'] - \
                                  core['n_H_error'][1]),
                                 calc_temperature(core['n_H'] + \
                                  core['n_H_error'][0])))
            core['T_H_error'] = T_H_error / 1000.0
            if abs(core['T_H_error'][0]) > core['T_H']:
                core['T_H_error'][0] = core['T_H']

        pressure = 3700.0
        pressure_error = (1200.0, 1200.0)
        core['T_H'], core['T_H_error'] = \
                calc_temperature(n_H=core['n_H'],
                                 pressure=pressure,
                                 pressure_error=pressure_error,
                                 n_H_error=core['n_H_error'])

        core['T_H'] /= 1000.0
        core['T_H_error'] = np.array(core['T_H_error']) / 1000.0

        # Krumholz params
        # =======================================================================
        krumholz_pressure_calc = True
        if krumholz_pressure_calc:
            # get the minimum CNM density, calculate n_CNM with phi_CNM, then
            # calculate temperature given galactic pressure between WNM and CNM

            #print('Cloud:', cloud)
            #print('Krumholz rad habing field:', core['rad_field_habing_median'])
            #print('Krumholz rad draine field:', core['rad_field_draine_median'])

            n_min, n_min_error = \
                myk09.calc_n_min(G_0=core['rad_field_draine_median'],
                               G_0_error=core['rad_field_draine_median_error'],
                               Z=1.0,
                               calc_error=True,
                               )
            phi_cnm = core['krumholz']['phi_cnm']
            phi_cnm_error = core['krumholz']['phi_cnm_error']
            Z = core['krumholz']['Z']
            Z_error = core['krumholz']['Z_error']
            sigma_d = core['krumholz']['sigma_d']
            sigma_d_error = core['krumholz']['sigma_d_error']
            core['n_cnm'] = n_min * phi_cnm
            core['n_cnm_error'] = ((phi_cnm * n_min_error)**2 + \
                                   (n_min * phi_cnm_error)**2)**0.5

            if 0:
                if cloud == 'perseus':
                    print 'habing median', core['rad_field_habing_median']
                    print 'phi_cnm', phi_cnm
                    print 'n_cnm', core['n_cnm']

            #print core['n_cnm_error']

            core['T_cnm'], core['T_cnm_error'] = \
                calc_temperature(n_H=core['n_cnm'],
                                 pressure=pressure,
                                 pressure_error=pressure_error,
                                 n_H_error=core['n_cnm_error'])

            core['chi'], core['chi_error'] =\
                myk09.calc_chi(phi_cnm=phi_cnm,
                               phi_cnm_error=phi_cnm_error,
                               Z=Z,
                               Z_error=Z_error,
                               sigma_d=sigma_d,
                               sigma_d_error=sigma_d_error,
                               )

        else:
            core['T_cnm'], core['T_cnm_error'] = \
                    myk09.calc_T_cnm(core['krumholz']['phi_cnm'],
                        phi_cnm_error=core['krumholz']['phi_cnm_error'],
                        calc_error=True,
                        )

            core['n_cnm'], core['n_cnm_error'] = \
                    myk09.calc_n_cnm(G_0=(core['rad_field'] / 1.7),
                             G_0_error=(core['rad_field_error'] / 1.7),
                             T_cnm=core['T_cnm'],
                             T_cnm_error=core['T_cnm_error'],
                             calc_error=True,
                             )


        core['T_cnm'], core['T_cnm_error'] = \
            calc_temperature(n_H=core['n_cnm'],
                             pressure=pressure,
                             pressure_error=pressure_error,
                             n_H_error=core['n_cnm_error'])



        core['alt_name'] = get_alt_name(core_name)