Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created a file for storing all constants #21

Merged
merged 8 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ where = src

[options.package_data]
nupyprop.datafiles = lookup_tables.h5
polarization_data.txt
nupyprop.models = *.ecsv

[options.entry_points]
Expand Down
41 changes: 41 additions & 0 deletions src/nupyprop/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
############################################################
#This file contains all the required constants for nupyprop
############################################################
import numpy as np
import scipy.constants as scc

#useful constants
N_A = 6.0221409e+23 # Avogadro's number in units of 1/mole

R_earth = 6378.137 #radius of Earth in km

rho_water, rho_rock, rho_iron = 1.02, 2.65, 7.87 #density of water, rock and iron in g/cm^3

m_mu = scc.physical_constants["muon mass energy equivalent in MeV"][0]*1e-3 # muon mass in GeV
m_tau = scc.physical_constants["tau mass energy equivalent in MeV"][0]*1e-3 # tau mass in GeV
m_pi = 139.57018e-3 # pion mass in GeV
m_p = scc.physical_constants["proton mass energy equivalent in MeV"][0]*1e-3 # proton mass in GeV

alpha_fs = scc.fine_structure #fine structure constant

#Earth emergence angles
beta_arr = np.asarray([float('{:.1f}'.format(i)) for i in np.arange(0.1,90.1,step=0.1)]) # finer steps of 0.1 degerees

#Cross-section models that exsist in src/nupyprop/datafiles/lookup_table.h5
nu_models = ['allm', 'bdhm', 'ct18nlo', 'nct15'] #for weak interaction
pn_models = ['allm', 'bb'] #for Photo-nuclear electromagnetic interaction

#step size for continuous energy loss
step_size = 4500 #in cm

#array of energies used in interpolation for cross-section and CDFs
E_nu = np.logspace(3,12,91,base=10).astype(np.float64) #for neutrinos in GeV
E_lep = np.logspace(0,12,121,base=10).astype(np.float64) #for charged leptons in GeV

#inelasticity values used in interpolation for energy CDFs for neutrinos and charged leptons
yvals = np.logspace(-3,0,31).astype(np.float64) #goes from 1e-3 to 1

#Earth layers considered in PREM - Earth density model
Rlay = np.array([1221.5, 3480.0, 5701.0, 5771.0, 5971.0, 6151.0, 6346.6, 6356.0, 6368.0, 6371.0])


9 changes: 5 additions & 4 deletions src/nupyprop/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

@author: sam
"""
import nupyprop.constants as const

import numpy as np
from decimal import Decimal
Expand All @@ -18,11 +19,11 @@
from collections.abc import Iterable
from scipy.interpolate import interpn

E_nu = np.logspace(3,12,91,base=10).astype(np.float64)
E_lep = np.logspace(0,12,121,base=10).astype(np.float64)
E_nu = const.E_nu
E_lep = const.E_lep

nu_models = ['allm', 'bdhm', 'ct18nlo', 'nct15'] #these are the models that exsist in lookup_table.h5
pn_models = ['allm', 'bb']
nu_models = const.nu_models #these are the models that exsist in lookup_table.h5
pn_models = const.pn_models

ref = importlib_resources.files('nupyprop.datafiles') / 'lookup_tables.h5' # path for lookup_tables

Expand Down
100 changes: 100 additions & 0 deletions src/nupyprop/datafiles/polarization_data.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#y PCthp P
1.000000000000000021e-02 9.999876410000000382e-01 9.999894299999999570e-01
2.000000000000000042e-02 9.999421029999999710e-01 9.999515599999999615e-01
2.999999999999999889e-02 9.998555930000000425e-01 9.998810500000000490e-01
4.000000000000000083e-02 9.997223109999999746e-01 9.997742299999999860e-01
5.000000000000000278e-02 9.995372460000000459e-01 9.996281599999999878e-01
6.000000000000000472e-02 9.992957209999999701e-01 9.994403200000000487e-01
6.999999999999999278e-02 9.989931229999999829e-01 9.992084100000000468e-01
8.000000000000000167e-02 9.986246979999999773e-01 9.989302199999999798e-01
8.999999999999999667e-02 9.981854000000000005e-01 9.986034999999999773e-01
9.999999999999999167e-02 9.976697559999999632e-01 9.982258699999999596e-01
1.100000000000000006e-01 9.970717679999999694e-01 9.977947600000000028e-01
1.199999999999999956e-01 9.963848279999999447e-01 9.973073700000000263e-01
1.300000000000000044e-01 9.956016460000000068e-01 9.967606100000000469e-01
1.400000000000000133e-01 9.947141999999999928e-01 9.961510999999999560e-01
1.500000000000000222e-01 9.937136989999999503e-01 9.954751299999999858e-01
1.600000000000000033e-01 9.925905480000000169e-01 9.947286699999999815e-01
1.700000000000000122e-01 9.913343409999999523e-01 9.939073899999999462e-01
1.800000000000000211e-01 9.899338420000000083e-01 9.930066699999999802e-01
1.900000000000000022e-01 9.883769930000000370e-01 9.920215999999999479e-01
2.000000000000000111e-01 9.866509199999999868e-01 9.909470299999999510e-01
2.100000000000000200e-01 9.847419450000000074e-01 9.897776200000000246e-01
2.200000000000000011e-01 9.826356130000000189e-01 9.885078200000000370e-01
2.300000000000000100e-01 9.803167210000000020e-01 9.871320000000000094e-01
2.400000000000000189e-01 9.777693530000000077e-01 9.856444199999999656e-01
2.500000000000000000e-01 9.749769270000000487e-01 9.840393200000000506e-01
2.600000000000000089e-01 9.719222480000000441e-01 9.823110000000000452e-01
2.700000000000000178e-01 9.685875739999999512e-01 9.804538200000000314e-01
2.800000000000000266e-01 9.649546810000000363e-01 9.784623399999999860e-01
2.900000000000000355e-01 9.610049520000000234e-01 9.763313300000000527e-01
2.999999999999999889e-01 9.567194639999999639e-01 9.740558999999999745e-01
3.099999999999999978e-01 9.520790949999999864e-01 9.716315300000000210e-01
3.200000000000000067e-01 9.470646350000000435e-01 9.690541999999999767e-01
3.300000000000000155e-01 9.416569110000000409e-01 9.663204300000000080e-01
3.400000000000000244e-01 9.358369250000000417e-01 9.634274099999999841e-01
3.500000000000000333e-01 9.295859929999999993e-01 9.603730700000000509e-01
3.600000000000000422e-01 9.228859090000000043e-01 9.571561800000000231e-01
3.699999999999999956e-01 9.157190960000000102e-01 9.537764300000000084e-01
3.800000000000000044e-01 9.080687859999999612e-01 9.502345199999999714e-01
3.900000000000000133e-01 8.999191899999999800e-01 9.465322299999999744e-01
4.000000000000000222e-01 8.912556750000000250e-01 9.426725099999999635e-01
4.100000000000000311e-01 8.820649449999999892e-01 9.386595699999999987e-01
4.200000000000000400e-01 8.723352180000000233e-01 9.344988800000000317e-01
4.299999999999999933e-01 8.620564010000000277e-01 9.301972499999999755e-01
4.400000000000000022e-01 8.512202530000000378e-01 9.257628700000000155e-01
4.500000000000000111e-01 8.398205420000000032e-01 9.212052699999999650e-01
4.600000000000000200e-01 8.278531909999999883e-01 9.165353899999999499e-01
4.700000000000000289e-01 8.153164010000000239e-01 9.117654899999999563e-01
4.800000000000000377e-01 8.022107649999999923e-01 9.069091099999999628e-01
4.899999999999999911e-01 7.885393490000000005e-01 9.019810499999999509e-01
5.000000000000000000e-01 7.743077619999999550e-01 8.969972099999999893e-01
5.100000000000000089e-01 7.595241879999999890e-01 8.919745199999999929e-01
5.200000000000000178e-01 7.441994020000000098e-01 8.869307899999999689e-01
5.300000000000000266e-01 7.283467529999999579e-01 8.818845400000000501e-01
5.400000000000000355e-01 7.119821160000000537e-01 8.768548299999999740e-01
5.500000000000000444e-01 6.951238199999999479e-01 8.718610900000000052e-01
5.600000000000000533e-01 6.777925500000000492e-01 8.669228799999999513e-01
5.700000000000000622e-01 6.600112139999999572e-01 8.620596699999999446e-01
5.800000000000000711e-01 6.418047989999999814e-01 8.572906700000000324e-01
5.899999999999999689e-01 6.232001910000000144e-01 8.526345600000000413e-01
5.999999999999999778e-01 6.042259840000000493e-01 8.481092599999999759e-01
6.099999999999999867e-01 5.849122749999999815e-01 8.437317699999999920e-01
6.199999999999999956e-01 5.652904359999999517e-01 8.395179499999999573e-01
6.300000000000000044e-01 5.453928829999999950e-01 8.354823200000000005e-01
6.400000000000000133e-01 5.252528440000000520e-01 8.316379099999999802e-01
6.500000000000000222e-01 5.049041159999999584e-01 8.279961399999999916e-01
6.600000000000000311e-01 4.843808250000000148e-01 8.245666900000000465e-01
6.700000000000000400e-01 4.637171979999999971e-01 8.213574500000000445e-01
6.800000000000000488e-01 4.429473340000000259e-01 8.183744099999999966e-01
6.900000000000000577e-01 4.221049900000000132e-01 8.156217399999999840e-01
7.000000000000000666e-01 4.012233809999999901e-01 8.131016800000000488e-01
7.100000000000000755e-01 3.803349899999999839e-01 8.108146800000000098e-01
7.199999999999999734e-01 3.594714019999999954e-01 8.087594099999999564e-01
7.299999999999999822e-01 3.386631500000000239e-01 8.069328799999999635e-01
7.399999999999999911e-01 3.179395799999999994e-01 8.053305299999999889e-01
7.500000000000000000e-01 2.973287410000000075e-01 8.039463700000000212e-01
7.600000000000000089e-01 2.768572859999999802e-01 8.027730899999999670e-01
7.700000000000000178e-01 2.565504009999999835e-01 8.018022599999999889e-01
7.800000000000000266e-01 2.364317429999999998e-01 8.010244600000000492e-01
7.900000000000000355e-01 2.165234010000000042e-01 8.004294299999999973e-01
8.000000000000000444e-01 1.968458790000000014e-01 8.000062399999999796e-01
8.100000000000000533e-01 1.774180810000000053e-01 7.997434500000000224e-01
8.200000000000000622e-01 1.582573240000000048e-01 7.996292200000000294e-01
8.300000000000000711e-01 1.393793600000000077e-01 7.996514999999999596e-01
8.400000000000000799e-01 1.207984059999999971e-01 7.997981299999999960e-01
8.499999999999999778e-01 1.025271920000000031e-01 8.000569600000000392e-01
8.599999999999999867e-01 8.457701410000000031e-02 8.004159600000000374e-01
8.699999999999999956e-01 6.695780319999999897e-02 8.008632999999999447e-01
8.800000000000000044e-01 4.967819729999999739e-02 8.013874399999999509e-01
8.900000000000000133e-01 3.274562830000000285e-02 8.019772099999999959e-01
9.000000000000000222e-01 1.616641859999999944e-02 8.026218200000000413e-01
9.100000000000000311e-01 -5.410652689999999662e-05 8.033109800000000078e-01
9.200000000000000400e-01 -1.591148519999999872e-02 8.040348200000000389e-01
9.300000000000000488e-01 -3.140195180000000114e-02 8.047840400000000338e-01
9.400000000000000577e-01 -4.652221270000000269e-02 8.055497799999999931e-01
9.500000000000000666e-01 -6.126911489999999766e-02 8.063237100000000268e-01
9.600000000000000755e-01 -7.563909589999999461e-02 8.070979499999999529e-01
9.699999999999999734e-01 -8.962711980000000189e-02 8.078649900000000050e-01
9.799999999999999822e-01 -1.032241549999999980e-01 8.086175300000000288e-01
9.899999999999999911e-01 -1.164087869999999997e-01 8.093477300000000429e-01
10 changes: 5 additions & 5 deletions src/nupyprop/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import nupyprop.data as Data
from nupyprop.propagate import geometry as Geometry
import nupyprop.constants as const

from collections import OrderedDict
import numpy as np
Expand All @@ -19,13 +20,12 @@
import warnings
warnings.filterwarnings('ignore')

Re = 6371.0 # radius of the earth in km
Rlay = np.array([1221.5, 3480.0, 5701.0, 5771.0, 5971.0, 6151.0, 6346.6, 6356.0, 6368.0, 6371.0]) # PREM layers based on R_earth. If you're using another Earth model, be sure to change it here as well as propagate.f90, in PREMdensity subroutine.
Re = const.R_earth #Radius of the earth in km
Rlay = const.Rlay #PREM layers based on R_earth. If you're using another Earth model, be sure to change it in the constants.py file

rho_water = 1.02 # density of water in g/cm^3
# beta_arr = np.asarray([float('{:.1f}'.format(i)) for i in np.concatenate((np.linspace(0.1,5,50), np.linspace(6,90,85)))])
rho_water = const.rho_water #density of water in g/cm^3

beta_arr = np.asarray([float('{:.1f}'.format(i)) for i in np.arange(0.1,90.1,step=0.1)]) # finer steps of 0.1 deg
beta_arr = const.beta_arr #Earth emergence angles in steps of 0.1 degrees

def sagitta_deg(beta_deg):
'''
Expand Down
4 changes: 3 additions & 1 deletion src/nupyprop/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import nupyprop.geometry as Geometry
from nupyprop.propagate import run as Run

import nupyprop.constants as const

import numpy as np
from astropy.table import Table
from collections import OrderedDict
Expand All @@ -18,7 +20,7 @@
import os
import glob

rho_water = 1.02 # g/cm^3
rho_water = const.rho_water # g/cm^3

def file_cleaner(output_type):
'''
Expand Down
26 changes: 10 additions & 16 deletions src/nupyprop/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,28 @@

@author: sam
"""
import nupyprop.data as Data
# import data as Data
import nupyprop.constants as const

