<jupyter_start><jupyter_text>MAIN BEST RESULTS FOR STELLAR PART OF THE SPECTRA AND ATTENUATION:<jupyter_code>print("stellar mass: {:.2f} [stellar mass]".format(log10(mod[obs['id'] == HELPid]['best.stellar.m_star'][0])))
print("V-band attenuation in the birth clouds: {:.2f} ".format((mod[obs['id'] == HELPid]['best.attenuation.Av_BC'][0])))
print("attenuation in FUV band: {:.2f} [mag]".format((mod[obs['id'] == HELPid]['best.attenuation.FUV'][0])))
print("attenuation in V band: {:.2f} [mag]".format((mod[obs['id'] == HELPid]['best.attenuation.V_B90'][0])))<jupyter_output>stellar mass: 10.61 [stellar mass]
V-band attenuation in the birth clouds: 4.00 
attenuation in FUV band: 5.33 [mag]
attenuation in V band: 1.90 [mag]<jupyter_text>Below on the plot stellar components (attenuated and unattenuated) are plotted against observed fluxes:<jupyter_code>if (sed.columns[1][wsed] > 0.).any():
    ax1 = plt.subplot(gs[0])
    ax1.loglog(wavelength_spec[wsed], (sed['stellar.young'][wsed] + sed['attenuation.stellar.young'][wsed] + 
               sed['stellar.old'][wsed] + sed['attenuation.stellar.old'][wsed]), 
               label="Stellar attenuated ", color='orange', marker=None, nonposy='clip', linestyle='-', linewidth=0.5)
    ax1.loglog(wavelength_spec[wsed], (sed['stellar.old'][wsed] +  sed['stellar.young'][wsed]), 
               label="Stellar unattenuated", color='b', marker=None, nonposy='clip', linestyle='--', linewidth=0.5)
    ax1.loglog(wavelength_spec[wsed], sed['L_lambda_total'][wsed], label=" ", color='white', nonposy='clip', 
               linestyle='-', linewidth=0)

    ax1.set_autoscale_on(False)
    mask_ok = np.logical_and(obs_fluxes > 0., obs_fluxes_err > 0.)
    ax1.errorbar(filters_wl[mask_ok], obs_fluxes[mask_ok], yerr=obs_fluxes_err[mask_ok]*3, ls='', marker='s', 
                 label='Observed fluxes', markerfacecolor='None',markersize=6, markeredgecolor='b', capsize=0.)

    mask = np.where(obs_fluxes > 0.)

    figure.subplots_adjust(hspace=0., wspace=0.)

    ax1.set_xlim(xmin, xmax)
    ymin = min(np.min(obs_fluxes[mask_ok]), np.min(mod_fluxes[mask_ok]))
    ymax = max(np.max(obs_fluxes[mask_ok]), np.max(mod_fluxes[mask_ok]))
    ax1.set_ylim(1e-1*ymin, 1e1*ymax)

    ax1.set_xlabel("Observed wavelength [$\mu$m]")
    ax1.set_ylabel("Flux [mJy]")
    ax1.legend(fontsize=6, loc='best', fancybox=True, framealpha=0.5)
    plt.setp(ax1.get_xticklabels(), visible=False)
    plt.setp(ax1.get_yticklabels()[1], visible=False)
    print("Best model for {} at z = {:.2f}. best log(Mstar) = {:.2f}". format(HELPid, z,log10(mod[obs['id'] == HELPid]['best.stellar.m_star'][0])))<jupyter_output>Best model for HELP_J095937.48+015501.93 at z = 0.61. best log(Mstar) = 10.61<jupyter_text>MAIN BEST RESULTS FOR DUST EMISSION:<jupyter_code>print("power law slope dU/dM (alpha) : {:.2f}".format((mod[obs['id'] == HELPid]['best.dust.alpha'][0])))
print("fraction illuminated from Umin to Umax (gamma): {:.2f} ".format((mod[obs['id'] == HELPid]['best.dust.gamma'][0])))
print("mass fraction of PAH: {:.2f} ".format((mod[obs['id'] == HELPid]['best.dust.qpah'][0])))
print("minimum radiation field: {:.2f} ".format((mod[obs['id'] == HELPid]['best.dust.umin'][0])))
print("best dust luminosity: {:.2f} [stellar luminosity]".format(log10((mod[obs['id'] == HELPid]['best.dust.luminosity'][0])/(3.846*pow(10,26)))))<jupyter_output>power law slope dU/dM (alpha) : 2.00
fraction illuminated from Umin to Umax (gamma): 0.01 
mass fraction of PAH: 3.90 
minimum radiation field: 1.00 
best dust luminosity: 11.22 [stellar luminosity]<jupyter_text>Below on the plot dust component is  plotted against observed fluxes:<jupyter_code>if (sed.columns[1][wsed] > 0.).any():
    ax1 = plt.subplot(gs[0])

    ax1.loglog(wavelength_spec[wsed],
                           (sed['dust.Umin_Umin'][wsed] +
                            sed['dust.Umin_Umax'][wsed]),
                           label="Dust emission", color='r', marker=None,
                           nonposy='clip', linestyle='-', linewidth=0.5)
    ax1.loglog(wavelength_spec[wsed], sed['L_lambda_total'][wsed],
                       label="", color='white', nonposy='clip',
                       linestyle='-', linewidth=0)

    mask_ok = np.logical_and(obs_fluxes > 0., obs_fluxes_err > 0.)
    ax1.errorbar(filters_wl[mask_ok], obs_fluxes[mask_ok],
                         yerr=obs_fluxes_err[mask_ok]*3, ls='', marker='s',
                         label='Observed fluxes', markerfacecolor='None',
                         markersize=6, markeredgecolor='b', capsize=0.)

    mask = np.where(obs_fluxes > 0.)

    figure.subplots_adjust(hspace=0., wspace=0.)

    ax1.set_xlim(xmin, xmax)
    ymin = min(np.min(obs_fluxes[mask_ok]),
                       np.min(mod_fluxes[mask_ok]))
    ymax = max(np.max(obs_fluxes[mask_ok]),
                           np.max(mod_fluxes[mask_ok]))
    ax1.set_ylim(1e-1*ymin, 1e1*ymax)


    ax1.set_xlabel("Observed wavelength [$\mu$m]")
    ax1.set_ylabel("Flux [mJy]")
    ax1.legend(fontsize=6, loc='best', fancybox=True, framealpha=0.5)
    plt.setp(ax1.get_xticklabels(), visible=False)
    plt.setp(ax1.get_yticklabels()[1], visible=False)
    print("Best model for {} at z = {:.2f}. best log(Ldust) = {:.2f}". format(HELPid, z,log10((mod[obs['id'] == HELPid]['best.dust.luminosity'][0])/(3.846*pow(10,26)))))<jupyter_output>Best model for HELP_J095937.48+015501.93 at z = 0.61. best log(Ldust) = 11.22<jupyter_text>MAIN BEST RESULTS FOR AGN component:<jupyter_code>print("best fraction of AGN : {:.2f}".format((mod[obs['id'] == HELPid]['best.agn.fracAGN'][0])))
if mod[obs['id'] == HELPid]['best.agn.fracAGN'][0]>0:
    print("best AGN liminosity: {:.2f} [stellar luminosity]".format(log10((mod[obs['id'] == HELPid]['best.agn.luminosity'][0])/(3.846*pow(10,26)))))



