Temporal evolution, two zones, cooling+acc+adb exp

import warnings
warnings.filterwarnings('ignore')
import matplotlib.pyplot as plt
import numpy as np
import jetset
print('tested on jetset',jetset.__version__)
tested on jetset 1.2.2

In this tutorial I show how to perform a full acc+radiative+adiabatic expansion simulation. To have full understanding of the analysis presented in this tutorial, it is advised to read the paper Tramacere et al (2022) [Tramacere2022].

We load the model of the flare simulated in :ref:temp_ev_two_zone_cooling_acc. And the we evolve the radiative region under the effect of radiative plus adiabatic cooling

from jetset.jet_timedep import JetTimeEvol

temp_ev_acc=JetTimeEvol.load_model('two_zone_rad_acc.pkl')
temp_ev_acc.show_model()
--------------------------------------------------------------------------------
JetTimeEvol model description
--------------------------------------------------------------------------------

physical setup:

--------------------------------------------------------------------------------
Table length=29
namepar typevalunitsval*units*log
delta ttime5.000000e+01s0.00029979245799999996R/cFalse
log. samplingtime0.000000e+00NoneFalse
R/ctime1.667820e+05s1.0R/cFalse
IC coolingoffNoneFalse
Sync coolingonNoneFalse
Adiab. coolingonNoneFalse
Reg. expansionoffNoneFalse
Diff coeff6.666667e-06s-1NoneFalse
Acc coeff4.000000e-05s-1NoneFalse
Diff index2.000000e+00NoneFalse
Acc index1.000000e+00s-1NoneFalse
Tesc acctime5.003461e+04s3.0R_acc/cFalse
Eacc maxenergy4.000000e+60ergNoneFalse
Tesc radtime1.667820e+65s1e+60R/cFalse
Delta R accaccelerator_width5.000000e+14cmNoneFalse
B accmagnetic field2.000000e-01cmNoneFalse
R_rad rad startregion_position5.000000e+15cmNoneFalse
R_H rad startregion_position1.000000e+17cmNoneFalse
T_A0=1/ACC_COEFFtime2.500000e+04s0.149896229R/cFalse
T_D0=1/DIFF_COEFFtime1.500000e+05s0.899377374R/cFalse
T_DA0=1/(2*DIFF_COEFF)time7.500000e+04s0.449688687R/cFalse
gamma Lambda Turb. max1.173358e+11NoneFalse
gamma Lambda Coher. max1.173358e+10NoneFalse
gamma eq Syst. Acc (synch. cool)7.832383e+05NoneFalse
gamma eq Diff. Acc (synch. cool)1.309535e+05NoneFalse
T cooling(gamma_eq=gamma_eq_Diff)1.477242e+05sNoneFalse
T cooling(gamma_eq=gamma_eq_Sys)2.469874e+04sNoneFalse
T min. synch. cooling1.934500e+02sNoneFalse
L inj (electrons)injected lum.5.000000e+39erg/sNoneFalse
model parameters:

