stellarPlotFile = outputFolder / f'{obj}{ext}_stellarFit.png'
        specCompPlot = outputFolder / f'{obj}{ext}_specComponents.png'

        # Set wavelength and flux
        print(f'\n-- Treating {counter} :{obj}{ext}.fits')
        wave, flux_array, header = sr.import_fits_data(fits_file,
                                                       instrument='OSIRIS')
        wave_rest = wave / (1 + z)
        idx_wave = (wave_rest >= wmin_array[i]) & (wave_rest <= wmax_array[i])
        flux = flux_array[idx_band][0] if ext in ('_B', '_R') else flux_array

        obsWave, obsFlux = wave_rest[idx_wave], flux[idx_wave]
        nebWave, nebFlux = np.loadtxt(nebCompFile, unpack=True)
        obsNoNebWave, obsNoNebFlux = np.loadtxt(nebFluxNoNebCompFile,
                                                unpack=True)
        sw = SSPsynthesizer()
        stellarWave, inFlux, stellarFlux, fit_output = sw.load_starlight_output(
            starlightOutput)
        tsl = atpy.TableSet(str(starlightOutput), type='starlightv4')
        psfh = plot_fits_and_SFH(tsl)
        psfh.plot_fig_starlight()

        # collapse = False
        # cumsum = False
        # zcolor = [item['color'] for item in matplotlib.rcParams['axes.prop_cycle']]
        # fig = plt.figure(figsize=(10, 8))
        # gs = gridspec.GridSpec(2, 1)
        # gs.update(left=0.05, bottom=0.05, right=0.98, hspace=0.0)
        # ageBase = np.unique(tsl.population['popage_base'])
        # zBase = np.unique(tsl.population['popZ_base'])
        # lageBase = np.log10(ageBase)
