Composite Models and depending pars

from jetset.jet_model import Jet
from jetset.plot_sedfit import PlotSED
from jetset.model_manager import FitModel

Composite models allow to combine together different models, such as Jet, and templates, including additive or multiplicative models, and give to the user the possibility to define the functional form of the model composition using a very simple and intuitive form such as: .. code-block:: python

‘jet1+jet2’*Franceschini_2008

that sums two jet models SEDs, and apply to both of them the Franceschini_2008 EBL absorption. dsad Building composite models it is very easy. Composite models are handled by the FitModel class, as shown by the following examples.

Combine a Jet model with the EBL model (Multiplicative case)

We start by combining a Jet model with the EBL absorption model, i.e. a multiplicative model. First, we define our Jet model

from jetset.jet_model import Jet
my_jet=Jet(electron_distribution='lppl',name='jet_flaring')

Second, we define the EBL model, and we use in this case the Franceschini_2008 model ( read the section EBL for more info regarding the EBL models)

from jetset.template_2Dmodel import EBLAbsorptionTemplate
ebl_franceschini=EBLAbsorptionTemplate.from_name('Franceschini_2008')

Now we add the components models to the the FitModel class, using the FitModel.add_component() method

composite_model=FitModel(nu_size=500,name='EBL corrected')
composite_model.add_component(my_jet)
composite_model.add_component(ebl_franceschini)
/Users/orion/anaconda3/envs/jetset/lib/python3.8/site-packages/jetset/model_manager.py:147: UserWarning: no cosmology defined, using default FlatLambdaCDM(name="Planck13", H0=67.8 km / (Mpc s), Om0=0.307, Tcmb0=2.725 K, Neff=3.05, m_nu=[0.   0.   0.06] eV, Ob0=0.0483)
  warnings.warn('no cosmology defined, using default %s'%self.cosmo)

the waring message is just telling that you are not passing any specific cosmology model to the FitModel class, so it is using a default one

composite_model.show_pars()
Table length=13
model namenamepar typeunitsvalphys. bound. minphys. bound. maxlogfrozen
jet_flaringRregion_sizecm5.000000e+151.000000e+031.000000e+30FalseFalse
jet_flaringR_Hregion_positioncm1.000000e+170.000000e+00--FalseTrue
jet_flaringBmagnetic_fieldgauss1.000000e-010.000000e+00--FalseFalse
jet_flaringNH_cold_to_rel_ecold_p_to_rel_e_ratio1.000000e-010.000000e+00--FalseTrue
jet_flaringbeam_objbeaminglorentz-factor*1.000000e+011.000000e-04--FalseFalse
jet_flaringz_cosmredshift1.000000e-010.000000e+00--FalseFalse
jet_flaringgminlow-energy-cut-offlorentz-factor*2.000000e+001.000000e+001.000000e+09FalseFalse
jet_flaringgmaxhigh-energy-cut-offlorentz-factor*1.000000e+061.000000e+001.000000e+15FalseFalse
jet_flaringNemitters_density1 / cm31.000000e+020.000000e+00--FalseFalse
jet_flaringgamma0_log_parabturn-over-energylorentz-factor*1.000000e+041.000000e+001.000000e+09FalseFalse
jet_flaringsLE_spectral_slope2.000000e+00-1.000000e+011.000000e+01FalseFalse
jet_flaringrspectral_curvature4.000000e-01-1.500000e+011.500000e+01FalseFalse
Franceschini_2008z_cosmredshift1.000000e+000.000000e+00--FalseTrue

Since, both the Jet model the EBL share the same parameter, i.e. the redshift, we link the two parameters

composite_model.link_par(par_name='z_cosm', from_model=my_jet.name, to_model='Franceschini_2008')
==> par: z_cosm from model: jet_flaring linked to same parameter in model Franceschini_2008
composite_model.show_pars()
Table length=13
model namenamepar typeunitsvalphys. bound. minphys. bound. maxlogfrozen
jet_flaringRregion_sizecm5.000000e+151.000000e+031.000000e+30FalseFalse
jet_flaringR_Hregion_positioncm1.000000e+170.000000e+00--FalseTrue
jet_flaringBmagnetic_fieldgauss1.000000e-010.000000e+00--FalseFalse
jet_flaringNH_cold_to_rel_ecold_p_to_rel_e_ratio1.000000e-010.000000e+00--FalseTrue
jet_flaringbeam_objbeaminglorentz-factor*1.000000e+011.000000e-04--FalseFalse
jet_flaringz_cosm(L,Franceschini_2008)redshift------FalseTrue
jet_flaringgminlow-energy-cut-offlorentz-factor*2.000000e+001.000000e+001.000000e+09FalseFalse
jet_flaringgmaxhigh-energy-cut-offlorentz-factor*1.000000e+061.000000e+001.000000e+15FalseFalse
jet_flaringNemitters_density1 / cm31.000000e+020.000000e+00--FalseFalse
jet_flaringgamma0_log_parabturn-over-energylorentz-factor*1.000000e+041.000000e+001.000000e+09FalseFalse
jet_flaringsLE_spectral_slope2.000000e+00-1.000000e+011.000000e+01FalseFalse
jet_flaringrspectral_curvature4.000000e-01-1.500000e+011.500000e+01FalseFalse
Franceschini_2008z_cosm(M)redshift1.000000e+000.000000e+00--FalseTrue