if mod[obs['id'] == HELPid]['best.agn.fracAGN'][0]>0:

    if (sed.columns[1][wsed] > 0.).any():
        ax1 = plt.subplot(gs[0])
        ax1.loglog(wavelength_spec[wsed],(sed['agn.fritz2006_therm'][wsed] + sed['agn.fritz2006_scatt'][wsed] + 
                    sed['agn.fritz2006_agn'][wsed]),label="AGN emission", color='g', marker=None, nonposy='clip', linestyle='-', linewidth=0.5)
        ax1.loglog(wavelength_spec[wsed], sed['L_lambda_total'][wsed], label="", color='white', nonposy='clip',
                       linestyle='-', linewidth=0)

        mask_ok = np.logical_and(obs_fluxes > 0., obs_fluxes_err > 0.)
        ax1.errorbar(filters_wl[mask_ok], obs_fluxes[mask_ok], yerr=obs_fluxes_err[mask_ok]*3, ls='', marker='s',
                label='Observed fluxes', markerfacecolor='None',markersize=6, markeredgecolor='b', capsize=0.)

        mask = np.where(obs_fluxes > 0.)

        figure.subplots_adjust(hspace=0., wspace=0.)

        ax1.set_xlim(xmin, xmax)
        ymin = min(np.min(obs_fluxes[mask_ok]), np.min(mod_fluxes[mask_ok]))
        ymax = max(np.max(obs_fluxes[mask_ok]), np.max(mod_fluxes[mask_ok]))
        ax1.set_ylim(1e-1*ymin, 1e1*ymax)

        ax1.set_xlabel("Observed wavelength [$\mu$m]")
        ax1.set_ylabel("Flux [mJy]")
        ax1.legend(fontsize=6, loc='best', fancybox=True, framealpha=0.5)
        plt.setp(ax1.get_xticklabels(), visible=False)
        plt.setp(ax1.get_yticklabels()[1], visible=False)

    print("Best model for {} at z = {:.2f}. best AGNfrac) = {:.2f}". format(HELPid, z,(mod[obs['id'] == HELPid]['best.agn.fracAGN'][0])))<jupyter_output>Best model for HELP_J095937.48+015501.93 at z = 0.61. best AGNfrac) = 0.40<jupyter_text>In the last step all modules are merge together to computed one best model (based on the $\chi^2$) marked as a black line in the figure below. Modeled fluxes for each filter used for SED fitting are calculated based on the best model. The relative residual fluxes are ploted in the bottom panel of the figure. Final $\chi^2$ value as well as main physical parameters computed based on PDF analysis are listed below:<jupyter_code>print("reduced $\chi^2$ : {:.2f} ".format((mod[obs['id'] == HELPid]['best.reduced_chi_square'][0])))
print("bayesian stellar mass {:.2f} +/- {:.2f} [M sun]:".format(log10(mod[obs['id'] == HELPid]['bayes.stellar.m_star'][0]),0.434*(mod[obs['id'] == HELPid]['bayes.stellar.m_star'][0])/(mod[obs['id'] == HELPid]['bayes.stellar.m_star_err'][0])))
print("bayesian dust luminosity: {:.2f} +/- {:.2f} [L sun]".format(log10((mod[obs['id'] == HELPid]['bayes.dust.luminosity'][0])/(3.846*pow(10,26))),0.434*(mod[obs['id'] == HELPid]['bayes.dust.luminosity'][0])/(mod[obs['id'] == HELPid]['bayes.dust.luminosity_err'][0])))
print("bayesian SFR {:.2f} +/- {:.2f} [M sun / yr]:".format((mod[obs['id'] == HELPid]['bayes.sfh.sfr10Myrs'][0]),(mod[obs['id'] == HELPid]['bayes.sfh.sfr10Myrs_err'][0])))
print("bayesian AGN fraction {:.2f} +/- {:.2f}:".format((mod[obs['id'] == HELPid]['bayes.agn.fracAGN'][0]),(mod[obs['id'] == HELPid]['bayes.agn.fracAGN_err'][0])))
if (sed.columns[1][wsed] > 0.).any():
    ax1 = plt.subplot(gs[0])
    ax2 = plt.subplot(gs[1])
    # Stellar emission
    ax1.loglog(wavelength_spec[wsed], (sed['stellar.young'][wsed] + sed['attenuation.stellar.young'][wsed] + 
               sed['stellar.old'][wsed] + sed['attenuation.stellar.old'][wsed]), label="Stellar attenuated ", 
               color='orange', marker=None, nonposy='clip', linestyle='-',linewidth=0.5)
    ax1.loglog(wavelength_spec[wsed],(sed['stellar.old'][wsed] + sed['stellar.young'][wsed]), 
               label="Stellar unattenuated", color='b', marker=None,nonposy='clip', linestyle='--', linewidth=0.5)
    #Dust emission
    ax1.loglog(wavelength_spec[wsed], (sed['dust.Umin_Umin'][wsed] + sed['dust.Umin_Umax'][wsed]), 
               label="Dust emission", color='r', marker=None, nonposy='clip', linestyle='-', linewidth=0.5)
    # AGN emission Fritz
    if 'agn.fritz2006_therm' in sed.columns:
        ax1.loglog(wavelength_spec[wsed], (sed['agn.fritz2006_therm'][wsed] + sed['agn.fritz2006_scatt'][wsed] + 
                sed['agn.fritz2006_agn'][wsed]), label="AGN emission", color='g', marker=None, nonposy='clip', 
                   linestyle='-', linewidth=0.5)

    ax1.loglog(wavelength_spec[wsed], sed['L_lambda_total'][wsed], label="Model spectrum", color='k', nonposy='clip',
                       linestyle='-', linewidth=1.5)

    ax1.set_autoscale_on(False)
    ax1.scatter(filters_wl, mod_fluxes, marker='o', color='r', s=8,zorder=3, label="Model fluxes")
    mask_ok = np.logical_and(obs_fluxes > 0., obs_fluxes_err > 0.)
    ax1.errorbar(filters_wl[mask_ok], obs_fluxes[mask_ok], yerr=obs_fluxes_err[mask_ok]*3, ls='', marker='s', 
                 label='Observed fluxes', markerfacecolor='None', markersize=6, markeredgecolor='b', capsize=0.)

    mask = np.where(obs_fluxes > 0.)
    ax2.errorbar(filters_wl[mask],(obs_fluxes[mask]-mod_fluxes[mask])/obs_fluxes[mask],  
                 yerr=obs_fluxes_err[mask]/obs_fluxes[mask]*3, marker='_', label="(Obs-Mod)/Obs", color='k', capsize=0.)
    ax2.plot([xmin, xmax], [0., 0.], ls='--', color='k')
    ax2.set_xscale('log')
    ax2.minorticks_on()

    figure.subplots_adjust(hspace=0., wspace=0.)

    ax1.set_xlim(xmin, xmax)
    ymin = min(np.min(obs_fluxes[mask_ok]),np.min(mod_fluxes[mask_ok]))
    ymax = max(np.max(obs_fluxes[mask_ok]),np.max(mod_fluxes[mask_ok]))
    ax1.set_ylim(1e-1*ymin, 1e1*ymax)
    ax2.set_xlim(xmin, xmax)
    ax2.set_ylim(-1.0, 1.0)

    ax2.set_xlabel("Observed wavelength [$\mu$m]")
    ax1.set_ylabel("Flux [mJy]")
    ax2.set_ylabel("Relative residual flux")
    ax1.legend(fontsize=6, loc='best', fancybox=True, framealpha=0.5)
    ax2.legend(fontsize=6, loc='best', fancybox=True, framealpha=0.5)
    plt.setp(ax1.get_xticklabels(), visible=False)
    plt.setp(ax1.get_yticklabels()[1], visible=False)
    
    print("Best model for {} at z = {:.2f}, best(Mstar) = {:.2f}, best log(Ldust) = {:.2f}, best AGNfrac = {:.2f}". 
          format(HELPid, z,log10(mod[obs['id'] == HELPid]['best.stellar.m_star'][0]),
                 log10((mod[obs['id'] == HELPid]['best.dust.luminosity'][0])/(3.846*pow(10,26))), 
                 mod[obs['id'] == HELPid]['bayes.agn.fracAGN'][0]))<jupyter_output>Best model for HELP_J095937.48+015501.93 at z = 0.61, best(Mstar) = 10.61, best log(Ldust) = 11.22, best AGNfrac = 0.40<jupyter_text>Global redshift vs stellar mass, redshift vs dust luminosity and redshift vs SFR relations: In three figures below red star corresponds to the analized galaxy:   redshift vs stellar mass<jupyter_code>mstar,red,ldust,sfr=[],[],[],[]
for gal in range(0,len(mod)):
    if mod[gal]['best.reduced_chi_square']<4:
        mstar.append(log10(mod[gal]['bayes.stellar.m_star']))
        red.append((mod[gal]['redshift']))
        ldust.append(log10(mod[gal]['bayes.dust.luminosity']/(3.846*pow(10,26))))
        sfr.append(log10(mod[gal]['bayes.sfh.sfr10Myrs']))

mstar=np.array(mstar)
red=np.array(red)
ldust=np.array(ldust)
sfr=np.array(sfr)

ax1 = plt.subplot(gs[0])

ax1.plot(red, mstar,'-o',c='lightgray',linewidth=0,linestyle=' ')
specific_mstar=log10(mod[obs['id'] == HELPid]['bayes.stellar.m_star'][0])
ax1.plot(z,specific_mstar,'-*',c='red',markersize=15)

ax1.set_xlabel("redshift")
ax1.set_ylabel("log(Mstar)")
ax1.set_ylim(7, 12)

ax1.legend(fontsize=6, loc='best', fancybox=True, framealpha=0.5)<jupyter_output>/opt/anaconda3/lib/python3.5/site-packages/matplotlib/axes/_axes.py:531: UserWarning: No labelled objects found. Use label='...' kwarg on individual plots.
  warnings.warn("No labelled objects found. "<jupyter_text>redshift vs dust luminosity<jupyter_code>ax1 = plt.subplot(gs[0])

ax1.plot(red, ldust,'-o',c='lightgray',linewidth=0,linestyle=' ')
specific_Ldust=log10(mod[obs['id'] == HELPid]['bayes.dust.luminosity']/(3.846*pow(10,26)))
ax1.plot(z,specific_Ldust,'-*',c='red',markersize=15)

ax1.set_xlabel("redshift")
ax1.set_ylabel("log(Ldust)")
ax1.set_ylim(8, 14)

ax1.legend(fontsize=6, loc='best', fancybox=True, framealpha=0.5)<jupyter_output>/opt/anaconda3/lib/python3.5/site-packages/matplotlib/axes/_axes.py:531: UserWarning: No labelled objects found. Use label='...' kwarg on individual plots.
  warnings.warn("No labelled objects found. "<jupyter_text>redshift vs SFR<jupyter_code>ax1 = plt.subplot(gs[0])

ax1.plot(red, sfr,'-o',c='lightgray',linewidth=0,linestyle=' ')
specific_sfr=log10(mod[obs['id'] == HELPid]['bayes.sfh.sfr10Myrs'])
ax1.plot(z,specific_sfr,'-*',c='red',markersize=15)

ax1.set_xlabel("redshift")
ax1.set_ylabel("log(SFR)")
ax1.set_ylim(-2, 4)

ax1.legend(fontsize=6, loc='best', fancybox=True, framealpha=0.5)<jupyter_output>/opt/anaconda3/lib/python3.5/site-packages/matplotlib/axes/_axes.py:531: UserWarning: No labelled objects found. Use label='...' kwarg on individual plots.
  warnings.warn("No labelled objects found. "
{'fraction_non_alphanumeric': 0.1977067643666463, 'fraction_numerical': 0.03840151977746116, 'mean_word_length': 4.572778827977316, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 46, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '127403', 'license': 'MIT', 'n_tokens_mistral': 6218, 'n_tokens_neox': 5699, 'n_words': 871, 'path': 'dmu28/dmu28_COSMOS/SEDs_HELP_J095937.48+015501.93.ipynb', 'repo_name': 'djbsmith/dmu_products', 'size': '14739'}