Beispiel #2
0
        outputFile = f'{obj}.BN'

        # Declare output files
        massFracPlotFile = objFolder / f'{obj}_{ext}_SSP_MasFrac_Papaderos_{cycle}.png'
        LightFracPlotFile = objFolder / f'{obj}_{ext}_SSP_LightFrac_Papaderos_{cycle}.png'
        stellarPlotFile = objFolder / f'{obj}_{ext}_stellarFit_Papaderos_{cycle}.png'
        maskPlotFile = objFolder / f'{obj}_{ext}_maskAndFlags_Papaderos_{cycle}.png'
        stellarFluxFile = objFolder / f'{obj}_{ext}_stellarFlux_Papaderos_{cycle}.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]))

        # Starlight wrapper
        sw = SSPsynthesizer()

        # Read output data
        stellar_Wave, obj_input_flux, stellar_flux, fit_output = sw.load_starlight_output(starlight2012_folder/outputFile)
        z_gp = obsData['sample_data']['z_array'][i]
        Mcor, Mint = fit_output['Mcor_tot'], fit_output['Mini_tot']
        mass_galaxy = computeSSP_galaxy_mass(Mcor, 1, z_gp)
        massProcess_galaxy = computeSSP_galaxy_mass(Mint, 1, z_gp)
        idcs_below_20Myr = fit_output['DF'].age_j < 2*10**7
        mass_galaxy_20Myr_percent = np.sum(fit_output['DF'].loc[idcs_below_20Myr, 'Mcor_j'].values)

        # Store starlight configuration values for linux runy
        rc = pn.RedCorr(R_V=RV, E_BV=fit_output['Av_min'] / RV, law=red_law)
        cHbeta_star = rc.cHbetaFromEbv(fit_output['Av_min']/RV)
        starlight_cfg = {'gridFileName': outputFile,
                         'outputFile': outputFile,
Beispiel #3
0
    age_range = np.unique(db.loc[idcs_db, 'age_yr'].values)
    z_range = np.unique(db.loc[idcs_db, 'z_star'].values)

    flux_matrix = np.empty((z_range.size, age_range.size, wave_array.size))
    flux_matrix[:, :, :] = np.nan
    for i_z, z in enumerate(z_range):
        for j_age, age in enumerate(age_range):
            i_flux = (db.z_star == z) & (db.age_yr == age)
            flux_matrix[i_z, j_age, :] = flux_array[i_flux]

    return z_range, age_range, flux_matrix


data_folder = Path('D:\Dropbox\Astrophysics\Papers\gtc_greenpeas\data')

starCalc = SSPsynthesizer()
nebCalc = NebularContinua()

# Stellar parameter
cropWaves = None
resamInter = 1
normWaves = (5100, 5150)
age_max_grid = 1.5e7
z_min_grid = 0.005

# Nebular parameters
temp_range = np.linspace(5000, 30000, 126)
HeI_range = np.linspace(0.05, 0.20, 51)
HeII_HI = 0.001

# Generate stellar data grids if they are not available:
    int_spec, corr_spec = double_arm_redCorr(lm.wave, lm.flux, w_div_array[i],
                                             red_law, RV, cHbeta)

    # 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]

    # Remove nebular component spectra
    specFlux = lm.flux - nebFlux

    # Starlight wrapper
    sw = SSPsynthesizer()

    # Generate starlight files
    clip_value = obsData[obj]['starlight_clipping']
    idcs_lines = ~linesDF.index.str.contains('_b')
    gridFileName, outputFile, saveFolder, waveResample, fluxResample = sw.generate_starlight_files(
        starlight_folder,
        f'{obj}_{ext}_{cycle}',
        lm.wave,
        specFlux,
        linesDF.loc[idcs_lines],
        clip_value=clip_value)

    if os.name != 'nt':
        # Launch starlight
        print(f'\n-Initiating starlight: {obj}')
            stellarPlotFile = outputFolder/f'{obj}{ext}_stellarFit.png'

            # Set wavelength and flux
            print(f'\n-- Treating {counter} :{obj}{ext}.fits')
            wave, flux_array, header = sr.import_fits_data(fits_file, instrument='OSIRIS')
            wave_rest = wave / (1 + z)
            idx_wave = (wave_rest >= wmin_array[i]) & (wave_rest <= wmax_array[i])
            flux = flux_array[idx_band][0] if ext in ('_B', '_R') else flux_array

            # Load the data
            obsWave, obsFlux = wave_rest[idx_wave], flux[idx_wave]
            specWave, specFlux = np.loadtxt(nebFluxNoNebCompFile, unpack=True)

            # Measuring objects
            lm = sr.LineMesurer(specWave, specFlux, lineLog_file, normFlux=flux_norm)
            sw = SSPsynthesizer()

            # Generate starlight files
            idcs_lines = ~lm.linesDF.index.str.contains('_b')
            gridFileName, outputFile, saveFolder, waveResample, fluxResample = sw.generate_starlight_files(starlightFolder,
                                                                                                             f'{obj}{ext}',
                                                                                                             specWave,
                                                                                                             specFlux,
                                                                                                             lm.linesDF.loc[idcs_lines])

            # # Launch starlight
            # print(f'\n-Initiating starlight: {obj}')
            # sw.starlight_launcher(gridFileName, starlightFolder)
            # print('\n-Starlight finished succesfully ended')

            # Read output data
    return z_range, age_range, flux_matrix


storing_folder = Path('D:\Dropbox\Astrophysics\Papers\gtc_greenpeas\data')

size_dict = {
    'axes.titlesize': 14,
    'axes.labelsize': 14,
    'legend.fontsize': 14,
    'xtick.labelsize': 12,
    'ytick.labelsize': 12,
}
rcParams.update(size_dict)

starCalc = SSPsynthesizer()
nebCalc = NebularContinua()

bases_folder = Path(
    "D:\Dropbox\Astrophysics\Papers\gtc_greenpeas\data\starlight\Bases")
bases_file = Path(
    "D:\Dropbox\Astrophysics\Papers\gtc_greenpeas\data\starlight\Dani_Bases_short.txt"
)

bases_df_file = storing_folder / 'bases_db'
# bases_df, wave_bases, flux_bases = starCalc.import_STARLIGHT_bases(bases_file, bases_folder, crop_waves=None, resam_inter=1, norm_waves=(5100, 5150))
#
# # Storing to files
# bases_df.to_pickle(f'{bases_df_file}_pickle')
# np.save(storing_folder/'waves_bases', wave_bases)
# np.save(storing_folder/'flux_bases', flux_bases)
Beispiel #7
0
    # Define wave and flux ranges
    wave_rest = wave / (1 + z_mean)
    idx_wave = (wave_rest >= wmin_array[i]) & (wave_rest <= wmax_array[i])

    # Load the data
    obsWave, obsFlux = wave_rest[idx_wave], flux[idx_wave]
    specWave, specFlux = np.loadtxt(lineLogFolder / nebFluxNoNebCompFile,
                                    unpack=True)

    # Measuring objects
    lm = sr.LineMesurer(specWave,
                        specFlux,
                        lineLogFolder / lineLogFile,
                        normFlux=flux_norm)
    sw = SSPsynthesizer()

    # Generate starlight files
    gridFileName, outputFile, outputFolder, waveResample, fluxResample = sw.generate_starlight_files(
        starlightFolder, objName, specWave, specFlux, lm.linesDF)

    # Compute the galaxy mass

    # # Launch starlight
    # print(f'\n-Initiating starlight: {objName}')
    # sw.starlight_launcher(gridFileName, starlightFolder)
    # print('\n-Starlight finished succesfully ended')

    # Read output data
    Input_Wavelength, Input_Flux, Output_Flux, fit_output = sw.load_starlight_output(
        outputFolder / outputFile)
pdf.addTableRow(sub_headers, last_row=True)

for i, obj in enumerate(objList):

    # Declare files location
    fits_file = dataFolder / f'{obj}{ext}.fits'
    objFolder = resultsFolder / f'{obj}'
    lineLog_file = objFolder / f'{obj}{ext}_linesLog_c2.txt'
    results_file = objFolder / f'{obj}{ext}_measurements.txt'
    objMask = objFolder / f'{obj}{ext}_mask.txt'
    nebCompFile = objFolder / f'{obj}{ext}_NebFlux_{cycle}.txt'
    run_ref = f'{obj}{ext}_{cycle}'
    objSSP_outputFile = starlight_folder / 'Output' / f'{obj}{ext}_it2.slOutput'

    # Starlight wrapper
    sw = SSPsynthesizer()

    # Data output
    results_dict = sr.loadConfData(results_file, group_variables=False)
    stellar_fit_dict = results_dict[f'Starlight_run_it2']
    stellar_Wave, obj_input_flux, stellar_flux, fit_output = sw.load_starlight_output(
        objSSP_outputFile)

    if stellar_fit_dict['A_V_stellarr'] == 0:
        stellar_fit_dict['A_V_stellarr'] = 0.0

    row_data = [
        objRefNames[i],
        np.round(stellar_fit_dict['Galaxy_mass_Current'], 2),
        np.round(stellar_fit_dict['Galaxy_mass_Percentbelow20Myr'], 2),
        np.round(stellar_fit_dict['A_V_stellarr'], 2),
Beispiel #9
0
# Import the observation data
obsData = sr.loadConfData(
    '../../../papers/gtc_greenpeas/gtc_greenpeas_data.ini',
    group_variables=False)
# starlightFolder = Path('/home/vital/Astro-data/osiris-Ricardo/starlight')
starlightFolder = Path(
    'D:/Google drive/Astrophysics/Datos/osiris-Ricardo/starlight')
data_folder = Path(obsData['file_information']['data_folder'])
file_list = obsData['file_information']['files_list']
addressList = list(data_folder / file for file in file_list)
flux_norm = obsData['sample_data']['norm_flux']

# Analyse the spectrum
for i, file_address in enumerate(addressList):

    sw = SSPsynthesizer()

    # Establish files location
    objName = obsData['file_information']['object_list'][i]
    fitsFolder, fitsFile = file_address.parent, file_address.name
    masksFolder, masksFile = fitsFolder, fitsFile.replace(
        '.fits', '_masks.txt')
    lineLogFolder = fitsFolder / 'flux_analysis'
    lineLogFile = fitsFile.replace('.fits', '_linesLog.txt')
    specCompPlot = fitsFile.replace('.fits', '_specComponents.png')
    nebFluxNoNebCompFile = fitsFile.replace('.fits',
                                            '_obs_RemoveNebularComp.txt')
    nebCompFile = fitsFile.replace('.fits', '_NebFlux.txt')
    outputFileAddress = starlightFolder / f'Output/{objName}.slOutput'
    objGasSpectrumFile = fitsFolder / 'flux_analysis' / f'{objName}_gasSpectrum.txt'
    print(f'-{objName}')