As you can see, now the paramter z_cosm in jet_flaring is the master parameter (flagged by the M in parenthesis), and the one belonging to the Franceschini_2008 component is the linked one (flagged by the L in parenthesis).

Setting parameters

Note

with the new implementation of composite model (FitModel class) to set parameters you have to specify the model component, this is different from versions<1.2.0

These methods are alternative and equivalent ways to set a parameter in a composite model:

  1. accessing the model component member of the

  2. using set_par and passing as first argument the model component name

  3. using set_par and passing as first argument the model component object

#a
composite_model.Franceschini_2008.parameters.z_cosm.val=0.1
#b
composite_model.set_par('Franceschini_2008','z_cosm',0.1)
#c
composite_model.set_par(ebl_franceschini,'z_cosm',0.1)

And now, we can define the functional form of the model composition, just by writing the mathematical expression as a string, using the model names reported in the model description table, and that’s it!

composite_model.show_model_components()
--------------------------------------------------------------------------------
Composite model description
--------------------------------------------------------------------------------
name: EBL corrected
type: composite_model
components models:
 -model name: jet_flaring model type: jet
 -model name: Franceschini_2008 model type: table2D

--------------------------------------------------------------------------------
composite_model.composite_expr='jet_flaring*Franceschini_2008'
composite_model.jet_flaring.IC_nu_size=150
composite_model.eval()
p=composite_model.plot_model()
../../../_images/Composite_model_24_0.png
composite_model.save_model('composite.pkl')
cm=FitModel.load_model('composite.pkl')
==> par: z_cosm from model: jet_flaring linked to same parameter in model Franceschini_2008

Sum of two jets (steady and flaring) and application of the EBL absorption to both (Multiplicative and additive)

Assume that now we want to sum to jet models (a steady and flaring component) and apply to both of them the EBL absorption.

composite_model=FitModel(nu_size=500,name='EBL corrected flaring+steady')
composite_model.add_component(my_jet)
composite_model.add_component(ebl_franceschini)
/Users/orion/anaconda3/envs/jetset/lib/python3.8/site-packages/jetset/model_manager.py:147: UserWarning: no cosmology defined, using default FlatLambdaCDM(name="Planck13", H0=67.8 km / (Mpc s), Om0=0.307, Tcmb0=2.725 K, Neff=3.05, m_nu=[0.   0.   0.06] eV, Ob0=0.0483)
  warnings.warn('no cosmology defined, using default %s'%self.cosmo)
steady_jet=Jet(electron_distribution='plc',name='steady_jet')
composite_model.add_component(steady_jet)
composite_model.show_model_components()
--------------------------------------------------------------------------------
Composite model description
--------------------------------------------------------------------------------
name: EBL corrected flaring+steady
type: composite_model
components models:
 -model name: jet_flaring model type: jet
 -model name: Franceschini_2008 model type: table2D
 -model name: steady_jet model type: jet

--------------------------------------------------------------------------------

now we link the same parameter z_cosm from the steady_jet to the same master parameter used for the EBL model, i.e. to the jet_flaring model

composite_model.link_par(par_name='z_cosm',from_model=['steady_jet'],to_model='Franceschini_2008')
==> par: z_cosm from model: steady_jet linked to same parameter in model Franceschini_2008
composite_model.show_pars()
Table length=24
model namenamepar typeunitsvalphys. bound. minphys. bound. maxlogfrozen
jet_flaringRregion_sizecm5.000000e+151.000000e+031.000000e+30FalseFalse
jet_flaringR_Hregion_positioncm1.000000e+170.000000e+00--FalseTrue
jet_flaringBmagnetic_fieldgauss1.000000e-010.000000e+00--FalseFalse
jet_flaringNH_cold_to_rel_ecold_p_to_rel_e_ratio1.000000e-010.000000e+00--FalseTrue
jet_flaringbeam_objbeaminglorentz-factor*1.000000e+011.000000e-04--FalseFalse
jet_flaringz_cosm(L,Franceschini_2008)redshift------FalseTrue
jet_flaringgminlow-energy-cut-offlorentz-factor*2.000000e+001.000000e+001.000000e+09FalseFalse
jet_flaringgmaxhigh-energy-cut-offlorentz-factor*1.000000e+061.000000e+001.000000e+15FalseFalse
jet_flaringNemitters_density1 / cm31.000000e+020.000000e+00--FalseFalse
jet_flaringgamma0_log_parabturn-over-energylorentz-factor*1.000000e+041.000000e+001.000000e+09FalseFalse
jet_flaringsLE_spectral_slope2.000000e+00-1.000000e+011.000000e+01FalseFalse
jet_flaringrspectral_curvature4.000000e-01-1.500000e+011.500000e+01FalseFalse
Franceschini_2008z_cosm(M)redshift1.000000e-010.000000e+00--FalseTrue
steady_jetRregion_sizecm5.000000e+151.000000e+031.000000e+30FalseFalse
steady_jetR_Hregion_positioncm1.000000e+170.000000e+00--FalseTrue
steady_jetBmagnetic_fieldgauss1.000000e-010.000000e+00--FalseFalse
steady_jetNH_cold_to_rel_ecold_p_to_rel_e_ratio1.000000e-010.000000e+00--FalseTrue
steady_jetbeam_objbeaminglorentz-factor*1.000000e+011.000000e-04--FalseFalse
steady_jetz_cosm(L,Franceschini_2008)redshift------FalseTrue
steady_jetgminlow-energy-cut-offlorentz-factor*2.000000e+001.000000e+001.000000e+09FalseFalse
steady_jetgmaxhigh-energy-cut-offlorentz-factor*1.000000e+061.000000e+001.000000e+15FalseFalse
steady_jetNemitters_density1 / cm31.000000e+020.000000e+00--FalseFalse
steady_jetgamma_cutturn-over-energylorentz-factor*1.000000e+041.000000e+001.000000e+09FalseFalse
steady_jetpLE_spectral_slope2.000000e+00-1.000000e+011.000000e+01FalseFalse
composite_model.steady_jet.IC_nu_size=150
composite_model.composite_expr='(jet_flaring + steady_jet) * Franceschini_2008'
composite_model.eval()
p=composite_model.plot_model()
p.setlim(y_max=1E-12)
../../../_images/Composite_model_35_0.png
composite_model.save_model('composite.pkl')
cm=FitModel.load_model('composite.pkl')
==> par: z_cosm from model: jet_flaring linked to same parameter in model Franceschini_2008
==> par: z_cosm from model: steady_jet linked to same parameter in model Franceschini_2008
cm.show_pars()
Table length=24
model namenamepar typeunitsvalphys. bound. minphys. bound. maxlogfrozen
jet_flaringgminlow-energy-cut-offlorentz-factor*2.000000e+001.000000e+001.000000e+09FalseFalse
jet_flaringgmaxhigh-energy-cut-offlorentz-factor*1.000000e+061.000000e+001.000000e+15FalseFalse
jet_flaringNemitters_density1 / cm31.000000e+020.000000e+00--FalseFalse
jet_flaringgamma0_log_parabturn-over-energylorentz-factor*1.000000e+041.000000e+001.000000e+09FalseFalse
jet_flaringsLE_spectral_slope2.000000e+00-1.000000e+011.000000e+01FalseFalse
jet_flaringrspectral_curvature4.000000e-01-1.500000e+011.500000e+01FalseFalse
jet_flaringRregion_sizecm5.000000e+151.000000e+031.000000e+30FalseFalse
jet_flaringR_Hregion_positioncm1.000000e+170.000000e+00--FalseTrue
jet_flaringBmagnetic_fieldgauss1.000000e-010.000000e+00--FalseFalse
jet_flaringNH_cold_to_rel_ecold_p_to_rel_e_ratio1.000000e-010.000000e+00--FalseTrue
jet_flaringbeam_objbeaminglorentz-factor*1.000000e+011.000000e-04--FalseFalse
jet_flaringz_cosm(L,Franceschini_2008)redshift------FalseTrue
Franceschini_2008z_cosm(M)redshift1.000000e-010.000000e+00--FalseTrue
steady_jetgminlow-energy-cut-offlorentz-factor*2.000000e+001.000000e+001.000000e+09FalseFalse
steady_jetgmaxhigh-energy-cut-offlorentz-factor*1.000000e+061.000000e+001.000000e+15FalseFalse
steady_jetNemitters_density1 / cm31.000000e+020.000000e+00--FalseFalse
steady_jetgamma_cutturn-over-energylorentz-factor*1.000000e+041.000000e+001.000000e+09FalseFalse
steady_jetpLE_spectral_slope2.000000e+00-1.000000e+011.000000e+01FalseFalse
steady_jetRregion_sizecm5.000000e+151.000000e+031.000000e+30FalseFalse
steady_jetR_Hregion_positioncm1.000000e+170.000000e+00--FalseTrue
steady_jetBmagnetic_fieldgauss1.000000e-010.000000e+00--FalseFalse
steady_jetNH_cold_to_rel_ecold_p_to_rel_e_ratio1.000000e-010.000000e+00--FalseTrue
steady_jetbeam_objbeaminglorentz-factor*1.000000e+011.000000e-04--FalseFalse
steady_jetz_cosm(L,Franceschini_2008)redshift------FalseTrue