import numpy as np
import scipy.integrate as integrate
import scipy.constants as scc
import multiprocessing as mp
from multiprocessing import Pool
# import matplotlib.pyplot as plt
# mpl.use('Agg') # for clusters
from astropy.table import Table
from astropy.io import ascii
from collections import OrderedDict
import time

E_nu = Data.E_nu
E_lep = Data.E_lep
E_nu = const.E_nu
E_lep = const.E_lep

m_e = scc.physical_constants["electron mass energy equivalent in MeV"][0]*1e-3 # GeV
m_mu = scc.physical_constants["muon mass energy equivalent in MeV"][0]*1e-3 # GeV
m_tau = scc.physical_constants["tau mass energy equivalent in MeV"][0]*1e-3 # GeV
m_pi = 139.57018e-3 # pion mass in GeV
alpha_fs = scc.fine_structure
le = 3.8616e-11 # electron Compton wavelength in cm
m_mu = const.m_mu #muon mass in GeV
m_tau = const.m_tau #tau mass in GeV
m_pi = const.m_pi #pion mass in GeV
alpha_fs = const.alpha_fs #fine structure constant

m_p = scc.physical_constants["proton mass energy equivalent in MeV"][0]*1e-3 # GeV
G_F = scc.physical_constants["Fermi coupling constant"][0] # GeV^-2
N_A = scc.Avogadro
m_p = const.m_p #proton mass in GeV
N_A = const.N_A #Avogadro's number

def rep(val): # Remove non-physical values
'''
Expand Down Expand Up @@ -517,4 +511,4 @@ def calc_xc(lepton, material, model):
# p.close()

# end_time = time.time()
# print(f"It took a total of {end_time-start_time:.2f} seconds to compute")
# print(f"It took a total of {end_time-start_time:.2f} seconds to compute")
Loading