What Causes a Shift in Cosmic Ray Distribution on Earth?

  • Context: Graduate 
  • Thread starter Thread starter RyuuJin
  • Start date Start date
  • Tags Tags
    Cosmic rays Rays
Click For Summary

Discussion Overview

The discussion revolves around the simulation of cosmic ray particle distribution affected by a planet's magnetic field, specifically focusing on the unexpected results regarding the maxima of distribution at latitudes around 70 degrees instead of the poles. Participants explore potential explanations and seek assistance with the code used for the simulation.

Discussion Character

  • Exploratory, Technical explanation, Debate/contested

Main Points Raised

  • One participant describes their simulation setup, including the use of a dipole approximation for the magnetic field and the expectation of a distribution maximum at the poles.
  • The same participant reports unexpected results, with maxima at approximately 70 degrees latitude, and questions whether this is due to an error in their code or if there is a physical explanation.
  • Another participant requests the code to better understand the issue.
  • The original poster shares their code, expressing uncertainty about potential errors and providing comments for clarity.
  • There is a mention of a fixed typing/naming error in the code, but no further analysis or resolution of the issue is provided.

Areas of Agreement / Disagreement

Participants have not reached a consensus on the cause of the unexpected distribution maxima, and multiple views regarding the potential reasons remain unaddressed.

Contextual Notes

The discussion includes complex technical details about the simulation and the magnetic field model, but lacks clarity on specific assumptions and dependencies that may affect the results.

RyuuJin
Messages
7
Reaction score
0
Hey guys!
I am trying to simulate distribution of cosmic ray particles, which change their trajectory due to planet's magnetic field (no atmosphere; dipole approximation). I tried considering protons with non-relativistic velocities, falling on an Earth-like planet, which has rotational axis aligned with the dipole axis. I was expecting a distribution maximum at the poles, but instead I got a result with maxima located at the latitudes of roughly 70 degrees (north and south). Do any of you know of an explanation for this occurrence? Or is just something wrong with my code?
Thanks!
 
Astronomy news on Phys.org
Can you please post the code you have written??
 
Here's the code (Python). I added comments for easier interpretation. I honestly have no idea, what could I be doing wrong...
Python:
# -*- coding: utf-8 -*-

from scipy import *
from scipy.integrate import ode, odeint
from math import *

from pylab import *
from mpl_toolkits.mplot3d import Axes3D

def dipole(x,y,z) :#cartesian dipole magnetic field
    xyz=[x,y,z]   
    len_r = vec_len(xyz)
    dir_r = vec_dir(xyz)
    mi0=1e-7
    A = mi0/(len_r**3)*m_velikost
    return A * (3*((np.dot(m_smer,dir_r))*dir_r) - m_smer)

#direction and length of a vector
def vec_len(x) :
    return np.sqrt(x[0]**2+x[1]**2+x[2]**2)

def vec_dir(x) :
    return np.array([x[0]/vec_len(x), x[1]/vec_len(x), x[2]/vec_len(x)])

'''initial velocity -> from energy'''
def velocity_rel(E,mass,c):
    return np.sqrt(c**2-mass**2*c**6/E**2)

def velocity_class(E,masa):
    return np.sqrt(2*E/masa)

'''spherical - cartesian'''
def cart_to_spher(x,y,z):
    x += 10**(-10)
    y += 10**(-10)
    z += 10**(-10)
    r = np.sqrt(x**2+y**2+z**2)
    fi = (np.arctan(y/x))
    fi = (fi - 0.5*(np.abs(x)/x - 1) * np.pi) % (2*np.pi)#if x<0
    theta = (np.arctan(np.sqrt(x**2+y**2)/z))
    theta = (theta - 0.5*(np.abs(z)/z - 1) * np.pi)#if z<0
    return r,fi,theta
   
def spher_to_cart(r,fi,theta):
    return [r*np.cos(fi)*np.sin(theta), r*np.sin(fi)*np.sin(theta), r*np.cos(theta)]

def vec_len(x) :
    return np.sqrt(x[0]**2+x[1]**2+x[2]**2)

'''gives trajectory of a particle'''
def SolveNewtonLorenz_2(x0, y0, z0, vx0, vy0, vz0, tend, dt, m, q,field=dipole):
    vsq = vx0**2 + vy0**2 + vz0**2
    gamma = 1.0/sqrt(1 - vsq/c**2)

    def f(Y, t=0):
        x,y,z,vx,vy,vz = Y
        Bx, By, Bz = field(x,y,z)
        fac = q/(m*gamma)
        return [ vx, vy, vz,
                 fac*(vy*Bz - vz*By),
                 fac*(vz*Bx - vx*Bz),
                 fac*(vx*By - vy*Bx) ]

    t = arange(0, tend, dt)
    y = odeint(f, [x0, y0, z0, vx0, vy0, vz0], t)
   
    coll_mat=[]
    for i in range(len(y)):
        vec=[y[i,0],y[i,1],y[i,2]]
        if vec_len(vec)<=Re:
            print("Aaay papi! It's a collision!")
            coll_mat=np.append(coll_mat,vec)
            break
    return y, coll_mat'''gives distribution of particles on the surface (theta, phi)'''
def distrib(N,r0, E0, e, mass, tend, dt):
    theta_tab=[]
    fi_tab=[]
    hits=0
    #I generate particles at distance r0 (theta, phi are random), with certain direction
    for i in range(N):
        #Gaussian velocity distribution
        E=normal(E0,scale=E0/10)
        #incoming direction
        x=rand(1)
        theta=acos(2*x-1)
        y=rand(1)
        fi=(2*np.pi*y)
        #position of particle
        fi0=uniform(0,2*np.pi)
        x1=rand(1)
        theta0=acos(2*x1-1)
       
        v0=velocity_class(E,mass)
        v_cart=spher_to_cart(v0,fi,theta)
       
       
        #if velocity too large -> general relativity
        if v0 >=0.1*c:
            v0=hitrost(E,masa,c)
            v_kart=spher_to_cart(v0,fi,theta)

        vx=v_kart[0]
        vy=v_kart[1]
        vz=v_kart[2]
       
        #I adjust direction of particles (all are flying towards or next to the planet - not from it!)

        if theta0>=0 and theta0<np.pi/2 and fi0 >=0 and fi0<np.pi/2:#1.octant
            vx=-np.abs(vx)
            vy=-np.abs(vy)
            vz=-np.abs(vz)
           
        elif theta0>=0 and theta0<np.pi/2 and fi0 >np.pi/2 and fi0<np.pi:#2. octant
            vx=np.abs(vx)
            vy=-np.abs(vy)
            vz=-np.abs(vz)
           
        elif theta0>=0 and theta0<np.pi/2 and fi0 >np.pi and fi0<np.pi*3/2:#3. octant
            vx=np.abs(vx)
            vy=np.abs(vy)
            vz=-np.abs(vz)
           
        elif theta0>=0 and theta0<np.pi/2 and fi0 >np.pi*3/2 and fi0<2*np.pi:#4. octant
            vx=-np.abs(vx)
            vy=np.abs(vy)
            vz=-np.abs(vz)

        elif theta0>=np.pi/2 and theta0<np.pi and fi0 >=0 and fi0<np.pi/2:#5. octant
            vx=-np.abs(vx)
            vy=-np.abs(vy)
            vz=np.abs(vz)

        elif theta0>=np.pi/2 and theta0<np.pi and fi0 >np.pi/2 and fi0<np.pi:#6. octant
            vx=np.abs(vx)
            vy=-np.abs(vy)
            vz=np.abs(vz)

        elif theta0>=np.pi/2 and theta0<np.pi and  fi0 >np.pi and fi0<np.pi*3/2:#7. octant
            vx=np.abs(vx)
            vy=np.abs(vy)
            vz=np.abs(vz)

        elif theta0>=np.pi/2 and theta0<np.pi and fi0 >np.pi*3/2 and fi0<2*np.pi:#8. octant
            vx=-np.abs(vx)
            vy=+np.abs(vy)
            vz=np.abs(vz)
       
        elif theta0==0:
            vz=-np.abs(vz)
           
        if theta0==np.pi:
            vz=np.abs(vz)

        if theta0==np.pi/2 and fi0==0 or fi0==2*np.pi:
            vx=-np.abs(vx)
       
        if theta0==np.pi/2 and fi0==np.pi:
            vx=np.abs(vx)
           
        if theta0==np.pi/2 and fi0==np.pi/2:
            vy=-np.abs(vx)
           
        if theta0==np.pi/2 and fi0==2*np.pi:
            vy=np.abs(vy)
           
        startVel=[float(vx),float(vy),float(vz)]
        startPos=spher_to_cart(r0,fi0,theta0)
       
        posMat,cPos= SolveNewtonLorenz_2(startPos[0],startPos[1],startPos[2], startVel[0],startVel[1],startVel[2], tend,dt, mass,e, field=dipole)

        if len(cPos)>1:#if collision occurred
           
            r_coll,fi_coll,theta_coll=cart_to_spher(cPos[0],cPos[1],cPos[2])
       
            theta_tab=np.append(theta_tab,theta_coll)
            fi_tab=np.append(fi_tab,fi_coll)
            hits+=1
    print(hits)   
    return fi_tab,theta_tab, posMat,cPos
 
