def MOCKdata (z, dict_modelfiles, dict_modelfluxes, parameters):

	all_tau, all_age, all_nh, all_irlum, filename_0_galaxy, filename_0_starburst, filename_0_torus = dict_modelsfiles
	STARBURSTFdict , BBBFdict, GALAXYFdict, TORUSFdict, EBVbbb_array, EBVgal_array = dict_modelfluxes
	tau, age, nh, irlum, SB ,BB, GA,TO, BBebv, GAebv = parameters


	SB_filename = model.pick_STARBURST_template(irlum, filename_0_starburst, all_irlum)
	GA_filename = model.pick_GALAXY_template(tau, age, filename_0_galaxy, all_tau, all_age)
	TOR_filename = model.pick_TORUS_template(nh, all_nh, filename_0_torus)
	BB_filename = model.pick_BBB_template()

	EBV_bbb_0 = model.pick_EBV_grid(EBVbbb_array, BBebv)
	EBV_bbb = (  str(int(EBV_bbb_0)) if  float(EBV_bbb_0).is_integer() else str(EBV_bbb_0))
	EBV_gal_0 = model.pick_EBV_grid(EBVgal_array,GAebv)
	EBV_gal = (  str(int(EBV_gal_0)) if  float(EBV_gal_0).is_integer() else str(EBV_gal_0)) 

	if (GA_filename, EBV_gal) in GALAXYFdict:
		bands, gal_Fnu = GALAXYFdict[GA_filename, EBV_gal]
	else:	
		print 'Error: Dictionary does not contain key of ', GA_filename, EBV_gal, ' or the E(B-V) grid or the DICTIONARIES_AGNfitter file does not match when the one used in PARAMETERSPACE_AGNfitter/ymodel.py'

	if SB_filename in STARBURSTFdict:	
		bands, sb_Fnu= STARBURSTFdict[SB_filename]
	else:
		print 'Error: Dictionary does not contain key'+SB_filename+'. all STARBURST files or the E(B-V) grid.'

	if (BB_filename, EBV_bbb) in BBBFdict:
		bands, bbb_Fnu = BBBFdict[BB_filename, EBV_bbb]	
	else:
		print'Error: Dictionary does not contain key: '+ BB_filename, EBV_bbb +'or the E(B-V) grid of the DICTIONARIES_AGNfitter file does not match when the one used in PARAMETERSPACE_AGNfitter/ymodel.py'

	if TOR_filename in TORUSFdict:
		bands, tor_Fnu= TORUSFdict[TOR_filename]
	else:
		print 'Error: Dictionary does not contain TORUS file:'+TOR_filename

	NormalizationFLux = 1e-28 # This is the flux to which the models are normalized to  have comparable NORM factors
	sb_Fnu_norm = sb_Fnu / 1e18 
	bbb_Fnu_norm = bbb_Fnu / 1e58
	gal_Fnu_norm = gal_Fnu/ 1e12
	tor_Fnu_norm = tor_Fnu/  1e-42 

	# Sum components
	# ---------------------------------------------------------------------------------------------------------------------------------------------------------#
	lum =    10**(SB)* sb_Fnu_norm      +     10**(BB)*bbb_Fnu_norm    +     (10**GA)*gal_Fnu_norm     +     10**TO *tor_Fnu_norm 

	#-----------------------------------------------------------------------------------------------------------------------------------------------------------
	mockfluxes_array = lum.reshape((np.size(lum),))	

	return bands, mockfluxes_array
def galaxy_flux(dict_modelsfiles, dict_modelfluxes, *par):

  all_tau, all_age, _, _, filename_0_galaxy, _, _ = dict_modelsfiles
  _, _, GALAXYFdict, _, _, EBVgal_array= dict_modelfluxes

  # calling parameters from Emcee
  tau, agelog, _, _, _ ,_, GA,_, _, GAebv= par[0:10]
 
  age = 10**agelog

  GA_filename = model.pick_GALAXY_template(tau, age, filename_0_galaxy, all_tau, all_age)
  EBV_gal_0 = model.pick_EBV_grid(EBVgal_array,GAebv)
  EBV_gal = (  str(int(EBV_gal_0)) if  float(EBV_gal_0).is_integer() else str(EBV_gal_0))


  try:
    bands, gal_Fnu = GALAXYFdict[GA_filename, EBV_gal]
  except ValueError:
    print 'Error: Dictionary does not contain key of ', GA_filename, EBV_gal, ' or the E(B-V) grid or the DICTIONARIES_AGNfitter file does not match when the one used in PARAMETERSPACE_AGNfitter/ymodel.py'
  
  gal_Fnu *= 1e-18 * 10**(GA)


  return bands, gal_Fnu
