Commit fe90ddbe authored by DavidWalz's avatar DavidWalz
Browse files

improve python3 compatibility, sim.py: fix optional make dir

parent 89690194
...@@ -5,8 +5,8 @@ __all__ = [ ...@@ -5,8 +5,8 @@ __all__ = [
"atmosphere", "atmosphere",
"plotting"] "plotting"]
import shower import airshower.shower
import utils import airshower.utils
import gumbel import airshower.gumbel
import atmosphere import airshower.atmosphere
import plotting import airshower.plotting
from __future__ import division, print_function
import numpy as np import numpy as np
from os import path
from scipy import integrate, interpolate, optimize from scipy import integrate, interpolate, optimize
import os.path
R_E = 6.371 * 1e6 # radius of Earth R_E = 6.371 * 1e6 # radius of Earth
H_MAX = 112829.2 # height above sea level where the mass overburden vanishes H_MAX = 112829.2 # height above sea level where the mass overburden vanishes
...@@ -226,7 +228,7 @@ class Atmosphere: ...@@ -226,7 +228,7 @@ class Atmosphere:
if filename is None: if filename is None:
filename = 'atmosphere_model%i.npz' % model filename = 'atmosphere_model%i.npz' % model
if os.path.exists(filename): if path.exists(filename):
print('Reading constants from %s' % filename) print('Reading constants from %s' % filename)
data = np.load(filename) data = np.load(filename)
assert self.model == data['model'], 'File contains parameters for different model %i' % model assert self.model == data['model'], 'File contains parameters for different model %i' % model
......
from __future__ import division from __future__ import division, print_function
import numpy as np import numpy as np
......
""" Plotting routines from __future__ import division, print_function
"""
from __future__ import division
import numpy as np import numpy as np
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from matplotlib.collections import PatchCollection from matplotlib.collections import PatchCollection
from matplotlib.colors import Normalize from matplotlib.colors import Normalize
import seaborn.apionly as sns import seaborn.apionly as sns
from airshower import utils
import utils
def maybe_save(fig, fname): def maybe_save(fig, fname):
......
from __future__ import division from __future__ import division, print_function
import numpy as np import numpy as np
import utils from airshower import atmosphere, gumbel, utils
import atmosphere
import gumbel
import plotting
HEIGHT = 1400 HEIGHT = 1400
...@@ -146,7 +142,6 @@ def rand_events(logE, mass, v_stations, fname=None, wavefront='planar'): ...@@ -146,7 +142,6 @@ def rand_events(logE, mass, v_stations, fname=None, wavefront='planar'):
S1 = np.zeros((nb_events, nb_stations, 80)) S1 = np.zeros((nb_events, nb_stations, 80))
S2 = np.zeros((nb_events, nb_stations, 80)) S2 = np.zeros((nb_events, nb_stations, 80))
for i in range(nb_events): for i in range(nb_events):
# print('%4i, logE = %.2f' % (i, logE[i]))
S1[i], S2[i] = detector_response(logE[i], mass[i], v_axis[i], v_core[i], v_max[i], v_stations) S1[i], S2[i] = detector_response(logE[i], mass[i], v_axis[i], v_core[i], v_max[i], v_stations)
if wavefront == 'planar': if wavefront == 'planar':
T[i] = utils.arrival_time_planar(v_stations, v_core[i], v_axis[i]) T[i] = utils.arrival_time_planar(v_stations, v_core[i], v_axis[i])
......
from __future__ import division from __future__ import division, print_function
import numpy as np import numpy as np
......
from __future__ import division, print_function
import numpy as np import numpy as np
from airshower import shower, utils, plotting
import argparse import argparse
import os
from airshower import shower, utils
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("--mass", default=1, type=int, help='mass number') parser.add_argument("--mass", default=1, type=int, help='mass number')
parser.add_argument("--nfiles", default=10, type=int, help='number of files') parser.add_argument("--nfiles", default=10, type=int, help='number of files')
parser.add_argument("--nevents", default=10000, type=int, help='number of events per file') parser.add_argument("--nevents", default=10000, type=int, help='number of events per file')
parser.add_argument("--path", default='./RawData', type=str, help='output folder')
args = parser.parse_args() args = parser.parse_args()
print 'Simulating' print('A', args.mass)
print 'A', args.mass print('nfiles', args.nfiles)
print 'nfiles', args.nfiles print('nevents', args.nevents)
print 'nevents', args.nevents print('path', args.path)
print('Simulating')
if not(os.path.exists(args.path)):
os.makedirs(args.path)
v_stations = utils.station_coordinates(9, layout='offset') v_stations = utils.station_coordinates(9, layout='offset')
for i in range(args.nfiles): for i in range(args.nfiles):
fname = '%s/showers-A%i-%i.npz' % (args.path, args.mass, i)
print(fname)
logE = 18.5 + 1.5 * np.random.rand(args.nevents) logE = 18.5 + 1.5 * np.random.rand(args.nevents)
mass = args.mass * np.ones(args.nevents) mass = args.mass * np.ones(args.nevents)
data = shower.rand_events(logE, mass, v_stations) data = shower.rand_events(logE, mass, v_stations)
print "save package:", i
np.savez_compressed( np.savez_compressed(
'./RawData/showers-A%i-%i.npz' % (args.mass, i), fname,
detector=data['detector'], detector=data['detector'],
logE=data['logE'], logE=data['logE'],
mass=data['mass'], mass=data['mass'],
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment