示例#1
0
    def load_elements(self):

        #Set atomic data
        #atomicData.setDataFile('he_i_rec_Pal12-Pal13.fits')
        atomicData.setDataFile('s_iii_coll_HRS12.dat')

        #Default: 's_iii_atom_PKW09.dat'
        'S3: All energy and A values: Podobedova, Kelleher, and Wiese 2009, J. Phys. Chem. Ref. Data, Vol.'
        'S3: collision strengths: Tayal & Gupta 1999, ApJ, 526, 544'

        #New Atomic data s_iii_coll_HRS12.dat
        'S3: All energy and A values: Podobedova, Kelleher, and Wiese 2009, J. Phys. Chem. Ref. Data, Vol.'
        'S3: collision strengths: Hudson, Ramsbottom & Scott 2012, ApJ, 750, 65'

        #Declare ions
        self.S2_atom = Atom('S', 2)
        self.S3_atom = Atom('S', 3)
        self.Ar3_atom = Atom('Ar', 3)
        self.Ar4_atom = Atom('Ar', 4)
        self.N2_atom = Atom('N', 2)
        self.O2_atom = Atom('O', 2)
        self.O3_atom = Atom('O', 3)
        self.H1_atom = RecAtom('H', 1)
        self.He1_atom = RecAtom('He', 1)
        self.He2_atom = RecAtom('He', 2)

        #Pyneb objects
        self.diags = Diagnostics()

        #Ohrs 2016 relation for the OI_SI gradient
        self.logSI_OI_Gradient = random.normal(
            -1.53, 0.05, size=self.MC_array_len
        )  # random.normal(-1.78,  0.03, size = self.MC_array_len)
        self.OI_SI = power(10, -self.logSI_OI_Gradient)

        #Theoretical ratios
        self.S3_ratio = self.S3_atom.getEmissivity(
            10000, 100, wave=9531) / self.S3_atom.getEmissivity(
                10000, 100, wave=9069)
        self.S3_9000_ratio = random.normal(
            self.S3_atom.getEmissivity(10000, 100, wave=9531) /
            self.S3_atom.getEmissivity(10000, 100, wave=9069),
            0.01,
            size=self.MC_array_len)
        self.N2_6000_ratio = self.N2_atom.getEmissivity(
            10000, 100, wave=6584) / self.N2_atom.getEmissivity(
                10000, 100, wave=6548)
        self.O3_5000_ratio = self.O3_atom.getEmissivity(
            10000, 100, wave=5007) / self.O3_atom.getEmissivity(
                10000, 100, wave=4959)

        #Factors to speed calculations
        self.lines_factors = {}
        self.lines_factors['S3_9069A'] = 1 + self.S3_ratio
        self.lines_factors['S3_9531A'] = 1 + 1 / self.S3_ratio

        #Cloudy models for the SIV contribution

        self.m_SIV_correction = random.normal(1.1628,
                                              0.00559,
                                              size=self.MC_array_len)
        self.n_SIV_correction = random.normal(0.0470,
                                              0.0097,
                                              size=self.MC_array_len)
        #self.m_SIV_correction   = random.normal(1.109,  0.01, size = self.MC_array_len)
        #self.n_SIV_correction   = random.normal(0.135,  0.0173, size = self.MC_array_len)

        #CHAOS relation TNII-TSIII
        #T[SIII]  = 1.312(+-0.075)T[NII]-0.313(+-0.058)
        #TNII     = (0.762+-0.044)*TSIII  + 0.239+-0.046
        self.m_TNII_correction = random.normal(0.762,
                                               0.044,
                                               size=self.MC_array_len)
        self.n_TNII_correction = random.normal(0.239,
                                               0.046,
                                               size=self.MC_array_len)

        #Truncated gaussian for the density
        lower_trunc, upper_trunc = (1.0 - 50.0) / 25.0, (100 - 50) / 25.0
        self.Truncated_gaussian = truncnorm(lower_trunc,
                                            upper_trunc,
                                            loc=50,
                                            scale=25)

        print '-Elements loaded\n'

        return
示例#2
0
    def compare_RecombCoeffs(self,
                             obj_data,
                             lineslog_frame,
                             spectral_limit=200):

        # Create hidrogen atom object
        self.H1_atom = RecAtom('H', 1)

        linformat_df = read_csv(
            '/home/vital/workspace/dazer/format/emlines_pyneb_optical_infrared.dz',
            index_col=0,
            names=['ion', 'lambda_theo', 'latex_format'],
            delim_whitespace=True)
        lineslog_frame['latex_format'] = 'none'

        for line in lineslog_frame.index:
            if '_w' not in line:  # Structure to avoid wide components
                lineslog_frame.loc[line, 'latex_format'] = r'${}$'.format(
                    linformat_df.loc[line, 'latex_format'])

        # Load electron temperature and density (if not available it will use Te = 10000K and ne = 100cm^-3)
        T_e = self.checking_for_ufloat(obj_data.TeSIII) if ~isnan(
            self.checking_for_ufloat(obj_data.TeSIII)) else 10000.0
        n_e = self.checking_for_ufloat(obj_data.neSII) if ~isnan(
            self.checking_for_ufloat(obj_data.neSII)) else 100.0

        # Get the Hidrogen recombination lines that we have observed in this object
        Obs_Hindx = lineslog_frame.Ion.isin(self.RecombRatios_Ions)

        # Calculate recombination coefficients and reddening curve values
        Obs_H_Emis = empty(len(Obs_Hindx))
        Obs_Ions = lineslog_frame.loc[Obs_Hindx, 'Ion'].values

        for i in range(len(Obs_Ions)):
            TransitionCode = Obs_Ions[i][Obs_Ions[i].find('_') +
                                         1:len(Obs_Ions[i])]
            Obs_H_Emis[i] = self.H1_atom.getEmissivity(tem=T_e,
                                                       den=n_e,
                                                       label=TransitionCode)

            # Normalize by Hbeta (this new constant is necessary to avoid a zero sigma)
        Hbeta_Emis = self.H1_atom.getEmissivity(tem=T_e, den=n_e, label='4_2')
        Fbeta_flux = ufloat(
            lineslog_frame.loc['H1_4861A']['line_Flux'].nominal_value,
            lineslog_frame.loc['H1_4861A']['line_Flux'].std_dev)

        # Load theoretical and observational recombination ratios to data frame
        lineslog_frame.loc[Obs_Hindx, 'line_Emissivity'] = Obs_H_Emis
        lineslog_frame.loc[Obs_Hindx,
                           'line_TheoRecombRatio'] = Obs_H_Emis / Hbeta_Emis
        lineslog_frame.loc[Obs_Hindx,
                           'line_ObsRecombRatio'] = lineslog_frame.loc[
                               Obs_Hindx, 'line_Flux'].values / Fbeta_flux

        # Get indeces of emissions in each arm
        ObsBlue_Hindx = Obs_Hindx & (lineslog_frame.lambda_theo <
                                     obj_data.join_wavelength)
        ObsRed_Hindx = Obs_Hindx & (lineslog_frame.lambda_theo >
                                    obj_data.join_wavelength)

        # Recalculate red arm coefficients so they are normalized by red arm line (the most intense)
        if (ObsRed_Hindx.sum()
            ) > 0:  # Can only work if there is at least one line
            idx_Redmax = lineslog_frame.loc[ObsRed_Hindx]['flux_intg'].idxmax(
            )  # We do not use line_flux because it is a ufloat and it does not work with idxmax
            H_Redmax_flux = lineslog_frame.loc[idx_Redmax, 'line_Flux']
            H_Redmax_emis = lineslog_frame.loc[idx_Redmax, 'line_Emissivity']
            Flux_Redmax = ufloat(
                H_Redmax_flux.nominal_value * Hbeta_Emis / H_Redmax_emis,
                H_Redmax_flux.std_dev * Hbeta_Emis / H_Redmax_emis)
            lineslog_frame.loc[ObsRed_Hindx,
                               'line_ObsRecombRatio'] = lineslog_frame.loc[
                                   ObsRed_Hindx,
                                   'line_Flux'].values / Flux_Redmax

        # Load x axis values: (f_lambda - f_Hbeta) and y axis values: log(F/Fbeta)_theo - log(F/Fbeta)_obs to dataframe
        lineslog_frame.loc[Obs_Hindx, 'x axis values'] = lineslog_frame.loc[Obs_Hindx, 'line_f'].values - \
                                                         lineslog_frame.loc['H1_4861A']['line_f']
        lineslog_frame.loc[Obs_Hindx, 'y axis values'] = unum_log10(
            lineslog_frame.loc[Obs_Hindx, 'line_TheoRecombRatio'].values
        ) - unum_log10(lineslog_frame.loc[Obs_Hindx,
                                          'line_ObsRecombRatio'].values)

        # Compute all the possible configuration of points and store them
        output_dict = {}

        # --- All points:
        output_dict['all_x'] = lineslog_frame.loc[Obs_Hindx,
                                                  'x axis values'].values
        output_dict['all_y'] = lineslog_frame.loc[Obs_Hindx,
                                                  'y axis values'].values
        output_dict['all_ions'] = list(
            lineslog_frame.loc[Obs_Hindx, 'latex_format'].values)

        # --- By arm
        output_dict['blue_x'] = lineslog_frame.loc[ObsBlue_Hindx,
                                                   'x axis values'].values
        output_dict['blue_y'] = lineslog_frame.loc[ObsBlue_Hindx,
                                                   'y axis values'].values
        output_dict['blue_ions'] = list(
            lineslog_frame.loc[ObsBlue_Hindx, 'latex_format'].values)
        output_dict['red_x'] = lineslog_frame.loc[ObsRed_Hindx,
                                                  'x axis values'].values
        output_dict['red_y'] = lineslog_frame.loc[ObsRed_Hindx,
                                                  'y axis values'].values
        output_dict['red_ions'] = list(
            lineslog_frame.loc[ObsRed_Hindx, 'latex_format'].values)

        # --- Store fluxes
        output_dict['Blue_ObsRatio'] = unum_log10(
            lineslog_frame.loc[ObsBlue_Hindx, 'line_ObsRecombRatio'].values)
        output_dict['Red_ObsRatio'] = unum_log10(
            lineslog_frame.loc[ObsRed_Hindx, 'line_ObsRecombRatio'].values)
        output_dict['line_Flux_Blue'] = lineslog_frame.loc[ObsBlue_Hindx,
                                                           'line_Flux'].values
        output_dict['line_Flux_Red'] = lineslog_frame.loc[ObsRed_Hindx,
                                                          'line_Flux'].values
        output_dict['line_wave_Blue'] = lineslog_frame.loc[
            ObsBlue_Hindx, 'lambda_theo'].values
        output_dict['line_wave_Red'] = lineslog_frame.loc[ObsRed_Hindx,
                                                          'lambda_theo'].values

        # --- Inside limits
        if obj_data.h_gamma_valid == 'yes':
            in_idcs = Obs_Hindx
        elif obj_data.h_gamma_valid == 'no':
            wave_idx = ((lineslog_frame.lambda_theo > (obj_data.Wmin_Blue + spectral_limit)) & (
                        lineslog_frame.lambda_theo < (obj_data.join_wavelength - spectral_limit))) \
                       | ((lineslog_frame.lambda_theo > (obj_data.join_wavelength + spectral_limit)) & (
                        lineslog_frame.lambda_theo < (obj_data.Wmax_Red - spectral_limit)))
            in_idcs = Obs_Hindx & wave_idx

        output_dict['in_x'] = lineslog_frame.loc[in_idcs,
                                                 'x axis values'].values
        output_dict['in_y'] = lineslog_frame.loc[in_idcs,
                                                 'y axis values'].values
        output_dict['in_ions'] = list(
            lineslog_frame.loc[in_idcs, 'latex_format'].values)

        # --- Outside limis
        if obj_data.h_gamma_valid == 'no':
            wave_idx = (lineslog_frame.lambda_theo <
                        (obj_data.Wmin_Blue + spectral_limit)) | (
                            lineslog_frame.lambda_theo >
                            (obj_data.Wmax_Red - spectral_limit))
            out_idcs = Obs_Hindx & wave_idx
            output_dict['out_x'] = lineslog_frame.loc[out_idcs,
                                                      'x axis values'].values
            output_dict['out_y'] = lineslog_frame.loc[out_idcs,
                                                      'y axis values'].values
            output_dict['out_ions'] = list(
                lineslog_frame.loc[out_idcs, 'latex_format'].values)
        else:
            output_dict['out_x'] = None
            output_dict['out_y'] = None
            output_dict['out_ions'] = None

        return output_dict