Beispiel #3
0
def fluxes_arrays(data_nus, catalog, sourceline, dict_modelsfiles, filterdict, chain, Nrealizations, path, dict_modelfluxes, mock_input):
    """
	This function constructs the luminosities arrays for many realizations from the parameter values

	## inputs:
	- v: frequency 
	- catalog file name
	- sourcelines

	## output:
	- dictionary P with all parameter characteristics
    """
 


#LIST OF OUTPUT

    SBFnu_list = []
    BBFnu_list = []
    GAFnu_list= []
    TOFnu_list = []
    TOTALFnu_list = []
    BBFnu_deredd_list = []
    filtered_modelpoints_list = []


    STARBURSTFdict , BBBFdict, GALAXYFdict, TORUSFdict, EBVbbb_array, EBVgal_array = dict_modelfluxes


    all_tau, all_age, all_nh, all_irlum, filename_0_galaxy, filename_0_starburst, filename_0_torus = dict_modelsfiles


    nsample, npar = chain.shape
    source = NAME(catalog, sourceline)

#CALL PARAMETERS FROM INPUT

    itau, iage, inh, iirlum, iSB ,iBB, iGA ,iTO, iBBebv, iGAebv= mock_input[sourceline] #calling parameter
    

#CALL PARAMETERS OF OUTPUT
    tau, agelog, nh, irlum, SB ,BB, GA,TO, BBebv0, GAebv0= [ chain[:,i] for i in range(npar)] #calling parameters


    
    z = REDSHIFT(catalog, sourceline)
    age = 10**agelog

    agelog = np.log10(age)	
    iagelog = np.log10(iage)

#LEFT PLOT

    for inp in range(1):
        

        SB_filename = path + model.pick_STARBURST_template(iirlum, filename_0_starburst, all_irlum)
        GA_filename = path + model.pick_GALAXY_template(itau, iage, filename_0_galaxy, all_tau, all_age)
        TO_filename = path + model.pick_TORUS_template(inh, all_nh, filename_0_torus)
        BB_filename = path + model.pick_BBB_template()

        all_model_nus = np.arange(12, 16, 0.001)#np.log10(dicts.stack_all_model_nus(filename_0_galaxy, filename_0_starburst, filename_0_torus, z, path ))  

        gal_nu, gal_nored_Fnu = model.GALAXY_read_4plotting( GA_filename, all_model_nus)
        gal_nu, gal_Fnu_red = model.GALAXY_nf2( gal_nu, gal_nored_Fnu, iGAebv )
        all_gal_nus, all_gal_Fnus =gal_nu, gal_Fnu_red

        sb_nu0, sb_Fnu0 = model.STARBURST_read_4plotting(SB_filename, all_model_nus)
        all_sb_nus, all_sb_Fnus = sb_nu0, sb_Fnu0

        bbb_nu, bbb_nored_Fnu = model.BBB_read_4plotting(BB_filename, all_model_nus)
        all_bbb_nus, all_bbb_Fnus = model.BBB_nf2(bbb_nu, bbb_nored_Fnu, iBBebv, z )
        all_bbb_nus, all_bbb_Fnus_deredd =all_bbb_nus, bbb_nored_Fnu

        tor_nu0, tor_Fnu0 = model.TORUS_read_4plotting(TO_filename, z, all_model_nus)
        all_tor_nus, all_tor_Fnus = tor_nu0, tor_Fnu0

        par_input = itau, iagelog, inh, iirlum, iSB ,iBB, iGA ,iTO, iBBebv, iGAebv


        ifiltered_modelpoints = parspace.ymodel(data_nus, z, dict_modelsfiles, dict_modelfluxes, *par_input)


        if len(all_gal_nus)==len(all_sb_nus) and len(all_sb_nus)==len(all_bbb_nus) and len(all_tor_nus)==len(all_bbb_nus) :
            nu= all_gal_nus

            all_sb_Fnus_norm = all_sb_Fnus /1e20
            all_bbb_Fnus_norm = all_bbb_Fnus / 1e60
            all_gal_Fnus_norm = all_gal_Fnus/ 1e18
            all_tor_Fnus_norm = all_tor_Fnus/  1e-40
            all_bbb_Fnus_deredd_norm = all_bbb_Fnus_deredd / 1e60


            iSBFnu =   all_sb_Fnus_norm *10**float(iSB) 
            iBBFnu =  all_bbb_Fnus_norm * 10**float(iBB) 
            iGAFnu =   all_gal_Fnus_norm * 10**float(iGA) 
            iTOFnu =   all_tor_Fnus_norm * 10**float(iTO)# /(1+z)
            iBBFnu_deredd = all_bbb_Fnus_deredd_norm* 10**float(iBB)

            iTOTALFnu =    iSBFnu + iBBFnu + iGAFnu + iTOFnu
         

