obj_AssignLines['FTDTR-9'] = helium1Lines  + helium2Lines + sulfurLines + oxygen3Lines + oxygen2Lines + nitrogenLines + argon3Lines
obj_AssignLines['FTDTR-10'] = helium1Lines  + helium2Lines + sulfurLines + oxygen3Lines + oxygen2Lines + nitrogenLines + argon3Lines

#Loop throught the objects
failing_objects = []
for objName in catalogue_df.loc[dz.idx_include].index:

        # Article reference
        quick_reference = catalogue_df.loc[objName].quick_index

        print objName, (quick_reference)

        # Object folder
        oldFolder = '{}{}/'.format(catalogue_dict['Obj_Folder'], objName)
        objectNewFolder = root_folder + objName + '/'
        make_folder(objectNewFolder)

        # Get fits data
        fits_file = catalogue_df.loc[objName].reduction_fits
        wave, flux, etraData = dz.get_spectra_data(fits_file)

        # Get lines log data
        lineslog_address = '{}{}{}'.format(oldFolder,objName,lineslog_ext)
        linesLogDf = dz.load_lineslog_frame(lineslog_address)
        linesLogDf.rename(columns=lineslogDfNewHeaders, inplace=True)
        linesLogDf.rename(index=lineslogDfNewIndeces, inplace=True)

        # Generate a grid plot and add continuum contribution in recombination lines
        lineFluxes = linesLogDf['line_Flux'].values
        linesLogDf['obs_flux'], linesLogDf['obs_fluxErr'] = nominal_values(lineFluxes), std_devs(lineFluxes)
        plotFolder = '{}/input_data/'.format(objectNewFolder)
Example #2
0
from lib.Astro_Libraries.spectrum_fitting.import_functions import make_folder
import shutil

# Import functions
dz = Dazer()
specS = SpectraSynthesizer()

# Declare data location
root_folder = 'E:\\Dropbox\\Astrophysics\\Data\\WHT_observations\\bayesianModel\\'  # root_folder = '/home/vital/Dropbox/Astrophysics/Data/WHT_observations/bayesianModel/'
whtSpreadSheet = 'E:\\Dropbox\\Astrophysics\\Data\\WHT_observations\\WHT_Galaxies_properties.xlsx'  # whtSpreadSheet = '/home/vital/Dropbox/Astrophysics/Data/WHT_observations/WHT_Galaxies_properties.xlsx'
article_supplementary_folder = 'E:\\Dropbox\\Astrophysics\\Papers\\Yp_BayesianMethodology\\supplementary material online\\'
fluxes_folder = article_supplementary_folder + 'emission_line_fluxes\\'
results_folder = article_supplementary_folder + 'model_parameters\\'

# Make new folder
make_folder(fluxes_folder)
make_folder(results_folder)

# Import data
catalogue_dict = dz.import_catalogue()
catalogue_df = dz.load_excel_DF(whtSpreadSheet)

default_lines = [
    'H1_4341A', 'H1_6563A', 'He1_4471A', 'He1_5876A', 'He1_6678A', 'He2_4686A',
    'O2_7319A', 'O2_7319A_b', 'O2_7330A', 'O3_4363A', 'O3_4959A', 'O3_5007A',
    'N2_6548A', 'N2_6584A', 'S2_6716A', 'S2_6731A', 'S3_6312A', 'S3_9069A',
    'S3_9531A', 'Ar3_7136A', 'Ar4_4740A'
]