RyuuJin said:
Here's the code (Python). I added comments for easier interpretation. I honestly have no idea, what could I be doing wrong...

EDIT: fixed typing/naming error in line 113

Python:
# -*- coding: utf-8 -*-

from scipy import *
from scipy.integrate import ode, odeint
from math import *

from pylab import *
from mpl_toolkits.mplot3d import Axes3D

def dipole(x,y,z) :#cartesian dipole magnetic field
    xyz=[x,y,z]  
    len_r = vec_len(xyz)
    dir_r = vec_dir(xyz)
    mi0=1e-7
    A = mi0/(len_r**3)*m_velikost
    return A * (3*((np.dot(m_smer,dir_r))*dir_r) - m_smer)

#direction and length of a vector
def vec_len(x) :
    return np.sqrt(x[0]**2+x[1]**2+x[2]**2)

def vec_dir(x) :
    return np.array([x[0]/vec_len(x), x[1]/vec_len(x), x[2]/vec_len(x)])

'''initial velocity -> from energy'''
def velocity_rel(E,mass,c):
    return np.sqrt(c**2-mass**2*c**6/E**2)

def velocity_class(E,masa):
    return np.sqrt(2*E/masa)

'''spherical - cartesian'''
def cart_to_spher(x,y,z):
    x += 10**(-10)
    y += 10**(-10)
    z += 10**(-10)
    r = np.sqrt(x**2+y**2+z**2)
    fi = (np.arctan(y/x))
    fi = (fi - 0.5*(np.abs(x)/x - 1) * np.pi) % (2*np.pi)#if x<0
    theta = (np.arctan(np.sqrt(x**2+y**2)/z))
    theta = (theta - 0.5*(np.abs(z)/z - 1) * np.pi)#if z<0
    return r,fi,theta
  
def spher_to_cart(r,fi,theta):
    return [r*np.cos(fi)*np.sin(theta), r*np.sin(fi)*np.sin(theta), r*np.cos(theta)]

def vec_len(x) :
    return np.sqrt(x[0]**2+x[1]**2+x[2]**2)

'''gives trajectory of a particle'''
def SolveNewtonLorenz_2(x0, y0, z0, vx0, vy0, vz0, tend, dt, m, q,field=dipole):
    vsq = vx0**2 + vy0**2 + vz0**2
    gamma = 1.0/sqrt(1 - vsq/c**2)

    def f(Y, t=0):
        x,y,z,vx,vy,vz = Y
        Bx, By, Bz = field(x,y,z)
        fac = q/(m*gamma)
        return [ vx, vy, vz,
                 fac*(vy*Bz - vz*By),
                 fac*(vz*Bx - vx*Bz),
                 fac*(vx*By - vy*Bx) ]

    t = arange(0, tend, dt)
    y = odeint(f, [x0, y0, z0, vx0, vy0, vz0], t)
  
    coll_mat=[]
    for i in range(len(y)):
        vec=[y[i,0],y[i,1],y[i,2]]
        if vec_len(vec)<=Re:
            print("Aaay papi! It's a collision!")
            coll_mat=np.append(coll_mat,vec)
            break
    return y, coll_mat'''gives distribution of particles on the surface (theta, phi)'''
