wave, flux, header = sr.import_fits_data(spec_file,
                                             instrument='xshooter',
                                             frame_idx=0)
    wave_sigma, sigma, header_sigma = sr.import_fits_data(
        sigm_file, instrument='xshooter', frame_idx=0)

    lm = sr.LineMesurer(wave,
                        flux,
                        crop_waves=[wmin_array[i], wmax_array[i]],
                        input_err=sigma,
                        normFlux=norm_flux,
                        redshift=z_obj)

    # lm.plot_spectrum(obsLinesTable=obsLinesTable, matchedLinesDF=maskLinesDF, specLabel=f'{objName}')
    mask_local = data_folder / f'{objName}_mask'
    mask_local_df = sr.lineslogFile_to_DF(mask_local)

    obsLines = mask_local_df.index.values
    for j, lineLabel in enumerate(obsLines):
        wave_regions = mask_local_df.loc[lineLabel, 'w1':'w6'].values
        if lineLabel in ['O3_5007A_b']:
            # wave_regions[2] = 8400.0/(1+lm.redshift)
            # wave_regions[3] = 8445.0/(1+lm.redshift)
            lm.fit_from_wavelengths(lineLabel,
                                    wave_regions,
                                    user_conf=profile_conf)
            lm.print_results(show_plot=True,
                             show_fit_report=False,
                             log_scale=False,
                             frame='rest')
    objMask = dataFolder / f'{obj}_{ext}_mask.txt'
    results_file = objFolder / f'{obj}_{ext}_measurements.txt'
    lineLog_file = objFolder / f'{obj}_{ext}_linesLog_it3.txt'

    # output spectrum
    spectrum_ssp = objFolder / f'{obj}_starlight_spectrum.txt'

    # Load the data
    wave, flux_array, header = sr.import_fits_data(fits_file,
                                                   instrument='OSIRIS')
    flux = flux_array[idx_band][0] if ext in ('_B', '_R') else flux_array
    lm = sr.LineMesurer(wave,
                        flux,
                        redshift=z_array[i],
                        crop_waves=(wmin_array[i], wmax_array[i]))
    linesDF = sr.lineslogFile_to_DF(lineLog_file)

    # Add new masks
    linesDF = sr.lineslogFile_to_DF(lineLog_file)
    ini_mask, end_points = obsData[obj]['ini_mask_array'], obsData[obj][
        'end_mask_array']
    labels = ['cont_mask_' + str(int(x)) for x in ini_mask]
    for j, label_mask in enumerate(labels):
        linesDF.loc[labels[j], ['w3', 'w4']] = ini_mask[j], end_points[j]

    # Compute the mask array
    mask_array = np.zeros(lm.wave.size)

    for mask_label in linesDF.index:
        w_blue, w_red = linesDF.loc[mask_label, ['w3', 'w4']].values
        idcs_mask = (lm.wave > w_blue) & (lm.wave < w_red)
Пример #3
0
from pathlib import Path
import src.specsiser as sr

# Declare the data location
obsFitsFile = Path('./sample_data/gp121903_BR.fits')
lineMaskFile = Path('./sample_data/gp121903_BR_mask.txt')
cfgFile = Path('./sample_data/gtc_greenpeas_data.ini')

# Load the data
obsConf = sr.loadConfData(cfgFile, objList_check=True, group_variables=False)
maskDF = sr.lineslogFile_to_DF(lineMaskFile)
wave, flux, header = sr.import_fits_data(obsFitsFile, instrument='OSIRIS')
user_conf = obsConf['gp121903_line_fitting']

# Declare line measuring object
lm = sr.LineMesurer(wave,
                    flux,
                    redshift=obsConf['sample_data']['z_array'][2],
                    normFlux=obsConf['sample_data']['norm_flux'])
lm.plot_spectrum()

# Find lines
norm_spec = lm.continuum_remover(
    noiseRegionLims=obsConf['sample_data']['noiseRegion_array'])
obsLinesTable = lm.line_finder(
    norm_spec,
    noiseWaveLim=obsConf['sample_data']['noiseRegion_array'],
    intLineThreshold=3)
matchedDF = lm.match_lines(obsLinesTable, maskDF)
lm.plot_spectrum(obsLinesTable=obsLinesTable,
                 matchedLinesDF=matchedDF,
Пример #4
0
for i, obj in enumerate(objList):

    if i == 0:

        # Data location
        objFolder = resultsFolder
        cube_address_i = fitsFolder / fileList[i]
        mask_address = dataFolder / obsConf['data_location']['mask_global']
        db_address = objFolder / f'{obj}_database.fits'

        # Load the data
        wave, data, header = sr.import_fits_data(cube_address_i,
                                                 instrument='fits-cube',
                                                 frame_idx=0)
        mask_global_DF = sr.lineslogFile_to_DF(mask_address)

        # Declare voxels to analyse
        flux5007_image = fits.getdata(db_address,
                                      f'{ref_flux_line}_flux',
                                      ver=1)
        flux5007_levels = np.nanpercentile(flux5007_image, percentil_array)
        ion, wavelength, latexLabel = sr.label_decomposition(
            ref_flux_line, scalar_output=True)

        for idx_level, flux_level in enumerate(flux5007_levels):

            if idx_level + 1 < len(flux5007_levels):

                if idx_level == 0:
                    maFlux_image = np.ma.masked_where(
Пример #5
0
import pathlib
import numpy as np
import pandas as pd
import src.specsiser as sr

conf_file_address = '../sampleHeII.ini'
obsData = sr.loadConfData(conf_file_address)

fits_folder = pathlib.Path(obsData['data_location']['fits_folder'])
data_folder = pathlib.Path(obsData['data_location']['treatment_folder'])
objList_file = data_folder/f'AVO_dataframe.txt'

pertil_array = obsData['sample_data']['percentil_array']

# Load the list of objects
logDF = sr.lineslogFile_to_DF(objList_file)

arrayFluxLevel = np.percentile(logDF['He2_4685A'].values, pertil_array)

# Recover the group of objects
for i, flux_level in enumerate(arrayFluxLevel):

    if i == 0:
        idcs_spec = logDF['He2_4685A'] >= flux_level
    else:
        idcs_spec = (logDF['He2_4685A'] < arrayFluxLevel[i-1]) & (logDF['He2_4685A'] >= flux_level)

    logDF.loc[idcs_spec, 'intensity_Group'] = i

df_file = data_folder/f'AVO_catalogue_dataframe.txt'
with open(df_file, 'wb') as output_file:
Пример #6
0
                            normFlux=normFlux,
                            crop_waves=(1 + z_i) *
                            np.array([4685 - 100, 5100]))
        yield idx_obj, obj_name, lm.wave, lm.flux


conf_file_address = '../sampleHeII.ini'
obsData = sr.loadConfData(conf_file_address)

fits_folder = pathlib.Path(obsData['data_location']['fits_folder'])
data_folder = pathlib.Path(obsData['data_location']['treatment_folder'])
catalogueDataframe = data_folder / f'AVO_catalogue_dataframe.txt'
normFlux = obsData['sample_data']['norm_flux']

# Load the list of objects
logDF = sr.lineslogFile_to_DF(catalogueDataframe)
# logDF['valid'] = False
# if 'valid' not in logDF:
#     logDF['valid'] = False
print('empezamos', (logDF['valid'] == True).sum())

# for obj in ['1734-53034-56', '859-52317-170', '616-52442-101', '525-52295-193', '2956-54525-19', '2173-53874-491']:
#     logDF.loc[obj, 'valid'] = True
#
# with open(catalogueDataframe, 'wb') as output_file:
#     string_DF = logDF.to_string()
#     output_file.write(string_DF.encode('UTF-8'))

first_obj = 0
list_groups = np.arange(8)
for idx_group in list_groups:
conf_file_address = '../../../papers/gtc_greenpeas/gtc_greenpeas_data.ini'
obsData = sr.loadConfData(conf_file_address, group_variables=False)

dataFolder = Path(obsData['file_information']['data_folder'])
resultsFolder = Path(obsData['file_information']['results_folder'])
fileList = obsData['file_information']['files_list']
color_dict = {'_SDSS': 'tab:purple', '_B': 'tab:blue', '_R': 'tab:red'}
label_dict = {'_SDSS': 'SDSS dr16', '_B': 'Blue arm - Osiris', '_R': 'Red arm - Osiris'}

counter = 0
for i, obj in enumerate(objList):

    objFolder = resultsFolder/f'{obj}'
    mainLinesLog = objFolder/f'{obj}_BR_linesLog.txt'

    mainLogDF = sr.lineslogFile_to_DF(mainLinesLog)

    flux_Hbeta, err_Hbeta = mainLogDF.loc['H1_4861A', 'intg_flux'], mainLogDF.loc['H1_4861A', 'intg_err']
    flux_norm = ufloat(flux_Hbeta, err_Hbeta)

    idcs_obsLines = ~mainLogDF.index.str.contains('_b')
    obsLines = mainLogDF.loc[idcs_obsLines].index.values

    linesFlux = mainLogDF.loc[idcs_obsLines, 'intg_flux'].values
    LinesErr = mainLogDF.loc[idcs_obsLines, 'intg_err'].values
    lineFluxArray = unumpy.uarray(linesFlux, LinesErr)
    lineNormArray = lineFluxArray/flux_norm

    ion_array, wave_array, latexLabel_array = sr.label_decomposition(obsLines, combined_dict=obsData['default_line_fitting'])

    # Plot Configuration
Пример #8
0
            wave = wave * 10 if objName != 'j131037' else wave
            wave_sigma = wave_sigma * 10 if objName != 'j131037' else wave_sigma

            trim_limits = [wmin_array[j], wmax_array[j]]
            lm = sr.LineMesurer(wave,
                                flux,
                                crop_waves=trim_limits,
                                input_err=sigma,
                                normFlux=norm_flux,
                                redshift=z_obj[i])
            if verbose:
                lm.plot_spectrum(continuumFlux=lm.errFlux)

            # Find lines
            global_mask = data_folder / f'global_mask.txt'
            global_mask_df = sr.lineslogFile_to_DF(global_mask)

            lineLabel = 'H1_6563A_b'
            wave_regions = global_mask_df.loc[lineLabel, 'w1':'w6'].values
            lm.fit_from_wavelengths(lineLabel,
                                    wave_regions,
                                    user_conf=profile_conf)
            w80 = lm.plot_line_velocity(plot_title=objName)
            print(f'{objName} {w80} {lineLabel}')

        # norm_spec = lm.continuum_remover(noiseRegionLims=norm_region)
        # obsLinesTable = lm.line_finder(norm_spec, noiseWaveLim=norm_region, intLineThreshold=3)
        # matchedDF = lm.match_lines(obsLinesTable, global_mask_df, find_line_borders=False)
        # if verbose:
        #     lm.plot_spectrum(obsLinesTable=obsLinesTable, matchedLinesDF=matchedDF, specLabel=f'Emission line detection')
Пример #9
0
        fluxImage_6312 = lineFlux_dict['S3_6312A']
        fluxLevels_6312 = levelFlux_dict['S3_6312A']
        int_level = fluxLevels_6312[-4]#[-4]
        array_idcs_voxels = np.argwhere(fluxImage_6312 > int_level)

        for idx_voxel, idx_pair in enumerate(array_idcs_voxels):

            idx_j, idx_i = idx_pair

            # Data location
            outputDb = voxelFolder/f'{idx_j}-{idx_i}_fitting.db'
            local_lineslog = voxelFolder/f'{idx_j}-{idx_i}_lineslog_{obj}.txt'
            inputLinesLog = voxelFolder/f'{idx_j}-{idx_i}_inputLinesLog.txt'

            # Asociate the corresponding flux to the appropiate line
            linesDF = sr.lineslogFile_to_DF(local_lineslog)

            if 'H1_4861A' in linesDF.index:

                # Sampler object
                obj1_model = sr.SpectraSynthesizer()

                # Adjust the lines log for the fitting
                flux_Hbeta = linesDF.loc['H1_4861A', 'intg_flux']
                linesDF.insert(loc=1, column='obsFlux', value=np.nan)
                linesDF.insert(loc=2, column='obsFluxErr', value=np.nan)
                linesDF['obsFlux'] = linesDF['intg_flux']/flux_Hbeta
                linesDF['obsFluxErr'] = linesDF['intg_err']/flux_Hbeta
                linesDF.rename(columns={'wavelength': 'obsWave'}, inplace=True)
                for ion in ['H1', 'He1', 'He2']:
                    idcs_ions = linesDF.ion == ion
Пример #10
0
from matplotlib import pyplot as plt, rcParams, cm, colors
from astropy.wcs import WCS
import time

conf_file_address = '../sampleHeII.ini'
obsData = sr.loadConfData(conf_file_address)

fits_folder = pathlib.Path(obsData['data_location']['fits_folder'])
treatment_folder = pathlib.Path(obsData['data_location']['treatment_folder'])
results_folder = pathlib.Path(obsData['data_location']['results_folder'])

catalogueDataframe = treatment_folder / f'AVO_catalogue_dataframe.txt'
normFlux = obsData['sample_data']['norm_flux']
noise_region = obsData['sample_data']['noiseRegion_array']

logDF = sr.lineslogFile_to_DF(catalogueDataframe)
idcs_obj = logDF.valid == True
objList = logDF.loc[idcs_obj].index.values

mask_global = treatment_folder / 'AVO_global_mask.txt'
maskDF = pd.read_csv(mask_global, delim_whitespace=True, header=0, index_col=0)

linesForced = [
    'He2_4686A', 'O3_4959A', 'O3_5007A', 'H1_4861A', 'H1_6563A', 'N2_6584A',
    'S2_6716A', 'S2_6731A'
]

columns = ['Eqw_Halpha', 'Eqw_Halpha_err']
properties_df = pd.DataFrame(index=objList, columns=columns)
properties_df_addresss = treatment_folder / 'AVO_properties_log_gaussian_flux.txt'
for line in linesForced:
Пример #11
0
fileList = obsConf['data_location']['file_list']
objList = obsConf['data_location']['object_list']
z_list = obsConf['sample_data']['z_array']
norm_flux = obsConf['sample_data']['norm_flux']
ef = EmissionFitting()
percentil_array = obsConf['sample_data']['percentil_array']

for i, obj in enumerate(objList):

    if i == 0:

        # Input data
        objFolder = resultsFolder
        cube_address = fitsFolder / fileList[i]
        mask_global_DF = sr.lineslogFile_to_DF(
            dataFolder / obsConf['data_location']['mask_global'])

        # Output data
        db_addresss = objFolder / f'{obj}_database.fits'
        hdul_lineslog = fits.HDUList()

        # Load the data
        print('\n', db_addresss)
        wave, data, header = import_fits_data(cube_address,
                                              crval3=obsConf[obj]['CRVAL3'],
                                              frame_idx=0)

        for lineLabel in ['O3_5007A_b']:
            lineWaves = mask_global_DF.loc[lineLabel, 'w1':'w6']
            idcsLineRegion, idcsContRegion = ef.define_masks(
                wave / (1 + z_list[i]), data, lineWaves)