--------------------------------------------------------------------------------
Table length=30
model namenamepar typeunitsvalphys. bound. minphys. bound. maxlogfrozen
jet_time_evdurationtime_grids1.000000e+060.000000e+00--FalseTrue
jet_time_evgmin_gridgamma_grid1.000000e+000.000000e+00--FalseTrue
jet_time_evgmax_gridgamma_grid1.000000e+080.000000e+00--FalseTrue
jet_time_evgamma_grid_sizegamma_grid1.500000e+030.000000e+00--FalseTrue
jet_time_evTStart_Acctime_grids0.000000e+000.000000e+00--FalseTrue
jet_time_evTStop_Acctime_grids1.000000e+050.000000e+00--FalseTrue
jet_time_evTStart_Injtime_grids0.000000e+000.000000e+00--FalseTrue
jet_time_evTStop_Injtime_grids1.000000e+050.000000e+00--FalseTrue
jet_time_evT_esc_accescape_time(R_acc/c)*3.000000e+00----FalseTrue
jet_time_evEsc_Index_accfp_coeff_index0.000000e+00----FalseTrue
jet_time_evt_D0acceleration_times1.500000e+050.000000e+00--FalseTrue
jet_time_evt_A0acceleration_times2.500000e+040.000000e+00--FalseTrue
jet_time_evDiff_Indexfp_coeff_indexs2.000000e+000.000000e+00--FalseTrue
jet_time_evAcc_Indexfp_coeff_index1.000000e+00----FalseTrue
jet_time_evDelta_R_accaccelerator_widthcm5.000000e+140.000000e+00--FalseTrue
jet_time_evB_accmagnetic_fieldG2.000000e-010.000000e+00--FalseTrue
jet_time_evE_acc_maxacc_energyerg4.000000e+600.000000e+00--FalseTrue
jet_time_evLambda_max_Turbturbulence_scalecm1.000000e+150.000000e+00--FalseTrue
jet_time_evLambda_choer_Turb_factorturbulence_scalecm1.000000e-010.000000e+00--FalseTrue
jet_time_evT_esc_radescape_time(R/c)*1.000000e+60----FalseTrue
jet_time_evEsc_Index_radfp_coeff_index0.000000e+00----FalseTrue
jet_time_evR_rad_startregion_sizecm5.000000e+150.000000e+00--FalseTrue
jet_time_evR_H_rad_startregion_positioncm1.000000e+170.000000e+00--FalseTrue
jet_time_evm_Bmagnetic_field_index1.000000e+001.000000e+002.000000e+00FalseTrue
jet_time_evt_jet_expexp_start_times1.000000e+050.000000e+00--FalseTrue
jet_time_evbeta_exp_Rbeta_expansionv/c*1.000000e+000.000000e+001.000000e+00FalseTrue
jet_time_evB_radmagnetic_fieldG2.000000e-010.000000e+00--FalseTrue
jet_time_evt_sizetime_grid2.000000e+040.000000e+00--FalseTrue
jet_time_evnum_samplestime_ev_output5.000000e+020.000000e+00--FalseTrue
jet_time_evL_injinj_luminosityerg / s5.000000e+390.000000e+00--FalseTrue

here we set some relevant parameters that will be described in detail in the next version of the documentation

temp_ev_acc.plot_time_profile()
<jetset.plot_sedfit.PlotTempEvDiagram at 0x7fef1f7baf10>
../../../_images/Temp_Ev_two_zones_acc_and_cooling_adb_exp_11_1.png

Particle spectrum in the radiative region

p=temp_ev_acc.plot_tempev_emitters(region='rad',loglog=False,energy_unit='gamma',pow=0)
p.ax.axvline(temp_ev_acc.temp_ev.gamma_eq_t_A, ls='--')
p.ax.axvline(temp_ev_acc.temp_ev.gamma_eq_t_DA, ls='--')
p.setlim(x_max=1E7,x_min=1,y_min=1E-18,y_max=100)
../../../_images/Temp_Ev_two_zones_acc_and_cooling_adb_exp_13_0.png

SEDs in the radiation region

p=temp_ev_acc.plot_tempev_model(region='rad',sed_data=None, use_cached = True)
p.setlim(y_min=1E-18,x_min=1E7)
../../../_images/Temp_Ev_two_zones_acc_and_cooling_adb_exp_15_0.png

We generate a lightcurve in the range nu1=2.4E22 Hz, nu2=7.2E25 Hz, without the effect of the light crossing time, in the observer frame

lg=temp_ev_acc.rad_region.make_lc(nu1=2.4E22,nu2=7.2E25,name='gamma',eval_cross_time=False,delta_t_out=100,use_cached=True,frame='obs')
plt.plot(lg['time'],lg['flux'])
plt.xlabel('time (%s)'%lg['time'].unit)
plt.ylabel('flux (%s)'%lg['flux'].unit)
Text(0, 0.5, 'flux (erg / (cm2 s))')
../../../_images/Temp_Ev_two_zones_acc_and_cooling_adb_exp_18_1.png

We generate a lightcurve in the range nu1=2.4E22 Hz, nu2=7.2E25 Hz, with the effect of the light crossing time, in the observer frame

