In [ ]:
%matplotlib notebook
from ipywidgets import interact, FloatSlider
import numpy as np
import matplotlib
matplotlib.rcParams['font.size'] = 16
import matplotlib.pyplot as plt
me = 9.109E-28 # electron mass in g
c = 2.998E10 # speed of light in cm/s
e = 4.803E-10 # electron charge in esu
def A(B):
return B**2*4*e**4/(9*c**5*me**3)
def gc(B, dt):
# dt in Myr
return 1/(A(B)*dt*3.155760E13)
gmax = 1E5
gmin = 10
B = 1E-6
nuc = 3.0*gmax**2*e*B/(4.0*np.pi*me*c)
nucmin = 3.0*gmin**2*e*B/(4.0*np.pi*me*c)
nus = np.logspace(7, 11, 100)
fig = plt.figure(figsize=(10,6))
ax = fig.add_subplot(1, 1, 1)
J = B**1.5*nus**(-0.5)*np.exp(-nus/nuc)
line, = ax.plot(nus, J)
ax.set_xlim(1E7, 1E11)
ax.semilogx()
ax.semilogy()
ax.set_xticks([1E7, 1E8, 1E9, 1E10, 1E11])
ax.set_xticklabels(['10 MHz', '100 MHz', '1 GHz', '10 GHz', '100 GHz'])
text_alpha = ax.text(nus[int(len(nus)*0.7)], 1E-11, 'alpha =')
text_B = ax.text(nus[int(len(nus)*0.7)], 1E-11, 'B =')
text_gamc = ax.text(nus[int(len(nus)*0.7)], 1E-11, r'$\gamma_c$ =')
text_nuc = ax.text(nus[int(len(nus)*0.7)], 1E-11, r'$\nu_c$ =', color='orange')
line_nuc = ax.axvline(nuc, color='orange')
def update(alpha=0.5, logB=-5, dt=10):
B = 10**(logB)
gmax = gc(B, dt)
nuc = 3.0*gmax**2*e*B/(4.0*np.pi*me*c)
nucmin = 3.0*gmin**2*e*B/(4.0*np.pi*me*c)
J = B**1.5*nus**(-alpha)*np.exp(-nus/nuc)
ymin = 1E-3*nus[0]**(-alpha)*B**1.5
ymax = 2E0*nus[0]**(-alpha)*B**1.5
text_alpha.set_text(r'$\alpha$ = %.2f' % alpha)
text_alpha.set_y(ymax*10**(-0.3))
text_B.set_text('B = %.1e G' % 10**logB)
text_B.set_y(ymax*10**(-0.5))
text_gamc.set_text(r'$\gamma_c$ = %.1e' % gmax)
text_gamc.set_y(ymax*10**(-0.7))
text_nuc.set_text(r'$\nu_c$ = %.1e' % nuc)
text_nuc.set_y(ymax*10**(-0.9))
line_nuc.set_xdata(nuc)
ax.set_ylim(ymin, ymax)
line.set_ydata(J)
fig.canvas.draw()
interact(update, alpha=(0,3,0.1), logB=(-7, -3, 0.1), loggc=(3, 9, 0.1), dt=(1, 500, 1));
In [ ]:
alpha = 0.5
B1 = 1E-6
t = 100
gmax = gc(B1, t)
nuc = 3.0*gmax**2*e*B1/(4.0*np.pi*me*c)
nucmin = 3.0*gmin**2*e*B1/(4.0*np.pi*me*c)
nus = np.logspace(7, 11, 100)
fig = plt.figure(figsize=(10,6))
ax = fig.add_subplot(1, 1, 1)
J1 = B1**1.5*nus**(-0.5)*np.exp(-nus/nuc)
ymin = 1E-3*nus[0]**(-alpha)*B1**1.5
ymax = 2E0*nus[0]**(-alpha)*B1**1.5
line, = ax.plot(nus, J1, color='orange')
x1 = 0.75
text_alpha = ax.text(nus[int(len(nus)*x1)], ymax*10**(-0.3), 't = %i Myr' % t)
text_B = ax.text(nus[int(len(nus)*x1)], ymax*10**(-0.5), 'B = %.1e G' % B1)
text_gamc = ax.text(nus[int(len(nus)*x1)], ymax*10**(-0.7), r'$\gamma_c$ = %.1e' % gmax)
text_nuc = ax.text(nus[int(len(nus)*x1)], ymax*10**(-0.9), r'$\nu_c$ = %.1e' % nuc, color='orange')
line_nuc = ax.axvline(nuc, color='orange', ls=':')
B2 = 1E-5
t = 100
gmax = gc(B2, t)
nuc = 3.0*gmax**2*e*B2/(4.0*np.pi*me*c)
nucmin = 3.0*gmin**2*e*B2/(4.0*np.pi*me*c)
nus = np.logspace(7, 11, 100)
J2 = B1**1.5*nus**(-0.5)*np.exp(-nus/nuc)
line2, = ax.plot(nus, J2, color='blue')
x2 = 0.05
text_alpha = ax.text(nus[int(len(nus)*x2)], ymax*10**(-2.3), 't = %i Myr' % t)
text_B = ax.text(nus[int(len(nus)*x2)], ymax*10**(-2.5), 'B = %.1e G' % B2)
text_gamc = ax.text(nus[int(len(nus)*x2)], ymax*10**(-2.7), r'$\gamma_c$ = %.1e' % gmax)
text_nuc = ax.text(nus[int(len(nus)*x2)], ymax*10**(-2.9), r'$\nu_c$ = %.1e' % nuc, color='blue')
line_nuc = ax.axvline(nuc, color='blue', ls=':')
ax.set_xlim(1E7, 1E11)
ax.semilogx()
ax.semilogy()
ax.set_xticks([1E7, 1E8, 1E9, 1E10, 1E11])
ax.set_xticklabels(['10 MHz', '100 MHz', '1 GHz', '10 GHz', '100 GHz'])
ax.set_ylim(ymin, ymax)
p = 2
distance=0.5
J_linear = (J1*distance**p+J2*(1-distance)**p)/(distance**p+(1-distance)**p)
J_log = np.exp((np.log(J1)*distance**p+np.log(J2)*(1-distance)**p)/(distance**p+(1-distance)**p))
line_linear, = ax.plot(nus, J_linear, color='black', ls='--', label='linear')
line_log, = ax.plot(nus, J_log, color='black', ls='-.', label='log')
plt.legend(loc=9)
def update(distance=0.5):
J_linear = (J1*distance**p+J2*(1-distance)**p)/(distance**p+(1-distance)**p)
J_log = np.exp((np.log(J1)*distance**p+np.log(J2)*(1-distance)**p)/(distance**p+(1-distance)**p))
line_linear.set_ydata(J_linear)
line_log.set_ydata(J_log)
interact(update, distance=(0, 1, 0.05));
In [ ]: