Ejemplo n.º 1
0
def plot_hist_and_fit_gauss(data_list,
                            binno=60,
                            normed=1,
                            facecolor="green",
                            linecolor='r--',
                            alpha=0.5):
    """
    return (mu, sigma)
    """
    # fit the data by maxwell-boltzmann distribution
    # mawell.fit returns shape, loc, scale : tuple of floats
    # MLEs for any shape statistics, followed by those for location and
    # scale.
    params = maxwell.fit(data_list)
    print params
    # plot the histogram of the data
    #(n, bins, patches) = plt.hist(data_list, binno, range=(0, 50), normed=normed, facecolor=facecolor, alpha=alpha)
    (n, bins, patches) = plt.hist(data_list,
                                  binno,
                                  normed=normed,
                                  facecolor=facecolor,
                                  alpha=alpha)
    x = np.linspace(0, 25, 100)
    # add a 'best fit' line
    plt.plot(x, maxwell.pdf(x, *params), linecolor, lw=3)
    print get_max_likelihood(data_list, params[0], params[1])
    return params
def plot(p2D,pens,p2De,para,params_exp,thickness,tempres):
    #print tempres
    plt.subplot(511)
    
    plt.hist(p2D[:,5], bins=20, normed=True)
    x = np.linspace(0, 5, 80)  
    if para !=None :
        plt.plot(x, maxwell.pdf(x, *para),'r',x,maxwell.cdf(x, *para), 'g')
    
    plt.subplot(512)
    plt.hist(pens, bins=20, normed=True)
    z=np.linspace(0,500,200)
    plt.xlim(0,2*thickness)  
    plt.plot(z, expon.pdf(z, *params_exp),'r')#plt.plot(z, expon.pdf(z, *params_exp),'r',z,expon.cdf(z, *params_exp), 'g')
    
    plt.subplot(513)
    plt.xlim(0,thickness+1)  
    plt.plot(p2D[:,0],p2D[:,1],'b.')
    
    plt.subplot(514)
    plt.ylim(-1*10**6,1*10**6)
    plt.xlim(0,thickness+1)
    plt.plot(p2De[:,0],p2De[:,1],'b.')
    
    
    plt.subplot(515)
    plt.plot(tempres[:,0],tempres[:,1],'r-')
    
    
    
    plt.savefig()
    plt.show()
    return
Ejemplo n.º 3
0
def plot(p2D, pens, p2De, para, params_exp, thickness):

    plt.subplot(411)

    plt.hist(p2D[:, 5], bins=10, normed=True)
    x = np.linspace(0, 5, 80)

    plt.plot(x, maxwell.pdf(x, *para), 'r', x, maxwell.cdf(x, *para), 'g')

    plt.subplot(412)
    plt.hist(pens, bins=20, normed=True)
    z = np.linspace(0, 500, 200)
    plt.xlim(0, 2 * thickness)
    plt.plot(
        z, expon.pdf(z, *params_exp), 'r'
    )  #plt.plot(z, expon.pdf(z, *params_exp),'r',z,expon.cdf(z, *params_exp), 'g')

    plt.subplot(413)
    plt.xlim(0, thickness + 1)
    plt.plot(p2D[:, 0], p2D[:, 1], 'b.')

    plt.subplot(414)
    plt.ylim(-1 * 10**6, 1 * 10**6)
    plt.xlim(0, thickness + 1)
    plt.plot(p2De[:, 0], p2De[:, 1], 'b.')
    plt.show()
    return
Ejemplo n.º 4
0
def gibbsDist():
    fig, ax = plt.subplots(1, 1)
    mean, var, skew, kurt = maxwell.stats(moments='mvsk')
    x = np.linspace(maxwell.ppf(0.01), maxwell.ppf(0.99), 100)
    ax.plot(x, maxwell.pdf(x), 'r-', lw=5, alpha=0.6, label='maxwell pdf')
    ax.legend(loc='best', frameon=False)
    plt.show()
def quiver_desired_velocity(crStats\
                                ,further_conditioning = None
                                ,grid_x=40,grid_y=40,small_incr=.00001\
                                ,qty='vel'
                                ,spec_type='gt'
                                ,img_format='png'
                                ,**kw):


        x_class_v,y_class_v,u_means,v_means,u_delta,v_delta,u_all,v_all =\
            sub_eval_desired_velocity_qtys(crStats
                                        ,further_conditioning\
                                               ,grid_x,grid_y,small_incr\
                                               ,qty\
                                               ,spec_type)


        plt.figure()
        plt.hist2d(u_delta,v_delta,**hist2d_param)
        plt.title('Overall noise distribution')
        plt.savefig(PATH_PREFIX + 'total_noise_%s_%s.%s' % (qty,spec_type,img_format))


        rv = maxwell()

        speed_delta = np.sqrt(np.asarray(u_delta)**2 + np.asarray(v_delta)**2)

        loc,scale = maxwell.fit(speed_delta)
        
        plt.figure()
        plt.hist(speed_delta,**hist_param_noLog)
        x = np.linspace(0,2,100)
        plt.plot(x,maxwell.pdf(x,scale=scale,loc=loc))
        
        plt.title('Overall abs noise distribution')
        plt.savefig(PATH_PREFIX + 'maxwellian_noise_%s_%s.%s' % (qty,spec_type,img_format))

        
        temperature  = np.sqrt( np.asarray([np.var(us) for us in u_all]) + np.asarray([np.var(vs) for vs in v_all]) )

        speed = [np.mean(np.sqrt(np.asarray(us)**2 + np.asarray(vs)**2)) for us,vs in zip(u_all,v_all) ]

        plt.figure()
        plt.quiver(x_class_v,y_class_v,u_means,v_means,temperature,**kw)
        plt.colorbar()
        plt.title('cross-realization "thermal" noise [m/s]')
        plt.xlabel('x [m]')
        plt.ylabel('y [m]')
        plt.savefig(PATH_PREFIX + 'quiver_thermal_noise_%s_%s.%s' % (qty,spec_type,img_format))
        
        plt.figure()
        plt.quiver(x_class_v,y_class_v,u_means,v_means,speed,**kw)
        plt.colorbar()
        plt.title('average speed')
        plt.xlabel('x [m]')
        plt.ylabel('y [m]')
        plt.savefig(PATH_PREFIX + 'quiver_average_modulus_%s_%s.%s' % (qty,spec_type,img_format))
Ejemplo n.º 6
0
def plot(p2D, pens, p2De, para, params_exp, thickness, tempres, petest,
         electron_affinity, finame):
    #print tempres
    plt.subplot(511)
    plt.xlabel('thickness[nm]')
    plt.ylabel('P')
    plt.hist(p2D[:, 5], bins=20, normed=True)
    x = np.linspace(0, 5, 80)
    if para != None:
        plt.plot(x, maxwell.pdf(x, *para), 'r', x, maxwell.cdf(x, *para), 'g')

    plt.subplot(512)
    plt.hist(pens, bins=20, normed=True)
    z = np.linspace(0, 500, 200)
    plt.xlabel('thickness[nm]')
    plt.ylabel('P')
    plt.xlim(0, 2 * thickness)
    plt.plot(
        z, expon.pdf(z, *params_exp), 'r'
    )  #plt.plot(z, expon.pdf(z, *params_exp),'r',z,expon.cdf(z, *params_exp), 'g')

    plt.subplot(513)
    plt.xlim(0, thickness + 1)
    plt.xlabel('thickness[nm]')
    plt.ylabel('size[nm]')
    plt.plot(p2D[:, 0], p2D[:, 1], 'b,')

    plt.subplot(514)
    plt.ylim(-1 * 10**6, 1 * 10**6)
    plt.xlim(0, thickness + 1)
    plt.xlabel('thickness[nm]')
    plt.ylabel('size[nm]')
    plt.plot(p2De[:, 0], p2De[:, 1], 'b,')

    plt.subplot(515)

    plt.xlabel('Time[s]')
    plt.ylabel('count[1]')
    smooth = 80

    for i in np.arange(0, len(tempres)):

        tempres[i,
                1] = (np.sum(tempres[i:i + smooth, 1]) / smooth).astype(float)

    plt.ylim(0, tempres[1, 1] * 1.5)
    plt.plot(tempres[:, 0], tempres[:, 1], 'r-')

    plt.savefig(finame + 'full_tk_%dpe_%.3fea_%.3f.pdf' %
                (thickness, petest, electron_affinity))
    plt.show()
    return
Ejemplo n.º 7
0
def ln_prior_v_kick(v_kick, sigma=c.v_kick_sigma):
    """
    Return the natural log of the prior probability on the SN kick velocity: ln P(v_kick).

    Args:
        v_kick : float, SN kick velocity.
        sigma : float (default: constants.v_kick_sigma), dispersion velocity for
            the Maxwellian distribution of birth kick magnitudes.

    Returns:
        ln_P_v_kick : float, natural logarithm of the prior on the SN kick velocity.
    """

    if v_kick < 0.0: return -np.inf
    return np.log(maxwell.pdf(v_kick, scale=sigma))
def plot_hist_and_fit_gauss(data_list, binno=60, normed=1, facecolor="green", linecolor='r--', alpha=0.5):
    """
    return (mu, sigma)
    """
    # fit the data by maxwell-boltzmann distribution
    # mawell.fit returns shape, loc, scale : tuple of floats
    # MLEs for any shape statistics, followed by those for location and
    # scale.
    params = maxwell.fit(data_list)
    print params
    # plot the histogram of the data
    #(n, bins, patches) = plt.hist(data_list, binno, range=(0, 50), normed=normed, facecolor=facecolor, alpha=alpha)
    (n, bins, patches) = plt.hist(data_list, binno, normed=normed, facecolor=facecolor, alpha=alpha)
    x = np.linspace(0, 25, 100)
    # add a 'best fit' line
    plt.plot(x, maxwell.pdf(x, *params), linecolor, lw=3)
    print get_max_likelihood(data_list, params[0], params[1])
    return params
Ejemplo n.º 9
0
def vel_distribution(dm_p): #reads in particle class details (FROM ALAN AND CORRECT)
	vrange = 10.**(np.linspace(1.,3.,num=100000.)) * units.km/units.s
	print vrange
	mass =10.*units.GeV/const.c**2
	temp = (0.5 * dm_p.mass* (230. * units.km/units.s)**2)/const.k_B
	print "Effective temp for DM particles moving at 230km/s ", temp.to(units.Kelvin)
	a = np.sqrt(const.k_B * temp/mass)
	print "Normalisation velocity ",a
	scale = a
	rv = maxwell.pdf(vrange, loc=0, scale=scale)
	plt.plot(vrange,rv,'-',color='b') #rv instead of 3000
        plt.title('Velocity Distribution')
        #plt.show()
        plt.clf()
    #global v_values
        v_values_i = maxwell.rvs(size=10000, loc=0, scale=scale) *units.m/units.s
        v_values = ((v_values_i)*1000) / const.c
        print("Velocity Values", v_values)
        plt.hist(v_values,1000,color='b',normed=1)
        plt.title('Velocity Samples')
        #plt.show()
        plt.clf()
        return v_values
Ejemplo n.º 10
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
 Tracé d'une distribution de Maxwell
"""
__author__ = "Dominique Lefebvre"
__copyright__ = "Copyright 2019 - TangenteX.com"
__version__ = "1.0"
__date__ = "2 novembre 2019"
__email__ = "*****@*****.**"

from scipy import linspace
from matplotlib.pylab import figure, title, grid, xlim, xlabel, ylabel, plot
from scipy.stats import maxwell

# domaine
x_min = 0.0
x_max = 10.0
x = linspace(x_min, x_max, 500)

# calcul de la distribution de Maxwell
y = maxwell.pdf(x)

# tracé de la distribution
fig1 = figure(figsize=(10, 8))
plot(x, y, 'blue')
grid()
xlim(x_min, x_max)
title(u'Distribution de Maxwell', fontsize=14)
xlabel('x')
ylabel('y')
Ejemplo n.º 11
0

# In[8]:


temp = 400
kb = 1.380649e-23


# In[9]:


mean, var, skew, kurt = maxwell.stats(moments ='mvsk')
fig, ax = plt.subplots(1, 1)
x = np.linspace(maxwell.ppf(0.01),maxwell.ppf(0.99), 100)
ax.plot(x, maxwell.pdf(x), 'r-', lw=4, alpha=0.6, label='maxwell pdf')
plt.title('1D Maxwell-Boltzmann Distribution')
plt.xlabel('Speed (m/s)') # fix this
plt.ylabel('Probability Density (s/m)')


# In[10]:


m = 2*kb*temp/(np.pi*float(mean)**2)
print('At STP, \nmass of particle = %s kg' % (m))


# In[11]:

Ejemplo n.º 12
0
def ln_priors(y):
    """ Priors on the model parameters

    Parameters
    ----------
    y : ra, dec, M1, M2, A, ecc, v_k, theta, phi, ra_b, dec_b, t_b
        Current HMXB location (ra, dec) and 10 model parameters

    Returns
    -------
    lp : float
        Natural log of the prior
    """

#    M1, M2, A, v_k, theta, phi, ra_b, dec_b, t_b = y
    ra, dec, M1, M2, A, ecc, v_k, theta, phi, ra_b, dec_b, t_b = y

    lp = 0.0

    # P(M1)
    if M1 < c.min_mass or M1 > c.max_mass: return -np.inf
    norm_const = (c.alpha+1.0) / (np.power(c.max_mass, c.alpha+1.0) - np.power(c.min_mass, c.alpha+1.0))
    lp += np.log( norm_const * np.power(M1, c.alpha) )
    # M1 must be massive enough to evolve off the MS by t_obs
    if load_sse.func_sse_tmax(M1) > t_b: return -np.inf

    # P(M2)
    # Normalization is over full q in (0,1.0)
    q = M2 / M1
    if q < 0.3 or q > 1.0: return -np.inf
    lp += np.log( (1.0 / M1 ) )

    # P(ecc)
    if ecc < 0.0 or ecc > 1.0: return -np.inf
    lp += np.log(2.0 * ecc)

    # P(A)
    if A*(1.0-ecc) < c.min_A or A*(1.0+ecc) > c.max_A: return -np.inf
    norm_const = np.log(c.max_A) - np.log(c.min_A)
    lp += np.log( norm_const / A )
    # A must avoid RLOF at ZAMS, by a factor of 2
    r_1_roche = binary_evolve.func_Roche_radius(M1, M2, A*(1.0-ecc))
    if 2.0 * load_sse.func_sse_r_ZAMS(M1) > r_1_roche: return -np.inf

    # P(v_k)
    if v_k < 0.0: return -np.inf
    lp += np.log( maxwell.pdf(v_k, scale=c.v_k_sigma) )

    # P(theta)
    if theta <= 0.0 or theta >= np.pi: return -np.inf
    lp += np.log(np.sin(theta) / 2.0)

    # P(phi)
    if phi < 0.0 or phi > np.pi: return -np.inf
    lp += -np.log( np.pi )

    # Get star formation history
    sf_history.load_sf_history()
    sfh = sf_history.get_SFH(ra_b, dec_b, t_b, sf_history.smc_coor, sf_history.smc_sfh)
    if sfh <= 0.0: return -np.inf

    # P(alpha, delta)
    # From spherical geometric effect, we need to care about cos(declination)
    lp += np.log(np.cos(c.deg_to_rad * dec_b) / 2.0)

    ##################################################################
    # We add an additional prior that scales the RA and Dec by the
    # area available to it, i.e. pi theta^2, where theta is the angle
    # of the maximum projected separation over the distance.
    #
    # Still under construction
    ##################################################################
    M1_b, M2_b, A_b = binary_evolve.func_MT_forward(M1, M2, A, ecc)
    A_c, v_sys, ecc = binary_evolve.func_SN_forward(M1_b, M2_b, A_b, v_k, theta, phi)
    if ecc < 0.0 or ecc > 1.0 or np.isnan(ecc): return -np.inf

    # Ensure that we only get non-compact object companions
    tobs_eff = binary_evolve.func_get_time(M1, M2, t_b)
    M_tmp, M_dot_tmp, R_tmp, k_type = load_sse.func_get_sse_star(M2_b, tobs_eff)
    if int(k_type) > 9: return -np.inf

#    t_sn = (t_b - func_sse_tmax(M1)) * 1.0e6 * yr_to_sec  # The time since the primary's core collapse
#    theta_max = (v_sys * t_sn) / dist_LMC  # Unitless
#    area = np.pi * rad_to_dec(theta_max)**2
#    lp += np.log(1.0 / area)
    ##################################################################
    # Instead, let's estimate the number of stars formed within a cone
    # around the observed position, over solid angle and time.
    # Prior is in Msun/Myr/steradian
    ##################################################################
    t_min = load_sse.func_sse_tmax(M1) * 1.0e6 * c.yr_to_sec
    t_max = (load_sse.func_sse_tmax(M2_b) - binary_evolve.func_get_time(M1, M2, 0.0)) * 1.0e6 * c.yr_to_sec
    if t_max-t_min < 0.0: return -np.inf
    theta_C = (v_sys * (t_max - t_min)) / c.dist_SMC
    stars_formed = get_stars_formed(ra, dec, t_min, t_max, v_sys, c.dist_SMC)
    if stars_formed == 0.0: return -np.inf
    volume_cone = (np.pi/3.0 * theta_C**2 * (t_max - t_min) / c.yr_to_sec / 1.0e6)
    lp += np.log(sfh / stars_formed / volume_cone)
    ##################################################################

#    # P(t_b | alpha, delta)
#    sfh_normalization = 1.0e-6
#    lp += np.log(sfh_normalization * sfh)

    # Add a prior so that the post-MT secondary is within the correct bounds
    M2_c = M1 + M2 - load_sse.func_sse_he_mass(M1)
    if M2_c > c.max_mass or M2_c < c.min_mass: return -np.inf

    # Add a prior so the effective time remains bounded
    t_eff_obs = binary_evolve.func_get_time(M1, M2, t_b)
    if t_eff_obs < 0.0: return -np.inf

    if t_b * 1.0e6 * c.yr_to_sec < t_min: return -np.inf
    if t_b * 1.0e6 * c.yr_to_sec > t_max: return -np.inf

    return lp
Ejemplo n.º 13
0
def ln_priors_population(y):
    """ Priors on the model parameters

    Parameters
    ----------
    y : M1, M2, A, ecc, v_k, theta, phi, ra_b, dec_b, t_b
        10 model parameters

    Returns
    -------
    lp : float
        Natural log of the prior
    """

    M1, M2, A, ecc, v_k, theta, phi, ra_b, dec_b, t_b = y

    lp = 0.0

    # P(M1)
    if M1 < c.min_mass or M1 > c.max_mass: return -np.inf
    norm_const = (c.alpha+1.0) / (np.power(c.max_mass, c.alpha+1.0) - np.power(c.min_mass, c.alpha+1.0))
    lp += np.log( norm_const * np.power(M1, c.alpha) )
    # M1 must be massive enough to evolve off the MS by t_obs
    if load_sse.func_sse_tmax(M1) > t_b: return -np.inf

    # P(M2)
    # Normalization is over full q in (0,1.0)
    q = M2 / M1
    if q < 0.3 or q > 1.0: return -np.inf
    lp += np.log( (1.0 / M1 ) )

    # P(ecc)
    if ecc < 0.0 or ecc > 1.0: return -np.inf
    lp += np.log(2.0 * ecc)

    # P(A)
    if A*(1.0-ecc) < c.min_A or A*(1.0+ecc) > c.max_A: return -np.inf
    norm_const = np.log(c.max_A) - np.log(c.min_A)
    lp += np.log( norm_const / A )
    # A must avoid RLOF at ZAMS, by a factor of 2
    r_1_roche = binary_evolve.func_Roche_radius(M1, M2, A*(1.0-ecc))
    if 2.0 * load_sse.func_sse_r_ZAMS(M1) > r_1_roche: return -np.inf

    # P(v_k)
    if v_k < 0.0: return -np.inf
    lp += np.log( maxwell.pdf(v_k, scale=c.v_k_sigma) )

    # P(theta)
    if theta <= 0.0 or theta >= np.pi: return -np.inf
    lp += np.log(np.sin(theta) / 2.0)

    # P(phi)
    if phi < 0.0 or phi > np.pi: return -np.inf
    lp += -np.log( np.pi )

    # Get star formation history
    sfh = sf_history.get_SFH(ra_b, dec_b, t_b, sf_history.smc_coor, sf_history.smc_sfh)
    if sfh <= 0.0: return -np.inf
    lp += np.log(sfh)

    # P(alpha, delta)
    # From spherical geometric effect, scale by cos(declination)
    lp += np.log(np.cos(c.deg_to_rad*dec_b) / 2.0)

    M1_b, M2_b, A_b = binary_evolve.func_MT_forward(M1, M2, A, ecc)
    A_c, v_sys, ecc = binary_evolve.func_SN_forward(M1_b, M2_b, A_b, v_k, theta, phi)
    if ecc < 0.0 or ecc > 1.0 or np.isnan(ecc): return -np.inf

    # Ensure that we only get non-compact object companions
    tobs_eff = binary_evolve.func_get_time(M1, M2, t_b)
    M_tmp, M_dot_tmp, R_tmp, k_type = load_sse.func_get_sse_star(M2_b, tobs_eff)
    if int(k_type) > 9: return -np.inf

    # Add a prior so that the post-MT secondary is within the correct bounds
    M2_c = M1 + M2 - load_sse.func_sse_he_mass(M1)
    if M2_c > c.max_mass or M2_c < c.min_mass: return -np.inf

    # Add a prior so the effective time remains bounded
    t_eff_obs = binary_evolve.func_get_time(M1, M2, t_b)
    if t_eff_obs < 0.0: return -np.inf
    t_max = (load_sse.func_sse_tmax(M2_b) - binary_evolve.func_get_time(M1, M2, 0.0))
    if t_b > t_max: return -np.inf

    return lp
Ejemplo n.º 14
0
from scipy.stats import maxwell
import matplotlib.pyplot as plt
fig, ax = plt.subplots(1, 1)

# Calculate a few first moments:

mean, var, skew, kurt = maxwell.stats(moments='mvsk')

# Display the probability density function (``pdf``):

x = np.linspace(maxwell.ppf(0.01),
                maxwell.ppf(0.99), 100)
ax.plot(x, maxwell.pdf(x),
       'r-', lw=5, alpha=0.6, label='maxwell pdf')

# Alternatively, the distribution object can be called (as a function)
# to fix the shape, location and scale parameters. This returns a "frozen"
# RV object holding the given parameters fixed.

# Freeze the distribution and display the frozen ``pdf``:

rv = maxwell()
ax.plot(x, rv.pdf(x), 'k-', lw=2, label='frozen pdf')

# Check accuracy of ``cdf`` and ``ppf``:

vals = maxwell.ppf([0.001, 0.5, 0.999])
np.allclose([0.001, 0.5, 0.999], maxwell.cdf(vals))
# True

# Generate random numbers:
Ejemplo n.º 15
0
    obj /= obj.max()
    obj_samples.append(obj)

subplot(412)
grid(True)
axis([350,750,0,1.5])
xlabel('Wavelength $\lambda$ (nm)')
ylabel('Reflectance coefficient')
title(r'Sample reflectivity behaviour')
for obj in obj_samples:
    plot(obj)
###############################
    
#### Black camera reflectivity

black_camera = maxwell.pdf(x, loc=350, scale=200,size=1000)
black_camera /= black_camera.max() * black_camera_absorbance

subplot(413)
grid(True)
axis([350,750,0,1.5])
xlabel('Wavelength $\lambda$ (nm)')
ylabel('Reflectance coefficient')
title(r'Black camera reflectivity behaviour')
plot(black_camera)
###############################

#### Reflected light from object and camera

subplot(414)
grid(True)
def get_max_likelihood(data_list, loc, scale, weight=45):
    pdf_array = maxwell.pdf(data_list, loc, scale)
    likelihood = 1
    for item in pdf_array:
        likelihood = item * weight * likelihood
    return likelihood
Ejemplo n.º 17
0
          'figure.subplot.left':0.15,
          'figure.subplot.right':0.92}

hexcols = ['#332288', '#88CCEE', '#44AA99', '#117733', '#999933', '#DDCC77',\
        '#CC6677', '#882255', '#AA4499', '#661100', '#6699CC', '#AA4466','#4477AA']

mpl.rcParams.update(params)

A=np.array([np.append([vkick],kicks.sample_kick_distribution_P(23,5.5,55,1.4,vdist=lambda x:[float(vkick)], num_v=5, num_theta=400,num_phi=100)) for vkick in range(0,701,5)])

print(A)
print(A[:,0])
print(A[:,1])
print(A[:,2])

fig, axes= plt.subplots(1)

maxw = axes.fill_between(A[:,0],0,maxwell.pdf(A[:,0], scale=265.)/max(maxwell.pdf(A[:,0],scale=265.)),color="b", alpha=0.2, label="Maxwellian, $\\sigma=265~\\rm km~s^{-1}$")
merge, = axes.plot(A[:,0],10*A[:,1], color=hexcols[2],label="GW merge fraction $\\times$ 10")
disrupt, = axes.plot(A[:,0],A[:,2], color=hexcols[8],ls="--", label="Disrupt fraction")

axes.set_xlabel("$v_{\\rm kick}~\\rm[km~s^{-1}]$")
axes.set_ylabel("fraction")
#axes.set_xlim([0,50])
axes.set_ylim([0,1.19])
axes.legend([maxw,merge,disrupt],["Maxwellian, $\\sigma=265~\\rm km~s^{-1}$", "GW merge fraction $\\times$ 10", "Disrupt fraction"], loc="upper left", fontsize=7)

plt.savefig("kick_dist.pdf")
#plt.clf()
#plt.close(plt.gcf())
Ejemplo n.º 18
0
M = 66.9792e6  #keV: Mass of Nucleus
M_det = 5.60959e32  #keV: Mass of Detector 1kg

#NSI parameters: 0

from scipy.integrate import quad
from scipy.stats import maxwell

flux_1m = 1.511067123220e12  #/cm^2/s at 1m
flux_r = lambda r: flux_1m / (r * r)  #r in meters
total_flux = flux_r(L)  #/cm^2/s at 1m

#np.arange(1e2,20e3,1e2)#E=100keV - 20MeV with 100keV step

form_n_flux = lambda En: maxwell.pdf((En + 1.9e3) / 1.7e3)  #En in keV
total = quad(lambda En: form_n_flux(En), 0, np.inf)[0]

norm_n_flux = lambda En: form_n_flux(En) / total
total_norm_n_flux = quad(norm_n_flux, 0, np.inf)[0]

n_flux = lambda En: total_flux * norm_n_flux(En)
total_n = quad(n_flux, 0, np.inf)[0]

#t=1#second
Gf2 = (1.16637e-17)**2  #keV-4
#area_det=34.322512#cm^2  /((4)*math.pi*100*100)

C_T = lambda En, T: (Gf2 * M / (2 * math.pi)) * (((G_V + G_A)**2) + ((
    (G_V - G_A)**2) * ((1 - (T / En))**2)) - (((G_V**2) - (G_A**2)) *
                                              (M * T / (En * En))))
Ejemplo n.º 19
0
def get_max_likelihood(data_list, loc, scale, weight=45):
    pdf_array = maxwell.pdf(data_list, loc, scale)
    likelihood = 1
    for item in pdf_array:
        likelihood = item * weight * likelihood
    return likelihood
Ejemplo n.º 20
0
from scipy.stats import maxwell
import numpy as np
import matplotlib.pyplot as plt
fig, ax = plt.subplots(1, 1)

mean, var, skew, kurt = maxwell.stats(moments='mvsk')
x = np.linspace(maxwell.ppf(0.01), maxwell.ppf(0.99), 10000)
ax.plot(x, maxwell.pdf(x), 'r-', lw=5.5, alpha=0.6)
vals = maxwell.ppf([0.001, 0.5, 0.999])
np.allclose([0.001, 0.5, 0.999], maxwell.cdf(vals))
r = maxwell.rvs(size=1000)
ax.hist(r, density=True, histtype='stepfilled', alpha=0.2)
ax.legend(loc='best', frameon=False)
plt.show()
print(mean, var, skew, kurt)
Ejemplo n.º 21
0
    return args


args = parse_arguments()
option = args['option']
data_name = args['dataname']

#  ---------------------------------------------------------  #
#  Import Data! (3/4)                                         #
#  ---------------------------------------------------------  #

mean, var, skew, kurt = maxwell.stats(moments='mvsk')

if 0:
    x = np.linspace(maxwell.ppf(0.0001), maxwell.ppf(0.9999), 1000)
    y = 16 * maxwell.pdf(x)
else:
    a = 1
    x = np.linspace(0.00001, 4.9, 1000)
    y2 = -1 * a * x**2
    yf = a * x**2
    y = yf * np.exp(y2)
    x = np.linspace(1, 250000, 1000)
    # y1 = x**2
    # ye = np.exp((-1 * y1) * 0.5)
    # y = np.sqrt(((2/math.pi) * y1)) * ye

mb = ax1.plot(x, y, 'r-', lw=5, alpha=0.6, label='maxwell pdf')

ax1.fill_between(x,
                 0,
Ejemplo n.º 22
0
def adjustar_Maxwell(mid_pointa, histoa):
    a_ajustar_ray = lambda x,l,s: maxwell.pdf(x, l, s)
    popt_wei, pcov = curve_fit(a_ajustar_ray, mid_pointa, histoa)
    print(popt_wei, pcov)
    ajustado_ray = a_ajustar_ray(mid_pointa, popt_wei[0], popt_wei[1])
    return(ajustado_ray)