def distrib(N,r0, E0, e, mass, tend, dt):
    theta_tab=[]
    fi_tab=[]
    hits=0
    #I generate particles at distance r0 (theta, phi are random), with certain direction
    for i in range(N):
        #Gaussian velocity distribution
        E=normal(E0,scale=E0/10)
        #incoming direction
        x=rand(1)
        theta=acos(2*x-1)
        y=rand(1)
        fi=(2*np.pi*y)
        #position of particle
        fi0=uniform(0,2*np.pi)
        x1=rand(1)
        theta0=acos(2*x1-1)
      
        v0=velocity_class(E,mass)
        v_cart=spher_to_cart(v0,fi,theta)
      
      
        #if velocity too large -> general relativity
        if v0 >=0.1*c:
            v0=velocity(E,mass,c)
            v_kart=spher_to_cart(v0,fi,theta)

        vx=v_kart[0]
        vy=v_kart[1]
        vz=v_kart[2]
      
        #I adjust direction of particles (all are flying towards or next to the planet - not from it!)

        if theta0>=0 and theta0<np.pi/2 and fi0 >=0 and fi0<np.pi/2:#1.octant
            vx=-np.abs(vx)
            vy=-np.abs(vy)
            vz=-np.abs(vz)
          
        elif theta0>=0 and theta0<np.pi/2 and fi0 >np.pi/2 and fi0<np.pi:#2. octant
            vx=np.abs(vx)
            vy=-np.abs(vy)
            vz=-np.abs(vz)
          
        elif theta0>=0 and theta0<np.pi/2 and fi0 >np.pi and fi0<np.pi*3/2:#3. octant
            vx=np.abs(vx)
            vy=np.abs(vy)
            vz=-np.abs(vz)
          
        elif theta0>=0 and theta0<np.pi/2 and fi0 >np.pi*3/2 and fi0<2*np.pi:#4. octant
            vx=-np.abs(vx)
            vy=np.abs(vy)
            vz=-np.abs(vz)

        elif theta0>=np.pi/2 and theta0<np.pi and fi0 >=0 and fi0<np.pi/2:#5. octant
            vx=-np.abs(vx)
            vy=-np.abs(vy)
            vz=np.abs(vz)

        elif theta0>=np.pi/2 and theta0<np.pi and fi0 >np.pi/2 and fi0<np.pi:#6. octant
            vx=np.abs(vx)
            vy=-np.abs(vy)
            vz=np.abs(vz)

        elif theta0>=np.pi/2 and theta0<np.pi and  fi0 >np.pi and fi0<np.pi*3/2:#7. octant
            vx=np.abs(vx)
            vy=np.abs(vy)
            vz=np.abs(vz)

        elif theta0>=np.pi/2 and theta0<np.pi and fi0 >np.pi*3/2 and fi0<2*np.pi:#8. octant
            vx=-np.abs(vx)
            vy=+np.abs(vy)
            vz=np.abs(vz)
      
        elif theta0==0:
            vz=-np.abs(vz)
          
        if theta0==np.pi:
            vz=np.abs(vz)

        if theta0==np.pi/2 and fi0==0 or fi0==2*np.pi:
            vx=-np.abs(vx)
      
        if theta0==np.pi/2 and fi0==np.pi:
            vx=np.abs(vx)
          
        if theta0==np.pi/2 and fi0==np.pi/2:
            vy=-np.abs(vx)
          
        if theta0==np.pi/2 and fi0==2*np.pi:
            vy=np.abs(vy)
          
        startVel=[float(vx),float(vy),float(vz)]
        startPos=spher_to_cart(r0,fi0,theta0)
      
        posMat,cPos= SolveNewtonLorenz_2(startPos[0],startPos[1],startPos[2], startVel[0],startVel[1],startVel[2], tend,dt, mass,e, field=dipole)

        if len(cPos)>1:#if collision occurred
          
            r_coll,fi_coll,theta_coll=cart_to_spher(cPos[0],cPos[1],cPos[2])
      
            theta_tab=np.append(theta_tab,theta_coll)
            fi_tab=np.append(fi_tab,fi_coll)
            hits+=1
    print(hits)  
    return fi_tab,theta_tab, posMat,cPos
 
May be the polar cusp.
 
stefan r said:
May be the polar cusp.
Are polar cusps formed in simple dipole approximation? I didn't classify regions like magnetosheath or magnetopause in my simulation.
 
The magnetic field lines stretch further outward at higher latitude. Your density would stop increasing because the magnetic field is no longer deflecting. At 0 degrees (equator) the proton feels a force at 90 degrees. A proton at high latitudes does not feel much force so it continues closer to forward. If a proton is coming in from above northern Siberia moving toward Canada there is not much force to change the direction. It would cross the north pole.

There is also more kilometers at 70 degrees relative to 80 degrees. The 90 degree latitude line is 0 kilometers long. Is your "maximum" a count of protons hitting between degree x and degree y? If so you should expect 0 impacts in the 90+ category. Should get increasing impacts with increasing area until the magnetic defection becomes strong and the map geometry effect becomes weak.
 

Similar threads

  • · Replies 28 ·
Replies
28
Views
7K
Replies
11
Views
9K
  • · Replies 21 ·
Replies
21
Views
5K
  • · Replies 9 ·
Replies
9
Views
1K
  • · Replies 7 ·
Replies
7
Views
4K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 25 ·
Replies
25
Views
7K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 9 ·
Replies
9
Views
6K