Пример #1
0
def calc_T_cnm(phi_cnm, phi_cnm_error, Z=1.0):

    from myscience import krumholz09 as k09

    T_cnm = k09.calc_T_cnm(phi_cnm)

    phi_cnm_low = phi_cnm - phi_cnm_error[0]
    phi_cnm_high = phi_cnm + phi_cnm_error[1]

    T_cnm_low = k09.calc_T_cnm(phi_cnm_low, Z=Z)
    T_cnm_high = k09.calc_T_cnm(phi_cnm_high, Z=Z)

    T_cnm_error = np.sort(np.array(np.abs(T_cnm - T_cnm_low),
                                   np.abs(T_cnm - T_cnm_high)))

    return T_cnm, T_cnm_error
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)