Ejemplo n.º 1
0
        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,
                         'saveFolder': starlight2012_folder.as_posix(),
                         'Galaxy_mass_Current': mass_galaxy,
                         'Galaxy_mass_Prosessed': massProcess_galaxy,
                         'Galaxy_mass_Percentbelow20Myr': mass_galaxy_20Myr_percent,
                         'Chi2': fit_output['Chi2'],
                         'A_V_stellarr': fit_output['Av_min'],
                         'cHbeta_stellar': cHbeta_star,
                         'PixelMeanDevPer': fit_output['SumXdev'],
                         'SN': fit_output['SignalToNoise_magnitudeWave']}
        sr.parseConfDict(results_file, starlight_cfg, f'Starlight_run_{cycle}', clear_section=True)

        # Plot the results
        plot_label = f'{obj} spectrum' if ext == '_BR' else f'{obj} blue arm spectrum'
        sw.population_fraction_plots(fit_output, plot_label, 'Mass_fraction', massFracPlotFile, mass_galaxy=mass_galaxy)
        sw.population_fraction_plots(fit_output, plot_label, 'Light_fraction', LightFracPlotFile)
        sw.mask_plot(fit_output, obj, lm.wave, lm.flux, stellar_Wave, stellar_flux, obj_input_flux)#, outputAddress=maskPlotFile)

    Int_StellarExtension = np.zeros(len(Wave_StellarExtension))

    #Increase the range of Wave_S so it is greater than the observational range
    Wave_S = np.hstack((Wave_StellarExtension, stellar_Wave))
    Int_S = np.hstack((Int_StellarExtension, stellar_flux))

    #Resampling stellar spectra
    Interpolation = interp1d(Wave_S, Int_S, kind='slinear')
    flux_Stellar_Resampled = Interpolation(lm.wave)

    # Save the non object spectrum without stellar component
    stellarFlux = flux_Stellar_Resampled
    np.savetxt(stellarFluxFile,
               np.transpose(np.array([lm.wave, stellarFlux])),
               fmt="%7.1f %10.4e")

    # Plot the results
    plot_label = f'{obj} spectrum' if ext == '_BR' else f'{obj} blue arm spectrum'
    sw.population_fraction_plots(fit_output,
                                 plot_label,
                                 'Mass_fraction',
                                 massFracPlotFile,
                                 mass_galaxy=mass_galaxy)
    sw.population_fraction_plots(fit_output, plot_label, 'Light_fraction',
                                 LightFracPlotFile)
    sw.stellar_fit_comparison_plot(f'{obj}_{ext}_{cycle}', lm.wave, lm.flux,
                                   nebCompFile, stellarFluxFile,
                                   stellarPlotFile)
    sw.mask_plot(fit_output, obj, lm.wave, specFlux, stellar_Wave,
                 stellar_flux, obj_input_flux, maskFile, maskPlotFile)