lg_cross=temp_ev_acc.rad_region.make_lc(nu1=2.4E22,nu2=7.2E25,name='gamma',eval_cross_time=True,delta_t_out=100,use_cached=True,frame='obs',cross_time_slices=100)
plt.plot(lg['time'],lg['flux'])
plt.plot(lg_cross['time'],lg_cross['flux'])

plt.xlabel('time (%s)'%lg['time'].unit)
plt.ylabel('flux (%s)'%lg['flux'].unit)
Text(0, 0.5, 'flux (erg / (cm2 s))')
../../../_images/Temp_Ev_two_zones_acc_and_cooling_adb_exp_21_1.png
lr_1=temp_ev_acc.rad_region.make_lc(nu1=1E10,name='1E10 Hz',eval_cross_time=False,delta_t_out=100,use_cached=True,frame='obs')
lr_2=temp_ev_acc.rad_region.make_lc(nu1=5E9,name='1E9 Hz',eval_cross_time=False,delta_t_out=100,use_cached=True,frame='obs')
plt.plot(lr_1['time'],lr_1['flux']/lr_1['flux'].max())
plt.plot(lr_2['time'],lr_2['flux']/lr_2['flux'].max())

plt.xlabel('time (%s)'%lr_1['time'].unit)
Text(0.5, 0, 'time (s)')
../../../_images/Temp_Ev_two_zones_acc_and_cooling_adb_exp_23_1.png
lr_1_cross=temp_ev_acc.rad_region.make_lc(nu1=1E10,name='gamma',eval_cross_time=True,delta_t_out=100,use_cached=True,frame='obs',cross_time_slices=100)
lr_2_cross=temp_ev_acc.rad_region.make_lc(nu1=5E9,name='gamma',eval_cross_time=True,delta_t_out=100,use_cached=True,frame='obs',cross_time_slices=100)
plt.plot(lr_1_cross['time'],lr_1_cross['flux']/lr_1_cross['flux'].max())
plt.plot(lr_2_cross['time'],lr_2_cross['flux']/lr_2_cross['flux'].max())

plt.xlabel('time (%s)'%lr_1_cross['time'].unit)
Text(0.5, 0, 'time (s)')
../../../_images/Temp_Ev_two_zones_acc_and_cooling_adb_exp_25_1.png

Expanding the radiative region

We now plug the radiative region from temp_ev_acc to new model with adiabatic expansion

the following two functions define an estimate of the total extent of the simulation to follow the expansion

def delta_t_est(t_exp,R0,beta_exp):
    return t_exp+R0/(beta_exp*3E10)

def t_dec_est(R0,a,beta_exp):
    return ((R0+beta_exp*3E10)*np.power(beta_exp*3E10,a))

we set the initial radius equal to the radius of the radiative region of the temp_ev_acc model

t_exp=1E7
beta_exp=0.3
R0=temp_ev_acc.rad_region.jet.parameters.R.val
duration=delta_t_est(t_exp,R0,beta_exp)+10*t_dec_est(R0,-1,beta_exp)

we build the temp_ev_expansion expansion model

from jetset.jet_timedep import JetTimeEvol
temp_ev_expansion=JetTimeEvol(jet_rad=temp_ev_acc.rad_region.jet,inplace=True,only_radiation=True,Q_inj=None)

temp_ev_expansion.rad_region.jet.nu_min=1E8
T_SIZE=np.int(duration/1000)
NUM_SET=np.int(T_SIZE)
NUM_SET=min(5000,NUM_SET)


temp_ev_expansion.parameters.TStart_Inj.val=-0
temp_ev_expansion.parameters.TStop_Inj.val=-0

temp_ev_expansion.parameters.duration.val=duration
temp_ev_expansion.parameters.T_esc_rad.val=1E60
temp_ev_expansion.parameters.Esc_Index_rad.val=0
temp_ev_expansion.parameters.t_size.val=T_SIZE
temp_ev_expansion.parameters.num_samples.val=NUM_SET