#RIGHT PLOT
    			
    for gi in range(Nrealizations): #LOOP for a 100th part of the realizations

        g= gi*(nsample/Nrealizations)



        BBebv1 = model.pick_EBV_grid(EBVbbb_array, BBebv0[g])
        BBebv2 = (  str(int(BBebv1)) if  float(BBebv1).is_integer() else str(BBebv1))
        GAebv1 = model.pick_EBV_grid(EBVgal_array,GAebv0[g])
        GAebv2 = (  str(int(GAebv1)) if  float(GAebv1).is_integer() else str(GAebv1))
    

        SB_filename = path + model.pick_STARBURST_template(irlum[g], filename_0_starburst, all_irlum)
        GA_filename = path + model.pick_GALAXY_template(tau[g], age[g], filename_0_galaxy, all_tau, all_age)
        TO_filename = path + model.pick_TORUS_template(nh[g], all_nh, filename_0_torus)
        BB_filename = path + model.pick_BBB_template()


        all_model_nus = np.arange(12, 16, 0.001)#np.log10(dicts.stack_all_model_nus(filename_0_galaxy, filename_0_starburst, filename_0_torus, z, path ))  
        gal_nu, gal_nored_Fnu = model.GALAXY_read_4plotting( GA_filename, all_model_nus)
        gal_nu, gal_Fnu_red = model.GALAXY_nf2( gal_nu, gal_nored_Fnu, float(GAebv2))
        all_gal_nus, all_gal_Fnus =gal_nu, gal_Fnu_red


        sb_nu0, sb_Fnu0 = model.STARBURST_read_4plotting(SB_filename, all_model_nus)
        all_sb_nus, all_sb_Fnus = sb_nu0, sb_Fnu0

        bbb_nu, bbb_nored_Fnu = model.BBB_read_4plotting(BB_filename, all_model_nus)
        bbb_nu0, bbb_Fnu_red = model.BBB_nf2(bbb_nu, bbb_nored_Fnu, float(BBebv2), z )
        all_bbb_nus, all_bbb_Fnus = bbb_nu0, bbb_Fnu_red
        all_bbb_nus, all_bbb_Fnus_deredd = bbb_nu0, bbb_nored_Fnu

        tor_nu0, tor_Fnu0 = model.TORUS_read_4plotting(TO_filename, z, all_model_nus)
        all_tor_nus, all_tor_Fnus = tor_nu0, tor_Fnu0

        par1 = tau[g], agelog[g], nh[g], irlum[g], SB[g] ,BB[g], GA[g] ,TO[g], float(BBebv2), float(GAebv2)
        filtered_modelpoints = parspace.ymodel(data_nus, z, dict_modelsfiles, dict_modelfluxes, *par1)


        if len(all_gal_nus)==len(all_sb_nus) and len(all_sb_nus)==len(all_bbb_nus) and len(all_tor_nus)==len(all_bbb_nus) :
            nu= all_gal_nus

           
            all_sb_Fnus_norm = all_sb_Fnus /1e20
            all_bbb_Fnus_norm = all_bbb_Fnus / 1e60
            all_gal_Fnus_norm = all_gal_Fnus/ 1e18
            all_tor_Fnus_norm = all_tor_Fnus/  1e-40
            all_bbb_Fnus_deredd_norm = all_bbb_Fnus_deredd / 1e60


            SBFnu =   all_sb_Fnus_norm *10**float(SB[g]) 
            BBFnu =  all_bbb_Fnus_norm * 10**float(BB[g]) 
            GAFnu =   all_gal_Fnus_norm * 10**float(GA[g])
            TOFnu =   all_tor_Fnus_norm * 10**float(TO[g]) #/(1+z)
            BBFnu_deredd = all_bbb_Fnus_deredd_norm* 10**float(BB[g])

            TOTALFnu =    SBFnu + BBFnu + GAFnu + TOFnu
            SBFnu_list.append(SBFnu)
            BBFnu_list.append(BBFnu)
            GAFnu_list.append(GAFnu)
            TOFnu_list.append(TOFnu)
            TOTALFnu_list.append(TOTALFnu)
            BBFnu_deredd_list.append(BBFnu_deredd)
            filtered_modelpoints_list.append(filtered_modelpoints)


    	else: 
	    	print 'Error:'
	    	print 'The frequencies in the MODELdict_plot dictionaries are not equal for all models and could not be added.'
	    	print 'Check that the dictionary_plot.py stacks all frequencies (bands+galaxy+bbb+sb+torus) properly.'	


	       
    SBFnu_array = np.array(SBFnu_list)
    BBFnu_array = np.array(BBFnu_list)
    GAFnu_array = np.array(GAFnu_list)
    TOFnu_array = np.array(TOFnu_list)
    TOTALFnu_array = np.array(TOTALFnu_list)
    BBFnu_array_deredd = np.array(BBFnu_deredd_list)	
    filtered_modelpoints = np.array(filtered_modelpoints_list)
    

    FLUXES4plotting = (SBFnu_array, BBFnu_array, GAFnu_array, TOFnu_array, TOTALFnu_array,BBFnu_array_deredd, iSBFnu, iBBFnu, iGAFnu, iTOFnu, iTOTALFnu,iBBFnu_deredd)


    return all_model_nus, FLUXES4plotting, filtered_modelpoints, ifiltered_modelpoints