# Quick indexing
dz.quick_indexing(catalogue_df)
Example #3
0
    def prepareSimulation(self,
                          obs_data,
                          ssp_data=None,
                          output_folder=None,
                          storage_folder=None,
                          spectra_components=None,
                          input_lines='all',
                          normalized_by_Hbeta=True,
                          excludeReddening=False,
                          T_high_prior=False,
                          prefit_ssp=True,
                          wavelengh_limits=None,
                          resample_inc=None,
                          norm_interval=None):

        # Store components fit
        self.spectraComponents = spectra_components

        # Folders to store inputs and outputs
        self.input_folder = output_folder + 'input_data/'  # TODO sure?
        self.output_folder = output_folder + 'output_data/'
        self.dataFolder = self.output_folder if storage_folder is None else storage_folder  # TODO sure?
        self.configFile = obs_data[
            'obsFile']  #TODO this one has to go into the configuration
        self.objName = str(obs_data['objName'])
        self.prefit_db = '{}{}_sspPrefitDB'.format(self.dataFolder,
                                                   self.objName)
        self.sspCoeffsPrefit_file = '{}{}_prefitSSPpopulations.txt'.format(
            self.input_folder, self.objName)
        self.sspCoeffs_file = '{}{}_SSPpopulations.txt'.format(
            self.input_folder, self.objName)

        # Create them if not available
        make_folder(self.input_folder)
        make_folder(self.output_folder)

        # Prepare spectrum components for fitting
        self.emissionCheck, self.stellarCheck, self.emissionCheck = False, False, False

        # Pre-analysis emission spectrum
        if 'emission' in self.spectraComponents:

            # Get emission data from input files
            self.ready_simulation(output_folder,
                                  obs_data,
                                  ssp_data,
                                  spectra_components,
                                  input_lines=input_lines,
                                  wavelengh_limits=wavelengh_limits,
                                  resample_inc=resample_inc,
                                  norm_interval=norm_interval)

            # Declare gas sampler variables
            self.gasSamplerVariables(
                self.obj_data['lineIons'], self.config['high_temp_ions'],
                self.obj_data['lineFluxes'], self.obj_data['lineErr'],
                self.obj_data['lineLabels'], self.obj_data['lineFlambda'],
                normalized_by_Hbeta, self.config['linesMinimumError'])

            # Prios definition # TODO this must go to the a special section
            self.priorsDict = {
                'T_low': self.obj_data['Te_prior'],
                'n_e': self.obj_data['ne_prior']
            }

            # Confirm inputs are valid
            self.emissionCheck = True

        # Prefit stellar continua
        if 'stellar' in self.spectraComponents:

            self.stellarCheck = True

            # Perform a new SPP synthesis otherwise use available data
            if prefit_ssp:

                # Compute nebular continuum using normalise Halpha and standard conditions
                self.computeDefaultNeb(
                    self.nebDefault['Te_neb'], self.obj_data['nebFlambda'],
                    self.nebDefault['cHbeta_neb'], self.nebDefault['He1_neb'],
                    self.nebDefault['He2_neb'],
                    self.nebDefault['flux_halpha'] /
                    self.obj_data['normFlux_coeff'], self.nebDefault['z_neb'])

                # Ready continuum data
                self.prepareContinuaData(
                    self.ssp_lib['wave_resam'],
                    self.ssp_lib['flux_norm'],
                    self.ssp_lib['normFlux_coeff'],
                    self.obj_data['wave_resam'],
                    self.obj_data['flux_norm'],
                    self.obj_data['continuum_sigma'],
                    self.int_mask,
                    nebularFlux=self.nebDefault['synth_neb_flux'])

                # Select model
                self.select_inference_model('stelar_prefit')

                # Plot input simulation data
                self.plotInputSSPsynthesis()

                # Run stellar continua prefit and store/print the results
                #self.run_pymc(self.prefit_db, iterations=8000, variables_list=['Av_star', 'sigma_star'], prefit = True)
                self.savePrefitData(self.sspCoeffsPrefit_file, self.prefit_db)

            # Compute nebular continuum using prior physical data
            self.computeDefaultNeb(
                self.nebDefault['Te_neb'], self.obj_data['nebFlambda'],
                self.nebDefault['cHbeta_neb'], self.nebDefault['He1_neb'],
                self.nebDefault['He2_neb'],
                self.obj_data['flux_halpha'] / self.obj_data['normFlux_coeff'],
                self.nebDefault['z_neb'])

            # Compute nebular continuum using normalise Halpha and standard conditions
            # TODO I think I need to remove nebular continuum here if I want to add it later
            self.prepareContinuaData(
                self.ssp_lib['wave_resam'],
                self.ssp_lib['flux_norm'],
                self.ssp_lib['normFlux_coeff'],
                self.obj_data['wave_resam'],
                self.obj_data['flux_norm'],
                self.obj_data['continuum_sigma'],
                self.int_mask,
                nebularFlux=None,  #self.nebDefault['synth_neb_flux'],
                mainPopulationsFile=self.sspCoeffsPrefit_file)

        return