Read.py 2.4 KB
from numpy import loadtxt

resultDirectory="Results/"
positionFile="/position"
momentumFile="/momentum"
extraFile="/extra"
profileFile="/profile"
ElmagFile="/Elmag_spectrum"

def ReadExtraFile(fileName,cols=[0,1,2,3,4,5]):
   '''
      charge, arrival redshift, weight, generation, arrival angle, emitting energy (source)
   '''
   return loadtxt(resultDirectory+fileName+extraFile,unpack=True,usecols=cols)

def ReadProfile(fileName,cols=[0,1,2,3,4,5]): 
   '''
      Source: Emin, redshift, dist (Mpc), total number of photons emitted, EGMF amplitude, 
              number of leptons producted
   '''
   return loadtxt(resultDirectory+fileName+profileFile,unpack=True,usecols=cols)

def ReadTime(fileName):
   return loadtxt(resultDirectory+fileName+positionFile,unpack=True,usecols=[0])

def ReadPosition(fileName):
   return loadtxt(resultDirectory+fileName+positionFile,unpack=True,usecols=[1,2,3])

def ReadPositionAngle(fileName):
   return loadtxt(resultDirectory+fileName+positionFile,unpack=True,usecols=[4,5])

def ReadEnergy(fileName):
   return loadtxt(resultDirectory+fileName+momentumFile,unpack=True,usecols=[0])

def ReadMomentum(fileName):
   return loadtxt(resultDirectory+fileName+momentumFile,unpack=True,usecols=[1,2,3])

def ReadMomentumAngle(fileName):
   return loadtxt(resultDirectory+fileName+momentumFile,unpack=True,usecols=[4,5])

def ReadElmag(fileName):
   Elmag=resultDirectory+fileName+ElmagFile
   energy,fluxGamma,fluxLepton = loadtxt(Elmag,unpack=True,usecols=[0,1,2])
   energy *= 10**(-9) #GeV
   flux=(fluxGamma+fluxLepton)*1e-9 #GeV normalized to 1 initial photon
   return energy,flux

def ReadSpectrum(fileName,cols=[0,1,2,3,4,5,6,7,8]): 
   return loadtxt(resultDirectory+fileName+"/Spectrum.txt",unpack=True,usecols=cols)

def ReadSourceSpectrum(fileName,cols=[0,1,2,3,4]): 
   return loadtxt(resultDirectory+fileName+"/Source_spectrum.txt",unpack=True,usecols=cols)

def ReadAngleVsEnergy(fileName,cols=[0,1,2,3,4]): 
   return loadtxt(resultDirectory+fileName+"/Angle_vs_Energy.txt",unpack=True,usecols=cols)

def ReadRadial(fileName,cols=[0,1,2,3,4]): 
   return loadtxt(resultDirectory+fileName+"/Radial_distribution.txt",unpack=True,usecols=cols)

def ReadTiming(fileName,cols=[0,1,2,3,4]): 
   return loadtxt(resultDirectory+fileName+"/Timing.txt",unpack=True,usecols=cols)

def ReadGeneration(fileName,cols=[0,1]):
   return loadtxt(resultDirectory+fileName+"/Generation.txt",unpack=True,usecols=cols)