def ymodel(data_nus, z, dict_modelsfiles, dict_modelfluxes, *par):

  """
	This function constructs the model from the parameter values

	## inputs:
	- v: frequency 
	- catalog file name
	- sourcelines

	## output:
	- dictionary P with all parameter characteristics

	## comments:
	- 

	## bugs:

  """

  all_tau, all_age, all_nh, all_irlum, filename_0_galaxy, filename_0_starburst, filename_0_torus = dict_modelsfiles
  STARBURSTFdict , BBBFdict, GALAXYFdict, TORUSFdict, EBVbbb_array, EBVgal_array= dict_modelfluxes


  # Call parameters from Emcee
  tau, agelog, nh, irlum, SB ,BB, GA,TO, BBebv, GAebv= par[0:10]
  age = 10**agelog


  # Pick templates for physical parameters
  SB_filename = model.pick_STARBURST_template(irlum, filename_0_starburst, all_irlum)
  GA_filename = model.pick_GALAXY_template(tau, age, filename_0_galaxy, all_tau, all_age)
  TOR_filename = model.pick_TORUS_template(nh, all_nh, filename_0_torus)
  BB_filename = 'models/BBB/richardsbbb.dat'

  EBV_bbb_0 = model.pick_EBV_grid(EBVbbb_array, BBebv)
  EBV_bbb = (  str(int(EBV_bbb_0)) if  float(EBV_bbb_0).is_integer() else str(EBV_bbb_0))
  EBV_gal_0 = model.pick_EBV_grid(EBVgal_array,GAebv)
  EBV_gal = (  str(int(EBV_gal_0)) if  float(EBV_gal_0).is_integer() else str(EBV_gal_0))


  try:	
        bands, gal_Fnu = GALAXYFdict[GA_filename, EBV_gal]
	bands, sb_Fnu= STARBURSTFdict[SB_filename] 
	bands, bbb_Fnu = BBBFdict[BB_filename, EBV_bbb]	
	bands, tor_Fnu= TORUSFdict[TOR_filename]
  except ValueError:
    print 'Error: Dictionary does not contain TORUS file:'+TOR_filename

  sb_Fnu *= 10**(SB)*1e-20#e50  
  bbb_Fnu *= 10**(BB)*1e-60#e90
  gal_Fnu *= 10**(GA)*1e-18
  tor_Fnu *=  10**(TO)*1e40


  # Sum components

  lum = sb_Fnu+ bbb_Fnu+ gal_Fnu + tor_Fnu

  lum = lum.reshape((np.size(lum),))	

  return lum