temp_ev_expansion.parameters.gmin_grid.val=1.0
temp_ev_expansion.parameters.gmax_grid.val=1E8
temp_ev_expansion.parameters.gamma_grid_size.val=1500

we set to 'on' the region expansion, and we set the relevant paramters

temp_ev_expansion.region_expansion='on'
temp_ev_expansion.parameters.t_jet_exp.val=t_exp
temp_ev_expansion.parameters.beta_exp_R.val = beta_exp
temp_ev_expansion.parameters.R_rad_start.val = R0
temp_ev_expansion.init_TempEv()
temp_ev_expansion.show_model()
--------------------------------------------------------------------------------
JetTimeEvol model description
--------------------------------------------------------------------------------

physical setup:

--------------------------------------------------------------------------------
Table length=12
namepar typevalunitsval*units*log
delta ttime1.000008e+03s0.005995894232556255R/cFalse
log. samplingtime0.000000e+00NoneFalse
R/ctime1.667820e+05s1.0R/cFalse
IC coolingoffNoneFalse
Sync coolingonNoneFalse
Adiab. coolingonNoneFalse
Reg. expansiononNoneFalse
Tesc radtime1.667820e+65s1e+60R/cFalse
R_rad rad startregion_position5.000000e+15cmNoneFalse
R_H rad startregion_position1.000000e+17cmNoneFalse
beta exp.region_position3.000000e-01v/c8993773740.0 cm / scm/sFalse
T min. synch. cooling1.934500e+02sNoneFalse
model parameters:

--------------------------------------------------------------------------------
Table length=17
model namenamepar typeunitsvalphys. bound. minphys. bound. maxlogfrozen
jet_time_evdurationtime_grids1.611112e+070.000000e+00--FalseTrue
jet_time_evgmin_gridgamma_grid1.000000e+000.000000e+00--FalseTrue
jet_time_evgmax_gridgamma_grid1.000000e+080.000000e+00--FalseTrue
jet_time_evgamma_grid_sizegamma_grid1.500000e+030.000000e+00--FalseTrue
jet_time_evTStart_Injtime_grids0.000000e+000.000000e+00--FalseTrue
jet_time_evTStop_Injtime_grids0.000000e+000.000000e+00--FalseTrue
jet_time_evT_esc_radescape_time(R/c)*1.000000e+60----FalseTrue
jet_time_evEsc_Index_radfp_coeff_index0.000000e+00----FalseTrue
jet_time_evR_rad_startregion_sizecm5.000000e+150.000000e+00--FalseTrue
jet_time_evR_H_rad_startregion_positioncm1.000000e+170.000000e+00--FalseTrue
jet_time_evm_Bmagnetic_field_index1.000000e+001.000000e+002.000000e+00FalseTrue
jet_time_evt_jet_expexp_start_times1.000000e+070.000000e+00--FalseTrue
jet_time_evbeta_exp_Rbeta_expansionv/c*3.000000e-010.000000e+001.000000e+00FalseTrue
jet_time_evB_radmagnetic_fieldG2.000000e-010.000000e+00--FalseTrue
jet_time_evt_sizetime_grid1.611100e+040.000000e+00--FalseTrue
jet_time_evnum_samplestime_ev_output5.000000e+030.000000e+00--FalseTrue
jet_time_evL_injinj_luminosityerg / s1.000000e+390.000000e+00--FalseTrue
temp_ev_expansion.plot_time_profile()
<jetset.plot_sedfit.PlotTempEvDiagram at 0x7fef0d4593a0>
../../../_images/Temp_Ev_two_zones_acc_and_cooling_adb_exp_37_1.png

we set ``do_injection=False`` because we want only to evolve the particle already injected and evolved in the radiative region of the ``temp_ev_acc`` model

setting cache_SEDs_rad=True will generate and cache all the SED at any time of the NUM_SET. This will increase the computational time during the run. Anyhow, will speed up the computation of SEDs and light curves. Moreover, these SEDs will be saved in the model, and will be read if once you will load the model in the future.

temp_ev_expansion.run(cache_SEDs_rad=True,do_injection=False)
temporal evolution running
0%|          | 0/16111 [00:00<?, ?it/s]
temporal evolution completed
caching SED for each saved distribution: start
0%|          | 0/5000 [00:00<?, ?it/s]
caching SED for each saved distribution: done

we now evaluate light curves, and plot the combination of the flare and adiabatic expansion simulations, for both the radio and gamma

lr_1_exp=temp_ev_expansion.rad_region.make_lc(nu1=1E10,name='1E10 Hz',eval_cross_time=False,delta_t_out=100,use_cached=True,frame='obs')
lr_2_exp=temp_ev_expansion.rad_region.make_lc(nu1=5E9,name='1E9 Hz',eval_cross_time=False,delta_t_out=100,use_cached=True,frame='obs')
lr_1_exp['time']+=lr_1['time'][-1]
lr_2_exp['time']+=lr_2['time'][-1]
lg_exp=temp_ev_expansion.rad_region.make_lc(nu1=2.4E22,nu2=7.2E25,name='gamma',eval_cross_time=False,delta_t_out=100,use_cached=True,frame='obs')
lg=temp_ev_acc.rad_region.make_lc(nu1=2.4E22,nu2=7.2E25,name='gamma',eval_cross_time=False,delta_t_out=100,use_cached=True,frame='obs')
lg_exp['time']+=lg['time'][-1]
plt.plot(lr_1['time'],lr_1['flux']/lr_1_exp['flux'].max(),c='b')
plt.plot(lr_2['time'],lr_2['flux']/lr_2_exp['flux'].max(),c='g')

plt.plot(lr_1_exp['time'],lr_1_exp['flux']/lr_1_exp['flux'].max(),label='10 GHz',c='b')
plt.plot(lr_2_exp['time'],lr_2_exp['flux']/lr_2_exp['flux'].max(),label='1 GHz',c='g')
plt.plot(lg['time'],lg['flux']/lg['flux'].max(),c='purple',label='gamma')
plt.plot(lg_exp['time'],lg_exp['flux']/lg['flux'].max(),c='purple')
plt.xlabel('time (%s)'%lr_1['time'].unit)
plt.legend()
<matplotlib.legend.Legend at 0x7feee3d7a2e0>
../../../_images/Temp_Ev_two_zones_acc_and_cooling_adb_exp_44_1.png

we notice the two peaks in the radio lightcurves, due to transition of the SSA frequency generated by the expansion (see [Tramacere2022] for more details)

p=temp_ev_expansion.plot_tempev_model(region='rad',sed_data=None, use_cached = True,time_slice_bin=50)
p.setlim(y_min=1E-18,x_min=1E7)
../../../_images/Temp_Ev_two_zones_acc_and_cooling_adb_exp_46_0.png
from jetset.plot_sedfit import PlotSED

p=PlotSED(frame='obs',density=False)
p.resplot.remove()
skip_label=False

step=int(temp_ev_expansion.parameters.num_samples.val/50)

for i in  range(0,NUM_SET,step):
    t=temp_ev_expansion.rad_region.time_sampled_emitters._get_time_samples(time_slice=i)
    s=temp_ev_expansion.rad_region.get_SED(comp='Sum',time_slice=i,frame='obs',use_cached=True)
    s_sync=temp_ev_expansion.rad_region.get_SED(comp='Sync',time_slice=i,frame='obs',use_cached=True)
    s_IC=temp_ev_expansion.rad_region.get_SED(comp='SSC',time_slice=i,frame='obs',use_cached=True)

    if t[0][0]<temp_ev_expansion.parameters.t_jet_exp.val:
        c='C0'
    else:
        c='C1'
    label=None
    if i==0:
        label='pre expansion'
    if t[0][0]>=temp_ev_expansion.parameters.t_jet_exp.val and skip_label is False:
        label='expansion'
        skip_label=True
    p.add_model_plot(model=s,label=label,color=c,density=False,auto_label=False)

p.setlim(y_min=1E-18,x_min=1E7)
../../../_images/Temp_Ev_two_zones_acc_and_cooling_adb_exp_47_0.png